List of usage examples for android.content SharedPreferences getInt
int getInt(String key, int defValue);
From source file:edu.rowan.app.fragments.FoodRatingFragment.java
/** * Stores received JSON data the given SharedPreferences object * Below an example map how the data is stored: * /* w w w.j av a 2 s . c om*/ * foodType -> entryId * entryId -> data.toString() * * When a new entry for a particular foodType is created, it will have a different entryId. * When new entries are received, we must clear the data of previous entries * * @param prefs Should be sharedPreferences created with FoodRatingFragment.PREFS * @param foodType TYPE_MARKETPLACE or TYPE_SMOKEHOUSE * @param data The Json being put into the preferences * @throws JSONException */ private static void updatePreferencesData(SharedPreferences prefs, String foodType, JSONObject data) throws JSONException { Editor edit = prefs.edit(); int newFoodId = data.getJSONObject("entry").getInt("id"); int oldFoodId = prefs.getInt(foodType, -1); // oldFoodEntry exists && newEntryId is different. Have a new entry, clear old data if (oldFoodId != -1 && newFoodId != oldFoodId) { Log.d("FoodRatingFragment", "NEW ENTRY DETECTED: removing old entry and vote state"); edit.remove(Integer.toString(oldFoodId)); // remove local vote state edit.remove(SubRatingFragment.getLocalVoteKey(foodType)); } edit.putInt(foodType, newFoodId); edit.putString(Integer.toString(newFoodId), data.toString()); edit.putLong(LAST_REFRESH, Calendar.getInstance().getTimeInMillis()); edit.commit(); }
From source file:com.irccloud.android.GCMIntentService.java
public static String getRegistrationId(Context context) { final SharedPreferences prefs = context.getSharedPreferences("prefs", 0); String registrationId = prefs.getString("gcm_reg_id", ""); if (registrationId.length() == 0) { Log.i("IRCCloud", "Registration not found."); return ""; }//from w ww . j a va 2s . c o m // 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("gcm_app_version", Integer.MIN_VALUE); int currentVersion = getAppVersion(); if (registeredVersion != currentVersion) { Log.i("IRCCloud", "App version changed."); return ""; } String build = prefs.getString("gcm_app_build", ""); if (!Build.FINGERPRINT.equals(build)) { Log.i("IRCCloud", "OS version changed."); return ""; } return registrationId; }
From source file:com.dmbstream.android.util.Util.java
public static int getUserId(Context context) { SharedPreferences prefs = getPreferences(context); return prefs.getInt(Constants.SHARED_USERID, -1); }
From source file:com.atinternet.tracker.LifeCycle.java
/** * Get the object which contains lifecycle metrics * * @return Closure//w w w. j a v a2 s .c om */ static Closure getMetrics(final SharedPreferences preferences) { return new Closure() { @Override public String execute() { try { LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>(); // fs map.put("fs", preferences.getBoolean(FIRST_SESSION, false) ? 1 : 0); // fsau map.put("fsau", preferences.getBoolean(FIRST_SESSION_AFTER_UPDATE, false) ? 1 : 0); if (!TextUtils.isEmpty(preferences.getString(FIRST_SESSION_DATE_AFTER_UPDATE, ""))) { map.put("scsu", preferences.getInt(SESSION_COUNT_SINCE_UPDATE, 0)); map.put("fsdau", Integer.parseInt(preferences.getString(FIRST_SESSION_DATE_AFTER_UPDATE, ""))); map.put("dsu", preferences.getInt(DAYS_SINCE_UPDATE, 0)); } map.put("sc", preferences.getInt(SESSION_COUNT, 0)); map.put("fsd", Integer.parseInt(preferences.getString(FIRST_SESSION_DATE, ""))); map.put("dsls", preferences.getInt(DAYS_SINCE_LAST_SESSION, 0)); map.put("dsfs", preferences.getInt(DAYS_SINCE_FIRST_SESSION, 0)); map.put("sessionId", sessionId); return new JSONObject().put("lifecycle", new JSONObject(map)).toString(); } catch (JSONException e) { e.printStackTrace(); } return ""; } }; }
From source file:com.dmbstream.android.util.Util.java
public static int getPreloadCount(Context context) { SharedPreferences prefs = getPreferences(context); int preloadCount = 5; try {/* www . j av a 2s . co m*/ preloadCount = Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_PRELOAD_COUNT, "5")); } catch (Exception ex) { preloadCount = prefs.getInt(Constants.PREFERENCES_KEY_PRELOAD_COUNT, 5); } return preloadCount == -1 ? Integer.MAX_VALUE : preloadCount; }
From source file:MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); SharedPreferences settings = getPreferences(MODE_PRIVATE); int defaultCounter = 0; mCounter = settings.getInt(KEY_COUNTER, defaultCounter); }
From source file:com.manning.androidhacks.hack045.MainActivity.java
@Override protected void onResume() { super.onResume(); SharedPreferences prefs = getSharedPreferences(PREFS_NAME, 0); mTimesOpened = prefs.getInt(TIMES_OPENED_KEY, 1); mTextView.setText(String.format(TIMES_OPENED_FMT, mTimesOpened)); }
From source file:com.firescar96.nom.GCMIntentService.java
/** * Gets the current registration ID for application on GCM service. * <p>//from w w w . j a v a 2 s . co m * If result is empty, the app needs to register. * * @return registration ID, or empty string if there is no existing * registration ID. */ public static String getRegistrationId(Context context) { final SharedPreferences prefs = getGcmPreferences(context); String registrationId = prefs.getString(PROPERTY_REG_ID, ""); if (regId != null) { System.out.println("Registration found." + registrationId); return regId; } if (registrationId.isEmpty()) { System.out.println("Registration not found."); return ""; } else System.out.println("Registration found." + registrationId); // 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) { System.out.println("App version changed."); return ""; } return registrationId; }
From source file:com.farmerbb.secondscreen.util.U.java
public static boolean runDensityCommand(Context context, String requestedDpi) { DisplayMetrics metrics = new DisplayMetrics(); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display disp = wm.getDefaultDisplay(); disp.getRealMetrics(metrics);/* w w w .j a v a 2 s . co m*/ SharedPreferences prefMain = getPrefMain(context); String currentDpi; String nativeDpi = Integer .toString(SystemProperties.getInt("ro.sf.lcd_density", prefMain.getInt("density", 0))); if (prefMain.getBoolean("debug_mode", false)) { SharedPreferences prefCurrent = getPrefCurrent(context); currentDpi = prefCurrent.getString("density", "reset"); if ("reset".equals(currentDpi)) currentDpi = nativeDpi; } else currentDpi = Integer.toString(metrics.densityDpi); if (requestedDpi.equals("reset")) requestedDpi = nativeDpi; return !requestedDpi.equals(currentDpi); }
From source file:de.appplant.cordova.plugin.badge.BadgeImpl.java
/** * Retrieves the badge of the app icon.//ww w.j a va 2s . c om * * @param ctx * The application context. * @param callback * The function to be exec as the callback. */ protected void getBadge(CallbackContext callback, Context ctx) { SharedPreferences settings = getSharedPreferences(ctx); int badge = settings.getInt(KEY, 0); PluginResult result; result = new PluginResult(PluginResult.Status.OK, badge); callback.sendPluginResult(result); }