Advertisement
yonijoni01

register

Feb 22nd, 2018
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.70 KB | None | 0 0
  1. package com.example.student19.joniapp;
  2.  
  3. import android.support.annotation.NonNull;
  4. import android.support.v7.app.AppCompatActivity;
  5. import android.os.Bundle;
  6. import android.util.Log;
  7. import android.widget.EditText;
  8. import android.widget.Toast;
  9.  
  10. import com.google.android.gms.tasks.OnCompleteListener;
  11. import com.google.android.gms.tasks.Task;
  12. import com.google.firebase.auth.AuthResult;
  13. import com.google.firebase.auth.FirebaseAuth;
  14. import com.google.firebase.auth.FirebaseUser;
  15.  
  16.  
  17.  
  18. public class MainActivity extends AppCompatActivity {
  19.  
  20. private static String TAG = "MainActivity";
  21. private FirebaseAuth mAuth;
  22. private FirebaseAuth.AuthStateListener mAuthListener;
  23. private EditText editEmail,editPass;
  24.  
  25. @Override
  26. protected void onCreate(Bundle savedInstanceState) {
  27. super.onCreate(savedInstanceState);
  28. setContentView(R.layout.activity_main);
  29. mAuth = FirebaseAuth.getInstance();
  30. mAuthListener = new FirebaseAuth.AuthStateListener() {
  31. @Override
  32. public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
  33. FirebaseUser user = firebaseAuth.getCurrentUser();
  34. if (user != null) {
  35. // User is signed in
  36. Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
  37. } else {
  38. // User is signed out
  39. Log.d(TAG, "onAuthStateChanged:signed_out");
  40. }
  41. // ...
  42. }
  43. };
  44.  
  45.  
  46. editEmail = (EditText)findViewById(R.id.Email);
  47. editPass = (EditText)findViewById(R.id.Pass);
  48.  
  49. }
  50. @Override
  51. public void onStart() {
  52. super.onStart();
  53. mAuth.addAuthStateListener(mAuthListener);
  54. }
  55. @Override
  56. public void onStop() {
  57. super.onStop();
  58. if (mAuthListener != null) {
  59. mAuth.removeAuthStateListener(mAuthListener);
  60. }
  61. }
  62. public void OnClick(){
  63. mAuth.createUserWithEmailAndPassword(editEmail.getText().toString(), editPass.getText().toString())
  64. .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
  65. @Override
  66. public void onComplete(@NonNull Task<AuthResult> task) {
  67. Log.d(TAG, "createUserWithEmail:onComplete:" + task.isSuccessful());
  68.  
  69. // If sign in fails, display a message to the user. If sign in succeeds
  70. // the auth state listener will be notified and logic to handle the
  71. // signed in user can be handled in the listener.
  72. if (!task.isSuccessful()) {
  73. Toast.makeText(MainActivity.this, "Authentication failed.",
  74. Toast.LENGTH_SHORT).show();
  75. }
  76.  
  77. // ...
  78. }
  79. });
  80.  
  81. }
  82. }
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109. <?xml version="1.0" encoding="utf-8"?>
  110. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  111. xmlns:tools="http://schemas.android.com/tools"
  112. android:id="@+id/activity_main"
  113. android:layout_width="match_parent"
  114. android:layout_height="match_parent"
  115. android:paddingBottom="@dimen/activity_vertical_margin"
  116. android:paddingLeft="@dimen/activity_horizontal_margin"
  117. android:paddingRight="@dimen/activity_horizontal_margin"
  118. android:paddingTop="@dimen/activity_vertical_margin"
  119. tools:context="com.example.student19.joniapp.MainActivity">
  120.  
  121. <EditText
  122. android:layout_width="wrap_content"
  123. android:layout_height="wrap_content"
  124. android:inputType="textPersonName"
  125. android:text="first Name"
  126. android:ems="10"
  127. android:layout_marginLeft="51dp"
  128. android:layout_marginStart="51dp"
  129. android:layout_marginTop="70dp"
  130. android:id="@+id/editText"
  131. android:layout_alignParentTop="true"
  132. android:layout_alignParentLeft="true"
  133. android:layout_alignParentStart="true" />
  134.  
  135. <EditText
  136. android:layout_width="wrap_content"
  137. android:layout_height="wrap_content"
  138. android:inputType="textPersonName"
  139. android:text="Last Name"
  140. android:ems="10"
  141. android:id="@+id/editText3"
  142. android:layout_marginTop="16dp"
  143. android:layout_below="@+id/editText"
  144. android:layout_alignLeft="@+id/editText"
  145. android:layout_alignStart="@+id/editText" />
  146.  
  147. <EditText
  148. android:layout_width="wrap_content"
  149. android:layout_height="wrap_content"
  150. android:inputType="textPassword"
  151. android:ems="10"
  152. android:id="@+id/Pass"
  153. android:layout_marginTop="16dp"
  154. android:layout_below="@+id/editText3"
  155. android:layout_alignLeft="@+id/editText3"
  156. android:layout_alignStart="@+id/editText3"
  157. android:text="password" />
  158.  
  159. <EditText
  160. android:layout_width="wrap_content"
  161. android:layout_height="wrap_content"
  162. android:inputType="textEmailAddress"
  163. android:ems="10"
  164. android:layout_below="@+id/Pass"
  165. android:layout_alignRight="@+id/Pass"
  166. android:layout_alignEnd="@+id/Pass"
  167. android:layout_marginTop="13dp"
  168. android:id="@+id/Email"
  169. android:text="E-Mail" />
  170.  
  171. <Button
  172. android:text="Registar"
  173. android:onClick="OnClick"
  174. android:layout_width="wrap_content"
  175. android:layout_height="wrap_content"
  176. android:layout_below="@+id/Email"
  177. android:layout_centerHorizontal="true"
  178. android:layout_marginTop="38dp"
  179. android:id="@+id/button2" />
  180.  
  181. </RelativeLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement