Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Login extends AppCompatActivity {
- // LogCat tag
- private static final String TAG = Register.class.getSimpleName();
- private EditText inputUsername, inputPassword;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_login);
- inputUsername = (EditText) findViewById(R.id.Username);
- inputPassword = (EditText) findViewById(R.id.Password);
- ImageView btnLogin = (ImageView) findViewById(R.id.ic_lgr_log);
- TextView btnLinkToRegister = (TextView) findViewById(R.id.btnLinkToRegisterScreen);
- TextView btnforgotPassword = (TextView) findViewById(R.id.btnForgotPassword);
- pDialog = new ProgressDialog(this);
- pDialog.setCancelable(false);
- if (btnLinkToRegister != null) {
- btnLinkToRegister.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Intent intent = new Intent(Login.this, Register.class);
- startActivity(intent);
- finish();
- }
- });
- }
- btnforgotPassword.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick (View view) {
- Intent i = new Intent(Login.this, ForgotPass.class);
- startActivity(i);
- finish();
- }
- });
- btnLogin.setOnClickListener(new View.OnClickListener() {
- public void onClick(View view) {
- String username = inputUsername.getText().toString();
- String password = inputPassword.getText().toString();
- // Check for empty data in the form
- if ((username.trim().length() == 0 || password.trim().length() == 0)) {
- // Prompt user to enter credentials
- Toast.makeText(getApplicationContext(),
- getString(R.string.err_msg_cred), Toast.LENGTH_LONG)
- .show();
- } else if (username.trim().length() <= 5) {
- // Minimum
- Toast.makeText(getApplicationContext(),
- getString(R.string.err_msg_uname), Toast.LENGTH_LONG)
- .show();
- requestFocus(inputUsername);
- } else if (password.trim().length() <= 5) {
- // Minimum
- Toast.makeText(getApplicationContext(),
- getString(R.string.err_msg_pass), Toast.LENGTH_LONG)
- .show();
- requestFocus(inputPassword);
- } else {
- // Login Procedure
- checkLogin(username, password);
- }
- }
- });
- }
- private void requestFocus(View view) {
- if (view.requestFocus()) {
- getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
- }
- }
- private void showDialog() {
- if (!pDialog.isShowing())
- pDialog.show();
- }
- private void hideDialog() {
- if (pDialog.isShowing())
- pDialog.dismiss();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement