diff --git a/src/pandroid/app/src/main/AndroidManifest.xml b/src/pandroid/app/src/main/AndroidManifest.xml index 291496f4b..15bf6270c 100644 --- a/src/pandroid/app/src/main/AndroidManifest.xml +++ b/src/pandroid/app/src/main/AndroidManifest.xml @@ -11,6 +11,7 @@ android:glEsVersion="0x0030001"/> T get(Key key) { + Serializable value; + if (key.defaultValue instanceof String) { + value = data.getString(key.name, (String) key.defaultValue); + } else if (key.defaultValue instanceof Integer) { + value = data.getInt(key.name, (int) key.defaultValue); + } else if (key.defaultValue instanceof Boolean) { + value = data.getBoolean(key.name, (boolean) key.defaultValue); + } else if (key.defaultValue instanceof Long) { + value = data.getLong(key.name, (long) key.defaultValue); + } else { + value = data.getFloat(key.name, (float) key.defaultValue); + } + return (T) value; + } + + public static synchronized void set(Key key, T value) { + if (value instanceof String) { + data.edit().putString(key.name, (String) value).apply(); + } else if (value instanceof Integer) { + data.edit().putInt(key.name, (int) value).apply(); + } else if (value instanceof Boolean) { + data.edit().putBoolean(key.name, (boolean) value).apply(); + } else if (value instanceof Long) { + data.edit().putLong(key.name, (long) value).apply(); + } else if (value instanceof Float) { + data.edit().putFloat(key.name, (float) value).apply(); + } else { + throw new IllegalArgumentException("Invalid global config value instance"); + } + } + + private static class Key { + private final String name; + private final T defaultValue; + + private Key(String name, T defaultValue) { + this.name = name; + this.defaultValue = defaultValue; + } + } +} diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/Constants.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/Constants.java index d94164c71..1aac0a4dd 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/Constants.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/utils/Constants.java @@ -20,4 +20,6 @@ public class Constants { public static final String ACTIVITY_PARAMETER_PATH = "path"; public static final String LOG_TAG = "pandroid"; + + public static final String PREF_GLOBAL_CONFIG = "app.GlobalConfig"; }