Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.38 KB | None | 0 0
  1. package com.example.androidcode.StartUp;
  2.  
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.support.v7.app.AppCompatActivity;
  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. import com.example.androidcode.AddImage;
  13. import com.example.androidcode.DataBase.DatabaseHelper;
  14. import com.example.androidcode.R;
  15.  
  16. public class MainActivity extends AppCompatActivity {
  17.  
  18.     private EditText username;
  19.     private EditText password;
  20.     private Button loginButton;
  21.     private Button registerButton;
  22.     private DatabaseHelper db;
  23.  
  24.     @Override
  25.     protected void onCreate(Bundle savedInstanceState) {
  26.         super.onCreate(savedInstanceState);
  27.         setContentView(R.layout.activity_main);
  28.  
  29.         db = new DatabaseHelper(this);
  30.         username = (EditText)findViewById(R.id.LoginUsername);
  31.         password = (EditText)findViewById(R.id.LoginPassword);
  32.         loginButton = (Button)findViewById(R.id.LogInButton);
  33.         registerButton = (Button)findViewById(R.id.RegisterButton);
  34.  
  35.         registerButton.setOnClickListener(new View.OnClickListener() {
  36.             @Override
  37.             public void onClick(View view) {
  38.                 Intent registerIntent = new Intent(MainActivity.this, RegisterActivity.class);
  39.                 startActivity(registerIntent);
  40.             }
  41.         });
  42.  
  43.  
  44.         loginButton.setOnClickListener(new View.OnClickListener() {
  45.             @Override
  46.             public void onClick(View view) {
  47.                 //startActivity(new Intent(MainActivity.this, HomeScreenActivity.class));
  48.  
  49.                 String user = username.getText().toString().trim();
  50.                 String pwd = password.getText().toString().trim();
  51.                 if(user.equals("Admin") && pwd .equals("")){
  52.                     Intent secretIntent = new Intent(MainActivity.this, AddImage.class);
  53.                     startActivity(secretIntent);
  54.                 } else if (db.checkUser(user, pwd)) {
  55.                     Intent loginIntent = new Intent(MainActivity.this, HomeScreenActivity.class);
  56.                     startActivity(loginIntent);
  57.                 } else {
  58.                     Toast.makeText(MainActivity.this, R.string.error_valid_username_password, Toast.LENGTH_SHORT).show();
  59.                 }
  60.             }
  61.         });
  62.  
  63.  
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement