SharedPreferences getInt - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for SharedPreferences getInt method.

This code example shows how to use the following methods:getInt
		GdxTests.tests.add(MatrixTest.class); 
		List<String> testNames = GdxTests.getNames();
		setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, testNames));
 
		prefs = getSharedPreferences("libgdx-tests", Context.MODE_PRIVATE);
		getListView().setSelectionFromTop(prefs.getInt("index", 0), prefs.getInt("top", 0));
	} 
 
	protected void onListItemClick (ListView listView, View view, int position, long id) {
		super.onListItemClick(listView, view, position, id);
 
		Editor editor = prefs.edit();
		editor.putInt("index", listView.getFirstVisiblePosition());
		editor.putInt("top", listView.getChildAt(0) == null ? 0 : listView.getChildAt(0).getTop());
		editor.commit();
 
		Object o = this.getListAdapter().getItem(position);
		String testName = o.toString();
 
		Bundle bundle = new Bundle();
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getInt
		return sharedPrefs.getBoolean(key, false);
	} 
 
	@Override 
	public int getInteger (String key) {
		return sharedPrefs.getInt(key, 0);
	} 
 
	@Override 
	public long getLong (String key) {
		return sharedPrefs.getLong(key, 0);
	} 
 
	@Override 
	public float getFloat (String key) {
		return sharedPrefs.getFloat(key, 0);
	} 
 
	@Override 
	public String getString (String key) {
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getInt
        editor.commit();
    } 
 
    public void readFromLocal() { 
        SharedPreferences prefs = mContext.getSharedPreferences(APP_PREF, Context.MODE_PRIVATE);
        mPasswordQuality = prefs.getInt(KEY_PASSWORD_QUALITY, -1);
        mPasswordLength = prefs.getInt(KEY_PASSWORD_LENGTH, -1);
        mPasswordMinUpperCase = prefs.getInt(KEY_PASSWORD_MIN_UPPERCASE, -1);
    } 
 
    /** 
     * Getter for password quality. 
     * 
     * @return 
     */ 
    public int getPasswordQuality() { return mPasswordQuality; }
 
    /** 
     * Getter for password length. 
     * 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:edit, getBoolean, getInt, getLong
     * @return the wall clock time ({@link System#currentTimeMillis()}) when the 
     * next operation should be attempted -- immediately, if the return value is 
     * before the current time. 
     */ 
    public long getNextTimeMillis(Options options) {
        boolean enabledState = mStorage.getBoolean(PREFIX + "enabledState", true);
        if (!enabledState) return Long.MAX_VALUE;
 
        boolean permanentError = mStorage.getBoolean(PREFIX + "permanentError", false);
        if (permanentError) return Long.MAX_VALUE;
 
        // We do quite a bit of limiting to prevent a clock rollback from totally 
        // hosing the scheduler.  Times which are supposed to be in the past are 
        // clipped to the current time so we don't languish forever. 
 
        int errorCount = mStorage.getInt(PREFIX + "errorCount", 0);
        long now = currentTimeMillis();
        long lastSuccessTimeMillis = getTimeBefore(PREFIX + "lastSuccessTimeMillis", now);
        long lastErrorTimeMillis = getTimeBefore(PREFIX + "lastErrorTimeMillis", now);
        long triggerTimeMillis = mStorage.getLong(PREFIX + "triggerTimeMillis", Long.MAX_VALUE);

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:edit, getInt
        } 
    } 
 
    private int getAndIncrementPref(String pref) {
        final SharedPreferences prefs = mPrefs;
        int value = prefs.getInt(pref, 0);
        SharedPreferences.Editor editor = prefs.edit();
        editor.putInt(pref, value + 1);
        SharedPreferencesCompat.apply(editor);
        return value;
    } 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getInt, getString
 
	public void initAfterCore(MapsApplication app) {
		//Loading settings from phone and setting measurement unit  
		GeneralSettings coreSettings = this.mapsApplication.getCore().getGeneralSettings();
        SharedPreferences prefs = openPrefs();
        this.setMeasurementSystem(prefs.getInt(KEY_MEASUREMENTS, coreSettings.getMeasurementSystem()));
        this.mapsApplication.setSavedAddress(prefs.getString(KEY_SAVED_ADDRESS, null));
        int lat = prefs.getInt(KEY_SAVED_ADDRESS_LATITUDE, 0);
        int lon = prefs.getInt(KEY_SAVED_ADDRESS_LONGITUDE, 0);
        if (lat != 0 && lon != 0) {
            this.mapsApplication.setSavedAddressPosition(new Position(lat, lon));
        } 
	} 
 
	public void setServerAddress(String url, int port) {
	    if(this.serverUrl == null || !this.serverUrl.equals(url) || this.serverPort != port) {
    		this.serverUrl = url;
    		this.serverPort = port;
            if(this.listener != null) {
                this.listener.onSettingsChangeListener(this);
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:edit, getBoolean, getInt
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:edit, getInt
    btn.setText(String.valueOf(prefs.getInt(KEY, 0)));
  } 
 
  @Override 
  public void onClick(View v) {
    prefs.edit().putInt(KEY, prefs.getInt("test", 0) + 1).apply();
  } 
} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getInt, getLong, getString
    } 
  } 
 
  public static String getRegistrationId(Context context) {
    final SharedPreferences prefs=getGCMPreferences(context);
    String registrationId=prefs.getString(PROPERTY_REG_ID, "");
    // check if app was updated; if so, it must clear 
    // registration id to 
    // avoid a race condition if GCM sends a message 
    int oldVersion=
        prefs.getInt(PROPERTY_APP_VERSION, Integer.MIN_VALUE);
    int newVersion=getAppVersion(context);
    if (oldVersion != Integer.MIN_VALUE && oldVersion != newVersion) {
      Log.v(TAG, "App version changed from " + oldVersion + " to "
          + newVersion + "; resetting registration id");
      clearRegistrationId(context);
      registrationId="";
    } 
    else if (isRegistrationExpired(context)) {
      Log.v(TAG, "Registration expired; resetting registration id");

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:edit, getBoolean, getInt
	private static final String LAUNCH_COUNT = "launches";
	private static final String THRESHOLD = "threshold";
	 
    public static final void onLaunch(final Context context, final int launchesUntilPrompt, final String appName, final String packageName) {
        SharedPreferences prefs = context.getSharedPreferences(appName + "rating", 0);
        if (prefs.getBoolean(DONT_SHOW, false)) 
        	return; 
        final SharedPreferences.Editor editor = prefs.edit();
        final int launchCount = prefs.getInt(LAUNCH_COUNT, 0) + 1;
        final int threshold = prefs.getInt(THRESHOLD, launchesUntilPrompt);
        editor.putInt(LAUNCH_COUNT, launchCount);
        if (launchCount == threshold) {
            final AlertDialog.Builder builder = new AlertDialog.Builder(context);
    		builder.setTitle("Like " + appName + "?")
    			   .setCancelable(true)
    			   .setPositiveButton("Rate It Now", new DialogInterface.OnClickListener() {
    		           public void onClick(DialogInterface dialog, int id) {
    		        	   	context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + packageName)));
    		                dialog.cancel();
    		           } 
6
CodeRank
Experience pair programming with AI  Get Codota for Java

Related SharedPreferences getInt Questions & Answers:

getInt Method Overview
Retrieve an int value from the preferences.
See Code Examples for other Android SharedPreferences Methods: