Guest User

Untitled

a guest
Oct 2nd, 2017
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. package bg.ittalents.lesson35;
  2.  
  3. import android.content.Intent;
  4. import android.support.v7.app.AppCompatActivity;
  5. import android.os.Bundle;
  6. import android.view.View;
  7. import android.widget.Button;
  8. import android.widget.CheckBox;
  9. import android.widget.EditText;
  10. import android.widget.Toast;
  11.  
  12. import java.util.ArrayList;
  13.  
  14. import bg.ittalents.lesson35.model.User;
  15.  
  16. public class Main extends AppCompatActivity {
  17.  
  18. private static ArrayList<User> users = new ArrayList<>();
  19.  
  20. static {
  21. users.add(new User("Rado","123", false));
  22.  
  23. users.add(new User("Didi","123", true));
  24.  
  25. users.add(new User("Niki","123" , false));
  26. }
  27.  
  28. private EditText userName;
  29. private EditText pass;
  30. private CheckBox isAdminBox;
  31. private Button buton;
  32. private User userLogged;
  33.  
  34. @Override
  35. protected void onCreate(Bundle savedInstanceState) {
  36. super.onCreate(savedInstanceState);
  37. setContentView(R.layout.activity_main);
  38.  
  39. userName = (EditText)findViewById(R.id.user_name);
  40. pass = (EditText)findViewById(R.id.pass);
  41. isAdminBox = (CheckBox)findViewById(R.id.chekche);
  42. buton = (Button)findViewById(R.id.login_button);
  43.  
  44. buton.setOnClickListener(new View.OnClickListener() {
  45. @Override
  46. public void onClick(View view) {
  47. String nameText = userName.getText().toString();
  48.  
  49. String passText = pass.getText().toString();
  50.  
  51. boolean isCheck = isAdminBox.isChecked();
  52.  
  53.  
  54. for (User userche : users){
  55. if(userche.getName().equals(nameText)
  56. && userche.getPass().equals(passText)
  57. && (userche.getIsAdmin() == isCheck)){
  58. userLogged = userche;
  59. break;
  60. }
  61. }
  62.  
  63. if(userLogged != null){
  64. Toast.makeText(Main.this, "Zdrasti " + userLogged.getName(), Toast.LENGTH_SHORT).show();
  65. Intent intent = new Intent(Main.this, Exam.class);
  66. startActivity(intent);
  67. finish();
  68. }else{
  69. Toast.makeText(Main.this, "Gledai si rabotata ! " + nameText, Toast.LENGTH_SHORT).show();
  70. }
  71.  
  72. userLogged = null;
  73. }
  74. });
  75.  
  76. }
  77. }
Add Comment
Please, Sign In to add comment