android.support.v4.content.SharedPreferencesCompat Java Examples

The following examples show how to use android.support.v4.content.SharedPreferencesCompat. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SPUtils.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 保存数据
 * @param context
 * @param key
 * @param value
 */
public static void put(Context context, String key, Object value) {
    SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sp.edit();
    if (value instanceof String) {
        editor.putString(key, (String) value);
    } else if (value instanceof Integer) {
        editor.putInt(key, (Integer) value);
    } else if (value instanceof Boolean) {
        editor.putBoolean(key, (Boolean) value);
    } else if (value instanceof Float) {
        editor.putFloat(key, (Float) value);
    } else if (value instanceof Long) {
        editor.putLong(key, (Long) value);
    } else {
        editor.putString(key, value.toString());
    }
    SharedPreferencesCompat.EditorCompat.getInstance().apply(editor);
}
 
Example #2
Source File: SPUtils.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 移除数据
 * @param context
 * @param key
 */
public static void remove(Context context, String key) {
    SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sp.edit();
    editor.remove(key);
    SharedPreferencesCompat.EditorCompat.getInstance().apply(editor);
}
 
Example #3
Source File: SPUtils.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 清空保存数据
 * @param context
 */
public static void clear(Context context) {
    SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sp.edit();
    editor.clear();
    SharedPreferencesCompat.EditorCompat.getInstance().apply(editor);
}
 
Example #4
Source File: MainApplication.java    From NightOwl with Apache License 2.0 5 votes vote down vote up
@Override
public void onSkinChange(int mode, Activity activity) {
    SharedPreferences preferences = activity.getSharedPreferences("NightOwlDemo",
            Activity.MODE_PRIVATE);
    SharedPreferences.Editor editor = preferences.edit();
    editor.putInt("mode", mode);
    SharedPreferencesCompat.EditorCompat.getInstance().apply(editor);
}
 
Example #5
Source File: Preferences.java    From AndroidSDK with MIT License 4 votes vote down vote up
public void putInt(final String key, final int value) {
    mEditor.putInt(key, value);
    SharedPreferencesCompat.EditorCompat.getInstance().apply(mEditor);
}
 
Example #6
Source File: Preferences.java    From AndroidSDK with MIT License 4 votes vote down vote up
public void putLong(final String key, final long value) {
    mEditor.putLong(key, value);
    SharedPreferencesCompat.EditorCompat.getInstance().apply(mEditor);
}
 
Example #7
Source File: Preferences.java    From AndroidSDK with MIT License 4 votes vote down vote up
public void putString(final String key, final String value) {
    mEditor.putString(key, value);
    SharedPreferencesCompat.EditorCompat.getInstance().apply(mEditor);
}
 
Example #8
Source File: Preferences.java    From AndroidSDK with MIT License 4 votes vote down vote up
public void putFloat(final String key, final float value) {
    mEditor.putFloat(key, value);
    SharedPreferencesCompat.EditorCompat.getInstance().apply(mEditor);
}
 
Example #9
Source File: Preferences.java    From AndroidSDK with MIT License 4 votes vote down vote up
public void putBoolean(final String key, final boolean value) {
    mEditor.putBoolean(key, value);
    SharedPreferencesCompat.EditorCompat.getInstance().apply(mEditor);
}
 
Example #10
Source File: Preferences.java    From AndroidSDK with MIT License 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void putStringSet(final String key, final Set<String> values) {
    mEditor.putStringSet(key, values);
    SharedPreferencesCompat.EditorCompat.getInstance().apply(mEditor);
}