Example usage for android.preference PreferenceManager getDefaultSharedPreferences

List of usage examples for android.preference PreferenceManager getDefaultSharedPreferences

Introduction

In this page you can find the example usage for android.preference PreferenceManager getDefaultSharedPreferences.

Prototype

public static SharedPreferences getDefaultSharedPreferences(Context context) 

Source Link

Document

Gets a SharedPreferences instance that points to the default file that is used by the preference framework in the given context.

Usage

From source file:Main.java

public static boolean isMyTBAEnabled(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    return prefs.getBoolean(PREF_MYTBA_ENABLED, false);
}

From source file:Main.java

public static String getPersistedData(Context context, String defaultLanguage) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    return preferences.getString(SELECTED_LANGUAGE, defaultLanguage);
}

From source file:Main.java

public static String GetNotificationRegistrationID() {
    SharedPreferences Prefs = PreferenceManager.getDefaultSharedPreferences(applicationContext);
    if (Prefs != null)
        return Prefs.getString(AUTH, "");
    return null;//w w  w.ja va2 s  .  c  om
}

From source file:Main.java

public static boolean isUpgradedVersion(Context context) {
    SharedPreferences appSettings = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = appSettings.edit();
    int versionCode = appSettings.getInt("appVersion", -1);
    try {//from w ww.  j  a v a  2 s  .  c o m
        PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
        int newVersion = pInfo.versionCode;
        if (versionCode != -1 && versionCode != newVersion) {
            editor.putInt("appVersion", newVersion);
            editor.commit();
            return true;
        }
    } catch (Exception e) {
    }
    ;
    return false;
}

From source file:Main.java

public static Boolean containKeySharePref(Context context, String key) {
    Boolean isContainer = false;/* w  w  w .jav a2s  .  c o  m*/
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    if (preferences.contains(key)) {
        isContainer = true;
    } else {
        isContainer = false;
    }
    return isContainer;

}

From source file:Main.java

public static boolean checkPreferences(@NonNull final Context context) {
    final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    return !(sharedPreferences.getString("sNummer", "").length() < 5
            || sharedPreferences.getString("RZLogin", "").length() < 3);
}

From source file:Main.java

public static final void removeAccessToken(Context context) {
    PreferenceManager.getDefaultSharedPreferences(context).edit().remove(KEY_PREF_USER_NAME)
            .remove(KEY_PREF_ACCESS_TOKEN).commit();
}

From source file:Main.java

public static boolean saveArray(Context mContext) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
    SharedPreferences.Editor mEdit1 = sp.edit();
    mEdit1.putInt("Like_size", mDishLikeList.size());

    for (int i = 0; i < mDishLikeList.size(); i++) {
        mEdit1.remove("Like_" + i);
        mEdit1.putString("Like_" + i, mDishLikeList.get(i));
    }//ww w .  ja v a  2  s .co m

    return mEdit1.commit();
}

From source file:Main.java

public static void loadArray(Context mContext) {
    SharedPreferences mSharedPreference1 = PreferenceManager.getDefaultSharedPreferences(mContext);
    mDishLikeList.clear();/*from  www  .j a  va2  s  .c o  m*/
    int size = mSharedPreference1.getInt("Like_size", 0);

    for (int i = 0; i < size; i++) {
        mDishLikeList.add(mSharedPreference1.getString("Like_" + i, null));
    }
}

From source file:Main.java

public static void setDefKeyboardHeight(Context context, int height) {
    if (sDefKeyboardHeight != height) {
        PreferenceManager.getDefaultSharedPreferences(context).edit().putInt(DEF_KEYBOARD_HEIGHT_KEY, height)
                .commit();/*w ww. j  a v a  2 s .c  o m*/
        sDefKeyboardHeight = height;
    }
}