SHARE
TWEET

HomeActivity

ThiagoEmanoel Feb 4th, 2016 22 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.example.kamikaze.estudantesfour;
  2.  
  3. import android.app.Activity;
  4. import android.app.Dialog;
  5. import android.content.Intent;
  6. import android.os.Bundle;
  7. import android.view.View;
  8. import android.widget.Button;
  9. import android.widget.EditText;
  10. import android.widget.Toast;
  11.  
  12. public class HomeActivity extends Activity
  13. {
  14.     Button btnSignIn,btnSignUp;
  15.     LoginDataBaseAdapter loginDataBaseAdapter;
  16.    
  17.     @Override
  18.     protected void onCreate(Bundle savedInstanceState)
  19.     {
  20.          super.onCreate(savedInstanceState);
  21.          setContentView(R.layout.main);
  22.          
  23.          // create a instance of SQLite Database
  24.          loginDataBaseAdapter=new LoginDataBaseAdapter(this);
  25.          loginDataBaseAdapter=loginDataBaseAdapter.open();
  26.          
  27.          // Get The Refference Of Buttons
  28.          btnSignIn=(Button)findViewById(R.id.buttonSignIN);
  29.          btnSignUp=(Button)findViewById(R.id.buttonSignUP);
  30.            
  31.         // Set OnClick Listener on SignUp button
  32.         btnSignUp.setOnClickListener(new View.OnClickListener() {
  33.         public void onClick(View v) {
  34.             // TODO Auto-generated method stub
  35.            
  36.             /// Create Intent for SignUpActivity  and Start The Activity
  37.             Intent intentSignUP=new Intent(getApplicationContext(),SignUPActivity.class);
  38.             startActivity(intentSignUP);
  39.             }
  40.         });
  41.     }
  42.     // Methos to handleClick Event of Sign In Button
  43.     public void signIn(View V)
  44.        {
  45.             final Dialog dialog = new Dialog(HomeActivity.this);
  46.             dialog.setContentView(R.layout.login);
  47.             dialog.setTitle("Login");
  48.    
  49.             // get the Refferences of views
  50.             final EditText editTextUserName=(EditText)dialog.findViewById(R.id.editTextUserNameToLogin);
  51.             final EditText editTextPassword=(EditText)dialog.findViewById(R.id.editTextPasswordToLogin);
  52.            
  53.             Button btnSignIn=(Button)dialog.findViewById(R.id.buttonSignIn);
  54.                
  55.             // Set On ClickListener
  56.             btnSignIn.setOnClickListener(new View.OnClickListener() {
  57.                
  58.                 public void onClick(View v) {
  59.                     // get The User name and Password
  60.                     String userName=editTextUserName.getText().toString();
  61.                     String password=editTextPassword.getText().toString();
  62.                    
  63.                     // fetch the Password form database for respective user name
  64.                     String storedPassword=loginDataBaseAdapter.getSinlgeEntry(userName);
  65.                    
  66.                     // check if the Stored password matches with  Password entered by user
  67.                     if(password.equals(storedPassword))
  68.                     {
  69.                         Toast.makeText(HomeActivity.this, "Congrats: Login Successfull", Toast.LENGTH_LONG).show();
  70.                         dialog.dismiss();
  71.                     }
  72.                     else
  73.                     {
  74.                         Toast.makeText(HomeActivity.this, "User Name or Password does not match", Toast.LENGTH_LONG).show();
  75.                     }
  76.                 }
  77.             });
  78.            
  79.             dialog.show();
  80.     }
  81.  
  82.     @Override
  83.     protected void onDestroy() {
  84.         super.onDestroy();
  85.         // Close The Database
  86.         loginDataBaseAdapter.close();
  87.     }
  88. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top