@Override
  public void onResume() {
    super.onResume();
    SharedPreferences profile = getSharedPreferences(Constants.PROFILE_PREFS, MODE_PRIVATE);
    if (profile.contains(Constants.EMAIL)) {
      mEmailView.setText(profile.getString(Constants.EMAIL, ""));
      if (profile.contains(Constants.INTERNAL_USER_ID)) {
        OWUser user =
            OWUser.objects(getApplicationContext(), OWUser.class)
                .get(profile.getInt(Constants.INTERNAL_USER_ID, 0));
        model_id = user.getId();
        if (user != null) {
          OWUtils.loadProfilePicture(
              getApplicationContext(), user, ((ImageView) findViewById(R.id.user_thumbnail)));
        }
      }
      if (profile.getBoolean(Constants.AUTHENTICATED, false)) {
        setViewsAsAuthenticated();
        return;
      }
    }

    Bundle extras = getIntent().getExtras();
    if (extras != null && extras.containsKey("message")) {
      setViewsAsNotAuthenticatedWithMessage(extras.getString("message"));
    } else if (!profile.contains(Constants.EMAIL)
        && !profile.getBoolean(Constants.AUTHENTICATED, false)) {
      // The user has never provided an email:
      setViewsAsNotAuthenticatedWithMessage(getString(R.string.create_account_prompt));
    }
  }
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
   super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
   if (cameraPhotoLocation != null) {
     OWUtils.handleSetUserAvatarResult(
         requestCode,
         resultCode,
         imageReturnedIntent,
         ((ImageView) this.findViewById(R.id.user_thumbnail)),
         this,
         OWUser.objects(getApplicationContext(), OWUser.class).get(model_id),
         cameraPhotoLocation.getAbsolutePath());
     cameraPhotoLocation = null;
   }
 }
 public void getUserAvatarFromDevice(View v) {
   SharedPreferences profile = getSharedPreferences(Constants.PROFILE_PREFS, MODE_PRIVATE);
   if (profile.getBoolean(Constants.AUTHENTICATED, false)) {
     OWUtils.setUserAvatar(
         this,
         v,
         OWUtils.SELECT_PHOTO,
         OWUtils.TAKE_PHOTO,
         new OWUtils.TakePictureCallback() {
           @Override
           public void gotPotentialPictureLocation(File image) {
             cameraPhotoLocation = image;
           }
         });
   }
 }
  /**
   * Attempts to sign in or register the account specified by the login form. If there are form
   * errors (invalid email, missing fields, etc.), the errors are presented and no actual login
   * attempt is made.
   */
  public void attemptLogin() {
    // Reset errors.
    mEmailView.setError(null);
    mPasswordView.setError(null);

    // Store values at the time of the login attempt.
    mEmail = mEmailView.getText().toString().trim();
    mPassword = mPasswordView.getText().toString();

    boolean cancel = false;
    View focusView = null;

    // Check for a valid password.
    if (TextUtils.isEmpty(mPassword)) {
      mPasswordView.setError(getString(R.string.error_field_required));
      focusView = mPasswordView;
      cancel = true;
    } else if (mPassword.length() < 4) {
      mPasswordView.setError(getString(R.string.error_invalid_password));
      focusView = mPasswordView;
      cancel = true;
    }

    // Check for a valid email address.
    if (TextUtils.isEmpty(mEmail)) {
      mEmailView.setError(getString(R.string.error_field_required));
      focusView = mEmailView;
      cancel = true;
    } else if (!OWUtils.checkEmail(mEmail)) {
      mEmailView.setError(getString(R.string.error_invalid_email));
      focusView = mEmailView;
      cancel = true;
    }

    if (cancel) {
      // There was an error; don't attempt login and focus the first
      // form field with an error.
      focusView.requestFocus();
    } else {
      // Show a progress spinner, and kick off a background task to
      // perform the user login attempt.
      mLoginStatusMessageView.setText(R.string.login_progress_signing_in);
      showProgress(true);
      UserLogin();
    }
  }