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:de.grundid.plusrad.recording.RecordingService.java

private void resumeTracking() {
    Log.i(TAG, "restarting tracking...");
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    int testState = sharedPreferences.getInt(CURRENT_STATE, -1);
    long testTripId = sharedPreferences.getLong(CURRENT_TRIP_ID, -1);
    if (testState != -1 && testTripId != -1) {
        this.state = testState;
        TripData tripData = dbAdapter.getTrip(testTripId);
        float distanceTraveled = sharedPreferences.getFloat(DISTANCE_TRAVELED, 0);
        float maxSpeed = sharedPreferences.getFloat(MAX_SPEED, 0);
        float currentSpeed = sharedPreferences.getFloat(CURRENT_SPEED, 0);
        int points = sharedPreferences.getInt(POINTS, 0);
        long standingTime = sharedPreferences.getLong(STANDING_TIME, 0);
        long pauseTimestamp = sharedPreferences.getLong(PAUSE_TIMESTAMP, 0);
        boolean manualPause = sharedPreferences.getBoolean(MANUAL_PAUSE, false);
        trip = new CurrentTrip(tripData, distanceTraveled, maxSpeed, currentSpeed, points, standingTime,
                pauseTimestamp, manualPause);
        if (state == STATE_RECORDING) {
            startLocationUpdates();//from   w ww .j  av  a  2 s .co  m
        }
    }
}

From source file:net.homelinux.penecoptero.android.citybikes.donation.app.StationsDBAdapter.java

public void retrieve() throws Exception {
    SharedPreferences settings = this.mCtx.getSharedPreferences(PREF_NAME, 0);
    RAWstations = settings.getString("stations", "[]");
    last_updated = settings.getString("last_updated", null);
    last_updated_time = settings.getLong("last_updated_time", 0);
    String network_url = settings.getString("network_url", "");
}

From source file:com.pgmacdesign.rsrtoolbox.TEST.java

double getDouble(final SharedPreferences prefs, final String key, final double defaultValue) {
    return Double.longBitsToDouble(prefs.getLong(key, Double.doubleToLongBits(defaultValue)));
}

From source file:com.sean.takeastand.ui.MainImageButtonFragment.java

private void endSessionAnalytics() {
    SharedPreferences sharedPreferences = mContext.getSharedPreferences(Constants.EVENT_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 > Utils.getDefaultFrequency(getActivity())
            * Constants.millisecondsInMinute) {
        Log.i(TAG, "Sending session analytics");
        long sessionLength = (currentTime.getTimeInMillis() - startTime) / Constants.millisecondsInMinute;
        String analyticsSession = "Session ran for " + Long.toString(sessionLength) + " minutes "
                + "with frequency of " + Integer.toString(Utils.getDefaultFrequency(getActivity()));
        Tracker t = ((Application) getActivity().getApplication())
                .getTracker(Application.TrackerName.APP_TRACKER);
        t.enableAdvertisingIdCollection(true);
        // Build and send an Event.
        t.send(new HitBuilders.EventBuilder().setCategory(Constants.SESSION_EVENT).setAction(analyticsSession)
                .build());//from   w w  w  .  j  a  v a 2s  .c o  m
    }
}

From source file:net.homelinux.penecoptero.android.citybikes.app.StationsDBAdapter.java

public void retrieve() throws Exception {
    SharedPreferences settings = this.mCtx.getSharedPreferences(PREF_NAME, 0);
    RAWstations = settings.getString("stations", "[]");
    last_updated = settings.getString("last_updated", null);
    last_updated_time = settings.getLong("last_updated_time", 0);
    @SuppressWarnings("unused")
    String network_url = settings.getString("network_url", "");
}

From source file:net.peterkuterna.android.apps.devoxxsched.service.SyncService.java

@Override
protected void onHandleIntent(Intent intent) {
    final ResultReceiver receiver = intent.getParcelableExtra(EXTRA_STATUS_RECEIVER);
    if (receiver != null)
        receiver.send(STATUS_RUNNING, Bundle.EMPTY);

    final Context context = this;
    final SharedPreferences syncServicePrefs = getSharedPreferences(SyncPrefs.DEVOXXSCHED_SYNC,
            Context.MODE_PRIVATE);
    final int localVersion = syncServicePrefs.getInt(SyncPrefs.LOCAL_VERSION, VERSION_NONE);
    final long lastRemoteSync = syncServicePrefs.getLong(SyncPrefs.LAST_REMOTE_SYNC, 0);

    try {//from w ww  . jav a 2  s.c o m
        // Bulk of sync work, performed by executing several fetches from
        // local and online sources.

        final long startLocal = System.currentTimeMillis();
        final boolean localParse = localVersion < VERSION_LOCAL;
        Log.d(TAG, "found localVersion=" + localVersion + " and VERSION_LOCAL=" + VERSION_LOCAL);
        if (localParse) {
            // Parse values from local cache first
            mLocalExecutor.execute(R.xml.search_suggest, new LocalSearchSuggestHandler());
            mLocalExecutor.execute(context, "cache-rooms.json", new RemoteRoomsHandler());
            mLocalExecutor.execute(context, "cache-presentationtypes.json", new RemoteSessionTypesHandler());
            mLocalExecutor.execute(context, "cache-speakers.json", new RemoteSpeakersHandler());
            mLocalExecutor.execute(context, "cache-presentations.json", new RemoteSessionsHandler());
            mLocalExecutor.execute(context, "cache-schedule.json", new RemoteScheduleHandler());

            // Save local parsed version
            syncServicePrefs.edit().putInt(SyncPrefs.LOCAL_VERSION, VERSION_LOCAL).commit();
        }
        Log.d(TAG, "local sync took " + (System.currentTimeMillis() - startLocal) + "ms");

        final long startRemote = System.currentTimeMillis();
        boolean performRemoteSync = performRemoteSync(mResolver, mHttpClient, intent, context);
        if (performRemoteSync) {
            // Parse values from REST interface
            ArrayList<RequestHash> result = mRemoteExecutor.executeGet(new String[] { Constants.ROOMS_URL, },
                    new RemoteRoomsHandler());
            for (RequestHash requestHash : result) {
                SyncUtils.updateLocalMd5(mResolver, requestHash.getUrl(), requestHash.getMd5());
            }
            result = mRemoteExecutor.executeGet(new String[] { Constants.LABS_PRESENTATION_TYPES_URL, },
                    new RemoteSessionTypesHandler());
            for (RequestHash requestHash : result) {
                SyncUtils.updateLocalMd5(mResolver, requestHash.getUrl(), requestHash.getMd5());
            }
            result = mRemoteExecutor.executeGet(
                    new String[] { Constants.SPEAKERS_URL, Constants.LABS_SPEAKERS_URL, },
                    new RemoteSpeakersHandler());
            for (RequestHash requestHash : result) {
                SyncUtils.updateLocalMd5(mResolver, requestHash.getUrl(), requestHash.getMd5());
            }
            result = mRemoteExecutor.executeGet(
                    new String[] { Constants.PRESENTATIONS_URL, Constants.LABS_PRESENTATIONS_URL, },
                    new RemoteSessionsHandler());
            for (RequestHash requestHash : result) {
                SyncUtils.updateLocalMd5(mResolver, requestHash.getUrl(), requestHash.getMd5());
            }
            result = mRemoteExecutor.executeGet(
                    new String[] { Constants.SCHEDULE_URL, Constants.LABS_SCHEDULE_URL, },
                    new RemoteScheduleHandler());
            for (RequestHash requestHash : result) {
                SyncUtils.updateLocalMd5(mResolver, requestHash.getUrl(), requestHash.getMd5());
            }

            // Save last remote sync time
            syncServicePrefs.edit().putLong(SyncPrefs.LAST_REMOTE_SYNC, startRemote).commit();
            // Save remote parsed version
            syncServicePrefs.edit().putInt(SyncPrefs.LOCAL_VERSION, VERSION_REMOTE).commit();
        }
        Log.d(TAG, "remote sync took " + (System.currentTimeMillis() - startRemote) + "ms");

        if (!localParse && performRemoteSync) {
            NotificationUtils.cancelNotifications(context);
            NotificationUtils.notifyNewSessions(context, getContentResolver());
            NotificationUtils.notifyChangedStarredSessions(context, getContentResolver());
        }
    } catch (Exception e) {
        Log.e(TAG, "Problem while syncing", e);

        if (receiver != null) {
            // Pass back error to surface listener
            final Bundle bundle = new Bundle();
            bundle.putString(Intent.EXTRA_TEXT, e.toString());
            receiver.send(STATUS_ERROR, bundle);
        }
    }

    // Announce success to any surface listener
    Log.d(TAG, "sync finished");
    if (receiver != null)
        receiver.send(STATUS_FINISHED, Bundle.EMPTY);
}

From source file:it.gulch.linuxday.android.activities.MainActivity.java

@Override
protected void onStart() {
    super.onStart();

    // Ensure the progress bar is hidden when starting
    //setSupportProgressBarVisibility(false);

    // Monitor the schedule download
    LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
    lbm.registerReceiver(scheduleDownloadProgressReceiver,
            new IntentFilter(LinuxDayApi.ACTION_DOWNLOAD_SCHEDULE_PROGRESS));
    lbm.registerReceiver(scheduleDownloadResultReceiver,
            new IntentFilter(LinuxDayApi.ACTION_DOWNLOAD_SCHEDULE_RESULT));

    // Download reminder
    long now = System.currentTimeMillis();
    long time = preferencesService.getLastUpdateTime(this);
    if ((time == -1L) || (time < (now - DATABASE_VALIDITY_DURATION))) {
        SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE);
        time = prefs.getLong(PREF_LAST_DOWNLOAD_REMINDER_TIME, -1L);
        if ((time == -1L) || (time < (now - DOWNLOAD_REMINDER_SNOOZE_DURATION))) {
            prefs.edit().putLong(PREF_LAST_DOWNLOAD_REMINDER_TIME, now).commit();

            FragmentManager fm = getSupportFragmentManager();
            if (fm.findFragmentByTag("download_reminder") == null) {
                new DownloadScheduleReminderDialogFragment().show(fm, "download_reminder");
            }/*  w w  w.  j ava2s .  c  o  m*/
        }
    }
}

From source file:com.nextgis.mobile.fragment.LayersFragment.java

protected void updateInfo() {
    if (null == mInfoText) {
        return;/*from   www .ja v  a 2s . co  m*/
    }

    SharedPreferences sharedPreferences = getActivity().getSharedPreferences(Constants.PREFERENCES,
            Constants.MODE_MULTI_PROCESS);
    long timeStamp = sharedPreferences.getLong(SettingsConstants.KEY_PREF_LAST_SYNC_TIMESTAMP, 0);
    if (timeStamp > 0) {
        mInfoText.setText(ControlHelper.getSyncTime(getContext(), timeStamp));
    }
}