Java 类android.content.SharedPreferences.Editor 实例源码

项目:InstagramManager-Android    文件:InstagramSession.java   
public void reset() {
    Editor editor = mSharedPref.edit();

    editor.putString(ACCESS_TOKEN,  "");
    editor.putString(USERID,        "");
    editor.putString(USERNAME,      "");
    editor.putString(FULLNAME,      "");
    editor.putString(PROFILPIC,     "");
    editor.putInt(FOLLOW,0);
    editor.putInt(FOLLOWED,0);

    editor.commit();

    CookieSyncManager.createInstance(mContext);

    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();
}
项目:GitHub    文件:HostListActivity.java   
protected void updateList() {
    if (prefs.getBoolean(PreferenceConstants.SORT_BY_COLOR, false) != sortedByColor) {
        Editor edit = prefs.edit();
        edit.putBoolean(PreferenceConstants.SORT_BY_COLOR, sortedByColor);
        edit.apply();
    }

    if (hostdb == null)
        hostdb = HostDatabase.get(this);

    hosts = hostdb.getHosts(sortedByColor);

    // Don't lose hosts that are connected via shortcuts but not in the database.
    if (bound != null) {
        for (TerminalBridge bridge : bound.getBridges()) {
            if (!hosts.contains(bridge.host))
                hosts.add(0, bridge.host);
        }
    }

    mAdapter = new HostAdapter(this, hosts, bound);
    mListView.setAdapter(mAdapter);
    adjustViewVisibility();
}
项目:keepass2android    文件:AccessManager.java   
public static void removeAccessToken(Context ctx, String hostPackage,
        String accessToken) {
    SharedPreferences prefs = getPrefsForHost(ctx, hostPackage);

    Log.d(_tag, "removing AccessToken.");
    if (prefs.getString(PREF_KEY_TOKEN, "").equals(accessToken))
    {
        Editor edit = prefs.edit();
        edit.clear();
        edit.commit();

    }

    SharedPreferences hostPrefs = ctx.getSharedPreferences("KP2A.PluginAccess.hosts", Context.MODE_PRIVATE);
    if (hostPrefs.contains(hostPackage))
    {
        hostPrefs.edit().remove(hostPackage).commit();
    }

}
项目:CSipSimple    文件:NightlyUpdater.java   
public UpdaterPopupLauncher getUpdaterPopup(boolean fallbackAlert) {
    UpdaterPopupLauncher popLauncher = null;
    Editor edt = prefs.edit();
    int onlineVersion = getLastOnlineVersion();
    // Reset ignore check value
    edt.putBoolean(IGNORE_NIGHTLY_CHECK, false);
    if(pinfo != null && pinfo.versionCode < onlineVersion) {
        popLauncher = new UpdaterPopupLauncher(context, onlineVersion);
    }else {
        // Set last check to now :)
        edt.putLong(LAST_NIGHTLY_CHECK, System.currentTimeMillis());
        // And delete latest nightly from cache
        File cachedFile = getCachedFile();
        if(cachedFile.exists()) {
            cachedFile.delete();
        }
        if(fallbackAlert) {
            popLauncher = new UpdaterPopupLauncher(context, 0);
        }
    }
    edt.commit();

    return popLauncher;
}
项目:CSipSimple    文件:CallHandlerPlugin.java   
/**
 * Retrieve internal id of call handler as saved in databases It should be
 * some negative < SipProfile.INVALID_ID number
 * 
 * @param ctxt Application context
 * @param packageName name of the call handler package
 * @return the id of this call handler in databases
 */
