List of usage examples for android.content SharedPreferences getLong
long getLong(String key, long defValue);
From source file:org.gnucash.android.ui.widget.WidgetConfigurationActivity.java
/** * Updates all widgets belonging to the application * @param context Application context/*from w w w. j av a 2 s . c om*/ */ public static void updateAllWidgets(Context context) { Log.i("WidgetConfiguration", "Updating all widgets"); AppWidgetManager widgetManager = AppWidgetManager.getInstance(context); ComponentName componentName = new ComponentName(context, TransactionAppWidgetProvider.class); int[] appWidgetIds = widgetManager.getAppWidgetIds(componentName); SharedPreferences defaultSharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); for (int widgetId : appWidgetIds) { long accountId = defaultSharedPrefs.getLong(UxArgument.SELECTED_ACCOUNT_ID + widgetId, -1); if (accountId <= 0) continue; updateWidget(context, widgetId, accountId); } }
From source file:se.erichansander.retrotimer.RetroTimer.java
/** * Initializes the app state, and initializes the AlarmManager if any alarms * are pending from before the device was rebooted. * //from w w w. j a v a 2 s . c o m * Should be called at device boot and at application start (in case the app * has been killed). */ public static void initAlarm(Context context) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); if (prefs.getBoolean(PREF_ALARM_SET, false) || prefs.getLong(PREF_ALARM_TIME, 0) > 0) { if (getMillisLeftToAlarm(context) > 1000) { /* * If there is time left until the alarm should trigger, we * register it again with the AlarmManager */ setAlarmAt(context, prefs.getLong(PREF_ALARM_TIME, 0)); } else { /* Otherwise, we do some clean-up */ clearAlarm(context); } } }
From source file:com.vonglasow.michael.satstat.GpsEventReceiver.java
/** * Refreshes AGPS data if necessary.//ww w.j a v a 2 s . c o m * * This method requests a refresh of the AGPS data. It optionally does so * only after checking when the AGPS data was last refreshed and * determining if it is stale by adding the refresh interval specified in * the user preferences and comparing the result against the current time. * If the result is less than current time, AGPS data is considered stale * and a refresh is requested. * * @param context A {@link Context} to be passed to {@link LocationManager}. * @param enforceInterval If true, prevents updates when the interval has * not yet expired. If false, updates are permitted at any time. This is to * prevent race conditions if alarms fire off too early. * @param wantFeedback Whether to display a toast informing the user about * the success of the operation. */ public static void refreshAgps(Context context, boolean enforceInterval, boolean wantFeedback) { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context); long last = sharedPref.getLong(Const.KEY_PREF_UPDATE_LAST, 0); long freqDays = Long.parseLong(sharedPref.getString(Const.KEY_PREF_UPDATE_FREQ, "0")); long now = System.currentTimeMillis(); if (enforceInterval && (last + freqDays * Const.MILLIS_PER_DAY > now)) return; //Log.d(GpsEventReceiver.class.getSimpleName(), String.format("refreshAgps, enforceInterval: %b, wantFeedback: %b", enforceInterval, wantFeedback)); if (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) new AgpsUpdateTask(wantFeedback).execute(context, mAgpsIntent, sharedPref, freqDays * Const.MILLIS_PER_DAY); else { Log.i(TAG, "Requesting permissions to update AGPS data"); PermissionHelper.requestPermissions((SatStatApplication) (context.getApplicationContext()), new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, Const.PERM_REQUEST_LOCATION_NOTIFICATION, context.getString(R.string.notify_perm_title), context.getString(R.string.notify_perm_body), R.drawable.ic_security); } }
From source file:com.owncloud.android.AppRater.java
public static void appLaunched(Context mContext, String packageName) { SharedPreferences prefs = mContext.getSharedPreferences(APP_RATER_PREF_TITLE, 0); if (prefs.getBoolean(APP_RATER_PREF_DONT_SHOW, false)) { return;//ww w .j a va 2s . com } SharedPreferences.Editor editor = prefs.edit(); /// Increment launch counter long launchCount = prefs.getLong(APP_RATER_PREF_LAUNCH_COUNT, 0) + 1; editor.putLong(APP_RATER_PREF_LAUNCH_COUNT, launchCount); /// Get date of first launch Long dateFirstLaunch = prefs.getLong(APP_RATER_PREF_DATE_FIRST_LAUNCH, 0); if (dateFirstLaunch == 0) { dateFirstLaunch = System.currentTimeMillis(); editor.putLong(APP_RATER_PREF_DATE_FIRST_LAUNCH, dateFirstLaunch); } /// Get date of neutral click Long dateNeutralClick = prefs.getLong(APP_RATER_PREF_DATE_NEUTRAL, 0); /// Wait at least n days before opening if (launchCount >= LAUNCHES_UNTIL_PROMPT) { if (System.currentTimeMillis() >= Math.max(dateFirstLaunch + daysToMilliseconds(DAYS_UNTIL_PROMPT), dateNeutralClick + daysToMilliseconds(DAYS_UNTIL_NEUTRAL_CLICK))) { showRateDialog(mContext, packageName, false); } } editor.apply(); }
From source file:se.erichansander.retrotimer.RetroTimer.java
/** Returns millis left to alarm, or zero if no alarm is set */ public static long getMillisLeftToAlarm(Context context) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); if (prefs.getBoolean(RetroTimer.PREF_ALARM_SET, false)) { return prefs.getLong(RetroTimer.PREF_ALARM_TIME, 0) - System.currentTimeMillis(); } else {/* ww w.j a va 2 s .c om*/ return 0; } }
From source file:se.erichansander.retrotimer.RetroTimer.java
/** * Returns the absolute time when alarm will trigger, in millis since epoch *//*from w ww .jav a 2 s.c o m*/ public static long getAlarmTime(Context context) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); if (prefs.getBoolean(RetroTimer.PREF_ALARM_SET, false)) { return prefs.getLong(RetroTimer.PREF_ALARM_TIME, 0); } else { return 0; } }
From source file:com.neuron.trafikanten.HelperFunctions.java
private static void updateStatistics(Context context, long size) { if (size == 0) return;/*from w w w . j a v a 2 s. co m*/ final SharedPreferences preferences = context.getSharedPreferences("trafikantenandroid", Context.MODE_PRIVATE); Long downloadByte = preferences.getLong(KEY_DOWNLOADBYTE, 0) + size; final SharedPreferences.Editor editor = preferences.edit(); editor.putLong(KEY_DOWNLOADBYTE, downloadByte); editor.commit(); }
From source file:com.lloydtorres.stately.push.TrixHelper.java
/** * Returns the stored last active time, in Unix seconds. * @param c App context./* w w w . j a v a 2 s . c o m*/ */ public static long getLastActiveTime(Context c) { SharedPreferences storage = PreferenceManager.getDefaultSharedPreferences(c); return storage.getLong(KEY_LASTACTIVITY, System.currentTimeMillis() / 1000L); }
From source file:org.catnut.plugin.fantasy.Photo.java
public static boolean shouldRefresh() { CatnutApp app = CatnutApp.getTingtingApp(); SharedPreferences pref = app.getPreferences(); return !pref.contains(app.getString(R.string.pref_first_run)) ? true : pref.getBoolean(app.getString(R.string.pref_enable_fantasy), app.getResources().getBoolean(R.bool.default_plugin_status)) && System.currentTimeMillis() - pref.getLong(LAST_FANTASY_MILLIS, 0) > DateTime.DAY_MILLIS; }
From source file:com.jdom.ajatt.viewer.util.HtmlUtil.java
public static String getRequest(Activity activity, final String url) { SharedPreferences prefs = activity.getSharedPreferences(CLASS_NAME, Context.MODE_PRIVATE); String cachedUrlContents = prefs.getString(url, null); String urlRetrievalTimeKey = url + ".time"; long cachedUrlRetrievalTime = prefs.getLong(urlRetrievalTimeKey, 0L); long ageOfCachedData = System.currentTimeMillis() - cachedUrlRetrievalTime; if (cachedUrlRetrievalTime == 0) { Log.d(CLASS_NAME, "Did not find cached data for URL [" + url + "]."); } else {// w w w . j a v a2 s .com Log.d(CLASS_NAME, "URL [" + url + "] has been cached for [" + ageOfCachedData + "] ms."); } Future<String> result = null; boolean expired = ageOfCachedData > CACHE_URL_MILLISECONDS; if (expired) { Log.d(CLASS_NAME, "URL [" + url + "] data is stale."); } else { long timeRemainingValidCache = CACHE_URL_MILLISECONDS - ageOfCachedData; Log.d(CLASS_NAME, "URL [" + url + "] data has [" + timeRemainingValidCache + "] ms of validity remaining."); } if (cachedUrlContents == null || expired) { Callable<String> callable = new Callable<String>() { public String call() throws Exception { long start = System.currentTimeMillis(); Log.d(CLASS_NAME, "Retrieving URL [" + url + "]."); HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(url); try { HttpResponse response = client.execute(request); return HttpHelper.request(response); } catch (Exception ex) { Log.e(CLASS_NAME, "Failure to retrieve the url!", ex); return null; } finally { Log.d(CLASS_NAME, "Retrieving URL [" + url + "] took [" + (System.currentTimeMillis() - start) + "] ms to retrieve."); } } }; ExecutorService executor = Executors.newSingleThreadExecutor(); result = executor.submit(callable); } if (cachedUrlContents == null) { try { cachedUrlContents = result.get(); Editor editor = prefs.edit(); editor.putLong(urlRetrievalTimeKey, System.currentTimeMillis()); editor.putString(url, cachedUrlContents); editor.commit(); } catch (Exception e) { Log.e(CLASS_NAME, "Failure to retrieve the url!", e); } } return cachedUrlContents; }