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.juanojfp.gcmsample.MainActivity.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.// ww w  . j  a  v a2  s .  co  m
 *
 * @return true if the registration has expired.
 */
private boolean isRegistrationExpired() {
    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:com.yeldi.yeldibazaar.ManageRepo.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("lightTheme", false))
        setTheme(R.style.AppThemeLight);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.repolist);/*from   ww w .ja v a2 s  . c o m*/

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

    TextView tv_lastCheck = (TextView) findViewById(R.id.lastUpdateCheck);
    long lastUpdate = prefs.getLong("lastUpdateCheck", 0);
    String s_lastUpdateCheck = "";
    if (lastUpdate == 0) {
        s_lastUpdateCheck = getString(R.string.never);
    } else {
        Date d = new Date(lastUpdate);
        s_lastUpdateCheck = DateFormat.getDateFormat(this).format(d) + " "
                + DateFormat.getTimeFormat(this).format(d);
    }
    tv_lastCheck.setText(getString(R.string.last_update_check, s_lastUpdateCheck));

    reposToRemove = new ArrayList<String>();
    reposToDisable = new ArrayList<String>();
}

From source file:cn.sharesdk.analysis.util.PreferencesHelper.java

/** get the time of last post log */
public long getLastReportTime() {
    SharedPreferences preferences = context.getSharedPreferences("mobclick_agent_state_" + packageName,
            Context.MODE_PRIVATE);
    return preferences.getLong("last_report_time", 0);
}

From source file:no.ntnu.idi.socialhitchhiking.utility.ShareOnFacebook.java

/**
 * Sets facebook token from Shared Preferences.
 * @param {@link Facebook}//  w  w w. j  a  v a  2  s.c  om
 * @return {@link true} if facebook session is valid
 */
@SuppressWarnings("deprecation")
public boolean restoreCredentials(Facebook facebook) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApp());
    facebook.setAccessToken(sharedPreferences.getString(TOKEN, null));
    facebook.setAccessExpires(sharedPreferences.getLong(EXPIRES, 0));
    return facebook.isSessionValid();
}

From source file:org.exobel.routerkeygen.ui.NetworksListActivity.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override/*from  ww  w  .j a v a2s. com*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_networks_list);

    networkListFragment = ((NetworksListFragment) getFragmentManager()
            .findFragmentById(R.id.frag_networks_list));
    if (findViewById(R.id.keygen_fragment) != null) {
        mTwoPane = true;
        networkListFragment.setActivateOnItemClick(true);
    }
    wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);

    wifiState = wifi.getWifiState() == WifiManager.WIFI_STATE_ENABLED
            || wifi.getWifiState() == WifiManager.WIFI_STATE_ENABLING;
    scanFinished = new WifiScanReceiver(wifi, networkListFragment, this);
    stateChanged = new WifiStateReceiver(wifi, networkListFragment);

    final SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    welcomeScreenShown = mPrefs.getBoolean(Preferences.VERSION, false);

    final long timePassed = System.currentTimeMillis() - mPrefs.getLong(LAST_DIALOG_TIME, 0);
    if (!welcomeScreenShown || (timePassed > DateUtils.WEEK_IN_MILLIS)) {
        final SharedPreferences.Editor editor = mPrefs.edit();
        editor.putBoolean(Preferences.VERSION, true);
        editor.putLong(LAST_DIALOG_TIME, System.currentTimeMillis());
        editor.apply();

        // Checking for updates every week
        if (BuildConfig.APPLICATION_ID.equals("org.exobel.routerkeygen")) {
            startService(new Intent(getApplicationContext(), UpdateCheckerService.class));
        }
        //
    }

    mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swiperefresh);
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            scan();
        }
    });
    mSwipeRefreshLayout.setColorSchemeResources(R.color.accent);
}

From source file:org.dpadgett.timer.StopwatchFragment.java

private void restoreState() {
    final SharedPreferences prefs = context.getSharedPreferences("Stopwatch", Context.MODE_PRIVATE);

    if (prefs.contains("isTimerRunning")) {
        isTimerRunning = prefs.getBoolean("isTimerRunning", false);
        timeStarted = prefs.getLong("timeStarted", 0L);
        additionalElapsed = prefs.getLong("additionalElapsed", 0L);
        additionalLapTimeElapsed = prefs.getLong("additionalLapTimeElapsed", 0L);
        lapTimes.restoreState(prefs);/*  w w w . j av  a 2  s  .  c o m*/
    }

    final Button startButton = (Button) rootView.findViewById(R.id.startButton);
    final Button resetButton = (Button) rootView.findViewById(R.id.stopButton);

    timerText.setStartingTime(timeStarted - additionalElapsed - additionalLapTimeElapsed);
    lapTimeText.setStartingTime(timeStarted - additionalElapsed);

    if (autoStartStopwatch == true) {
        if (isTimerRunning) {
            lap();
        } else {
            // TODO: if current stopped timer == 0, then start
            // if !=0, then lap and start, that way the time of a stopped timer is not lost.
            reset();
            start();
        }
        autoStartStopwatch = false;
    }

    if (isTimerRunning) {
        timerText.resume();
        lapTimeText.resume();
        startButton.setText(context.getString(R.string.stopwatch_button_stop));
        resetButton.setText(context.getString(R.string.stopwatch_button_lap));
    }
    timerText.forceUpdate(timeStarted);
    lapTimeText.forceUpdate(timeStarted);
}

From source file:cn.sharesdk.analysis.util.PreferencesHelper.java

/** get session time */
public long getSessionTime() {
    SharedPreferences preferences2sessiontime = context
            .getSharedPreferences("mobclick_agent_state_" + packageName, Context.MODE_PRIVATE);
    return preferences2sessiontime.getLong("session_save_time", 0);
}

From source file:withings.apiaccess.WithingsAPI.java

private void loadUser() {
    SharedPreferences preferences = context.getSharedPreferences(PREFERENCES_FILE, Context.MODE_PRIVATE);
    if (!preferences.contains("name")) {
        user = null;// w  w  w.ja  va2  s. c om
        return;
    }

    long id = preferences.getLong("id", 0);
    String name = preferences.getString("name", null);
    String publicKey = preferences.getString("publicKey", null);
    callbackId = preferences.getLong("callbackId", -1);
    user = new WithingsUser(id, name, publicKey, 0);
}

From source file:com.google.samples.apps.gameloopmanager.TestLoopsActivity.java

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test_loops);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    launchAllButton = (Button) findViewById(R.id.run_all);
    launchAllButton.setOnClickListener(new OnClickListener() {
        @Override/*from ww w .j a v a2s  .c o m*/
        public void onClick(View v) {
            startLoopFromUi();
        }
    });

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    timeout = prefs.getLong(TIMEOUT, 3 * 60 * 1000);

    if (savedInstanceState != null) {
        checkedScenarios.addAll(savedInstanceState.getIntegerArrayList(CHECKED_SCENARIOS));
        List<TestLoopGroup> savedTestLoopGroups = savedInstanceState.getParcelableArrayList(TEST_LOOP_GROUPS);
        testLoopGroups.addAll(savedTestLoopGroups);
        updateTestLoopButton();
    }

    resolveInfo = getIntent().getParcelableExtra("resolveInfo");

    adapter = new TestLoopGroupAdapter(this, checkedScenarios, testLoopGroups);
    expandableListView = (ExpandableListView) findViewById(R.id.test_loop_list);
    expandableListView.setAdapter(adapter);
    expandableListView.setOnChildClickListener(new OnChildClickListener() {
        @Override
        public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition,
                long id) {
            if (childPosition == 0) {
                CheckBox checkBox = (CheckBox) v;
                if (checkBox.isChecked()) {
                    for (int item : adapter.getGroup(groupPosition).getLoops()) {
                        checkedScenarios.remove(item);
                    }
                } else {
                    for (int item : adapter.getGroup(groupPosition).getLoops()) {
                        checkedScenarios.add(item);
                    }
                }
            } else {
                Integer data = adapter.getChild(groupPosition, childPosition - 1);
                if (!checkedScenarios.remove(data)) {
                    checkedScenarios.add(data);
                }
            }

            adapter.notifyDataSetChanged();
            updateTestLoopButton();
            return true;
        }
    });

}