Advertisement
Guest User

Untitled

a guest
Apr 7th, 2017
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | None | 0 0
  1. package com.safariagaming.flix;
  2.  
  3. import android.app.ProgressDialog;
  4. import android.content.Intent;
  5. import android.support.annotation.NonNull;
  6. import android.support.v7.app.AppCompatActivity;
  7. import android.os.Bundle;
  8. import android.text.TextUtils;
  9. import android.util.Log;
  10. import android.view.View;
  11. import android.widget.Button;
  12. import android.widget.EditText;
  13. import android.widget.TextView;
  14. import android.widget.Toast;
  15. import com.google.android.gms.tasks.OnCompleteListener;
  16. import com.google.android.gms.tasks.Task;
  17. import com.google.firebase.auth.AuthResult;
  18. import com.google.firebase.auth.FirebaseAuth;
  19.  
  20. import static android.R.attr.password;
  21.  
  22. public class LoginScreen extends AppCompatActivity implements View.OnClickListener {
  23.  
  24. public void openSignUpScreen(View view) {
  25.  
  26. Intent i = new Intent(this, SignUpScreen.class /*we use .class to say that it is a class*/); //The intent is stored in i
  27. startActivity(i);
  28.  
  29. }
  30.  
  31. public void openForgotScreen(View view) {
  32.  
  33. Intent i = new Intent(this, ForgotScreen.class /*we use .class to say that it is a class*/); //The intent is stored in i
  34. startActivity(i);
  35.  
  36. }
  37.  
  38.  
  39. //defining views
  40. private Button buttonSignIn;
  41. private EditText editTextEmail;
  42. private EditText editTextPassword;
  43.  
  44. //firebase auth object
  45. private FirebaseAuth firebaseAuth;
  46.  
  47. //progress dialog
  48. private ProgressDialog progressDialog;
  49.  
  50.  
  51. @Override
  52. protected void onCreate(Bundle savedInstanceState) {
  53. super.onCreate(savedInstanceState);
  54. setContentView(R.layout.activity_login_screen);
  55.  
  56. //getting firebase auth object
  57. firebaseAuth = FirebaseAuth.getInstance();
  58.  
  59. //if the objects getcurrentuser method is not null
  60. //means user is already logged in
  61. /* if(firebaseAuth.getCurrentUser() != null){
  62. //close this activity
  63. finish();
  64. //opening profile activity
  65. startActivity(new Intent(getApplicationContext(), screen_after_logged_in.class));
  66. }
  67. */
  68.  
  69. //initializing views
  70. editTextEmail = (EditText) findViewById(R.id.ET_USERNAME_log);
  71. editTextPassword = (EditText) findViewById(R.id.ET_PASSWORD_log);
  72. buttonSignIn = (Button) findViewById(R.id.btn_LOGIN_log);
  73.  
  74. progressDialog = new ProgressDialog(this);
  75.  
  76. //attaching click listener
  77. buttonSignIn.setOnClickListener(this);
  78. }
  79.  
  80. //method for user login
  81. private void userLogin(){
  82. String email = editTextEmail.getText().toString().trim();
  83. String password = editTextPassword.getText().toString().trim();
  84.  
  85.  
  86. //checking if email and passwords are empty
  87. if(TextUtils.isEmpty(email)){
  88. Toast.makeText(this,"Please enter email",Toast.LENGTH_LONG).show();
  89. return;
  90. }
  91.  
  92. if(TextUtils.isEmpty(password)){
  93. Toast.makeText(this,"Please enter password",Toast.LENGTH_LONG).show();
  94. return;
  95. }
  96.  
  97. //if the email and password are not empty
  98. //displaying a progress dialog
  99.  
  100. progressDialog.setMessage("Loging in");
  101. progressDialog.show();
  102.  
  103. //logging in the user
  104. firebaseAuth.signInWithEmailAndPassword(email, password)
  105. .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
  106. @Override
  107. public void onComplete(@NonNull Task<AuthResult> task) {
  108. progressDialog.dismiss();
  109. //if the task is successfull
  110. if(task.isSuccessful()){
  111. //start the profile activity
  112. finish();
  113. startActivity(new Intent(getApplicationContext(), screen_after_logged_in.class));
  114. }
  115. }
  116. });
  117.  
  118. }
  119.  
  120. @Override
  121. public void onClick(View view) {
  122. if(view == buttonSignIn){
  123. userLogin();
  124. }
  125.  
  126. }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement