Exemplo n.º 1
0
  private void onAccountChoose(String accountName) {
    try {
      YukonAccount[] secondaryAccountArray = yukonAccountKeeper.getSecondaryAccountArray();

      if (!addingAccount) {
        secondaryAccountArray = removeSecondaryAccount(secondaryAccountArray, accountName);
      }
      secondaryAccountArray =
          addSecondaryAccount(secondaryAccountArray, yukonAccountKeeper.getMainAccount());

      yukonAccountKeeper.setSecondaryAccountArray(secondaryAccountArray);
      yukonAccountKeeper.setMainAccount(new YukonAccount(null, accountName, null));

      commitYukonAccountKeeperRegister();
    } catch (JSONException e) {
      e.printStackTrace();
    }

    generateCredential();
    requestAuthorization();

    if (addingAccount) {
      addingAccount = false;
      Intent refreshIntent = new Intent(this, getClass());
      startActivity(refreshIntent);
      finish();
    }
  }
Exemplo n.º 2
0
  protected void removeCredential() {
    AndroidUtil androidUtil = new AndroidUtil(this);

    try {
      YukonAccountKeeper yukonAccountKeeper =
          new YukonAccountKeeper(
              androidUtil.readFromSharedPreferences(ACCOUNT_FILE, ACCOUNT_KEEPER_KEY, null));
      yukonAccountKeeper.setMainAccount(null);
      androidUtil.writeToSharedPreferences(
          ACCOUNT_FILE, ACCOUNT_KEEPER_KEY, yukonAccountKeeper.toString());
    } catch (NullPointerException | JSONException e) {
      androidUtil.writeToSharedPreferences(ACCOUNT_FILE, ACCOUNT_KEEPER_KEY, null);
    }

    credential = null;
  }