Permalink
Browse files

Enhance Preferences class

  • Loading branch information...
1 parent 8bae155 commit 24645dd27f2d9b0da071da82921b08fa028a22fa @yukuku committed Sep 1, 2016
Showing with 24 additions and 2 deletions.
  1. +24 −2 Afw/src/main/java/yuku/afw/storage/Preferences.java
@@ -196,17 +196,39 @@ public static int getInt(@StringRes final int keyStringResId, @IntegerRes final
}
}
- public static boolean getBoolean(@StringRes final int keyStringResId, @BoolRes final int defaultIntResId) {
+ public static boolean getBoolean(@StringRes final int keyStringResId, @BoolRes final int defaultBoolResId) {
final Resources r = App.context.getResources();
final String key = r.getString(keyStringResId);
final Object value = get(key);
if (value == null) {
- return r.getBoolean(defaultIntResId);
+ return r.getBoolean(defaultBoolResId);
} else {
return (boolean) value;
}
}
+ public static String getString(@StringRes final int keyStringResId, @StringRes final int defaultStringResId) {
+ final Resources r = App.context.getResources();
+ final String key = r.getString(keyStringResId);
+ final Object value = get(key);
+ if (value == null) {
+ return r.getString(defaultStringResId);
+ } else {
+ return (String) value;
+ }
+ }
+
+ public static String getString(@StringRes final int keyStringResId) {
+ final Resources r = App.context.getResources();
+ final String key = r.getString(keyStringResId);
+ final Object value = get(key);
+ if (value == null) {
+ return null;
+ } else {
+ return (String) value;
+ }
+ }
+
@TargetApi(9) private synchronized static void commitIfNotHeld() {
if (held > 0) {
// don't do anything now

0 comments on commit 24645dd

Please sign in to comment.