Java Code Examples for androidx.preference.Preference#getKey()
The following examples show how to use
androidx.preference.Preference#getKey() .
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: PreferenceFragment.java From AndroidPreferenceActivity with Apache License 2.0 | 6 votes |
/** * Restores the default preferences, which are contained by a specific preference group. * * @param preferenceGroup * The preference group, whose preferences should be restored, as an instance of the * class {@link PreferenceGroup}. The preference group may not be null * @param sharedPreferences * The shared preferences, which should be used to restore the preferences, as an * instance of the type {@link SharedPreferences}. The shared preferences may not be * null */ private void restoreDefaults(@NonNull final PreferenceGroup preferenceGroup, @NonNull final SharedPreferences sharedPreferences) { for (int i = 0; i < preferenceGroup.getPreferenceCount(); i++) { Preference preference = preferenceGroup.getPreference(i); if (preference instanceof PreferenceGroup) { restoreDefaults((PreferenceGroup) preference, sharedPreferences); } else if (preference.getKey() != null && !preference.getKey().isEmpty()) { Object oldValue = sharedPreferences.getAll().get(preference.getKey()); if (notifyOnRestoreDefaultValueRequested(preference, oldValue)) { sharedPreferences.edit().remove(preference.getKey()).apply(); preferenceGroup.removePreference(preference); preferenceGroup.addPreference(preference); Object newValue = sharedPreferences.getAll().get(preference.getKey()); notifyOnRestoredDefaultValue(preference, oldValue, newValue); } else { preferenceGroup.removePreference(preference); preferenceGroup.addPreference(preference); } } } }
Example 2
Source File: SettingsFragment.java From prayer-times-android with Apache License 2.0 | 6 votes |
@Override public boolean onPreferenceClick(@NonNull Preference preference) { switch (preference.getKey()) { case "backupRestore": startActivity(new Intent(getActivity(), BackupRestoreActivity.class)); return true; case "kerahatDuration": SettingsFragment frag = new SettingsFragment(); Bundle bdl = new Bundle(); bdl.putBoolean("showKerahatDuration", true); frag.setArguments(bdl); ((BaseActivity) getActivity()).moveToFrag(frag); return true; } return false; }
Example 3
Source File: SettingsFragment.java From prayer-times-android with Apache License 2.0 | 6 votes |
@Override public boolean onPreferenceClick(@NonNull Preference preference) { switch (preference.getKey()) { case "backupRestore": startActivity(new Intent(getActivity(), BackupRestoreActivity.class)); return true; case "kerahatDuration": SettingsFragment frag = new SettingsFragment(); Bundle bdl = new Bundle(); bdl.putBoolean("showKerahatDuration", true); frag.setArguments(bdl); ((BaseActivity) getActivity()).moveToFrag(frag); return true; } return false; }
Example 4
Source File: LoginSettingsFragment.java From tindroid with Apache License 2.0 | 5 votes |
@Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { Preference preference = findPreference(key); Context context = getContext(); if (preference == null || context == null) { return; } switch (preference.getKey()) { case "pref_wireTransport": ListPreference listPreference = (ListPreference) preference; int prefIndex = listPreference.findIndexOfValue(sharedPreferences.getString(key,null)); if (prefIndex >= 0) { preference.setSummary(getString(R.string.settings_wire_explained, listPreference.getEntries()[prefIndex])); } break; case "pref_useTLS": break; case "pref_hostName": preference.setSummary(getString(R.string.settings_host_name_explained, sharedPreferences.getString("pref_hostName", TindroidApp.getDefaultHostName(context)))); break; default: Log.w(TAG, "Unknown preference '" + key + "'"); // do nothing. } }
Example 5
Source File: SettingsActivity.java From GotoBrowser with GNU General Public License v3.0 | 5 votes |
@Override public boolean onPreferenceTreeClick(Preference preference) { String key = preference.getKey(); if (key.equals(PREF_CHECK_UPDATE)) { KcUtils.requestLatestAppVersion(getActivity(), updateCheck, true); } else if (key.equals(PREF_SUBTITLE_UPDATE) && subtitleData != null) { onLocaleItemDownload(subtitleData); } return super.onPreferenceTreeClick(preference); }
Example 6
Source File: SettingsFragment.java From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 | 5 votes |
@Override public boolean onPreferenceChange(Preference preference, Object o) { boolean checked = (boolean) o; String key = preference.getKey(); switch (key) { case KEY_UPDATE_NOTIFICATION: AppSettings.saveBoolean("show_update_notif", checked, getActivity()); return true; case KEY_FORCE_ENGLISH: case KEY_DARK_THEME: getActivity().finish(); Intent intent = new Intent(getActivity(), MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra(NavigationActivity.INTENT_SECTION, SettingsFragment.class.getCanonicalName()); startActivity(intent); return true; /* case KEY_MATERIAL_ICON: Utils.setStartActivity(checked, getActivity()); return true; */ case KEY_HIDE_BANNER: return true; case KEY_SECTIONS_ICON: ((NavigationActivity) getActivity()).appendFragments(); return true; default: if (key.endsWith("_enabled")) { ((NavigationActivity) getActivity()).appendFragments(); return true; } break; } return false; }
Example 7
Source File: OverrideApnFragment.java From android-testdpc with Apache License 2.0 | 5 votes |
@Override @SuppressLint("NewApi") public boolean onPreferenceChange(Preference preference, Object newValue) { String key = preference.getKey(); switch (key) { case ENABLE_OVERRIDE_APN_KEY: boolean enabled = (boolean) newValue; mDevicePolicyManager.setOverrideApnsEnabled(mAdminComponentName, enabled); reloadEnableOverrideApnUi(); return true; } return false; }
Example 8
Source File: CrossProfileCalendarFragment.java From android-testdpc with Apache License 2.0 | 5 votes |
@Override public boolean onPreferenceClick(Preference preference) { String key = preference.getKey(); switch (key) { case CROSS_PROFILE_CALENDAR_SET_ALLOWED_PACKAGES_KEY: showSetPackagesDialog(); return true; } return false; }
Example 9
Source File: SettingsFragment.java From XposedSmsCode with GNU General Public License v3.0 | 5 votes |
@Override public boolean onPreferenceClick(Preference preference) { String key = preference.getKey(); if (PrefConst.KEY_CHOOSE_THEME.equals(key)) { Intent intent = new Intent(mActivity, CyaneaSettingsActivity.class); startActivity(intent); } else if (PrefConst.KEY_CODE_RULES.equals(key)) { CodeRulesActivity.startToMe(mActivity); } else if (PrefConst.KEY_SMSCODE_TEST.equals(key)) { showSmsCodeTestDialog(); } else if (PrefConst.KEY_JOIN_QQ_GROUP.equals(key)) { mPresenter.joinQQGroup(); } else if (PrefConst.KEY_SOURCE_CODE.equals(key)) { mPresenter.showSourceProject(); } else if (PrefConst.KEY_DONATE_BY_ALIPAY.equals(key)) { donateByAlipay(); } else if (PrefConst.KEY_ENTRY_CODE_RECORDS.equals(key)) { CodeRecordActivity.startToMe(mActivity); } else if (PrefConst.KEY_GET_ALIPAY_PACKET.equals(key)) { getAlipayPacket(); } else if (PrefConst.KEY_APP_BLOCK_ENTRY.equals(key)) { AppBlockActivity.startMe(mActivity); } else if (PrefConst.KEY_VERSION.equals(key)) { mPresenter.checkUpdate(); } else { return false; } return true; }
Example 10
Source File: SettingsFragment.java From fresco with MIT License | 5 votes |
@Override public boolean onPreferenceTreeClick(Preference preference) { switch (preference.getKey()) { case KEY_CLEAR_DISK_CACHE: onClearDiskCachePreferenceClicked(); return true; case KEY_URI_OVERRIDE: onUriOverrideClicked(); return true; default: return super.onPreferenceTreeClick(preference); } }
Example 11
Source File: ResetActivePreferenceFragment.java From green_android with GNU General Public License v3.0 | 5 votes |
@Override public boolean onPreferenceClick(final Preference preference) { switch (preference.getKey()) { case PrefKeys.CANCEL_TWOFACTOR_RESET: startTwoFactorActivity("cancel"); return true; case PrefKeys.DISPUTE_TWOFACTOR_RESET: startTwoFactorActivity("dispute"); return true; } return false; }
Example 12
Source File: BaseSearchablePolicyPreferenceFragment.java From android-testdpc with Apache License 2.0 | 5 votes |
private int findListPositionFromKey(PreferenceGroupAdapter adapter, String key) { final int count = adapter.getItemCount(); for (int n = 0; n < count; n++) { final Preference preference = adapter.getItem(n); final String preferenceKey = preference.getKey(); if (preferenceKey != null && preferenceKey.equals(key)) { return n; } } return -1; }
Example 13
Source File: CrossProfileCalendarFragment.java From android-testdpc with Apache License 2.0 | 5 votes |
@Override public boolean onPreferenceChange(Preference preference, Object newValue) { String key = preference.getKey(); switch (key) { case CROSS_PROFILE_CALENDAR_ALLOW_ALL_PACKAGES_KEY: mDevicePolicyManager.setCrossProfileCalendarPackages( mAdminComponentName, newValue.equals(true) ? null : Collections.emptySet()); reloadAllowAllPackagesUi(); } return false; }
Example 14
Source File: AutoInputSettingsFragment.java From SmsCode with GNU General Public License v3.0 | 5 votes |
@Override public boolean onPreferenceChange(Preference preference, Object newValue) { String key = preference.getKey(); switch (key) { case ENABLE_AUTO_INPUT_CODE: refreshEnableAutoInputPreference((Boolean) newValue); break; case AUTO_INPUT_MODE: { if (!newValue.equals(mAutoInputMode)) { mAutoInputMode = (String) newValue; refreshAutoInputModePreference(mAutoInputMode); if (AUTO_INPUT_MODE_ROOT.equals(mAutoInputMode)) { showRootModePrompt(); } else if (AUTO_INPUT_MODE_ACCESSIBILITY.equals(mAutoInputMode)) { showAccessibilityModePrompt(); } } break; } case FOCUS_MODE: { if (!newValue.equals(mFocusMode)) { mFocusMode = (String) newValue; refreshFocusModePreference((ListPreference) preference, mFocusMode); refreshManualFocusIfFailedPreference(); break; } } default: return false; } return true; }
Example 15
Source File: SettingsFragment.java From SmsCode with GNU General Public License v3.0 | 5 votes |
@Override public boolean onPreferenceChange(Preference preference, Object newValue) { String key = preference.getKey(); switch (key) { case ENABLE: onEnabledSwitched((Boolean) newValue); break; case LISTEN_MODE: { if (!newValue.equals(mCurListenMode)) { mCurListenMode = (String) newValue; refreshListenModePreference((ListPreference) preference, mCurListenMode); if (PrefConst.LISTEN_MODE_COMPATIBLE.equals(mCurListenMode)) { showCompatibleModePrompt(); } } break; } case MARK_AS_READ: showAppOpsPrompt((SwitchPreference) preference, (Boolean) newValue); break; case DELETE_SMS: showAppOpsPrompt((SwitchPreference) preference, (Boolean) newValue); break; case VERBOSE_LOG_MODE: refreshVerboseLogPreference(preference, (Boolean) newValue); break; case EXCLUDE_FROM_RECENTS: onExcludeFromRecentsSwitched((Boolean) newValue); break; case BLOCK_NOTIFICATION: onBlockNotificationSwitched((SwitchPreference) preference, (Boolean) newValue); break; default: return false; } return true; }
Example 16
Source File: ProfilePolicyManagementFragment.java From android-testdpc with Apache License 2.0 | 5 votes |
@Override @SuppressLint("NewApi") public boolean onPreferenceChange(Preference preference, Object newValue) { String key = preference.getKey(); switch (key) { case DISABLE_BLUETOOTH_CONTACT_SHARING_KEY: boolean disableBluetoothContactSharing = (Boolean) newValue; mDevicePolicyManager.setBluetoothContactSharingDisabled(mAdminComponentName, disableBluetoothContactSharing); // Reload UI to verify the state of bluetooth contact sharing is set correctly. reloadBluetoothContactSharing(); return true; case DISABLE_CROSS_PROFILE_CALLER_ID_KEY: boolean disableCrossProfileCallerId = (Boolean) newValue; mDevicePolicyManager.setCrossProfileCallerIdDisabled(mAdminComponentName, disableCrossProfileCallerId); // Reload UI to verify the state of cross-profile caller Id is set correctly. reloadCrossProfileCallerIdDisableUi(); return true; case DISABLE_CROSS_PROFILE_CONTACTS_SEARCH_KEY: boolean disableCrossProfileContactsSearch = (Boolean) newValue; mDevicePolicyManager.setCrossProfileContactsSearchDisabled(mAdminComponentName, disableCrossProfileContactsSearch); // Reload UI to verify the state of cross-profile contacts search is set correctly. reloadCrossProfileContactsSearchDisableUi(); return true; case SET_PROFILE_ORGANIZATION_NAME_KEY: mDevicePolicyManager.setOrganizationName(mAdminComponentName, (String) newValue); mSetOrganizationNamePreference.setSummary((String) newValue); return true; } return false; }
Example 17
Source File: ProfilePolicyManagementFragment.java From android-testdpc with Apache License 2.0 | 5 votes |
@Override public boolean onPreferenceClick(Preference preference) { String key = preference.getKey(); switch (key) { case ADD_CROSS_PROFILE_INTENT_FILTER_PREFERENCE_KEY: showAddCrossProfileIntentFilterFragment(); return true; case CLEAR_CROSS_PROFILE_INTENT_FILTERS_PREFERENCE_KEY: mDevicePolicyManager.clearCrossProfileIntentFilters(mAdminComponentName); showToast(R.string.cross_profile_intent_filters_cleared); return true; case REMOVE_PROFILE_KEY: mRemoveManagedProfilePreference.setEnabled(false); mDevicePolicyManager.wipeData(0); showToast(R.string.removing_managed_profile); // Finish the activity because all other functions will not work after the managed // profile is removed. getActivity().finish(); case ADD_CROSS_PROFILE_APP_WIDGETS_KEY: showDisabledAppWidgetList(); return true; case REMOVE_CROSS_PROFILE_APP_WIDGETS_KEY: showEnabledAppWidgetList(); return true; case SET_ORGANIZATION_COLOR_KEY: int colorValue = getActivity().getResources().getColor(R.color.teal); final CharSequence summary = mSetOrganizationColorPreference.getSummary(); if (summary != null) { try { colorValue = Color.parseColor(summary.toString()); } catch (IllegalArgumentException e) { // Ignore } } ColorPicker.newInstance(colorValue, FRAGMENT_TAG, ORGANIZATION_COLOR_ID) .show(getFragmentManager(), "colorPicker"); } return false; }
Example 18
Source File: PreferencesCommonFragment.java From InviZible with GNU General Public License v3.0 | 4 votes |
@Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (getActivity() == null) { return false; } switch (preference.getKey()) { case "swShowNotification": if (!Boolean.parseBoolean(newValue.toString())) { Intent intent = new Intent(getActivity(), ModulesService.class); intent.setAction(ModulesService.actionDismissNotification); getActivity().startService(intent); InfoNotificationProtectService infoNotification = new InfoNotificationProtectService(); if (isAdded()) { infoNotification.show(getParentFragmentManager(), "dialogProtectService"); } } break; case "pref_common_tor_tethering": allowTorTether = Boolean.parseBoolean(newValue.toString()); readTorConf(); if (new PrefManager(getActivity()).getBoolPref("Tor Running")) { ModulesRestarter.restartTor(getActivity()); ModulesStatus.getInstance().setIptablesRulesUpdateRequested(getActivity(), true); //ModulesAux.requestModulesStatusUpdate(getActivity()); } break; case "pref_common_itpd_tethering": allowITPDtether = Boolean.parseBoolean(newValue.toString()); readITPDConf(); readITPDTunnelsConf(); if (new PrefManager(getActivity()).getBoolPref("I2PD Running")) { ModulesRestarter.restartITPD(getActivity()); ModulesStatus.getInstance().setIptablesRulesUpdateRequested(getActivity(), true); //ModulesAux.requestModulesStatusUpdate(getActivity()); } break; case "pref_common_tor_route_all": Preference prefTorSiteUnlockTether = findPreference("prefTorSiteUnlockTether"); if (prefTorSiteUnlockTether != null) { if (Boolean.parseBoolean(newValue.toString())) { prefTorSiteUnlockTether.setEnabled(false); } else { prefTorSiteUnlockTether.setEnabled(true); } } if (new PrefManager(getActivity()).getBoolPref("Tor Running")) { ModulesStatus.getInstance().setIptablesRulesUpdateRequested(getActivity(), true); //ModulesAux.requestModulesStatusUpdate(getActivity()); } break; case "pref_common_block_http": if (new PrefManager(getActivity()).getBoolPref("DNSCrypt Running") || new PrefManager(getActivity()).getBoolPref("Tor Running")) { ModulesStatus.getInstance().setIptablesRulesUpdateRequested(getActivity(), true); //ModulesAux.requestModulesStatusUpdate(getActivity()); } break; case "swUseModulesRoot": ModulesStatus modulesStatus = ModulesStatus.getInstance(); ModulesAux.stopModulesIfRunning(getActivity()); boolean newOptionValue = Boolean.parseBoolean(newValue.toString()); modulesStatus.setUseModulesWithRoot(newOptionValue); modulesStatus.setContextUIDUpdateRequested(true); ModulesAux.makeModulesStateExtraLoop(getActivity()); //ModulesAux.requestModulesStatusUpdate(getActivity()); Preference fixTTLPreference = findPreference("pref_common_fix_ttl"); if (fixTTLPreference != null) { fixTTLPreference.setEnabled(!newOptionValue); } Log.i(LOG_TAG, "PreferencesCommonFragment switch to " + (Boolean.parseBoolean(newValue.toString())? "Root" : "No Root")); break; case "pref_common_fix_ttl": modulesStatus = ModulesStatus.getInstance(); boolean fixed = Boolean.parseBoolean(newValue.toString()); modulesStatus.setFixTTL(fixed); modulesStatus.setIptablesRulesUpdateRequested(getActivity(), true); new PrefManager(getActivity()).setBoolPref("refresh_main_activity", true); break; case "pref_common_local_eth_device_addr": ModulesStatus.getInstance().setIptablesRulesUpdateRequested(getActivity(), true); break; case "swWakelock": ModulesAux.requestModulesStatusUpdate(getActivity()); break; } return true; }
Example 19
Source File: MainPreferenceFragment.java From kcanotify with GNU General Public License v3.0 | 4 votes |
@Override public boolean onPreferenceTreeClick(Preference preference) { Log.e("KCA", "onPreferenceTreeClick " + preference.getKey()); String key = preference.getKey(); if (!isActivitySet) return false; if (PREF_OVERLAY_SETTING.equals(key)) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { showObtainingPermissionOverlayWindow(); } else { showToast(getActivity(), getStringWithLocale(R.string.sa_overlay_under_m), Toast.LENGTH_SHORT); } } if (PREF_SCREEN_ADV_NETWORK.equals(key)) { mCallback.onNestedPreferenceSelected(NestedPreferenceFragment.FRAGMENT_ADV_NETWORK); return false; } if (PREF_KCA_NOTI_RINGTONE.equals(key)) { Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER); intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION); intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true); intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true); intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, DEFAULT_NOTIFICATION_URI); String existingValue = sharedPref.getString(key, null); if (existingValue != null) { if (existingValue.length() == 0) { // Select "Silent" intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (Uri) null); } else { intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Uri.parse(existingValue)); } } else { // No ringtone has been selected, set to the default intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Settings.System.DEFAULT_NOTIFICATION_URI); } startActivityForResult(intent, REQUEST_ALERT_RINGTONE); } if (PREF_CHECK_UPDATE.equals(key)) { checkRecentVersion(); } return super.onPreferenceTreeClick(preference); }
Example 20
Source File: PasswordConstraintsFragment.java From android-testdpc with Apache License 2.0 | 4 votes |
@Override public boolean onPreferenceChange(Preference preference, Object newValue) { final int value; if (newValue instanceof String && ((String) newValue).length() != 0) { try { value = Integer.parseInt((String) newValue); } catch (NumberFormatException e) { Toast.makeText(getActivity(), R.string.not_valid_input, Toast.LENGTH_SHORT).show(); return false; } } else { value = 0; } // By default, show the new value as a summary. CharSequence summary = newValue.toString(); switch (preference.getKey()) { case Keys.EXPIRATION_TIME: { getDpm().setPasswordExpirationTimeout(getAdmin(), TimeUnit.SECONDS.toMillis(value)); updateExpirationTimes(); return true; } case Keys.HISTORY_LENGTH: getDpm().setPasswordHistoryLength(getAdmin(), value); break; case Keys.QUALITY: { final ListPreference list = (ListPreference) preference; // Store newValue now so getEntry() can return the new setting list.setValue((String) newValue); summary = list.getEntry(); getDpm().setPasswordQuality(getAdmin(), value); refreshPreferences(); break; } case Keys.MIN_LENGTH: getDpm().setPasswordMinimumLength(getAdmin(), value); break; case Keys.MIN_LETTERS: getDpm().setPasswordMinimumLetters(getAdmin(), value); break; case Keys.MIN_NUMERIC: getDpm().setPasswordMinimumNumeric(getAdmin(), value); break; case Keys.MIN_LOWERCASE: getDpm().setPasswordMinimumLowerCase(getAdmin(), value); break; case Keys.MIN_UPPERCASE: getDpm().setPasswordMinimumUpperCase(getAdmin(), value); break; case Keys.MIN_SYMBOLS: getDpm().setPasswordMinimumSymbols(getAdmin(), value); break; case Keys.MIN_NONLETTER: getDpm().setPasswordMinimumNonLetter(getAdmin(), value); break; default: return false; } preference.setSummary(summary); DeviceAdminReceiver.sendPasswordRequirementsChanged(getActivity()); return true; }