Example usage for android.accounts AccountManager KEY_ACCOUNT_NAME

List of usage examples for android.accounts AccountManager KEY_ACCOUNT_NAME

Introduction

In this page you can find the example usage for android.accounts AccountManager KEY_ACCOUNT_NAME.

Prototype

String KEY_ACCOUNT_NAME

To view the source code for android.accounts AccountManager KEY_ACCOUNT_NAME.

Click Source Link

Document

Bundle key used for the String account name in results from methods which return information about a particular account.

Usage

From source file:mobile.tiis.appv2.LoginActivity.java

/**
 * This method will take the url built to use the webservice
 * and will try to parse JSON from the webservice stream to get
 * the user and password if they are correct or not. In case correct, fills
 * the Android Account Manager./*from  w w  w . j  a  va  2 s.  c om*/
 *
 * <p>This method will throw a Toast message when user and password
 * are not valid
 *
 */

protected void startWebService(final CharSequence loginURL, final String username, final String password) {
    client.setBasicAuth(username, password, true);

    //new handler in case of login error in the thread
    handler = new Handler();

    Thread thread = new Thread(new Runnable() {
        public void run() {
            try {
                int balanceCounter = 0;
                DefaultHttpClient httpClient = new DefaultHttpClient();
                HttpGet httpGet = new HttpGet(loginURL.toString());
                Utils.writeNetworkLogFileOnSD(
                        Utils.returnDeviceIdAndTimestamp(getApplicationContext()) + loginURL.toString());
                httpGet.setHeader("Authorization", "Basic "
                        + Base64.encodeToString((username + ":" + password).getBytes(), Base64.NO_WRAP));
                HttpResponse httpResponse = httpClient.execute(httpGet);
                InputStream inputStream = httpResponse.getEntity().getContent();
                Log.d("", loginURL.toString());

                ByteArrayInputStream bais = Utils.getMultiReadInputStream(inputStream);
                Utils.writeNetworkLogFileOnSD(Utils.returnDeviceIdAndTimestamp(getApplicationContext())
                        + Utils.getStringFromInputStreamAndLeaveStreamOpen(bais));
                bais.reset();
                JsonFactory factory = new JsonFactory();
                JsonParser jsonParser = factory.createJsonParser(bais);
                JsonToken token = jsonParser.nextToken();

                if (token == JsonToken.START_OBJECT) {
                    balanceCounter++;
                    boolean idNextToHfId = false;
                    while (!(balanceCounter == 0)) {
                        token = jsonParser.nextToken();

                        if (token == JsonToken.START_OBJECT) {
                            balanceCounter++;
                        } else if (token == JsonToken.END_OBJECT) {
                            balanceCounter--;
                        } else if (token == JsonToken.FIELD_NAME) {
                            String object = jsonParser.getCurrentName();
                            switch (object) {
                            case "HealthFacilityId":
                                token = jsonParser.nextToken();
                                app.setLoggedInUserHealthFacilityId(jsonParser.getText());
                                Log.d("", "healthFacilityId is: " + jsonParser.getText());
                                idNextToHfId = true;
                                break;
                            case "Firstname":
                                token = jsonParser.nextToken();
                                app.setLoggedInFirstname(jsonParser.getText());
                                Log.d("", "firstname is: " + jsonParser.getText());
                                break;
                            case "Lastname":
                                token = jsonParser.nextToken();
                                app.setLoggedInLastname(jsonParser.getText());
                                Log.d("", "lastname is: " + jsonParser.getText());
                                break;
                            case "Username":
                                token = jsonParser.nextToken();
                                app.setLoggedInUsername(jsonParser.getText());
                                Log.d("", "username is: " + jsonParser.getText());
                                break;
                            case "Lastlogin":
                                token = jsonParser.nextToken();
                                Log.d("", "lastlogin is: " + jsonParser.getText());
                                break;
                            case "Id":
                                if (idNextToHfId) {
                                    token = jsonParser.nextToken();
                                    app.setLoggedInUserId(jsonParser.getText());
                                    Log.d("", "Id is: " + jsonParser.getText());
                                }
                                break;
                            default:
                                break;
                            }
                        }
                    }

                    Account account = new Account(username, ACCOUNT_TYPE);
                    AccountManager accountManager = AccountManager.get(LoginActivity.this);
                    //                        boolean accountCreated = accountManager.addAccountExplicitly(account, LoginActivity.this.password, null);
                    boolean accountCreated = accountManager.addAccountExplicitly(account, password, null);

                    Bundle extras = LoginActivity.this.getIntent().getExtras();
                    if (extras != null) {
                        if (accountCreated) { //Pass the new account back to the account manager
                            AccountAuthenticatorResponse response = extras
                                    .getParcelable(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE);
                            Bundle res = new Bundle();
                            res.putString(AccountManager.KEY_ACCOUNT_NAME, username);
                            res.putString(AccountManager.KEY_ACCOUNT_TYPE, ACCOUNT_TYPE);
                            res.putString(AccountManager.KEY_PASSWORD, password);
                            response.onResult(res);
                        }
                    }

                    SharedPreferences prefs = PreferenceManager
                            .getDefaultSharedPreferences(getApplicationContext());
                    SharedPreferences.Editor editor = prefs.edit();
                    editor.putBoolean("secondSyncNeeded", true);
                    editor.commit();

                    ContentValues values = new ContentValues();
                    values.put(SQLHandler.SyncColumns.UPDATED, 1);
                    values.put(SQLHandler.UserColumns.FIRSTNAME, app.getLOGGED_IN_FIRSTNAME());
                    values.put(SQLHandler.UserColumns.LASTNAME, app.getLOGGED_IN_LASTNAME());
                    values.put(SQLHandler.UserColumns.HEALTH_FACILITY_ID, app.getLOGGED_IN_USER_HF_ID());
                    values.put(SQLHandler.UserColumns.ID, app.getLOGGED_IN_USER_ID());
                    values.put(SQLHandler.UserColumns.USERNAME, app.getLOGGED_IN_USERNAME());
                    values.put(SQLHandler.UserColumns.PASSWORD, password);
                    databaseHandler.addUser(values);

                    Log.d(TAG, "initiating offline for " + username + " password = " + password);
                    app.initializeOffline(username, password);

                    Intent intent;
                    if (prefs.getBoolean("synchronization_needed", true)) {
                        Log.d("supportLog", "call the loggin second time before the account was found");
                        intent = new Intent(LoginActivity.this, LotSettingsActivity.class);
                    } else {
                        Log.d("supportLog", "call the loggin second time before the account was found");
                        intent = new Intent(LoginActivity.this, LotSettingsActivity.class);
                        evaluateIfFirstLogin(app.getLOGGED_IN_USER_ID());
                    }
                    app.setUsername(username);

                    startActivity(intent);
                }
                //if login failed show error
                else {
                    handler.post(new Runnable() {
                        public void run() {
                            progressDialog.show();
                            progressDialog.dismiss();
                            toastMessage("Login failed.\nPlease check your details!");
                            loginButton.setEnabled(true);
                        }
                    });
                }
            } catch (Exception e) {
                handler.post(new Runnable() {
                    public void run() {
                        progressDialog.show();
                        progressDialog.dismiss();
                        toastMessage("Login failed Login failed.\n"
                                + "Please check your details or your web connectivity");
                        loginButton.setEnabled(true);

                    }
                });
                e.printStackTrace();
            }
        }
    });
    thread.start();

}

