本文整理匯總了Java中android.content.SharedPreferences.Editor類的典型用法代碼示例。如果您正苦於以下問題:Java Editor類的具體用法?Java Editor怎麽用?Java Editor使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Editor類屬於android.content.SharedPreferences包,在下文中一共展示了Editor類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: reset
import android.content.SharedPreferences.Editor; //導入依賴的package包/類
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();
}
示例2: updateList
import android.content.SharedPreferences.Editor; //導入依賴的package包/類
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();
}
示例3: removeAccessToken
import android.content.SharedPreferences.Editor; //導入依賴的package包/類
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();
}
}
示例4: getUpdaterPopup
import android.content.SharedPreferences.Editor; //導入依賴的package包/類
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;
}
示例5: getAccountIdForCallHandler
import android.content.SharedPreferences.Editor; //導入依賴的package包/類
/**
* 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;
}
示例6: put
import android.content.SharedPreferences.Editor; //導入依賴的package包/類
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();
}
示例7: getUrlAddParamer
import android.content.SharedPreferences.Editor; //導入依賴的package包/類
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();
}
示例8: logoutFromTwitter
import android.content.SharedPreferences.Editor; //導入依賴的package包/類
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();
}
示例9: setBind
import android.content.SharedPreferences.Editor; //導入依賴的package包/類
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();
}
示例10: setDefaults
import android.content.SharedPreferences.Editor; //導入依賴的package包/類
/**
* 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();
}
}
}
}
}
示例11: setDatabasesUpToDate
import android.content.SharedPreferences.Editor; //導入依賴的package包/類
/**
* 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();
}
}
示例12: removeAccount
import android.content.SharedPreferences.Editor; //導入依賴的package包/類
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();
}
示例13: savePreferences
import android.content.SharedPreferences.Editor; //導入依賴的package包/類
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();
}
示例14: deleteValue
import android.content.SharedPreferences.Editor; //導入依賴的package包/類
/**
* 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();
}
示例15: remove
import android.content.SharedPreferences.Editor; //導入依賴的package包/類
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();
}