Guest User

Untitled

a guest
Jan 16th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.31 KB | None | 0 0
  1. <uses-permission android:name="android.permission.INTERNET"></uses-permission>
  2. <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
  3. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
  4. <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
  5.  
  6. <application
  7. android:allowBackup="true"
  8. android:hardwareAccelerated="false"
  9. android:icon="@mipmap/ic_launcher"
  10. android:label="@string/app_name"
  11. android:largeHeap="true"
  12. android:roundIcon="@mipmap/ic_launcher_round"
  13. android:supportsRtl="true"
  14. android:theme="@style/AppTheme">
  15. <activity android:name=".MainActivity">
  16. <intent-filter>
  17. <action android:name="android.intent.action.MAIN" />
  18.  
  19. <category android:name="android.intent.category.LAUNCHER" />
  20. </intent-filter>
  21. </activity>
  22. <activity android:name=".RegisterActivity" />
  23. <activity android:name=".Login" />
  24. <activity android:name=".SetupActivity"></activity>
  25. <activity android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
  26. android:theme="@style/Base.Theme.AppCompat"/>
  27. </application>
  28.  
  29. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  30. xmlns:app="http://schemas.android.com/apk/res-auto"
  31. xmlns:tools="http://schemas.android.com/tools"
  32. android:layout_width="match_parent"
  33. android:layout_height="match_parent"
  34. tools:context=".SetupActivity"
  35. android:background="@drawable/setup_background">
  36.  
  37.  
  38. <de.hdodenhof.circleimageview.CircleImageView
  39. android:id="@+id/profile_image"
  40. android:layout_width="170dp"
  41. android:layout_height="170dp"
  42. android:layout_alignParentTop="true"
  43. android:layout_centerHorizontal="true"
  44. android:layout_marginTop="0dp"
  45. android:src="@drawable/profile21"></de.hdodenhof.circleimageview.CircleImageView>
  46. <!--app:civ_border_color="@color/colorPrimaryDark"-->
  47. <!--app:civ_border_width="1dp"/>-->
  48.  
  49. <EditText
  50. android:id="@+id/setup_username"
  51. android:layout_width="match_parent"
  52. android:layout_height="wrap_content"
  53. android:layout_alignParentStart="true"
  54. android:layout_alignParentLeft="true"
  55. android:layout_alignParentTop="true"
  56. android:layout_marginTop="237dp"
  57. android:drawableLeft="@drawable/username"
  58. android:ems="10"
  59. android:hint="User Name"
  60. android:inputType="textMultiLine"
  61. android:textColor="#ffffff"
  62. android:textColorHint="@android:color/background_light"
  63. android:textSize="20sp"
  64. android:textStyle="bold" />
  65.  
  66. <EditText
  67. android:id="@+id/setup_fullname"
  68. android:layout_width="match_parent"
  69. android:layout_height="wrap_content"
  70. android:layout_below="@+id/setup_username"
  71. android:layout_alignParentStart="true"
  72. android:layout_alignParentLeft="true"
  73. android:drawableLeft="@drawable/name"
  74. android:ems="10"
  75. android:hint="Full Name"
  76. android:inputType="textMultiLine"
  77. android:textColor="#ffffff"
  78. android:textColorHint="@android:color/background_light"
  79. android:textSize="20sp"
  80. android:textStyle="bold" />
  81.  
  82. <EditText
  83. android:id="@+id/setup_country"
  84. android:layout_width="match_parent"
  85. android:layout_height="wrap_content"
  86. android:layout_below="@+id/setup_fullname"
  87. android:layout_alignParentStart="true"
  88. android:drawableLeft="@drawable/country"
  89. android:ems="10"
  90. android:hint="Country"
  91. android:inputType="textMultiLine"
  92. android:textColor="#ffffff"
  93. android:textColorHint="@android:color/background_light"
  94. android:textSize="20sp"
  95. android:textStyle="bold" />
  96.  
  97. <Button
  98. android:id="@+id/setup_saveinformation"
  99. android:layout_width="wrap_content"
  100. android:layout_height="wrap_content"
  101. android:layout_alignParentBottom="true"
  102. android:layout_centerHorizontal="true"
  103. android:textStyle="bold"
  104. android:textSize="18dp"
  105. android:layout_marginBottom="62dp"
  106. android:text="Save"
  107. android:background="@drawable/button"/>
  108.  
  109. </RelativeLayout>
  110.  
  111. public class SetupActivity extends AppCompatActivity {
  112. private Button Save;
  113. private EditText Username,Userfullname,Usercountry;
  114. private CircleImageView profileimage;
  115. private FirebaseAuth mAuth;
  116. private DatabaseReference userRef;
  117. private String currentuserid;
  118. private ProgressDialog loadingbar;
  119. private static int GALLARY_PICK = 1;
  120. private StorageReference Userprofileimageref;
  121.  
  122. @Override
  123. protected void onCreate(Bundle savedInstanceState) {
  124. super.onCreate(savedInstanceState);
  125. setContentView(R.layout.activity_setup);
  126.  
  127. mAuth=FirebaseAuth.getInstance();
  128. currentuserid=mAuth.getCurrentUser().getUid();
  129. userRef =FirebaseDatabase.getInstance().getReference().child("Users").child(currentuserid);
  130. Userprofileimageref = FirebaseStorage.getInstance().getReference().child("profile image");
  131. Save= findViewById(R.id.setup_saveinformation);
  132. Username= findViewById(R.id.setup_username);
  133. Userfullname= findViewById(R.id.setup_fullname);
  134. Usercountry= findViewById(R.id.setup_country);
  135. profileimage= findViewById(R.id.profile_image);
  136. loadingbar = new ProgressDialog(this);
  137.  
  138. Save.setOnClickListener(new View.OnClickListener() {
  139. @Override
  140. public void onClick(View v) {
  141. saveusersetupinfirmation();
  142. }
  143. });
  144.  
  145. profileimage.setOnClickListener(new View.OnClickListener() {
  146. @Override
  147. public void onClick(View v) {
  148. Intent galleryIntent = new Intent();
  149. galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
  150. galleryIntent.setType("image/*");
  151. startActivityForResult(galleryIntent, GALLARY_PICK);
  152. }
  153. });
  154. userRef.addValueEventListener(new ValueEventListener() {
  155. @Override
  156. public void onDataChange(DataSnapshot dataSnapshot) {
  157. if (dataSnapshot.exists())
  158. {
  159. String image =dataSnapshot.child("profileimage").getValue().toString();
  160. //
  161. // Glide.with(SetupActivity.this)
  162. // .load(image)
  163. // .into(profileimage);
  164.  
  165.  
  166. // Picasso.with(SetupActivity.this)
  167. // .load(image)
  168. // .fit()
  169. // .placeholder(R.drawable.profile)
  170. // .memoryPolicy(MemoryPolicy.NO_CACHE)
  171. // .networkPolicy(NetworkPolicy.NO_CACHE)
  172. // .into(profileimage);
  173. Picasso.get().load(image).resize(100,100).centerCrop().placeholder(R.drawable.profile).into(profileimage);
  174.  
  175.  
  176. }
  177.  
  178.  
  179. }
  180.  
  181. @Override
  182. public void onCancelled(DatabaseError databaseError) {
  183.  
  184. }
  185. });
  186. }
  187.  
  188. @Override
  189. protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
  190. super.onActivityResult(requestCode, resultCode, data);
  191. if (requestCode ==GALLARY_PICK && resultCode== RESULT_OK && data!=null)
  192. {
  193. Uri imageuri = data.getData();
  194.  
  195. CropImage.activity(imageuri)
  196. .setGuidelines(CropImageView.Guidelines.ON)
  197. .setAspectRatio(1, 1)
  198. .start(this);
  199.  
  200. }
  201.  
  202. if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
  203. CropImage.ActivityResult result = CropImage.getActivityResult(data);
  204. if (resultCode == RESULT_OK) {
  205.  
  206. loadingbar.setTitle("saving image");
  207. loadingbar.setMessage("please wait ....");
  208. loadingbar.show();
  209. loadingbar.setCanceledOnTouchOutside(true);
  210. Uri resultUri = result.getUri();
  211. final StorageReference filePath = Userprofileimageref.child(currentuserid + "jpg");
  212.  
  213. filePath.putFile(resultUri).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
  214. @Override
  215. public void onComplete(Task<UploadTask.TaskSnapshot> task) {
  216.  
  217. if (task.isSuccessful())
  218. {
  219. Toast.makeText(SetupActivity.this,"Profile image stored successfully",Toast.LENGTH_SHORT).show();
  220. final String downloadUrl = filePath.getDownloadUrl().toString();
  221. userRef.child("profileimage").setValue(downloadUrl)
  222. .addOnCompleteListener(new OnCompleteListener<Void>() {
  223. @Override
  224. public void onComplete(Task<Void> task) {
  225. if (task.isSuccessful())
  226. {
  227. Intent selfintent = new Intent(SetupActivity.this,SetupActivity.class);
  228. startActivity(selfintent);
  229. Toast.makeText(SetupActivity.this,"image saved successfully",Toast.LENGTH_SHORT).show();
  230. loadingbar.dismiss();
  231.  
  232. }
  233. else
  234. {
  235. String message = task.getException().getMessage();
  236. Toast.makeText(SetupActivity.this,"Error occurred: "+ message,Toast.LENGTH_SHORT).show();
  237. loadingbar.dismiss();
  238.  
  239. }
  240.  
  241.  
  242. }
  243. });
  244. }
  245.  
  246. }
  247. });
  248. }else
  249. {
  250. Toast.makeText(SetupActivity.this,"image cannot be cropped",Toast.LENGTH_SHORT).show();
  251. loadingbar.dismiss();
  252. }
  253.  
  254. }
  255.  
  256. }
Add Comment
Please, Sign In to add comment