Advertisement
Guest User

Untitled

a guest
Mar 5th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. public class MainActivity extends AppCompatActivity {
  2.  
  3. EditText username;
  4. EditText password;
  5. TextView attempt_count;
  6. Button login_btn;
  7. int attempts_remaining = 3;
  8.  
  9. @Override
  10. protected void onCreate(Bundle savedInstanceState) {
  11. super.onCreate(savedInstanceState);
  12. setContentView(R.layout.activity_main);
  13.  
  14. username = (EditText) findViewById(R.id.editText_user);
  15. password = (EditText) findViewById(R.id.editText_password);
  16. attempt_count = (TextView) findViewById(R.id.textView_attempts_count);
  17. login_btn = (Button) findViewById(R.id.button);
  18.  
  19.  
  20.  
  21. login_btn.setOnClickListener(new View.OnClickListener() {
  22. @Override
  23. public void onClick(View v) {
  24.  
  25.  
  26. if (username.getText().toString().equals("admin") && password.getText().toString().equals("password")) {
  27. Toast.makeText(getApplicationContext(), "Redirecting ...", Toast.LENGTH_SHORT).show();
  28. Intent website = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.co.uk"));
  29. startActivity(website);
  30.  
  31.  
  32. } else {
  33. Toast.makeText(getApplicationContext(), "Wrong Username or Password", Toast.LENGTH_SHORT).show();
  34.  
  35.  
  36. attempt_count.setVisibility(View.VISIBLE);
  37. attempt_count.setTextColor(Color.RED);
  38. attempts_remaining--;
  39. attempt_count.setText(Integer.toString(attempts_remaining));
  40.  
  41.  
  42. if (attempts_remaining == 0) {
  43.  
  44. Toast.makeText(getApplicationContext(), "Login Failed", Toast.LENGTH_SHORT).show();
  45. Toast.makeText(getApplicationContext(), "Please Wait", Toast.LENGTH_SHORT).show();
  46. login_btn.setEnabled(false);
  47.  
  48.  
  49. }
  50. }
  51.  
  52. }
  53. });
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement