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:net.sf.diningout.app.AppApplication.java

/**
 * Move non-user setting preferences from default to app preferences.
 *//*from   w  w  w  . j a  va 2 s .c  o m*/
private void migrateAppPrefs() {
    SharedPreferences def = Prefs.get(this);
    Editor editDef = def.edit();
    SharedPreferences app = Prefs.get(this, APP);
    Editor editApp = app.edit();
    if (def.contains(ACCOUNT_INITIALISED)) {
        editApp.putBoolean(ACCOUNT_INITIALISED, def.getBoolean(ACCOUNT_INITIALISED, false));
        editDef.remove(ACCOUNT_INITIALISED);
    }
    if (def.contains(ACCOUNT_NAME)) {
        editApp.putString(ACCOUNT_NAME, def.getString(ACCOUNT_NAME, null));
        editDef.remove(ACCOUNT_NAME);
    }
    if (def.contains(CLOUD_ID)) {
        editApp.putString(CLOUD_ID, def.getString(CLOUD_ID, null));
        editDef.remove(CLOUD_ID);
    }
    if (def.contains(INSTALL_ID)) {
        editApp.putLong(INSTALL_ID, def.getLong(INSTALL_ID, 0L));
        editDef.remove(INSTALL_ID);
    }
    if (def.contains(LAST_SYNC)) {
        editApp.putLong(LAST_SYNC, def.getLong(LAST_SYNC, 0L));
        editDef.remove(LAST_SYNC);
    }
    if (def.contains(NAVIGATION_DRAWER_OPENED)) {
        editApp.putBoolean(NAVIGATION_DRAWER_OPENED, def.getBoolean(NAVIGATION_DRAWER_OPENED, false));
        editDef.remove(NAVIGATION_DRAWER_OPENED);
    }
    if (def.contains(ONBOARDED)) {
        editApp.putBoolean(ONBOARDED, def.getBoolean(ONBOARDED, false));
        editDef.remove(ONBOARDED);
    }
    editDef.apply();
    editApp.apply();
}

From source file:org.physical_web.physicalweb.UrlDeviceDiscoveryService.java

private void restoreCache() {
    // Make sure we are trying to load the right version of the cache
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    int prefsVersion = prefs.getInt(PREFS_VERSION_KEY, 0);
    long now = new Date().getTime();
    if (prefsVersion != PREFS_VERSION) {
        mScanStartTime = now;/*from   w w w . jav  a2 s  .c om*/
        return;
    }

    // Don't load the cache if it's stale
    mScanStartTime = prefs.getLong(SCAN_START_TIME_KEY, 0);
    long scanDelta = now - mScanStartTime;
    if (scanDelta >= SCAN_STALE_TIME_MILLIS) {
        mScanStartTime = now;
        return;
    }

    // Restore the cached metadata
    try {
        JSONObject serializedCollection = new JSONObject(prefs.getString(PW_COLLECTION_KEY, null));
        mPwCollection = PhysicalWebCollection.jsonDeserialize(serializedCollection);
        Utils.setPwsEndpoint(this, mPwCollection);
    } catch (JSONException e) {
        Log.e(TAG, "Could not restore Physical Web collection cache", e);
    } catch (PhysicalWebCollectionException e) {
        Log.e(TAG, "Could not restore Physical Web collection cache", e);
    }
    // replace TxPower and RSSI data after restoring cache
    for (UrlDevice urlDevice : mPwCollection.getUrlDevices()) {
        if (Utils.isBleUrlDevice(urlDevice)) {
            Utils.updateRegion(urlDevice);
        }
    }
    // Unresolvable devices are typically not
    // relevant outside of scan range. Hence,
    // we specially clean them from the cache.
    if (scanDelta >= LOCAL_SCAN_STALE_TIME_MILLIS) {
        for (UrlDevice urlDevice : mPwCollection.getUrlDevices()) {
            if (!Utils.isResolvableDevice(urlDevice)) {
                mPwCollection.removeUrlDevice(urlDevice);
            }
        }
    }
}

From source file:com.prey.PreyConfig.java

private long getLong(String key, long defaultValue) {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(ctx);
    return settings.getLong(key, defaultValue);
}

From source file:edu.pdx.cecs.orcycle.MyApplication.java

