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:Main.java

public static int getAlarmSettingsForID(Context context, String id) {
    SharedPreferences settings = context.getSharedPreferences(BCB14_ALARMS, Context.MODE_PRIVATE);
    return settings.getInt(ALARM_PREFIX + id, ALARM_NOT_SET);
}

From source file:Main.java

public static Integer getUsageNumber(Context context) {
    Integer value = 0;//w ww.  jav a 2s.c  om

    try {
        SharedPreferences settings = context.getSharedPreferences("Settings", Context.MODE_PRIVATE);
        value = settings.getInt("usage_num", 0);
    } catch (Exception e) {
        e.printStackTrace();
    }

    return value;
}

From source file:Main.java

public static void increment(Context context, String key, int amount) {
    SharedPreferences sp = context.getSharedPreferences(DEFAULT_FILE_NAME, Context.MODE_PRIVATE);
    int count = sp.getInt(key, -1);
    if (count == -1)
        count = 0;//from  www  . j  a  v  a  2  s . co  m
    count++;
    SharedPreferences.Editor editor = context.getSharedPreferences(DEFAULT_FILE_NAME, Context.MODE_PRIVATE)
            .edit();
    editor.putInt(key, count);
    editor.commit();
}

From source file:Main.java

/**
 * Method to get the last assumed Stage of the active session 
 * /*  w  w  w. j a v a  2 s.c  o  m*/
 * @param context Context
 * @return Last assumed Stage of the active session 
 */
public static int getActiveSessionStage(Context context) {
    SharedPreferences prefs = context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);

    return prefs.getInt(PREFS_KEY_STAGE, 0);
}

From source file:Main.java

public static int getInt(Context context, String key) {
    SharedPreferences sharedPreferences = context.getSharedPreferences("Zelory", Context.MODE_PRIVATE);

    return sharedPreferences.getInt(key, 0);
}

From source file:Main.java

public static Integer getPreferences(Context context, String key, int defValue) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    Integer savedPref = sharedPreferences.getInt(key, defValue);
    return savedPref;
}

From source file:Main.java

public static int GetInt(Context context, String key, int defaultValue) {
    SharedPreferences settings = context.getSharedPreferences(ConfigurationName, Context.MODE_PRIVATE);

    return settings.getInt(key, defaultValue);
}

From source file:Main.java

public static ArrayList<String> loadSavedCityList(Context c) {
    ArrayList<String> list = new ArrayList<String>();

    SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
    int cityNum = preferences.getInt(PREF_KEPT_CITY_NUM_KEY, 0);

    for (int i = 0; i < cityNum; i++) {
        String keptCity = preferences.getString(PREF_KEPT_CITY_ITEM_BASE + (i + 1), "");

        if (!TextUtils.isEmpty(keptCity)) {
            list.add(keptCity);/*from   w w  w  .  j  a  v a 2s  .  co m*/
        }
    }
    return list;
}

From source file:Main.java

/**
 * Gets the preference.//from w  ww .j a  v  a2 s. co m
 *
 * @param key the key
 * @param defaultValue the default value
 * @return the preference
 */
public static int getPreference(String key, int defaultValue, Context c) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(c);
    return preferences.getInt(key, defaultValue);
}

From source file:Main.java

public static int getIntSharedPref(Context context, String key, int mode) {
    SharedPreferences sharedPref = context.getSharedPreferences(SHARED_PREFERENCES_FILE, mode);
    int defaultValue = 0;
    return sharedPref.getInt(key, defaultValue);

}