Skip to content

Instantly share code, notes, and snippets.

@yanzm
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yanzm/5eb70b27be9ec8fb966c to your computer and use it in GitHub Desktop.
Save yanzm/5eb70b27be9ec8fb966c to your computer and use it in GitHub Desktop.
private static final String PREF_SIZE_KEY = "pref_size_key";
public static void saveSize(@NonNull Context context, @Nullable Size size) {
final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
final SharedPreferences.Editor editor = pref.edit();
if (size == null) {
editor.remove(PREF_SIZE_KEY);
} else {
editor.putInt(PREF_SIZE_KEY, size.getValue());
}
editor.apply();
}
@Nullable
public static Size getSavedSize(@NonNull Context context) {
final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
if (pref.contains(PREF_SIZE_KEY)) {
@Size.ValidSize int value = pref.getInt(PREF_SIZE_KEY, Size.SIZE_L);
return Size.valueOf(value);
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment