List of usage examples for android.content SharedPreferences getStringSet
@Nullable Set<String> getStringSet(String key, @Nullable Set<String> defValues);
From source file:com.rong.xposed.headsoff.PerAppWhiteList.java
@SuppressLint("WorldReadableFiles") @SuppressWarnings("deprecation") private List<String> getWhiteList(String pkg) { SharedPreferences prefs = getSharedPreferences(SettingValues.PREF_FILE, Context.MODE_WORLD_READABLE); String key = pkg + SettingValues.KEY_SUFFIX_WHITELIST_COUNT; int count = prefs.getInt(key, SettingValues.DEFAULT_WHITELIST_COUNT); if (count == 0) { return new ArrayList<>(); }// w w w . j a v a2 s.c om key = pkg + SettingValues.KEY_SUFFIX_WHITELIST; Set<String> set = prefs.getStringSet(key, null); if (set == null) return new ArrayList<>(); return new ArrayList<>(set); }
From source file:com.vonglasow.michael.satstat.GpsEventReceiver.java
@Override public void onReceive(Context context, Intent intent) { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context); // some logic to use the pre-1.7 setting KEY_PREF_UPDATE_WIFI as a // fallback if KEY_PREF_UPDATE_NETWORKS is not set Set<String> fallbackUpdateNetworks = new HashSet<String>(); if (sharedPref.getBoolean(Const.KEY_PREF_UPDATE_WIFI, false)) { fallbackUpdateNetworks.add(Const.KEY_PREF_UPDATE_NETWORKS_WIFI); }/*from w w w . ja va 2s . c o m*/ Set<String> updateNetworks = sharedPref.getStringSet(Const.KEY_PREF_UPDATE_NETWORKS, fallbackUpdateNetworks); if (intent.getAction().equals(Const.GPS_ENABLED_CHANGE) || intent.getAction().equals(Const.GPS_ENABLED_CHANGE)) { //FIXME: why are we checking for the same intent twice? Should on of them be GPS_FIX_CHANGE? // an application has connected to GPS or disconnected from it, check if notification needs updating boolean notifyFix = sharedPref.getBoolean(Const.KEY_PREF_NOTIFY_FIX, false); boolean notifySearch = sharedPref.getBoolean(Const.KEY_PREF_NOTIFY_SEARCH, false); if (notifyFix || notifySearch) { boolean isRunning = false; ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if (PasvLocListenerService.class.getName().equals(service.service.getClassName())) { isRunning = true; } } if (!isRunning) { Intent startServiceIntent = new Intent(context, PasvLocListenerService.class); startServiceIntent.setAction(intent.getAction()); startServiceIntent.putExtras(intent.getExtras()); context.startService(startServiceIntent); } } } else if (intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION) && updateNetworks.contains(Const.KEY_PREF_UPDATE_NETWORKS_WIFI)) { // change in WiFi connectivity, check if we are connected and need to refresh AGPS //FIXME: KEY_PREF_UPDATE_WIFI as fallback only NetworkInfo netinfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO); if (netinfo == null) return; if (!netinfo.isConnected()) return; //Toast.makeText(context, "WiFi is connected", Toast.LENGTH_SHORT).show(); Log.i(this.getClass().getSimpleName(), "WiFi is connected"); refreshAgps(context, true, false); } else if ((intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) || (intent.getAction().equals(Const.AGPS_DATA_EXPIRED))) { // change in network connectivity or AGPS expiration timer fired boolean isAgpsExpired = false; if (intent.getAction().equals(Const.AGPS_DATA_EXPIRED)) { Log.i(this.getClass().getSimpleName(), "AGPS data expired, checking available networks"); isAgpsExpired = true; } NetworkInfo netinfo = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE)) .getActiveNetworkInfo(); if (netinfo == null) return; if (!netinfo.isConnected()) return; String type; if ((netinfo.getType() < ConnectivityManager.TYPE_MOBILE_MMS) || (netinfo.getType() > ConnectivityManager.TYPE_MOBILE_HIPRI)) { type = Integer.toString(netinfo.getType()); } else { // specific mobile data connections will be treated as TYPE_MOBILE type = Const.KEY_PREF_UPDATE_NETWORKS_MOBILE; } if (!updateNetworks.contains(type)) return; if (!isAgpsExpired) Log.i(this.getClass().getSimpleName(), "Network of type " + netinfo.getTypeName() + " is connected"); // Enforce the update interval if we were called by a network event // but not if we were called by a timer, because in that case the // check has already been done. (I am somewhat paranoid and don't // count on alarms not going off a few milliseconds too early.) refreshAgps(context, !isAgpsExpired, false); } }
From source file:de.alosdev.android.customerschoice.CustomersChoice.java
public void setLifeTime(Context context, LifeTime lifeTime) { final SharedPreferences preferences = getPreferences(context); final Set<String> foundVariants; switch (lifeTime) { case Session: { Editor editor = preferences.edit(); foundVariants = preferences.getStringSet(getPreferencesKey(FIELD_VARIANTS, ""), null); if ((null != foundVariants) && !foundVariants.isEmpty()) { for (String variantName : foundVariants) { editor.remove(getPreferencesKey(FIELD_VARIANTS, variantName)); }//from w ww.ja v a 2s . co m editor.remove(getPreferencesKey(FIELD_VARIANTS, "")); editor.commit(); } log.d(TAG, "cleared persisted Variant"); break; } case Persistent: { foundVariants = preferences.getStringSet(getPreferencesKey(FIELD_VARIANTS, ""), null); if ((null != foundVariants) && !foundVariants.isEmpty()) { for (String variantName : foundVariants) { forceVariant(context, variantName, preferences.getInt(getPreferencesKey(FIELD_VARIANTS, variantName), 0)); } } log.d(TAG, "read persisted Variant"); break; } default: { throw new IllegalArgumentException("Unknown LifeTime: " + lifeTime); } } this.lifeTime = lifeTime; }
From source file:com.anysoftkeyboard.keyboards.KeyboardSwitcher.java
@RequiresApi(Build.VERSION_CODES.HONEYCOMB) private void loadKeyboardAppMapping() { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext); Set<String> mapping = sharedPreferences.getStringSet( mContext.getString(R.string.settings_key_persistent_layout_per_package_id_mapping), Collections.<String>emptySet()); for (String aMapping : mapping) { String[] mapPair = aMapping.split(PACKAGE_ID_TO_KEYBOARD_ID_TOKEN); if (mapPair.length == 2) { mAlphabetKeyboardIndexByPackageId.put(mapPair[0], mapPair[1]); }/* w ww .j a v a 2 s .c om*/ } }
From source file:net.sf.sprockets.app.ui.SprocketsPreferenceFragment.java
/** * Set the preference's value(s) as its summary. *//*from w w w . j av a 2s . c o m*/ protected void setSummary(Preference pref) { SharedPreferences prefs = getPreferenceManager().getSharedPreferences(); if (pref instanceof RingtonePreference) { String val = prefs.getString(pref.getKey(), null); if (!TextUtils.isEmpty(val)) { Ringtone tone = RingtoneManager.getRingtone(a, Uri.parse(val)); if (tone != null) { pref.setSummary(tone.getTitle(a)); } } else { pref.setSummary(R.string.none); } } else if (pref instanceof MultiSelectListPreference) { Set<String> vals = prefs.getStringSet(pref.getKey(), null); if (vals != null) { if (!vals.isEmpty()) { MultiSelectListPreference multi = (MultiSelectListPreference) pref; IntList indexList = new ArrayIntList(vals.size()); for (String val : vals) { // find selected entry indexes int i = multi.findIndexOfValue(val); if (i >= 0) { indexList.add(i); } } int[] indexes = indexList.toArray(); Arrays.sort(indexes); // to display in same order as dialog pref.setSummary(TextUtils.join(getString(R.string.delimiter), Elements.slice(multi.getEntries(), indexes))); } else { pref.setSummary(R.string.none); } } } else if (pref instanceof EditTextPreference) { pref.setSummary(prefs.getString(pref.getKey(), null)); } else if (pref.getClass() == Preference.class) { String val = prefs.getString(pref.getKey(), null); if (!TextUtils.isEmpty(val)) { // don't clear existing summary pref.setSummary(val); } } }
From source file:com.piusvelte.taplock.client.core.TapLockService.java
@Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (key.equals(KEY_DEVICES)) { mDevices.clear();/*from w w w . j a v a2s. c o m*/ Set<String> devices = sharedPreferences.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()); } } } } }
From source file:com.example.alyshia.customsimplelauncher.MainActivity.java
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) { super.onActivityResult(requestCode, resultCode, imageReturnedIntent); switch (requestCode) { case REQ_CODE_PICK_IMAGE: if (resultCode == RESULT_OK) { if (imageReturnedIntent != null) { System.out.println("path " + Uri.parse(filePath)); Bitmap selectedImage = BitmapFactory.decodeFile(filePath); screen.setBackground(new BitmapDrawable(selectedImage)); //if (tempFile.exists()) tempFile.delete(); }/*from ww w.ja v a 2s . co m*/ } else { if (f.exists()) f.delete(); } } //enable back gallery if needed SharedPreferences knoxPref = getSharedPreferences(KnoxConstants.PREFS_KNOX, MODE_PRIVATE); Set<String> blacklist = knoxPref.getStringSet(KnoxConstants.BList, null); if (blacklist != null) { if (blacklist.contains(gallery)) { if (edm == null) { edm = (EnterpriseDeviceManager) getSystemService( EnterpriseDeviceManager.ENTERPRISE_POLICY_SERVICE); } ApplicationPolicy appPolicy = edm.getApplicationPolicy(); appPolicy.addPackagesToPreventStartBlackList(gallery); } } }
From source file:com.piusvelte.taplock.client.core.TapLockSettings.java
@Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (key.equals(KEY_DEVICES)) { mDevices.clear();/* w w w.j a va2 s. c om*/ Set<String> devices = sharedPreferences.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()); } } } String[] deviceNames = TapLock.getDeviceNames(mDevices); setListAdapter(new ArrayAdapter<String>(TapLockSettings.this, android.R.layout.simple_list_item_1, deviceNames)); } }
From source file:com.google.fpl.voltair.VoltAirActivity.java
/** * @brief Called after onCreate() or @c onRestart() when the activity is being displayed to the * user./*w w w . ja va2 s. com*/ * @note This may automatically kick off a GPGS sign-in flow. See * GooglePlayServicesHelper#onStart for more information. */ @Override public void onStart() { super.onStart(); mInputManager.registerInputDeviceListener(this, null); // Restore preferences. SharedPreferences settings = getSharedPreferences(VOLTAIR_PREFS, Context.MODE_PRIVATE); mRevealedAchievements = new HashSet<String>( settings.getStringSet(REVEALED_ACHIEVEMENTS, new HashSet<String>())); mUnlockedAchievements = new HashSet<String>( settings.getStringSet(UNLOCKED_ACHIEVEMENTS, new HashSet<String>())); mSoundManager.onStart(this); onApplicationStart(); mPlayServicesHelper.onStart(this); }
From source file:org.lunci.dumbthing.account.LinkFacebook.java
@Override public void unlink() { if (BuildConfig.DEBUG) { Log.i(TAG, "unlinkFacebook"); }/*from w w w .jav a 2s. c o m*/ callUnlinkConfirmDialog(R.string.unlink_facebook_warning, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getActivity()); try { Session session = Session.getActiveSession(); if (session == null) { final String token = pref.getString(Keys.Preference_Facebook_AccessToken, ""); final long expire = pref.getLong(Keys.Preference_Facebook_AccessToken_Expire, 0); final Date expDate = new Date(); expDate.setTime(expire); final long lastRefresh = pref.getLong(Keys.Preference_Facebook_Last_Refresh_Date, 0); final Date lastDate = new Date(); lastDate.setTime(lastRefresh); final Set<String> permissions = pref.getStringSet(Keys.Preference_Facebook_Permissions, null); final List<String> permissionList = new ArrayList<>(); permissionList.addAll(permissions); // final Set<String> declinedPermissions=pref.getStringSet(Keys.Preference_Facebook_Declined_Permissions, null); final String source = pref.getString(Keys.Preference_Facebook_AccessToken_Source, ""); final AccessTokenSource tokenSource = AccessTokenSource.valueOf(source); final AccessToken accessToken = AccessToken.createFromExistingAccessToken(token, expDate, lastDate, tokenSource, permissionList); session = Session.openActiveSessionWithAccessToken(getActivity(), accessToken, null); } if (session != null) session.closeAndClearTokenInformation(); else { Log.w(TAG, "Unable to retrieve session"); } } catch (NullPointerException ex) { ex.printStackTrace(); } finally { final SharedPreferences.Editor editor = pref.edit(); editor.putBoolean(Keys.Preference_Facebook_Linked, false).commit(); mButtonContainer.updateLinked(false); } } }); }