@Test public void get() throws Exception { PreferenceJsonController<SourceSetting> preferences = new PreferenceJsonController<>(); preferences.put(RuntimeEnvironment.application, "abc", 12345); assertEquals(preferences.getAsInt(RuntimeEnvironment.application, "abc"), new Integer(12345)); List<String> collection = new ArrayList<String>(); collection.add("abc"); collection.add("123"); preferences.put(RuntimeEnvironment.application, "123", collection); assertTrue(preferences.getAsList(RuntimeEnvironment.application, "123", new TypeToken<List<String>>(){}) .contains("123")); }
public Object get(Context context, String key) { SharedPreferences settings = context.getSharedPreferences(PREFERENCE, Context.MODE_PRIVATE); return parser.fromJson(settings.getString(key, ""), Object.class); }
PreferenceJsonController { public Object get(Context context, String key) { SharedPreferences settings = context.getSharedPreferences(PREFERENCE, Context.MODE_PRIVATE); return parser.fromJson(settings.getString(key, ""), Object.class); } }
PreferenceJsonController { public Object get(Context context, String key) { SharedPreferences settings = context.getSharedPreferences(PREFERENCE, Context.MODE_PRIVATE); return parser.fromJson(settings.getString(key, ""), Object.class); } PreferenceJsonController(); }
PreferenceJsonController { public Object get(Context context, String key) { SharedPreferences settings = context.getSharedPreferences(PREFERENCE, Context.MODE_PRIVATE); return parser.fromJson(settings.getString(key, ""), Object.class); } PreferenceJsonController(); Object get(Context context, String key); Integer getAsInt(Context context, String key); List<T> getAsList(Context context, String key, TypeToken token); void put(Context context, String key, Object value); }
PreferenceJsonController { public Object get(Context context, String key) { SharedPreferences settings = context.getSharedPreferences(PREFERENCE, Context.MODE_PRIVATE); return parser.fromJson(settings.getString(key, ""), Object.class); } PreferenceJsonController(); Object get(Context context, String key); Integer getAsInt(Context context, String key); List<T> getAsList(Context context, String key, TypeToken token); void put(Context context, String key, Object value);  }