List of usage examples for android.content SharedPreferences getString
@Nullable String getString(String key, @Nullable String defValue);
From source file:com.umeng.comm.ui.imagepicker.util.FeedMemento.java
/** * @param context/*from ww w .j a va 2 s. c om*/ * @return */ public static FeedItem restoreMemento(Context context) { FeedItem feedItem = new FeedItem(); SharedPreferences sharedPreferences = context.getSharedPreferences(Constants.FEED_SHARE_PREF, Context.MODE_PRIVATE); String saveFeedStr = sharedPreferences.getString(Constants.FEED_SHARE_PREF_KEY, ""); if (!TextUtils.isEmpty(saveFeedStr)) { try { JSONObject feedJsonObject = new JSONObject(saveFeedStr); feedItem.text = feedJsonObject.optString("content"); feedItem.title = feedJsonObject.optString("title"); feedItem.locationAddr = feedJsonObject.optString("location_addr"); // parseImages(feedItem, feedJsonObject); // ? parseTopics(feedItem, feedJsonObject); // ? parseFriends(feedItem, feedJsonObject); } catch (JSONException e) { e.printStackTrace(); } } // end if return feedItem; }
From source file:Main.java
@TargetApi(10) private static Bitmap getSidebarWallpaperApi10(Context context, SharedPreferences preferences, int sidebarWidth, int sidebarHeight) { boolean useBackground = preferences.getBoolean("pref_sidebar_custom_background", false); if (!useBackground) return null; String path = preferences.getString("pref_sidebar_background_image", null); if (path == null) return null; try {//from ww w. java 2 s. c o m BitmapFactory.Options bounds = decodeBounds(createWallpaperInputStream(context, path)); int decodeHeight = Math.min(bounds.outHeight, sidebarHeight); int decodeWidth = Math.min(bounds.outWidth, sidebarWidth); InputStream in = createWallpaperInputStream(context, path); try { BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance(in, false); BitmapFactory.Options options = new BitmapFactory.Options(); return decoder.decodeRegion(new Rect(0, 0, decodeWidth, decodeHeight), options); } finally { in.close(); } } catch (IOException e) { return null; } }
From source file:com.colossaldb.dnd.prefs.AppPreferences.java
private static JSONArray getJSONArray(SharedPreferences preferences, String listKey) { JSONArray events;/*from w ww .j a va2 s . c om*/ String eventStr = preferences.getString(listKey, null); if (eventStr == null) { events = new JSONArray(); } else { try { events = new JSONArray(eventStr); } catch (JSONException ignored) { // Cannot do much... Log.e("AppPreferences", "Error: " + ignored.getMessage(), ignored); events = new JSONArray(); } } return events; }
From source file:com.amazonaws.mobileconnectors.util.ClientContext.java
/** * Gets the installation id from shared preferences. A new one will be * assigned if not found. The installation id is unique per app * installation. This value appears as installation_id in client context * object in AWS Lambda.//w ww . j ava2s .co m * * @param context context of the app * @return the unique installation id per app installation * @see <a * href="http://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-context.html">The * Context Object (Node.js)</a> */ public static String getInstallationId(Context context) { final SharedPreferences sp = context.getSharedPreferences(SHARED_PREFERENCES, Context.MODE_PRIVATE); String installationId = sp.getString("installation_id", null); if (installationId == null) { installationId = UUID.randomUUID().toString(); sp.edit().putString("installation_id", installationId).commit(); } return installationId; }
From source file:com.clutch.ClutchAPIClient.java
public static void setup(Context inContext, String inAppKey, String inRpcUrl) { context = inContext;/*from w w w . j av a 2 s. c o m*/ client = AndroidHttpClient.newInstance("Clutch-Android", context); try { versionName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; } catch (NameNotFoundException e) { Log.e(TAG, "Could not get bundle version"); e.printStackTrace(); } appKey = inAppKey; rpcUrl = inRpcUrl; SharedPreferences prefs = context.getSharedPreferences("clutchab" + context.getPackageName(), Context.MODE_PRIVATE); fakeGUID = prefs.getString("fakeGUID", null); if (fakeGUID == null) { fakeGUID = ClutchUtils.getUUID(); SharedPreferences.Editor editor = prefs.edit(); editor.putString("fakeGUID", fakeGUID); editor.commit(); } }
From source file:com.hybris.mobile.lib.commerce.helper.SecurityHelper.java
/** * Get the String encrypted value associated with the key on the secure shared preferences * * @param sharedPreferences The SharedPreferences used * @param key The SharedPreferences key * @param defaultValue The default value if nothing if found on the SharedPreferences *//*from w ww . j ava2s .c om*/ public static String getStringFromSecureSharedPreferences(SharedPreferences sharedPreferences, String key, String defaultValue) { if (sharedPreferences == null || StringUtils.isBlank(key)) { throw new IllegalArgumentException(); } return SecurityHelper.decrypt(sharedPreferences.getString(key, defaultValue)); }
From source file:org.yaoha.ApiConnector.java
private static void setConsumer() { Context ctx = YaohaActivity.getStaticApplicationContext(); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(ctx); oauthToken = oauthTokenSecret = null; consumer = null;/*from w w w.ja v a 2s . c om*/ oauthToken = preferences.getString(OAuth.OAUTH_TOKEN, null); oauthTokenSecret = preferences.getString(OAuth.OAUTH_TOKEN_SECRET, null); if (oauthToken != null && oauthTokenSecret != null) { consumer = new CommonsHttpOAuthConsumer(C.CONSUMER_KEY, C.CONSUMER_SECRET); consumer.setTokenWithSecret(oauthToken, oauthTokenSecret); } }
From source file:com.atinternet.tracker.LifeCycle.java
static void firstSessionInit(SharedPreferences preferences, SharedPreferences backwardPreferences) { // If SDKV1 lifecycle exists if (backwardPreferences != null && backwardPreferences.getString("ATFirstLaunch", null) != null) { preferences.edit().putBoolean(FIRST_SESSION, false) .putString(FIRST_SESSION_DATE, backwardPreferences.getString("ATFirstLaunch", "")) .putInt(SESSION_COUNT, backwardPreferences.getInt("ATLaunchCount", 0)) .putString(LAST_SESSION_DATE, backwardPreferences.getString("ATLastLaunch", "")).apply(); backwardPreferences.edit().putString("ATFirstLaunch", null).apply(); } else {/*from w w w . ja v a2 s . c om*/ preferences.edit().putBoolean(FIRST_SESSION, true).putBoolean(FIRST_SESSION_AFTER_UPDATE, false) .putInt(SESSION_COUNT, 1).putInt(SESSION_COUNT_SINCE_UPDATE, 1) .putInt(DAYS_SINCE_FIRST_SESSION, 0).putInt(DAYS_SINCE_LAST_SESSION, 0) .putString(FIRST_SESSION_DATE, simpleDateFormat.format(new Date())) .putString(LAST_SESSION_DATE, simpleDateFormat.format(new Date())).apply(); } preferences.edit().putString(LifeCycle.VERSION_CODE_KEY, versionCode).apply(); sessionId = UUID.randomUUID().toString(); }
From source file:bala.padio.Settings.java
private static String getConfig(String name, String defValue, String setting) { SharedPreferences preference = MainActivity.AppContext.getSharedPreferences(setting, Context.MODE_PRIVATE); return preference.getString(name, defValue); }
From source file:com.binomed.showtime.android.util.CineShowTimeLayoutUtils.java
/** Set the theme of the activity, according to the configuration. */ public static void onActivityCreateSetTheme(Activity activity, SharedPreferences pref) { String defaultTheme = activity.getResources().getString(R.string.preference_gen_default_theme); String theme = pref.getString(activity.getResources().getString(R.string.preference_gen_key_theme), defaultTheme);/*from w w w . j ava 2 s .c om*/ if (theme.equals(defaultTheme)) { activity.setTheme(R.style.Theme_Dark_Night); } else { activity.setTheme(R.style.Theme_Shine_the_lite); } }