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:eu.liveGov.libraries.livegovtoolkit.helper.UserInformationHelper.java

public static int getAnonymousUserId(Context c) {
    SharedPreferences sharedPreferences = c.getSharedPreferences("UserInformation", Context.MODE_PRIVATE);
    return sharedPreferences.getInt(USER_ID, UserInformation.UNDEFINED_ID);
}

From source file:Main.java

public static Object getSp(Context context, String key, Object defaultObject) {
    String type = defaultObject.getClass().getSimpleName();
    String packageName = context.getPackageName();
    SharedPreferences sp = context.getSharedPreferences(packageName, Context.MODE_PRIVATE);
    if ("String".equals(type)) {
        return sp.getString(key, (String) defaultObject);
    } else if ("Integer".equals(type)) {
        return sp.getInt(key, (Integer) defaultObject);
    } else if ("Boolean".equals(type)) {
        return sp.getBoolean(key, (Boolean) defaultObject);
    } else if ("Float".equals(type)) {
        return sp.getFloat(key, (Float) defaultObject);
    } else if ("Long".equals(type)) {
        return sp.getLong(key, (Long) defaultObject);
    }// www  .j  a v a  2  s .c o  m
    return null;
}

From source file:Main.java

public static Object get(Context context, String key, Object defaultObject) {
    SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
    if (defaultObject instanceof String) {
        return sp.getString(key, (String) defaultObject);
    } else if (defaultObject instanceof Integer) {
        return sp.getInt(key, (Integer) defaultObject);
    } else if (defaultObject instanceof Boolean) {
        return sp.getBoolean(key, (Boolean) defaultObject);
    } else if (defaultObject instanceof Float) {
        return sp.getFloat(key, (Float) defaultObject);
    } else if (defaultObject instanceof Long) {
        return sp.getLong(key, (Long) defaultObject);
    }//from www. j av  a 2  s .  c o m
    return null;
}

From source file:Main.java

public static Object get(Context context, String key, Object defaultObject) {
    SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);

    if (defaultObject instanceof String) {
        return sp.getString(key, (String) defaultObject);
    } else if (defaultObject instanceof Integer) {
        return sp.getInt(key, (Integer) defaultObject);
    } else if (defaultObject instanceof Boolean) {
        return sp.getBoolean(key, (Boolean) defaultObject);
    } else if (defaultObject instanceof Float) {
        return sp.getFloat(key, (Float) defaultObject);
    } else if (defaultObject instanceof Long) {
        return sp.getLong(key, (Long) defaultObject);
    }/*from ww  w  .  ja va  2  s  . c o m*/

    return null;
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static <T> T getPref(Context _context, String prefKey, T defValue, Class<T> clazz) {
    final SharedPreferences pref = getDefaultSharedPreferences(_context);
    if (Long.class == clazz) {
        return (T) (Long.valueOf(pref.getLong(prefKey, (Long) defValue)));
    } else if (Integer.class == clazz) {
        return (T) (Integer.valueOf(pref.getInt(prefKey, (Integer) defValue)));
    } else if (defValue instanceof String) {
        return (T) (pref.getString(prefKey, String.valueOf(defValue)));
    } else if (defValue instanceof Boolean) {
        return (T) (Boolean.valueOf(pref.getBoolean(prefKey, (Boolean) defValue)));
    }//from  w ww. jav a 2 s  .com
    throw new UnsupportedOperationException("Class " + clazz + " not supported");
}

From source file:com.sublimis.urgentcallfilter.MyPreference.java

public static int getIntPref(int prefKeyResId, int defaultValue) {
    String prefKey = getStringResource(prefKeyResId);
    SharedPreferences sharedPrefs = getPrefs();

    if (sharedPrefs != null)
        return sharedPrefs.getInt(prefKey, defaultValue);
    else//from   ww w . j a  v  a 2 s  .  c  o m
        return defaultValue;
}

From source file:Main.java

public static int getApplicationIconBadgeNumber(Context context) {
    SharedPreferences prefs = getApplicationIconBadgeSettings(context);
    if (prefs == null) {
        Log.i(TAG, "Failed to retrieve application icon badge number");
        return 0;
    }/* www  .  j  a  v  a2 s. c  om*/
    Log.i(TAG, "Getting application icon badge number");
    return prefs.getInt(LAST_BADGE_COUNT_TAG, 0);
}

From source file:com.binomed.showtime.android.util.CineShowTimeLayoutUtils.java

public static boolean isPreferenceAnalyticsPresent(SharedPreferences pref) {
    boolean result = false;
    result = pref.getInt(CineShowtimeCst.PREF_KEY_ANALYTICS, -1) != -1;
    return result;
}

From source file:com.libresoft.apps.ARviewer.Utils.GeoNames.AltitudeManager.java

public static double getAbsoluteAltitude(Context context, double base_altitude, boolean is_floor) {
    double altitude = AltitudeManager.NO_ALTITUDE_VALUE;

    if (base_altitude != AltitudeManager.NO_ALTITUDE_VALUE) {
        try {//from  ww w  .ja  v  a 2s.  co  m
            SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);

            float user_height = ((float) sharedPreferences.getInt(AltitudePreferences.KEY_USER_HEIGHT, 175))
                    / 100;

            if (is_floor && sharedPreferences.getBoolean(AltitudePreferences.KEY_USE_FLOOR, false)) {
                int floor_number = sharedPreferences.getInt(AltitudePreferences.KEY_FLOOR, 0);

                altitude = (float) (base_altitude + user_height + floor_number * 3); // 3 meters per room
                Log.d("AltitudeManager", "Using floor");
            } else
                altitude = (float) (base_altitude + user_height);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            Log.e("AltitudeManager", e.toString());
        }
    }

    return altitude;
}

From source file:Main.java

public static Object getData(Context context, String fileName, String key, Class clazz) {
    SharedPreferences sharedPreferences = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
    if (clazz.getName().equals(String.class.getName())) {
        return sharedPreferences.getString(key, "");
    } else if (clazz.getName().equals(Integer.class.getName())) {
        return sharedPreferences.getInt(key, 0);
    } else if (clazz.getName().equals(Float.class.getName())) {
        return sharedPreferences.getFloat(key, 0);
    } else if (clazz.getName().equals(Long.class.getName())) {
        return sharedPreferences.getLong(key, 0);
    } else {//from  w w w. j av  a2 s .c om
        return sharedPreferences.getBoolean(key, false);
    }
}