Advertisement
Guest User

Untitled

a guest
Nov 28th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.71 KB | None | 0 0
  1. package com.parse.starter;
  2.  
  3. import android.content.Intent;
  4. import android.os.Bundle;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.util.Log;
  7. import android.view.View;
  8. import android.widget.Button;
  9. import android.widget.EditText;
  10. import android.widget.TextView;
  11. import android.widget.Toast;
  12.  
  13. import com.parse.LogInCallback;
  14. import com.parse.Parse;
  15. import com.parse.ParseException;
  16. import com.parse.ParseObject;
  17. import com.parse.ParseUser;
  18. import com.parse.SaveCallback;
  19.  
  20. import java.util.jar.Attributes;
  21.  
  22. public class LoginActivity extends AppCompatActivity {
  23.     @Override
  24.     protected void onCreate(Bundle savedInstanceState) {
  25.         super.onCreate(savedInstanceState);
  26.         setContentView(R.layout.activity_login);
  27.  
  28.         final EditText UserName = (EditText) findViewById(R.id.UserName);
  29.         final EditText Password = (EditText) findViewById(R.id.Password);
  30.         final Button Login = (Button) findViewById(R.id.Login);
  31.         final TextView RegisterHere = (TextView) findViewById(R.id.tvRegister);
  32.         final String userNameTxt = UserName.getText().toString();
  33.         final String passwordTxt = Password.getText().toString();
  34.  
  35.  
  36.         Login.setOnClickListener(new View.OnClickListener() {
  37.             @Override
  38.             public void onClick(View view) {
  39.  
  40.  
  41.                 boolean Validation_error = false;
  42.                 StringBuilder ValidationErrorMessage = new StringBuilder("Error");
  43.  
  44.                 if (isEmpty(UserName)) {
  45.                     Validation_error = true;
  46.                     ValidationErrorMessage.append("User Name not Entered");
  47.                 }
  48.  
  49.                 if (isEmpty(Password)) {
  50.                     Validation_error = true;
  51.                     ValidationErrorMessage.append("Password/s not entered ");
  52.                 }
  53.  
  54.                 if (Validation_error) {
  55.                     Toast.makeText(LoginActivity.this, ValidationErrorMessage.toString(), Toast.LENGTH_LONG)
  56.                             .show();
  57.                     return;
  58.                 }
  59.  
  60.                 ParseUser.logInInBackground(userNameTxt,passwordTxt, new LogInCallback() {
  61.                     public void done(ParseUser user, ParseException e) {
  62.                         if (user != null) {
  63.                             Toast.makeText(LoginActivity.this,userNameTxt, Toast.LENGTH_LONG).show();
  64.                             Toast.makeText(LoginActivity.this,"User Logged In", Toast.LENGTH_LONG)
  65.                                     .show();
  66.                             Intent UserIntent = new Intent(LoginActivity.this, UserActivity.class);
  67.                             LoginActivity.this.startActivity(UserIntent);
  68.                         } else {
  69.                             Toast.makeText(LoginActivity.this,userNameTxt, Toast.LENGTH_LONG).show();
  70.                             Toast.makeText(LoginActivity.this,passwordTxt, Toast.LENGTH_LONG).show();
  71.                             Toast.makeText(LoginActivity.this, "User Not in database", Toast.LENGTH_LONG)
  72.                                     .show();
  73.                         }
  74.                     }
  75.                 });
  76.             }
  77.         });
  78.  
  79.         RegisterHere.setOnClickListener(new View.OnClickListener() {
  80.             @Override
  81.             public void onClick(View view) {
  82.                 Intent registerIntent = new Intent(LoginActivity.this, RegisterActivity.class);
  83.                 LoginActivity.this.startActivity(registerIntent);
  84.             }
  85.         });
  86.     }
  87.  
  88.         private boolean isEmpty(EditText etText) {
  89.             if (etText.getText().toString().trim().length() > 0) {
  90.                 return false;
  91.             } else {
  92.                 return true;
  93.             }
  94.         }
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement