List of usage examples for android.content SharedPreferences getLong
long getLong(String key, long defValue);
From source file:com.cbsb.ftpserv.ProxyConnector.java
long getPersistedProxyUsage() { // This gets the last persisted value for bytes transferred through // the proxy. It can be out of date since it doesn't include data // transferred during the current session. SharedPreferences prefs = Globals.getContext().getSharedPreferences(USAGE_PREFS_NAME, 0); // 0 == private return prefs.getLong(USAGE_PREFS_NAME, 0); // Default count of 0 }
From source file:com.secretparty.app.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); SharedPreferences prefs = this.getPreferences(MODE_PRIVATE); thematicRepo = ((SecretPartyApplication) getApplication()).getThematicRepository(); api = ((SecretPartyApplication) getApplication()).getApiService(); //TODO : check if thematics are in the database. If so, launch a ThematicFragment. Otherwise, download them, save them to the db and launch TheamticFragment int userId = prefs.getInt(getString(R.string.SP_user_id), -1); int partyId = prefs.getInt(getString(R.string.SP_party_id), -1); long partyEnd = prefs.getLong(getString(R.string.SP_date_party_end), -1); Log.v("creation", new Date(partyEnd).toLocaleString() + ""); api.listThematics(new OnReceivedThematics()); if (userId == -1) { DialogFragment df = new UserCreationDialog(); df.setCancelable(false);/*from ww w. j ava2s.c o m*/ df.show(getSupportFragmentManager(), "dialog"); } }
From source file:com.nextgis.ngm_clink_monitoring.fragments.MapFragment.java
@Override public void onResume() { super.onResume(); GISApplication app = (GISApplication) getActivity().getApplication(); if (null != mGpsEventSource) { mGpsEventSource.addListener(this); }// w w w . j a va2 s .c o m mCurrentCenter = null; if (null != mMapView) { mMapView.addListener(this); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); float mapZoom = prefs.getFloat(FoclSettingsConstantsUI.KEY_PREF_ZOOM_LEVEL, mMapView.getMinZoom()); double mapScrollX = Double .longBitsToDouble(prefs.getLong(FoclSettingsConstantsUI.KEY_PREF_SCROLL_X, 0)); double mapScrollY = Double .longBitsToDouble(prefs.getLong(FoclSettingsConstantsUI.KEY_PREF_SCROLL_Y, 0)); mMapView.setZoomAndCenter(mapZoom, new GeoPoint(mapScrollX, mapScrollY)); //change zoom controls visibility boolean showControls = prefs.getBoolean(FoclSettingsConstantsUI.KEY_PREF_SHOW_ZOOM_CONTROLS, false); if (showControls) { addMapButtons(); } else { removeMapButtons(); } if (null != mCurrentLocationOverlay) { mCurrentLocationOverlay.updateMode(app.getLocationOverlayMode()); mCurrentLocationOverlay.startShowingCurrentLocation(); mMapView.addOverlay(mCurrentLocationOverlay); } if (null != mGpsEventSource && onMenuMapClicked) { onMenuMapClicked = false; Location lastLocation = mGpsEventSource.getLastKnownLocation(); setCurrentCenter(lastLocation); locateCurrentPositionAndZoom(false, lastLocation); } /// TODO: ??? // mMapView.drawMapDrawable(); } }
From source file:id.ridon.keude.UpdateService.java
/** * Check whether it is time to run the scheduled update. * We don't want to run if://w w w. j av a2s . c o m * - The time between scheduled runs is set to zero (though don't know * when that would occur) * - Last update was too recent * - Not on wifi, but the property for "Only auto update on wifi" is set. * @return True if we are due for a scheduled update. */ private boolean verifyIsTimeForScheduledRun() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); long lastUpdate = prefs.getLong(Preferences.PREF_UPD_LAST, 0); String sint = prefs.getString(Preferences.PREF_UPD_INTERVAL, "0"); int interval = Integer.parseInt(sint); if (interval == 0) { Log.d("Keude", "Skipping update - disabled"); return false; } long elapsed = System.currentTimeMillis() - lastUpdate; if (elapsed < interval * 60 * 60 * 1000) { Log.d("Keude", "Skipping update - done " + elapsed + "ms ago, interval is " + interval + " hours"); return false; } // If we are to update the repos only on wifi, make sure that // connection is active if (prefs.getBoolean(Preferences.PREF_UPD_WIFI_ONLY, false)) { ConnectivityManager conMan = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo.State wifi = conMan.getNetworkInfo(1).getState(); if (wifi != NetworkInfo.State.CONNECTED && wifi != NetworkInfo.State.CONNECTING) { Log.d("Keude", "Skipping update - wifi not available"); return false; } } return true; }
From source file:org.fdroid.fdroid.UpdateService.java
/** * Check whether it is time to run the scheduled update. * We don't want to run if:/*w w w . j av a 2 s . c o m*/ * - The time between scheduled runs is set to zero (though don't know * when that would occur) * - Last update was too recent * - Not on wifi, but the property for "Only auto update on wifi" is set. * * @return True if we are due for a scheduled update. */ private boolean verifyIsTimeForScheduledRun() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); String sint = prefs.getString(Preferences.PREF_UPD_INTERVAL, "0"); int interval = Integer.parseInt(sint); if (interval == 0) { Log.i(TAG, "Skipping update - disabled"); return false; } long lastUpdate = prefs.getLong(STATE_LAST_UPDATED, 0); long elapsed = System.currentTimeMillis() - lastUpdate; if (elapsed < interval * 60 * 60 * 1000) { Log.i(TAG, "Skipping update - done " + elapsed + "ms ago, interval is " + interval + " hours"); return false; } return isNetworkAvailableForUpdate(this); }
From source file:com.karma.konnect.PwoDiscoveryService.java
private void restoreCache() { // Make sure we are trying to load the right version of the cache String preferencesKey = getString(R.string.discovery_service_prefs_key); SharedPreferences prefs = getSharedPreferences(preferencesKey, Context.MODE_PRIVATE); int prefsVersion = prefs.getInt(PREFS_VERSION_KEY, 0); long now = new Date().getTime(); if (prefsVersion != PREFS_VERSION) { mScanStartTime = now;// w ww . j a v a2 s . c o m return; } // Don't load the cache if it's stale mScanStartTime = prefs.getLong(SCAN_START_TIME_KEY, 0); if (now - mScanStartTime >= SCAN_STALE_TIME_MILLIS) { mScanStartTime = now; return; } // Restore the cached metadata Set<String> serializedPwoMetadata = prefs.getStringSet(PWO_METADATA_KEY, new HashSet<String>()); for (String pwoMetadataStr : serializedPwoMetadata) { PwoMetadata pwoMetadata; try { pwoMetadata = PwoMetadata.fromJsonStr(pwoMetadataStr); } catch (JSONException e) { Log.e(TAG, "Could not deserialize PWO cache item: " + e); continue; } onPwoDiscovered(pwoMetadata); if (pwoMetadata.hasBleMetadata()) { pwoMetadata.bleMetadata.updateRegionInfo(); } } }
From source file:com.juick.android.ThreadActivity.java
/** * @param prefetchedReply nullable, for prefetch mode only * @param drafts oh/* w ww.ja v a2 s . c o m*/ * @param q draft index */ private void pullDraft(JuickMessage prefetchedReply, SharedPreferences drafts, int q) { final long savedRid = drafts.getLong("rid" + q, 0); boolean matchingRid = prefetchedReply == null; for (int msg = 0; msg < tf.getListView().getAdapter().getCount(); msg++) { final Object item = tf.getListView().getAdapter().getItem(msg); if (item instanceof JuickMessage) { JuickMessage someReply = (JuickMessage) item; if (someReply.getRID() == savedRid) { onReplySelected(someReply); if (prefetchedReply != null && prefetchedReply.getRID() == someReply.getRID()) { matchingRid = true; } break; } } } if (matchingRid) { etMessage.setText(pulledDraft = drafts.getString("message" + q, null)); pulledDraftMid = drafts.getString("mid" + q, null); pulledDraftRid = drafts.getLong("rid" + q, 0); pulledDraftTs = drafts.getLong("timestamp" + q, 0); etMessage.requestFocus(); drafts.edit().remove("message" + q).remove("timestamp" + q).remove("rid" + q).remove("mid" + q) .commit(); } }
From source file:se.hakanostrom.traveldiary.DEPRECATED.Internet.java
private long readHash() { SharedPreferences settings = mContext.getSharedPreferences("InternetPreferences", 0); SharedPreferences.Editor prefEditor = settings.edit(); // If it does not exists i shared prefs? if (!settings.contains("hash")) { // Create and write it prefEditor.putLong("hash", System.currentTimeMillis()); // prefEditor.putLong("hash", 42); prefEditor.commit();//from www . ja va2s . c o m } // Fetch and return it return settings.getLong("hash", 0); }
From source file:com.cybrosys.currency.CurrencyMain.java
public void onStart() { super.onStart(); getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); linlaHeaderProgress = (LinearLayout) getView().findViewById(R.id.linlaHeaderProgress); imgvHead = (ImageView) getView().findViewById(R.id.imageHead); txtvHead = (TextView) getView().findViewById(R.id.textHead); lstvMainlistView = (ListView) getView().findViewById(R.id.listview); etxtText = (EditText) getView().findViewById(R.id.editText1); slide = (SlidingDrawer) getView().findViewById(R.id.SlidingDrawer); TableLayout tablePad = (TableLayout) getView().findViewById(R.id.tablone); int inPadCount = tablePad.getChildCount(); for (int i = 0; i < inPadCount; i++) { View v = tablePad.getChildAt(i); if (v instanceof TableRow) { TableRow row = (TableRow) v; int rowCount = row.getChildCount(); for (int r = 0; r < rowCount; r++) { View v2 = row.getChildAt(r); if (v2 instanceof Button) { Button b = (Button) v2; b.setOnClickListener(buttonpad); } else if (v2 instanceof TextView) { TextView txtv = (TextView) v2; txtv.setOnClickListener(null); }//from w ww. j a v a 2s . c om } } } isFlag2 = true; Settings = getActivity().getSharedPreferences(strPREFERNAME, 0); for (int inI = 0; inI <= 5; inI++) { if (Settings.getString("val" + inI, "").equals("") && Settings.getString("CrnCode" + inI, "").equals("") && Settings.getString("flag" + inI, "").equals("")) { isFlag2 = false; } } if (isFlag2 == true) { Sharepreferences(); } else { CustomListView(); if (isConnection() == true) { } else { isFlag2 = true; isFlag = true; Toast.makeText(getActivity(), "No Internet Conection", Toast.LENGTH_LONG).show(); } } SharedPreferences prefs = PalmCalcActivity.ctx.getSharedPreferences("UpdateTime", 0); lastUpdateTime = prefs.getLong("lastUpdateTime", 0); if ((lastUpdateTime) <= System.currentTimeMillis()) { lastUpdateTime = System.currentTimeMillis(); SharedPreferences.Editor editors = prefs.edit(); editors.putLong("lastUpdateTime", lastUpdateTime); editors.commit(); if (isConnection() == true) { new BackProsess().execute(getActivity()); } } etxtText.addTextChangedListener(textwach); aList = new ArrayList<HashMap<String, String>>(); for (int InI = 0; InI < 5; InI++) { hm = new HashMap<String, String>(); hm.put("flag", Integer.toString(fltFlags[InI])); if (InI != 5) { hm.put("cur", strCrnCode[InI].substring(0, 3)); } else { hm.put("cur", strCrnCode[InI]); } aList.add(hm); } txtvHead.setText(strCrnCode[5]); imgvHead.setImageResource(fltFlags[5]); adapter = new ListAdapter1(getActivity(), aList); lstvMainlistView.setAdapter(adapter); lstvMainlistView.setOnItemClickListener(ListsingleClick); lstvMainlistView.setOnItemLongClickListener(ListLongClick); Decimalpoint(); View vwMain = (View) getActivity().findViewById(R.id.idCurrencyMain); vwMain.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { slide.close(); return true; } }); etxtText.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (!slide.isOpened()) { slide.open(); } } }); if (!Settings.getString("Input", "").equals("")) { calculation(Double.parseDouble(Settings.getString("Input", ""))); etxtText.setText(""); etxtText.setText(Settings.getString("Input", "")); } else { etxtText.setText(Settings.getString("Input", "1")); } }
From source file:com.adflake.AdFlakeManager.java
/** * Fetch the ADFlake config from the remote server. * /*from w w w . j a va 2 s . c o m*/ * @note If the config timeout has not been hit, the previously downloaded * config will be reused. If testmode is enabled, the config will * always be downloaded. */ public void fetchConfigFromServer() { Context context = _contextReference.get(); // If the context is null here something went wrong with initialization. if (context == null) { return; } SharedPreferences adFlakePrefs = context.getSharedPreferences(adFlakeKey, Context.MODE_PRIVATE); String jsonString = adFlakePrefs.getString(PREFS_STRING_CONFIG, null); long timestamp = adFlakePrefs.getLong(PREFS_STRING_TIMESTAMP, -1); Log.d(AdFlakeUtil.ADFLAKE, "Prefs{" + adFlakeKey + "}: {\"" + PREFS_STRING_CONFIG + "\": \"" + jsonString + "\", \"" + PREFS_STRING_TIMESTAMP + "\": " + timestamp + "}"); if (jsonString == null || _configExpireTimeout == -1 || System.currentTimeMillis() >= timestamp + _configExpireTimeout || AdFlakeTargeting.getTestMode() == true) { Log.i(AdFlakeUtil.ADFLAKE, "Stored config info not present or expired, fetching fresh data"); HttpClient httpClient = new DefaultHttpClient(); String url = String.format(AdFlakeUtil.urlConfig, this.adFlakeKey, AdFlakeUtil.VERSION); HttpGet httpGet = new HttpGet(url); HttpResponse httpResponse; try { httpResponse = httpClient.execute(httpGet); Log.d(AdFlakeUtil.ADFLAKE, httpResponse.getStatusLine().toString()); HttpEntity entity = httpResponse.getEntity(); if (entity != null) { InputStream inputStream = entity.getContent(); jsonString = convertStreamToString(inputStream); SharedPreferences.Editor editor = adFlakePrefs.edit(); editor.putString(PREFS_STRING_CONFIG, jsonString); editor.putLong(PREFS_STRING_TIMESTAMP, System.currentTimeMillis()); editor.commit(); } } catch (ClientProtocolException e) { Log.e(AdFlakeUtil.ADFLAKE, "Caught ClientProtocolException in fetchConfig()", e); } catch (IOException e) { Log.e(AdFlakeUtil.ADFLAKE, "Caught IOException in fetchConfig()", e); } } else { Log.i(AdFlakeUtil.ADFLAKE, "Using stored config data"); } parseConfigurationString(jsonString); }