public static Long getAccountIdForCallHandler(Context ctxt, String packageName) {
    SharedPreferences prefs = ctxt.getSharedPreferences("handlerCache", Context.MODE_PRIVATE);

    long accountId = SipProfile.INVALID_ID;
    try {
        accountId = prefs.getLong(VIRTUAL_ACC_PREFIX + packageName, SipProfile.INVALID_ID);
    } catch (Exception e) {
        Log.e(THIS_FILE, "Can't retrieve call handler cache id - reset");
    }
    if (accountId == SipProfile.INVALID_ID) {
        // We never seen this one, add a new entry for account id
        int maxAcc = prefs.getInt(VIRTUAL_ACC_MAX_ENTRIES, 0x0);
        int currentEntry = maxAcc + 1;
        accountId = SipProfile.INVALID_ID - (long) currentEntry;
        Editor edt = prefs.edit();
        edt.putLong(VIRTUAL_ACC_PREFIX + packageName, accountId);
        edt.putInt(VIRTUAL_ACC_MAX_ENTRIES, currentEntry);
        edt.commit();
    }
    return accountId;
}
项目:Accessibility    文件:SPUtils.java   
public static void put(String fileName, Context context, String key, Object object) {
    SharedPreferences sp = SharedPreferencesImpl.getSharedPreferences(context, getFileName(fileName),
            Context.MODE_PRIVATE);
    Editor editor = sp.edit();

    if (object instanceof String) {
        editor.putString(key, (String) object);
    } else if (object instanceof Integer) {
        editor.putInt(key, (Integer) object);
    } else if (object instanceof Boolean) {
        editor.putBoolean(key, (Boolean) object);
    } else if (object instanceof Float) {
        editor.putFloat(key, (Float) object);
    } else if (object instanceof Long) {
        editor.putLong(key, (Long) object);
    } else if (object instanceof Set) {
        editor.putStringSet(key, (Set) object);
    } else if(object == null) {
        editor.remove(key);
    }
    editor.apply();
}
项目:letv    文件:UninstalledObserver.java   
private static String getUrlAddParamer(String url, Context context) {
    SharedPreferences setting = context.getSharedPreferences(TAG, 0);
    if (!setting.getBoolean("isInit", false)) {
        try {
            Editor edit = setting.edit();
            edit.putString(VERSION_NAME, context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName);
            edit.putString(MODEL, Build.MODEL);
            edit.putString("version", VERSION.RELEASE);
            edit.putString("url", url);
            edit.putBoolean("isInit", true);
            edit.commit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    StringBuilder builder = new StringBuilder(url);
    builder.append("&model=" + setting.getString(MODEL, ""));
    builder.append("&os=android" + setting.getString("version", ""));
    builder.append("&version=" + setting.getString(VERSION_NAME, ""));
    return builder.toString();
}
项目:CustomAndroidOneSheeld    文件:TwitterShield.java   
public void logoutFromTwitter() {
    stopListeningOnAKeyword();
    Editor e = mSharedPreferences.edit();
    e.remove(PREF_KEY_OAUTH_TOKEN);
    e.remove(PREF_KEY_OAUTH_SECRET);
    e.remove(PREF_KEY_TWITTER_LOGIN);
    e.remove(PREF_KEY_TWITTER_USERNAME);
    e.commit();
}
项目:boohee_v5.6    文件:Utils.java   
public static void setBind(Context context, boolean flag) {
    String flagStr = "not";
    if (flag) {
        flagStr = "ok";
    }
    Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
    editor.putString("bind_flag", flagStr);
    editor.commit();
}
项目:Treebolic    文件:Settings.java   
/**
 * Set providers default settings from provider data
 *
 * @param context locatorContext
 */
@SuppressLint({"CommitPrefEdits", "ApplySharedPref"})
@SuppressWarnings("boxing")
static public void setDefaults(@NonNull final Context context)
{
    // create providers
    final List<HashMap<String, Object>> providers = Providers.getProviders(context, false);

    // create prefs for built-in providers
    if (providers != null)
    {
        for (int i = 0; i < providers.size(); i++)
        {
            final HashMap<String, Object> provider = providers.get(i);
            if (provider.get(Providers.ISPLUGIN).equals(true))
            {
                continue;
            }

            // provider shared preferences
            final SharedPreferences providerSharedPrefs = context.getSharedPreferences(Settings.PREF_FILE_PREFIX + provider.get(Providers.NAME), Context.MODE_PRIVATE);

            // commit non existent values
            final Editor providerEditor = providerSharedPrefs.edit();
            final String[] keys = new String[]{TreebolicIface.PREF_SOURCE, TreebolicIface.PREF_BASE, TreebolicIface.PREF_IMAGEBASE, TreebolicIface.PREF_SETTINGS, Settings.PREF_PROVIDER};
            final String[] providerKeys = new String[]{Providers.SOURCE, Providers.BASE, Providers.IMAGEBASE, Providers.SETTINGS, Providers.PROVIDER};
            for (int j = 0; j < keys.length; j++)
            {
                final String key = keys[j];
                if (!providerSharedPrefs.contains(key))
                {
                    final String value = (String) provider.get(providerKeys[j]);
                    providerEditor.putString(key, value).commit();
                }
            }
        }
    }
}
项目:q-mail    文件:QMail.java   
/**
 * Remember that all account databases are using the most recent database schema.
 *
 * @param save
 *         Whether or not to write the current database version to the
 *         {@code SharedPreferences} {@link #DATABASE_VERSION_CACHE}.
 *
 * @see #areDatabasesUpToDate()
 */
public static synchronized void setDatabasesUpToDate(boolean save) {
    sDatabasesUpToDate = true;

    if (save) {
        Editor editor = sDatabaseVersionCache.edit();
        editor.putInt(KEY_LAST_ACCOUNT_DATABASE_VERSION, LocalStore.DB_VERSION);
        editor.apply();
    }
}
项目:boohee_v5.6    文件:PlatformDb.java   
public void removeAccount() {
    ArrayList arrayList = new ArrayList();
    for (Entry key : this.db.getAll().entrySet()) {
        arrayList.add(key.getKey());
    }
    Editor edit = this.db.edit();
    Iterator it = arrayList.iterator();
    while (it.hasNext()) {
        edit.remove((String) it.next());
    }
    edit.commit();
}
项目:ShangHanLun    文件:SingletonData.java   
public void savePreferences() {
    SharedPreferences pref = MyApplication.getAppContext()
            .getSharedPreferences(preferenceKey, Context.MODE_PRIVATE);
    Editor editor = pref.edit();
    editor.putInt("showShanghan", showShanghan);
    editor.putInt("showJinkui", showJinkui);
    editor.commit();
}
项目:NoteBuddy    文件:KeyValueDB.java   
/**
 * Delete value method
 * @param context
 * @param key
 * @throws NoSuchAlgorithmException
 */
private static void deleteValue(@NonNull Context context, @NonNull String key) throws NoSuchAlgorithmException {
    SharedPreferences settings;
    Editor editor;

    settings = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
    editor = settings.edit();

    editor.remove(key);
    editor.apply();
}
项目:Accessibility    文件:SPUtils.java   
public static void remove(String fileName, Context context, String key) {
    SharedPreferences sp = SharedPreferencesImpl.getSharedPreferences(context, getFileName(fileName),
            Context.MODE_PRIVATE);
    Editor editor = sp.edit();
    editor.remove(key);
    editor.apply();
}
项目:react-native-udesk    文件:PreferenceHelper.java   
public static void write(Context context, String fileName, String k,
        String v) {
    SharedPreferences preference = context.getSharedPreferences(fileName,
            Context.MODE_PRIVATE);
    Editor editor = preference.edit();
    editor.putString(k, v);
    editor.apply();
}
项目:GitHub    文件:AccessTokenKeeper.java   
/**
 * 保存 Token 对象到 SharedPreferences。
 * 
 * @param context 应用程序上下文环境
 * @param token   Token 对象
 */
public static void writeAccessToken(Context context, Oauth2AccessToken token) {
    if (null == context || null == token) {
        return;
    }

    SharedPreferences pref = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_APPEND);
    Editor editor = pref.edit();
    editor.putString(KEY_UID, token.getUid());
    editor.putString(KEY_ACCESS_TOKEN, token.getToken());
    editor.putLong(KEY_EXPIRES_IN, token.getExpiresTime());
    editor.apply();
}
项目:AndroFish    文件:SimplePersistence.java   
public void commit() {
    Editor edt = editor;
    if (edt != null) {
        synchronized (edt) {
            edt.commit();
            if (edt == editor) {
                editor = null;
            }
        }
    }
}
项目:StopApp    文件:SharedPreferenceUtil.java   
/**
 * 移除某个key值已经对应的值
 *
 * @param context
 * @param key
 */
public static void remove(Context context, String key) {
    SharedPreferences sp = context.getSharedPreferences(FILL_NAME, Context.MODE_PRIVATE);
    Editor edit = sp.edit();
    edit.remove(key);
    SharedPreferencesCompat.EditorCompat.getInstance().apply(edit);
}
项目:Pluto-Android    文件:SharePreferenceUtils.java   
public void setBooleanPrefByPackage( String name, boolean value) {
    String pkg = context.getPackageName();// 用包名当作文件名
    SharedPreferences prefs = context.getSharedPreferences(pkg, Context.MODE_PRIVATE);
    Editor ed = prefs.edit();
    ed.putBoolean(name, value);
    ed.apply();
}
项目:Expert-Android-Programming    文件:SessionPreference.java   
public static boolean setUserParams(Context context, User user) {

        Editor editor = context.getSharedPreferences(KEY, Context.MODE_PRIVATE).edit();
        editor.putInt(ID, user.getId());
        editor.putString(NAME, user.getName());
        editor.putString(EMAIL, user.getEmail());
        editor.putString(IMAGE, user.getImage());
        editor.putString(UID, user.getUid());
        editor.putBoolean(IS_LOGGED_IN, true);
        return editor.commit();
    }
项目:mininoteview    文件:MainActivity.java   
private void saveConfig()
{
    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
    Editor editor = pref.edit();
    editor.putInt(getString(R.string.prefFileListOrderKey), mCurrentOrder);
    editor.apply();
}
项目:StopApp    文件:SharedPreferenceUtil.java   
/**
 * 清除所有内容
 *
 * @param context
 */
public static void clear(Context context) {
    SharedPreferences sp = context.getSharedPreferences(FILL_NAME, Context.MODE_PRIVATE);
    Editor edit = sp.edit();
    edit.clear();
    SharedPreferencesCompat.EditorCompat.getInstance().apply(edit);
}
项目:letv    文件:ServerSetting.java   
public void setEnvironment(Context context, int i) {
    if (context != null && (this.c == null || this.c.get() == null)) {
        this.c = new WeakReference(context.getSharedPreferences("ServerPrefs", 0));
    }
    if (i == 0 || i == 1) {
        Editor edit;
        switch (i) {
            case 0:
                edit = ((SharedPreferences) this.c.get()).edit();
                edit.putInt("ServerType", 0);
                edit.putString(KEY_OPEN_ENV, "formal");
                edit.putString(KEY_HOST_QZS_QQ, KEY_HOST_QZS_QQ);
                edit.putString(KEY_HOST_OPEN_MOBILE, KEY_HOST_OPEN_MOBILE);
                edit.commit();
                changeServer();
                Toast.makeText(context, "已切换到正式环境", 0).show();
                return;
            case 1:
                edit = ((SharedPreferences) this.c.get()).edit();
                edit.putInt("ServerType", 1);
                edit.putString(KEY_OPEN_ENV, "exp");
                edit.putString(KEY_HOST_QZS_QQ, "testmobile.qq.com");
                edit.putString(KEY_HOST_OPEN_MOBILE, "test.openmobile.qq.com");
                edit.commit();
                changeServer();
                Toast.makeText(context, "已切换到体验环境", 0).show();
                return;
            default:
                return;
        }
    }
    f.e(a, "切换环境参数错误,正式环境为0,体验环境为1");
}
项目:letv    文件:af.java   
public static void a(Context context, String str, long j) {
    if (a(context)) {
        b(context);
        Editor edit = a.edit();
        edit.putLong(str, j);
        edit.apply();
        return;
    }
    z.d();
}
项目:OpenYOLO-Android    文件:UserRepository.java   
private void setCurrentUserEmail(@Nullable String email) {
    Editor editor = mSharedPrefs.edit();
    if (email == null) {
        editor.remove(KEY_CURRENT_USER);
    } else {
        editor.putString(KEY_CURRENT_USER, email);
    }
    editor.apply();
}
项目:dcs-sdk-java    文件:PreferenceUtil.java   
private static void editSubmit(Editor editor) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        editor.apply();
    } else {
        editor.commit();
    }
}
项目:exciting-app    文件:ConfigParamsKeeper.java   
/***
 * 设置配置值
 *
 * param key   配置变量名
 * param value 配置数值
 */
