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.thejoshwa.ultrasonic.androidapp.util.Util.java

public static boolean getJukeboxEnabled(Context context, int instance) {
    if (instance == 0) {
        return false;
    }/*w  ww .  ja  v a 2  s .  c  om*/
    SharedPreferences prefs = getPreferences(context);
    return prefs.getBoolean(Constants.PREFERENCES_KEY_JUKEBOX_BY_DEFAULT + instance, false);
}

From source file:io.v.android.apps.syncslides.NavigationDrawerFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Read in the flag indicating whether or not the user has demonstrated awareness of the
    // drawer. See PREF_USER_LEARNED_DRAWER for details.
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    mUserLearnedDrawer = prefs.getBoolean(PREF_USER_LEARNED_DRAWER, false);
    mUserEmail = SignInActivity.getUserEmail(getActivity());
    mUserName = SignInActivity.getUserName(getActivity());

    if (savedInstanceState != null) {
        mCurrentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION);
        mFromSavedInstanceState = true;/*from www .  j a  va 2  s . com*/
    }

    // Select either the default item (0) or the last selected item.
    selectItem(mCurrentSelectedPosition);
}

From source file:com.juick.android.Utils.java

public static RESTResponse getJSON(final Context context, final String url,
        final Notification progressNotification, final int timeout, final boolean forceAttachCredentials) {
    final URLAuth authorizer = getAuthorizer(url);
    final RESTResponse[] ret = new RESTResponse[] { null };
    final URLAuth finalAuthorizer = authorizer;
    final boolean[] cookieCleared = { false };
    authorizer.authorize(context, false, forceAttachCredentials, url, new Function<Void, String>() {
        @Override/*from   ww w .j  av  a  2 s .com*/
        public Void apply(String myCookie) {
            final boolean noAuthRequested = myCookie != null && myCookie.equals(URLAuth.REFUSED_AUTH);
            if (noAuthRequested)
                myCookie = null;
            final DefaultHttpClient client = getNewHttpClient();
            try {
                final Function<Void, String> thiz = this;
                final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
                boolean compression = sp.getBoolean("http_compression", false);
                long l = System.currentTimeMillis();
                if (compression)
                    initCompressionSupport(client);
                HttpGet httpGet = new HttpGet(authorizer.authorizeURL(url, myCookie));
                Integer timeoutForConnection = timeout > 0 ? timeout
                        : (sp.getBoolean("use_timeouts_json", false) ? 10000 : 2222000);
                client.getParams().setParameter("http.connection.timeout", timeoutForConnection);
                httpGet.getParams().setParameter("http.socket.timeout", timeoutForConnection);
                httpGet.getParams().setParameter("http.protocol.head-body-timeout", timeoutForConnection);

                finalAuthorizer.authorizeRequest(httpGet, myCookie);

                client.execute(httpGet, new ResponseHandler<Object>() {
                    @Override
                    public Object handleResponse(HttpResponse o) throws ClientProtocolException, IOException {
                        URLAuth.ReplyCode authReplyCode = o.getStatusLine().getStatusCode() == 200
                                ? URLAuth.ReplyCode.NORMAL
                                : authorizer.validateNon200Reply(o, url, forceAttachCredentials);
                        boolean simulateError = false;
                        if (o.getStatusLine().getStatusCode() == 200 && !simulateError) {
                            reloginTried = 0;
                            HttpEntity e = o.getEntity();
                            if (progressNotification instanceof DownloadProgressNotification) {
                                ((DownloadProgressNotification) progressNotification).notifyDownloadProgress(0);
                            }
                            InputStream content = e.getContent();
                            RESTResponse retval = streamToString(content, progressNotification);
                            content.close();
                            if (authorizer.isNoAuthInResponse(retval) && !cookieCleared[0]) {
                                cookieCleared[0] = true; // don't enter loop
                                authorizer.clearCookie(context, new Runnable() {
                                    @Override
                                    public void run() {
                                        authorizer.authorize(context, true, false, url, thiz);
                                    }
                                });
                                return null;
                            }
                            ret[0] = retval;
                        } else {
                            if (authReplyCode == URLAuth.ReplyCode.FORBIDDEN && noAuthRequested) {
                                ret[0] = new RESTResponse(NO_AUTH, false, null);
                                return o;
                            }
                            if (authReplyCode == URLAuth.ReplyCode.FORBIDDEN && !forceAttachCredentials) {
                                ret[0] = getJSON(context, url, progressNotification, timeout, true);
                                return o;
                            } else if (authReplyCode == URLAuth.ReplyCode.FORBIDDEN && !cookieCleared[0]) {
                                cookieCleared[0] = true; // don't enter loop
                                authorizer.clearCookie(context, new Runnable() {
                                    @Override
                                    public void run() {
                                        authorizer.authorize(context, true, false, url, thiz);
                                    }
                                });
                                return null;
                            } else if (o.getStatusLine().getStatusCode() / 100 == 4) {
                                if (context instanceof Activity) {
                                    final Activity activity = (Activity) context;
                                    reloginTried++;
                                    if (reloginTried == 3) {
                                        activity.runOnUiThread(new Runnable() {
                                            @Override
                                            public void run() {
                                                sp.edit().remove("web_cookie").commit();
                                                reloginTried = 0;
                                            }
                                        });
                                    }
                                }
                                // fall through
                            }

                            if (progressNotification instanceof DownloadErrorNotification) {
                                ((DownloadErrorNotification) progressNotification).notifyDownloadError(
                                        "HTTP response code: " + o.getStatusLine().getStatusCode());
                            }
                            ret[0] = new RESTResponse("HTTP: " + o.getStatusLine().getStatusCode() + " "
                                    + o.getStatusLine().getReasonPhrase(), false, null);
                        }
                        return o;
                    }
                });
                l = System.currentTimeMillis() - l;
                if (reportTimes) {
                    Toast.makeText(context, "Load time=" + l + " msec", Toast.LENGTH_LONG).show();
                }
            } catch (Exception e) {
                if (progressNotification instanceof DownloadErrorNotification) {
                    ((DownloadErrorNotification) progressNotification)
                            .notifyDownloadError("HTTP connect: " + e.toString());
                }
                Log.e("getJSON", e.toString());
                ret[0] = new RESTResponse(e.toString(), true, null);
            } finally {
                client.getConnectionManager().shutdown();
            }
            return null; //To change body of implemented methods use File | Settings | File Templates.
        }
    });
    while (ret[0] == null) { // bad, but true
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        }
    }
    return ret[0];
}

