Advertisement
Guest User

Untitled

a guest
Jun 29th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. public class Login extends AppCompatActivity {
  2.  
  3. // LogCat tag
  4. private static final String TAG = Register.class.getSimpleName();
  5.  
  6. private EditText inputUsername, inputPassword;
  7.  
  8. @Override
  9. protected void onCreate(Bundle savedInstanceState) {
  10. super.onCreate(savedInstanceState);
  11. setContentView(R.layout.activity_login);
  12.  
  13.  
  14. inputUsername = (EditText) findViewById(R.id.Username);
  15. inputPassword = (EditText) findViewById(R.id.Password);
  16.  
  17. ImageView btnLogin = (ImageView) findViewById(R.id.ic_lgr_log);
  18.  
  19. TextView btnLinkToRegister = (TextView) findViewById(R.id.btnLinkToRegisterScreen);
  20. TextView btnforgotPassword = (TextView) findViewById(R.id.btnForgotPassword);
  21.  
  22.  
  23. pDialog = new ProgressDialog(this);
  24. pDialog.setCancelable(false);
  25.  
  26. if (btnLinkToRegister != null) {
  27. btnLinkToRegister.setOnClickListener(new View.OnClickListener() {
  28. @Override
  29. public void onClick(View view) {
  30. Intent intent = new Intent(Login.this, Register.class);
  31. startActivity(intent);
  32. finish();
  33. }
  34. });
  35. }
  36.  
  37. btnforgotPassword.setOnClickListener(new View.OnClickListener() {
  38. @Override
  39. public void onClick (View view) {
  40. Intent i = new Intent(Login.this, ForgotPass.class);
  41. startActivity(i);
  42. finish();
  43. }
  44.  
  45. });
  46.  
  47. btnLogin.setOnClickListener(new View.OnClickListener() {
  48.  
  49. public void onClick(View view) {
  50. String username = inputUsername.getText().toString();
  51. String password = inputPassword.getText().toString();
  52.  
  53. // Check for empty data in the form
  54. if ((username.trim().length() == 0 || password.trim().length() == 0)) {
  55. // Prompt user to enter credentials
  56. Toast.makeText(getApplicationContext(),
  57. getString(R.string.err_msg_cred), Toast.LENGTH_LONG)
  58. .show();
  59.  
  60. } else if (username.trim().length() <= 5) {
  61.  
  62. // Minimum
  63. Toast.makeText(getApplicationContext(),
  64. getString(R.string.err_msg_uname), Toast.LENGTH_LONG)
  65. .show();
  66.  
  67. requestFocus(inputUsername);
  68.  
  69. } else if (password.trim().length() <= 5) {
  70. // Minimum
  71. Toast.makeText(getApplicationContext(),
  72. getString(R.string.err_msg_pass), Toast.LENGTH_LONG)
  73. .show();
  74.  
  75. requestFocus(inputPassword);
  76.  
  77. } else {
  78. // Login Procedure
  79. checkLogin(username, password);
  80. }
  81. }
  82.  
  83. });
  84. }
  85.  
  86. private void requestFocus(View view) {
  87. if (view.requestFocus()) {
  88. getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
  89. }
  90. }
  91.  
  92. private void showDialog() {
  93. if (!pDialog.isShowing())
  94. pDialog.show();
  95. }
  96.  
  97. private void hideDialog() {
  98. if (pDialog.isShowing())
  99. pDialog.dismiss();
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement