Exemplo n.º 1
0
 private static void clearCurrentState() {
   List<String> allKeys = KeyValueStorage.getEncryptedKeys();
   for (String key : allKeys) {
     if (key.startsWith(GateStorage.DB_GATE_KEY_PREFIX)
         || key.startsWith(LevelStorage.DB_LEVEL_KEY_PREFIX)
         || key.startsWith(MissionStorage.DB_MISSION_KEY_PREFIX)
         || key.startsWith(ScoreStorage.DB_SCORE_KEY_PREFIX)
         || key.startsWith(WorldStorage.DB_WORLD_KEY_PREFIX)) {
       KeyValueStorage.deleteKeyValue(key);
     }
   }
 }
Exemplo n.º 2
0
  /** {@inheritDoc} */
  @Override
  public void logout(final AuthCallbacks.LogoutListener logoutListener) {
    SoomlaUtils.LogDebug(TAG, "logout");

    KeyValueStorage.deleteKeyValue(getTwitterStorageKey(TWITTER_OAUTH_TOKEN));
    KeyValueStorage.deleteKeyValue(getTwitterStorageKey(TWITTER_OAUTH_SECRET));

    mainRequestToken = null;

    twitter.setOAuthAccessToken(null);
    twitter.shutdown();

    logoutListener.success();
  }
Exemplo n.º 3
0
        /**
         * Called when OAuth authentication has been finalized and an Access Token and Access Token
         * Secret have been provided
         *
         * @param accessToken The access token to use to do REST calls
         */
        @Override
        public void gotOAuthAccessToken(AccessToken accessToken) {
          SoomlaUtils.LogDebug(TAG, "login/onComplete");

          twitter.setOAuthAccessToken(accessToken);

          // Keep in storage for logging in without web-authentication
          KeyValueStorage.setValue(
              getTwitterStorageKey(TWITTER_OAUTH_TOKEN), accessToken.getToken());
          KeyValueStorage.setValue(
              getTwitterStorageKey(TWITTER_OAUTH_SECRET), accessToken.getTokenSecret());

          // Keep screen name since Twitter4J does not have it when
          // logging in using authenticated tokens
          KeyValueStorage.setValue(
              getTwitterStorageKey(TWITTER_SCREEN_NAME), accessToken.getScreenName());

          twitterScreenName = accessToken.getScreenName();

          RefLoginListener.success(RefProvider);

          clearListener(ACTION_LOGIN);
        }
Exemplo n.º 4
0
  /** {@inheritDoc} */
  @Override
  public void login(
      final Activity parentActivity, final AuthCallbacks.LoginListener loginListener) {
    if (!isInitialized) {
      SoomlaUtils.LogError(
          TAG, "Consumer key and secret were not defined, please provide them in initialization");
      return;
    }

    SoomlaUtils.LogDebug(TAG, "login");
    WeakRefParentActivity = new WeakReference<Activity>(parentActivity);

    RefProvider = getProvider();
    RefLoginListener = loginListener;

    preformingAction = ACTION_LOGIN;

    mainRequestToken = null;
    twitter.setOAuthAccessToken(null);

    // Try logging in using store credentials
    String oauthToken = KeyValueStorage.getValue(getTwitterStorageKey(TWITTER_OAUTH_TOKEN));
    String oauthTokenSecret = KeyValueStorage.getValue(getTwitterStorageKey(TWITTER_OAUTH_SECRET));
    if (!TextUtils.isEmpty(oauthToken) && !TextUtils.isEmpty(oauthTokenSecret)) {
      twitter.setOAuthAccessToken(new AccessToken(oauthToken, oauthTokenSecret));
      twitterScreenName = KeyValueStorage.getValue(getTwitterStorageKey(TWITTER_SCREEN_NAME));

      loginListener.success(RefProvider);

      clearListener(ACTION_LOGIN);
    } else {
      // If no stored credentials start login process by requesting
      // a request token
      twitter.getOAuthRequestTokenAsync(oauthCallbackURL);
    }
  }
Exemplo n.º 5
0
  public static JSONObject getLevelUpModel() {
    JSONObject modelJSON = null;

    String model = KeyValueStorage.getValue(DB_KEY_PREFIX + "model");
    SoomlaUtils.LogDebug(TAG, "model: " + model);
    if (model == null) {
      return null;
    }

    try {
      modelJSON = new JSONObject(model);
    } catch (JSONException e) {
      SoomlaUtils.LogError(TAG, "Unable to parse LevelUp model into JSON");
    }

    return modelJSON;
  }