Advertisement
Guest User

Untitled

a guest
Mar 31st, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. ```java
  2. @OnClick(R.id.sign_in_btn)
  3. public void onSignInButtonClicked(View view){
  4. DisplayUtility.hideKeyboard(getContext(), view);
  5.  
  6. String username = mEmailInputLayout.getEditText().getText().toString();
  7. String password = mPasswordInputLayout.getEditText().getText().toString();
  8.  
  9. final boolean emailIsValid = validateEmail(username);
  10. final boolean passwordIsValid = validatePassword(password);
  11.  
  12. if(emailIsValid && passwordIsValid){
  13. mEmailInputLayout.setError(null);
  14. mPasswordInputLayout.setError(null);
  15.  
  16. disableError(mEmailInputLayout);
  17. disableError(mPasswordInputLayout);
  18. // mEmailInputLayout.setErrorEnabled(false);
  19. // mPasswordInputLayout.setErrorEnabled(false);
  20. doLogin();
  21. return;
  22. } else if(emailIsValid){
  23. mEmailInputLayout.setError(null);
  24.  
  25. disableError(mEmailInputLayout);
  26. // mEmailInputLayout.setErrorEnabled(false);
  27. } else if(passwordIsValid){
  28. mPasswordInputLayout.setError(null);
  29.  
  30. disableError(mPasswordInputLayout);
  31. // mPasswordInputLayout.setErrorEnabled(false);
  32. }
  33.  
  34. if(!emailIsValid){
  35. enableError(mEmailInputLayout);
  36. // mEmailInputLayout.setErrorEnabled(true);
  37.  
  38. mEmailInputLayout.setError("Not a valid email address!");
  39. }
  40.  
  41. if(!passwordIsValid){
  42. enableError(mPasswordInputLayout);
  43. // mPasswordInputLayout.setErrorEnabled(true);
  44.  
  45. mPasswordInputLayout.setError("Not a valid password!");
  46. }
  47. }
  48.  
  49. private void enableError(TextInputLayout textInputLayout){
  50. if (textInputLayout.getChildCount() == 2)
  51. textInputLayout.getChildAt(1).setVisibility(View.VISIBLE);
  52. }
  53.  
  54. private void disableError(TextInputLayout textInputLayout){
  55. if (textInputLayout.getChildCount() == 2)
  56. textInputLayout.getChildAt(1).setVisibility(View.GONE);
  57. }
  58. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement