Guest User

Untitled

a guest
Dec 15th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. @Override
  2. protected void onCreate(Bundle savedInstanceState) {
  3. super.onCreate(savedInstanceState);
  4.  
  5. mAuth = FirebaseAuth.getInstance();
  6. btRegistro = (Button) findViewById(R.id.bt_registro);
  7. etUser = (EditText) findViewById(R.id.et_userRegistro);
  8. etEmail = (EditText) findViewById(R.id.et_correoRegistro);
  9. etPass = (EditText) findViewById(R.id.et_passwordRegistro);
  10. //Progreso
  11. mProgress = new ProgressDialog(this);
  12.  
  13. //string
  14. String name = etUser.getText().toString();
  15. String email = etEmail.getText().toString();
  16. String pass = etPass.getText().toString();
  17.  
  18. if (!TextUtils.isEmpty(name) && !TextUtils.isEmpty(email) && !TextUtils.isEmpty(pass)){
  19. //Seteo la barra de progreso
  20. mProgress.setMessage("Registering, please wait...");
  21. mProgress.show();
  22. //Creo el registro para FireBase
  23. mAuth.createUserWithEmailAndPassword(email,pass).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
  24.  
  25. @Override
  26. public void onComplete(@NonNull Task<AuthResult> task) {
  27. mProgress.dismiss(); //quito el Progress dialog
  28. if (task.isSuccessful()){
  29. String user_id = mAuth.getCurrentUser().getUid();
  30. Toast.makeText(Registro.this, "Authentication Complete : " + user_id, Toast.LENGTH_SHORT).show();
  31. limpiarCampos();
  32. }else{
  33. // If sign in fails, display a message to the user.
  34. //Log.w(TAG, "createUserWithEmail:failure", task.getException());
  35. Toast.makeText(Registro.this, "Authentication failed.",
  36. Toast.LENGTH_SHORT).show();
  37. }
  38. }
  39. });
  40. }
  41.  
  42. }//fin del oncreate
  43.  
  44.  
  45. //Metodos Propios
  46. public boolean validarCampos(){
  47. try{
  48. String user = etUser.getText().toString();
  49. String correo = etEmail.getText().toString();
  50. String pass = etPass.getText().toString();
  51. if (user.isEmpty() || correo.isEmpty() || pass.isEmpty()){
  52. Toast.makeText(this, "Tiene campos en blanco", Toast.LENGTH_SHORT).show();
  53. return false;
  54. }else {
  55. return true;
  56. }
  57. }catch (Exception e){
  58. Toast.makeText(this, "Error al capturar los datos " + e.toString(), Toast.LENGTH_SHORT).show();
  59. }
  60. return false;
  61. }
  62.  
  63. public void limpiarCampos(){
  64. etUser.setText("");
  65. etEmail.setText("");
  66. etPass.setText("");
  67. }}
  68.  
  69. <LinearLayout
  70. android:id="@+id/lnlayout"
  71. android:layout_width="match_parent"
  72. android:layout_height="match_parent"
  73. android:layout_centerVertical="true"
  74. android:layout_centerHorizontal="true"
  75. android:orientation="vertical">
  76.  
  77.  
  78. <TextView
  79. android:id="@+id/tv_logo"
  80. style="@style/tv_tituloStyle"
  81. android:layout_margin="50dp"
  82. android:text="@string/tv_logo" />
  83.  
  84. <EditText
  85. android:id="@+id/et_userRegistro"
  86. style="@style/et_style"
  87. android:hint="@string/hint_userRegistro"
  88. android:inputType="textPersonName" />
  89.  
  90. <EditText
  91. android:id="@+id/et_correoRegistro"
  92. style="@style/et_style"
  93. android:hint="@string/et_correoRegistro"
  94. android:inputType="textEmailAddress" />
  95.  
  96. <EditText
  97. android:id="@+id/et_passwordRegistro"
  98. style="@style/et_style"
  99. android:hint="@string/hint_passRegistro"
  100. android:inputType="textPassword" />
  101.  
  102. <Button
  103. android:id="@+id/bt_registro"
  104. style="@style/btn_style"
  105. android:text="@string/bt_registro" />
  106.  
  107.  
  108. <TextView
  109. android:id="@+id/tv_kris"
  110. style="@style/tv_style"
  111. android:text="@string/tv_kris" />
  112.  
  113.  
  114. </LinearLayout>
Add Comment
Please, Sign In to add comment