List of usage examples for android.content SharedPreferences getInt
int getInt(String key, int defValue);
From source file:com.cmgapps.android.util.CMGAppRater.java
private static String ratePreferenceToString(SharedPreferences pref) { JSONObject thiz = new JSONObject(); try {/* www . j a va2 s . c o m*/ thiz.put(DECLINED_RATE, pref.getBoolean(DECLINED_RATE, false)); thiz.put(APP_RATED, pref.getBoolean(APP_RATED, false)); thiz.put(TRACKING_VERSION, pref.getInt(TRACKING_VERSION, -1)); thiz.put(FIRST_USE, SimpleDateFormat.getDateTimeInstance().format(new Date(pref.getLong(FIRST_USE, 0L)))); thiz.put(USE_COUNT, pref.getInt(USE_COUNT, 0)); thiz.put(REMIND_LATER_DATE, SimpleDateFormat.getDateTimeInstance().format(new Date(pref.getLong(REMIND_LATER_DATE, 0L)))); } catch (JSONException exc) { LOGE(TAG, "Error creating JSON Object", exc); } return thiz.toString(); }
From source file:net.peterkuterna.android.apps.devoxxsched.service.SyncService.java
/** * Should we perform a remote sync?//from w w w . j av a 2 s . c om */ private static boolean performRemoteSync(ContentResolver resolver, HttpClient httpClient, Intent intent, Context context) { final SharedPreferences settingsPrefs = context.getSharedPreferences(SettingsActivity.SETTINGS_NAME, MODE_PRIVATE); final SharedPreferences syncServicePrefs = context.getSharedPreferences(SyncPrefs.DEVOXXSCHED_SYNC, Context.MODE_PRIVATE); final boolean onlySyncWifi = settingsPrefs.getBoolean(context.getString(R.string.sync_only_wifi_key), false); final int localVersion = syncServicePrefs.getInt(SyncPrefs.LOCAL_VERSION, VERSION_NONE); if (!onlySyncWifi || isWifiConnected(context)) { final boolean remoteParse = localVersion < VERSION_REMOTE; final boolean forceRemoteRefresh = intent.getBooleanExtra(EXTRA_FORCE_REFRESH, false); final boolean hasContentChanged = hasContentChanged(resolver, httpClient); return remoteParse || forceRemoteRefresh || hasContentChanged; } return false; }
From source file:com.ntsync.android.sync.shared.SyncUtils.java
/** * Create a new Account and activate the automatic sync * //from w w w. j ava 2 s . c om * @param account * null is not allowed * @param accountManager * null is not allowed * @param password * null is not allowed */ public static boolean createAccount(Context context, final Account account, AccountManager accountManager, String password) { boolean added = accountManager.addAccountExplicitly(account, password, null); if (added) { List<PeriodicSync> syncs = ContentResolver.getPeriodicSyncs(account, ContactsContract.AUTHORITY); if (syncs != null) { // Remove default syncs. for (PeriodicSync periodicSync : syncs) { ContentResolver.removePeriodicSync(account, ContactsContract.AUTHORITY, periodicSync.extras); } } SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context); int synctime; try { synctime = settings.getInt("pref_synctime", DEFAULT_SYNCINTERVAL); } catch (ClassCastException e) { LogHelper.logI(TAG, "Invalid SyncTime-Settingvalue", e); synctime = DEFAULT_SYNCINTERVAL; } if (synctime != 0) { addPeriodicSync(ContactsContract.AUTHORITY, Bundle.EMPTY, synctime, context); } // Set contacts sync for this account. ContentResolver.setSyncAutomatically(account, ContactsContract.AUTHORITY, true); } else { LogHelper.logI(TAG, "Account " + account.name + " is already available."); } return added; }
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 www . j a va2s .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(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:fr.shywim.antoinedaniel.utils.GcmUtils.java
public static String getRegistrationId(Context context) { final SharedPreferences prefs = context.getSharedPreferences(AppConstants.GOOGLE_PREFS, Context.MODE_PRIVATE); String registrationId = prefs.getString(AppConstants.GOOGLE_GCM_REGID, ""); if (registrationId.isEmpty()) { return ""; }// w w w . j ava2 s . 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(AppConstants.GOOGLE_GCM_APPVER, Integer.MIN_VALUE); int currentVersion = Utils.getAppVersion(context); if (registeredVersion != currentVersion) { return ""; } return registrationId; }
From source file:de.schaeuffelhut.android.openvpn.Preferences.java
public final static boolean applicationWasUpdated(Context context) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); int applicationVersionCode = Util.applicationVersionCode(context); int storedVersionCode = sharedPreferences.getInt(KEY_OPENVPN_VERSION_CODE, -1); final boolean wasUpdated = applicationVersionCode > storedVersionCode; if (wasUpdated) sharedPreferences.edit().putInt(KEY_OPENVPN_VERSION_CODE, applicationVersionCode).commit(); return wasUpdated; }
From source file:com.smarthome.deskclock.Alarms.java
private static void clearSnoozePreference(final Context context, final SharedPreferences prefs) { final int alarmId = prefs.getInt(PREF_SNOOZE_ID, -1); if (alarmId != -1) { NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); nm.cancel(alarmId);/*from w w w .j a v a 2 s.c o m*/ } final SharedPreferences.Editor ed = prefs.edit(); ed.remove(PREF_SNOOZE_ID); ed.remove(PREF_SNOOZE_TIME); ed.apply(); }
From source file:com.tagaugmentedreality.utilties.Utilities.java
public static Object getSharedPreferences(Context context, String key, char type) { /**/* www . ja v a 2 s. c om*/ * s: String i: Integer b: Boolean l: Long f: Float */ SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0); if ('s' == type) { return (Object) settings.getString(key, ""); } // end if else if ('i' == type) { return (Object) settings.getInt(key, 0); } // end else if else if ('b' == type) { return (Object) settings.getBoolean(key, false); } // end else if else if ('l' == type) { return (Object) settings.getLong(key, 0); } // end else if else if ('f' == type) { return (Object) settings.getFloat(key, 0.0f); } // end else if else { return null; } // end else }
From source file:com.memetro.android.notifications.NotificationUtils.java
/** * Gets the current registration id for application on GCM service. * <p>// www. j a va 2 s.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, ""); if (registrationId.length() == 0) { Log.v(TAG, "Registration not found."); return ""; } // check if app was updated; if so, it must clear registration id to // avoid a race condition if GCM sends a message int registeredVersion = prefs.getInt(PROPERTY_APP_VERSION, Integer.MIN_VALUE); int currentVersion = getAppVersion(context); if (registeredVersion != currentVersion || isRegistrationExpired(context)) { Log.v(TAG, "App version changed or registration expired."); return ""; } return registrationId; }
From source file:com.smarthome.deskclock.Alarms.java
/** * Disable the snooze alert if the given id matches the snooze id. */// w w w . j ava2s . co m static void disableSnoozeAlert(final Context context, final int id) { SharedPreferences prefs = context.getSharedPreferences(AlarmClock.PREFERENCES, 0); int snoozeId = prefs.getInt(PREF_SNOOZE_ID, -1); if (snoozeId == -1) { // No snooze set, do nothing. return; } else if (snoozeId == id) { // This is the same id so clear the shared prefs. clearSnoozePreference(context, prefs); } }