List of usage examples for android.content SharedPreferences getLong
long getLong(String key, long defValue);
From source file:com.tagaugmentedreality.utilties.Utilities.java
public static Object getSharedPreferences(Context context, String key, char type) { /**/* w w w. j a va 2s.co m*/ * 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.malubu.wordpress.ratemedialogv4.RateMeDialogV4.java
/** * Call from your Activity.// w w w . j av a2s.c o m * @param ownerManager FragmentManager of the owner, the entity from which we want to show a dialog. * @param publisherName If null then the relative button will be removed from the dialog. * @param appPackageName The app to rate. * @param title The dialog title. For now the title is rendered as a separate TextView for more flexibility. If null then the relative View will be removed from the dialog. * @param total_days Number of days to do before show this dialog. * Pass < 0 along with total_launches < 0 to ignore RATEMEDIALOG_NEVER. * @param total_launches Number of launches to do before show this dialog. * Pass < 0 along with total_days < 0 to ignore RATEMEDIALOG_NEVER. * @param context Normally it is the Activity from which you called this method. * @return */ public static boolean showRateMeDialog(FragmentManager ownerManager, String publisherName, String appPackageName, String title, int total_days, int total_launches, Context context) { SharedPreferences pref = context.getSharedPreferences(RATEMEDIALOG_TAG, 0); //If user don't want to see this Dialog, return immediately. if (pref.getBoolean(RATEMEDIALOG_NEVER, false) && total_days > 0 && total_launches > 0) { return false; } SharedPreferences.Editor editor = pref.edit(); //One new launch. int launchCounter = pref.getInt(RATEMEDIALOG_LAUNCH, 0) + 1; editor.putInt(RATEMEDIALOG_LAUNCH, launchCounter); //Retrieve date of first launch. long firstLaunch = pref.getLong(RATEMEDIALOG_FIRST_LAUNCH, 0); if (firstLaunch == 0)//If this is indeed the first launch, update it. { firstLaunch = System.currentTimeMillis(); editor.putLong(RATEMEDIALOG_FIRST_LAUNCH, firstLaunch); } //Update SharedPreferences. editor.commit(); int later = pref.getInt(RATEMEDIALOG_LATER, 1); //First check if number of launches is right. if (total_launches > launchCounter)//Skipped if total_launches < 0, as launchCounter starts from 0. { //More launches needed. return false; } //Then check number of days if (total_days > 0 && //Skip if total_days < 0. (System.currentTimeMillis() < firstLaunch + ((total_days * later) * 24 * 60 * 60 * 1000))) { //More days needed. return false; } //Only one dialog at time. hideRateMeDialog(ownerManager);//Save last FragmentManager. //Create the dialog. RateMeDialogV4 dialog = new RateMeDialogV4(); Bundle params = new Bundle(); params.putString(RATEMEDIALOG_PUBLISHER, publisherName); params.putString(RATEMEDIALOG_APPAPCKAGENAME, appPackageName); params.putString(RATEMEDIALOG_TITLE, title); dialog.setArguments(params); //Show the dialog. FragmentTransaction ownerTransaction = ownerManager.beginTransaction(); dialog.show(ownerTransaction, RATEMEDIALOG_TAG); return true; }
From source file:com.dmbstream.android.util.Util.java
public static Long getLastAccessed(Context context) { SharedPreferences prefs = getPreferences(context); return prefs.getLong(Constants.SHARED_LASTACCESSED, -1); }
From source file:com.sentaroh.android.SMBSync2.CommonUtilities.java
static private void saveSettingsParmsToFileLong(Context c, PrintWriter pw, long dflt, boolean encrypt_required, final CipherParms cp, String key) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c); String k_type;//from w w w .jav a 2 s. c o m long k_val; k_val = prefs.getLong(key, dflt); k_type = SMBSYNC_UNLOAD_SETTINGS_TYPE_LONG; String k_str = SMBSYNC_PROF_TYPE_SETTINGS + "\t" + key + "\t" + k_type + "\t" + k_val; if (encrypt_required) { String enc = Base64Compat.encodeToString(EncryptUtil.encrypt(k_str, cp), Base64Compat.NO_WRAP); pw.println(CURRENT_SMBSYNC_PROFILE_VERSION + enc); } else { pw.println(CURRENT_SMBSYNC_PROFILE_VERSION + k_str); } }
From source file:com.facebook.Settings.java
static Response publishInstallAndWaitForResponse(final Context context, final String applicationId) { try {/*from ww w . j a v a2 s . c o m*/ if (context == null || applicationId == null) { throw new IllegalArgumentException("Both context and applicationId must be non-null"); } AttributionIdentifiers identifiers = AttributionIdentifiers.getAttributionIdentifiers(context); SharedPreferences preferences = context.getSharedPreferences(ATTRIBUTION_PREFERENCES, Context.MODE_PRIVATE); String pingKey = applicationId + "ping"; String jsonKey = applicationId + "json"; long lastPing = preferences.getLong(pingKey, 0); String lastResponseJSON = preferences.getString(jsonKey, null); GraphObject publishParams = GraphObject.Factory.create(); publishParams.setProperty(ANALYTICS_EVENT, MOBILE_INSTALL_EVENT); Utility.setAppEventAttributionParameters(publishParams, identifiers, AppEventsLogger.getAnonymousAppDeviceGUID(context), getLimitEventAndDataUsage(context)); publishParams.setProperty("application_package_name", context.getPackageName()); String publishUrl = String.format(PUBLISH_ACTIVITY_PATH, applicationId); Request publishRequest = Request.newPostRequest(null, publishUrl, publishParams, null); if (lastPing != 0) { GraphObject graphObject = null; try { if (lastResponseJSON != null) { graphObject = GraphObject.Factory.create(new JSONObject(lastResponseJSON)); } } catch (JSONException je) { // return the default graph object if there is any problem reading the data. } if (graphObject == null) { return Response.createResponsesFromString("true", null, new RequestBatch(publishRequest), true) .get(0); } else { return new Response(null, null, null, graphObject, true); } } else { Response publishResponse = publishRequest.executeAndWait(); // denote success since no error threw from the post. SharedPreferences.Editor editor = preferences.edit(); lastPing = System.currentTimeMillis(); editor.putLong(pingKey, lastPing); // if we got an object response back, cache the string of the JSON. if (publishResponse.getGraphObject() != null && publishResponse.getGraphObject().getInnerJSONObject() != null) { editor.putString(jsonKey, publishResponse.getGraphObject().getInnerJSONObject().toString()); } editor.apply(); return publishResponse; } } catch (Exception e) { // if there was an error, fall through to the failure case. Utility.logd("Facebook-publish", e); return new Response(null, null, new FacebookRequestError(null, e)); } }
From source file:com.wbtech.ums.UmsAgent.java
private static void isCreateNewSessionID(Context context) { // TODO Auto-generated method stub long currenttime = System.currentTimeMillis(); SharedPreferences preferences = context.getSharedPreferences("UMS_session_ID_savetime", Context.MODE_PRIVATE); long session_save_time = preferences.getLong("session_save_time", currenttime); if (currenttime - session_save_time > UmsConstants.kContinueSessionMillis) { try {// w ww. j a v a2 s . co m generateSeesion(context); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:org.catnut.util.CatnutUtils.java
public static void checkout(boolean required, Context context, SharedPreferences preferences) { long now = System.currentTimeMillis(); String key = context.getString(R.string.pref_check_upgrade); if (required) { context.startService(new Intent(context, UpgradeService.class)); preferences.edit().putLong(key, now).commit(); } else {/*from w w w. j a va 2s .com*/ long last = preferences.getLong(key, now); if (now - last > (7 * 24 * 60 * 60 * 1000)) { // ? Log.d(TAG, "need upgrade..."); preferences.edit().putLong(key, now).commit(); context.startService(new Intent(context, UpgradeService.class)); } } }
From source file:fyc.framework.util.PrefsUtils.java
public static long getLong(Context context, String name, String key, long defValue, int mode, boolean[] keyValueEncrypt) { SharedPreferences preferences = null; if (TextUtils.isEmpty(name)) { preferences = PreferenceManager.getDefaultSharedPreferences(context); } else {/*from w w w . j a v a 2 s . c o m*/ preferences = context.getSharedPreferences(name, mode); } if (keyValueEncrypt[1]) { String value = getString(context, name, key, String.valueOf(defValue), mode, keyValueEncrypt); try { return Long.valueOf(value); } catch (Exception e) { return defValue; } } else { return preferences.getLong(keyValueEncrypt[0] ? SecurityUtils.MD5(key) : key, defValue); } }
From source file:com.facebook.FacebookSdk.java
static GraphResponse publishInstallAndWaitForResponse(final Context context, final String applicationId) { try {//from w w w. ja va 2 s .c o m if (context == null || applicationId == null) { throw new IllegalArgumentException("Both context and applicationId must be non-null"); } AttributionIdentifiers identifiers = AttributionIdentifiers.getAttributionIdentifiers(context); SharedPreferences preferences = context.getSharedPreferences(ATTRIBUTION_PREFERENCES, Context.MODE_PRIVATE); String pingKey = applicationId + "ping"; String jsonKey = applicationId + "json"; long lastPing = preferences.getLong(pingKey, 0); String lastResponseJSON = preferences.getString(jsonKey, null); JSONObject publishParams; try { publishParams = AppEventsLoggerUtility.getJSONObjectForGraphAPICall( AppEventsLoggerUtility.GraphAPIActivityType.MOBILE_INSTALL_EVENT, identifiers, AppEventsLogger.getAnonymousAppDeviceGUID(context), getLimitEventAndDataUsage(context), context); } catch (JSONException e) { throw new FacebookException("An error occurred while publishing install.", e); } String publishUrl = String.format(PUBLISH_ACTIVITY_PATH, applicationId); GraphRequest publishRequest = GraphRequest.newPostRequest(null, publishUrl, publishParams, null); if (lastPing != 0) { JSONObject graphObject = null; try { if (lastResponseJSON != null) { graphObject = new JSONObject(lastResponseJSON); } } catch (JSONException je) { // return the default graph object if there is any problem reading the data. } if (graphObject == null) { return GraphResponse .createResponsesFromString("true", null, new GraphRequestBatch(publishRequest)).get(0); } else { return new GraphResponse(null, null, null, graphObject); } } else { GraphResponse publishResponse = publishRequest.executeAndWait(); // denote success since no error threw from the post. SharedPreferences.Editor editor = preferences.edit(); lastPing = System.currentTimeMillis(); editor.putLong(pingKey, lastPing); // if we got an object response back, cache the string of the JSON. if (publishResponse.getJSONObject() != null) { editor.putString(jsonKey, publishResponse.getJSONObject().toString()); } editor.apply(); return publishResponse; } } catch (Exception e) { // if there was an error, fall through to the failure case. Utility.logd("Facebook-publish", e); return new GraphResponse(null, null, new FacebookRequestError(null, e)); } }
From source file:org.alfresco.mobile.android.application.operations.sync.SynchroManager.java
public static long getSyncPrepareTimestamp(Context context, Account account) { if (account == null) { return -1; }//w w w . j av a 2s . co m SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context); return sharedPref.getLong(LAST_SYNC_ACTIVATED_AT + account.getId(), new Date().getTime()); }