List of usage examples for android.content SharedPreferences getString
@Nullable String getString(String key, @Nullable String defValue);
From source file:net.evecom.android.util.HttpUtil.java
public static String getPageSize(Context context) { if (null == context) { return "15"; }/* ww w .j a v a2 s . c o m*/ SharedPreferences sp = context.getSharedPreferences("PageSize", context.MODE_PRIVATE); sp.getString("pagesize", "15"); return sp.getString("pagesize", "15"); }
From source file:Main.java
public static void initialize(Activity activity) { /** /*from www. j a va 2s . c o m*/ *gets a SharedPreferences instance that points to the default file that is used by the preference framework */ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity); /** * used to store latest orientation of android device */ String orientation = prefs.getString("prefOrientation", "Null"); if ("Landscape".equals(orientation)) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } else if ("Portrait".equals(orientation)) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR); } }
From source file:jp.co.ipublishing.aeskit.notification.gcm.GCMRegister.java
/** * GCMID??//from ww w . j a va2 s .co m * * @param context * @return GCMID?????????????? */ @NonNull private static String getRegistrationId(@NonNull Context context) { final SharedPreferences prefs = getPreferences(context); final String registrationId = prefs.getString(PROPERTY_REG_ID, ""); if (registrationId.isEmpty()) { Log.i(TAG, "Registration not found."); return ""; } final int registeredVersion = prefs.getInt(PROPERTY_APP_VERSION, Integer.MIN_VALUE); final int currentVersion = getAppVersion(context); if (registeredVersion != currentVersion) { Log.i(TAG, "App version changed."); return ""; } return registrationId; }
From source file:Main.java
public static LinkedList<String> loadList(SharedPreferences prefs, String listName) { int size = prefs.getInt(listName + "_size", 0); LinkedList<String> list = new LinkedList<String>(); for (int i = 0; i < size; i++) { list.add(prefs.getString(listName + "_" + i, null)); }/*from w ww . jav a2 s.c o m*/ return list; }
From source file:cc.softwarefactory.lokki.android.utilities.gcm.GcmHelper.java
private static String getRegistrationId(Context context) { final SharedPreferences prefs = getGCMPreferences(context); String registrationId = prefs.getString(PROPERTY_REG_ID, ""); if (registrationId.isEmpty()) { Log.e(TAG, "Registration not found."); return ""; }//from w ww . j a va2s . com // Check if app was updated; if so, it must clear the registration ID since the existing regID is not guaranteed to work with the new app version. int registeredVersion = prefs.getInt(PROPERTY_APP_VERSION, Integer.MIN_VALUE); int currentVersion = getAppVersion(context); if (registeredVersion == currentVersion) { return registrationId; } Log.i(TAG, "App version changed."); return ""; }
From source file:com.vel9studios.levani.popularmovies.util.AppUtils.java
public static String getSortOrderQuery(Context context) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); String sortOrder = prefs.getString(context.getString(R.string.pref_sort_key), context.getString(R.string.pref_sort_default)); if (sortOrder.equals(AppConstants.QUERY_SORT_TYPE_POPULARITY)) return MoviesContract.MoviesEntry.COLUMN_POPULARITY + " DESC"; else if (sortOrder.equals(AppConstants.QUERY_SORT_TYPE_VOTE)) return MoviesContract.MoviesEntry.COLUMN_VOTE_AVERAGE + " DESC"; return null;//from w ww.jav a 2 s .com }
From source file:foodcenter.android.service.AndroidRequestUtils.java
/** Should be called on startup and after login */ public static void setUpUrl(Context context) { SharedPreferences p = getSharedPreferences(context); SERVER_URL = p.getString(PREF_SERVER_URL, PROD_URL); }
From source file:Main.java
public static void showChangelog(final Context context, final String title, final String appname, final int resChanges, final int resNotes) { final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context); final String v0 = p.getString(PREFS_LAST_RUN, ""); String v1 = null;//from www .j a va 2 s .c o m try { v1 = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; } catch (NameNotFoundException e) { Log.e(TAG, "package not found: " + context.getPackageName(), e); } p.edit().putString(PREFS_LAST_RUN, v1).commit(); if (v0.length() == 0) { Log.d(TAG, "first boot, skip changelog"); // return; } if (v0.equals(v1)) { Log.d(TAG, "no changes"); return; } String[] changes = context.getResources().getStringArray(resChanges); String[] notes = resNotes > 0 ? context.getResources().getStringArray(resNotes) : null; final SpannableStringBuilder sb = new SpannableStringBuilder(); for (String s : notes) { SpannableString ss = new SpannableString(s + "\n"); int j = s.indexOf(":"); if (j > 0) { if (!TextUtils.isEmpty(s)) { ss.setSpan(new StyleSpan(Typeface.BOLD), 0, j, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } } sb.append(ss); sb.append("\n"); } if (notes != null && notes.length > 0) { sb.append("\n"); } for (String s : changes) { s = appname + " " + s.replaceFirst(": ", ":\n* ").replaceAll(", ", "\n* ") + "\n"; SpannableString ss = new SpannableString(s); int j = s.indexOf(":"); if (j > 0) { ss.setSpan(new StyleSpan(Typeface.BOLD), 0, j, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } sb.append(ss); sb.append("\n"); } sb.setSpan(new RelativeSizeSpan(0.75f), 0, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); changes = null; notes = null; AlertDialog.Builder b = new AlertDialog.Builder(context); b.setTitle(title); b.setMessage(sb); b.setCancelable(true); b.setPositiveButton(android.R.string.ok, null); b.show(); }
From source file:com.google.android.apps.chrometophone.DeviceRegistrar.java
static String getAccountName(Context context) { SharedPreferences settings = Prefs.get(context); String accountName = settings.getString("accountName", null); return accountName; }
From source file:fr.simon.marquis.secretcodes.util.Utils.java
public static ArrayList<SecretCode> getSecretCodes(Context ctx) { ArrayList<SecretCode> res = new ArrayList<SecretCode>(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx); try {//from ww w . j a v a2 s . co m JSONArray array = new JSONArray(prefs.getString(KEY_SECRET_CODES, "")); for (int i = 0; i < array.length(); i++) { SecretCode code = SecretCode.fromJSON(array.optJSONObject(i)); if (code != null) { res.add(code); } } return res; } catch (JSONException e) { return res; } }