List of usage examples for android.content SharedPreferences contains
boolean contains(String key);
From source file:de.tum.frm2.nicos_android.gui.MainActivity.java
private void onDeviceSelected(Device device) { Object limits = device.getParam("userlimits"); Object mapping = device.getParam("mapping"); if (limits == null && mapping == null) { Toast.makeText(getApplicationContext(), "Cannot move " + device.getName() + ": Limits unknown", Toast.LENGTH_SHORT).show(); return;// w w w .ja va 2 s . c o m } _currentDevice = device; _currentDeviceTextView.setText(device.getName()); _currentDeviceValueTextView.setText(device.getFormattedValue()); _currentDeviceStatusImageView.setImageResource(DeviceStatus.getStatusResource(device.getStatus())); if (limits != null) { Object o_max = ((Object[]) limits)[1]; double max = (double) o_max; // Try to read a value from the preferences. SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); String coarseKey = _uniquePrefix + _currentDevice.getName() + "coarse"; String fineKey = _uniquePrefix + _currentDevice.getName() + "fine"; if (prefs.contains(coarseKey) && prefs.contains(fineKey)) { long dec_coarse = prefs.getLong(coarseKey, 0); long dec_fine = prefs.getLong(fineKey, 0); _coarseStepEditText.setText(String.valueOf(Double.longBitsToDouble(dec_coarse))); _fineStepEditText.setText(String.valueOf(Double.longBitsToDouble(dec_fine))); } else { // infer default steps from the max limit. _coarseStepEditText.setText(String.valueOf(max / 5)); _fineStepEditText.setText(String.valueOf(max / 10)); } } else { // TODO: Implement devices with mapping! return; } _coarseStepLeftButton.setEnabled(true); _fineStepLeftButton.setEnabled(true); _stopButton.setEnabled(true); _fineStepRightButton.setEnabled(true); _coarseStepRightButton.setEnabled(true); _slidingUpPanelLayout.setEnabled(true); }
From source file:com.gaba.alex.trafficincidents.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout); swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override/* w ww . j a v a 2s. c o m*/ public void onRefresh() { refresh(); swipeRefreshLayout.setRefreshing(false); } }); mAccountName = getString(R.string.app_name); mAccountType = getString(R.string.account_type); checkGooglePlayServices(); try { Utility.updateSettings(getApplicationContext()); } catch (RemoteException | OperationApplicationException e) { e.printStackTrace(); } mAccount = createSyncAccount(); final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); mPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() { public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { if (key.equals(PREF_LAT) || key.equals(PREF_LNG)) { try { Utility.updateSettings(getApplicationContext()); } catch (RemoteException | OperationApplicationException e) { e.printStackTrace(); } } else if (key.equals(getString(R.string.pref_auto_refresh_key))) { configurePeriodicSync(mAccount); } } }; preferences.registerOnSharedPreferenceChangeListener(mPreferencesListener); PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder(); if (preferences.contains(PREF_LAT) && preferences.contains(PREF_LNG)) { double lat = Double.parseDouble(preferences.getString(PREF_LAT, "0")); double lng = Double.parseDouble(preferences.getString(PREF_LNG, "0")); builder.setLatLngBounds(new LatLngBounds(new LatLng(lat, lng), new LatLng(lat, lng))); } configurePeriodicSync(mAccount); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); String address = preferences.getString(PREF_ADDRESS, getString(R.string.select_location)); TextView addressTextView = (TextView) findViewById(R.id.address); addressTextView.setText(address); try { mPlacePickerIntent = builder.build(this); } catch (GooglePlayServicesNotAvailableException | GooglePlayServicesRepairableException e) { e.printStackTrace(); } FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { startActivityForResult(mPlacePickerIntent, PLACE_PICKER_REQUEST); } }); }
From source file:com.irccloud.android.Notifications.java
private void load() { mNotifications = new ArrayList<Notification>(); mNetworks = new SparseArray<String>(); mLastSeenEIDs = new SparseArray<Long>(); SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(IRCCloudApplication.getInstance().getApplicationContext()); if (prefs.contains("notifications_json")) { try {//from w w w . j a va 2s . c o m JSONArray array = new JSONArray(prefs.getString("networks_json", "[]")); for (int i = 0; i < array.length(); i++) { JSONObject o = array.getJSONObject(i); mNetworks.put(o.getInt("cid"), o.getString("network")); } array = new JSONArray(prefs.getString("lastseeneids_json", "[]")); for (int i = 0; i < array.length(); i++) { JSONObject o = array.getJSONObject(i); mLastSeenEIDs.put(o.getInt("bid"), o.getLong("eid")); } synchronized (mNotifications) { array = new JSONArray(prefs.getString("notifications_json", "[]")); for (int i = 0; i < array.length(); i++) { JSONObject o = array.getJSONObject(i); Notification n = new Notification(); n.bid = o.getInt("bid"); n.cid = o.getInt("cid"); n.eid = o.getLong("eid"); n.nick = o.getString("nick"); n.message = o.getString("message"); n.chan = o.getString("chan"); n.buffer_type = o.getString("buffer_type"); n.message_type = o.getString("message_type"); n.network = mNetworks.get(n.cid); if (o.has("shown")) n.shown = o.getBoolean("shown"); mNotifications.add(n); } Collections.sort(mNotifications, new comparator()); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:it.geosolutions.geocollect.android.core.mission.PendingMissionListActivity.java
@Override public void onLocationChanged(Location location) { Log.v(TAG, "Location: \n lat " + location.getLatitude() + "\n lon " + location.getLongitude()); SharedPreferences sp = getSharedPreferences(SQLiteCascadeFeatureLoader.PREF_NAME, Context.MODE_PRIVATE); // If it is the first time we get a Location, and the list is ordered by distance, refresh the list automatically boolean needRefresh = sp.getBoolean(SQLiteCascadeFeatureLoader.ORDER_BY_DISTANCE, false) && (!sp.contains(SQLiteCascadeFeatureLoader.LOCATION_X) || sp.getLong(SQLiteCascadeFeatureLoader.LOCATION_X, 0) == 0); SharedPreferences.Editor editor = sp.edit(); // Set position editor.putLong(SQLiteCascadeFeatureLoader.LOCATION_X, Double.doubleToRawLongBits(location.getLongitude())); editor.putLong(SQLiteCascadeFeatureLoader.LOCATION_Y, Double.doubleToRawLongBits(location.getLatitude())); editor.apply();/*from w w w . j a va2 s .c o m*/ if (needRefresh) { PendingMissionListFragment listFragment = ((PendingMissionListFragment) getSupportFragmentManager() .findFragmentById(R.id.pendingmission_list)); if (listFragment != null) { listFragment.onRefresh(); } } }
From source file:dynamite.zafroshops.app.MainActivity.java
public LocationBase getAddress(boolean force) { Geocoder geocoder = new Geocoder(this, Locale.ENGLISH); SharedPreferences preferences = getPreferences(0); SharedPreferences.Editor editor = preferences.edit(); boolean locationToggle = preferences.getBoolean(StorageKeys.LOCATION_TOGGLE_KEY, locationToggleDefault); try {//from www .j a v a 2s . c o m if (!force && LastLocation != null) { if (preferences.contains(StorageKeys.COUNTRY_KEY) && !preferences.getString(StorageKeys.COUNTRY_KEY, "").equals("")) { LastLocation.CountryCode = preferences.getString(StorageKeys.COUNTRY_KEY, ""); LastLocation.Town = preferences.getString(StorageKeys.TOWN_KEY, ""); LastLocation.Street = preferences.getString(StorageKeys.STREET_KEY, ""); LastLocation.StreetNumber = preferences.getString(StorageKeys.STREETNUMBER_KEY, ""); } } else if (locationToggle && LastLocation != null) { List<Address> addresses = geocoder.getFromLocation(LastLocation.Latitude, LastLocation.Longitude, 1); if (addresses != null && addresses.size() > 0) { Address address = addresses.get(0); LastLocation.CountryCode = address.getCountryCode(); LastLocation.Town = address.getLocality(); if (address.getMaxAddressLineIndex() > 0) { String line = address.getAddressLine(0); if (line.compareTo(LastLocation.Town) < 0) { LastLocation.Street = line.replaceAll("(\\D+) \\d+.*", "$1"); LastLocation.StreetNumber = line.replaceAll("\\D+ (\\d+.*)", "$1"); } } editor.putString(StorageKeys.COUNTRY_KEY, LastLocation.CountryCode); editor.putString(StorageKeys.TOWN_KEY, LastLocation.Town); editor.putString(StorageKeys.STREET_KEY, LastLocation.Street); editor.putString(StorageKeys.STREETNUMBER_KEY, LastLocation.StreetNumber); editor.commit(); } } else { return null; } return LastLocation; } catch (IOException e) { return null; } }
From source file:org.restcomm.app.utillib.Reporters.ReportManager.java
public List<Carrier> getTopOperators(double latitude, double longitude, int radius, int mcc, int limit, boolean bReload) { // see if top operators is cached if (topoperators == null) { SharedPreferences preferenceSettings = PreferenceKeys.getSecurePreferences(mContext); if (preferenceSettings.contains(PreferenceKeys.Miscellaneous.TOPOP_RESPONSE) && !bReload) { try { String strTopopResponse = preferenceSettings .getString(PreferenceKeys.Miscellaneous.TOPOP_RESPONSE, ""); String strLat = preferenceSettings.getString(PreferenceKeys.Miscellaneous.TOPOP_LAT, ""); String strLng = preferenceSettings.getString(PreferenceKeys.Miscellaneous.TOPOP_LNG, ""); if (strTopopResponse != null && strTopopResponse.length() > 10 && strLat != null && strLat.length() > 0 && strLng.length() > 0) { double lat = Double.parseDouble(strLat); double lng = Double.parseDouble(strLng); if ((Math.abs(latitude - lat) < 2.0 && Math.abs(longitude - lng) < 2.0)) { topoperators = new ArrayList<Carrier>(); JSONArray operators = new JSONObject(strTopopResponse).getJSONArray("operators"); for (int i = 0; i < operators.length(); i++) { Carrier carrier = new Carrier(operators.getJSONObject(i)); carrier.loadLogo(mContext); if (!carrier.Name.equals("null") && !carrier.Name.equals("")) topoperators.add(carrier); }/*from www.j a v a 2 s . co m*/ return topoperators; } } } catch (JSONException e) { LoggerUtil.logToFile(LoggerUtil.Level.ERROR, TAG, "loadEventsQueue", "JSONException loading events from storage", e); } catch (Exception e) { LoggerUtil.logToFile(LoggerUtil.Level.ERROR, TAG, "loadEventsQueue", "Exception loading events from storage", e); } } } if (bReload) try { topoperators = mWebReporter.getTopOperators(latitude, longitude, radius, mcc, limit); } catch (Exception e) { //topoperators = null; topopfailed = true; } return topoperators; }
From source file:org.restcomm.app.utillib.Reporters.ReportManager.java
public JSONObject getTopCarriersStats(List<Carrier> operators, int months, double latitude, double longitude, float radius, int speedTier, boolean bReload) throws LibException { //WSManagerOld wsManager; //if (mmcService == null || mmcService.getWSManager() == null) // wsManager = new WSManagerOld(mContext); //else/* w w w .j a v a 2 s . co m*/ // wsManager = mmcService.getWSManager(); if (months == 0) months = 2;//(mContext.getResources().getInteger(R.integer.STATS_MONTHS)); int medianSamples = 0; String ops = ""; if (operators == null) { if (getCurrentCarrier() != null) ops = getCurrentCarrier().OperatorId; radius = 6000.0f; } else { medianSamples = operators.get(operators.size() / 2).Samples; ops = "0,"; for (int i = 0; i < operators.size(); i++) { if (operators.get(i) != null) { ops += operators.get(i).OperatorId; if (i < operators.size() - 1) ops += ","; } } int iMonths = 0; if (radius == 0f) { if (medianSamples < 500) radius = 12000.0f; else if (medianSamples < 10000) radius = 8000.0f; else if (medianSamples < 70000) radius = 5000.0f; else radius = 3000.0f; } } // see if top operators is cached if (topstats == null && !bReload) { SharedPreferences preferenceSettings = PreferenceKeys.getSecurePreferences(mContext); if (preferenceSettings.contains(PreferenceKeys.Miscellaneous.TOPSTATS_RESPONSE)) { try { String strTopStatsResponse = preferenceSettings .getString(PreferenceKeys.Miscellaneous.TOPSTATS_RESPONSE, ""); String strLat = preferenceSettings.getString(PreferenceKeys.Miscellaneous.TOPSTATS_LAT, ""); String strLng = preferenceSettings.getString(PreferenceKeys.Miscellaneous.TOPSTATS_LNG, ""); if (strTopStatsResponse != null && strTopStatsResponse.length() > 10 && strLat != null && strLat.length() > 0 && strLng.length() > 0) { double lat = Double.parseDouble(strLat); double lng = Double.parseDouble(strLng); if ((Math.abs(latitude - lat) < 0.01 && Math.abs(longitude - lng) < 0.01)) { topstats = new JSONObject(strTopStatsResponse); if (bReload == false) { try { topstats.put("radius", String.valueOf(radius)); } catch (JSONException e) { } return topstats; } } } } catch (Exception e) { LoggerUtil.logToFile(LoggerUtil.Level.ERROR, TAG, "loadEventsQueue", "Exception loading events from storage", e); } } } if (bReload) try { topstats = mWebReporter.getAreaStats(latitude, longitude, (int) radius, months, ops); if (topstats != null) adjustStatsForSpeedTier(topstats, speedTier); } catch (Exception e) { //topoperators = null; topstatfailed = true; } if (topstats != null) try { topstats.put("radius", String.valueOf(radius)); } catch (JSONException e) { } //topstats = wsManager.getTopCarriersStats(operators, months, latitude, longitude, 0, speedTier); return topstats; }
From source file:com.example.haizhu.myvoiceassistant.ui.RobotChatActivity.java
public void bindParams(Intent intent) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); 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); if (sp.contains(Constant.EXTRA_INFILE)) { String tmp = sp.getString(Constant.EXTRA_INFILE, "").replaceAll(",.*", "").trim(); intent.putExtra(Constant.EXTRA_INFILE, tmp); }//from w ww.j ava 2s . c o m 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)); } } intent.putExtra("grammar", "asset:///baidu_speech_grammar.bsg"); 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); } } intent.putExtra(Constant.EXTRA_NLU, "enable"); 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.xorcode.andtweet.PreferencesActivity.java
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (PreferencesActivity.this.mCredentialsAreBeingVerified) { return;/*from w ww .ja va2 s . c om*/ } if (onSharedPreferenceChanged_busy) { return; } onSharedPreferenceChanged_busy = true; try { String value = "(not set)"; if (sharedPreferences.contains(key)) { try { value = sharedPreferences.getString(key, ""); } catch (ClassCastException e) { value = "(not string)"; } } MyLog.d(TAG, "onSharedPreferenceChanged: " + key + "='" + value + "'"); // Remember when last changes were made sharedPreferences.edit() .putLong(MyPreferences.KEY_PREFERENCES_CHANGE_TIME, java.lang.System.currentTimeMillis()) .commit(); TwitterUser tu = TwitterUser.getTwitterUser(); String usernameNew = sharedPreferences.getString(MyPreferences.KEY_TWITTER_USERNAME_NEW, ""); if (key.equals(MyPreferences.KEY_OAUTH)) { // Here and below: // Check if there are changes to avoid "ripples" if (tu.isOAuth() != mOAuth.isChecked()) { tu = TwitterUser.getAddEditTwitterUser(usernameNew); tu.setCurrentUser(); showUserPreferences(tu); } } if (key.equals(MyPreferences.KEY_TWITTER_USERNAME_NEW)) { String usernameOld = sharedPreferences.getString(MyPreferences.KEY_TWITTER_USERNAME, ""); if (usernameNew.compareTo(usernameOld) != 0) { // Try to find existing TwitterUser by the new Username // without clearing Auth information tu = TwitterUser.getTwitterUser(usernameNew); tu.setCurrentUser(); showUserPreferences(tu); } } if (key.equals(MyPreferences.KEY_TWITTER_PASSWORD)) { if (tu.getPassword().compareTo(mEditTextPassword.getText()) != 0) { tu = TwitterUser.getAddEditTwitterUser(usernameNew); tu.setCurrentUser(); showUserPreferences(tu); } } if (key.equals(MyPreferences.KEY_FETCH_FREQUENCY)) { showFrequency(); } if (key.equals(MyPreferences.KEY_RINGTONE_PREFERENCE)) { // TODO: Try to move it here from onPreferenceChange... // updateRingtone(); } if (key.equals(MyPreferences.KEY_HISTORY_SIZE)) { showHistorySize(); } if (key.equals(MyPreferences.KEY_HISTORY_TIME)) { showHistoryTime(); } if (key.equals(MyPreferences.KEY_MIN_LOG_LEVEL)) { showMinLogLevel(); } } finally { onSharedPreferenceChanged_busy = false; } }
From source file:org.telegraph.ui.Components.EmojiView.java
public void loadRecents() { String str;//from w w w .j a v a 2s .c om SharedPreferences preferences = getContext().getSharedPreferences("emoji", Activity.MODE_PRIVATE); if (preferences.contains("recents")) { try { str = preferences.getString("recents", ""); if (str != null && str.length() > 0) { String[] args = str.split(","); for (int i = 0; i < args.length; i++) { emojiUseHistory.put(Long.parseLong(args[i]), args.length - i); } } } catch (Exception e) { FileLog.e("tmessages", e); } sortEmoji(); preferences.edit().remove("recents").commit(); saveRecentEmoji(); adapters.get(0).notifyDataSetChanged(); } else { try { emojiUseHistory.clear(); str = preferences.getString("emojis", ""); if (str != null && str.length() > 0) { String[] args = str.split(","); for (String arg : args) { String[] args2 = arg.split("="); emojiUseHistory.put(Long.parseLong(args2[0]), Integer.parseInt(args2[1])); } } if (emojiUseHistory.isEmpty()) { long[] newRecent = new long[] { 0x00000000D83DDE02L, 0x00000000D83DDE18L, 0x0000000000002764L, 0x00000000D83DDE0DL, 0x00000000D83DDE0AL, 0x00000000D83DDE01L, 0x00000000D83DDC4DL, 0x000000000000263AL, 0x00000000D83DDE14L, 0x00000000D83DDE04L, 0x00000000D83DDE2DL, 0x00000000D83DDC8BL, 0x00000000D83DDE12L, 0x00000000D83DDE33L, 0x00000000D83DDE1CL, 0x00000000D83DDE48L, 0x00000000D83DDE09L, 0x00000000D83DDE03L, 0x00000000D83DDE22L, 0x00000000D83DDE1DL, 0x00000000D83DDE31L, 0x00000000D83DDE21L, 0x00000000D83DDE0FL, 0x00000000D83DDE1EL, 0x00000000D83DDE05L, 0x00000000D83DDE1AL, 0x00000000D83DDE4AL, 0x00000000D83DDE0CL, 0x00000000D83DDE00L, 0x00000000D83DDE0BL, 0x00000000D83DDE06L, 0x00000000D83DDC4CL, 0x00000000D83DDE10L, 0x00000000D83DDE15L }; for (int i = 0; i < newRecent.length; i++) { emojiUseHistory.put(newRecent[i], newRecent.length - i); } saveRecentEmoji(); } sortEmoji(); adapters.get(0).notifyDataSetChanged(); } catch (Exception e) { FileLog.e("tmessages", e); } } if (showStickers) { try { stickersUseHistory.clear(); str = preferences.getString("stickers", ""); if (str != null && str.length() > 0) { String[] args = str.split(","); for (String arg : args) { String[] args2 = arg.split("="); stickersUseHistory.put(Long.parseLong(args2[0]), Integer.parseInt(args2[1])); } } stickerSetsUseCount.clear(); str = preferences.getString("sets", ""); if (str != null && str.length() > 0) { String[] args = str.split(","); for (String arg : args) { String[] args2 = arg.split("="); stickerSetsUseCount.put(Long.parseLong(args2[0]), Integer.parseInt(args2[1])); } } sortStickers(); updateStickerTabs(); } catch (Exception e) { FileLog.e("tmessages", e); } } }