Example usage for android.content SharedPreferences getInt

List of usage examples for android.content SharedPreferences getInt

Introduction

In this page you can find the example usage for android.content SharedPreferences getInt.

Prototype

int getInt(String key, int defValue);

Source Link

Document

Retrieve an int value from the preferences.

Usage

From source file:de.schaeuffelhut.android.openvpn.Preferences.java

public final static int getDnsChange(Context context, File configFile) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    return sharedPreferences.getInt(Preferences.KEY_CONFIG_DNSCHANGE(configFile), -1);
}

From source file:com.adkdevelopment.earthquakesurvival.utils.Utilities.java

/**
 * Method to return Magnitude from SharedPreferences
 * @param context from which call is being made
 * @return value of magnitude to query and show
 *///  w  w w  .j ava  2 s . com
public static int getMagnitudePrefs(Context context) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    return sharedPreferences.getInt(context.getString(R.string.sharedprefs_key_magnitude), 3);
}

From source file:com.adkdevelopment.earthquakesurvival.utils.Utilities.java

/**
 * Returns sorting preference//from  www.j a  v a2s  .  c  o m
 * @param context from which call is being made
 * @return int preference according to the database schema
 */
public static int getSortingPreference(Context context) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    return sharedPreferences.getInt(context.getString(R.string.sharedprefs_key_sort),
            EarthquakeObject.SORT_TIME);
}

From source file:de.schaeuffelhut.android.openvpn.Preferences.java

public final static int getNotificationId(Context context, File configFile) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    int id = sharedPreferences.getInt(Preferences.KEY_CONFIG_NOTIFICATION_ID(configFile), -1);
    if (id == -1) {
        synchronized (KEY_NEXT_NOTIFICATION_ID) {
            id = sharedPreferences.getInt(KEY_NEXT_NOTIFICATION_ID, FIRST_CONFIG_ID);
            Editor edit = sharedPreferences.edit();
            edit.putInt(Preferences.KEY_CONFIG_NOTIFICATION_ID(configFile), id);
            edit.putInt(KEY_NEXT_NOTIFICATION_ID, id + 1);
            edit.commit();/*from   ww w  .  ja  v a 2 s.  co m*/
        }
    }
    return id;
}

From source file:com.adkdevelopment.earthquakesurvival.utils.Utilities.java

/**
 * Method to get Distance parameter from the SharedPreferences
 * @param context from which call is being made
 * @return distance in meters to use in Geofence radius
 *///from w w w  .  j  a  v a  2  s .c  o  m
public static int getDistancePrefs(Context context) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    int distance = sharedPreferences.getInt(context.getString(R.string.sharedprefs_key_distance), 25);
    // miles
    distance = (int) (distance * 1000 * 1.6);
    return distance;
}

From source file:com.scoreflex.ScoreflexGcmClient.java

protected static String getRegistrationId(Context c) {
    final SharedPreferences prefs = Scoreflex.getSharedPreferences(c);
    String registrationId = prefs.getString(GCM_REGISTRATION_ID_PREF_NAME, "");
    if (registrationId == null || registrationId.length() > 0) {
        return "";
    }/*from  ww  w  .j av a  2  s  . c  o  m*/

    int registeredVersion = prefs.getInt(GCM_REGISTRATION_APP_VERSION_PREF_NAME, Integer.MIN_VALUE);
    int currentVersion = getAppVersion(Scoreflex.getApplicationContext());
    if (registeredVersion != currentVersion) {
        return "";
    }
    return registrationId;
}

From source file:fr.simon.marquis.preferencesmanager.util.Utils.java

private static boolean needToBackport(SharedPreferences sp) {
    // 18 was the latest version code release with old Backup system
    return sp.getInt(VERSION_CODE_KEY, 0) <= 18;
}

From source file:bander.notepad.Notepad.java

/**
 * Sets the theme for AppCompat. There is really no dark theme at the moment, it is mainly for
 * the Toolbar Color Chooser.//from   w ww  .j  a  va  2s . com
 *
 * @param activity ActionBarActivity acting as a Context
 * @param classType Launch a new activity.
 */
public static void setAppCompatThemeFromPreferences(ActionBarActivity activity, String classType) {
    SharedPreferences mSettings = PreferenceManager.getDefaultSharedPreferences(activity);
    if (mSettings.getString("themeType", "0").equals("0")) {
        final int abc = mSettings.getInt("actionBarColor", 0);

        /**
         * In case you are wondering, the random numbers are the 500 colors that show up with
         * black text from here:
         * {@link http://www.google.com/design/spec/style/color.html}
         * The black text means that I have to use a light theme.
         */
        if (abc >= 11 && abc <= 15 || abc == 18) {
            mSettings.edit().putBoolean("darkAppCompatTheme", false).apply();
        } else {
            mSettings.edit().putBoolean("darkAppCompatTheme", true).apply();
        }
    } else {
        /**
         * Somehow, we ended up with the wrong theme, so let's launch the right activity.
         */
        switch (classType) {
        case "Prefs": {
            Intent intent = new Intent();
            intent.setClass(activity, PrefsActivity.class);
            activity.startActivity(intent);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP
                    | Intent.FLAG_ACTIVITY_NEW_TASK);
            new PrefsActivityAppCompat().finish();
            break;
        }
        case "Edit": {
            Intent intent = new Intent();
            intent.setClass(activity, NoteEdit.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP
                    | Intent.FLAG_ACTIVITY_NEW_TASK);
            activity.startActivity(intent);
            new NoteEditAppCompat().finish();
            break;
        }
        case "NoteList": {
            Intent intent = new Intent();
            intent.setClass(activity, NoteList.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP
                    | Intent.FLAG_ACTIVITY_NEW_TASK);
            activity.startActivity(intent);
            new NoteListAppCompat().finish();
            break;
        }
        default: {
            Intent intent = new Intent();
            intent.setClass(activity, Notepad.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP
                    | Intent.FLAG_ACTIVITY_NEW_TASK);
            activity.startActivity(intent);
            break;
        }
        }
    }
}

From source file:com.ichi2.anki.AnkiDroidApp.java

public static boolean initiateGestures(SharedPreferences preferences) {
    Boolean enabled = preferences.getBoolean("gestures", false);
    if (enabled) {
        int sensitivity = preferences.getInt("swipeSensitivity", 100);
        if (sensitivity != 100) {
            float sens = 100.0f / sensitivity;
            sSwipeMinDistance = (int) (DEFAULT_SWIPE_MIN_DISTANCE * sens + 0.5f);
            sSwipeThresholdVelocity = (int) (DEFAULT_SWIPE_THRESHOLD_VELOCITY * sens + 0.5f);
        } else {//www  .  j a v a2s.  com
            sSwipeMinDistance = DEFAULT_SWIPE_MIN_DISTANCE;
            sSwipeThresholdVelocity = DEFAULT_SWIPE_THRESHOLD_VELOCITY;
        }
    }
    return enabled;
}

From source file:com.example.igorklimov.popularmoviesdemo.helpers.Utility.java

public static int getPagePreference(Context c) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c);
    switch (getSortByPreference(c)) {
    case 1://ww w.  ja v  a  2s . c o m
        return prefs.getInt(c.getString(R.string.pop_page), 1);
    case 2:
        return prefs.getInt(c.getString(R.string.release_page), 1);
    case 3:
        return prefs.getInt(c.getString(R.string.votes_page), 1);
    }
    return -1;
}