public void setValue(String key, boolean flag) {
    SharedPreferences preferences = context.getSharedPreferences(KEEPERNAME, Context.MODE_PRIVATE);
    Editor editor = preferences.edit();
    editor.putBoolean(key, flag);
    editor.apply();
}
项目:javaide    文件:PreferenceHelper.java   
/**
 * Record that we managed to get root in JellyBean.
 *
 * @param context
 * @return
 */
public static void setJellybeanRootRan(Context context) {
    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
    Editor editor = sharedPrefs.edit();
    editor.putBoolean(context.getString(R.string.pref_ran_jellybean_su_update), true);
    editor.commit();
}
项目:aos-MediaLib    文件:Trakt.java   
public static void wipePreferences(SharedPreferences pref, boolean userChanged) {
    Editor editor = pref.edit();
    if (!userChanged) {
        editor.remove(Trakt.KEY_TRAKT_USER);
        editor.remove(Trakt.KEY_TRAKT_SHA1);
        editor.remove(Trakt.KEY_TRAKT_LIVE_SCROBBLING);
        editor.remove(Trakt.KEY_TRAKT_SYNC_COLLECTION);
    }
    editor.remove(Trakt.KEY_TRAKT_SYNC_FLAG);
    editor.remove(Trakt.KEY_TRAKT_LAST_TIME_MOVIE_WATCHED);
    editor.remove(Trakt.KEY_TRAKT_LAST_TIME_SHOW_WATCHED);

    editor.commit();
}
项目:CSipSimple    文件:PreferencesWrapper.java   
/**
 * Set a preference string value
 * @param key the preference key to set
 * @param value the value for this key
 */
public void setPreferenceStringValue(String key, String value) {
    if(sharedEditor == null) {
        Editor editor = prefs.edit();
        editor.putString(key, value);
        editor.commit();
    }else {
        sharedEditor.putString(key, value);
    }
}
项目:boohee_v5.6    文件:d.java   
protected final void b(String str) {
    synchronized (this) {
        Log.i("MID", "write mid to sharedPreferences");
        Editor edit = PreferenceManager.getDefaultSharedPreferences(this.e).edit();
        edit.putString(h.f("4kU71lN96TJUomD1vOU9lgj9Tw=="), str);
        edit.commit();
    }
}
项目:exciting-app    文件:ConfigParamsKeeper.java   
/***
 * 设置配置值
 *
 * param key   配置变量名
 * param value 配置数值
 */
public void setValue(String key, int value) {
    SharedPreferences preferences = context.getSharedPreferences(KEEPERNAME, Context.MODE_PRIVATE);
    Editor editor = preferences.edit();
    editor.putInt(key, value);
    editor.apply();
}
项目:CSipSimple    文件:MediaManager.java   
/**
     * Restore the state of the audio
     */
    @SuppressWarnings("deprecation")
    private final synchronized void restoreAudioState() {
        if( !prefs.getBoolean("isSavedAudioState", false) ) {
            //If we have NEVER set, do not try to reset !
            return;
        }

        ContentResolver ctntResolver = service.getContentResolver();
        Compatibility.setWifiSleepPolicy(ctntResolver, prefs.getInt("savedWifiPolicy", Compatibility.getWifiSleepPolicyDefault()));
//      audioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, prefs.getInt("savedVibrateRing", AudioManager.VIBRATE_SETTING_ONLY_SILENT));
//      audioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, prefs.getInt("savedVibradeNotif", AudioManager.VIBRATE_SETTING_OFF));
//      audioManager.setRingerMode(prefs.getInt("savedRingerMode", AudioManager.RINGER_MODE_NORMAL));

        int inCallStream = Compatibility.getInCallStream(userWantBluetooth);
        setStreamVolume(inCallStream, prefs.getInt("savedVolume", (int)(audioManager.getStreamMaxVolume(inCallStream)*0.8) ), 0);

        int targetMode = getAudioTargetMode();
        if(service.getPrefs().useRoutingApi()) {
            audioManager.setRouting(targetMode, prefs.getInt("savedRoute", AudioManager.ROUTE_SPEAKER), AudioManager.ROUTE_ALL);
        }else {
            audioManager.setSpeakerphoneOn(prefs.getBoolean("savedSpeakerPhone", false));
        }
        audioManager.setMode(prefs.getInt("savedMode", AudioManager.MODE_NORMAL));


        Editor ed = prefs.edit();
        ed.putBoolean("isSavedAudioState", false);
        ed.commit();
    }
项目:Treebolic    文件:Settings.java   
/**
 * Set active provider settings (copied into default preferences)
 *
 * @param context  locatorContext
 * @param provider active provider
 */
@SuppressLint({"CommitPrefEdits", "ApplySharedPref"})
static public void setActivePrefs(@NonNull final Context context, @NonNull final HashMap<String, Object> provider)
{
    final SharedPreferences defaultSharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
    final Editor defaultEditor = defaultSharedPrefs.edit();
    SharedPreferences providerSharedPrefs;

    final Boolean isPlugin = (Boolean) provider.get(Providers.ISPLUGIN);
    if (isPlugin)
    {
        final String pkg = (String) provider.get(Providers.PACKAGE);
        providerSharedPrefs = Utils.getPluginDefaultSharedPreferences(context, pkg);
        defaultEditor.putString(Settings.PREF_PROVIDER, (String) provider.get(Providers.PROVIDER));
    }
    else
    {
        providerSharedPrefs = context.getSharedPreferences(Settings.PREF_FILE_PREFIX + provider.get(Providers.NAME), Context.MODE_PRIVATE);
        final String providerClass = providerSharedPrefs.getString(Settings.PREF_PROVIDER, null);
        defaultEditor.putString(Settings.PREF_PROVIDER, providerClass);
    }
    if (providerSharedPrefs != null)
    {
        final String[] keys = new String[]{TreebolicIface.PREF_SOURCE, TreebolicIface.PREF_BASE, TreebolicIface.PREF_IMAGEBASE, TreebolicIface.PREF_SETTINGS};
        for (final String key : keys)
        {
            final String value = providerSharedPrefs.getString(key, null);
            defaultEditor.putString(key, value);
        }
    }
    defaultEditor.commit();
}
项目:BilibiliClient    文件:PreferenceUtil.java   
public static void putBoolean(String key, boolean value) {

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(
        BilibiliApp.getInstance());
    Editor editor = sharedPreferences.edit();
    editor.putBoolean(key, value);
    editor.apply();
  }
项目:GrowingProject    文件:SharedPreferenceUtils.java   
public static void setObject(Editor pEditor, String pKey, Object o) {
    String str = null;
    try {
        str = SharedPreferenceUtils.writeObject(o);
    } catch (Exception e) {
        e.printStackTrace();
    }
    pEditor.putString(pKey, str);
    pEditor.commit();
}
项目:boohee_v5.6    文件:a$a.java   
public void a(String str, String str2, String str3) {
    this.a = str;
    this.b = str2;
    this.g = str3;
    Editor edit = this.k.j().edit();
    edit.putString("appId", this.a);
    edit.putString("appToken", str2);
    edit.putString("regResource", str3);
    edit.commit();
}
项目:BilibiliClient    文件:PreferenceUtil.java   
private static void putString(String key, String value) {

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(
        BilibiliApp.getInstance());
    Editor editor = sharedPreferences.edit();
    editor.putString(key, value);
    editor.apply();
  }
项目:Accessibility    文件:SPUtils.java   
/**
 * 清除所有数据
 */
public static void clear(Context context) {
    SharedPreferences sp = SharedPreferencesImpl.getSharedPreferences(context, getFileName(),
            Context.MODE_PRIVATE);
    Editor editor = sp.edit();
    editor.clear();
    editor.apply();
}