Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <LinearLayout
- android:layout_width="288dp"
- android:layout_height="80dp"
- android:orientation="horizontal"
- android:weightSum="1">
- <ImageView
- android:id="@+id/profile_pic"
- android:layout_width="120dp"
- android:layout_height="75dp"
- android:background="#CED5E4"
- android:src="@drawable/user_placeholder" />
- <TextView
- android:paddingTop="5dp"
- android:layout_width="145dp"
- android:layout_height="78dp"
- android:layout_marginLeft="10dp"
- android:textSize="16dp"
- android:textColor="#FFFFFF"
- android:textAlignment="center"
- android:text="Press the Take Pic button and create your Profile Pic"
- android:layout_weight="0.23">
- </TextView>
- </LinearLayout>
- private ImageButton license_photo;
- private Uri filepath;
- private StorageReference storageRef;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_b_driver_registration);
- firebaseAuth = FirebaseAuth.getInstance();
- storageRef = FirebaseStorage.getInstance().getReference();
- license_photo = (ImageButton) findViewById(R.id.license_photo);
- license_photo.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Intent intentCamera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
- startActivityForResult(intentCamera, 0);
- }
- });
- register_btn = (Button) findViewById(R.id.register_btn);
- register_btn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- attemptLogin(true);
- uploadFile();
- }
- });
- } // onCreate
- public void uploadFile() {
- if (filepath != null) {
- final ProgressDialog progressDialog = new ProgressDialog(this);
- progressDialog.setTitle("Uploading ...");
- progressDialog.show();
- String userId = FirebaseAuth.getInstance().getCurrentUser().getUid();
- StorageReference licenseRef = storageRef.child("drivers").child(userId)
- .child("images/license.jpg");
- licenseRef.putFile(filepath)
- .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
- @Override
- public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
- progressDialog.dismiss();
- Toast.makeText(getApplicationContext(), "File Uploaded", Toast
- .LENGTH_LONG).show();
- }
- })
- .addOnFailureListener(new OnFailureListener() {
- @Override
- public void onFailure(@NonNull Exception exception) {
- progressDialog.dismiss();
- Toast.makeText(getApplicationContext(), exception
- .getMessage(), Toast.LENGTH_LONG).show();
- }
- })
- .addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
- @Override
- public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
- double progress = (100.0 * taskSnapshot
- .getBytesTransferred()) / taskSnapshot.getTotalByteCount();
- progressDialog.setMessage(((int) progress) + "% Uploaded...");
- }
- });
- } else {
- // display an error toast
- }
- } // uploadFile()
- public static class UsernameDialogFragment extends DialogFragment {
- @Override
- public Dialog onCreateDialog(Bundle savedInstanceState) {
- AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
- // Get the layout inflater
- LayoutInflater inflater = getActivity().getLayoutInflater();
- // Inflate and set the layout for the dialog
- // Pass null as the parent view because its going in the dialog layout
- builder.setView(inflater.inflate(R.layout.username_dialog, null));
- // Add action buttons ...
- builder.setPositiveButton(R.string.action_register, new DialogInterface.OnClickListener() {
- @Override
- public final void onClick(final DialogInterface dialog, int id) {
- // save the username to Firebase and sign in user ...
- // ... casting dialog interface to an alert dialog and casting
- // the result of the findView to an EditText
- EditText usernameField = (EditText)((AlertDialog) dialog)
- .findViewById(username);
- String username = usernameField.getText().toString();
- // year
- EditText yearField = (EditText)((AlertDialog) dialog).findViewById(R.id.year);
- String year = yearField.getText().toString();
- // color, make and model
- EditText cmmField = (EditText)((AlertDialog) dialog).findViewById(R.id.cmm);
- String cmm = cmmField.getText().toString();
- // cell
- EditText cellField = (EditText)((AlertDialog) dialog).findViewById(R.id.cell);
- String cell = cellField.getText().toString();
- // license plate no.
- EditText plateField = (EditText)((AlertDialog) dialog).findViewById(R.id.licenseNo);
- String licenseNo = plateField.getText().toString();
- // profile pic
- ImageView profilePic = (ImageView)((AlertDialog) dialog).findViewById(R.id.profile_pic);
- profilePic.setImageResource(R.drawable.user_placeholder);
- // ... get user's unique id
- String userId = FirebaseAuth.getInstance().getCurrentUser().getUid();
- User aUser = new User(username, year, cmm, cell, licenseNo);
- /* https://android-chat-af94c.firebaseio.com/android-chat-af94c/
- users/pRsxsToJZPTzCdtft69f1grIJC13/profile/username
- getInstance -> grabbing the url:
- https://android-chat-af94c.firebaseio.com/android-chat-af94c/
- */
- // above is the same as below ...
- FirebaseDatabase.getInstance().getReference("drivers").child(userId).setValue(aUser);
- Intent intent = new Intent(getActivity().getBaseContext(), PoliciesActivity.class);
- startActivity(intent);
- }
- });
- builder.setNeutralButton(R.string.action_take_pic, new DialogInterface.OnClickListener() {
- @Override
- public final void onClick(final DialogInterface dialog, int id) {
- }
- });
- return builder.create();
- }
- } // UsernameDialogFragment
- // take photo
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- filepath = data.getData();
- Bitmap bitmap = (Bitmap)data.getExtras().get("data");
- license_photo.setImageBitmap(bitmap);
- } // onActivityResult
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement