/** Remove Token, Secret from preferences */
  public void disconnectTwitter() {
    Editor editor = sharedPreferences.edit();
    editor.remove(TwitterConsts.PREF_KEY_TOKEN);
    editor.remove(TwitterConsts.PREF_KEY_SECRET);

    editor.commit();
  }
    @Override
    protected void onPostExecute(Payload result) {
      super.onPostExecute(result);
      HashMap<String, Object> results = (HashMap<String, Object>) result.result;
      Decks deck = (Decks) results.get("deck");
      // Close the previously opened deck.
      //            DeckManager.closeDeck(deck.getDeckPath());

      SharedDeckDownload download = (SharedDeckDownload) result.data[0];
      SharedPreferences pref = PrefSettings.getSharedPrefs(getBaseContext());
      Editor editor = pref.edit();

      Log.i(AnkiDroidApp.TAG, "Finished deck " + download.getFilename() + " " + result.success);
      if (result.success) {
        // Put updated cards to 0
        // TODO: Why do we need to zero the updated cards?
        editor.putLong(
            "numUpdatedCards:" + mDestination + "/tmp/" + download.getFilename() + ".anki.updating",
            0);
        editor.commit();
        // Move deck and media to the default deck path
        new File(mDestination + "/tmp/" + download.getFilename() + ".anki.updating")
            .renameTo(new File(mDestination + "/" + download.getFilename() + ".anki"));
        new File(mDestination + "/tmp/" + download.getFilename() + ".media/")
            .renameTo(new File(mDestination + "/" + download.getFilename() + ".media/"));
        mSharedDeckDownloads.remove(download);
        showNotification(download.getTitle(), download.getFilename());
      } else {
        // If paused do nothing, if cancelled clean up
        if (download.getStatus() == Download.STATUS_CANCELLED) {
          try {
            new File(mDestination + "/tmp/" + download.getFilename() + ".anki.updating").delete();
            File mediaFolder =
                new File(mDestination + "/tmp/" + download.getFilename() + ".media/");
            if (mediaFolder != null && mediaFolder.listFiles() != null) {
              for (File f : mediaFolder.listFiles()) {
                f.delete();
              }
              mediaFolder.delete();
            }
          } catch (SecurityException e) {
            Log.e(AnkiDroidApp.TAG, "SecurityException = " + e.getMessage());
            e.printStackTrace();
          }
          editor.remove(
              "numUpdatedCards:"
                  + mDestination
                  + "/tmp/"
                  + download.getFilename()
                  + ".anki.updating");
          editor.remove(
              "paused:" + mDestination + "/tmp/" + download.getFilename() + ".anki.updating");
          editor.commit();
          mSharedDeckDownloads.remove(download);
        }
      }
      notifySharedDeckObservers();
      stopIfFinished();
    }
Exemple #3
0
 public void cleanLoginSession() {
   Editor editor = getPreferencesEditor();
   editor.putBoolean(IS_LOGGED_IN, false);
   editor.remove(USER_ID);
   editor.remove(PSWD);
   // Retain the last login info.
   editor.commit();
 }
Exemple #4
0
 public void logOut() {
   Editor ed = this.settings.edit();
   ed.remove("email");
   ed.remove("api_key");
   ed.commit();
   this.api_key = null;
   setEventQueueId(null);
 }
 /** Function to logout from twitter It will just clear the application shared preferences */
 private void logoutAndRevokeFromTwitter() {
   // Clear the shared preferences
   Editor e = mSharedPreferences.edit();
   e.remove(PREF_KEY_OAUTH_TOKEN);
   e.remove(PREF_KEY_OAUTH_SECRET);
   e.remove(PREF_KEY_TWITTER_LOGIN);
   e.commit();
 }
 public synchronized void clearArea() {
   if (mSharePreference != null) {
     Editor editor = mSharePreference.edit();
     editor.remove(AREA_ID);
     editor.remove(AREA_NAME);
     editor.commit();
   }
 }
 private void doClear() {
   Resources res = getResources();
   SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
   Editor ed = prefs.edit();
   ed.remove(res.getString(R.string.pref_bt_name));
   ed.remove(res.getString(R.string.pref_bt_address));
   ed.remove(res.getString(R.string.pref_bt_provider));
   ed.commit();
 }
 public void clear() {
   this.cookies.clear();
   Editor edit = this.cookiePrefs.edit();
   Iterator it = this.cookies.keySet().iterator();
   while (it.hasNext()) {
     edit.remove(COOKIE_NAME_PREFIX + ((String) it.next()));
   }
   edit.remove(COOKIE_NAME_STORE);
   edit.commit();
 }
 private void deleteWidgetPrefs(Context context, int widgetId) {
   WidgetConfiguration.TaskSharedConfigNames cfgNames =
       new WidgetConfiguration.TaskSharedConfigNames(widgetId);
   SharedPreferences config = context.getSharedPreferences(WidgetConfiguration.PREFS_NAME, 0);
   Editor prefsEditor = config.edit();
   prefsEditor.remove(cfgNames.Id);
   prefsEditor.remove(cfgNames.Name);
   prefsEditor.remove(cfgNames.Done);
   prefsEditor.commit();
 }
  /**
   * Light version of logout that doesn't fire any events or perform any API calls. logout, bleow,
   * should almost always be the one to use.
   */
  public void shallowLogout() {
    final SharedPreferences prefs = getSharedPreferences(PREFERENCE_FILE, Context.MODE_PRIVATE);
    Editor editor = prefs.edit();
    editor.remove(mSite.mName + AUTH_TOKEN_KEY);
    editor.remove(mSite.mName + USERNAME_KEY);
    editor.remove(mSite.mName + USERID_KEY);
    editor.commit();

    mUser = null;
  }
  public void clearGeofence(String id) {

    // Remove a flattened geofence object from storage by removing all of its keys
    Editor editor = mPrefs.edit();
    editor.remove(getGeofenceFieldKey(id, GeofenceUtils.KEY_LATITUDE));
    editor.remove(getGeofenceFieldKey(id, GeofenceUtils.KEY_LONGITUDE));
    editor.remove(getGeofenceFieldKey(id, GeofenceUtils.KEY_RADIUS));
    editor.remove(getGeofenceFieldKey(id, GeofenceUtils.KEY_EXPIRATION_DURATION));
    editor.remove(getGeofenceFieldKey(id, GeofenceUtils.KEY_TRANSITION_TYPE));
    editor.commit();
  }
  @Override
  public void RemoveStoredKeyValuePairs(String[] keynames) {
    List<String> successfullKeyPairs = new ArrayList<String>();
    List<String> failedKeyPairs = new ArrayList<String>();
    SharedPreferences settings = GetOtherAppSharedPreferences();
    if (settings != null) {
      for (String keyname : keynames) {
        if (settings.contains(keyname)) {
          Editor ed = settings.edit();
          ed.remove(keyname);
          ed.commit();
          successfullKeyPairs.add(keyname);
        } else failedKeyPairs.add(keyname);
      }
    } else {
      LOGGER.logError("RemoveStoredKeyValuePairs", "Storage Unit is null.");
    }

    LOGGER.logInfo(
        "RemoveStoredKeyValuePairs",
        "Keys removed from storage unit: "
            + successfullKeyPairs.size()
            + "; Keys Not removed from storage unit: "
            + failedKeyPairs.size());
    IActivityManager am =
        (IActivityManager)
            AndroidServiceLocator.GetInstance()
                .GetService(AndroidServiceLocator.SERVICE_ANDROID_ACTIVITY_MANAGER);
    am.executeJS(
        "Unity.OnKeyValuePairsRemoveCompleted",
        new Object[] {successfullKeyPairs.toArray(), failedKeyPairs.toArray()});
  }
  /**
   * Removes the registration name and id association from local storage
   *
   * @param registrationName The registration name of the association to remove from local storage
   * @throws Exception
   */
  private void removeRegistrationId(String registrationName) throws Exception {
    Editor editor = mSharedPreferences.edit();

    editor.remove(STORAGE_PREFIX + REGISTRATION_NAME_STORAGE_KEY + registrationName);

    editor.commit();
  }
 /**
  * Clear data in shared preferences
  *
  * @param context
  */
 public static void clearSharedPreferences(Context context) {
   SharedPreferences pref = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
   Editor editor = pref.edit();
   editor.remove(KEY_INSTALL_DATE);
   editor.remove(KEY_LAUNCH_TIMES);
   editor.commit();
 }
 private void migrateUsageStatisticsPreferences() {
   final SharedPreferences preferences = getSharedPreferences();
   final boolean hasUsageStatistics = preferences.contains(KEY_USAGE_STATISTICS);
   if (hasUsageStatistics) return;
   if (preferences.contains(KEY_UCD_DATA_PROFILING)
       || preferences.contains(KEY_SPICE_DATA_PROFILING)) {
     final boolean prevUsageEnabled =
         preferences.getBoolean(KEY_UCD_DATA_PROFILING, false)
             || preferences.getBoolean(KEY_SPICE_DATA_PROFILING, false);
     final Editor editor = preferences.edit();
     editor.putBoolean(KEY_USAGE_STATISTICS, prevUsageEnabled);
     editor.remove(KEY_UCD_DATA_PROFILING);
     editor.remove(KEY_SPICE_DATA_PROFILING);
     editor.apply();
   }
 }
 public void remove(Collection<String> keys) {
   Editor editor = preferences.edit();
   for (String k : keys) {
     editor.remove(k);
   }
   editor.commit();
 }
 public void setPreferenceValue(final Editor edit, final E value) {
   if (value != null) {
     edit.putString(key, value.getResValue());
   } else {
     edit.remove(key);
   }
 }
 public synchronized void clearTechTime() {
   if (mSharePreference != null) {
     Editor editor = mSharePreference.edit();
     editor.remove(TECH_START_TIME);
     editor.commit();
   }
 }
  /**
   * Remove a specific alarm from the Android shared Preferences.
   *
   * @param alarmId The Id of the notification that must be removed.
   */
  public static void unpersist(String alarmId) {
    Editor editor = getSharedPreferences().edit();

    if (alarmId != null) {
      editor.remove(alarmId);
      editor.commit();
    }
  }
Exemple #20
0
  public static void removeSetting(Context ctx, String setting) {
    //        Log.v(Tag, "Removing setting " + setting);

    SharedPreferences sp = ctx.getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE);
    Editor editor = sp.edit();
    editor.remove(setting);
    editor.commit();
  }
Exemple #21
0
  public static void clearPreferences(Activity activity, String key) {

    SharedPreferences sp =
        PreferenceManager.getDefaultSharedPreferences(activity.getApplicationContext());
    Editor editor = sp.edit();
    editor.remove(key);
    editor.commit();
  }
  /**
   * Remove a specific alarm from the Android shared Preferences
   *
   * @param alarmId The Id of the notification that must be removed.
   * @return true when successfull, otherwise false
   */
  private boolean unpersistAlarm(String alarmId) {
    final Editor alarmSettingsEditor =
        this.ctx.getSharedPreferences(PLUGIN_NAME, Context.MODE_PRIVATE).edit();

    alarmSettingsEditor.remove(alarmId);

    return alarmSettingsEditor.commit();
  }
 /**
  * Stores the second line of the event title.
  *
  * @param context the {@link Context}.
  * @param eventLineTwo the second line of the event title; or an empty string. Pass null to clear.
  */
 public void storeEventLineTwo(Context context, String eventLineTwo) {
   Editor editor =
       PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext()).edit();
   if (eventLineTwo != null && eventLineTwo.length() > 0) {
     editor.putString(KEY_EVENT_LINE_TWO, eventLineTwo).apply();
   } else {
     editor.remove(KEY_EVENT_LINE_TWO).apply();
   }
 }
 /**
  * Stores the uri to the event logo image.
  *
  * @param context the {@link Context}.
  * @param uri the uri to the event logo image; or an empty string. Pass null to clear.
  */
 public void storeEventLogoUri(Context context, String uri) {
   Editor editor =
       PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext()).edit();
   if (uri != null && uri.length() > 0) {
     editor.putString(KEY_EVENT_LOGO_URI, uri).apply();
   } else {
     editor.remove(KEY_EVENT_LOGO_URI).apply();
   }
 }
Exemple #25
0
  public void openDB() {
    // always make sure that the db still exists, if not, send the user back to Welcome and pop up
    // an Alert
    // saying that their database is gone somehow. Pass the path to the lost database to Welcome in
    // extras.
    if (fullPath != null) {
      if (fileExists(fullPath)) {
        db = SQLiteDatabase.openDatabase(fullPath, null, 0);
        dbOpen = true;
      } else {
        // clear the users preferences in settings.
        Editor edit = this.prefs.edit();
        edit.putBoolean("openLastUsed", false);
        edit.remove("Full Path");
        edit.apply();

        // make sure that we no longer show the database open or have a path set for it.
        this.fullPath = null;
        this.dbOpen = false;

        // Send the user to Welcome.
        Intent i = new Intent(this, WelcomeActivity.class);
        i.putExtra("lostPath", fullPath);
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(i);
      }
    } else {
      // clear the users preferences in settings.
      Editor edit = this.prefs.edit();
      edit.putBoolean("openLastUsed", false);
      edit.remove("Full Path");
      edit.apply();

      // make sure that we no longer show the database open or have a path set for it.
      this.fullPath = null;
      this.dbOpen = false;

      // Send the user to Welcome.
      Intent i = new Intent(this, WelcomeActivity.class);
      i.putExtra("lostPath", fullPath);
      i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      startActivity(i);
    }
  }
Exemple #26
0
  private void logoutFromTwitter() {
    // Clear the shared preferences
    Editor e = mSharedPreferences.edit();
    e.remove(PREF_KEY_OAUTH_TOKEN);
    e.remove(PREF_KEY_OAUTH_SECRET);
    e.remove(PREF_KEY_TWITTER_LOGIN);
    e.commit();

    // After this take the appropriate action
    // I am showing the hiding/showing buttons again
    // You might not needed this code
    btnLogoutTwitter.setVisibility(View.GONE);
    btnGetTweets.setVisibility(View.GONE);
    lblUserName.setVisibility(View.GONE);
    btnShowOnMap.setVisibility(View.GONE);
    btnUsers.setVisibility(View.GONE);

    btnLoginTwitter.setVisibility(View.VISIBLE);
  }
Exemple #27
0
 public void finish(View view) {
   Editor editor = getSharedPreferences(SHARED_PREFERENCE_NAME, MODE_PRIVATE).edit();
   if (checkBox.isChecked()) {
     editor = editor.putBoolean(demoActivityId, true);
   } else {
     editor = editor.remove(demoActivityId);
   }
   editor.commit();
   finish();
 }
Exemple #28
0
  protected void clearUserProfile() {
    Context context = getApplicationContext();
    SharedPreferences pref = context.getSharedPreferences(PREF_NAME, PREF_MODE);

    Editor editor = pref.edit();
    ;

    editor.remove(KEY_AGE);
    editor.remove(KEY_HEIGHT);
    editor.remove(KEY_WEIGHT);
    editor.clear();
    editor.commit();

    mEditAge.setText(null);
    mEditHeight.setText(null);
    mEditWeight.setText(null);

    Toast.makeText(getApplicationContext(), "User profile cleared!", Toast.LENGTH_LONG).show();
  }
  /**
   * Cleans up the SharedPreferences space from numUpdatedCards records of downloads that have been
   * completed or cancelled.
   */
  public void removeCompletedDownloadsPrefs() {
    Log.i(
        AnkiDroidApp.TAG,
        "DownloadManagerService - Removing shared preferences of completed or cancelled downloads");

    File dir = new File(mDestination + "/tmp/");
    File[] fileList = dir.listFiles(new IncompleteDownloadsFilter());
    HashSet<String> filenames = new HashSet();

    // Get all incomplete downloads filenames
    if (fileList != null) {
      for (File file : fileList) {
        filenames.add(file.getName());
      }
    }

    // Remove any download related shared preference that doesn't have a corresponding incomplete
    // file
    SharedPreferences pref = PrefSettings.getSharedPrefs(getBaseContext());
    Matcher sharedPrefMatcher;
    Editor editor = pref.edit();
    boolean sharedPreferencesChanged = false;
    for (String key : pref.getAll().keySet()) {
      sharedPrefMatcher = sNumUpdatedCardsPattern.matcher(key);
      if (sharedPrefMatcher.matches() && sharedPrefMatcher.groupCount() > 0) {
        if (!filenames.contains(sharedPrefMatcher.group(1))) {
          editor.remove(key);
          sharedPreferencesChanged = true;
        }
      }
      sharedPrefMatcher = sPausedPattern.matcher(key);
      if (sharedPrefMatcher.matches() && sharedPrefMatcher.groupCount() > 0) {
        if (!filenames.contains(sharedPrefMatcher.group(1))) {
          editor.remove(key);
          sharedPreferencesChanged = true;
        }
      }
    }
    if (sharedPreferencesChanged) {
      editor.commit();
    }
  }
 @TargetApi(Build.VERSION_CODES.GINGERBREAD)
 public static void removeAccount(Context ctx) {
   Editor editor = PreferenceManager.getDefaultSharedPreferences(ctx).edit();
   editor.remove(KEY_ACCOUNT_NAME);
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
     editor.apply();
   } else {
     editor.commit();
   }
   mCurrentUser = null;
 }