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 <T> T getData(Context context, String fileName, String key, Class T) {
    SharedPreferences sharedPreferences = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
    T result;/*  w  w w.j  a va2s .  co  m*/
    if (String.class.isAssignableFrom(T)) {
        result = (T) sharedPreferences.getString(key, "");
    } else if (Integer.class.isAssignableFrom(T)) {
        result = (T) Integer.valueOf(sharedPreferences.getInt(key, 0));
    } else if (Float.class.isAssignableFrom(T)) {
        result = (T) Float.valueOf(sharedPreferences.getFloat(key, 0));
    } else if (Long.class.isAssignableFrom(T)) {
        result = (T) Long.valueOf(sharedPreferences.getLong(key, 0));
    } else {
        result = (T) Boolean.valueOf(sharedPreferences.getBoolean(key, false));
    }
    return result;
}

From source file:Main.java

private static String getChannelBySharedPreferences(Context context) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    int currentVersionCode = getVersionCode(context);
    if (currentVersionCode == -1) {
        return "";
    }//from  w  ww  .j  a  v  a 2s  .  co  m
    int versionCodeSaved = sp.getInt(CHANNEL_VERSION_KEY, -1);
    if (versionCodeSaved == -1) {
        return "";
    }
    if (currentVersionCode != versionCodeSaved) {
        return "";
    }
    return sp.getString(CHANNEL_KEY, "");
}

From source file:cm.aptoide.pt.util.NetworkUtils.java

public static String getUserAgentString(Context mctx) {
    SharedPreferences sPref = PreferenceManager.getDefaultSharedPreferences(mctx);
    String myid = sPref.getString("myId", "NoInfo");
    String myscr = sPref.getInt("scW", 0) + "x" + sPref.getInt("scH", 0);
    String partnerid = "";
    if (ApplicationAptoide.PARTNERID != null) {
        partnerid = "PartnerID:" + ApplicationAptoide.PARTNERID + ";";
    }//from www  . j a v  a 2 s.com

    return "aptoide-" + mctx.getString(R.string.ver_str) + ";" + Configs.TERMINAL_INFO + ";" + myscr + ";id:"
            + myid + ";" + sPref.getString(Configs.LOGIN_USER_LOGIN, "") + ";" + partnerid;
}

From source file:com.cyanogenmod.account.util.CMAccountUtils.java

private static int getBackoff(SharedPreferences prefs) {
    return prefs.getInt(CMAccount.BACKOFF_MS, CMAccount.DEFAULT_BACKOFF_MS);
}

From source file:com.phonemetra.account.util.AccountUtils.java

private static int getBackoff(SharedPreferences prefs) {
    return prefs.getInt(Account.BACKOFF_MS, Account.DEFAULT_BACKOFF_MS);
}

From source file:mobisocial.musubi.ui.fragments.EulaFragment.java

public static boolean needsEULA(Context context) {
    SharedPreferences prefs = context.getSharedPreferences(EulaFragment.PREFS_NAME, 0);
    int old_version = prefs.getInt(EulaFragment.EULA_VERSION_KEY, -1);
    if (old_version < 0 || old_version < EulaFragment.CURRENT_VERSION) {
        return true;
    }//from w  ww. j  a v a2 s  . co m
    return false;
}

From source file:android_network.hetnet.vpn_service.Receiver.java

public static void upgrade(boolean initialized, Context context) {
    synchronized (context.getApplicationContext()) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        int oldVersion = prefs.getInt("version", -1);
        int newVersion = Util.getSelfVersionCode(context);
        if (oldVersion == newVersion)
            return;
        Log.i(TAG, "Upgrading from version " + oldVersion + " to " + newVersion);

        SharedPreferences.Editor editor = prefs.edit();

        if (initialized) {
            if (oldVersion < 38) {
                Log.i(TAG, "Converting screen wifi/mobile");
                editor.putBoolean("screen_wifi", prefs.getBoolean("unused", false));
                editor.putBoolean("screen_other", prefs.getBoolean("unused", false));
                editor.remove("unused");

                SharedPreferences unused = context.getSharedPreferences("unused", Context.MODE_PRIVATE);
                SharedPreferences screen_wifi = context.getSharedPreferences("screen_wifi",
                        Context.MODE_PRIVATE);
                SharedPreferences screen_other = context.getSharedPreferences("screen_other",
                        Context.MODE_PRIVATE);

                Map<String, ?> punused = unused.getAll();
                SharedPreferences.Editor edit_screen_wifi = screen_wifi.edit();
                SharedPreferences.Editor edit_screen_other = screen_other.edit();
                for (String key : punused.keySet()) {
                    edit_screen_wifi.putBoolean(key, (Boolean) punused.get(key));
                    edit_screen_other.putBoolean(key, (Boolean) punused.get(key));
                }/*w w w . ja  v  a 2 s  . c  o m*/
                edit_screen_wifi.apply();
                edit_screen_other.apply();
            }
        } else {
            Log.i(TAG, "Initializing sdk=" + Build.VERSION.SDK_INT);
            editor.putBoolean("whitelist_wifi", false);
            editor.putBoolean("whitelist_other", false);
            if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP)
                editor.putBoolean("filter", true); // Optional
        }

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
            editor.putBoolean("filter", true); // Mandatory

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            editor.remove("show_top");
            if ("data".equals(prefs.getString("sort", "name")))
                editor.remove("sort");
        }

        if (Util.isPlayStoreInstall(context)) {
            editor.remove("update_check");
            editor.remove("use_hosts");
            editor.remove("hosts_url");
        }

        if (!Util.isDebuggable(context))
            editor.remove("loglevel");

        editor.putInt("version", newVersion);
        editor.apply();
    }
}

From source file:jp.co.ipublishing.aeskit.notification.gcm.GCMRegister.java

/**
 * GCMID??/*  w w  w . j a  v  a2  s .co  m*/
 *
 * @param context 
 * @return GCMID??????????????
 */
@NonNull
private static String getRegistrationId(@NonNull Context context) {
    final SharedPreferences prefs = getPreferences(context);
    final String registrationId = prefs.getString(PROPERTY_REG_ID, "");
    if (registrationId.isEmpty()) {
        Log.i(TAG, "Registration not found.");
        return "";
    }

    final int registeredVersion = prefs.getInt(PROPERTY_APP_VERSION, Integer.MIN_VALUE);
    final int currentVersion = getAppVersion(context);
    if (registeredVersion != currentVersion) {
        Log.i(TAG, "App version changed.");
        return "";
    }
    return registrationId;
}

From source file:com.wikonos.fingerprint.activities.MainActivity.java

public static int getSentFlags(String filename, Context context) {
    SharedPreferences prefs = context.getSharedPreferences("REVIEW_SENT_PREFS", MODE_PRIVATE);
    return prefs.getInt(filename, 0);
}

From source file:com.breadwallet.tools.manager.SharedPreferencesManager.java

public static int getCurrencyListPosition(Context context) {
    SharedPreferences settings = context.getSharedPreferences(BRConstants.PREFS_NAME, 0);
    return settings.getInt(BRConstants.POSITION, 0);
}