Advertisement
Guest User

Untitled

a guest
Sep 21st, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. public class UserLoginTask extends AsyncTask<Void, Void, Boolean> {
  2.  
  3. private final String mUsername;
  4. private final String mPassword;
  5.  
  6. UserLoginTask(String username, String password) {
  7. mUsername = username;
  8. mPassword = password;
  9. }
  10.  
  11. @Override
  12. protected Boolean doInBackground(Void... params) {
  13.  
  14. try { // Simulate network access.
  15. Thread.sleep(2000);
  16. } catch (InterruptedException e) {
  17. return false;
  18. }
  19.  
  20. for (String credential : DUMMY_CREDENTIALS) {
  21. String[] pieces = credential.split(":");
  22. if (pieces[0].equals(mUsername)) {
  23. // Account exists, return true if the password matches.
  24. return pieces[1].equals(mPassword);
  25. }
  26. }
  27.  
  28. return true;
  29. }
  30.  
  31. @Override
  32. protected void onPostExecute(final Boolean success) {
  33. mAuthTask = null;
  34. showProgress(false);
  35.  
  36. if (success) {
  37. //finish();
  38. Intent mainpageIntent = new Intent(LoginActivity.this, NavigationActivity.class);
  39. LoginActivity.this.startActivity(mainpageIntent);
  40. } else {
  41. mPasswordView.setError(getString(R.string.error_incorrect_password));
  42. mPasswordView.requestFocus();
  43. }
  44. }
  45.  
  46. @Override
  47. protected void onCancelled() {
  48. mAuthTask = null;
  49. showProgress(false);
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement