Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MainActivity extends AppCompatActivity {
- EditText username;
- EditText password;
- TextView attempt_count;
- Button login_btn;
- int attempts_remaining = 3;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- username = (EditText) findViewById(R.id.editText_user);
- password = (EditText) findViewById(R.id.editText_password);
- attempt_count = (TextView) findViewById(R.id.textView_attempts_count);
- login_btn = (Button) findViewById(R.id.button);
- login_btn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if (username.getText().toString().equals("admin") && password.getText().toString().equals("password")) {
- Toast.makeText(getApplicationContext(), "Redirecting ...", Toast.LENGTH_SHORT).show();
- Intent website = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.co.uk"));
- startActivity(website);
- } else {
- Toast.makeText(getApplicationContext(), "Wrong Username or Password", Toast.LENGTH_SHORT).show();
- attempt_count.setVisibility(View.VISIBLE);
- attempt_count.setTextColor(Color.RED);
- attempts_remaining--;
- attempt_count.setText(Integer.toString(attempts_remaining));
- if (attempts_remaining == 0) {
- Toast.makeText(getApplicationContext(), "Login Failed", Toast.LENGTH_SHORT).show();
- Toast.makeText(getApplicationContext(), "Please Wait", Toast.LENGTH_SHORT).show();
- login_btn.setEnabled(false);
- }
- }
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement