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 void saveWeatherInfo(Context context, String cityName, String tempMin, String tempMax,
        String weatherDay, String weatherNight, String publishTime, String date1DayPic, String date2DayPic,
        String date3DayPic, String date4DayPic, String date5DayPic, String nowPic, String comf, String drsg,
        String flu, String sport, String trav, String uv) {
    SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
    editor.putBoolean("city_selected", true);
    editor.putString("city_name", cityName);
    editor.putString("temp_min", tempMin);
    editor.putString("temp_max", tempMax);
    editor.putString("weather_day", weatherDay);
    editor.putString("weather_night", weatherNight);
    editor.putString("publish_time", publishTime);
    editor.putString("date1_day_pic", date1DayPic);
    editor.putString("date2_day_pic", date2DayPic);
    editor.putString("date3_day_pic", date3DayPic);
    editor.putString("date4_day_pic", date4DayPic);
    editor.putString("date5_day_pic", date5DayPic);
    editor.putString("now_pic", nowPic);
    editor.putString("comf_index", comf);
    editor.putString("drsg_index", drsg);
    editor.putString("flu_index", flu);
    editor.putString("sport_index", sport);
    editor.putString("trav_index", trav);
    editor.putString("uv_index", uv);
    editor.commit();//from w ww  .  j a  v a  2 s. co  m
}

From source file:Main.java

/** 
 * @param context The application context.
 * @return The stored sender ID or the default value if not available.
 *//*from   w ww. ja va 2  s.  c  o m*/
public static String getSenderId(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    return prefs.getString(PREFS_KEY_SENDER_ID, DEFAULT_SENDER_ID);
}

From source file:Main.java

public static SharedPreferences getDefaultPreference(Context context) {
    return PreferenceManager.getDefaultSharedPreferences(context);
}

From source file:Main.java

/**
 * Stores the given sender ID.//from   w ww .  ja v  a  2 s .c om
 *  
 * @param context The application context.
 * @param id The sender ID to store.
 * @return True if successful, false otherwise.
 */
public static boolean setSenderId(Context context, String id) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    return prefs.edit().putString(PREFS_KEY_SENDER_ID, id).commit();
}

From source file:Main.java

public static void clearAllPreferences() {
    SharedPreferences preferences;/*from  w  w w . ja  v a 2  s  .  c  o m*/
    SharedPreferences.Editor editor;
    preferences = context.getSharedPreferences("longpoll", Context.MODE_MULTI_PROCESS);
    editor = preferences.edit();
    editor.clear();
    editor.commit();
    preferences = context.getSharedPreferences("durov", Context.MODE_MULTI_PROCESS);
    editor = preferences.edit();
    editor.clear();
    editor.commit();
    preferences = PreferenceManager.getDefaultSharedPreferences(context);
    editor = preferences.edit();
    editor.clear();
    editor.commit();
}

From source file:Main.java

public static void setBindStr(Context context, String bindStr, String strValue) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    Editor editor = sp.edit();/*from  w ww  . j a v  a 2s  . co  m*/
    editor.putString(bindStr, strValue);
    editor.commit();
}

From source file:Main.java

public static int getNextEventCounter(Activity hostActivity, String key) {
    SharedPreferences preferences = PreferenceManager
            .getDefaultSharedPreferences(hostActivity.getApplicationContext());

    int id = preferences.getInt(key, 0);
    id += 1;//from   ww w  .  ja  v a2  s  .  c o  m

    SharedPreferences.Editor editor = preferences.edit();
    editor.putInt(key, id).commit();

    return id;
}

From source file:Main.java

public static AlertDialog showTutorialDialog(final Context context) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle("Watch a YouTube video tutorial?");
    builder.setIcon(android.R.drawable.ic_dialog_info);
    builder.setPositiveButton("Watch", new DialogInterface.OnClickListener() {
        @Override/*ww w .  java 2s.c  o m*/
        public void onClick(DialogInterface dialog, int which) {
            PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("firstrun", false)
                    .commit();
            Intent browserIntent = new Intent(Intent.ACTION_VIEW,
                    Uri.parse("http://www.youtube.com/watch?v=LhiSWE5-ezM"));
            context.startActivity(browserIntent);
        }
    });

    builder.setNeutralButton("Close", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("firstrun", false)
                    .commit();
            dialog.dismiss();
        }
    });
    AlertDialog alert = builder.create();
    alert.show();

    return alert;
}

From source file:Main.java

public static boolean ensureWifi(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    if (netInfo == null || !netInfo.isConnectedOrConnecting())
        return false;
    // always OK if we're on wifi
    if (netInfo.getType() == ConnectivityManager.TYPE_WIFI)
        return true;
    // check for wifi only pref
    if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean("wifiPref", true)) {
        Log.d("Podax", "Not downloading because Wifi is required and not connected");
        return false;
    }/*from   w ww. java  2s.  c  o  m*/
    // check for 3g data turned off
    if (!netInfo.isConnected()) {
        Log.d("Podax", "Not downloading because background data is turned off");
        return false;
    }

    return true;
}

From source file:Main.java

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