From source file:com.razza.apps.iosched.ui.BaseActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // Handle the select {@code startActivityForResult} from
    // {@code enforceActiveGoogleAccount()} when a Google Account wasn't present on the device.
    if (requestCode == SELECT_GOOGLE_ACCOUNT_RESULT) {
        if (resultCode == RESULT_OK) {
            // Set selected GoogleAccount as active.
            String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
            AccountUtils.setActiveAccount(this, accountName);
            onAuthSuccess(accountName, true);
        } else {//from w  w w . j a va  2 s. c  o  m
            LogUtils.LOGW(TAG, "A Google Account is required to use this application.");
            // This application requires a Google Account to be selected.
            finish();
        }
        return;
    }

    if (mLoginAndAuthHelper == null || !mLoginAndAuthHelper.onActivityResult(requestCode, resultCode, data)) {
        super.onActivityResult(requestCode, resultCode, data);
    }
}

From source file:com.google.samples.apps.iosched.ui.BaseActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // Handle the select {@code startActivityForResult} from
    // {@code enforceActiveGoogleAccount()} when a Google Account wasn't present on the device.
    if (requestCode == SELECT_GOOGLE_ACCOUNT_RESULT) {
        if (resultCode == RESULT_OK) {
            // Set selected GoogleAccount as active.
            String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
            AccountUtils.setActiveAccount(this, accountName);
            onAuthSuccess(accountName, true);
        } else {//from   ww  w  . ja va2s. co m
            LOGW(TAG, "A Google Account is required to use this application.");
            // This application requires a Google Account to be selected.
            finish();
        }
        return;
    }

    if (mLoginAndAuthHelper == null || !mLoginAndAuthHelper.onActivityResult(requestCode, resultCode, data)) {
        super.onActivityResult(requestCode, resultCode, data);
    }
}

From source file:mobisocial.musubi.ui.fragments.AccountLinkDialog.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (data == null) {
        return;/*from   w w w.java2s . com*/
    }
    switch (requestCode) {
    case REQUEST_GOOGLE_ACCOUNT:
        if (resultCode == Activity.RESULT_OK) {
            String account = data.getStringExtra(EXTRA_ACCOUNT);
            tryGoogleAccount(mActivity, account);
        }
        break;
    case REQUEST_GOOGLE_AUTHENTICATE:
        //this doesnt really seem to be called because of the account manager having a
        //weird api
        if (resultCode == Activity.RESULT_OK) {
            String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
            tryGoogleAccount(mActivity, accountName);
        }
        break;
    case REQUEST_FACEBOOK:
        Log.d(TAG, "Authorizing Facebook callback");
        Facebook facebook = getFacebookInstance(mActivity);
        facebook.authorizeCallback(requestCode, resultCode, data);
        break;
    case REQUEST_PHONE_NUMBER:
        if (resultCode == Activity.RESULT_OK) {
            String phoneNumber = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
            phoneNumber = validatePhoneNumber(phoneNumber);
            setupPhoneAccount(phoneNumber);
        }
        break;
    }
}

From source file:com.owncloud.android.authentication.AuthenticatorActivity.java

/**
 * Sets the proper response to get that the Account Authenticator that
 * started this activity saves a new authorization token for mAccount.
 *//*  w  ww.  j  a  va 2s  .  c o m*/
private boolean updateToken() {
    Bundle response = new Bundle();
    response.putString(AccountManager.KEY_ACCOUNT_NAME, mAccount.name);
    response.putString(AccountManager.KEY_ACCOUNT_TYPE, mAccount.type);

    if (AccountAuthenticator.AUTH_TOKEN_TYPE_ACCESS_TOKEN.equals(mAuthTokenType)) {
        response.putString(AccountManager.KEY_AUTHTOKEN, mAuthToken);
        // the next line is necessary; by now, notifications are calling
        // directly to the AuthenticatorActivity to update, without
        // AccountManager intervention
        mAccountMgr.setAuthToken(mAccount, mAuthTokenType, mAuthToken);

    } else if (AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE.equals(mAuthTokenType)) {
        String username = getUserNameForSamlSso();

        if (!(mUsernameInput.getText().toString() + "@" + location).equals(username)) {
            // fail - not a new account, but an existing one; disallow
            RemoteOperationResult result = new RemoteOperationResult(ResultCode.ACCOUNT_NOT_THE_SAME);
            updateAuthStatusIconAndText(result);
            showAuthStatus();
            Log_OC.d(TAG, result.getLogMessage());

            return false;
        }

        response.putString(AccountManager.KEY_AUTHTOKEN, mAuthToken);
        // the next line is necessary; by now, notifications are calling
        // directly to the AuthenticatorActivity to update, without
        // AccountManager intervention
        mAccountMgr.setAuthToken(mAccount, mAuthTokenType, mAuthToken);

    } else {
        response.putString(AccountManager.KEY_AUTHTOKEN, mPasswordInput.getText().toString());
        mAccountMgr.setPassword(mAccount, mPasswordInput.getText().toString());
    }
    setAccountAuthenticatorResult(response);

    return true;
}

From source file:com.digitalarx.android.authentication.AuthenticatorActivity.java

/**
 * Sets the proper response to get that the Account Authenticator that started this activity saves 
 * a new authorization token for mAccount.
 *///from w w  w .j a v a 2 s  . c  om
private void updateToken() {
    Bundle response = new Bundle();
    response.putString(AccountManager.KEY_ACCOUNT_NAME, mAccount.name);
    response.putString(AccountManager.KEY_ACCOUNT_TYPE, mAccount.type);

    if (AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType()).equals(mAuthTokenType)) {
        response.putString(AccountManager.KEY_AUTHTOKEN, mAuthToken);
        // the next line is necessary; by now, notifications are calling directly to the AuthenticatorActivity to update, without AccountManager intervention
        mAccountMgr.setAuthToken(mAccount, mAuthTokenType, mAuthToken);

    } else if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType())
            .equals(mAuthTokenType)) {

        response.putString(AccountManager.KEY_AUTHTOKEN, mAuthToken);
        // the next line is necessary; by now, notifications are calling directly to the AuthenticatorActivity to update, without AccountManager intervention
        mAccountMgr.setAuthToken(mAccount, mAuthTokenType, mAuthToken);

    } else {
        response.putString(AccountManager.KEY_AUTHTOKEN, mPasswordInput.getText().toString());
        mAccountMgr.setPassword(mAccount, mPasswordInput.getText().toString());
    }
    setAccountAuthenticatorResult(response);

}

From source file:com.cerema.cloud2.authentication.AuthenticatorActivity.java

/**
 * Updates the authentication token.//from   w  w w.  java2 s  . c  om
 *
 * Sets the proper response so that the AccountAuthenticator that started this activity
 * saves a new authorization token for mAccount.
 *
 * Kills the session kept by OwnCloudClientManager so that a new one will created with
 * the new credentials when needed.
 */
private void updateAccountAuthentication() throws AccountNotFoundException {

    Bundle response = new Bundle();
    response.putString(AccountManager.KEY_ACCOUNT_NAME, mAccount.name);
    response.putString(AccountManager.KEY_ACCOUNT_TYPE, mAccount.type);

    if (AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType()).equals(mAuthTokenType)) {
        response.putString(AccountManager.KEY_AUTHTOKEN, mAuthToken);
        // the next line is necessary, notifications are calling directly to the 
        // AuthenticatorActivity to update, without AccountManager intervention
        mAccountMgr.setAuthToken(mAccount, mAuthTokenType, mAuthToken);

    } else if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType())
            .equals(mAuthTokenType)) {

        response.putString(AccountManager.KEY_AUTHTOKEN, mAuthToken);
        // the next line is necessary; by now, notifications are calling directly to the 
        // AuthenticatorActivity to update, without AccountManager intervention
        mAccountMgr.setAuthToken(mAccount, mAuthTokenType, mAuthToken);

    } else {
        response.putString(AccountManager.KEY_AUTHTOKEN, mPasswordInput.getText().toString());
        mAccountMgr.setPassword(mAccount, mPasswordInput.getText().toString());
    }
    setAccountAuthenticatorResult(response);

}

From source file:com.owncloud.android.authentication.AuthenticatorActivity.java

/**
 * Creates a new account through the Account Authenticator that started this
 * activity.//w  ww  . j a  v a2 s .co  m
 * 
 * This makes the account permanent.
 * 
 * TODO Decide how to name the OAuth accounts
 */
private boolean createAccount() {
    // / create and save new ownCloud account
    boolean isOAuth = AccountAuthenticator.AUTH_TOKEN_TYPE_ACCESS_TOKEN.equals(mAuthTokenType);
    boolean isSaml = AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE.equals(mAuthTokenType);

    Uri uri = Uri.parse(mHostBaseUrl);
    String username = mUsernameInput.getText().toString().trim();
    username = username + "@" + location;

    if (isSaml) {
        username = getUserNameForSamlSso();

    } else if (isOAuth) {
        username = "OAuth_user" + (new java.util.Random(System.currentTimeMillis())).nextLong();
    }
    String accountName = username + "@" + uri.getHost();
    if (uri.getPort() >= 0) {
        accountName += ":" + uri.getPort();
    }

    mAccount = new Account(accountName, AccountAuthenticator.ACCOUNT_TYPE);
    if (AccountUtils.exists(mAccount, getApplicationContext())) {
        // fail - not a new account, but an existing one; disallow
        RemoteOperationResult result = new RemoteOperationResult(ResultCode.ACCOUNT_NOT_NEW);
        updateAuthStatusIconAndText(result);
        showAuthStatus();
        Log_OC.d(TAG, result.getLogMessage());
        return false;

    } else {

        if (isOAuth || isSaml) {
            mAccountMgr.addAccountExplicitly(mAccount, "", null); // with
                                                                  // external
                                                                  // authorizations,
                                                                  // the
                                                                  // password
                                                                  // is
                                                                  // never
                                                                  // input
                                                                  // in the
                                                                  // app
        } else {
            mAccountMgr.addAccountExplicitly(mAccount, mPasswordInput.getText().toString(), null);
        }

        // / add the new account as default in preferences, if there is none
        // already
        Account defaultAccount = AccountUtils.getCurrentOwnCloudAccount(this);
        if (defaultAccount == null) {
            SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
            editor.putString("select_oc_account", accountName);
            editor.commit();
        }

        // / prepare result to return to the Authenticator
        // TODO check again what the Authenticator makes with it; probably
        // has the same effect as addAccountExplicitly, but it's not well
        // done
        final Intent intent = new Intent();
        intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, AccountAuthenticator.ACCOUNT_TYPE);
        intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, mAccount.name);
        /*
         * if (!isOAuth) intent.putExtra(AccountManager.KEY_AUTHTOKEN,
         * AccountAuthenticator.ACCOUNT_TYPE);
         */
        intent.putExtra(AccountManager.KEY_USERDATA, username);
        if (isOAuth || isSaml) {
            mAccountMgr.setAuthToken(mAccount, mAuthTokenType, mAuthToken);
        }
        // / add user data to the new account; TODO probably can be done in
        // the last parameter addAccountExplicitly, or in KEY_USERDATA
        mAccountMgr.setUserData(mAccount, AccountAuthenticator.KEY_OC_VERSION, mDiscoveredVersion.toString());
        mAccountMgr.setUserData(mAccount, AccountAuthenticator.KEY_OC_BASE_URL, mHostBaseUrl);
        if (isSaml) {
            mAccountMgr.setUserData(mAccount, AccountAuthenticator.KEY_SUPPORTS_SAML_WEB_SSO, "TRUE");
        } else if (isOAuth) {
            mAccountMgr.setUserData(mAccount, AccountAuthenticator.KEY_SUPPORTS_OAUTH2, "TRUE");
        }

        setAccountAuthenticatorResult(intent.getExtras());
        setResult(RESULT_OK, intent);

        // / immediately request for the synchronization of the new account
        Bundle bundle = new Bundle();
        bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
        ContentResolver.requestSync(mAccount, AccountAuthenticator.AUTHORITY, bundle);
        syncAccount();
        // Bundle bundle = new Bundle();
        // bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
        // ContentResolver.requestSync(mAccount,
        // AccountAuthenticator.AUTHORITY, bundle);
        return true;
    }
}

From source file:com.digitalarx.android.authentication.AuthenticatorActivity.java

/**
 * Creates a new account through the Account Authenticator that started this activity. 
 * // www .ja va 2  s . c  o m
 * This makes the account permanent.
 * 
 * TODO Decide how to name the OAuth accounts
 */
private boolean createAccount() {
    /// create and save new ownCloud account
    boolean isOAuth = AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType())
            .equals(mAuthTokenType);
    boolean isSaml = AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType())
            .equals(mAuthTokenType);

    Uri uri = Uri.parse(mServerInfo.mBaseUrl);
    String username = mUsernameInput.getText().toString().trim();
    if (isOAuth) {
        username = "OAuth_user" + (new java.util.Random(System.currentTimeMillis())).nextLong();
    }
    String accountName = com.owncloud.android.lib.common.accounts.AccountUtils.buildAccountName(uri, username);
    Account newAccount = new Account(accountName, MainApp.getAccountType());
    if (AccountUtils.exists(newAccount, getApplicationContext())) {
        // fail - not a new account, but an existing one; disallow
        RemoteOperationResult result = new RemoteOperationResult(ResultCode.ACCOUNT_NOT_NEW);
        updateAuthStatusIconAndText(result);
        showAuthStatus();
        Log_OC.d(TAG, result.getLogMessage());
        return false;

    } else {
        mAccount = newAccount;

        if (isOAuth || isSaml) {
            mAccountMgr.addAccountExplicitly(mAccount, "", null); // with external authorizations, the password is never input in the app
        } else {
            mAccountMgr.addAccountExplicitly(mAccount, mPasswordInput.getText().toString(), null);
        }

        /// add the new account as default in preferences, if there is none already
        Account defaultAccount = AccountUtils.getCurrentOwnCloudAccount(this);
        if (defaultAccount == null) {
            SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
            editor.putString("select_oc_account", accountName);
            editor.commit();
        }

        /// prepare result to return to the Authenticator
        //  TODO check again what the Authenticator makes with it; probably has the same effect as addAccountExplicitly, but it's not well done
        final Intent intent = new Intent();
        intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, MainApp.getAccountType());
        intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, mAccount.name);
        /*if (!isOAuth)
        intent.putExtra(AccountManager.KEY_AUTHTOKEN,   MainApp.getAccountType()); */
        intent.putExtra(AccountManager.KEY_USERDATA, username);
        if (isOAuth || isSaml) {
            mAccountMgr.setAuthToken(mAccount, mAuthTokenType, mAuthToken);
        }
        /// add user data to the new account; TODO probably can be done in the last parameter addAccountExplicitly, or in KEY_USERDATA
        mAccountMgr.setUserData(mAccount, Constants.KEY_OC_VERSION, mServerInfo.mVersion.getVersion());
        mAccountMgr.setUserData(mAccount, Constants.KEY_OC_BASE_URL, mServerInfo.mBaseUrl);

        if (isSaml) {
            mAccountMgr.setUserData(mAccount, Constants.KEY_SUPPORTS_SAML_WEB_SSO, "TRUE");
        } else if (isOAuth) {
            mAccountMgr.setUserData(mAccount, Constants.KEY_SUPPORTS_OAUTH2, "TRUE");
        }

        setAccountAuthenticatorResult(intent.getExtras());
        setResult(RESULT_OK, intent);

        return true;
    }
}

From source file:com.hangulo.powercontact.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // Check which request we're responding to
    if (requestCode == Constants.SETTINGS_REQUEST) {
        // Make sure the request was successful
        if (resultCode == RESULT_OK) { // ok there is some changed vaule, find & activate to current screen
            // PowerContactSettings  mLastSavedSettings = new PowerContactSettings(); // --> ?   ....
            PowerContactSettings changedSettings = new PowerContactSettings();
            readDefaultSettings(changedSettings); // ?? ?.

            if (!changedSettings.equals(mPowerContactSettings)) { //  ? ...
                //    .
                //    onResume? ?? ? ?.
                //   ?.
                // 3.  ( ?)
                // 4. ?   

                boolean mustChangeSpinnerType = false;
                boolean mustChangeSpinnerPosition = false;

                if (changedSettings.getDistance() != mPowerContactSettings.getDistance()) {
                    //  ..  ?? ..  ? .

                    mustChangeSpinnerPosition = true;
                    //                        mustChangeAllLoader = true;
                    mPowerContactSettings.setDistance(changedSettings.getDistance()); // change ~!
                }/*from w  ww. j  a v  a2  s .  co  m*/
                if (changedSettings.getMarkerType() != mPowerContactSettings.getMarkerType()) {
                    //                        Toast.makeText(this, "Now change marker", Toast.LENGTH_SHORT).show();
                    mPowerContactSettings.setMarkerType(changedSettings.getMarkerType());
                }
                if (changedSettings.getRealDistanceUnits() != mPowerContactSettings.getRealDistanceUnits()) {
                    //  ...
                    // 1.   .
                    // 2.   .(  )
                    mustChangeSpinnerType = true;
                    mustChangeSpinnerPosition = true;
                    //                        mustChangeListView=true;
                    mPowerContactSettings.setDistanceUnits(changedSettings.getRealDistanceUnits());
                    // ? ?   ?...??? --> settings?  ?.
                }

                // demo mode
                if (changedSettings.isDemoMode() != mPowerContactSettings.isDemoMode()) {
                    // demo mode ..  ? ? ?? --> ? 
                    mPowerContactSettings.setDemoMode(changedSettings.isDemoMode());
                }

                if (mustChangeSpinnerType) {
                    if (mListFragment != null) {
                        mListFragment.setDistanceSpinnerAdapter();
                    }
                }

                if (mustChangeSpinnerPosition) {
                    final int num_array_pref_range_distance_values;

                    // ?? ? ? ? .
                    if (mPowerContactSettings.getRealDistanceUnits() == Constants.DISTANCE_UNITS_METER) {
                        num_array_pref_range_distance_values = R.array.pref_range_distance_values_meter;
                    } else { // if (mPowerContactSettings.getRealDistanceUnits() == Constants.DISTANCE_UNITS_MILE)
                        num_array_pref_range_distance_values = R.array.pref_range_distance_values_mile;
                    }

                    if (mListFragment != null) {

                        // ?      ? ?? ...
                        mListFragment.mSpinnerDistance.setSelection(Arrays
                                .asList(getResources().getStringArray(num_array_pref_range_distance_values))
                                .indexOf((String.valueOf(mPowerContactSettings.getDistance())))); // set default distance
                        // 2. ?   .

                        //                        Toast.makeText(this, "Now change marker", Toast.LENGTH_SHORT).show();
                    }

                }

                // ? ? onResume()?  ? ??.

            }
        }
    } else if (requestCode == REQUEST_RESOLVE_ERROR) { // https://developers.google.com/android/guides/api-client
        mResolvingError = false;
        if (resultCode == RESULT_OK) {
            // Make sure the app is not already connected or attempting to connect
            if (!mGoogleApiClient.isConnecting() && !mGoogleApiClient.isConnected()) {
                mGoogleApiClient.connect();
            }
        }
    } else if (requestCode == Constants.REQUEST_ACCOUNT_SELECT
            || requestCode == Constants.REQUEST_ACCOUNT_SELECT_AND_RUN_SERVICE && resultCode == RESULT_OK) {
        mAccountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);

        // write to shared preference
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        SharedPreferences.Editor editor = prefs.edit();
        editor.putString(Constants.SETTINGS_ACCOUNT_KEY, mAccountName);
        editor.apply();

        if (requestCode == Constants.REQUEST_ACCOUNT_SELECT_AND_RUN_SERVICE) // ok start service
            getPermissionAndsyncData(mAccountName);
    }
}