Example usage for android.content SharedPreferences getLong

List of usage examples for android.content SharedPreferences getLong

Introduction

In this page you can find the example usage for android.content SharedPreferences getLong.

Prototype

long getLong(String key, long defValue);

Source Link

Document

Retrieve a long value from the preferences.

Usage

From source file:com.google.ipc.invalidation.ticl.android.c2dm.C2DMSettings.java

private static long retrieveField(Context context, String field, long defaultValue) {
    SharedPreferences preferences = getPreferences(context);
    return preferences.getLong(field, defaultValue);
}

From source file:at.florian_lentsch.expirysync.NotifyChecker.java

private static long getFirstStartMillis(Context appContext) {
    final SharedPreferences sharedPref = appContext.getSharedPreferences("main", Context.MODE_PRIVATE);
    long firstStartMillis = sharedPref.getLong(SettingsActivity.KEY_ALERT_TIME, -1);
    if (firstStartMillis == -1) {
        return -1;
    }/*from  w w w.jav  a 2 s .  com*/

    Calendar midnight = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    midnight.set(Calendar.HOUR_OF_DAY, 0);
    midnight.set(Calendar.MINUTE, 0);
    midnight.set(Calendar.SECOND, 0);
    midnight.set(Calendar.MILLISECOND, 0);

    // add "today at 0:00" to the ms value for the alarm (else the alarm
    // would be scheduled for 1970-01-01):
    firstStartMillis += midnight.getTimeInMillis();

    // if we're already past the alarm time today, we need to add another
    // day:
    if (firstStartMillis <= Calendar.getInstance().getTimeInMillis()) {
        firstStartMillis += AlarmManager.INTERVAL_DAY;
    }

    return firstStartMillis;
}

From source file:com.apptentive.android.sdk.module.engagement.interaction.InteractionManager.java

private static boolean hasCacheExpired(Context context) {
    SharedPreferences prefs = context.getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE);
    long expiration = prefs.getLong(Constants.PREF_KEY_INTERACTIONS_PAYLOAD_CACHE_EXPIRATION, 0);
    return expiration < System.currentTimeMillis();
}

From source file:com.asburymotors.android.disneysocal.common.Utils.java

/**
 * Fetch the location from app preferences.
 *//*from w ww. j  a  v  a2 s  . c  o  m*/
public static LatLng getLocation(Context context) {
    if (!checkFineLocationPermission(context)) {
        return null;
    }

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    Long lat = prefs.getLong(PREFERENCES_LAT, Long.MAX_VALUE);
    Long lng = prefs.getLong(PREFERENCES_LNG, Long.MAX_VALUE);
    if (lat != Long.MAX_VALUE && lng != Long.MAX_VALUE) {
        Double latDbl = Double.longBitsToDouble(lat);
        Double lngDbl = Double.longBitsToDouble(lng);
        return new LatLng(latDbl, lngDbl);
    }
    return null;
}

From source file:fr.eoit.parameter.Parameters.java

public static void loadParameters(FragmentActivity pActivity) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(pActivity);
    characterId = preferences.getLong("character_id", -1);
    keyId = preferences.getLong("user_id", -1);
    vCode = preferences.getString("api_key", null);
    isMiningActive = preferences.getBoolean("mining_active", true);
    territory = preferences.getInt("territory", EOITConst.Territories.CALDARI_SPACE);
    securityStatus = preferences.getFloat("security_status", 0.7f);

    context = pActivity.getApplicationContext();

    if (keyId == -1 && vCode == null) {
        Skills.setLevelVChar(true);// w w w. ja  v  a 2 s  .  c o m
    }

    pActivity.getSupportLoaderManager().initLoader(PARAM_LOADER_ID, null, new Parameters());
    pActivity.getSupportLoaderManager().initLoader(STATIONS_LOADER_ID, null, new Parameters());

    validateStationParams(pActivity);
}

From source file:com.memetro.android.notifications.NotificationUtils.java

/**
 * Checks if the registration has expired.
 *
 * <p>To avoid the scenario where the device sends the registration to the
 * server but the server loses it, the app developer may choose to
 * re-register after REGISTRATION_EXPIRY_TIME_MS.
 *
 * @param context application's context.
 *
 * @return true if the registration has expired.
 *//* w w  w  .  jav a  2  s  . c  om*/
private static boolean isRegistrationExpired(Context context) {
    final SharedPreferences prefs = getGCMPreferences(context);
    // checks if the information is not stale
    long expirationTime = prefs.getLong(PROPERTY_ON_SERVER_EXPIRATION_TIME, -1);
    return System.currentTimeMillis() > expirationTime;
}

From source file:org.alfresco.mobile.android.application.configuration.ConfigurationManager.java

private static Long getLastModificationTime(Context activity, long accountId) {
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(activity);
    return sharedPref.getLong(LASTMODIFICATION_PREFIX + accountId, -1);
}

From source file:com.batontouch.facebook.SessionStore.java

public static boolean restore(Facebook session, Context context) {
    mcontext = context;/*from  w  w w  . j ava 2 s .  c  o  m*/
    SharedPreferences savedSession = context.getSharedPreferences(KEY, Context.MODE_PRIVATE);
    session.setAccessToken(savedSession.getString(TOKEN, null));
    session.setAccessExpires(savedSession.getLong(EXPIRES, 0));
    return session.isSessionValid();
}

From source file:ch.ethz.twimight.activities.HomeScreenActivity.java

/**
 * Gets the Twitter ID from shared preferences
 * /*from  w w  w  .j a v  a2s . c om*/
 * @param context
 * @return
 */
public static Long getOnPauseTimestamp(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    return prefs.getLong(ON_PAUSE_TIMESTAMP, 0);
}

From source file:com.asalfo.wiulgi.util.Utils.java

/**
 * Fetch the location from app preferences.
 *//*w ww. j av a 2s . c  o m*/
public static LatLng getLocation(@NonNull Context context) {
    if (!checkFineLocationPermission(context)) {
        return null;
    }

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    Long lat = prefs.getLong(PREFERENCES_LAT, Long.MAX_VALUE);
    Long lng = prefs.getLong(PREFERENCES_LNG, Long.MAX_VALUE);
    if (lat != Long.MAX_VALUE && lng != Long.MAX_VALUE) {
        Double latDbl = Double.longBitsToDouble(lat);
        Double lngDbl = Double.longBitsToDouble(lng);
        return new LatLng(latDbl, lngDbl);
    }
    return null;
}