Facebook
From Commodious Matamata, 6 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 298
  1. package mateuszszufladowicz.pl;
  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.EditText;
  9. import android.widget.TextView;
  10.  
  11. public class login extends AppCompatActivity {
  12.     private Button Register;
  13.     private EditText Name;
  14.     private EditText Password;
  15.     private TextView Info;
  16.     private Button  Login;
  17.     private int counter = 5;
  18.  
  19.     @Override
  20.     protected void onCreate(Bundle savedInstanceState) {
  21.         super.onCreate(savedInstanceState);
  22.         setContentView(R.layout.activity_login);
  23.        Name = (EditText)findViewById(R.id.etName);
  24.        Password = (EditText)findViewById(R.id.etPassword);
  25.        Info = (TextView)findViewById(R.id.tvinfo);
  26.        Login = (Button)findViewById(R.id.btnLogin);
  27.        Register = (Button)findViewById(R.id.btnRegister);
  28.  
  29.        Register.setOnClickListener(new View.OnClickListener() {
  30.                                        @Override
  31.                                        public void onClick(View view) {
  32.                                            Intent intent = new Intent(login.this, register.class);
  33.                                            startActivity(intent);
  34.                                        }
  35.                                        });
  36.  
  37.  
  38.        Info.setText("Próby logowania: 5");
  39.  
  40.        Login.setOnClickListener(new View.OnClickListener(){
  41.            @Override
  42.            public void onClick(View view) {
  43.               validate(Name.getText().toString(), Password.getText().toString());
  44.            }
  45.            });
  46.     }
  47.     private void validate(String userName, String userPassword){
  48.         if((userName == "Admin") && (userPassword == "1234"))
  49.         {
  50.             Intent intent = new Intent(this, logged.class);
  51.             startActivity(intent);
  52.         }else {
  53.            counter--;
  54.            Info.setText("Próby logowania: "+ String.valueOf(counter));
  55.         if(counter == 0){
  56.             Login.setEnabled(false);
  57.         }
  58.         }
  59.  
  60.     }
  61. }