From source file:com.triarc.sync.LogCollector.java

public boolean hasForceCloseHappened() {
    String[] filterSpecs = { "*:E" }; //{"AndroidRuntime:E"}; // for some reason, AndroidRuntime:E lists all logs
    ArrayList<String> lines = new ArrayList<String>();
    collectLog(lines, "time", null, filterSpecs);
    if (lines.size() > 0) {
        boolean forceClosedSinceLastCheck = false;
        for (String line : lines) {
            final Matcher matcher = mPattern.matcher(line);
            boolean isMyStackTrace = matcher.matches();
            SharedPreferences prefs = mPrefs;
            if (isMyStackTrace) {
                String timestamp = matcher.group(1);
                boolean appeared = prefs.getBoolean(timestamp, false);
                //               Log.d(LOG_TAG, lineKey);
                if (!appeared) {
                    //                  Log.d(LOG_TAG, "!appeared");
                    forceClosedSinceLastCheck = true;
                    prefs.edit().putBoolean(timestamp, true).commit();
                }//from  ww  w  .  java2 s .co m
            }
        }
        return forceClosedSinceLastCheck;
    } else
        return false;
}

From source file:github.daneren2005.dsub.util.Util.java

public static void applyTheme(Context context, String theme) {
    if ("dark".equals(theme)) {
        context.setTheme(R.style.Theme_DSub_Dark);
    } else if ("black".equals(theme)) {
        context.setTheme(R.style.Theme_DSub_Black);
    } else if ("holo".equals(theme)) {
        context.setTheme(R.style.Theme_DSub_Holo);
    } else {//from   www.  j ava  2 s  . co m
        context.setTheme(R.style.Theme_DSub_Light);
    }

    SharedPreferences prefs = Util.getPreferences(context);
    if (prefs.getBoolean(Constants.PREFERENCES_KEY_OVERRIDE_SYSTEM_LANGUAGE, false)) {
        Configuration config = new Configuration();
        config.locale = Locale.ENGLISH;
        context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
    }
}

From source file:com.sourceallies.android.zonebeacon.activity.TransferActivityTest.java

@Test
public void test_changedSeenNearbySetting() {
    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(activity);
    assertTrue(sharedPrefs.getBoolean("seen_nearby", false));
}

From source file:com.baidu.android.voicedemo.ActivityTouch.java

public void bindParams(Intent intent) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    if (sp.getBoolean("tips_sound", true)) {
        intent.putExtra(Constant.EXTRA_SOUND_START, R.raw.bdspeech_recognition_start);
        intent.putExtra(Constant.EXTRA_SOUND_END, R.raw.bdspeech_speech_end);
        intent.putExtra(Constant.EXTRA_SOUND_SUCCESS, R.raw.bdspeech_recognition_success);
        intent.putExtra(Constant.EXTRA_SOUND_ERROR, R.raw.bdspeech_recognition_error);
        intent.putExtra(Constant.EXTRA_SOUND_CANCEL, R.raw.bdspeech_recognition_cancel);
    }/*w  w w. j  a  va  2 s . c  o  m*/
    if (sp.contains(Constant.EXTRA_INFILE)) {
        String tmp = sp.getString(Constant.EXTRA_INFILE, "").replaceAll(",.*", "").trim();
        intent.putExtra(Constant.EXTRA_INFILE, tmp);
    }
    if (sp.getBoolean(Constant.EXTRA_OUTFILE, false)) {
        intent.putExtra(Constant.EXTRA_OUTFILE, "sdcard/outfile.pcm");
    }
    if (sp.contains(Constant.EXTRA_SAMPLE)) {
        String tmp = sp.getString(Constant.EXTRA_SAMPLE, "").replaceAll(",.*", "").trim();
        if (null != tmp && !"".equals(tmp)) {
            intent.putExtra(Constant.EXTRA_SAMPLE, Integer.parseInt(tmp));
        }
    }
    if (sp.contains(Constant.EXTRA_LANGUAGE)) {
        String tmp = sp.getString(Constant.EXTRA_LANGUAGE, "").replaceAll(",.*", "").trim();
        if (null != tmp && !"".equals(tmp)) {
            intent.putExtra(Constant.EXTRA_LANGUAGE, tmp);
        }
    }
    if (sp.contains(Constant.EXTRA_NLU)) {
        String tmp = sp.getString(Constant.EXTRA_NLU, "").replaceAll(",.*", "").trim();
        if (null != tmp && !"".equals(tmp)) {
            intent.putExtra(Constant.EXTRA_NLU, tmp);
        }
    }

    if (sp.contains(Constant.EXTRA_VAD)) {
        String tmp = sp.getString(Constant.EXTRA_VAD, "").replaceAll(",.*", "").trim();
        if (null != tmp && !"".equals(tmp)) {
            intent.putExtra(Constant.EXTRA_VAD, tmp);
        }
    }
    String prop = null;
    if (sp.contains(Constant.EXTRA_PROP)) {
        String tmp = sp.getString(Constant.EXTRA_PROP, "").replaceAll(",.*", "").trim();
        if (null != tmp && !"".equals(tmp)) {
            intent.putExtra(Constant.EXTRA_PROP, Integer.parseInt(tmp));
            prop = tmp;
        }
    }
    // offline asr
    {
        intent.putExtra(Constant.EXTRA_OFFLINE_ASR_BASE_FILE_PATH, "/sdcard/easr/s_1");
        intent.putExtra(Constant.EXTRA_LICENSE_FILE_PATH, "/sdcard/easr/license-tmp-20150530.txt");
        if (null != prop) {
            int propInt = Integer.parseInt(prop);
            if (propInt == 10060) {
                intent.putExtra(Constant.EXTRA_OFFLINE_LM_RES_FILE_PATH, "/sdcard/easr/s_2_Navi");
            } else if (propInt == 20000) {
                intent.putExtra(Constant.EXTRA_OFFLINE_LM_RES_FILE_PATH, "/sdcard/easr/s_2_InputMethod");
            }
        }
        intent.putExtra(Constant.EXTRA_OFFLINE_SLOT_DATA, buildTestSlotData());
    }
}

From source file:com.project.qrypto.keymanagement.KeyManager.java

public void init(Activity context) throws InvalidCipherTextException, IOException {
    if (!storeLoaded) {
        SharedPreferences preferences = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_PRIVATE);
        internalStorage = preferences.getBoolean(USE_INTERNAL_STORAGE, true);
        passwordProtected = preferences.getBoolean(PASSWORD_PROTECTED, true);
        setupComplete = preferences.getBoolean(SETUP_COMPLETE, false);
        if (passwordProtected) {
            Intent intent = new Intent(context, SetupActivity.class);
            context.startActivity(intent);
        } else {/*from w  ww. ja  v a2  s  .c o  m*/
            load(context);
        }
    }
}

From source file:com.sourceallies.android.zonebeacon.activity.TransferActivity.java

@Override
public void onStart() {
    super.onStart();

    final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    if (!sharedPrefs.getBoolean(SEEN_NEARBY_KEY, false)) {
        new AlertDialog.Builder(this).setMessage(R.string.initial_nearby_information).setCancelable(false)
                .setPositiveButton(android.R.string.ok, this).show();

        sharedPrefs.edit().putBoolean(SEEN_NEARBY_KEY, true).apply();
    } else {/* w  w w  . j ava2  s. c  o m*/
        initializeClient();
    }
}

From source file:de.taxilof.UulmLoginAgent.java

public UulmLoginAgent(Context contextIn) {
    context = contextIn;//from w w  w . j a v  a  2 s. c o  m
    // read preferences
    SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0);
    username = settings.getString("username", "");
    password = settings.getString("password", "");
    notifySuccess = settings.getBoolean("checkSuccess", true);
    notifyFailure = settings.getBoolean("checkFailure", true);
}