android.preference.Preference Java Examples
The following examples show how to use
android.preference.Preference.
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: SettingsFragment.java From droidddle with Apache License 2.0 | 6 votes |
@Override public boolean onPreferenceChange(Preference preference, Object value) { String stringValue = value.toString(); if (preference instanceof ListPreference) { // For list preferences, look up the correct display value in // the preference's 'entries' list. ListPreference listPreference = (ListPreference) preference; int index = listPreference.findIndexOfValue(stringValue); // Set the summary to reflect the new value. preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null); } else { // For all other preferences, set the summary to the value's // simple string representation. preference.setSummary(stringValue); } return true; }
Example #2
Source File: SettingsActivity.java From Doze-Settings-Editor with MIT License | 6 votes |
@Override public boolean onPreferenceChange(Preference preference, Object value) { String stringValue = value.toString(); if (preference instanceof ListPreference) { // For list preferences, look up the correct display value in // the preference's 'entries' list. ListPreference listPreference = (ListPreference) preference; int index = listPreference.findIndexOfValue(stringValue); // Set the summary to reflect the new value. preference.setSummary( index >= 0 ? listPreference.getEntries()[index] : null); } else { // For all other preferences, set the summary to the value's // simple string representation. preference.setSummary(stringValue); } return true; }
Example #3
Source File: SettingsFragment.java From NightWidget with GNU General Public License v2.0 | 6 votes |
private void initSummary(Preference p) { if (p instanceof PreferenceCategory) { PreferenceCategory pCat = (PreferenceCategory) p; for (int i = 0; i < pCat.getPreferenceCount(); i++) { initSummary(pCat.getPreference(i)); } } else if (p instanceof PreferenceScreen) { PreferenceScreen pSc = (PreferenceScreen) p; for (int i = 0; i < pSc.getPreferenceCount(); i++) { initSummary(pSc.getPreference(i)); } } else { updatePrefSummary(p); } }
Example #4
Source File: BlueJayAdapter.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
@Override public boolean onPreferenceChange(Preference preference, Object value) { try { if ((boolean) value) { // setting to true if (preference.getSharedPreferences().getBoolean("bluejay_run_as_phone_collector", false)) { JoH.static_toast_long("Must disable BlueJay using phone slot first!"); return false; } } } catch (Exception e) { // } return true; }
Example #5
Source File: AbstractSettingsActivity.java From mytracks with Apache License 2.0 | 6 votes |
/** * Configures a list preference. * * @param listPreference the list preference * @param summary the summary array * @param options the options array * @param values the values array * @param value the value * @param listener optional listener */ protected void configureListPreference(ListPreference listPreference, final String[] summary, final String[] options, final String[] values, String value, final OnPreferenceChangeListener listener) { listPreference.setEntryValues(values); listPreference.setEntries(options); listPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference pref, Object newValue) { updatePreferenceSummary(pref, summary, values, (String) newValue); if (listener != null) { listener.onPreferenceChange(pref, newValue); } return true; } }); updatePreferenceSummary(listPreference, summary, values, value); if (listener != null) { listener.onPreferenceChange(listPreference, value); } }
Example #6
Source File: SettingsActivity.java From mOrgAnd with GNU General Public License v2.0 | 6 votes |
@Override public boolean onPreferenceChange(Preference preference, Object value) { String stringValue = value.toString(); if (preference instanceof ListPreference) { // For list preferences, look up the correct display value in // the preference's 'entries' list. ListPreference listPreference = (ListPreference) preference; int index = listPreference.findIndexOfValue(stringValue); // Set the summary to reflect the new value. preference.setSummary( index >= 0 ? listPreference.getEntries()[index] : null ); } else { // For all other preferences, set the summary to the value's // simple string representation. preference.setSummary(stringValue); } return true; }
Example #7
Source File: LXMyApp.java From android_library_libxposed with Apache License 2.0 | 6 votes |
public static boolean transferPreferences(String action, Preference preference, Object value) { Intent i = new Intent(action); if (value instanceof Boolean) { i.putExtra(preference.getKey(), (Boolean) value); } else if (value instanceof Float) { i.putExtra(preference.getKey(), (Float) value); } else if (value instanceof Integer) { i.putExtra(preference.getKey(), (Integer) value); } else if (value instanceof Long) { i.putExtra(preference.getKey(), (Long) value); } else if (value instanceof String) { i.putExtra(preference.getKey(), (String) value); } else if (value instanceof String[]) { i.putExtra(preference.getKey(), (String[]) value); } else { throw new IllegalArgumentException(value.getClass() .getCanonicalName() + " is not a supported Preference!"); } preference.getContext().sendBroadcast(i); return true; }
Example #8
Source File: PreferencesActivity.java From AndroidAPS with GNU Affero General Public License v3.0 | 6 votes |
private static void updatePrefSummary(Preference pref) { if (pref instanceof ListPreference) { ListPreference listPref = (ListPreference) pref; pref.setSummary(listPref.getEntry()); } if (pref instanceof EditTextPreference) { EditTextPreference editTextPref = (EditTextPreference) pref; if (pref.getKey().contains("password") || pref.getKey().contains("secret")) { pref.setSummary("******"); } else if (editTextPref.getText() != null) { ((EditTextPreference) pref).setDialogMessage(editTextPref.getDialogMessage()); pref.setSummary(editTextPref.getText()); } else { for (PluginBase plugin : MainApp.getPluginsList()) { plugin.updatePreferenceSummary(pref); } } } if (pref != null) adjustUnitDependentPrefs(pref); }
Example #9
Source File: SettingsActivity.java From Acastus with GNU Lesser General Public License v3.0 | 6 votes |
@Override public boolean onPreferenceChange(Preference preference, Object value) { String stringValue = value.toString(); if (preference instanceof ListPreference) { // For list preferences, look up the correct display value in // the preference's 'entries' list. ListPreference listPreference = (ListPreference) preference; int index = listPreference.findIndexOfValue(stringValue); // Set the summary to reflect the new value. preference.setSummary( index >= 0 ? listPreference.getEntries()[index] : null); } else { // For all other preferences, set the summary to the value's // simple string representation. preference.setSummary(stringValue); } return true; }
Example #10
Source File: DownloadFragment.java From EhViewer with Apache License 2.0 | 6 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.download_settings); Preference mediaScan = findPreference(Settings.KEY_MEDIA_SCAN); Preference imageResolution = findPreference(Settings.KEY_IMAGE_RESOLUTION); mDownloadLocation = findPreference(KEY_DOWNLOAD_LOCATION); onUpdateDownloadLocation(); mediaScan.setOnPreferenceChangeListener(this); imageResolution.setOnPreferenceChangeListener(this); if (mDownloadLocation != null) { mDownloadLocation.setOnPreferenceClickListener(this); } }
Example #11
Source File: SettingsActivity.java From prettygoodmusicplayer with GNU General Public License v3.0 | 6 votes |
@Override @Deprecated public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { // TODO clean this up a bunch. Log.i(TAG, "User clicked " + preference.getTitle()); if (preference.getKey().equals("choose_music_directory_prompt")) { final File path = Utils.getRootStorageDirectory(); DirectoryPickerOnClickListener picker = new DirectoryPickerOnClickListener( this, path); picker.showDirectoryPicker(); Log.i(TAG, "User selected " + picker.path); return true; } return super.onPreferenceTreeClick(preferenceScreen, preference); }
Example #12
Source File: SettingsActivity.java From DataLogger with MIT License | 6 votes |
@Override public boolean onPreferenceChange(Preference preference, Object value) { String stringValue = value.toString(); if (preference instanceof ListPreference) { // For list preferences, look up the correct display value in // the preference's 'entries' list. ListPreference listPreference = (ListPreference) preference; int index = listPreference.findIndexOfValue(stringValue); // Set the summary to reflect the new value. preference.setSummary( index >= 0 ? listPreference.getEntries()[index] : null); } else { // For all other preferences, set the summary to the value's // simple string representation. preference.setSummary(stringValue); } return true; }
Example #13
Source File: StatsSettingsActivity.java From mytracks with Apache License 2.0 | 6 votes |
/** * Configures the preferred units list preference. */ private void configUnitsListPreference() { @SuppressWarnings("deprecation") ListPreference listPreference = (ListPreference) findPreference( getString(R.string.stats_units_key)); OnPreferenceChangeListener listener = new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference pref, Object newValue) { boolean metricUnits = PreferencesUtils.STATS_UNITS_DEFAULT.equals((String) newValue); configRateListPreference(metricUnits); return true; } }; String value = PreferencesUtils.getString( this, R.string.stats_units_key, PreferencesUtils.STATS_UNITS_DEFAULT); String[] values = getResources().getStringArray(R.array.stats_units_values); String[] options = getResources().getStringArray(R.array.stats_units_options); configureListPreference(listPreference, options, options, values, value, listener); }
Example #14
Source File: SettingsActivity.java From NetworkMapper with GNU General Public License v2.0 | 6 votes |
@Override public boolean onPreferenceChange(Preference preference, Object value) { String stringValue = value.toString(); if (preference instanceof ListPreference) { // For list preferences, look up the correct display value in // the preference's 'entries' list. ListPreference listPreference = (ListPreference) preference; int index = listPreference.findIndexOfValue(stringValue); // Set the summary to reflect the new value. preference.setSummary( index >= 0 ? listPreference.getEntries()[index] : null); } else { // For all other preferences, set the summary to the value's // simple string representation. preference.setSummary(stringValue); } return true; }
Example #15
Source File: SettingsFragment.java From aMuleRemote with GNU General Public License v3.0 | 6 votes |
private void setPreferenceSummary(String key, String value) { if (DEBUG) Log.d(TAG, "SettingsFragment.setPreferenceSummary(): Setting summary for " + key + " and value " + value); String summary = value; if (key.equals(AmuleRemoteApplication.AC_SETTING_AUTOREFRESH_INTERVAL)) { summary = getString(R.string.settings_summary_client_autorefresh_interval, Integer.parseInt(value)); } else if (key.equals(AmuleRemoteApplication.AC_SETTING_CONNECT_TIMEOUT)) { summary = getString(R.string.settings_summary_client_connect_timeout, Integer.parseInt(value)); } else if (key.equals(AmuleRemoteApplication.AC_SETTING_READ_TIMEOUT)) { summary = getString(R.string.settings_summary_client_read_timeout, Integer.parseInt(value)); } Preference p = mPrefGroup.findPreference(key); if (p != null) { // null in cas of change of a preference not displayed here p.setSummary(summary); } }
Example #16
Source File: CustomInputStyleSettingsFragment.java From Indic-Keyboard with Apache License 2.0 | 6 votes |
static void updateCustomInputStylesSummary(final Preference pref) { // When we are called from the Settings application but we are not already running, some // singleton and utility classes may not have been initialized. We have to call // initialization method of these classes here. See {@link LatinIME#onCreate()}. SubtypeLocaleUtils.init(pref.getContext()); final Resources res = pref.getContext().getResources(); final SharedPreferences prefs = pref.getSharedPreferences(); final String prefSubtype = Settings.readPrefAdditionalSubtypes(prefs, res); final InputMethodSubtype[] subtypes = AdditionalSubtypeUtils.createAdditionalSubtypesArray(prefSubtype); final ArrayList<String> subtypeNames = new ArrayList<>(); for (final InputMethodSubtype subtype : subtypes) { subtypeNames.add(SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(subtype)); } // TODO: A delimiter of custom input styles should be localized. pref.setSummary(TextUtils.join(", ", subtypeNames)); }
Example #17
Source File: BraceletSettingsFragment.java From MiBandDecompiled with Apache License 2.0 | 6 votes |
public boolean onPreferenceTreeClick(PreferenceScreen preferencescreen, Preference preference) { if (preference.getKey().equals("settings_bracelet_reset")) { b(); return true; } if (!preference.getKey().equals("settings_fw_upgrade")) goto _L2; else goto _L1 _L1: e(); _L4: return super.onPreferenceTreeClick(preferencescreen, preference); _L2: if (preference.getKey().equals("settings_push_goals_progress")) { c(); } if (true) goto _L4; else goto _L3 _L3: }
Example #18
Source File: AboutFragment.java From android with MIT License | 6 votes |
@Override public boolean onPreferenceClick(Preference preference) { final String key = preference.getKey(); if (ONBOARDING.equals(key)) { startActivity(TutorialActivity.newIntent(getActivity(), false)); } else if (RATE_APP.equals(key)) { AppRate.setRateDialogAgreed(getActivity()); /** * Launch Playstore to rate app */ final Intent viewIntent = new Intent(Intent.ACTION_VIEW); viewIntent.setData(Uri.parse(getResources().getString(R.string.url_playstore))); startActivity(viewIntent); } else if (TERMS.equals(key) || FAQ.equals(key) || PRIVACY.equals(key)) { startActivity(WebViewActivity.newIntent(getActivity(), key)); } return false; }
Example #19
Source File: PrivacyFragment.java From MHViewer with Apache License 2.0 | 5 votes |
@Override public void onResume() { super.onResume(); Preference patternProtection = findPreference(KEY_PATTERN_PROTECTION); patternProtection.setSummary(TextUtils.isEmpty(Settings.getSecurity()) ? R.string.settings_privacy_pattern_protection_not_set : R.string.settings_privacy_pattern_protection_set); }
Example #20
Source File: VideoBlockerPreferenceFragment.java From SkyTube with GNU General Public License v3.0 | 5 votes |
/** * Initialized the channel whitelist preference. */ private void initChannelWhitelistingPreference(final Preference channelWhitelistPreference) { channelWhitelistPreference.setOnPreferenceClickListener(preference -> { new WhitelistChannelsDialog(getActivity()).show(); return true; }); }
Example #21
Source File: Preferences.java From xDrip with GNU General Public License v3.0 | 5 votes |
@Override public boolean onPreferenceChange(Preference preference, Object value) { boolean do_update = false; // detect not first run if (preference.getTitle().toString().contains("(")) { do_update = true; } preference.setTitle(preference.getTitle().toString().replaceAll(" \\([a-z0-9A-Z]+\\)$", "") + " (" + value.toString() + ")"); if (do_update) { preference.getEditor().putInt(preference.getKey(), (int)value).apply(); // update prefs now } return true; }
Example #22
Source File: TwoFactorPreferenceFragment.java From GreenBits with GNU General Public License v3.0 | 5 votes |
@Override public boolean onPreferenceClick(final Preference preference) { if (preference == mLimitsPref) return onLimitsPreferenceClicked(preference); if (preference == mSendNLocktimePref) return onSendNLocktimeClicked(preference); if (preference == mTwoFactorResetPref) return onTwoFactorResetClicked(); return false; }
Example #23
Source File: SeekBarPreference.java From MaxLock with GNU General Public License v3.0 | 5 votes |
@Override public void onDependencyChanged(Preference dependency, boolean disableDependent) { super.onDependencyChanged(dependency, disableDependent); //Disable movement of seek bar when dependency is false if (mSeekBar != null) { mSeekBar.setEnabled(!disableDependent); } }
Example #24
Source File: ActivitySettings.java From tracker-control-android with GNU General Public License v3.0 | 5 votes |
private void updateTechnicalInfo() { PreferenceScreen screen = getPreferenceScreen(); Preference pref_technical_info = screen.findPreference("technical_info"); Preference pref_technical_network = screen.findPreference("technical_network"); pref_technical_info.setSummary(Util.getGeneralInfo(this)); pref_technical_network.setSummary(Util.getNetworkInfo(this)); }
Example #25
Source File: Preferences.java From xDrip with GNU General Public License v3.0 | 5 votes |
@Override public boolean onPreferenceChange(Preference preference, Object newValue) { Context context = preference.getContext(); if (AppWidgetManager.getInstance(context).getAppWidgetIds(new ComponentName(context, xDripWidget.class)).length > 0) { context.startService(new Intent(context, WidgetUpdateService.class)); } return true; }
Example #26
Source File: BrailleBackPreferencesActivity.java From brailleback with Apache License 2.0 | 5 votes |
/** * Assigns the appropriate intent to the key bindings preference. */ private void assignKeyBindingsIntent() { Preference pref = findPreferenceByResId(R.string.pref_key_bindings_key); final Intent intent = new Intent(this, KeyBindingsActivity.class); pref.setIntent(intent); }
Example #27
Source File: SettingsActivity.java From privacy-friendly-interval-timer with GNU General Public License v3.0 | 5 votes |
/** * Binds a preference's summary to its value. More specifically, when the * preference's value is changed, its summary (line of text below the * preference title) is updated to reflect the value. The summary is also * immediately updated upon calling this method. The exact display format is * dependent on the type of preference. * * @see #sBindPreferenceSummaryToValueListener */ private static void bindPreferenceSummaryToValue(Preference preference) { // Set the listener to watch for value changes. preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener); // Trigger the listener immediately with the preference's // current value. sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, PreferenceManager .getDefaultSharedPreferences(preference.getContext()) .getString(preference.getKey(), "")); }
Example #28
Source File: CustomListPreference.java From android-kernel-tweaker with GNU General Public License v3.0 | 5 votes |
public void updateDb( final Preference p, final String value,final boolean isChecked) { class LongOperation extends AsyncTask<String, Void, String> { @Override protected String doInBackground(String... params) { if(isChecked) { List<DataItem> items = db.getAllItems(); for(DataItem item : items) { if(item.getName().equals("'"+p.getKey()+"'")) { db.deleteItemByName("'"+p.getKey()+"'"); } } db.addItem(new DataItem("'"+p.getKey()+"'", value, p.getTitle().toString(), category)); } else { if(db.getContactsCount() != 0) { db.deleteItemByName("'"+p.getKey()+"'"); } } return "Executed"; } @Override protected void onPostExecute(String result) { items = db.getAllItems(); } } new LongOperation().execute(); }
Example #29
Source File: ServerSettingsFragment.java From aMuleRemote with GNU General Public License v3.0 | 5 votes |
private void setPreferenceSummary(String key, String value) { if (DEBUG) Log.d(TAG, "SererSettingsFragment.setPreferenceSummary(): Setting summary for " + key + " and value " + value); String summary = value; if (key.equals(ServerSettingsActivity.SETTINGS_SERVER_NAME)) { summary = (value.length() > 0 ? value : getString(R.string.settings_summary_server_name)); } else if (key.equals(ServerSettingsActivity.SETTINGS_SERVER_HOST)) { summary = (value.length() > 0 ? value : getString(R.string.settings_summary_server_host)); } else if (key.equals(ServerSettingsActivity.SETTINGS_SERVER_PASSWORD)) { summary = (value.length() > 0 ? "******" : getResources().getString(R.string.settings_summary_server_password)); } else if (key.equals(ServerSettingsActivity.SETTINGS_SERVER_VERSION)) { String[] versionDescription = getResources().getStringArray(R.array.settings_server_version_description); String[] versionValue = getResources().getStringArray(R.array.settings_server_version_value); summary = getResources().getString(R.string.settings_summary_server_version); for (int i = 0; i < versionValue.length; i++) { if (value.equals(versionValue[i])) { summary = versionDescription[i]; break; } } } Preference p = mPrefGroup.findPreference(key); if (p != null) { // null in cas of change of a preference not displayed here p.setSummary(summary); } }
Example #30
Source File: ProListPreference.java From Noyze with Apache License 2.0 | 5 votes |
@Override public boolean onPreferenceChange(Preference pref, Object value) { mAccountant = Accountant.getInstance(getContext()); LogUtils.LOGI(ProListPreference.class.getSimpleName(), "onPreferenceChange(" + String.valueOf(value) + "), mAccountant = " + mAccountant); if (mAccountant.has(sku) == Boolean.TRUE) { return true; } else { mAccountant.buy((Activity) getContext(), sku); return false; } }