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:eu.faircode.netguard.IAB.java

public static boolean isPurchasedAny(Context context) {
    if (Util.isDebuggable(context)) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        return !(prefs.getBoolean("debug_iab", false) || prefs.getBoolean("debug_ads", false));
    }/*w w w.  j ava 2 s.co  m*/

    SharedPreferences prefs = context.getSharedPreferences("IAB", Context.MODE_PRIVATE);
    for (String key : prefs.getAll().keySet())
        if (prefs.getBoolean(key, false))
            return true;
    return false;
}

From source file:org.fdroid.enigtext.mms.MmsCommunication.java

protected static MmsConnectionParameters getLocallyConfiguredMmsConnectionParameters(Context context)
        throws ApnUnavailableException {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);

    if (preferences.getBoolean(ApplicationPreferencesActivity.ENABLE_MANUAL_MMS_PREF, false)) {
        String mmsc = preferences.getString(ApplicationPreferencesActivity.MMSC_HOST_PREF, null);

        if (mmsc == null)
            throw new ApnUnavailableException("Malformed locally configured MMSC.");

        if (!mmsc.startsWith("http"))
            mmsc = "http://" + mmsc;

        String proxy = preferences.getString(ApplicationPreferencesActivity.MMSC_PROXY_HOST_PREF, null);
        String port = preferences.getString(ApplicationPreferencesActivity.MMSC_PROXY_PORT_PREF, null);

        return new MmsConnectionParameters(mmsc, proxy, port);
    }/*from  w w  w.j a  v  a2 s.co m*/

    throw new ApnUnavailableException("No locally configured parameters available");
}

From source file:key.secretkey.utils.PasswordStorage.java

public static File getRepositoryDirectory(Context context) {
    File dir = null;/*w w w. j a v  a2s.  co  m*/
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());

    if (settings.getBoolean("git_external", false)) {
        String external_repo = settings.getString("git_external_repo", null);
        if (external_repo != null) {
            dir = new File(external_repo);
        }
    } else {
        dir = new File(context.getFilesDir() + "/store");
    }

    return dir;
}

From source file:com.nadmm.airports.utils.NetworkUtils.java

public static boolean canDownloadData(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    boolean alwaysAutoFetch = prefs.getBoolean(PreferencesActivity.KEY_AUTO_DOWNLOAD_ON_3G, false);
    return (alwaysAutoFetch || !NetworkUtils.isConnectedToMeteredNetwork(context));
}

From source file:Main.java

public static Object getParam(Context context, String key, Object defaultObject) {
    String type = defaultObject.getClass().getSimpleName();
    SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);

    if ("String".equals(type)) {
        return sp.getString(key, (String) defaultObject);
    } else if ("Integer".equals(type)) {
        return sp.getInt(key, (Integer) defaultObject);
    } else if ("Boolean".equals(type)) {
        return sp.getBoolean(key, (Boolean) defaultObject);
    } else if ("Float".equals(type)) {
        return sp.getFloat(key, (Float) defaultObject);
    } else if ("Long".equals(type)) {
        return sp.getLong(key, (Long) defaultObject);
    }/*from   w  w w.  j av a2 s.c  om*/
    return null;
}

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

private static boolean filterNotification(SharedPreferences preferences, Notification notification) {
    switch (notification.type) {
    default:/*from   w w  w  .  j  a  v a2  s.  c o  m*/
    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:Main.java

public static boolean getPrefBool(Context context, int keyId, int defaultValueId) {

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    String key = context.getString(keyId);
    boolean defaultValue = false;
    try {/*w  w w.j  a v a2 s  . c o m*/
        defaultValue = Boolean.parseBoolean(context.getString(defaultValueId));
    } catch (Exception e) { /* don't care */
    }

    return sharedPreferences.getBoolean(key, defaultValue);
}

From source file:bala.padio.Settings.java

private static boolean getConfig(String name, boolean defValue, String setting) {
    SharedPreferences preference = MainActivity.AppContext.getSharedPreferences(setting, Context.MODE_PRIVATE);
    return preference.getBoolean(name, defValue);
}

From source file:Main.java

public static Object getSp(Context context, String key, Object defaultObject) {
    String type = defaultObject.getClass().getSimpleName();
    String packageName = context.getPackageName();
    SharedPreferences sp = context.getSharedPreferences(packageName, Context.MODE_PRIVATE);
    if ("String".equals(type)) {
        return sp.getString(key, (String) defaultObject);
    } else if ("Integer".equals(type)) {
        return sp.getInt(key, (Integer) defaultObject);
    } else if ("Boolean".equals(type)) {
        return sp.getBoolean(key, (Boolean) defaultObject);
    } else if ("Float".equals(type)) {
        return sp.getFloat(key, (Float) defaultObject);
    } else if ("Long".equals(type)) {
        return sp.getLong(key, (Long) defaultObject);
    }/*from   ww  w. ja  va2 s. c om*/
    return null;
}

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

/**
 * This method will show either a Welcome or a No Love AutomatedMessage. If a No Love message has been shown, no other
 * AutomatedMessage shall be shown, and no AutomatedMessage shall be shown twice.
 *
 * @param context The context from which this method is called.
 * @param forced  If true, show a Welcome AutomatedMessage, else show a NoLove AutomatedMessage.
 *//*from w  w  w  . j av a 2s . c  o  m*/
public static void createMessageCenterAutoMessage(Context context, boolean forced) {
    SharedPreferences prefs = context.getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE);

    boolean shownAutoMessage = prefs.getBoolean(Constants.PREF_KEY_AUTO_MESSAGE_SHOWN_AUTO_MESSAGE, false);

    // Migrate old values if needed.
    boolean shownManual = prefs.getBoolean(Constants.PREF_KEY_AUTO_MESSAGE_SHOWN_MANUAL, false);
    boolean shownNoLove = prefs.getBoolean(Constants.PREF_KEY_AUTO_MESSAGE_SHOWN_NO_LOVE, false);
    if (!shownAutoMessage) {
        if (shownManual || shownNoLove) {
            shownAutoMessage = true;
            prefs.edit().putBoolean(Constants.PREF_KEY_AUTO_MESSAGE_SHOWN_AUTO_MESSAGE, true).commit();
        }
    }

    AutomatedMessage message = null;

    if (!shownAutoMessage) {
        if (forced) {
            message = AutomatedMessage.createWelcomeMessage(context);
        } else {
            message = AutomatedMessage.createNoLoveMessage(context);
        }
        if (message != null) {
            prefs.edit().putBoolean(Constants.PREF_KEY_AUTO_MESSAGE_SHOWN_AUTO_MESSAGE, true).commit();
            getMessageStore(context).addOrUpdateMessages(message);
            ApptentiveDatabase.getInstance(context).addPayload(message);
        }
    }
}