private void loadApplicationSettings() {

    //generateUserId();  // For resetting while debugging
    SharedPreferences settings = getSharedPreferences(PREFS_APPLICATION, MODE_PRIVATE);
    userId = settings.getString(SETTING_USER_ID, null);
    if ((null == userId) || (userId.equals(""))) {
        userId = generateUserId();//from   w  w w.j  a  v  a2s.c o  m
    }

    firstUse = settings.getLong(SETTING_FIRST_USE, -1);
    if (-1 == firstUse) {
        firstUse = generateFirstUse();
    }

    // setDefaultApplicationSettings();

    firstTripCompleted = settings.getBoolean(SETTING_FIRST_TRIP_COMPLETED, true);

    userProfileUploaded = settings.getBoolean(SETTING_USER_INFO_UPLOADED, false);

    //userWelcomeEnabled = settings.getBoolean(SETTING_USER_WELCOME_ENABLED, true);
    // We are purposely disabling the welcome screen for now
    userWelcomeEnabled = false;

    tutorialEnabled = settings.getBoolean(SETTING_TUTORIAL_ENABLED, true);

    hintDontRepeatTrips = settings.getBoolean(SETTING_HINT_DONT_REPEAT_TRIPS, true);
    hintDoReportNow = settings.getBoolean(SETTING_HINT_DO_REPORT_NOW, true);
    hintDoReportLater = settings.getBoolean(SETTING_HINT_DO_REPORT_LATER, true);
    hintEmailNameAndNumber = settings.getBoolean(SETTING_HINT_EMAIL_NAME_AND_NUMBER, true);

    if (false == (sixMonthAlarmEnabled = settings.getBoolean(SETTING_SIX_MONTH_ALARM_ENABLED, false))) {
        UseReminder.rescheduleAlarm(this.getBaseContext());
        setSixMonthAlarmEnabled(true);
    }

    loadDeviceInfo();
}

From source file:com.andrewshu.android.reddit.settings.RedditSettings.java

public void loadRedditPreferences(Context context, HttpClient client) {
    // Session/*  ww  w.  j a  v a2 s  .  c  o  m*/
    SharedPreferences sessionPrefs = PreferenceManager.getDefaultSharedPreferences(context);
    this.setUsername(sessionPrefs.getString("username", null));
    this.setModhash(sessionPrefs.getString("modhash", null));
    String cookieValue = sessionPrefs.getString("reddit_sessionValue", null);
    String cookieDomain = sessionPrefs.getString("reddit_sessionDomain", null);
    String cookiePath = sessionPrefs.getString("reddit_sessionPath", null);
    long cookieExpiryDate = sessionPrefs.getLong("reddit_sessionExpiryDate", -1);
    if (cookieValue != null) {
        BasicClientCookie redditSessionCookie = new BasicClientCookie("reddit_session", cookieValue);
        redditSessionCookie.setDomain(cookieDomain);
        redditSessionCookie.setPath(cookiePath);
        if (cookieExpiryDate != -1)
            redditSessionCookie.setExpiryDate(new Date(cookieExpiryDate));
        else
            redditSessionCookie.setExpiryDate(null);
        this.setRedditSessionCookie(redditSessionCookie);
        RedditIsFunHttpClientFactory.getCookieStore().addCookie(redditSessionCookie);
        try {
            CookieSyncManager.getInstance().sync();
        } catch (IllegalStateException ex) {
            if (Constants.LOGGING)
                Log.e(TAG, "CookieSyncManager.getInstance().sync()", ex);
        }
    }

    // Default subreddit
    String homepage = sessionPrefs.getString(Constants.PREF_HOMEPAGE, Constants.FRONTPAGE_STRING).trim();
    if (StringUtils.isEmpty(homepage))
        this.setHomepage(Constants.FRONTPAGE_STRING);
    else
        this.setHomepage(homepage);

    // Use external browser instead of BrowserActivity
    this.setUseExternalBrowser(sessionPrefs.getBoolean(Constants.PREF_USE_EXTERNAL_BROWSER, false));

    // Show confirmation dialog when backing out of root Activity
    this.setConfirmQuitOrLogout(sessionPrefs.getBoolean(Constants.PREF_CONFIRM_QUIT, true));

    // Save reddit history to Browser history
    this.setSaveHistory(sessionPrefs.getBoolean(Constants.PREF_SAVE_HISTORY, true));

    // Whether to always show the next/previous buttons, or only at bottom of list
    this.setAlwaysShowNextPrevious(sessionPrefs.getBoolean(Constants.PREF_ALWAYS_SHOW_NEXT_PREVIOUS, true));

    // Comments sort order
    this.setCommentsSortByUrl(sessionPrefs.getString(Constants.PREF_COMMENTS_SORT_BY_URL,
            Constants.CommentsSort.SORT_BY_BEST_URL));

    // Theme and text size
    this.setTheme(Util.getThemeResourceFromPrefs(
            sessionPrefs.getString(Constants.PREF_THEME, Constants.PREF_THEME_LIGHT),
            sessionPrefs.getString(Constants.PREF_TEXT_SIZE, Constants.PREF_TEXT_SIZE_MEDIUM)));

    // Comment guide lines
    this.setShowCommentGuideLines(sessionPrefs.getBoolean(Constants.PREF_SHOW_COMMENT_GUIDE_LINES, true));

    // Rotation
    this.setRotation(RedditSettings.Rotation
            .valueOf(sessionPrefs.getString(Constants.PREF_ROTATION, Constants.PREF_ROTATION_UNSPECIFIED)));

    // Thumbnails
    this.setLoadThumbnails(sessionPrefs.getBoolean(Constants.PREF_LOAD_THUMBNAILS, true));
    // Thumbnails on Wifi
    this.setLoadThumbnailsOnlyWifi(sessionPrefs.getBoolean(Constants.PREF_LOAD_THUMBNAILS_ONLY_WIFI, false));

    // Notifications
    this.setMailNotificationStyle(sessionPrefs.getString(Constants.PREF_MAIL_NOTIFICATION_STYLE,
            Constants.PREF_MAIL_NOTIFICATION_STYLE_DEFAULT));
    this.setMailNotificationService(sessionPrefs.getString(Constants.PREF_MAIL_NOTIFICATION_SERVICE,
            Constants.PREF_MAIL_NOTIFICATION_SERVICE_OFF));
}

From source file:com.ds.kaixin.Kaixin.java

/**
 * /*from   w  w w  . j a v  a2 s  .  c o m*/
 * 
 * @param context
 * @return 
 */
public boolean loadStorage(Context context) {
    SharedPreferences sp = context.getSharedPreferences(KAIXIN_SDK_STORAGE, Context.MODE_PRIVATE);
    String accessToken = sp.getString(KAIXIN_SDK_STORAGE_ACCESS_TOKEN, null);
    if (accessToken == null) {
        return false;
    }

    String refreshToken = sp.getString(KAIXIN_SDK_STORAGE_REFRESH_TOKEN, null);
    if (refreshToken == null) {
        return false;
    }

    long expires = sp.getLong(KAIXIN_SDK_STORAGE_EXPIRES, 0);
    long currenct = System.currentTimeMillis();
    if (expires < (currenct - ONE_HOUR)) {
        clearStorage(context);
        return false;
    }

    mAccessToken = accessToken;
    mRefreshToken = refreshToken;
    mAccessExpires = expires;

    return true;
}

From source file:de.ub0r.android.callmeter.ui.prefs.PreferencesPlain.java

/** Load widget list. */
@SuppressWarnings("deprecation")
private void loadWidgets() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    Preference p = findPreference("container");
    if (p != null && p instanceof PreferenceScreen) {
        PreferenceScreen ps = (PreferenceScreen) p;
        ps.removeAll();//from   w  w  w. java2 s  .  c om
        int[] ids = AppWidgetManager.getInstance(this)
                .getAppWidgetIds(new ComponentName(this, StatsAppWidgetProvider.class));
        boolean added = false;
        if (ids != null && ids.length > 0) {
            for (int id : ids) {
                if (prefs.getLong(StatsAppWidgetProvider.WIDGET_PLANID + id, -1) <= 0) {
                    continue;
                }
                added = true;
                p = new Preference(this);
                p.setTitle(getString(R.string.widget_) + " #" + id);
                final int fid = id;
                p.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                    @Override
                    public boolean onPreferenceClick(final Preference preference) {
                        Intent i = new Intent(PreferencesPlain.this, StatsAppWidgetConfigure.class);
                        i.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, fid);
                        PreferencesPlain.this.startActivity(i);
                        return true;
                    }
                });
                ps.addPreference(p);
            }
        }
        ids = AppWidgetManager.getInstance(this)
                .getAppWidgetIds(new ComponentName(this, LogsAppWidgetProvider.class));
        if (ids != null && ids.length > 0) {
            for (int id : ids) {
                if (prefs.getLong(LogsAppWidgetProvider.WIDGET_PLANID + id, -1) <= 0) {
                    continue;
                }
                added = true;
                p = new Preference(this);
                p.setTitle(getString(R.string.widget_) + " #" + id);
                final int fid = id;
                p.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                    @Override
                    public boolean onPreferenceClick(final Preference preference) {
                        Intent i = new Intent(PreferencesPlain.this, LogsAppWidgetConfigure.class);
                        i.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, fid);
                        PreferencesPlain.this.startActivity(i);
                        return true;
                    }
                });
                ps.addPreference(p);
            }
        }
        if (!added) {
            p = new Preference(this);
            p.setTitle(R.string.widgets_no_widgets_);
            p.setSummary(R.string.widgets_no_widgets_hint);
            ps.addPreference(p);
        }
    }
}

