List of usage examples for android.content SharedPreferences getInt
int getInt(String key, int defValue);
From source file:com.smarthome.deskclock.Alarms.java
/** * If there is a snooze set, enable it in AlarmManager * @return true if snooze is set//from ww w . j ava 2s . c om */ private static boolean enableSnoozeAlert(final Context context) { SharedPreferences prefs = context.getSharedPreferences(AlarmClock.PREFERENCES, 0); int id = prefs.getInt(PREF_SNOOZE_ID, -1); if (id == -1) { return false; } long time = prefs.getLong(PREF_SNOOZE_TIME, -1); // Get the alarm from the db. final Alarm alarm = getAlarm(context.getContentResolver(), id); if (alarm == null) { return false; } // The time in the database is either 0 (repeating) or a specific time // for a non-repeating alarm. Update this value so the AlarmReceiver // has the right time to compare. alarm.time = time; enableAlert(context, alarm, time); return true; }
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 ww .j a v a 2s. com 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:fr.pasteque.client.Configure.java
public static int getStatus(Context ctx) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx); return prefs.getInt(LABEL_STATUS, Configure.STATUS_NONE); }
From source file:com.google.android.gcm.GCMRegistrar.java
/** * Gets the current registration id for application on GCM service. * <p>//ww w . ja v a 2s .c om * If result is empty, the registration has failed. * * @return registration id, or empty string if the registration is not * complete. */ public static String getRegistrationId(Context context) { final SharedPreferences prefs = getGCMPreferences(context); String registrationId = prefs.getString(PROPERTY_REG_ID, ""); // check if app was updated; if so, it must clear registration id to // avoid a race condition if GCM sends a message int oldVersion = prefs.getInt(PROPERTY_APP_VERSION, Integer.MIN_VALUE); int newVersion = getAppVersion(context); if (oldVersion != Integer.MIN_VALUE && oldVersion != newVersion) { Log.v(TAG, "App version changed from " + oldVersion + " to " + newVersion + "; resetting registration id"); clearRegistrationId(context); registrationId = ""; } return registrationId; }
From source file:com.wbtech.common.CommonUtil.java
/** * ?????/*from www. ja v a 2 s .c o m*/ * @param context * @return */ public static int getReportPolicyMode(Context context) { String str = context.getPackageName(); SharedPreferences localSharedPreferences = context.getSharedPreferences("ums_agent_online_setting_" + str, 0); int type = localSharedPreferences.getInt("ums_local_report_policy", 0); return type; }
From source file:com.dubsar_dictionary.Dubsar.model.Model.java
/** * Create or return the common HttpClient used by all model requests. * @return the HttpClient/*from ww w . j av a 2 s . co m*/ */ protected static HttpClient getClient() { if (sClient == null) { SharedPreferences preferences = getContext() .getSharedPreferences(PreferencesActivity.DUBSAR_PREFERENCES, Context.MODE_PRIVATE); String host = preferences.getString(PreferencesActivity.HTTP_PROXY_HOST, null); int port = preferences.getInt(PreferencesActivity.HTTP_PROXY_PORT, 0); // creates the client setProxy(host, port); } return sClient; }
From source file:com.nxp.ltsm.ltsmclient.tools.Utils.java
public static int loadInt(String name, Context mContext) { SharedPreferences prefs = mContext.getSharedPreferences(name, Context.MODE_PRIVATE); int savedCnt = prefs.getInt("chnl_cnt", 0); return savedCnt; }
From source file:com.nxp.ltsm.ltsmclient.tools.Utils.java
public static int[] loadArray(String arrayName, Context mContext) { int[] ret;// w ww .jav a2s . co m SharedPreferences prefs = mContext.getSharedPreferences(arrayName, Context.MODE_PRIVATE); int count = prefs.getInt("Count", 0); ret = new int[count]; for (int i = 0; i < count; i++) { ret[i] = prefs.getInt("IntValue_" + i, i); } return ret; }
From source file:fr.inria.ucn.Helpers.java
/** * @param c//www . j a v a 2s. c o m * @return <code>True</code> if user has enabled the night-time mode and current time is * within night, else <code>False</code>. */ public static boolean isNightTime(Context c) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c); if (!prefs.getBoolean(Constants.PREF_STOP_NIGHT, false)) return false; int nstart = prefs.getInt(Constants.PREF_NIGHT_START, 23 * 3600); int nstop = prefs.getInt(Constants.PREF_NIGHT_STOP, 6 * 3600); Calendar nightstart = Calendar.getInstance(); nightstart.roll(Calendar.HOUR_OF_DAY, -1 * nightstart.get(Calendar.HOUR_OF_DAY)); nightstart.roll(Calendar.MINUTE, -1 * nightstart.get(Calendar.MINUTE)); nightstart.roll(Calendar.SECOND, -1 * nightstart.get(Calendar.SECOND)); nightstart.roll(Calendar.MILLISECOND, -1 * nightstart.get(Calendar.MILLISECOND)); nightstart.add(Calendar.SECOND, nstart); Calendar nightstop = Calendar.getInstance(); nightstop.roll(Calendar.HOUR_OF_DAY, -1 * nightstop.get(Calendar.HOUR_OF_DAY)); nightstop.roll(Calendar.MINUTE, -1 * nightstop.get(Calendar.MINUTE)); nightstop.roll(Calendar.SECOND, -1 * nightstop.get(Calendar.SECOND)); nightstop.roll(Calendar.MILLISECOND, -1 * nightstop.get(Calendar.MILLISECOND)); nightstop.add(Calendar.SECOND, nstop); if (nightstop.before(nightstart)) nightstop.add(Calendar.HOUR, 24); Log.d(Constants.LOGTAG, "nightstart " + nstart + " -> " + nightstart.toString()); Log.d(Constants.LOGTAG, "nightstop " + nstop + " -> " + nightstop.toString()); Calendar now = Calendar.getInstance(); return (now.after(nightstart) && now.before(nightstop)); }
From source file:fr.inria.ucn.Helpers.java
/** * /*w w w . j a v a2 s.c om*/ * @param c * @return -1 if not at night-time (or feature disabled), else milliseconds until morning. */ public static long getNightEnd(Context c) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c); if (!prefs.getBoolean(Constants.PREF_STOP_NIGHT, false)) return -1; int nstart = prefs.getInt(Constants.PREF_NIGHT_START, 23 * 3600); int nstop = prefs.getInt(Constants.PREF_NIGHT_STOP, 6 * 3600); Calendar nightstart = Calendar.getInstance(); nightstart.roll(Calendar.HOUR_OF_DAY, -1 * nightstart.get(Calendar.HOUR_OF_DAY)); nightstart.roll(Calendar.MINUTE, -1 * nightstart.get(Calendar.MINUTE)); nightstart.roll(Calendar.SECOND, -1 * nightstart.get(Calendar.SECOND)); nightstart.roll(Calendar.MILLISECOND, -1 * nightstart.get(Calendar.MILLISECOND)); nightstart.add(Calendar.SECOND, nstart); Calendar nightstop = Calendar.getInstance(); nightstop.roll(Calendar.HOUR_OF_DAY, -1 * nightstop.get(Calendar.HOUR_OF_DAY)); nightstop.roll(Calendar.MINUTE, -1 * nightstop.get(Calendar.MINUTE)); nightstop.roll(Calendar.SECOND, -1 * nightstop.get(Calendar.SECOND)); nightstop.roll(Calendar.MILLISECOND, -1 * nightstop.get(Calendar.MILLISECOND)); nightstop.add(Calendar.SECOND, nstop); if (nightstop.before(nightstart)) nightstop.add(Calendar.HOUR, 24); Log.d(Constants.LOGTAG, "nightstart " + nstart + " -> " + nightstart.toString()); Log.d(Constants.LOGTAG, "nightstop " + nstop + " -> " + nightstop.toString()); Calendar now = Calendar.getInstance(); if (now.after(nightstart) && now.before(nightstop)) { return nightstop.getTimeInMillis(); } else { return -1; } }