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.miz.apis.trakt.Trakt.java

public static boolean markEpisodeAsWatched(String showId, List<com.miz.functions.TvShowEpisode> episodes,
        Context c, boolean watched) {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(c);
    String username = settings.getString(TRAKT_USERNAME, "").trim();
    String password = settings.getString(TRAKT_PASSWORD, "");

    if (TextUtils.isEmpty(username) || TextUtils.isEmpty(password)
            || !settings.getBoolean(SYNC_WITH_TRAKT, false) || episodes.size() == 0)
        return false;

    try {/*from  w w w . j  av a2s  .co m*/
        JSONObject holder = new JSONObject();
        holder.put("username", username);
        holder.put("password", password);
        holder.put("imdb_id", "");
        holder.put("tvdb_id", showId);
        holder.put("title", "");
        holder.put("year", "");

        JSONArray array = new JSONArray();
        int count = episodes.size();
        for (int i = 0; i < count; i++) {
            JSONObject jsonMovie = new JSONObject();
            jsonMovie.put("season", episodes.get(i).getSeason());
            jsonMovie.put("episode", episodes.get(i).getEpisode());
            array.put(jsonMovie);
        }
        holder.put("episodes", array);

        Request request = MizLib.getJsonPostRequest(
                "http://api.trakt.tv/show/episode/" + (!watched ? "un" : "") + "seen/" + getApiKey(c), holder);
        Response response = MizuuApplication.getOkHttpClient().newCall(request).execute();

        return response.isSuccessful();
    } catch (Exception e) {
        return false;
    }
}

From source file:edu.polyu.screamalert.SoundProcessing.java

private static void callPhone() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Exchanger.thisContext);
    String phoneNumber = prefs.getString("phoneNumber", null);
    Boolean enableCall = prefs.getBoolean("enableCall", false);
    if (phoneNumber != null && enableCall) {
        if (phoneNumber.trim().length() > 0) { // Avoid empty string or white spaces in the preference field
            TelephonyManager phoneMgr = (TelephonyManager) thisContext
                    .getSystemService(Context.TELEPHONY_SERVICE);
            if (phoneMgr.getCallState() == TelephonyManager.CALL_STATE_IDLE
                    && phoneMgr.getSimState() != TelephonyManager.SIM_STATE_ABSENT) {
                Intent callIntent = new Intent(Intent.ACTION_CALL);
                callIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                callIntent.setData(Uri.parse("tel:" + phoneNumber));
                Exchanger.thisContext.startActivity(callIntent);
            }/*from   w  w  w  . j  a  va2  s.c o m*/
        }
    }
}

From source file:com.cssweb.android.common.FairyUI.java

/**
 * ?//from ww w. j  ava  2 s  .  c om
 * 
 * @param paramInt
 * @param paramInt2
 * @param paramContext
 * @return
 */
public static boolean genIsActiveIntent(int paramInt, int paramInt2, Context paramContext) {
    SharedPreferences sharedPreferences = paramContext.getSharedPreferences("mobile", Context.MODE_PRIVATE);
    boolean flag = sharedPreferences.getBoolean("jhSuccess", false);
    return flag;
}

From source file:com.crte.sipstackhome.ui.preferences.PreferencesWrapper.java

/**
 * boolean?//from ww  w.java 2s . c  om
 *
 * @param aPrefs
 * @param key
 * @return
 */
private static Boolean gPrefBooleanValue(SharedPreferences aPrefs, String key) {
    if (aPrefs == null) {
        return BOOLEAN_PREFS.get(key);
    }
    if (BOOLEAN_PREFS.containsKey(key)) {
        return aPrefs.getBoolean(key, BOOLEAN_PREFS.get(key));
    }
    if (aPrefs.contains(key)) {
        return aPrefs.getBoolean(key, false);
    }
    return null;
}

From source file:com.rsegismont.androlife.core.utils.AndrolifeUtils.java

private static String[][] getCursorValues(Context paramContext, int paramInt, Calendar... paramVarArgs) {

    String[] arrayOfString1;/*from   w  w w  .  j  a v  a2  s .  co m*/
    String[] arrayOfString2;
    try {
        final SharedPreferences localSharedPreferences = PreferenceManager
                .getDefaultSharedPreferences(paramContext);
        String str1 = SharedInformation.DatabaseColumn.TYPE.stringValue + "<>? AND "
                + SharedInformation.DatabaseColumn.TYPE.stringValue + "<>? AND "
                + SharedInformation.DatabaseColumn.TYPE.stringValue + "<>?";
        String str2 = "";
        String str3 = "";
        String str4 = "";
        if (!localSharedPreferences.getBoolean("settings_filters_clip", true)) {
            str2 = "Clip";
        }
        if (!localSharedPreferences.getBoolean("settings_filters_magazines", true)) {
            str3 = "Magazine";
        }
        if (!localSharedPreferences.getBoolean("settings_filters_series", true)) {
            str4 = "Fiction";
        }

        arrayOfString1 = new String[paramVarArgs.length >= 2 ? 5 : 3];
        arrayOfString1[0] = str2;
        arrayOfString1[1] = str4;
        arrayOfString1[2] = str3;

        if (paramVarArgs.length >= 2) {
            str1 = str1 + " AND " + SharedInformation.DatabaseColumn.DATE_UTC.stringValue + " BETWEEN ? AND ?";
            arrayOfString1[3] = "" + paramVarArgs[0].getTime().getTime();
            arrayOfString1[4] = "" + paramVarArgs[1].getTime().getTime();
        }

        switch (paramInt) {
        case Constantes.CURSOR_SELECTION:
            arrayOfString2 = new String[1 + arrayOfString1.length];
            System.arraycopy(arrayOfString1, 0, arrayOfString2, 0, arrayOfString1.length);
            str1 = str1 + " AND " + SharedInformation.DatabaseColumn.LEVELTYPE.stringValue + "=?";
            arrayOfString2[arrayOfString1.length] = "110";
            break;
        case Constantes.CURSOR_NEWS:
            arrayOfString2 = new String[1 + arrayOfString1.length];
            System.arraycopy(arrayOfString1, 0, arrayOfString2, 0, arrayOfString1.length);
            str1 = str1 + " AND " + SharedInformation.DatabaseColumn.PREMIERE_DIFFUSION.stringValue + "=?";
            arrayOfString2[arrayOfString1.length] = "1";
            break;
        default:
            arrayOfString2 = new String[arrayOfString1.length];
            System.arraycopy(arrayOfString1, 0, arrayOfString2, 0, arrayOfString1.length);
            break;
        }

        String[][] arrayOfString = (String[][]) Array.newInstance(String.class,
                new int[] { 2, arrayOfString2.length });
        arrayOfString[0][0] = str1;
        arrayOfString[1] = arrayOfString2;
        return arrayOfString;
    } catch (Throwable localThrowable) {
        localThrowable.printStackTrace();
        return null;
    }

}

From source file:com.farmerbb.secondscreen.util.U.java

public static boolean runSizeCommand(Context context, String requestedRes) {
    DisplayMetrics metrics = new DisplayMetrics();
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display disp = wm.getDefaultDisplay();
    disp.getRealMetrics(metrics);//w  ww  . j  a v  a2  s. co m

    SharedPreferences prefMain = getPrefMain(context);
    String currentRes = " ";
    String nativeRes;

    if (prefMain.getBoolean("landscape", false))
        nativeRes = Integer.toString(prefMain.getInt("height", 0)) + "x"
                + Integer.toString(prefMain.getInt("width", 0));
    else
        nativeRes = Integer.toString(prefMain.getInt("width", 0)) + "x"
                + Integer.toString(prefMain.getInt("height", 0));

    if (prefMain.getBoolean("debug_mode", false)) {
        SharedPreferences prefCurrent = getPrefCurrent(context);
        currentRes = prefCurrent.getString("size", "reset");

        if ("reset".equals(currentRes))
            currentRes = nativeRes;
    } else {
        if ((context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT
                && !prefMain.getBoolean("landscape", false))
                || (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE
                        && prefMain.getBoolean("landscape", false))) {
            currentRes = Integer.toString(metrics.widthPixels) + "x" + Integer.toString(metrics.heightPixels);
        } else if ((context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE
                && !prefMain.getBoolean("landscape", false))
                || (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT
                        && prefMain.getBoolean("landscape", false))) {
            currentRes = Integer.toString(metrics.heightPixels) + "x" + Integer.toString(metrics.widthPixels);
        }
    }

    if (requestedRes.equals("reset"))
        requestedRes = nativeRes;

    return !requestedRes.equals(currentRes);
}

From source file:com.onesignal.OSPermissionState.java

OSPermissionState(boolean asFrom) {
    // Java 8 method reference can be used in the future with Android Studio 2.4.0
    //   OSPermissionChangedInternalObserver::changed
    observable = new OSObservable<>("changed", false);

    if (asFrom) {
        final SharedPreferences prefs = getGcmPreferences(appContext);
        enabled = prefs.getBoolean("ONESIGNAL_ACCEPTED_NOTIFICATION_LAST", false);
    } else/*from   ww w.  j a  va2s . c o  m*/
        refreshAsTo();
}

From source file:de.ub0r.android.websms.connector.common.Utils.java

/**
 * Get custom sender from preferences by users choice. Else: default sender
 * is selected./*from w ww.jav  a2s. c  o  m*/
 * 
 * @param context
 *            {@link Context}
 * @param defSender
 *            default Sender
 * @return selected Sender
 */
public static String getSender(final Context context, // .
        final String defSender) {
    if (context == null) {
        return defSender;
    }
    final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context);
    if (p.getBoolean(PREFS_USE_DEFAULT_SENDER, true)) {
        return defSender;
    }
    final String s = p.getString(PREFS_CUSTOM_SENDER, "");
    if (s == null || s.length() == 0) {
        return defSender;
    }
    return s;
}

From source file:de.ub0r.android.websms.connector.common.Utils.java

/**
 * Get custom sender number from preferences by users choice. Else: default
 * sender is selected./*w  ww .  j  a va2  s.  c o m*/
 * 
 * @param context
 *            {@link Context}
 * @param defSender
 *            default Sender
 * @return selected Sender
 */
public static String getSenderNumber(final Context context, // .
        final String defSender) {
    if (context == null) {
        return defSender;
    }
    final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context);
    if (p.getBoolean(PREFS_USE_DEFAULT_SENDER, true)) {
        return defSender;
    }
    final String s = p.getString(PREFS_CUSTOM_SENDER, "");
    if (s == null || s.length() == 0) {
        return defSender;
    }
    final String sn = s.replaceAll("(\\+|[0-9])", "");
    if (sn.length() > 0) {
        Log.d(TAG, "fall back to default numer: " + sn);
        return defSender;
    }
    return s;
}

From source file:damo.three.ie.prepay.InternetAddonAlarmManagerReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    SharedPreferences sharedPrefsUsages = context.getSharedPreferences("damo.three.ie.previous_usage",
            Context.MODE_PRIVATE);
    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);

    boolean notificationsEnabled = sharedPrefs.getBoolean("notification", true);
    String usages = sharedPrefsUsages.getString("usage_info", null);

    // first check if anything was persisted
    if (usages != null) {
        try {/* w  w w.  j  av a  2s  .  co  m*/
            List<UsageItem> usageItems = JSONUtils.jsonToUsageItems(new JSONArray(usages));
            List<BasicUsageItem> basicUsageItems = UsageUtils.getAllBasicItems(usageItems);
            UsageUtils.registerInternetExpireAlarm(context, basicUsageItems, notificationsEnabled, false);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}