Example usage for android.content SharedPreferences getBoolean

List of usage examples for android.content SharedPreferences getBoolean

Introduction

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

Prototype

boolean getBoolean(String key, boolean defValue);

Source Link

Document

Retrieve a boolean value from the preferences.

Usage

From source file:com.keylesspalace.tusky.util.NotificationManager.java

private static boolean filterNotification(SharedPreferences preferences, Notification notification) {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        return true; //do not filter on Android O or newer, the system does it for us
    }//from  w w  w .j a va 2  s. co  m

    switch (notification.type) {
    default:
    case MENTION:
        return preferences.getBoolean("notificationFilterMentions", true);
    case FOLLOW:
        return preferences.getBoolean("notificationFilterFollows", true);
    case REBLOG:
        return preferences.getBoolean("notificationFilterReblogs", true);
    case FAVOURITE:
        return preferences.getBoolean("notificationFilterFavourites", true);
    }
}

From source file:com.yamin.kk.vlc.Util.java

public static void updateLibVlcSettings(SharedPreferences pref) {
    LibVLC instance = LibVLC.getExistingInstance();
    if (instance == null)
        return;/*from w  w w  .j a  v a2s.  com*/

    instance.setIomx(pref.getBoolean("enable_iomx", false));
    instance.setSubtitlesEncoding(pref.getString("subtitles_text_encoding", ""));
    instance.setTimeStretching(pref.getBoolean("enable_time_stretching_audio", false));
    instance.setFrameSkip(pref.getBoolean("enable_frame_skip", false));
    instance.setChroma(pref.getString("chroma_format", ""));
    instance.setVerboseMode(pref.getBoolean("enable_verbose_mode", true));

    if (pref.getBoolean("equalizer_enabled", false))
        instance.setEqualizer(getFloatArray(pref, "equalizer_values"));

    int aout;
    try {
        aout = Integer.parseInt(pref.getString("aout", "-1"));
    } catch (NumberFormatException nfe) {
        aout = -1;
    }
    int vout;
    try {
        vout = Integer.parseInt(pref.getString("vout", "-1"));
    } catch (NumberFormatException nfe) {
        vout = -1;
    }
    int deblocking;
    try {
        deblocking = Integer.parseInt(pref.getString("deblocking", "-1"));
    } catch (NumberFormatException nfe) {
        deblocking = -1;
    }
    int hardwareAcceleration;
    try {
        hardwareAcceleration = Integer.parseInt(pref.getString("hardware_acceleration", "-1"));
    } catch (NumberFormatException nfe) {
        hardwareAcceleration = -1;
    }
    int networkCaching = pref.getInt("network_caching_value", 0);
    if (networkCaching > 60000)
        networkCaching = 60000;
    else if (networkCaching < 0)
        networkCaching = 0;
    instance.setAout(aout);
    instance.setVout(vout);
    instance.setDeblocking(deblocking);
    instance.setNetworkCaching(networkCaching);
    instance.setHardwareAcceleration(hardwareAcceleration);
}

From source file:fr.pasteque.client.Configure.java

public static boolean getSsl(Context ctx) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
    return prefs.getBoolean("ssl", DEFAULT_SSL);
}

From source file:fr.pasteque.client.Configure.java

public static boolean getDiscount(Context ctx) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
    return prefs.getBoolean("discount", DEFAULT_DISCOUNT);
}

From source file:com.thoughtmetric.tl.TLLib.java

private static TagNode TagNodeFromURLHelper(InputStream is, String fullTag, Handler handler, Context context,
        HtmlCleaner cleaner) throws IOException {
    SharedPreferences settings = context.getSharedPreferences(Settings.SETTINGS_FILE_NAME, 0);
    boolean disableSmartParsing = settings.getBoolean(Settings.DISABLE_SMART_PARSING, false);
    if (fullTag != null && !disableSmartParsing) {
        FileOutputStream fos = context.openFileOutput(TEMP_FILE_NAME, Context.MODE_WORLD_WRITEABLE);
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));
        TagParser.extractTagToFile(fullTag, is, bw);
        bw.flush();/*from  www  . j  a  va2  s  .c  om*/
        bw.close();
        if (handler != null)
            handler.sendEmptyMessage(PROGRESS_PARSING);

        return cleaner.clean(context.openFileInput(TEMP_FILE_NAME));
    } else {
        if (handler != null)
            handler.sendEmptyMessage(PROGRESS_PARSING);
        return cleaner.clean(is);
    }
}

From source file:fr.inria.ucn.Helpers.java

/**
 * @param c/*from www  . ja v  a 2s.com*/
 * @return <code>True</code> if user has enabled the night-time mode and current time is
 * within night, else <code>False</code>.
 */
public static boolean isNightTime(Context c) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c);
    if (!prefs.getBoolean(Constants.PREF_STOP_NIGHT, false))
        return false;

    int nstart = prefs.getInt(Constants.PREF_NIGHT_START, 23 * 3600);
    int nstop = prefs.getInt(Constants.PREF_NIGHT_STOP, 6 * 3600);

    Calendar nightstart = Calendar.getInstance();
    nightstart.roll(Calendar.HOUR_OF_DAY, -1 * nightstart.get(Calendar.HOUR_OF_DAY));
    nightstart.roll(Calendar.MINUTE, -1 * nightstart.get(Calendar.MINUTE));
    nightstart.roll(Calendar.SECOND, -1 * nightstart.get(Calendar.SECOND));
    nightstart.roll(Calendar.MILLISECOND, -1 * nightstart.get(Calendar.MILLISECOND));
    nightstart.add(Calendar.SECOND, nstart);

    Calendar nightstop = Calendar.getInstance();
    nightstop.roll(Calendar.HOUR_OF_DAY, -1 * nightstop.get(Calendar.HOUR_OF_DAY));
    nightstop.roll(Calendar.MINUTE, -1 * nightstop.get(Calendar.MINUTE));
    nightstop.roll(Calendar.SECOND, -1 * nightstop.get(Calendar.SECOND));
    nightstop.roll(Calendar.MILLISECOND, -1 * nightstop.get(Calendar.MILLISECOND));
    nightstop.add(Calendar.SECOND, nstop);
    if (nightstop.before(nightstart))
        nightstop.add(Calendar.HOUR, 24);

    Log.d(Constants.LOGTAG, "nightstart " + nstart + " -> " + nightstart.toString());
    Log.d(Constants.LOGTAG, "nightstop " + nstop + " -> " + nightstop.toString());

    Calendar now = Calendar.getInstance();
    return (now.after(nightstart) && now.before(nightstop));
}

From source file:fr.inria.ucn.Helpers.java

/**
 * //from  w w  w .  j av a  2 s .co m
 * @param c
 * @return -1 if not at night-time (or feature disabled), else milliseconds until morning.
 */
public static long getNightEnd(Context c) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c);
    if (!prefs.getBoolean(Constants.PREF_STOP_NIGHT, false))
        return -1;

    int nstart = prefs.getInt(Constants.PREF_NIGHT_START, 23 * 3600);
    int nstop = prefs.getInt(Constants.PREF_NIGHT_STOP, 6 * 3600);

    Calendar nightstart = Calendar.getInstance();
    nightstart.roll(Calendar.HOUR_OF_DAY, -1 * nightstart.get(Calendar.HOUR_OF_DAY));
    nightstart.roll(Calendar.MINUTE, -1 * nightstart.get(Calendar.MINUTE));
    nightstart.roll(Calendar.SECOND, -1 * nightstart.get(Calendar.SECOND));
    nightstart.roll(Calendar.MILLISECOND, -1 * nightstart.get(Calendar.MILLISECOND));
    nightstart.add(Calendar.SECOND, nstart);

    Calendar nightstop = Calendar.getInstance();
    nightstop.roll(Calendar.HOUR_OF_DAY, -1 * nightstop.get(Calendar.HOUR_OF_DAY));
    nightstop.roll(Calendar.MINUTE, -1 * nightstop.get(Calendar.MINUTE));
    nightstop.roll(Calendar.SECOND, -1 * nightstop.get(Calendar.SECOND));
    nightstop.roll(Calendar.MILLISECOND, -1 * nightstop.get(Calendar.MILLISECOND));
    nightstop.add(Calendar.SECOND, nstop);
    if (nightstop.before(nightstart))
        nightstop.add(Calendar.HOUR, 24);

    Log.d(Constants.LOGTAG, "nightstart " + nstart + " -> " + nightstart.toString());
    Log.d(Constants.LOGTAG, "nightstop " + nstop + " -> " + nightstop.toString());

    Calendar now = Calendar.getInstance();
    if (now.after(nightstart) && now.before(nightstop)) {
        return nightstop.getTimeInMillis();
    } else {
        return -1;
    }
}

From source file:com.apptentive.android.sdk.module.messagecenter.ApptentiveMessageCenter.java

protected static void show(Activity activity) {
    SharedPreferences prefs = activity.getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE);
    Configuration conf = Configuration.load(activity);
    boolean enableMessageCenter = conf.isMessageCenterEnabled(activity);
    boolean emailRequired = conf.isMessageCenterEmailRequired(activity);
    boolean shouldShowIntroDialog = !enableMessageCenter
            || prefs.getBoolean(Constants.PREF_KEY_MESSAGE_CENTER_SHOULD_SHOW_INTRO_DIALOG, true);
    // TODO: What if there is an incoming message that is unread? Shouldn't they see the Message Center right away?
    if (shouldShowIntroDialog) {
        showIntroDialog(activity, emailRequired);
    } else {//from  w w w.  ja  v a 2  s. c  om
        Intent intent = new Intent();
        intent.setClass(activity, ViewActivity.class);
        intent.putExtra(ActivityContent.KEY, ActivityContent.Type.MESSAGE_CENTER.toString());
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.slide_up_in, R.anim.slide_down_out);
    }
}

From source file:Main.java

public static <T> T getData(Context context, String fileName, String key, Class T) {
    SharedPreferences sharedPreferences = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
    T result;//from w w  w . j  av  a2  s. c om
    if (String.class.isAssignableFrom(T)) {
        result = (T) sharedPreferences.getString(key, "");
    } else if (Integer.class.isAssignableFrom(T)) {
        result = (T) Integer.valueOf(sharedPreferences.getInt(key, 0));
    } else if (Float.class.isAssignableFrom(T)) {
        result = (T) Float.valueOf(sharedPreferences.getFloat(key, 0));
    } else if (Long.class.isAssignableFrom(T)) {
        result = (T) Long.valueOf(sharedPreferences.getLong(key, 0));
    } else {
        result = (T) Boolean.valueOf(sharedPreferences.getBoolean(key, false));
    }
    return result;
}

From source file:com.matze5800.paupdater.Functions.java

public static String CheckGoo(Context context) {
    String Rom = getRomId(context);
    String Dev = getDevId(context);
    String device = detectDevice(context);
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    Boolean CheckDev = prefs.getBoolean("prefCheckDev", true);
    String result = null;/*from   ww  w  .j a  v a2  s .  co  m*/
    try {
        JSONArray files = null;
        JSONObject json = null;
        JSONObject e;
        int item = 1;

        if (Dev.equals("dsmitty166") || Dev.equals("fabi280") || Dev.equals("BigB1984")) {
            CheckDev = false;
        }

        if (CheckDev) {
            json = JSONfunctions.getJSONfromURL("http://goo.im/json2&action=search&query=pa_" + device);
            if (json != null) {
                files = json.getJSONArray("search_result");
                item = 0;
            }
        } else {
            if (Dev.equals("dsmitty166") && Rom.equals("Zion")) {
                json = JSONfunctions.getJSONfromURL("http://goo.im/json2&path=/devs/dsmitty166/Zion");
            } else if (Dev.equals("dsmitty166") && Rom.equals("paranoidandroid_nightly")) {
                json = JSONfunctions.getJSONfromURL("http://goo.im/json2&path=/devs/NIGHTLIES/" + device);
            } else if (Dev.equals("fabi280") && Rom.equals("paranoidandroid_nightly")) {
                json = JSONfunctions
                        .getJSONfromURL("http://goo.im/json2&path=/devs/fabi280/" + device + "_pa_nightly");
            } else if (Dev.equals("BigB1984") && Rom.equals("Rubik-maguro-jb")) {
                json = JSONfunctions.getJSONfromURL(
                        "http://goo.im/json2&path=/devs/BigBrother1984/RUBIK/ROM/PURE/maguro" + device);
            } else {
                json = JSONfunctions
                        .getJSONfromURL("http://goo.im/json2&path=/devs/paranoidandroid/roms/" + device);
            }
            if (json != null) {
                files = json.getJSONArray("list");
                String version;
                item = 0;
                e = files.getJSONObject(item);
                try {
                    version = e.getString("ro_version");
                } catch (JSONException ex) {
                    version = null;
                }
                while (version == null) {
                    Log.i("Goo Parser", "No file, skipping item " + item);
                    item = item + 1;
                    e = files.getJSONObject(item);
                    try {
                        version = e.getString("ro_version");
                    } catch (JSONException ex) {
                        version = null;
                    }
                }
            }
        }
        if (json != null) {
            e = files.getJSONObject(item);
            String gooDev = e.getString("ro_developerid");
            while (!gooDev.equals(Dev)) {
                item = item + 1;
                Log.i("Goo Parser", "Wrong dev, skipping item " + item);
                e = files.getJSONObject(item);
                gooDev = e.getString("ro_developerid");
            }
            e = files.getJSONObject(item);
            result = e.getString("ro_version");
            prefs.edit().putString("gooFilename", e.getString("filename")).commit();
            String url = "http://goo.im" + e.getString("path");
            Log.i("Goo Parser", "ROM URL: " + url);
            prefs.edit().putString("gooShortURL", url).commit();
            prefs.edit().putString("rom_md5", e.getString("md5")).commit();
            json = JSONfunctions.getJSONfromURL("http://goo.im/json2&path=/devs/paranoidandroid/roms/gapps");
            files = json.getJSONArray("list");
            String filename;
            item = 0;
            e = files.getJSONObject(item);
            try {
                filename = e.getString("filename");
            } catch (JSONException ex) {
                filename = null;
            }
            while (filename == null) {
                Log.i("Goo Parser", "GAPPS: No file, skipping item " + item);
                item = item + 1;
                e = files.getJSONObject(item);
                try {
                    filename = e.getString("filename");
                } catch (JSONException ex) {
                    filename = null;
                }
            }
            e = files.getJSONObject(item);
            url = "http://goo.im" + e.getString("path");
            Log.i("Goo Parser", "GAPPS URL: " + url);
            prefs.edit().putString("gappsURL", url).commit();
            prefs.edit().putString("gappsmd5", e.getString("md5")).commit();
            prefs.edit().putString("gappsFilename", e.getString("filename")).commit();
        } else {
            return "err";
        }
    } catch (Exception e) {
        Log.e("Goo Parser", "Error parsing data " + e.toString());
    }
    return result;
}