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 SharedPreferences createSharedPreferences(Context context) {
    return PreferenceManager.getDefaultSharedPreferences(context);
}

From source file:Main.java

public static void initialize(Activity activity) {

    /** /*from  www  .j a va2  s . co m*/
     *gets a SharedPreferences instance that points to the default file that is used by the preference framework 
     */
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);

    /**
     * used to store latest orientation of android device
     */
    String orientation = prefs.getString("prefOrientation", "Null");
    if ("Landscape".equals(orientation)) {
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    } else if ("Portrait".equals(orientation)) {
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    } else {
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);
    }
}

From source file:Main.java

public static void reloadLocale(Context context) {
    SharedPreferences sharedPrefs = PreferenceManager
            .getDefaultSharedPreferences(context.getApplicationContext());
    String lang = sharedPrefs.getString(PREF_APP_LANGUAGE, Locale.getDefault().getLanguage());
    if (sharedPrefs.getString(PREF_APP_LANGUAGE, "").equalsIgnoreCase("")) {
        sharedPrefs.edit().putString(PREF_APP_LANGUAGE, lang).commit();
    }//from  w  w w .j  ava2  s .  c  o  m
    Configuration newConfig = context.getResources().getConfiguration();

    if (!newConfig.locale.getLanguage().equals(lang)) {
        locale = new Locale(lang);
    }

    if (locale != null) {
        Locale.setDefault(locale);
        newConfig.locale = locale;
        context.getResources().updateConfiguration(newConfig, context.getResources().getDisplayMetrics());
    }
}

From source file:Main.java

/**
 * Retrieves a float value from preference manager. If no such key exists, it will return
 * <code>Float.MIN_VALUE</code>.
 *//*from w  ww . ja v  a  2  s.  co m*/
public static float getFloatFromPreference(Context context, String key) {
    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
    return pref.getFloat(key, Float.MIN_VALUE);
}

From source file:Main.java

public static void initialize(Activity activity) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);

    String orientation = prefs.getString("prefOrientation", "Null");
    if ("Landscape".equals(orientation)) {
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    } else if ("Portrait".equals(orientation)) {
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    } else {/* w  w  w .ja  va  2 s  . com*/
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);
    }
}

From source file:Main.java

public static String getSharedPreferences(Context context, String key) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    return sharedPreferences.getString(HORSEPUSH + key, "");
}

From source file:Main.java

/**
 * Get the shared preferences with application context for saving
 * and loading ("global") values./*ww w  .  j  av  a2 s  .  c  o  m*/
 * @return The shared preferences object with application context.
 */
public static SharedPreferences getPreferences() {
    return PreferenceManager.getDefaultSharedPreferences(mAppContext);
}

From source file:Main.java

/**
 * Set username and password under setting. This will be use for next app launching.
 * @param context//from w  w w  .  j a  v a  2s.  co  m
 * @param email
 * @param password
 */
public static void storeCredential(Context context, String email, String password) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putString("username", email);
    editor.putString("password", password);
    editor.commit();
}

From source file:Main.java

/**
 * Gets the preference./*from w  w  w  . j  av a2  s .  co  m*/
 *
 * @param key the key
 * @param defaultValue the default value
 * @return the preference
 */
public static int getPreference(String key, int defaultValue, Context c) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(c);
    return preferences.getInt(key, defaultValue);
}

From source file:Main.java

public static ComponentName getDefaultViewerComponentName(Context context, String fullPath, String mimeType) {
    String viewer = PreferenceManager.getDefaultSharedPreferences(context)
            .getString(DEFAULT_VIEWER_PREFIX + fullPath, null);
    if (viewer == null) {
        viewer = PreferenceManager.getDefaultSharedPreferences(context)
                .getString(DEFAULT_VIEWER_PREFIX + mimeType, null);
    }/*w w w .j  a va2 s .c o  m*/

    if (viewer != null) {
        String[] comps = viewer.split("\t");
        if (comps.length == 2) {
            return new ComponentName(comps[0], comps[1]);
        }
        throw new IllegalArgumentException("Unable to decode " + TextUtils.join(" ", comps));
    }
    return null;
}