Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.44 KB | None | 0 0
  1. <LinearLayout
  2. android:layout_width="288dp"
  3. android:layout_height="80dp"
  4. android:orientation="horizontal"
  5. android:weightSum="1">
  6.  
  7. <ImageView
  8. android:id="@+id/profile_pic"
  9. android:layout_width="120dp"
  10. android:layout_height="75dp"
  11. android:background="#CED5E4"
  12. android:src="@drawable/user_placeholder" />
  13.  
  14. <TextView
  15. android:paddingTop="5dp"
  16. android:layout_width="145dp"
  17. android:layout_height="78dp"
  18. android:layout_marginLeft="10dp"
  19. android:textSize="16dp"
  20. android:textColor="#FFFFFF"
  21. android:textAlignment="center"
  22. android:text="Press the Take Pic button and create your Profile Pic"
  23. android:layout_weight="0.23">
  24.  
  25. </TextView>
  26.  
  27. </LinearLayout>
  28.  
  29. private ImageButton license_photo;
  30. private Uri filepath;
  31. private StorageReference storageRef;
  32.  
  33. @Override
  34. protected void onCreate(Bundle savedInstanceState) {
  35. super.onCreate(savedInstanceState);
  36. setContentView(R.layout.activity_b_driver_registration);
  37.  
  38. firebaseAuth = FirebaseAuth.getInstance();
  39. storageRef = FirebaseStorage.getInstance().getReference();
  40.  
  41. license_photo = (ImageButton) findViewById(R.id.license_photo);
  42. license_photo.setOnClickListener(new View.OnClickListener() {
  43. @Override
  44. public void onClick(View view) {
  45. Intent intentCamera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  46. startActivityForResult(intentCamera, 0);
  47. }
  48. });
  49.  
  50. register_btn = (Button) findViewById(R.id.register_btn);
  51. register_btn.setOnClickListener(new View.OnClickListener() {
  52. @Override
  53. public void onClick(View view) {
  54.  
  55. attemptLogin(true);
  56. uploadFile();
  57. }
  58. });
  59.  
  60.  
  61. } // onCreate
  62.  
  63. public void uploadFile() {
  64.  
  65. if (filepath != null) {
  66. final ProgressDialog progressDialog = new ProgressDialog(this);
  67. progressDialog.setTitle("Uploading ...");
  68. progressDialog.show();
  69.  
  70. String userId = FirebaseAuth.getInstance().getCurrentUser().getUid();
  71.  
  72. StorageReference licenseRef = storageRef.child("drivers").child(userId)
  73. .child("images/license.jpg");
  74.  
  75. licenseRef.putFile(filepath)
  76. .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
  77. @Override
  78. public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
  79. progressDialog.dismiss();
  80. Toast.makeText(getApplicationContext(), "File Uploaded", Toast
  81. .LENGTH_LONG).show();
  82. }
  83. })
  84. .addOnFailureListener(new OnFailureListener() {
  85. @Override
  86. public void onFailure(@NonNull Exception exception) {
  87. progressDialog.dismiss();
  88. Toast.makeText(getApplicationContext(), exception
  89. .getMessage(), Toast.LENGTH_LONG).show();
  90. }
  91. })
  92.  
  93. .addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
  94. @Override
  95. public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
  96. double progress = (100.0 * taskSnapshot
  97. .getBytesTransferred()) / taskSnapshot.getTotalByteCount();
  98. progressDialog.setMessage(((int) progress) + "% Uploaded...");
  99. }
  100. });
  101.  
  102. } else {
  103. // display an error toast
  104. }
  105.  
  106. } // uploadFile()
  107.  
  108. public static class UsernameDialogFragment extends DialogFragment {
  109.  
  110. @Override
  111. public Dialog onCreateDialog(Bundle savedInstanceState) {
  112. AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
  113. // Get the layout inflater
  114. LayoutInflater inflater = getActivity().getLayoutInflater();
  115.  
  116. // Inflate and set the layout for the dialog
  117. // Pass null as the parent view because its going in the dialog layout
  118. builder.setView(inflater.inflate(R.layout.username_dialog, null));
  119.  
  120. // Add action buttons ...
  121.  
  122. builder.setPositiveButton(R.string.action_register, new DialogInterface.OnClickListener() {
  123. @Override
  124. public final void onClick(final DialogInterface dialog, int id) {
  125.  
  126. // save the username to Firebase and sign in user ...
  127.  
  128. // ... casting dialog interface to an alert dialog and casting
  129. // the result of the findView to an EditText
  130. EditText usernameField = (EditText)((AlertDialog) dialog)
  131. .findViewById(username);
  132. String username = usernameField.getText().toString();
  133.  
  134. // year
  135. EditText yearField = (EditText)((AlertDialog) dialog).findViewById(R.id.year);
  136. String year = yearField.getText().toString();
  137.  
  138. // color, make and model
  139. EditText cmmField = (EditText)((AlertDialog) dialog).findViewById(R.id.cmm);
  140. String cmm = cmmField.getText().toString();
  141.  
  142. // cell
  143. EditText cellField = (EditText)((AlertDialog) dialog).findViewById(R.id.cell);
  144. String cell = cellField.getText().toString();
  145.  
  146. // license plate no.
  147. EditText plateField = (EditText)((AlertDialog) dialog).findViewById(R.id.licenseNo);
  148. String licenseNo = plateField.getText().toString();
  149.  
  150. // profile pic
  151. ImageView profilePic = (ImageView)((AlertDialog) dialog).findViewById(R.id.profile_pic);
  152. profilePic.setImageResource(R.drawable.user_placeholder);
  153.  
  154.  
  155.  
  156. // ... get user's unique id
  157. String userId = FirebaseAuth.getInstance().getCurrentUser().getUid();
  158.  
  159. User aUser = new User(username, year, cmm, cell, licenseNo);
  160.  
  161.  
  162. /* https://android-chat-af94c.firebaseio.com/android-chat-af94c/
  163. users/pRsxsToJZPTzCdtft69f1grIJC13/profile/username
  164.  
  165. getInstance -> grabbing the url:
  166. https://android-chat-af94c.firebaseio.com/android-chat-af94c/
  167. */
  168. // above is the same as below ...
  169. FirebaseDatabase.getInstance().getReference("drivers").child(userId).setValue(aUser);
  170.  
  171. Intent intent = new Intent(getActivity().getBaseContext(), PoliciesActivity.class);
  172. startActivity(intent);
  173. }
  174.  
  175. });
  176.  
  177. builder.setNeutralButton(R.string.action_take_pic, new DialogInterface.OnClickListener() {
  178. @Override
  179. public final void onClick(final DialogInterface dialog, int id) {
  180.  
  181.  
  182. }
  183. });
  184.  
  185. return builder.create();
  186.  
  187. }
  188.  
  189. } // UsernameDialogFragment
  190.  
  191. // take photo
  192. @Override
  193. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  194. super.onActivityResult(requestCode, resultCode, data);
  195.  
  196. filepath = data.getData();
  197.  
  198. Bitmap bitmap = (Bitmap)data.getExtras().get("data");
  199. license_photo.setImageBitmap(bitmap);
  200.  
  201. } // onActivityResult
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement