List of usage examples for android.content SharedPreferences getLong
long getLong(String key, long defValue);
From source file:com.breadwallet.tools.manager.SharedPreferencesManager.java
public static long getFeePerKb(Activity context) { SharedPreferences prefs = context.getSharedPreferences(BRConstants.PREFS_NAME, Context.MODE_PRIVATE); return prefs.getLong(BRConstants.FEE_KB_PREFS, 0); }
From source file:net.wequick.small.Small.java
public static long getBundleLastModified(String bundleName) { SharedPreferences sp = getContext().getSharedPreferences(SHARED_PREFERENCES_BUNDLE_MODIFIES, 0); if (sp == null) return 0; return sp.getLong(bundleName, 0); }
From source file:com.breadwallet.tools.manager.SharedPreferencesManager.java
public static long getSecureTime(Activity activity) { SharedPreferences prefs = activity.getSharedPreferences(BRConstants.PREFS_NAME, Context.MODE_PRIVATE); return prefs.getLong(BRConstants.SECURE_TIME_PREFS, System.currentTimeMillis() / 1000); }
From source file:com.breadwallet.tools.manager.SharedPreferencesManager.java
public static long getPhraseWarningTime(Activity activity) { SharedPreferences prefs = activity.getSharedPreferences(BRConstants.PREFS_NAME, Context.MODE_PRIVATE); return prefs.getLong(BRConstants.PHRASE_WARNING_TIME, 0); }
From source file:com.tinyhydra.botd.BotdServerOperations.java
public static void GetTopTen(final Activity activity, final Handler handler, boolean override) { final SharedPreferences settings = activity.getSharedPreferences(Const.GenPrefs, 0); final List<JavaShop> TopTen = new ArrayList<JavaShop>(); for (int i = 0; i < 10; i++) { TopTen.add(new JavaShop()); }/*from w ww.j a v a 2 s. c om*/ if (settings.getLong(Const.LastTopTenQueryTime, 0) > (Calendar.getInstance().getTimeInMillis() - 180000) & !override) { Message msg = new Message(); msg.arg1 = Const.CODE_GETTOPTEN; handler.sendMessage(msg); } else new Thread() { @Override public void run() { BufferedReader in = null; try { HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(); request.setURI(new URI(activity.getResources().getString(R.string.server_url))); HttpResponse response = client.execute(request); in = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer sb = new StringBuffer(""); String line = ""; while ((line = in.readLine()) != null) { sb.append(line); } in.close(); SharedPreferences.Editor editor = settings.edit(); editor.putString(Const.LastTopTenQueryResults, sb.toString()); editor.putLong(Const.LastTopTenQueryTime, Calendar.getInstance().getTimeInMillis()); editor.commit(); Message msg = new Message(); msg.arg1 = Const.CODE_GETTOPTEN; handler.sendMessage(msg); // more generic error handling //TODO: implement better error handling } catch (URISyntaxException usex) { usex.printStackTrace(); Utils.PostToastMessageToHandler(handler, "Unable to retrieve Brew of the day. Poor signal? Please try again", Toast.LENGTH_LONG); } catch (ClientProtocolException cpex) { cpex.printStackTrace(); Utils.PostToastMessageToHandler(handler, "Unable to retrieve Brew of the day. Poor signal? Please try again", Toast.LENGTH_LONG); } catch (IOException iex) { iex.printStackTrace(); Utils.PostToastMessageToHandler(handler, "Unable to retrieve Brew of the day. Poor signal? Please try again", Toast.LENGTH_LONG); } finally { if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } } }.start(); }
From source file:m2.android.archetype.example.FacebookSdk.Settings.java
/** * Manually publish install attribution to the Facebook graph. Internally handles tracking repeat calls to prevent * multiple installs being published to the graph. * @param context the current Context/*w w w . j a v a 2 s . c o m*/ * @return returns false on error. Applications should retry until true is returned. Safe to call again after * true is returned. */ public static boolean publishInstallAndWait(final Context context, final String applicationId) { try { if (applicationId == null) { return false; } String attributionId = Settings.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); Request pingRequest = Request.newGraphPathRequest(null, applicationId, null); pingRequest.setParameters(supportsAttributionParams); GraphObject supportResponse = pingRequest.executeAndWait().getGraphObject(); Object doesSupportAttribution = supportResponse.getProperty(SUPPORTS_ATTRIBUTION); if (!(doesSupportAttribution instanceof Boolean)) { throw new JSONException(String.format("%s contains %s instead of a Boolean", SUPPORTS_ATTRIBUTION, doesSupportAttribution)); } if ((Boolean) doesSupportAttribution) { GraphObject publishParams = GraphObject.Factory.create(); publishParams.setProperty(ANALYTICS_EVENT, MOBILE_INSTALL_EVENT); publishParams.setProperty(ATTRIBUTION_KEY, attributionId); String publishUrl = String.format(PUBLISH_ACTIVITY_PATH, applicationId); Request publishRequest = Request.newPostRequest(null, publishUrl, publishParams, null); publishRequest.executeAndWait(); // denote success since no error threw from the post. SharedPreferences.Editor editor = preferences.edit(); lastPing = System.currentTimeMillis(); editor.putLong(pingKey, lastPing); editor.commit(); } } return lastPing != 0; } catch (Exception e) { // if there was an error, fall through to the failure case. Utility.logd("Facebook-publish", e.getMessage()); } return false; }
From source file:org.quantumbadger.redreader.receivers.NewMessageChecker.java
public static void checkForNewMessages(Context context) { Log.i("RedReader", "Checking for new messages."); boolean notificationsEnabled = PrefsUtility.pref_behaviour_notifications(context, PreferenceManager.getDefaultSharedPreferences(context)); if (!notificationsEnabled) return;/* w w w . j a v a 2s . co m*/ final RedditAccount user = RedditAccountManager.getInstance(context).getDefaultAccount(); if (user.isAnonymous()) { return; } final CacheManager cm = CacheManager.getInstance(context); final URI url = Constants.Reddit.getUri("/message/unread.json?limit=2"); final CacheRequest request = new CacheRequest(url, user, null, Constants.Priority.API_INBOX_LIST, 0, DownloadStrategyAlways.INSTANCE, Constants.FileType.INBOX_LIST, CacheRequest.DOWNLOAD_QUEUE_REDDIT_API, true, true, context) { @Override protected void onDownloadNecessary() { } @Override protected void onDownloadStarted() { } @Override protected void onCallbackException(final Throwable t) { BugReportActivity.handleGlobalError(context, t); } @Override protected void onFailure(final @CacheRequest.RequestFailureType int type, final Throwable t, final Integer status, final String readableMessage) { Log.e(TAG, "Request failed", t); } @Override protected void onProgress(final boolean authorizationInProgress, final long bytesRead, final long totalBytes) { } @Override protected void onSuccess(final CacheManager.ReadableCacheFile cacheFile, final long timestamp, final UUID session, final boolean fromCache, final String mimetype) { } @Override public void onJsonParseStarted(final JsonValue value, final long timestamp, final UUID session, final boolean fromCache) { try { final JsonBufferedObject root = value.asObject(); final JsonBufferedObject data = root.getObject("data"); final JsonBufferedArray children = data.getArray("children"); children.join(); final int messageCount = children.getCurrentItemCount(); Log.e(TAG, "Got response. Message count = " + messageCount); if (messageCount < 1) { return; } final RedditThing thing = children.get(0).asObject(RedditThing.class); String title; final String text = context.getString(R.string.notification_message_action); final String messageID; final long messageTimestamp; switch (thing.getKind()) { case COMMENT: { final RedditComment comment = thing.asComment(); title = context.getString(R.string.notification_comment, comment.author); messageID = comment.name; messageTimestamp = comment.created_utc; break; } case MESSAGE: { final RedditMessage message = thing.asMessage(); title = context.getString(R.string.notification_message, message.author); messageID = message.name; messageTimestamp = message.created_utc; break; } default: { throw new RuntimeException("Unknown item in list."); } } // Check if the previously saved message is the same as the one we just received final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); final String oldMessageId = prefs.getString(PREFS_SAVED_MESSAGE_ID, ""); final long oldMessageTimestamp = prefs.getLong(PREFS_SAVED_MESSAGE_TIMESTAMP, 0); if (oldMessageId == null || (!messageID.equals(oldMessageId) && oldMessageTimestamp <= messageTimestamp)) { Log.e(TAG, "New messages detected. Showing notification."); prefs.edit().putString(PREFS_SAVED_MESSAGE_ID, messageID) .putLong(PREFS_SAVED_MESSAGE_TIMESTAMP, messageTimestamp).apply(); if (messageCount > 1) { title = context.getString(R.string.notification_message_multiple); } createNotification(title, text, context); } else { Log.e(TAG, "All messages have been previously seen."); } } catch (Throwable t) { notifyFailure(CacheRequest.REQUEST_FAILURE_PARSE, t, null, "Parse failure"); } } }; cm.makeRequest(request); }
From source file:io.jari.geenstijl.API.API.java
/** * getCache returns the latest cached items. * If the cache is over 30 mins old it'll return null and you're expected to download the new articles and set the cache again * * @return Artikel[]/*from w w w . j ava2 s .c om*/ */ private static Artikel[] getCache(Context context) { SharedPreferences preferences = context.getSharedPreferences("geenstijl", 0); long age = preferences.getLong("items_age", 0); if (Calendar.getInstance().getTimeInMillis() - age <= 1800000) return (Artikel[]) SerializeObject.stringToObject(preferences.getString("items", "")); else return null; }
From source file:com.google.sample.castcompanionlibrary.utils.Utils.java
/** * Retrieves a long value from preference manager. If no such key exists, it will return the * value provided as <code>defaultValue</code> * * @param context//from www . ja va 2s .co m * @param key * @param defaultValue * @return */ public static long getLongFromPreference(Context context, String key, long defaultValue) { SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context); return pref.getLong(key, defaultValue); }
From source file:Main.java
public static Object getData(Context context, String fileName, String key, Class clazz) { SharedPreferences sharedPreferences = context.getSharedPreferences(fileName, Context.MODE_PRIVATE); if (clazz.getName().equals(String.class.getName())) { return sharedPreferences.getString(key, ""); } else if (clazz.getName().equals(Integer.class.getName())) { return sharedPreferences.getInt(key, 0); } else if (clazz.getName().equals(Float.class.getName())) { return sharedPreferences.getFloat(key, 0); } else if (clazz.getName().equals(Long.class.getName())) { return sharedPreferences.getLong(key, 0); } else {/* w w w. j a v a 2 s.c o m*/ return sharedPreferences.getBoolean(key, false); } }