List of usage examples for android.content SharedPreferences getLong
long getLong(String key, long defValue);
From source file:net.zionsoft.obadiah.model.utils.AppUpdateChecker.java
@Override protected void onHandleIntent(Intent intent) { try {/*w ww . j a va 2 s . co m*/ // we only check if at least 24 hours is passed final SharedPreferences preferences = getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE); final long now = System.currentTimeMillis(); final long lastCheckedTimestamp = preferences .getLong(Constants.PREF_KEY_CHECKED_APPLICATION_VERSION_TIMESTAMP, 0); if (now - lastCheckedTimestamp < DateUtils.DAY_IN_MILLIS) { return; } // we only check if the user has active WiFi or WiMAX final NetworkInfo networkInfo = ((ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE)) .getActiveNetworkInfo(); if (networkInfo == null || !networkInfo.isConnected()) { return; } final int networkType = networkInfo.getType(); if (networkType != ConnectivityManager.TYPE_WIFI && networkType != ConnectivityManager.TYPE_WIMAX) { return; } final String response = new String(NetworkHelper.get(NetworkHelper.CLIENT_VERSION_URL), "UTF-8"); final JSONObject versionObject = new JSONObject(response); final int latestVersion = versionObject.getInt("versionCode"); final SharedPreferences.Editor editor = preferences.edit(); if (latestVersion < preferences.getInt(Constants.PREF_KEY_CHECKED_APPLICATION_VERSION, 0)) { editor.putInt(Constants.PREF_KEY_CHECKED_APPLICATION_VERSION, latestVersion) .putBoolean(Constants.PREF_KEY_ASKED_APPLICATION_UPDATE, false); } editor.putLong(Constants.PREF_KEY_CHECKED_APPLICATION_VERSION_TIMESTAMP, now).apply(); } catch (Exception e) { Crashlytics.logException(e); } }
From source file:cm.aptoide.com.facebook.android.Facebook.java
/** * This function does the heavy lifting of publishing an install. * @param fb/* ww w . ja v a 2s .c o m*/ * @param applicationId * @param context * @throws Exception */ private static void publishInstall(final Facebook fb, final String applicationId, final Context context) throws JSONException, FacebookError, MalformedURLException, IOException { String attributionId = Facebook.getAttributionId(context.getContentResolver()); SharedPreferences preferences = context.getSharedPreferences(ATTRIBUTION_PREFERENCES, Context.MODE_PRIVATE); String pingKey = applicationId + "ping"; long lastPing = preferences.getLong(pingKey, 0); if (lastPing == 0 && attributionId != null) { Bundle supportsAttributionParams = new Bundle(); supportsAttributionParams.putString(APPLICATION_FIELDS, SUPPORTS_ATTRIBUTION); JSONObject supportResponse = Util.parseJson(fb.request(applicationId, supportsAttributionParams)); Object doesSupportAttribution = (Boolean) supportResponse.get(SUPPORTS_ATTRIBUTION); if (!(doesSupportAttribution instanceof Boolean)) { throw new JSONException(String.format("%s contains %s instead of a Boolean", SUPPORTS_ATTRIBUTION, doesSupportAttribution)); } if ((Boolean) doesSupportAttribution) { Bundle publishParams = new Bundle(); publishParams.putString(ANALYTICS_EVENT, MOBILE_INSTALL_EVENT); publishParams.putString(ATTRIBUTION_KEY, attributionId); String publishUrl = String.format(PUBLISH_ACTIVITY_PATH, applicationId); fb.request(publishUrl, publishParams, "POST"); // denote success since no error threw from the post. SharedPreferences.Editor editor = preferences.edit(); editor.putLong(pingKey, System.currentTimeMillis()); editor.commit(); } } }
From source file:org.godotengine.godot.utils.HttpRequester.java
public long getResponseTtl(String request) { SharedPreferences sharedPref = context.getSharedPreferences("http_get_cache", Context.MODE_PRIVATE); return sharedPref.getLong("request_" + Crypt.md5(request) + "_ttl", 0l); }
From source file:com.sean.takeastand.alarmprocess.ScheduledRepeatingAlarm.java
private long getNextAlarmTimeMillis() { SharedPreferences sharedPreferences = mContext.getSharedPreferences(Constants.EVENT_SHARED_PREFERENCES, 0); return sharedPreferences.getLong(Constants.NEXT_ALARM_TIME_MILLIS, -1); }
From source file:edu.tsinghua.hotmobi.UploadLogsTask.java
@Override public void run() { final SharedPreferences prefs = context.getSharedPreferences("spice_data_profiling", Context.MODE_PRIVATE); if (prefs.contains(HotMobiLogger.LAST_UPLOAD_TIME)) { final long lastUpload = prefs.getLong(HotMobiLogger.LAST_UPLOAD_TIME, System.currentTimeMillis()); final double deltaDays = (System.currentTimeMillis() - lastUpload) / (double) HotMobiLogger.UPLOAD_INTERVAL_MILLIS; if (deltaDays < 1) { SpiceProfilingUtil.log("Last uploaded was conducted in 1 day ago."); return; }/*from ww w . j a va 2s .c o m*/ } if (uploadLogs()) { prefs.edit().putLong(HotMobiLogger.LAST_UPLOAD_TIME, System.currentTimeMillis()).apply(); } }
From source file:org.jraf.android.hellomundo.app.saveshare.SaveShareHelper.java
@Background(Type.DISK) private long getCurrentWallpaperWebcamId(Context context) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); final long currentWebcamId = preferences.getLong(Constants.PREF_CURRENT_WEBCAM_ID, Constants.PREF_SELECTED_WEBCAM_ID_DEFAULT); return currentWebcamId; }
From source file:info.tongrenlu.MainActivity.java
private void initUser(Context context) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); Long id = sharedPreferences.getLong("userId", 0); String defaultNickname = getString(R.string.guest); String nickname = sharedPreferences.getString("nickname", defaultNickname); mUser = new UserBean(); mUser.setId(id);/*ww w.ja v a 2 s . c o m*/ mUser.setNickname(nickname); }
From source file:pl.mrwojtek.sensrec.app.SamplingPeriodDialog.java
private void setFromPreferences() { // Mark as initializing to disable focus override on start initializing = true;//from w w w .jav a 2 s .c o m SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); long delay = prefs.getLong(SensorsRecorder.PREF_SAMPLING_PERIOD, SensorsRecorder.DEFAULT_SAMPLING_PERIOD); int position = getSamplingPosition(delay); samplingSpinner.setSelection(position); // If set to custom then set edit text value if (position == POSITION_CUSTOM) { millisecondsEdit.setText(String.format("%d", delay)); } else { millisecondsEdit.setText(""); } }
From source file:org.jraf.android.hellomundo.app.pickwebcam.PickWebcamActivity.java
@Override public void onClickPositive(int tag, Object payload) { final long id = (Long) payload; new TaskFragment(new Task<PickWebcamActivity>() { @Override/*from w ww.j a v a 2s.c o m*/ protected void doInBackground() throws Throwable { getContentResolver().delete(ContentUris.withAppendedId(WebcamColumns.CONTENT_URI, id), null, null); // Check if the selected cam is the one we just deleted, if yes set the eiffel tower one SharedPreferences sharedPreferences = PreferenceManager .getDefaultSharedPreferences(PickWebcamActivity.this); long selectedWebcamId = sharedPreferences.getLong(Constants.PREF_SELECTED_WEBCAM_ID, Constants.PREF_SELECTED_WEBCAM_ID_DEFAULT); if (id == selectedWebcamId) { Log.d("User deleted currently selected webcam: reset to defaults"); Editor editor = sharedPreferences.edit(); editor.putLong(Constants.PREF_SELECTED_WEBCAM_ID, Constants.PREF_SELECTED_WEBCAM_ID_DEFAULT); editor.putLong(Constants.PREF_CURRENT_WEBCAM_ID, Constants.PREF_SELECTED_WEBCAM_ID_DEFAULT); editor.commit(); // Invoke service to download the default image now. HelloMundoService.updateWallpaperNow(PickWebcamActivity.this); } } }.toastOk(R.string.pickWebcam_webcamDeletedToast)).execute(getSupportFragmentManager()); }
From source file:com.mgalgs.trackthatthing.LocationReceiver.java
@Override public void onReceive(Context context, Intent intent) { mContext = context;//from ww w. ja va 2 s .c o m Location loc = (Location) intent.getExtras().get(LocationPoller.EXTRA_LOCATION); if (loc == null) { msg = intent.getStringExtra(LocationPoller.EXTRA_ERROR); } else { SharedPreferences settings = context.getSharedPreferences(TrackThatThing.PREFS_NAME, Context.MODE_PRIVATE); long sleep_period = settings.getLong(TrackThatThing.PREF_SLEEP_TIME, TrackThatThing.DEFAULT_SLEEP_TIME); if (getTimeSinceLastLoc_S() > sleep_period - 3 || mLastLocTime == -1) { // it has been long enough } else { // it hasn't been long enough! Log.d(TrackThatThing.TAG, "It has only been " + getTimeSinceLastLoc_S() + " seconds since the last location update, not long enough!"); return; } mLastLocTime = SystemClock.elapsedRealtime(); float acc = loc.getAccuracy(); double lat = loc.getLatitude(); double lon = loc.getLongitude(); float speed = loc.getSpeed(); String secret_code = settings.getString(TrackThatThing.PREF_SECRET_CODE, null); QueryString qs = new QueryString(TrackThatThing.BASE_URL + "/put"); qs.add("secret", secret_code); qs.add("lat", Double.toString(lat)); qs.add("lon", Double.toString(lon)); qs.add("acc", Float.toString(acc)); qs.add("speed", Float.toString(speed)); Runnable r = new MyInternetThread(qs); new Thread(r).start(); msg = loc.toString(); } Log.d(TrackThatThing.TAG, "got this location: " + msg); }