@Override public void onClick(View v) { Intent intent; switch (v.getId()) { case R.id.btnSignup: intent = new Intent(this, SignupActivity.class); startActivity(intent); break; case R.id.btnLogin: usernametxt = etUsername.getText().toString(); passwordtxt = etPassword.getText().toString(); if (TextUtils.isEmpty(usernametxt) || TextUtils.isEmpty(passwordtxt)) { Toast.makeText(this, "Please insert all fields", Toast.LENGTH_SHORT).show(); return; } UserSession.getInstance(this).setUsername(usernametxt); UserSession.getInstance(this).setPassword(passwordtxt); if (checkBox.isChecked()) { UserSession.getInstance(this).setRememberme(true); } else { // UserSession.getInstance(this).clearSession(); } login(usernametxt, passwordtxt); break; case R.id.tvChangePassword: intent = new Intent(this, ChangePasswordActivity.class); startActivity(intent); break; default: break; } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); getActionBar().setTitle("Login"); btnSignup = (Button) findViewById(R.id.btnSignup); btnSignup.setOnClickListener(this); btnLogin = (Button) findViewById(R.id.btnLogin); btnLogin.setOnClickListener(this); etUsername = (EditText) findViewById(R.id.etUsername); etPassword = (EditText) findViewById(R.id.etPassword); checkBox = (CheckBox) findViewById(R.id.cbRememberMe); tvChangePassword = (TextView) findViewById(R.id.tvChangePassword); tvChangePassword.setOnClickListener(this); isRememberMe = UserSession.getInstance(this).isRememberme(); if (isRememberMe) { etUsername.setText(UserSession.getInstance(this).getUsername()); etPassword.setText(UserSession.getInstance(this).getPassword()); checkBox.setChecked(true); Intent intent; if (UserSession.getInstance(this).isAdmin()) { // intent = new Intent(LoginActivity.this,HomeBaseActivity.class); // Toast.makeText(LoginActivity.this, "Admin dashboard comming soon ...", // Toast.LENGTH_SHORT).show(); intent = new Intent(LoginActivity.this, AdminDashboardActivity.class); startActivity(intent); } else { intent = new Intent(LoginActivity.this, StudentDashboardActivity.class); startActivity(intent); } finish(); // login(UserSession.getInstance(this).getUsername(), // UserSession.getInstance(this).getPassword()); } checkBox.setOnCheckedChangeListener( new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton arg0, boolean arg1) {} }); }