List of usage examples for android.content SharedPreferences getInt
int getInt(String key, int defValue);
From source file:Main.java
public static int getNextEventCounter(Activity hostActivity, String key) { SharedPreferences preferences = PreferenceManager .getDefaultSharedPreferences(hostActivity.getApplicationContext()); int id = preferences.getInt(key, 0); id += 1;// w ww . j a va 2 s .c om SharedPreferences.Editor editor = preferences.edit(); editor.putInt(key, id).commit(); return id; }
From source file:Main.java
/** * Return int value of shared preference specifies by key * @param context/*w w w.j a va 2s. c om*/ * @param key * @return */ public static int getSharedPreferenceInt(Context context, String key) { int result = -1; if (context != null) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); if (sharedPreferences != null) { result = sharedPreferences.getInt(key, -1); } } return result; }
From source file:Main.java
public static void save_screen_status(Context context) { SharedPreferences localSharedPreferences = context.getSharedPreferences("SCREEN_STATUS", 0); Editor localEditor = localSharedPreferences.edit(); localEditor.putInt("screen_count", localSharedPreferences.getInt("screen_count", 0) + 1); localEditor.commit();/* w w w . java 2s . c o m*/ }
From source file:Main.java
public static boolean isUpgradedVersion(Context context) { SharedPreferences appSettings = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences.Editor editor = appSettings.edit(); int versionCode = appSettings.getInt("appVersion", -1); try {/*from w ww . jav a 2s . com*/ PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); int newVersion = pInfo.versionCode; if (versionCode != -1 && versionCode != newVersion) { editor.putInt("appVersion", newVersion); editor.commit(); return true; } } catch (Exception e) { } ; return false; }
From source file:Main.java
public static boolean judgeFirstIn(Context context) { SharedPreferences preferences = context.getSharedPreferences("isFirst", Context.MODE_PRIVATE); boolean isFirst = preferences.getBoolean("isFirst", true); int versionCode = preferences.getInt("versionCode", 1); if (isFirst || versionCode < getVersionCode(context)) { preferences.edit().putBoolean("isFirst", false).commit(); preferences.edit().putInt("versionCode", getVersionCode(context)).commit(); }/*from www . j av a 2s . c om*/ // return isFirst; return false; }
From source file:edu.cwru.apo.Auth.java
public static void loadKeys(SharedPreferences prefs) { Hex secretKey = new Hex(prefs.getString("secretKey", "0")); int counter = prefs.getInt("counter", -1); int increment = prefs.getInt("increment", 0); if (secretKey.toString().compareTo("0") == 0) return;/* w ww. jav a 2 s. c om*/ if (counter == -1) return; if (increment == 0) return; Auth.Hmac = new DynamicHmac(secretKey, counter, increment); }
From source file:am.roadpolice.roadpolice.dialogs.DialogSettings.java
public static int getUpdateInterval(final Context context) { // Set to weekly update interval by default. int defaultUpdateInterval = WEEKLY; if (context == null) return defaultUpdateInterval; // Try to get update interval from preferences. SharedPreferences sp = context.getSharedPreferences(TAG, Context.MODE_PRIVATE); return sp.getInt(KEY_UPDATE_INTERVAL, defaultUpdateInterval); }
From source file:Main.java
public static void incrementCount(Context context) { SharedPreferences sharedPreferences = context.getSharedPreferences(REVIEW_PREFS, Context.MODE_PRIVATE); Editor edit = sharedPreferences.edit(); edit.putInt(KEY_COUNT, sharedPreferences.getInt(KEY_COUNT, 0) + 1); edit.commit();//from www . j ava 2 s . c om }
From source file:com.binomed.showtime.android.util.CineShowTimeLayoutUtils.java
public static boolean isAnalyticsAthorized(SharedPreferences pref) { return pref.getInt(CineShowtimeCst.PREF_KEY_ANALYTICS, 0) == 1; }
From source file:Main.java
public static Object getParam(Context context, String key, Object defaultObject) { String type = defaultObject.getClass().getSimpleName(); SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE); if ("String".equals(type)) { return sp.getString(key, (String) defaultObject); } else if ("Integer".equals(type)) { return sp.getInt(key, (Integer) defaultObject); } else if ("Boolean".equals(type)) { return sp.getBoolean(key, (Boolean) defaultObject); } else if ("Float".equals(type)) { return sp.getFloat(key, (Float) defaultObject); } else if ("Long".equals(type)) { return sp.getLong(key, (Long) defaultObject); }/*from ww w . jav a 2 s.co m*/ return null; }