Example usage for android.content SharedPreferences contains

List of usage examples for android.content SharedPreferences contains

Introduction

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

Prototype

boolean contains(String key);

Source Link

Document

Checks whether the preferences contains a preference.

Usage

From source file:Main.java

public static int getMinutes(SharedPreferences prefs) {
    if (prefs.contains(PREFS_MINS)) {
        return prefs.getInt(PREFS_MINS, DEFAULT_MINS);
    } else {//from   w w  w .j  ava2  s . c om
        return DEFAULT_MINS;
    }
}

From source file:Main.java

public static int getHours(SharedPreferences prefs) {
    if (prefs.contains(PREFS_HRS)) {
        return prefs.getInt(PREFS_HRS, DEFAULT_HRS);
    } else {//from w w w.  j a  v  a 2  s .  co  m
        return DEFAULT_HRS;
    }
}

From source file:Main.java

public static boolean existsSet(SharedPreferences prefs, String setName) {
    return prefs.contains(setName + "_size");
}

From source file:Main.java

public static boolean isNewInstall(Context context) {
    SharedPreferences sp = getSP(context);
    return !sp.contains(APP_ACTIVE_TIME);
}

From source file:Main.java

/**
 * @return {@code Boolean} value if {@code sharedPreferences} contains the value
 *   corresponding to the {@code key}. Otherwise returns {@code null}.
 *//*from  w  w  w  . j a  v  a2 s  .c  o  m*/
private static Boolean getBoolean(SharedPreferences sharedPreferences, String key) {
    if (!sharedPreferences.contains(key)) {
        return null;
    }

    // Default value wouldn't be used in actual case, but it is required.
    return Boolean.valueOf(sharedPreferences.getBoolean(key, false));
}

From source file:Main.java

public static boolean containsKey(Context context, String key) {
    SharedPreferences sp = getSharedPreferences(context);
    return sp.contains(key);
}

From source file:Main.java

@SuppressLint("CommitPrefEdits")
public static void defaultState(Context context, boolean state) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    if (!prefs.contains("wifi_state"))
        prefs.edit().putBoolean("wifi_state", state).commit();
}

From source file:Main.java

public static boolean contains(Context context, String key) {
    SharedPreferences sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
    return sp.contains(key);
}

From source file:Main.java

public static String getChatBg(Context context, String key) {
    SharedPreferences spf = context.getSharedPreferences("chat", Context.MODE_PRIVATE);
    if (spf.contains(key)) {
        return spf.getString(key, "");
    }//  www . j a  v  a2 s .c o m
    return "";
}

From source file:Main.java

public static boolean contains(Context context, String file_name, String key) {
    SharedPreferences sp = context.getSharedPreferences(file_name, Context.MODE_PRIVATE);
    return sp.contains(key);
}