From source file:com.trigger_context.Main_Service.java

@Override
public void onCreate() {
    super.onCreate();
    main_Service = this;
    SharedPreferences users_sp = getSharedPreferences(Main_Service.USERS, MODE_PRIVATE);
    SharedPreferences data_sp = getSharedPreferences(Main_Service.MY_DATA, MODE_PRIVATE);
    conf_macs = new ArrayList<String>(users_sp.getAll().keySet());
    noti(conf_macs.toString(), "");
    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cm.getNetworkInfo(android.net.ConnectivityManager.TYPE_WIFI);
    Intent ServiceIntent = new Intent(this, Network_Service.class);

    if (info != null) {
        if (info.isConnected()) {
            Main_Service.wifi = true;
            Network.setWifiOn(true);/*from w  w w  . j av  a 2  s .com*/
            Thread z = new Thread(new Network());
            z.start();
            try {
                z.join();
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            // start service
            startService(ServiceIntent);
        }
    }
    users_sp.registerOnSharedPreferenceChangeListener(this);
    data_sp.registerOnSharedPreferenceChangeListener(new OnSharedPreferenceChangeListener() {

        @Override
        public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
            // timeout n username can only be added or modified. not removed
            if (key.equals("username")) {
                username = sharedPreferences.getString("username", "defUsername");
            } else {
                timeout = sharedPreferences.getLong("timeout", 5 * 60) * 1000;
            }

        }
    });
    Log.i(LOG_TAG, "Main_Service-onCreate");
    noti("main serv", "started");
}

From source file:com.laquysoft.droidconnl.Hunt.java

/** Loads player progress. */
public void restore(Resources res, Context context) {
    SharedPreferences sharedPref = context.getSharedPreferences(res.getString(R.string.preference_file_key),
            Context.MODE_PRIVATE);

    for (String tag : tags.keySet()) {
        Boolean val = sharedPref.getBoolean(tag, false);
        tagsFound.put(tag, val);
    }/*ww w. j  a  va  2s . co  m*/

    hasSeenIntro = sharedPref.getBoolean(HAS_SEEN_INTRO_KEY, false);
    questionState = sharedPref.getInt(QUESTION_STATE_KEY, QUESTION_STATE_NONE);
    finishTime = sharedPref.getLong(FINISH_TIME_KEY, 0);
}

From source file:com.cerema.cloud2.ui.fragment.OCFileListFragment.java

/**
 * {@inheritDoc}//  ww  w . j a  v a 2s . c  om
 */
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    Log_OC.e(TAG, "onActivityCreated() start");

    if (savedInstanceState != null) {
        mFile = savedInstanceState.getParcelable(KEY_FILE);
    }

    if (mJustFolders) {
        setFooterEnabled(false);
    } else {
        setFooterEnabled(true);
    }

    Bundle args = getArguments();
    mJustFolders = (args == null) ? false : args.getBoolean(ARG_JUST_FOLDERS, false);
    mAdapter = new FileListListAdapter(mJustFolders, getActivity(), mContainerActivity);
    setListAdapter(mAdapter);

    registerLongClickListener();

    boolean hideFab = (args != null) && args.getBoolean(ARG_HIDE_FAB, false);
    if (hideFab) {
        setFabEnabled(false);
    } else {
        setFabEnabled(true);
        registerFabListeners();

        // detect if a mini FAB has ever been clicked
        final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
        if (prefs.getLong(KEY_FAB_EVER_CLICKED, 0) > 0) {
            miniFabClicked = true;
        }

        // add labels to the min FABs when none of them has ever been clicked on
        if (!miniFabClicked) {
            setFabLabels();
        } else {
            removeFabLabels();
        }
    }
}