我想使个人资料图片特别添加到帐户中,并将其保存(存储)到数据库中-Cloud Firestore作为每个帐户的特殊个人资料图片
例如更多解释:
遵循Profile Java和活动的代码
Profile.Java
public class Child_Profile extends AppCompatActivity {
private TextView name;
private TextView gender;
private TextView birth;
private TextView bload;
private TextView Text_Dates;
private TextView Text_Time;
private Button Button_record;
private TextView Text_record;
private TextView Text_hospial;
private TextView Text_Plan;
private TextView Text_Satus;
private TextView Text_Price;
private ImageView ImageView_choose_image;
private Button button_choose_image;
private Uri mUri;
private static final int GALLERY_INTENT = 1;
private StorageReference mStorage;
private DatabaseReference mData;
private FirebaseFirestore db = FirebaseFirestore.getInstance();
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu,menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId()==R.id.action_sign_out)
signOut();
return true;
}
private void signOut() {
AuthUI.getInstance().signOut(this)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
startActivity(new Intent(Child_Profile.this,User.class));
finish();
}
});
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_child__profile);
name = findViewById(R.id.text_view_Namee);
gender = findViewById(R.id.text_view_Gender);
birth = findViewById(R.id.text_view_Birth);
bload = findViewById(R.id.text_view_Blood);
Text_Dates = findViewById(R.id.Text_Dates);
Text_Time = findViewById(R.id.Text_Time);
Text_record = findViewById(R.id.Text_record);
Text_hospial = findViewById(R.id.Text_hospial);
Text_Plan = findViewById(R.id.Text_Plan);
Text_Satus = findViewById(R.id.Text_Satus);
Button_record = findViewById(R.id.Button_record);
Text_Price = findViewById(R.id.Text_Price);
button_choose_image = findViewById(R.id.button_choose_image);
ImageView_choose_image = findViewById(R.id.ImageView_choose_image);
mStorage = FirebaseStorage.getInstance().getReference("Photo");
mData = FirebaseDatabase.getInstance().getReference("Photo");
button_choose_image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openFileChooser();
}
});
Intent in = getIntent();
final Bundle b = in.getExtras();
if (b != null) {
String n = (String) b.get("id");
db.collection("Child Profile").document(n).get()
.addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
String pName = documentSnapshot.getString("name");
String pgender = documentSnapshot.getString("gender");
String pbirth = documentSnapshot.getString("birth");
String pbload = documentSnapshot.getString("bload");
String pDates = documentSnapshot.getString("dates");
String pTime = documentSnapshot.getString("time");
String pHospital = documentSnapshot.getString("hospital");
String pPlan = documentSnapshot.getString("typeOfPlan");
String pSatus = documentSnapshot.getString("satus");
String pPrice = documentSnapshot.getString("price");
name.setText(pName);
gender.setText(pgender);
birth.setText(pbirth);
bload.setText(pbload);
Text_Dates.setText(pDates);
Text_Time.setText(pTime);
Text_hospial.setText(pHospital);
Text_Plan.setText(pPlan);
Text_Satus.setText(pSatus);
Text_Price.setText(pPrice);
}
});
}
}
private void openFileChooser() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, GALLERY_INTENT);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == GALLERY_INTENT && resultCode == RESULT_OK && data != null && data.getData()!= null) {
mUri = data.getData();
Picasso.with(this).load(mUri).into(ImageView_choose_image);
}
}
public void ImageView_choose_image(View view) {
}
Profile.Xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="@color/colorPrimaryDark"
android:orientation="vertical">
<ImageView
android:id="@+id/ImageView_choose_image"
android:layout_width="86dp"
android:layout_height="68dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="45dp"
android:onClick="ImageView_choose_image"/>
<Button
android:id="@+id/button_choose_image"
android:layout_width="wrap_content"
android:layout_height="68dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="-110dp"
android:background="@null"
android:text="chid Picture" />
<TextView
android:id="@+id/text_view_Namee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="40dp"
android:text="Name"
android:textColor="@android:color/white"
android:textSize="25dp"
android:textStyle="bold" />
</LinearLayout>
<android.support.v7.widget.CardView
android:layout_width="350dp"
android:layout_height="100dp"
android:layout_marginLeft="10dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="160dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="3">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/text_view_Gender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gender"
android:textSize="20dp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/text_view_Birth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Birth Day"
android:textSize="20dp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/text_view_Blood"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Blood Type"
android:textSize="20dp" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<LinearLayout
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:layout_marginTop="50dp"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_weight="9"
android:orientation="horizontal">
<ImageView
android:layout_width="50dp"
android:layout_height="65dp"
android:background="@drawable/calendar"/>
<TextView
android:id="@+id/Text_Dates"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="Dates" />
<TextView
android:id="@+id/Text_Time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="-35dp"
android:text="Time" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_marginTop="240dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_marginLeft="-1dp"
android:orientation="horizontal">
<LinearLayout
android:layout_marginTop="70dp"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_weight="9"
android:orientation="horizontal">
<ImageView
android:layout_width="50dp"
android:layout_height="65dp"
android:layout_marginTop="25dp"
android:background="@drawable/recodbook" />
<TextView
android:id="@+id/Text_Plan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="Plan" />
<TextView
android:id="@+id/Text_Price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:layout_marginLeft="-30dp"
android:padding="2dp"
android:text="Price" />
<TextView
android:id="@+id/Text_Satus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="-30dp"
android:padding="2dp"
android:layout_marginTop="70dp"
android:text="Satus" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_marginLeft="180dp"
android:orientation="horizontal">
<LinearLayout
android:layout_marginTop="50dp"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_weight="9"
android:orientation="horizontal">
<Button
android:id="@+id/Button_record"
android:layout_width="50dp"
android:layout_height="65dp"
android:layout_marginLeft="20dp"
android:background="@drawable/record" />
<TextView
android:id="@+id/Text_record"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="your record" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_marginTop="250dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_marginLeft="160dp"
android:orientation="horizontal">
<LinearLayout
android:layout_marginTop="70dp"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_weight="9"
android:orientation="horizontal">
<ImageView
android:layout_width="50dp"
android:layout_height="65dp"
android:layout_marginLeft="6dp"
android:layout_marginTop="5dp"
android:src="@drawable/medical" />
<TextView
android:id="@+id/Text_hospial"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:gravity="center"
android:text="your hospital" />
</LinearLayout>
</LinearLayout>