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

private static void saveChannelBySharedPreferences(Context context, String channel) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = sp.edit();
    editor.putString(CHANNEL_KEY, channel);
    editor.putInt(CHANNEL_VERSION_KEY, getVersionCode(context));
    editor.commit();/*w ww  .  j  a v a2 s .  com*/
}

From source file:Main.java

/**
 * Gets the localization method from the shared preferences.
 *
 * @param context The calling context./*from   w w w  .j  a  v a2  s.  com*/
 * @return int value, default 1 {@link com.indoor.navigation.indoornavigation.R.array#pref_loc_entries}.
 */
public static int getPrefPositioningMethod(Context context) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    return Integer.valueOf(sharedPreferences.getString("localization_type", "0"));
}

From source file:Main.java

public static int getDefKeyboardHeight(Context context) {
    if (sDefKeyboardHeight < 0) {
        sDefKeyboardHeight = dip2px(context, DEF_KEYBOARD_HEIGHT_DP);
    }/*from  w w w  . j  a  va2s.  c  o  m*/
    int height = PreferenceManager.getDefaultSharedPreferences(context).getInt(DEF_KEYBOARD_HEIGHT_KEY, 0);
    return sDefKeyboardHeight = height > 0 && sDefKeyboardHeight != height ? height : sDefKeyboardHeight;
}

From source file:Main.java

/**
 * @Title: getSettingRingtone//w w w  .ja v  a 2  s . c o  m
 * @Description: Get current setting ring tone
 * @param context
 * @param type
 * @return
 * @return String
 * @throws
 */
public static String getSettingRingtone(Context context, int type) {
    SharedPreferences mSharePref = PreferenceManager.getDefaultSharedPreferences(context);
    String value = mSharePref.getString(TYPE_PRE + type, "");
    return value;
}

From source file:Main.java

public static boolean isNewVersion(final Context context) {
    final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context);
    final String v0 = p.getString(PREFS_LAST_RUN, "");
    String v1 = null;/*w  w  w.  j av a2  s  .c o m*/
    try {
        v1 = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
    } catch (NameNotFoundException e) {
        Log.e(TAG, "package not found: " + context.getPackageName(), e);
    }
    if (v0.equals(v1)) {
        return false;
    }
    return true;
}

From source file:Main.java

public static void setChosenAccountName(final Context context, final String accountName) {
    Log.d(TAG, "Chose account " + accountName);
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    sp.edit().putString(PREF_CHOSEN_ACCOUNT, accountName).commit();
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.GINGERBREAD)
public static void removeAccount(Context ctx) {
    SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(ctx).edit();
    editor.remove(KEY_ACCOUNT_NAME);//w  w  w  . j a  v  a  2 s .c  om
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        editor.apply();
    } else {
        editor.commit();
    }
    mCurrentUser = null;
}

From source file:Main.java

/**
 * Return int value of shared preference specifies by key
 * @param context/*from  w  w  w .  j av a2  s. c o  m*/
 * @param key
 * @return
 */
public static int getSharedPreferenceInt(Context context, String key) {

    int result = -1;
    if (context != null) {
        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
        if (sharedPreferences != null) {
            result = sharedPreferences.getInt(key, -1);
        }
    }
    return result;
}

From source file:Main.java

/**
 * Saves a string value under the provided key in the preference manager. If <code>value</code>
 * is <code>null</code>, then the provided key will be removed from the preferences.
 *//*from  ww  w  .j  a va2  s .  c  o m*/
public static void saveStringToPreference(Context context, String key, String value) {
    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
    if (null == value) {
        // we want to remove
        pref.edit().remove(key).apply();
    } else {
        pref.edit().putString(key, value).apply();
    }
}

From source file:Main.java

private static SharedPreferences getPreferences(Context context) {
    return PreferenceManager.getDefaultSharedPreferences(context);
}