List of usage examples for android.content SharedPreferences getStringSet
@Nullable Set<String> getStringSet(String key, @Nullable Set<String> defValues);
From source file:csci4176.toptentoday.MainActivity.java
public void onNavItemSelected(MenuItem menuItem) { switch (menuItem.getGroupId()) { case R.id.pref_filter_group: String stringToStore = menuItem.getTitle().toString().toLowerCase(); SharedPreferences prefs = this.getSharedPreferences("prefs", Context.MODE_PRIVATE); SharedPreferences.Editor edit = prefs.edit(); Set<String> filterSet = prefs.getStringSet("filter-list", new HashSet<String>(Arrays.asList("all-sections"))); filterSet.add(stringToStore);/*www. j av a2 s . com*/ if (menuItem.getItemId() == R.id.pref_filter_all) { filterSet = new HashSet<String>(Arrays.asList("all-sections")); } edit.putStringSet("filter-list", filterSet); edit.commit(); adapter.getArticles().refresh(); return; default: } switch (menuItem.getItemId()) { case R.id.nav_licenses: Intent intent = new Intent(this, Licenses.class); startActivity(intent); break; } mDrawer.closeDrawers(); }
From source file:org.omni.roadrunner.PowerProfileFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_new_profile: SharedPreferences sp = getActivity().getSharedPreferences(Constants.KEY_POWER_PROFILE_SETTINGS, 0); // Find a free profile ID int newProfileId = 0; Set<String> profiles = new HashSet<String>(sp.getStringSet(KEY_PROFILE_IDS, new HashSet<String>())); SharedPreferences.Editor editor = sp.edit(); while (profiles.contains(Integer.toString(newProfileId))) { newProfileId++;/*from w w w . j a va2s.c o m*/ } profiles.add(Integer.toString(newProfileId)); editor.putStringSet(KEY_PROFILE_IDS, profiles); editor.commit(); // Open our setup activity with our new profile ID Intent intent = new Intent(getActivity(), ProfileSetupActivity.class); intent.putExtra(ProfileSetupActivity.EXTRA_PROFILE_ID, newProfileId); startActivity(intent); return true; } return false; }
From source file:fr.s13d.photobackup.media.PBMediaStore.java
private boolean isBucketSelected(final String requestedBucketId) { Log.d(LOG_TAG, "Checking if bucket " + requestedBucketId + " is selected by user."); final SharedPreferences prefs = getDefaultSharedPreferences(PBApplication.getApp()); final Set<String> bucketSet = prefs.getStringSet(PBConstants.PREF_PICTURE_FOLDER_LIST, null); return bucketSet != null && bucketSet.contains(requestedBucketId); }
From source file:org.wso2.carbon.iot.android.sense.event.streams.speed.SpeedDataReader.java
public SpeedDataReader(Context context) { ctx = context;/* w w w . jav a2 s. c o m*/ SharedPreferences sharedPreferences = ctx.getSharedPreferences(SupportedSensors.SELECTED_SENSORS, Context.MODE_MULTI_PROCESS); Set<String> selectedSet = sharedPreferences.getStringSet(SupportedSensors.SELECTED_SENSORS_BY_USER, null); mSensorManager = (SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE); selectedSensorList(selectedSet); for (Sensor sensor : sensorList) { mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL); } LocalBroadcastManager.getInstance(ctx).registerReceiver(mMessageReceiver, new IntentFilter("speedUpdate")); }
From source file:com.QuarkLabs.BTCeClient.services.CheckTickersService.java
@Override protected void onHandleIntent(Intent intent) { SharedPreferences sh = PreferenceManager.getDefaultSharedPreferences(this); Set<String> x = sh.getStringSet("PairsToDisplay", new HashSet<String>()); if (x.size() == 0) { return;/*from www . j av a2 s.co m*/ } String[] pairs = x.toArray(new String[x.size()]); ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); String url = BASE_URL; for (String xx : pairs) { url += xx.replace("/", "_").toLowerCase(Locale.US) + "-"; } SimpleRequest reqSim = new SimpleRequest(); if (networkInfo != null && networkInfo.isConnected()) { JSONObject data = null; try { data = reqSim.makeRequest(url); } catch (JSONException e) { e.printStackTrace(); } if (data != null && data.optInt("success", 1) != 0) { ArrayList<Ticker> tickers = new ArrayList<>(); for (@SuppressWarnings("unchecked") Iterator<String> iterator = data.keys(); iterator.hasNext();) { String key = iterator.next(); JSONObject pairData = data.optJSONObject(key); Ticker ticker = new Ticker(key); ticker.setUpdated(pairData.optLong("updated")); ticker.setAvg(pairData.optDouble("avg")); ticker.setBuy(pairData.optDouble("buy")); ticker.setSell(pairData.optDouble("sell")); ticker.setHigh(pairData.optDouble("high")); ticker.setLast(pairData.optDouble("last")); ticker.setLow(pairData.optDouble("low")); ticker.setVol(pairData.optDouble("vol")); ticker.setVolCur(pairData.optDouble("vol_cur")); tickers.add(ticker); } String message = checkNotifiers(tickers, TickersStorage.loadLatestData()); if (message.length() != 0) { NotificationManager notificationManager = (NotificationManager) getSystemService( NOTIFICATION_SERVICE); NotificationCompat.Builder nb = new NotificationCompat.Builder(this) .setContentTitle(getResources().getString(R.string.app_name)) .setSmallIcon(R.drawable.ic_stat_bitcoin_sign) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .setContentText(message.substring(0, message.length() - 2)); notificationManager.notify(ConstantHolder.ALARM_NOTIF_ID, nb.build()); } Map<String, Ticker> newData = new HashMap<>(); for (Ticker ticker : tickers) { newData.put(ticker.getPair(), ticker); } TickersStorage.saveData(newData); LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent("UpdateTickers")); } } else { new Handler().post(new Runnable() { @Override public void run() { //Toast.makeText(CheckTickersService.this, "Unable to fetch data", Toast.LENGTH_SHORT).show(); } }); } }
From source file:com.example.volunteerhandbook.GcmIntentService.java
int saveData(String tblName, String fixLine) { String fileName = "notification" + tblName; int iPending = 0; Set<String> nullSet = null; synchronized (fileLock) { SharedPreferences sharedPref = getSharedPreferences(fileName, Context.MODE_PRIVATE); Set<String> pendingData = sharedPref.getStringSet("notification", nullSet); if (pendingData == null) pendingData = new HashSet<String>(); pendingData.add(fixLine);/* w w w . j a va2 s .c om*/ SharedPreferences.Editor adder = sharedPref.edit(); adder.putStringSet("notification", pendingData); adder.commit(); iPending = pendingData.size(); } return iPending; }
From source file:fr.s13d.photobackup.media.PBMediaStore.java
Cursor getAllMediasCursor() { String where = null;//from w ww .j av a2 s . c o m final SharedPreferences prefs = getDefaultSharedPreferences(PBApplication.getApp()); final Set<String> bucketIds = prefs.getStringSet(PBConstants.PREF_PICTURE_FOLDER_LIST, null); if (bucketIds != null && !bucketIds.isEmpty()) { final String bucketString = TextUtils.join(", ", bucketIds); where = "bucket_id in (" + bucketString + ")"; } final boolean backupVideos = prefs.getBoolean(PBConstants.PREF_MEDIA_BACKUP_VIDEO, false); final String[] projection = new String[] { "_id", "_data", "date_added" }; final ContentResolver cr = PBApplication.getApp().getContentResolver(); final Cursor[] cursors = new Cursor[backupVideos ? 2 : 1]; cursors[0] = cr.query(imagesUri, projection, where, null, DATE_ADDED_DESC); if (backupVideos) { cursors[1] = cr.query(videosUri, projection, where, null, DATE_ADDED_DESC); } if (cursors[0] == null) { Log.d(LOG_TAG, "Media cursor is null."); return null; } return new MergeCursor(cursors); }
From source file:com.piusvelte.taplock.client.core.TapLockToggle.java
@Override protected void onResume() { super.onResume(); mProgressDialog = new ProgressDialog(this); mProgressDialog.setTitle(R.string.title_toggle); mProgressDialog.setMessage(mProgressMessage); mProgressDialog.setCancelable(true); mProgressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override/*w w w. j a v a2s. com*/ public void onCancel(DialogInterface dialog) { finish(); } }); mProgressDialog.setButton(getString(R.string.close), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (mServiceInterface != null) { try { mServiceInterface.cancelRequest(); } catch (RemoteException e) { Log.e(TAG, e.toString()); } } dialog.cancel(); } }); mProgressDialog.show(); mDevices.clear(); final SharedPreferences sp = getSharedPreferences(KEY_PREFS, MODE_PRIVATE); Set<String> devices = sp.getStringSet(KEY_DEVICES, null); if (devices != null) { for (String device : devices) { try { mDevices.add(new JSONObject(device)); } catch (JSONException e) { Log.e(TAG, e.toString()); } } } // start the service before binding so that the service stays around for faster future connections startService(TapLock.getPackageIntent(this, TapLockService.class)); bindService(TapLock.getPackageIntent(this, TapLockService.class), this, BIND_AUTO_CREATE); }
From source file:dude.morrildl.weatherport.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // We store the list of airports the user has expressed interest in in // SharedPrefs, as a list (well, Set) of Strings SharedPreferences prefs = getSharedPreferences("prefs", Context.MODE_PRIVATE); Set<String> currentSet = prefs.getStringSet("airports", null); if (currentSet == null || currentSet.size() < 1) { // i.e. first run -- hard-default KSFO to the list HashSet<String> defaultSet = new HashSet<String>(); defaultSet.add("KSFO"); prefs.edit().putStringSet("airports", defaultSet).commit(); currentSet = defaultSet;/*from www . ja v a2 s. c o m*/ } // enable the nav spinner, which we'll use to pick which airport to look // at ActionBar bar = getActionBar(); bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE); bar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); ArrayList<String> currentList = new ArrayList<String>(); currentList.addAll(currentSet); Collections.sort(currentList); adapter = new ArrayAdapter<CharSequence>(bar.getThemedContext(), android.R.layout.simple_spinner_dropdown_item); adapter.addAll(currentList); bar.setListNavigationCallbacks(adapter, new OnNavigationListener() { @Override public boolean onNavigationItemSelected(int arg0, long arg1) { // this re-ups the data whenever the user changes the current // airport startAsyncFetch(adapter.getItem(arg0).toString()); return true; } }); // Let's set up a fancy new v2 MapView, for the lulz mapFragment = new SupportMapFragment(); pagerAdapter = new TwoFragmentPagerAdapter(this, getSupportFragmentManager(), new DetailsFragment(), mapFragment); viewPager = (ViewPager) findViewById(R.id.pager); viewPager.setAdapter(pagerAdapter); viewPager.setOnPageChangeListener(this); // No placemarker on the map because I've always secretly hated that // glyph }
From source file:dude.morrildl.weatherport.MainActivity.java
@Override protected void onResume() { super.onResume(); SharedPreferences prefs = getSharedPreferences("prefs", Context.MODE_PRIVATE); ArrayList<String> airports = new ArrayList<String>(); airports.addAll(prefs.getStringSet("airports", null)); Collections.sort(airports);/*w w w.ja va 2 s . c o m*/ // So, we hit the network every time the screen reloads. This is all // kinds of evil, or rather would be in a real app; but this app is so // small and the JSON serves so far it's not a big deal. And at least // we're not doing it on the UI thread. startAsyncFetch(airports.get(0)); }