Java Code Examples for android.content.SharedPreferences#getStringSet()
The following examples show how to use
android.content.SharedPreferences#getStringSet() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GlobalConfig.java From NewsPushMonitor with Apache License 2.0 | 6 votes |
public static String[] getMonitorApps() { if (mMonitorApps != null) { return mMonitorApps; } SharedPreferences sharedPref = getSharedPref(); Set<String> set = sharedPref.getStringSet(KEY_PREF_APPS_TO_MONITOR, null); if (set == null) { mMonitorApps = sDefaultMonitorApps; HashSet<String> apps = new HashSet<>(); for (String app : sDefaultMonitorApps) { apps.add(app); } putStringSet(sharedPref, KEY_PREF_APPS_TO_MONITOR, apps); } else { mMonitorApps = set.toArray(new String[set.size()]); } return mMonitorApps; }
Example 2
Source File: BeaconManager.java From PresencePublisher with MIT License | 6 votes |
public synchronized void removeBeacon(Context context, String beaconId) { Context applicationContext = context.getApplicationContext(); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(applicationContext); Set<String> storedBeacons = new HashSet<>(sharedPreferences.getStringSet(BEACON_LIST, Collections.emptySet())); storedBeacons.remove(beaconId); Set<String> foundBeacons = new HashSet<>(sharedPreferences.getStringSet(FOUND_BEACON_LIST, Collections.emptySet())); foundBeacons.remove(beaconId); sharedPreferences.edit() .putStringSet(BEACON_LIST, storedBeacons) .putStringSet(FOUND_BEACON_LIST, foundBeacons) .apply(); HyperLog.d(TAG, "Remove scanning for beacon " + beaconId); Region region = new Region(beaconId, BeaconIdHelper.toAddress(beaconId)); if (regionBootstrap != null) { if (storedBeacons.isEmpty()) { HyperLog.i(TAG, "Disable scanning for beacons"); regionBootstrap.disable(); regionBootstrap = null; } else { regionBootstrap.removeRegion(region); } } }
Example 3
Source File: RemotesFragment.java From rcloneExplorer with MIT License | 6 votes |
private void pinRemote(RemoteItem remoteItem) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences.Editor editor = sharedPreferences.edit(); Set<String> stringSet = sharedPreferences.getStringSet(getString(R.string.shared_preferences_pinned_remotes), new HashSet<String>()); Set<String> pinnedRemotes = new HashSet<>(stringSet); // bug in android means that we have to create a copy pinnedRemotes.add(remoteItem.getName()); remoteItem.pin(true); editor.putStringSet(getString(R.string.shared_preferences_pinned_remotes), pinnedRemotes); editor.apply(); int from = remotes.indexOf(remoteItem); Collections.sort(remotes); int to = remotes.indexOf(remoteItem); recyclerViewAdapter.moveDataItem(remotes, from, to); }
Example 4
Source File: TransactionManager.java From fingen with Apache License 2.0 | 6 votes |
public static boolean isValidToSmsAutocreate(Transaction transaction, Context context) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); Set<String> defValues = new HashSet<>(Arrays.asList(context.getResources().getStringArray(R.array.pref_autocreate_prerequisites_values))); Set<String> set = preferences.getStringSet("autocreate_prerequisites", defValues); boolean result = true; if (set.contains("account")) { result = transaction.getAccountID() > 0; } if (set.contains("amount")) { result = result & transaction.getAmount().compareTo(BigDecimal.ZERO) != 0; } if (set.contains("payee") & transaction.getTransactionType() != Transaction.TRANSACTION_TYPE_TRANSFER) { result = result & transaction.getPayeeID() > 0; } if (set.contains("category") & transaction.getTransactionType() != Transaction.TRANSACTION_TYPE_TRANSFER) { result = result & transaction.getCategoryID() > 0; } if (transaction.getTransactionType() == Transaction.TRANSACTION_TYPE_TRANSFER) { result = result & transaction.getDestAccountID() > 0; } return result; }
Example 5
Source File: VoIPHelper.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
public static void showRateAlert(Context context, TLRPC.TL_messageActionPhoneCall call){ SharedPreferences prefs=MessagesController.getNotificationsSettings(UserConfig.selectedAccount); // always called from chat UI Set<String> hashes=prefs.getStringSet("calls_access_hashes", (Set<String>)Collections.EMPTY_SET); for(String hash:hashes){ String[] d=hash.split(" "); if(d.length<2) continue; if(d[0].equals(call.call_id+"")){ try{ long accessHash=Long.parseLong(d[1]); showRateAlert(context, null, call.call_id, accessHash, UserConfig.selectedAccount); }catch(Exception x){} return; } } }
Example 6
Source File: RemotesFragment.java From rcloneExplorer with MIT License | 6 votes |
private void unpinFromDrawer(RemoteItem remoteItem) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences.Editor editor = sharedPreferences.edit(); Set<String> stringSet = sharedPreferences.getStringSet(getString(R.string.shared_preferences_drawer_pinned_remotes), new HashSet<String>()); Set<String> pinnedRemotes = new HashSet<>(stringSet); if (pinnedRemotes.contains(remoteItem.getName())) { pinnedRemotes.remove(remoteItem.getName()); } remoteItem.setDrawerPinned(false); editor.putStringSet(getString(R.string.shared_preferences_drawer_pinned_remotes), pinnedRemotes); editor.apply(); pinToDrawerListener.removeRemoteFromNavDrawer(); }
Example 7
Source File: SPUtil.java From FastLib with Apache License 2.0 | 6 votes |
/** * 获取存放object * * @param context * @param fileName * @param key * @param def * @return */ public static Object get(Context context, String fileName, String key, Object def) { SharedPreferences sp = context.getSharedPreferences(fileName, Context.MODE_PRIVATE); if (def instanceof String) { return sp.getString(key, def.toString()); } else if (def instanceof Integer) { return sp.getInt(key, ((Integer) def).intValue()); } else if (def instanceof Boolean) { return sp.getBoolean(key, ((Boolean) def).booleanValue()); } else if (def instanceof Float) { return sp.getFloat(key, ((Float) def).floatValue()); } else if (def instanceof Long) { return sp.getLong(key, ((Long) def).longValue()); } else if (def instanceof Set) { return sp.getStringSet(key, (Set<String>) def); } return def; }
Example 8
Source File: InstallShortcutReceiver.java From LaunchEnr with GNU General Public License v3.0 | 6 votes |
private static ArrayList<PendingInstallShortcutInfo> getAndClearInstallQueue(Context context) { SharedPreferences sharedPrefs = Utilities.getPrefs(context); synchronized(sLock) { ArrayList<PendingInstallShortcutInfo> infos = new ArrayList<>(); Set<String> strings = sharedPrefs.getStringSet(APPS_PENDING_INSTALL, null); if (strings == null) { return infos; } for (String encoded : strings) { PendingInstallShortcutInfo info = decode(encoded, context); if (info != null) { infos.add(info); } } sharedPrefs.edit().putStringSet(APPS_PENDING_INSTALL, new HashSet<String>()).apply(); return infos; } }
Example 9
Source File: BeaconManager.java From PresencePublisher with MIT License | 5 votes |
private List<Region> getConfiguredScanRegions(SharedPreferences sharedPreferences) { Set<String> beaconList = sharedPreferences.getStringSet(BEACON_LIST, Collections.emptySet()); List<Region> scanRegions = new ArrayList<>(beaconList.size()); for (String beaconId : beaconList) { String address = BeaconIdHelper.toAddress(beaconId); HyperLog.d(TAG, "Registering scan region for beacon " + beaconId); scanRegions.add(new Region(beaconId, address)); } return scanRegions; }
Example 10
Source File: MyGradeFragment.java From PKUCourses with GNU General Public License v3.0 | 5 votes |
private void updateAdapter(String rootNodeStr, boolean showAnimation) { Node rootNode = Utils.stringToNode(rootNodeStr); if (rootNode != null) { FragmentActivity fa = getActivity(); if (fa == null) { return; } SharedPreferences sharedPreferences = fa.getSharedPreferences("pinnedCourseList", Context.MODE_PRIVATE); Set<String> hset = sharedPreferences.getStringSet("key", null); if (hset == null) hset = new HashSet<>(); ArrayList<CourseInfo> courses_list = new ArrayList<>(); NodeList nCoursesList = rootNode.getFirstChild().getChildNodes(); for (int temp = 0; temp < nCoursesList.getLength(); temp++) { CourseInfo ci = new CourseInfo((Element) nCoursesList.item(temp)); if (hset.contains(ci.getRawCourseName())) ci.setPinned(1); courses_list.add(ci); } adapter.updateList(courses_list); // 显示课程列表的fancy的动画 if (showAnimation) mRecyclerView.scheduleLayoutAnimation(); if (showLongPressHintFlag) showLongPressHint(); } }
Example 11
Source File: Config.java From V2EX with GNU General Public License v3.0 | 5 votes |
private static void loadConfig(@NonNull Context context){ SharedPreferences preferences = context.getSharedPreferences( (String) Config.getConfig(ConfigRefEnum.CONFIG_PREFERENCE_SETTING_FILE), Context.MODE_PRIVATE); Map<String, ?> pref = preferences.getAll(); for (ConfigRefEnum refEnum:ConfigRefEnum.values()){ String key = refEnum.getKey(); CONFIG.put(refEnum, pref.get(key) != null ? (Serializable) pref.get(key) : refEnum.getDefaultValue()); } Set<String> homeTabs = preferences.getStringSet( ConfigRefEnum.CONFIG_HOME_TAB.getKey(), null); if (homeTabs == null){ CONFIG.put(ConfigRefEnum.CONFIG_HOME_TAB, HOME_TAB_DEFAULT); return; } ArrayList<Tab> tabEnums = new ArrayList<>(); for (String tab:homeTabs){ Tab tab1 = new Gson().fromJson(tab, Tab.class); tabEnums.add(tab1); } Collections.sort(tabEnums); CONFIG.put(ConfigRefEnum.CONFIG_HOME_TAB, tabEnums); mConfig.fontScale = mConfig.fontScale * Float.valueOf(Config.getConfig(ConfigRefEnum.CONFIG_FONT_SCALE)); mConfig.densityDpi = (int) (mConfig.densityDpi * Float.valueOf(Config.getConfig(ConfigRefEnum.CONFIG_UI_SCALE))); }
Example 12
Source File: CourseListFragment.java From PKUCourses with GNU General Public License v3.0 | 5 votes |
private void updateAdapter(String rootNodeStr, boolean showAnimation) { Node rootNode = Utils.stringToNode(rootNodeStr); if (rootNode != null) { FragmentActivity fa = getActivity(); if (fa == null) { return; } SharedPreferences sharedPreferences = fa.getSharedPreferences("pinnedCourseList", Context.MODE_PRIVATE); Set<String> hset = sharedPreferences.getStringSet("key", null); if (hset == null) hset = new HashSet<>(); ArrayList<CourseInfo> courses_list = new ArrayList<>(); NodeList nCoursesList = rootNode.getFirstChild().getChildNodes(); for (int temp = 0; temp < nCoursesList.getLength(); temp++) { CourseInfo ci = new CourseInfo((Element) nCoursesList.item(temp)); if (hset.contains(ci.getRawCourseName())) ci.setPinned(1); courses_list.add(ci); } adapter.updateList(courses_list); // 显示课程列表的fancy的动画 if (showAnimation) mRecyclerView.scheduleLayoutAnimation(); if (showLongPressHintFlag) showLongPressHint(); } }
Example 13
Source File: ReadCookiesInterceptor.java From Yuan-WanAndroid with Apache License 2.0 | 5 votes |
@Override public Response intercept(Interceptor.Chain chain) throws IOException { Request.Builder builder = chain.request().newBuilder(); SharedPreferences pref= PreferenceManager.getDefaultSharedPreferences(mContext); HashSet<String> preferences = (HashSet)pref.getStringSet(TAG, new HashSet<>()); for (String cookie : preferences) { builder.addHeader("Cookie", cookie); } return chain.proceed(builder.build()); }
Example 14
Source File: RemotesFragment.java From rcloneExplorer with MIT License | 5 votes |
@Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getContext() == null) { return; } setHasOptionsMenu(true); ((FragmentActivity) context).setTitle(getString(R.string.remotes_toolbar_title)); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); Set<String> hiddenRemotes = sharedPreferences.getStringSet(getString(R.string.shared_preferences_hidden_remotes), new HashSet<String>()); rclone = new Rclone(getContext()); remotes = rclone.getRemotes(); if (!hiddenRemotes.isEmpty()) { ArrayList<RemoteItem> toBeHidden = new ArrayList<>(); for (RemoteItem remoteItem : remotes) { if (hiddenRemotes.contains(remoteItem.getName())) { toBeHidden.add(remoteItem); } } remotes.removeAll(toBeHidden); } Collections.sort(remotes); }
Example 15
Source File: SampleContentDb.java From leanback-homescreen-channels with Apache License 2.0 | 5 votes |
private SampleContentDb(Context context) { mContext = context.getApplicationContext(); SharedPreferences sampleLocalDbPrefs = mContext.getSharedPreferences(SAMPLE_LOCAL_DB, Context.MODE_PRIVATE); // Creating a copy of the set instance returned by getStringSet since the consistency of the // stored data is not guaranteed if the content is modified according to the docs. Set<String> removedClips = sampleLocalDbPrefs.getStringSet(REMOVED_CLIPS_KEY, new HashSet<String>()); mRemovedClips = new HashSet<>(removedClips); SharedPreferences clipsProgressPrefs = context.getSharedPreferences(CLIPS_PROGRESS_DB, Context.MODE_PRIVATE); Map<String, Long> clipsProgress = (Map<String, Long>) clipsProgressPrefs.getAll(); mClipsProgress = new HashMap<>(clipsProgress); }
Example 16
Source File: BluetoothEventsReceiver.java From your-local-weather with GNU General Public License v3.0 | 5 votes |
private void btDeviceDisConnected(BluetoothDevice bluetoothDevice) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); Set<String> connectedBtDevices = sharedPreferences.getStringSet(Constants.CONNECTED_BT_DEVICES, new HashSet<String>()); if (connectedBtDevices.contains(bluetoothDevice.getAddress())) { connectedBtDevices.remove(bluetoothDevice.getAddress()); sharedPreferences.edit().putStringSet(Constants.CONNECTED_BT_DEVICES, connectedBtDevices).apply(); } }
Example 17
Source File: ServiceSinkhole.java From tracker-control-android with GNU General Public License v3.0 | 4 votes |
private List<Rule> getAllowedRules(List<Rule> listRule) { List<Rule> listAllowed = new ArrayList<>(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); // Check state boolean wifi = Util.isWifiActive(this); boolean metered = Util.isMeteredNetwork(this); boolean useMetered = prefs.getBoolean("use_metered", false); Set<String> ssidHomes = prefs.getStringSet("wifi_homes", new HashSet<String>()); String ssidNetwork = Util.getWifiSSID(this); String generation = Util.getNetworkGeneration(this); boolean unmetered_2g = prefs.getBoolean("unmetered_2g", false); boolean unmetered_3g = prefs.getBoolean("unmetered_3g", false); boolean unmetered_4g = prefs.getBoolean("unmetered_4g", false); boolean roaming = Util.isRoaming(ServiceSinkhole.this); boolean national = prefs.getBoolean("national_roaming", false); boolean eu = prefs.getBoolean("eu_roaming", false); boolean tethering = prefs.getBoolean("tethering", false); boolean filter = prefs.getBoolean("filter", true); // Update connected state last_connected = Util.isConnected(ServiceSinkhole.this); boolean org_metered = metered; boolean org_roaming = roaming; // https://issuetracker.google.com/issues/70633700 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) ssidHomes.clear(); // Update metered state if (wifi && !useMetered) metered = false; if (wifi && ssidHomes.size() > 0 && !(ssidHomes.contains(ssidNetwork) || ssidHomes.contains('"' + ssidNetwork + '"'))) { metered = true; Log.i(TAG, "!@home=" + ssidNetwork + " homes=" + TextUtils.join(",", ssidHomes)); } if (unmetered_2g && "2G".equals(generation)) metered = false; if (unmetered_3g && "3G".equals(generation)) metered = false; if (unmetered_4g && "4G".equals(generation)) metered = false; last_metered = metered; boolean lockdown = isLockedDown(last_metered); // Update roaming state if (roaming && eu) roaming = !Util.isEU(this); if (roaming && national) roaming = !Util.isNational(this); Log.i(TAG, "Get allowed" + " connected=" + last_connected + " wifi=" + wifi + " home=" + TextUtils.join(",", ssidHomes) + " network=" + ssidNetwork + " metered=" + metered + "/" + org_metered + " generation=" + generation + " roaming=" + roaming + "/" + org_roaming + " interactive=" + last_interactive + " tethering=" + tethering + " filter=" + filter + " lockdown=" + lockdown); if (last_connected) for (Rule rule : listRule) { boolean blocked = (metered ? rule.other_blocked : rule.wifi_blocked); boolean screen = (metered ? rule.screen_other : rule.screen_wifi); if ((!blocked || (screen && last_interactive)) && (!metered || !(rule.roaming && roaming)) && (!lockdown || rule.lockdown)) listAllowed.add(rule); } Log.i(TAG, "Allowed " + listAllowed.size() + " of " + listRule.size()); return listAllowed; }
Example 18
Source File: SharedPreferenceUtil.java From ankihelper with GNU General Public License v3.0 | 4 votes |
public static Set<String> getSharedPreferencesStringSet(Context context, String key, Set<String> defaultValue) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); return preferences.getStringSet(key, defaultValue); }
Example 19
Source File: ScheduledTasksAddActivity.java From FreezeYou with Apache License 2.0 | 4 votes |
private boolean prepareSaveTimeTaskData(SharedPreferences defaultSharedPreferences, Map<String, Object> returnPreparedData) { String time = defaultSharedPreferences.getString("stma_add_time", "09:09"); if (time == null) { time = "09:09"; } int indexOfColon = time.indexOf(":"); if (indexOfColon == -1) { showToast(this, R.string.mustContainColon); return false; } int hour; int minutes; try { hour = Integer.parseInt(time.substring(0, indexOfColon)); minutes = Integer.parseInt(time.substring(indexOfColon + 1)); } catch (Exception e) { showToast(this, getString(R.string.minutesShouldBetween) + System.getProperty("line.separator") + getString(R.string.hourShouldBetween)); return false; } int enabled = defaultSharedPreferences.getBoolean("stma_add_enable", true) ? 1 : 0; StringBuilder repeatStringBuilder = new StringBuilder(); Set<String> stringSet = defaultSharedPreferences.getStringSet("stma_add_repeat", null); if (stringSet != null) { for (String str : stringSet) { switch (str) { case "1": case "2": case "3": case "4": case "5": case "6": case "7": repeatStringBuilder.append(str); break; default: break; } } } String repeat = repeatStringBuilder.toString().equals("") ? "0" : repeatStringBuilder.toString(); String label = defaultSharedPreferences.getString("stma_add_label", getString(R.string.label)); String task = defaultSharedPreferences.getString("stma_add_task", "okuf"); returnPreparedData.put("hour", hour); returnPreparedData.put("minutes", minutes); returnPreparedData.put("enabled", enabled); returnPreparedData.put("repeat", repeat); returnPreparedData.put("label", label == null ? "" : label); returnPreparedData.put("task", task == null ? "" : task); return true; }
Example 20
Source File: SharedPrefer.java From FastAndroid with Apache License 2.0 | 2 votes |
/** * 获取字符串集合 * * @param key * @return */ public Set<String> getStringSet(@NonNull Context context, @NonNull String key) { SharedPreferences sp = context.getSharedPreferences(fileName, Context.MODE_PRIVATE); return sp.getStringSet(key, null); }