Java Code Examples for android.content.SharedPreferences#contains()
The following examples show how to use
android.content.SharedPreferences#contains() .
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: SettingsValues.java From openboard with GNU General Public License v3.0 | 6 votes |
private static boolean needsToShowVoiceInputKey(final SharedPreferences prefs, final Resources res) { // Migrate preference from {@link Settings#PREF_VOICE_MODE_OBSOLETE} to // {@link Settings#PREF_VOICE_INPUT_KEY}. if (prefs.contains(Settings.PREF_VOICE_MODE_OBSOLETE)) { final String voiceModeMain = res.getString(R.string.voice_mode_main); final String voiceMode = prefs.getString( Settings.PREF_VOICE_MODE_OBSOLETE, voiceModeMain); final boolean shouldShowVoiceInputKey = voiceModeMain.equals(voiceMode); prefs.edit() .putBoolean(Settings.PREF_VOICE_INPUT_KEY, shouldShowVoiceInputKey) // Remove the obsolete preference if exists. .remove(Settings.PREF_VOICE_MODE_OBSOLETE) .apply(); } return prefs.getBoolean(Settings.PREF_VOICE_INPUT_KEY, true); }
Example 2
Source File: TextSecurePreferences.java From bcm-android with GNU General Public License v3.0 | 5 votes |
private static Set<String> getStringSetPreference(AccountContext accountContext, String key, Set<String> defaultValues) { final SharedPreferences pref = getCurrentSharedPreferences(accountContext); if (null != pref && pref.contains(key)) { return pref.getStringSet(key, Collections.<String>emptySet()); } else { return defaultValues; } }
Example 3
Source File: SettingsValues.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 5 votes |
private static boolean readSuggestionsEnabled(final SharedPreferences prefs) { if (prefs.contains(Settings.PREF_SHOW_SUGGESTIONS_SETTING_OBSOLETE)) { final boolean alwaysHide = SUGGESTIONS_VISIBILITY_HIDE_VALUE_OBSOLETE.equals( prefs.getString(Settings.PREF_SHOW_SUGGESTIONS_SETTING_OBSOLETE, null)); prefs.edit() .remove(Settings.PREF_SHOW_SUGGESTIONS_SETTING_OBSOLETE) .putBoolean(Settings.PREF_SHOW_SUGGESTIONS, !alwaysHide) .apply(); } return prefs.getBoolean(Settings.PREF_SHOW_SUGGESTIONS, true); }
Example 4
Source File: AddCookiesInterceptor.java From AndroidWallet with GNU General Public License v3.0 | 5 votes |
private String getCookie(String url, String domain) { SharedPreferences sp = Utils.getContext().getSharedPreferences(COOKIE_PREF, Context.MODE_PRIVATE); if (!TextUtils.isEmpty(url) && sp.contains(url) && !TextUtils.isEmpty(sp.getString(url, ""))) { return sp.getString(url, ""); } if (!TextUtils.isEmpty(domain) && sp.contains(domain) && !TextUtils.isEmpty(sp.getString(domain, ""))) { return sp.getString(domain, ""); } return null; }
Example 5
Source File: PreferencesFragment.java From SensorTag-CC2650 with Apache License 2.0 | 5 votes |
public boolean isEnabledByPrefs(final Sensor sensor) { String preferenceKeyString = "pref_" + sensor.name().toLowerCase(Locale.ENGLISH) + "_on"; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); if (!prefs.contains(preferenceKeyString)) { //throw new RuntimeException("Programmer error, could not find preference with key " + preferenceKeyString); return false; } return prefs.getBoolean(preferenceKeyString, true); }
Example 6
Source File: WakeUpAtFragment.java From sleep-cycle-alarm with GNU General Public License v3.0 | 5 votes |
@Override public void setLastExecutionDateFromPreferences() { SharedPreferences pref = getActivity() .getSharedPreferences(getString(R.string.wakeupat_preferences_name), Context.MODE_PRIVATE); if (pref.contains(getString(R.string.key_last_execution_date))) { String notFormattedDate = pref.getString(getString(R.string.key_last_execution_date), null); if (!TextUtils.isEmpty(notFormattedDate)) { setLastExecutionDate(DateTime.parse(notFormattedDate)); } } }
Example 7
Source File: SunshinePreferences.java From android-dev-challenge with Apache License 2.0 | 5 votes |
/** * Returns true if the latitude and longitude values are available. The latitude and * longitude will not be available until the lesson where the PlacePicker API is taught. * * @param context used to get the SharedPreferences * @return true if lat/long are saved in SharedPreferences */ public static boolean isLocationLatLonAvailable(Context context) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); boolean spContainLatitude = sp.contains(PREF_COORD_LAT); boolean spContainLongitude = sp.contains(PREF_COORD_LONG); boolean spContainBothLatitudeAndLongitude = false; if (spContainLatitude && spContainLongitude) { spContainBothLatitudeAndLongitude = true; } return spContainBothLatitudeAndLongitude; }
Example 8
Source File: SunshinePreferences.java From android-dev-challenge with Apache License 2.0 | 5 votes |
/** * Returns true if the latitude and longitude values are available. The latitude and * longitude will not be available until the lesson where the PlacePicker API is taught. * * @param context used to get the SharedPreferences * @return true if lat/long are saved in SharedPreferences */ public static boolean isLocationLatLonAvailable(Context context) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); boolean spContainLatitude = sp.contains(PREF_COORD_LAT); boolean spContainLongitude = sp.contains(PREF_COORD_LONG); boolean spContainBothLatitudeAndLongitude = false; if (spContainLatitude && spContainLongitude) { spContainBothLatitudeAndLongitude = true; } return spContainBothLatitudeAndLongitude; }
Example 9
Source File: Settings.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 5 votes |
public static boolean readShowsLanguageSwitchKey(final SharedPreferences prefs) { if (prefs.contains(PREF_SUPPRESS_LANGUAGE_SWITCH_KEY)) { final boolean suppressLanguageSwitchKey = prefs.getBoolean( PREF_SUPPRESS_LANGUAGE_SWITCH_KEY, false); final SharedPreferences.Editor editor = prefs.edit(); editor.remove(PREF_SUPPRESS_LANGUAGE_SWITCH_KEY); editor.putBoolean(PREF_SHOW_LANGUAGE_SWITCH_KEY, !suppressLanguageSwitchKey); editor.apply(); } return prefs.getBoolean(PREF_SHOW_LANGUAGE_SWITCH_KEY, true); }
Example 10
Source File: IntegerListPreference.java From EdXposedManager with GNU General Public License v3.0 | 5 votes |
@Override protected String getPersistedString(String defaultReturnValue) { SharedPreferences pref = getPreferenceManager().getSharedPreferences(); String key = getKey(); if (!shouldPersist() || !pref.contains(key)) return defaultReturnValue; return String.valueOf(pref.getInt(key, 0)); }
Example 11
Source File: HtmlBook.java From BookyMcBookface with GNU General Public License v3.0 | 4 votes |
@Override protected void load() throws IOException { if (!getFile().exists() || !getFile().canRead()) { throw new FileNotFoundException(getFile() + " doesn't exist or not readable"); } toc = new LinkedHashMap<>(); SharedPreferences bookdat = getSharedPreferences(); if (bookdat.contains(ORDERCOUNT)) { int toccount = bookdat.getInt(ORDERCOUNT, 0); for (int i = 0; i < toccount; i++) { String label = bookdat.getString(TOC_LABEL + i, ""); String point = bookdat.getString(TOC_CONTENT + i, ""); toc.put(point, label); Log.d("EPUB", "TOC: " + label + ". File: " + point); } } else { try (BufferedReader reader = new BufferedReader(new FileReader(getFile()))) { int c = 0; String line; Pattern idlinkrx = Pattern.compile("<a\\s+[^>]*\\b(?i:name|id)=\"([^\"]+)\"[^>]*>(?:(.+?)</a>)?"); Pattern hidlinkrx = Pattern.compile("<h[1-3]\\s+[^>]*\\bid=\"([^\"]+)\"[^>]*>(.+?)</h"); SharedPreferences.Editor bookdatedit = bookdat.edit(); while ((line = reader.readLine()) != null) { String id = null; String text = null; Matcher t = idlinkrx.matcher(line); if (t.find()) { id = t.group(1); text = t.group(2); } Matcher t2 = hidlinkrx.matcher(line); if (t2.find()) { id = t2.group(1); text = t2.group(2); } if (id != null) { if (text==null) text=id; bookdatedit.putString(TOC_LABEL +c, text); bookdatedit.putString(TOC_CONTENT +c, "#"+id); toc.put("#"+id, text); c++; } } bookdatedit.putInt(ORDERCOUNT, c); bookdatedit.apply(); } } }
Example 12
Source File: SharedUtil.java From MegviiFacepp-Android-SDK with Apache License 2.0 | 4 votes |
public boolean contains(String key) { SharedPreferences sharePre = ctx.getSharedPreferences(FileName, Context.MODE_PRIVATE); return sharePre.contains(key); }
Example 13
Source File: SPUtils.java From shinny-futures-android with GNU General Public License v3.0 | 4 votes |
/** * 查询某个key是否已经存在 */ public static boolean contains(Context context, String key) { SharedPreferences sp = context.getSharedPreferences(getSpName(context), Context.MODE_PRIVATE); return sp.contains(key); }
Example 14
Source File: ProfileNotificationsActivity.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
@Override public boolean onFragmentCreate() { rowCount = 0; customRow = rowCount++; customInfoRow = rowCount++; generalRow = rowCount++; soundRow = rowCount++; vibrateRow = rowCount++; if ((int) dialog_id < 0) { smartRow = rowCount++; } else { smartRow = -1; } if (Build.VERSION.SDK_INT >= 21) { priorityRow = rowCount++; } else { priorityRow = -1; } priorityInfoRow = rowCount++; boolean isChannel; int lower_id = (int) dialog_id; if (lower_id < 0) { TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-lower_id); isChannel = chat != null && ChatObject.isChannel(chat) && !chat.megagroup; } else { isChannel = false; } if (lower_id != 0 && !isChannel) { popupRow = rowCount++; popupEnabledRow = rowCount++; popupDisabledRow = rowCount++; popupInfoRow = rowCount++; } else { popupRow = -1; popupEnabledRow = -1; popupDisabledRow = -1; popupInfoRow = -1; } if (lower_id > 0) { callsRow = rowCount++; callsVibrateRow = rowCount++; ringtoneRow = rowCount++; ringtoneInfoRow = rowCount++; } else { callsRow = -1; callsVibrateRow = -1; ringtoneRow = -1; ringtoneInfoRow = -1; } ledRow = rowCount++; colorRow = rowCount++; ledInfoRow = rowCount++; SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount); customEnabled = preferences.getBoolean("custom_" + dialog_id, false); boolean hasOverride = preferences.contains("notify2_" + dialog_id); int value = preferences.getInt("notify2_" + dialog_id, 0); if (value == 0) { if (hasOverride) { notificationsEnabled = true; } else { if ((int) dialog_id < 0) { notificationsEnabled = preferences.getBoolean("EnableGroup", true); } else { notificationsEnabled = preferences.getBoolean("EnableAll", true); } } } else if (value == 1) { notificationsEnabled = true; } else if (value == 2) { notificationsEnabled = false; } else { notificationsEnabled = false; } NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.notificationsSettingsUpdated); return super.onFragmentCreate(); }
Example 15
Source File: StorageUtils.java From prebid-mobile-android with Apache License 2.0 | 4 votes |
private static boolean checkSharedPreferencesKey(String key) throws PbContextNullException { SharedPreferences pref = getSharedPreferences(); return pref.contains(key); }
Example 16
Source File: KcaService.java From kcanotify_h5-master with GNU General Public License v3.0 | 4 votes |
private boolean checkKeyInPreferences(String key) { SharedPreferences pref = getSharedPreferences("pref", MODE_PRIVATE); return pref.contains(key); }
Example 17
Source File: SharedPreferencesUtil.java From MarketAndroidApp with Apache License 2.0 | 2 votes |
/** * 查询某个key是否已经存在 * * @param context * @param key * @return */ public static boolean contains(Context context, String key) { SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE); return sp.contains(key); }
Example 18
Source File: SPUtils.java From SmartChart with Apache License 2.0 | 2 votes |
/** * 查询某个key是否已经存在 * * @param context * @param key * @return */ public static boolean contains(Context context, String key) { SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE); return sp.contains(key); }
Example 19
Source File: XPreferencesUtils.java From XFrame with Apache License 2.0 | 2 votes |
/** * 查询某个key是否已经存在 * * @param key * @return */ public static boolean contains(String key) { SharedPreferences sp = XFrame.getContext().getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE); return sp.contains(key); }
Example 20
Source File: Preference.java From Hauk with Apache License 2.0 | 2 votes |
/** * Checks whether or not the preference exists in the given preference object. * * @param prefs The shared preferences to check for preference existence in. */ public final boolean has(SharedPreferences prefs) { return prefs.contains(this.key); }