List of usage examples for android.content SharedPreferences getBoolean
boolean getBoolean(String key, boolean defValue);
From source file:com.nextgis.mobile.services.DataSendService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.d(TAG, "Received start id " + startId + ": " + intent); super.onStartCommand(intent, flags, startId); if (intent == null) return START_STICKY; String action = intent.getAction(); if (action.equals(DATASEND_ACTION_STOP)) { //Toast.makeText(getApplicationContext(), "Send position service stoped", Toast.LENGTH_SHORT).show(); stopSelf();/* www .java 2 s . co m*/ } else if (action.equals(DATASEND_ACTION_START)) { SharedPreferences prefs = getSharedPreferences(Constants.SERVICE_PREF, MODE_MULTI_PROCESS); boolean bStart = prefs.getBoolean(Constants.KEY_PREF_SW_SENDPOS_SRV, false); if (bStart) new SendPositionDataTask().execute(getApplicationContext()); else //Toast.makeText(getApplicationContext(), "Send position service started", Toast.LENGTH_SHORT).show(); stopSelf(); } return START_STICKY; }
From source file:com.getmarco.weatherstationviewer.gcm.StationGcmListenerService.java
/** * Called when message is received.//from w w w .j av a 2 s . c o m * * @param from SenderID of the sender. * @param data Data bundle containing message data as key/value pairs. * For Set of keys use data.keySet(). */ // [START receive_message] @Override public void onMessageReceived(String from, Bundle data) { String message = data.getString("message"); Log.d(LOG_TAG, "From: " + from); Log.d(LOG_TAG, "Message: " + message); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); boolean enableTempNotifications = sharedPreferences .getBoolean(getString(R.string.pref_enable_temp_notifications_key), Boolean.parseBoolean("true")); boolean enableHumidityNotifications = sharedPreferences.getBoolean( getString(R.string.pref_enable_humidity_notifications_key), Boolean.parseBoolean("true")); boolean notifyUser = false; String tag = null; double temp = 0; double humidity = 0; double latitude = 0; double longitude = 0; String dateString = null; StringBuilder msg = new StringBuilder(); try { JSONObject json = new JSONObject(message); if (!json.isNull(STATION_TAG)) { tag = json.getString(STATION_TAG); msg.append(tag); } else throw new IllegalArgumentException("station tag is required"); if (!json.isNull(CONDITION_DATE)) dateString = json.getString(CONDITION_DATE); else throw new IllegalArgumentException("date is required"); if (msg.length() > 0) msg.append(" -"); if (!json.isNull(CONDITION_TEMP)) { notifyUser |= enableTempNotifications; temp = json.getDouble(CONDITION_TEMP); msg.append(" temp: " + getString(R.string.format_temperature, temp)); } if (!json.isNull(CONDITION_HUMIDITY)) { notifyUser |= enableHumidityNotifications; humidity = json.getDouble(CONDITION_HUMIDITY); msg.append(" humidity: " + getString(R.string.format_humidity, humidity)); } if (!json.isNull(CONDITION_LAT)) { latitude = json.getDouble(CONDITION_LAT); } if (!json.isNull(CONDITION_LONG)) { longitude = json.getDouble(CONDITION_LONG); } } catch (JSONException e) { Log.e(LOG_TAG, "error parsing GCM message JSON", e); } long stationId = addStation(tag); Date date = Utility.parseDateDb(dateString); ContentValues conditionValues = new ContentValues(); conditionValues.put(StationContract.ConditionEntry.COLUMN_STATION_KEY, stationId); conditionValues.put(StationContract.ConditionEntry.COLUMN_TEMP, temp); conditionValues.put(StationContract.ConditionEntry.COLUMN_HUMIDITY, humidity); conditionValues.put(StationContract.ConditionEntry.COLUMN_LATITUDE, latitude); conditionValues.put(StationContract.ConditionEntry.COLUMN_LONGITUDE, longitude); conditionValues.put(StationContract.ConditionEntry.COLUMN_DATE, date != null ? date.getTime() : 0); getContentResolver().insert(StationContract.ConditionEntry.CONTENT_URI, conditionValues); /** * show a notification indicating to the user that a message was received. */ if (notifyUser) sendNotification(msg.toString()); }
From source file:com.poloure.simplerss.FeedsActivity.java
private void setServiceIntent(int state) { // Load the ManageFeedsRefresh boolean value from settings. SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this); if (!pref.getBoolean("refreshing_enabled", false) && ALARM_SERVICE_START == state) { return;//www.jav a 2s .c o m } // Create intent, turn into pending intent, and get the alarm manager. Intent intent = new Intent(this, ServiceUpdate.class); PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, 0); AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); // Depending on the state string, start or stop the service. if (ALARM_SERVICE_START == state) { String intervalString = pref.getString("refresh_interval", "120"); long interval = Long.parseLong(intervalString) * MINUTE_VALUE; long next = System.currentTimeMillis() + interval; am.setRepeating(AlarmManager.RTC_WAKEUP, next, interval, pendingIntent); } else if (ALARM_SERVICE_STOP == state) { am.cancel(pendingIntent); } }
From source file:github.daneren2005.dsub.util.Util.java
public static boolean isTagBrowsing(Context context, int instance) { SharedPreferences prefs = getPreferences(context); return prefs.getBoolean(Constants.PREFERENCES_KEY_BROWSE_TAGS + instance, false); }
From source file:github.daneren2005.dsub.util.Util.java
public static boolean isSyncEnabled(Context context, int instance) { SharedPreferences prefs = getPreferences(context); return prefs.getBoolean(Constants.PREFERENCES_KEY_SERVER_SYNC + instance, true); }
From source file:github.daneren2005.dsub.util.Util.java
public static boolean isOpenToLibrary(Context context) { SharedPreferences prefs = getPreferences(context); return prefs.getBoolean(Constants.PREFERENCES_KEY_OPEN_TO_LIBRARY, false); }
From source file:de.ub0r.android.websms.connector.gmx.ConnectorGMX.java
/** * {@inheritDoc}/* w w w . ja va 2s .com*/ */ @Override public ConnectorSpec updateSpec(final Context context, final ConnectorSpec connectorSpec) { final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context); if (p.getBoolean(Preferences.PREFS_ENABLED, false)) { if (p.getString(Preferences.PREFS_MAIL, "").length() > 0 && p.getString(Preferences.PREFS_PASSWORD, "") // . .length() > 0) { connectorSpec.setReady(); } else { connectorSpec.setStatus(ConnectorSpec.STATUS_ENABLED); } } else { connectorSpec.setStatus(ConnectorSpec.STATUS_INACTIVE); } return connectorSpec; }
From source file:github.daneren2005.dsub.util.Util.java
public static boolean isScrobblingEnabled(Context context) { SharedPreferences prefs = getPreferences(context); return prefs.getBoolean(Constants.PREFERENCES_KEY_SCROBBLE, true) && (isOffline(context) || UserUtil.canScrobble()); }
From source file:github.daneren2005.dsub.util.Util.java
public static int getActiveServer(Context context) { SharedPreferences prefs = getPreferences(context); return prefs.getBoolean(Constants.PREFERENCES_KEY_OFFLINE, false) ? 0 : prefs.getInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1); }
From source file:de.unclenet.dehabewe.CalendarActivity.java
private void handleException(Exception e) { e.printStackTrace();//from w w w. ja va 2 s. c o m SharedPreferences settings = getSharedPreferences(PREF, 0); boolean log = settings.getBoolean("logging", false); if (e instanceof HttpResponseException) { HttpResponse response = ((HttpResponseException) e).response; int statusCode = response.statusCode; try { response.ignore(); } catch (IOException e1) { e1.printStackTrace(); } if (statusCode == 401 || statusCode == 403) { gotAccount(true); return; } if (log) { try { Log.e(DEBUG_TAG, response.parseAsString()); } catch (IOException parseException) { parseException.printStackTrace(); } } } if (log) { Log.e(DEBUG_TAG, e.getMessage(), e); } }