List of usage examples for android.content SharedPreferences getString
@Nullable String getString(String key, @Nullable String defValue);
From source file:com.openquartz.glassmemo.Utils.java
/** * Gets the arraylist from shared preferences * @param context/* w w w . ja v a 2 s.c o m*/ * @param key * @return */ public static ArrayList<String> getStringArrayPref(final Context context, String key) { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context); String json = sharedPref.getString(key, null); ArrayList<String> memoList = new ArrayList<String>(); if (json != null) { try { JSONArray a = new JSONArray(json); for (int i = 0; i < a.length(); i++) { memoList.add(a.optString(i)); } } catch (JSONException e) { } } return memoList; }
From source file:de.grobox.blitzmail.MailStorage.java
static public JSONObject getMails(Context context) { SharedPreferences sharedPref = context.getSharedPreferences("BlitzMail", Context.MODE_PRIVATE); String mails_str = sharedPref.getString("mails", null); JSONObject mails = new JSONObject(); if (mails_str != null) { try {/*from ww w .j a v a 2 s. c o m*/ mails = new JSONObject(mails_str); } catch (JSONException e) { e.printStackTrace(); } } return mails; }
From source file:Main.java
public static String[] loadArray(SharedPreferences prefs, String arrayName) { int size = prefs.getInt(arrayName + "_size", 0); String array[] = new String[size]; for (int i = 0; i < size; i++) array[i] = prefs.getString(arrayName + "_" + i, null); return array; }
From source file:com.vel9studios.levani.popularmovies.util.AppUtils.java
public static String getPreferredSortOrder(Context context) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); return prefs.getString(context.getString(R.string.pref_sort_key), context.getString(R.string.pref_sort_default)); }
From source file:sg.macbuntu.android.pushcontacts.SmsReceiver.java
private static boolean accountExist(Context context) { boolean exist = false; SharedPreferences settings = Prefs.get(context); String accountName = settings.getString("accountName", null); if (accountName != null) { exist = true;/*from w w w . ja v a 2 s.com*/ } return exist; }
From source file:Main.java
public static <T> T getData(Context context, String fileName, String key, Class T) { SharedPreferences sharedPreferences = context.getSharedPreferences(fileName, Context.MODE_PRIVATE); T result;/*w w w . ja va 2 s . co m*/ if (String.class.isAssignableFrom(T)) { result = (T) sharedPreferences.getString(key, ""); } else if (Integer.class.isAssignableFrom(T)) { result = (T) Integer.valueOf(sharedPreferences.getInt(key, 0)); } else if (Float.class.isAssignableFrom(T)) { result = (T) Float.valueOf(sharedPreferences.getFloat(key, 0)); } else if (Long.class.isAssignableFrom(T)) { result = (T) Long.valueOf(sharedPreferences.getLong(key, 0)); } else { result = (T) Boolean.valueOf(sharedPreferences.getBoolean(key, false)); } return result; }
From source file:Main.java
public static String getCameraId(Context context) { SharedPreferences preferences; String cameraid;/*from w ww .ja va2s .c o m*/ if (context != null) { preferences = context.getSharedPreferences("CameraConfig", Context.MODE_PRIVATE); cameraid = preferences.getString("camera", "0"); } else { cameraid = "0"; } return cameraid; }
From source file:me.qisthi.cuit.helper.StorageHelper.java
public static List<String[]> readPreferenceStatusValue(Activity activity, String key) throws Exception { SharedPreferences sharedPreferences = activity.getPreferences(Context.MODE_PRIVATE); String jsonValue = sharedPreferences.getString(key, null); List<String[]> statuses; if (jsonValue != null) { ObjectMapper mapper = new ObjectMapper(); statuses = mapper.readValue(jsonValue, new TypeReference<List<String[]>>() { });//from ww w . ja v a 2 s . com return statuses; } return null; }
From source file:Main.java
public static Map<String, String> getStringPreferences(Context context, String... prefNames) { SharedPreferences preferences = getDefaultPreference(context); Map<String, String> prefMap = new HashMap<String, String>(); for (String name : prefNames) { prefMap.put(name, preferences.getString(name, "")); }// w w w .ja v a 2 s .c om return prefMap; }
From source file:Main.java
public static Set<String> loadSet(SharedPreferences prefs, String setName) { final int size = prefs.getInt(setName + "_size", 0); Set<String> set = new HashSet<String>(size); for (int i = 0; i < size; i++) set.add(prefs.getString(setName + "_" + i, null)); return set;//from w ww .ja v a 2 s.co m }