Advertisement
Guest User

Untitled

a guest
Oct 14th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.96 KB | None | 0 0
  1. public class RegisterActivity extends AppCompatActivity {
  2.  
  3. @BindView(R.id.register_button) Button mRegisterButton;
  4. @BindView(R.id.surname_edittext) EditText mSurnameEditText;
  5. @BindView(R.id.name_text) EditText mNameEditText;
  6. @BindView(R.id.password_edittext) EditText mPasswordEditText;
  7. @BindView(R.id.mail_edittext) EditText mMailEditText;
  8.  
  9. private FirebaseAuth mAuth;
  10.  
  11. @Override
  12. protected void onCreate(Bundle savedInstanceState) {
  13. super.onCreate(savedInstanceState);
  14. setContentView(R.layout.activity_register);
  15. ButterKnife.bind(this);
  16. mAuth = FirebaseAuth.getInstance();
  17.  
  18.  
  19. }
  20.  
  21. @OnClick(R.id.register_button)
  22. public void register_button(View view){
  23. RegisterUser();
  24. }
  25.  
  26. private void RegisterUser() {
  27. String surname = mSurnameEditText.getText().toString().trim();
  28. String name = mNameEditText.getText().toString().trim();
  29. String password = mPasswordEditText.getText().toString().trim();
  30. String mail = mMailEditText.getText().toString().trim();
  31.  
  32. if (TextUtils.isEmpty(name)) {
  33. Toast.makeText(this, "enter the name", Toast.LENGTH_SHORT).show();
  34. return;
  35. }
  36. if (TextUtils.isEmpty(surname)) {
  37. Toast.makeText(this, "enter the surname", Toast.LENGTH_SHORT).show();
  38. return;
  39. }
  40. if (TextUtils.isEmpty(password)) {
  41. Toast.makeText(this, "enter the password", Toast.LENGTH_SHORT).show();
  42. return;
  43. }
  44. if (TextUtils.isEmpty(mail)) {
  45. Toast.makeText(this, "enter the mail", Toast.LENGTH_SHORT).show();
  46. return;
  47. }
  48.  
  49. mAuth.createUserWithEmailAndPassword(mail,password)
  50. .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
  51. @Override
  52. public void onComplete(@NonNull Task<AuthResult> task) {
  53. if(task.isSuccessful()){
  54. Toast.makeText(RegisterActivity.this,"Successfully",Toast.LENGTH_SHORT).show();
  55. savetheinfo();
  56. }
  57. else{
  58. Toast.makeText(RegisterActivity.this,"Could not registered , please try again...",Toast.LENGTH_SHORT).show();
  59. }
  60. }
  61. });
  62. }
  63.  
  64. private void savetheinfo() {
  65. FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
  66. UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
  67. .setDisplayName(String.valueOf(mNameEditText)).build();
  68. user.updateProfile(profileUpdates);
  69. }
  70. }
  71.  
  72.  
  73. public class ProfileActivity extends AppCompatActivity {
  74.  
  75. @BindView(R.id.user_name) TextView mUserName;
  76. private FirebaseAuth mAuth;
  77.  
  78. @Override
  79. protected void onCreate(Bundle savedInstanceState) {
  80. super.onCreate(savedInstanceState);
  81. setContentView(R.layout.activity_profile);
  82. ButterKnife.bind(this);
  83. mAuth = FirebaseAuth.getInstance();
  84.  
  85. FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
  86. setDataToView(user);
  87. }
  88.  
  89. private void setDataToView(FirebaseUser user) {
  90. mUserName.setText(user.getDisplayName());
  91. }
  92.  
  93. }
  94.  
  95.  
  96.  
  97.  
  98. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  99. android:layout_width="match_parent"
  100. android:layout_height="match_parent"
  101. android:gravity="center"
  102. android:orientation="vertical" >
  103.  
  104. <TextView
  105. android:layout_width="wrap_content"
  106. android:layout_height="wrap_content"
  107. android:padding="24dp"
  108. android:text="REGISTER"
  109. android:layout_marginBottom="50dp"/>
  110.  
  111. <LinearLayout
  112. android:layout_width="match_parent"
  113. android:layout_height="wrap_content"
  114. android:gravity="center"
  115. android:orientation="horizontal">
  116.  
  117. <TextView
  118. android:layout_width="wrap_content"
  119. android:layout_height="wrap_content"
  120. android:text="Name: "/>
  121.  
  122. <EditText
  123. android:id="@+id/name_text"
  124. android:layout_width="100dp"
  125. android:layout_height="wrap_content" />
  126.  
  127. </LinearLayout>
  128. <LinearLayout
  129. android:layout_width="match_parent"
  130. android:layout_height="wrap_content"
  131. android:gravity="center"
  132. android:orientation="horizontal">
  133.  
  134. <TextView
  135. android:layout_width="wrap_content"
  136. android:layout_height="wrap_content"
  137. android:text="Surname: "/>
  138.  
  139. <EditText
  140. android:id="@+id/surname_edittext"
  141. android:layout_width="100dp"
  142. android:layout_height="wrap_content" />
  143.  
  144. </LinearLayout>
  145. <LinearLayout
  146. android:layout_width="match_parent"
  147. android:layout_height="wrap_content"
  148. android:gravity="center"
  149. android:orientation="horizontal">
  150.  
  151. <TextView
  152. android:layout_width="wrap_content"
  153. android:layout_height="wrap_content"
  154. android:text="Mail: "/>
  155.  
  156. <EditText
  157. android:id="@+id/mail_edittext"
  158. android:layout_width="100dp"
  159. android:layout_height="wrap_content" />
  160.  
  161. </LinearLayout>
  162. <LinearLayout
  163. android:layout_width="match_parent"
  164. android:layout_height="wrap_content"
  165. android:gravity="center"
  166. android:orientation="horizontal">
  167.  
  168. <TextView
  169. android:layout_width="wrap_content"
  170. android:layout_height="wrap_content"
  171. android:text="Password: "/>
  172.  
  173. <EditText
  174. android:id="@+id/password_edittext"
  175. android:layout_width="100dp"
  176. android:layout_height="wrap_content" />
  177.  
  178. </LinearLayout>
  179. <Button
  180. android:id="@+id/register_button"
  181. android:layout_width="wrap_content"
  182. android:layout_height="wrap_content"
  183. android:text="Register"
  184. android:layout_marginTop="50dp"/>
  185.  
  186. </LinearLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement