List of usage examples for android.content SharedPreferences getBoolean
boolean getBoolean(String key, boolean defValue);
From source file:net.peterkuterna.android.apps.devoxxfrsched.service.CfpSyncManager.java
/** * Set up the alarm.//w ww . j a v a2 s.co m * * @param trigger * when the alarm should first trigger in milliseconds. */ public void setSyncAlarm(long trigger) { Log.d(TAG, "Setting up sync alarm"); final Context context = getContext(); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); final boolean doBackgroundUpdates = prefs.getBoolean(SettingsActivity.KEY_BACKGROUND_UPDATES, true); if (doBackgroundUpdates) { AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); PendingIntent pi = getAlarmPendingIntent(); if (pi == null) { pi = createAlarmPendingIntent(); } am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + trigger, INTERVAL, pi); } }
From source file:info.graffy.android.websms.connector.meinbmw.ConnectorMeinBMW.java
private final ConnectorSpec setConnectorStatus(final ConnectorSpec connectorSpec) { final SharedPreferences p = getDefaultSharedPreferences(); if (p.getBoolean(Preferences.PREFS_ENABLED, false)) if (getUserName().length() > 0 && getPassword().length() > 0) connectorSpec.setReady();//from www . ja v a 2s .c o m else connectorSpec.setStatus(ConnectorSpec.STATUS_ENABLED); else connectorSpec.setStatus(ConnectorSpec.STATUS_INACTIVE); return connectorSpec; }
From source file:edu.nd.darts.cimon.NDroidAdmin.java
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); try {//from w w w . j av a 2 s . com inflater.inflate(R.menu.options_menu, menu); } catch (InflateException e) { e.printStackTrace(); return false; } MenuItem item = menu.findItem(R.id.startup); if (item != null) { SharedPreferences appPrefs = getSharedPreferences(SHARED_PREFS, Context.MODE_PRIVATE); boolean startup = appPrefs.getBoolean(PREF_STARTUP, true); item.setChecked(startup); } return true; }
From source file:com.muzima.view.forms.HTMLFormDataStore.java
@JavascriptInterface public String getDefaultEncounterProvider() { SharedPreferences preferences = PreferenceManager .getDefaultSharedPreferences(formWebViewActivity.getApplicationContext()); boolean encounterProviderPreference = preferences.getBoolean("encounterProviderPreference", false); List<Provider> providers = new ArrayList<Provider>(); if (encounterProviderPreference) { MuzimaApplication applicationContext = (MuzimaApplication) formWebViewActivity.getApplicationContext(); providers.add(providerController .getProviderBySystemId(applicationContext.getAuthenticatedUser().getSystemId())); return JSONValue.toJSONString(providers); }/*from w ww.ja v a 2s . c om*/ return JSONValue.toJSONString(providers); }
From source file:com.saarang.samples.apps.iosched.ui.ExpertsDirectoryActivity.java
public Boolean loadpref(String event) { SharedPreferences fav = PreferenceManager.getDefaultSharedPreferences(this); Boolean cbvalue = fav.getBoolean(event, false); return cbvalue; }
From source file:com.google.android.apps.chrometophone.C2DMReceiver.java
@Override public void onMessage(Context context, Intent intent) { Bundle extras = intent.getExtras();//from ww w . ja v a2 s. co m if (extras != null) { String url = (String) extras.get("url"); String title = (String) extras.get("title"); String sel = (String) extras.get("sel"); String debug = (String) extras.get("debug"); if (debug != null) { // server-controlled debug - the server wants to know // we received the message, and when. This is not user-controllable, // we don't want extra traffic on the server or phone. Server may // turn this on for a small percentage of requests or for users // who report issues. DefaultHttpClient client = new DefaultHttpClient(); HttpGet get = new HttpGet(DeviceRegistrar.BASE_URL + "/debug?id=" + extras.get("collapse_key")); // No auth - the purpose is only to generate a log/confirm delivery // (to avoid overhead of getting the token) try { client.execute(get); } catch (ClientProtocolException e) { // ignore } catch (IOException e) { // ignore } } if (title != null && url != null && url.startsWith("http")) { SharedPreferences settings = Prefs.get(context); Intent launchIntent = getLaunchIntent(context, url, title, sel); if (settings.getBoolean("launchBrowserOrMaps", true) && launchIntent != null) { playNotificationSound(context); context.startActivity(launchIntent); } else { if (sel != null && sel.length() > 0) { // have selection generateNotification(context, sel, context.getString(R.string.copied_desktop_clipboard), launchIntent); } else { generateNotification(context, url, title, launchIntent); } } } } }
From source file:com.lvlstudios.android.gtmessage.C2DMReceiver.java
@Override public void onMessage(Context context, Intent intent) { Bundle extras = intent.getExtras();/*from ww w .ja v a 2 s .c o m*/ if (extras != null) { String url = (String) extras.get("url"); String title = (String) extras.get("title"); String sel = (String) extras.get("sel"); String debug = (String) extras.get("debug"); Log.d(TAG, String.format("C2DMReceiver.onMessage: url='%s', title='%s', sel='%s'", url, title, sel)); if (debug != null) { // server-controlled debug - the server wants to know we received the message, and when. // This is not user-controllable, // we don't want extra traffic on the server or phone. Server may // turn this on for a small percentage of requests or for users // who report issues. DefaultHttpClient client = new DefaultHttpClient(); HttpGet get = new HttpGet(AppEngineClient.BASE_URL + "/debug?id=" + extras.get("collapse_key")); // No auth - the purpose is only to generate a log/confirm delivery // (to avoid overhead of getting the token) try { client.execute(get); } catch (ClientProtocolException e) { // ignore } catch (IOException e) { // ignore } } if (title != null && url != null && url.startsWith("http")) { SharedPreferences settings = Prefs.get(context); Intent launchIntent = LauncherUtils.getLaunchIntent(context, title, url, sel); // Notify and optionally start activity if (settings.getBoolean("launchBrowserOrMaps", true) && launchIntent != null) { try { context.startActivity(launchIntent); LauncherUtils.playNotificationSound(context); } catch (ActivityNotFoundException e) { return; } } else { if (sel != null && sel.length() > 0) { // have selection LauncherUtils.generateNotification(context, sel, context.getString(R.string.copied_desktop_clipboard), launchIntent); } else { LauncherUtils.generateNotification(context, url, title, launchIntent); } } // Record history (for link/maps only) if (launchIntent != null && launchIntent.getAction().equals(Intent.ACTION_VIEW)) { HistoryDatabase.get(context).insertHistory(title, url); } } } }
From source file:com.adguard.android.contentblocker.preferences.PreferenceDb.java
private void refreshItems() { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); for (PreferenceItem item : itemsList) { if (item.value instanceof Boolean) { item.value = prefs.getBoolean(item.name, (Boolean) item.value); } else if (item.value instanceof Integer) { item.value = prefs.getInt(item.name, (Integer) item.value); } else if (item.value instanceof String) { item.value = prefs.getString(item.name, (String) item.value); } else if (item.value instanceof String[]) { item.value = StringUtils.split(prefs.getString(item.name, (String) item.value), System.lineSeparator()); }//from w w w . j ava 2 s . co m } }
From source file:de.ub0r.android.websms.connector.sms77.ConnectorSms77.java
/** * {@inheritDoc}// w ww. j a v a 2 s . com */ @Override public final ConnectorSpec initSpec(final Context context) { final String name = context.getString(R.string.connector_sms77_name); ConnectorSpec c = new ConnectorSpec(name); c.setAuthor(context.getString(R.string.connector_sms77_author)); c.setBalance(null); c.setSMSLengthCalculator(new BasicSMSLengthCalculator(new int[] { 160, 153 })); // FIXME: c.setLimitLength(MAX_CUSTOM_SENDER_LENGTH); c.setCapabilities(ConnectorSpec.CAPABILITIES_UPDATE | ConnectorSpec.CAPABILITIES_SEND | ConnectorSpec.CAPABILITIES_PREFS); SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context); if (!p.getBoolean(PREFS_HIDE_WO_SENDER, false)) { c.addSubConnector(ID_WO_SENDER, context.getString(R.string.wo_sender), SubConnectorSpec.FEATURE_SENDLATER); } if (!p.getBoolean(PREFS_HIDE_QUALITY, false)) { c.addSubConnector(ID_QUALITY, context.getString(R.string.quality), SubConnectorSpec.FEATURE_CUSTOMSENDER | SubConnectorSpec.FEATURE_SENDLATER | SubConnectorSpec.FEATURE_FLASHSMS); } return c; }
From source file:com.dattasmoon.pebble.plugin.FireReceiver.java
@Override public void onReceive(final Context context, final Intent intent) { if (com.twofortyfouram.locale.Intent.ACTION_FIRE_SETTING.equals(intent.getAction())) { // fetch this for later, we may need it in case we change things // around and we need to know what version of the code they were // running when they saved the action int bundleVersionCode = intent.getIntExtra(Constants.BUNDLE_EXTRA_INT_VERSION_CODE, 1); Type type = Type.values()[intent.getIntExtra(Constants.BUNDLE_EXTRA_INT_TYPE, Type.NOTIFICATION.ordinal())]; PowerManager pm;/*from w w w .j av a 2 s. c o m*/ switch (type) { case NOTIFICATION: SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context); // handle screen DND boolean notifScreenOn = sharedPref.getBoolean(Constants.PREFERENCE_NOTIF_SCREEN_ON, true); pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); if (Constants.IS_LOGGABLE) { Log.d(Constants.LOG_TAG, "FireReceiver.onReceive: notifScreenOn=" + notifScreenOn + " screen=" + pm.isScreenOn()); } if (!notifScreenOn && pm.isScreenOn()) { break; } //handle quiet hours DND boolean quiet_hours = sharedPref.getBoolean(Constants.PREFERENCE_QUIET_HOURS, false); //we only need to pull this if quiet hours are enabled. Save the cycles for the cpu! (haha) if (quiet_hours) { String[] pieces = sharedPref.getString(Constants.PREFERENCE_QUIET_HOURS_BEFORE, "00:00") .split(":"); Date quiet_hours_before = new Date(0, 0, 0, Integer.parseInt(pieces[0]), Integer.parseInt(pieces[1])); pieces = sharedPref.getString(Constants.PREFERENCE_QUIET_HOURS_AFTER, "23:59").split(":"); Date quiet_hours_after = new Date(0, 0, 0, Integer.parseInt(pieces[0]), Integer.parseInt(pieces[1])); Calendar c = Calendar.getInstance(); Date now = new Date(0, 0, 0, c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE)); if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Checking quiet hours. Now: " + now.toString() + " vs " + quiet_hours_before.toString() + " and " + quiet_hours_after.toString()); } if (now.before(quiet_hours_before) || now.after(quiet_hours_after)) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Time is before or after the quiet hours time. Returning."); } break; } } String title = intent.getStringExtra(Constants.BUNDLE_EXTRA_STRING_TITLE); String body = intent.getStringExtra(Constants.BUNDLE_EXTRA_STRING_BODY); sendAlertToPebble(context, bundleVersionCode, title, body); break; case SETTINGS: Mode mode = Mode.values()[intent.getIntExtra(Constants.BUNDLE_EXTRA_INT_MODE, Mode.OFF.ordinal())]; String packageList = intent.getStringExtra(Constants.BUNDLE_EXTRA_STRING_PACKAGE_LIST); setNotificationSettings(context, bundleVersionCode, mode, packageList); break; } } }