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 getValue(Context context, String key, int defValue) {
    SharedPreferences sp = context.getSharedPreferences(SETTING, Context.MODE_PRIVATE);
    int value = sp.getInt(key, defValue);
    return value;
}

From source file:Main.java

public static int getInt(Context context, String key) {
    SharedPreferences sp = context.getSharedPreferences(key, Context.MODE_PRIVATE);
    int value;//from  ww  w.  j  av a  2 s .  c  om
    value = sp.getInt(key, -1);
    return value;
}

From source file:Main.java

private static int[] readCache(Activity activity) {
    SharedPreferences config = activity.getSharedPreferences("config", Context.MODE_PRIVATE);
    return new int[] { config.getInt("height", 0), config.getInt("width", 0) };
}

From source file:Main.java

public static boolean isBeamUnlocked(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    return (prefs.getInt(PREF_BEAM_STATE, BEAM_STATE_LOCKED) == BEAM_STATE_UNLOCKED);
}

From source file:Main.java

public static int getIntFromDefaults(Context context, String key) {
    if (context != null) {
        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
        return sharedPreferences.getInt(key, -1);
    } else//w  ww.j  av  a 2s .  c om
        return -1;
}

From source file:Main.java

/**
 * Retrieves the value of counter from preference manager. If no value exists, it will return
 * <code>0</code>.//from   w w w  .j  a v  a  2  s  .c  o m
 */
public static int getCounterFromPreference(Context context) {
    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
    return pref.getInt(PREF_KEY_COUNTER, 0);
}

From source file:Main.java

public static int getDataFromShared(String sharedKey, String key, Context context) {

    SharedPreferences sharedPreferences = context.getSharedPreferences(sharedKey, Context.MODE_PRIVATE);

    return sharedPreferences.getInt(key, 0);
}

From source file:Main.java

public static int getCount(Context context) {
    SharedPreferences preferences = context.getSharedPreferences(DOWN_COUNT, Context.MODE_PRIVATE);
    int count = preferences.getInt(DOWN_COUNT_KEY, 0);
    return count;
}

From source file:Main.java

public static int getDeskEffect(Context context) {
    SharedPreferences preferences = context.getSharedPreferences("DeskEffect", Context.MODE_PRIVATE);
    int effect = preferences.getInt("DeskEffectItem", 0);
    return effect;
}

From source file:Main.java

public static int ReadSharedPreferencesInt(Context context, String name, String key, int defaultvalue) {
    try {//from   ww  w  . ja v  a  2s .  c  o  m
        SharedPreferences userInfo = context.getSharedPreferences(name, Context.MODE_WORLD_READABLE);
        return userInfo.getInt(key, defaultvalue);
    } catch (NullPointerException e) {
        return -1;
    }
}