Last active
August 29, 2015 14:21
-
-
Save yanzm/5eb70b27be9ec8fb966c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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