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:damo.three.ie.activity.InternetExpirationActivity.java

/**
 * Get last refreshed time/*from  w w  w  .  ja va2  s  .c  o  m*/
 *
 * @return Last refreshed time as {@link String}
 */
private String getLastRefreshTime() {
    SharedPreferences sharedPref = getSharedPreferences("damo.three.ie.previous_usage", Context.MODE_PRIVATE);
    long refreshDate = sharedPref.getLong("last_refreshed_milliseconds", 0L);
    return DateUtils.formatDateTime(refreshDate);
}

From source file:com.sean.takeastand.alarmprocess.AlarmReceiver.java

private void endSessionAnalytics(FixedAlarmSchedule fixedAlarmSchedule) {
    SharedPreferences sharedPreferences = mContext.getSharedPreferences(Constants.USER_SHARED_PREFERENCES, 0);
    long startTime = sharedPreferences.getLong(Constants.SESSION_START_TIME,
            Calendar.getInstance().getTimeInMillis());
    Calendar currentTime = Calendar.getInstance();
    //Send analytics event only if the user has had to stand at least once in the session
    if (currentTime.getTimeInMillis() - startTime > fixedAlarmSchedule.getFrequency()
            * Constants.millisecondsInMinute) {
        long sessionLength = (currentTime.getTimeInMillis() - startTime) / Constants.millisecondsInMinute;
        String analyticsSession = "Session ran for " + Long.toString(sessionLength) + " minutes "
                + "with frequency of " + Integer.toString(fixedAlarmSchedule.getFrequency());
        sendAnalyticsEvent(analyticsSession);
    }/*from   ww  w  .  j ava2 s  . c  o m*/
}

From source file:net.tawacentral.roger.secrets.FileUtils.java

/**
 * Is the online backup too old?//from w  w  w . j  a  va2  s  .  c  o m
 *
 * @param ctx A context to get the preferences from.
 * @return True if the last backup is too old.
 */
public static boolean isOnlineBackupTooOld(Context ctx) {
    long now = System.currentTimeMillis();
    long lastSaved = getTimeOfLastOnlineBackup(ctx);

    // If lastSaved is zero, this means an online backup has never been done.
    // Nag the user about it, but no more than once per week.
    if (lastSaved == 0) {
        SharedPreferences prefs = ctx.getSharedPreferences(PREFS_FILE_NAME, 0);
        long lastNag = prefs.getLong(PREF_LAST_NAG_DATE, 0);
        final long sixDays = 6 * 24 * 60 * 60 * 1000; // 6 days in millis.
        final long oneWeek = 7 * 24 * 60 * 60 * 1000; // One week in millis.

        // Don't warn the very first day the user runs the program.
        if (lastNag == 0) {
            prefs.edit().putLong(PREF_LAST_NAG_DATE, now - sixDays).apply();
        } else if ((now - lastNag) > oneWeek) {
            // In order not to nag users more than once a week about missing online
            // backup support, set the last nag time to now.
            prefs.edit().putLong(PREF_LAST_NAG_DATE, now).apply();
            return true;
        }
    }

    return false;
}

From source file:org.francho.apps.zgzpolen.service.PollenService.java

/**
  * is the database udpdated?//  w w w.  ja  v a 2  s  .c  o  m
  * 
  * @return
  */
private boolean isUpdated() {
    Cursor c = getContentResolver().query(Pollen.getPollenUri(), null, null, null, null);
    try {
        if (c.getCount() < 1) {
            return false;
        }
    } finally {
        c.close();
    }

    final SharedPreferences prefs = getSharedPreferences(POLLEN_SERVICE_PREFS, Context.MODE_PRIVATE);
    long lastTimeStamp = prefs.getLong(PREF_POLLEN_DATE, 0);

    Log.d(TAG, "" + System.currentTimeMillis() + " " + lastTimeStamp + ":"
            + (System.currentTimeMillis() - lastTimeStamp));

    return DateUtils.isToday(lastTimeStamp);
}

From source file:com.playhaven.android.req.OpenRequest.java

@Override
protected UriComponentsBuilder createUrl(android.content.Context context) throws PlayHavenException {
    UriComponentsBuilder builder = super.createUrl(context);
    builder.queryParam("tz", TimeZoneFormatter.getDefaultTimezone());

    SharedPreferences pref = PlayHaven.getPreferences(context);
    int scount = pref.getInt(SCOUNT, 0);
    long ssum = pref.getLong(SSUM, 0);
    long stime = pref.getLong(STIME, 0);
    ssum += stime;//w  ww . ja  va  2s  . c o m

    builder.queryParam(SCOUNT, scount);
    builder.queryParam(SSUM, ssum);

    SharedPreferences.Editor edit = pref.edit();
    // Increment count
    scount++;
    edit.putInt(SCOUNT, scount);
    // Clear current game time
    edit.putLong(STIME, 0);
    // Don't alter the previous sum until success
    // Save a start time
    Calendar rightNow = Calendar.getInstance();
    Date date = rightNow.getTime();
    edit.putLong(SSTART, date.getTime());
    // Commit changes
    edit.commit();

    return builder;
}

From source file:com.example.groupproject.Model.LocationReceiver.java

private void addJoy(long joyValue) {
    SharedPreferences pm = _context.getSharedPreferences("GeoCat", 0);
    long joy = pm.getLong("joy", MAX_JOY);
    joy += joyValue;/*from   w ww.ja v a 2  s  .  c o  m*/
    SharedPreferences.Editor editor = pm.edit();
    editor.putLong("joy", joy);
    editor.commit();
}

From source file:com.example.groupproject.Model.LocationReceiver.java

private void addHunger(long hungerValue) {
    SharedPreferences pm = _context.getSharedPreferences("GeoCat", 0);
    long hunger = pm.getLong("hunger", MAX_HUNGER);
    hunger = hunger + hungerValue;//from   w w  w.ja  va  2  s  .c  om
    SharedPreferences.Editor editor = pm.edit();
    editor.putLong("hunger", hunger);
    editor.commit();
}

From source file:com.example.groupproject.Model.LocationReceiver.java

private void addHealth(long healthValue) {
    SharedPreferences pm = _context.getSharedPreferences("GeoCat", 0);
    long health = pm.getLong("health", MAX_HEALTH);
    health += healthValue;/*from w  w  w.j  a v a 2s.c  o  m*/
    SharedPreferences.Editor editor = pm.edit();
    editor.putLong("health", health);
    editor.commit();
}

From source file:hu.naturlecso.naturshutd.CommandsFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
    hostId = sp.getLong(HOST_ID, INVALID_ID);

    adapter = new CommandsRecyclerAdapter(this);
}

From source file:com.demo.navigator.ds.DsRepository.java

private void callInFastMobileNetwork(@NonNull EntryLoadedCallback callback) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(mApp);
    mLocalDs.loadEntry(callback);//from w  w w  . j  a  v  a2 s  .  c  o m
    callback.onTextMessage(R.string.mobile_network);
    long expiration = preferences.getLong(PRE_KEY_EXPIRATION, 0);
    if (expiration > 0 && System.currentTimeMillis() > expiration) {
        callOnline(callback);
        callback.onTextMessage(R.string.forced_loading);
    }
}