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:org.bwgz.quotation.service.QuotationService.java

@Override
protected void onHandleIntent(Intent intent) {
    Log.d(TAG, String.format("onHandleIntent - intent: %s (%s)", intent, new Date().toString()));

    SharedPreferences preferences = getSharedPreferences(QuotationApplication.APPLICATION_PREFERENCES,
            Context.MODE_PRIVATE);
    long modified = preferences.getLong(QuotationApplication.APPLICATION_PREFERENCE_QUOTATION_PICKS_MODIFIED,
            0);//  w  ww. j  av  a 2  s .  c o  m

    if (modified + PICKS_PERIOD < System.currentTimeMillis()) {
        getContentResolver().delete(PickQuotation.CONTENT_URI, null, null);
        getContentResolver().delete(PickPerson.CONTENT_URI, null, null);
        getContentResolver().delete(PickSubject.CONTENT_URI, null, null);

        FreebaseIdLoader freebaseIdLoader = FreebaseIdLoader.getInstance(getApplicationContext());
        List<Pick> quotationPicks = freebaseIdLoader.getRandomQuotationPicks(PICK_SIZE);
        List<Pick> authorPicks = freebaseIdLoader.getRandomAuthorPicks(PICK_SIZE);
        List<Pick> subjectPicks = freebaseIdLoader.getRandomSubjectPicks(PICK_SIZE);

        for (int i = 0; i < PICK_SIZE; i++) {
            getContentResolver()
                    .query(PickQuotation.withAppendedId(quotationPicks.get(i).getId()), null, null, null, null)
                    .close();
            getContentResolver()
                    .query(PickPerson.withAppendedId(authorPicks.get(i).getId()), null, null, null, null)
                    .close();
            getContentResolver()
                    .query(PickSubject.withAppendedId(subjectPicks.get(i).getId()), null, null, null, null)
                    .close();
        }

        SharedPreferences.Editor editor = preferences.edit();
        modified = System.currentTimeMillis();
        editor.putLong(QuotationApplication.APPLICATION_PREFERENCE_QUOTATION_PICKS_MODIFIED, modified);
        editor.putLong(QuotationApplication.APPLICATION_PREFERENCE_PERSON_PICKS_MODIFIED, modified);
        editor.putLong(QuotationApplication.APPLICATION_PREFERENCE_SUBJECT_PICKS_MODIFIED, modified);
        editor.commit();
    }

    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    PendingIntent alarmIntent = PendingIntent.getBroadcast(this, 0,
            new Intent(this, QuotationAlarmReceiver.class), 0);
    alarmManager.cancel(alarmIntent);

    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.set(Calendar.HOUR_OF_DAY, 2);
    calendar.set(Calendar.MINUTE, random.nextInt(60));
    calendar.set(Calendar.SECOND, random.nextInt(60));
    alarmManager.set(AlarmManager.RTC, calendar.getTimeInMillis() + PICKS_PERIOD, alarmIntent);

    LocalBroadcastManager.getInstance(this)
            .sendBroadcast(new Intent(BROADCAST_ACTION).putExtra(EXTENDED_DATA_STATUS, true));
}

From source file:com.onesignal.OneSignal.java

static long GetUnsentActiveTime() {
    if (unSentActiveTime == -1 && appContext != null) {
        final SharedPreferences prefs = getGcmPreferences(appContext);
        unSentActiveTime = prefs.getLong("GT_UNSENT_ACTIVE_TIME", 0);
    }/*from  w w  w .j  a  v  a  2 s.  c om*/

    Log(LOG_LEVEL.INFO, "GetUnsentActiveTime: " + unSentActiveTime);

    return unSentActiveTime;
}

From source file:com.hplasplas.reminders.services.NotificationService.java

private long getStartPointTime(SharedPreferences notificationPreferences) {

    long startPointTime = notificationPreferences.getLong(START_POINT_TIME, 0);
    if (startPointTime == 0) {
        startPointTime = System.currentTimeMillis();
    }//from  w  ww  .  ja  v  a  2s. co m
    return startPointTime;
}

From source file:com.locadz.AdUnitAllocationService.java

/**
 * load the allocation configuration for the adunit from SharedPreferences.
 *
 * @param adUnitContext the context of the adunit.
 * @return the allocation configuration for the adunit.
 *//*  w  ww  .  j  a  v a 2  s  . co  m*/
String loadFromSharedPreferences(AdUnitContext adUnitContext) {
    SharedPreferences perfs = this.getApplicationContext().getSharedPreferences(adUnitContext.getAdUnitId(),
            Context.MODE_PRIVATE);

    long lastUpdateTime = perfs.getLong(PREFS_STRING_TIMESTAMP, 0);
    if (System.currentTimeMillis() - lastUpdateTime <= CACHE_EXPIRATION_PERIOD) {
        return perfs.getString(PREFS_STRING_CONFIG, "");
    }
    return null;
}

From source file:com.android.settings.cyanogenmod.LtoService.java

private long getLastDownload() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    return prefs.getLong(LtoService.KEY_LAST_DOWNLOAD, 0);
}

From source file:paarmann.physikprofil.HomeworkUpdater.java

/**
 * Loads the data and returns it to the currently registered listener.
 * @param forceDownload if true, no cached results will be used
 *//*from  www .j a  va 2 s  . c  om*/
public void getData(boolean forceDownload) {
    Date now = new Date();
    SharedPreferences prefs = context.getSharedPreferences(MainActivity.PREF_NAME, 0);
    Date lastUpdated = new Date(prefs.getLong(MainActivity.PREF_LASTUPDATED, 0));
    long diffMinutes = Utils.getDateDiff(lastUpdated, now, TimeUnit.MINUTES);

    if (diffMinutes >= 90 || forceDownload) {
        //Last updated longer than 90 minutes ago
        downloadHomework();
    } else {
        loadHomeworkFromFile();
    }
}

From source file:io.github.gsantner.opoc.util.AppSettingsBase.java

public long getLong(SharedPreferences pref, @StringRes int keyResourceId, long defaultValue) {
    return pref.getLong(rstr(keyResourceId), defaultValue);
}

From source file:com.markupartist.sthlmtraveling.utils.AdProxy.java

public boolean shouldShowAfterDismiss() {
    final SharedPreferences sharedPreferences = PreferenceManager
            .getDefaultSharedPreferences(mContext.getApplicationContext());
    long dismissedAt = sharedPreferences.getLong(AD_DISMISSED_AT_KEY, 0);
    long timePassed = System.currentTimeMillis() - dismissedAt;
    return timePassed >= AD_DISMISSED_GRACE_PERIOD;
}

From source file:com.scooter1556.sms.android.activity.BaseActivity.java

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

    Log.d(TAG, "onCreate()");

    // Retrieve preferences if they exist
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    if (savedInstanceState == null) {
        // Check connection
        long id = sharedPreferences.getLong("Connection", -1);

        if (id < 0) {
            Intent connectionsIntent = new Intent(this, ConnectionActivity.class);
            startActivityForResult(connectionsIntent, RESULT_CODE_SETTINGS);
        }/*from  w ww.j a v  a 2  s .c o  m*/
    }

    // Connect a media browser just to get the media session token. There are other ways
    // this can be done, for example by sharing the session token directly.
    mediaBrowser = new MediaBrowserCompat(this, new ComponentName(getApplicationContext(), MediaService.class),
            connectionCallback, null);
}

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

private void countPoints(List<Zone> zones, double longitude, double latitude) {
    //sendNotification("GeoDog","counting...");
    android.content.SharedPreferences pm = _context.getSharedPreferences("GeoCat", 0);
    String name = pm.getString("name", "Your Geo-Dog");
    long hunger = pm.getLong("hunger", MAX_HUNGER);
    if (hunger <= 0) {
        if (hunger == 0) {
            sendNotification("GeoDog", name + " is starving and its health is deteriorating. Buy some food!");
            addHunger(-1);//from   w  w  w . j a va  2 s  .co m
        }
        long health = pm.getLong("health", MAX_HEALTH);
        if (health == 0) {
            String message = name
                    + " was taken away by a concerned vet. It's okay though, pick yourself up and try again!";
            sendNotification("GeoDog", message);
            resetStats();
        } else {
            addHealth(HEALTH_INCREMENT);
        }
    } else {
        addHunger(HUNGER_INCREMENT);
    }
    for (Zone zone : zones) {
        if (inZone(zone, longitude, latitude)) {
            if (zone.getZoneType() != 0) {
                addJoy(JOY_INCREMENT);
                long joy = pm.getLong("joy", MAX_JOY);
                if (joy <= 0) {
                    if (joy == 0) {
                        sendNotification("GeoDog",
                                "Oh no! " + name + "is completely pooped! buy a treat to cheer it up!");
                        addJoy(-1);
                    } //10% chance to reset statistics
                    Random r = new Random();
                    if (r.nextInt(100 - 0) >= 90) {
                        sendNotification("GeoDog", "Dude, " + name + " just ran away!");
                        resetStats();
                    }
                }
            } else {
                addPoints(POINT_INCREMENT);
            }
        }
        Log.d("Points", Long.toString(points));
    }
}