Java Code Examples for android.preference.Preference#setOnPreferenceClickListener()
The following examples show how to use
android.preference.Preference#setOnPreferenceClickListener() .
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: PreferenceCompatFragment.java From Audinaut with GNU General Public License v3.0 | 6 votes |
private PreferenceScreen addPreferencesFromResource(int resId) { requirePreferenceManager(); PreferenceScreen screen = inflateFromResource(getActivity(), resId, getPreferenceScreen()); setPreferenceScreen(screen); for (int i = 0; i < screen.getPreferenceCount(); i++) { Preference preference = screen.getPreference(i); if (preference instanceof PreferenceScreen && preference.getKey() != null) { preference.setOnPreferenceClickListener(preference1 -> { onStartNewFragment(preference1.getKey()); return false; }); } } return screen; }
Example 2
Source File: SettingsActivity.java From rpicheck with MIT License | 6 votes |
@SuppressWarnings("deprecation") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); // adding preference listener to log / changelog Preference prefLog = findPreference(KEY_PREF_LOG); prefLog.setOnPreferenceClickListener(this); Preference prefChangelog = findPreference(KEY_PREF_CHANGELOG); prefChangelog.setOnPreferenceClickListener(this); findPreference("pref_app_version").setSummary(BuildConfig.VERSION_NAME); // init summary texts to reflect users choice this.initSummaries(); }
Example 3
Source File: SettingsActivity.java From lrkFM with MIT License | 6 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences_general); setHasOptionsMenu(true); try { Preference app_version = findPreference("app_version"); app_version.setSummary(getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0).versionName); app_version.setOnPreferenceClickListener(preference -> { c++; if (c % 8 == 0) { GlitchEffect.showGlitch(getActivity()); } return true; }); } catch (PackageManager.NameNotFoundException e) { Log.e(TAG, "Unable to get App version!", e); } addOnPreferenceChangeListeners(this.getPreferenceScreen()); }
Example 4
Source File: MobileMainActivity.java From android-wear-gopro-remote with Apache License 2.0 | 6 votes |
private void bindPreferenceSummaryToValue(Preference preference) { // Set the listener to watch for value changes. preference.setOnPreferenceChangeListener(this); preference.setOnPreferenceClickListener(this); Object value = null; if(preference instanceof CheckBoxPreference) { value = ((CheckBoxPreference)preference).isChecked(); } else if(preference instanceof ListPreference) { value = ((ListPreference)preference).getValue(); } else if(preference instanceof EditTextPreference) { value = ((EditTextPreference)preference).getText(); } // Trigger the listener immediately with the preference's // current value. if(value != null) { this.onPreferenceChange(preference, value); } }
Example 5
Source File: PreferenceFragment.java From AndroidBottomSheet with Apache License 2.0 | 6 votes |
/** * Initializes the preference, which allows to display the applications, which are suited for * handling an intent. */ private void initializeShowIntentBottmSheetPreference() { Preference showIntentBottomSheetPreference = findPreference(getString(R.string.show_intent_bottom_sheet_preference_key)); showIntentBottomSheetPreference .setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { initializeIntentBottomSheet(); intentBottomSheet.show(); return true; } }); }
Example 6
Source File: AdvancedFragment.java From MHViewer with Apache License 2.0 | 6 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.advanced_settings); Preference dumpLogcat = findPreference(KEY_DUMP_LOGCAT); Preference clearMemoryCache = findPreference(KEY_CLEAR_MEMORY_CACHE); Preference appLanguage = findPreference(KEY_APP_LANGUAGE); Preference exportData = findPreference(KEY_EXPORT_DATA); Preference importData = findPreference(KEY_IMPORT_DATA); Preference importRecord = findPreference(KEY_IMPORT_RECORD); dumpLogcat.setOnPreferenceClickListener(this); clearMemoryCache.setOnPreferenceClickListener(this); exportData.setOnPreferenceClickListener(this); importData.setOnPreferenceClickListener(this); importRecord.setOnPreferenceClickListener(this); appLanguage.setOnPreferenceChangeListener(this); }
Example 7
Source File: AdvancedFragment.java From EhViewer with Apache License 2.0 | 6 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.advanced_settings); Preference dumpLogcat = findPreference(KEY_DUMP_LOGCAT); Preference clearMemoryCache = findPreference(KEY_CLEAR_MEMORY_CACHE); Preference appLanguage = findPreference(KEY_APP_LANGUAGE); Preference importData = findPreference(KEY_IMPORT_DATA); dumpLogcat.setOnPreferenceClickListener(this); clearMemoryCache.setOnPreferenceClickListener(this); importData.setOnPreferenceClickListener(this); appLanguage.setOnPreferenceChangeListener(this); }
Example 8
Source File: DeveloperPreferences.java From narrate-android with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.developer_preferences); findPreference("disable").setOnPreferenceClickListener(this); // mLogging = (CheckBoxPreference) findPreference("logging_enabled"); // mLogging.setChecked(GlobalApplication.getUser().loggingEnabled); if (BuildConfig.DEBUG) { Preference pref = new Preference(this); pref.setTitle("Prepare for screenshots"); pref.setSummary("Clears all data and adds entries for screenshots"); pref.setKey("screenshots"); pref.setOnPreferenceClickListener(this); getPreferenceScreen().addPreference(pref); } }
Example 9
Source File: DisplaySettingsFragment.java From Xndroid with GNU General Public License v3.0 | 5 votes |
private void initPrefs() { // mPreferences storage mThemeOptions = this.getResources().getStringArray(R.array.themes); mCurrentTheme = mPreferenceManager.getUseTheme(); mTheme = findPreference(SETTINGS_THEME); Preference textSize = findPreference(SETTINGS_TEXTSIZE); CheckBoxPreference cbStatus = (CheckBoxPreference) findPreference(SETTINGS_HIDESTATUSBAR); CheckBoxPreference cbFullScreen = (CheckBoxPreference) findPreference(SETTINGS_FULLSCREEN); CheckBoxPreference cbViewPort = (CheckBoxPreference) findPreference(SETTINGS_VIEWPORT); CheckBoxPreference cbOverview = (CheckBoxPreference) findPreference(SETTINGS_OVERVIEWMODE); CheckBoxPreference cbReflow = (CheckBoxPreference) findPreference(SETTINGS_REFLOW); CheckBoxPreference cbBlackStatus = (CheckBoxPreference) findPreference(SETTINGS_BLACK_STATUS); CheckBoxPreference cbDrawerTabs = (CheckBoxPreference) findPreference(SETTINGS_DRAWERTABS); CheckBoxPreference cbSwapTabs = (CheckBoxPreference) findPreference(SETTINGS_SWAPTABS); mTheme.setOnPreferenceClickListener(this); textSize.setOnPreferenceClickListener(this); cbStatus.setOnPreferenceChangeListener(this); cbFullScreen.setOnPreferenceChangeListener(this); cbViewPort.setOnPreferenceChangeListener(this); cbOverview.setOnPreferenceChangeListener(this); cbReflow.setOnPreferenceChangeListener(this); cbBlackStatus.setOnPreferenceChangeListener(this); cbDrawerTabs.setOnPreferenceChangeListener(this); cbSwapTabs.setOnPreferenceChangeListener(this); cbStatus.setChecked(mPreferenceManager.getHideStatusBarEnabled()); cbFullScreen.setChecked(mPreferenceManager.getFullScreenEnabled()); cbViewPort.setChecked(mPreferenceManager.getUseWideViewportEnabled()); cbOverview.setChecked(mPreferenceManager.getOverviewModeEnabled()); cbReflow.setChecked(mPreferenceManager.getTextReflowEnabled()); cbBlackStatus.setChecked(mPreferenceManager.getUseBlackStatusBar()); cbDrawerTabs.setChecked(mPreferenceManager.getShowTabsInDrawer(true)); cbSwapTabs.setChecked(mPreferenceManager.getBookmarksAndTabsSwapped()); mTheme.setSummary(mThemeOptions[mPreferenceManager.getUseTheme()]); }
Example 10
Source File: Pref.java From GeoLog with Apache License 2.0 | 5 votes |
public static Preference Preference(Context context, PreferenceCategory category, int caption, int summary, boolean enabled, Preference.OnPreferenceClickListener onClick) { Preference retval = new Preference(context); if (caption > 0) retval.setTitle(caption); if (summary > 0) retval.setSummary(summary); retval.setEnabled(enabled); if (onClick != null) { retval.setOnPreferenceClickListener(onClick); } if (category != null) category.addPreference(retval); return retval; }
Example 11
Source File: AboutFragment.java From EhViewer with Apache License 2.0 | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.about_settings); Preference author = findPreference(KEY_AUTHOR); Preference donate = findPreference(KEY_DONATE); Preference checkForUpdate = findPreference(KEY_CHECK_FOR_UPDATES); author.setSummary(getString(R.string.settings_about_author_summary).replace('$', '@')); author.setOnPreferenceClickListener(this); donate.setOnPreferenceClickListener(this); checkForUpdate.setOnPreferenceClickListener(this); }
Example 12
Source File: SettingsFragment.java From NekoSMS with GNU General Public License v3.0 | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // General settings addPreferencesFromResource(R.xml.settings); if (!XposedUtils.isModuleEnabled()) { Preference enablePreference = findPreference(PreferenceConsts.KEY_ENABLE); enablePreference.setEnabled(false); enablePreference.setSummary(R.string.pref_enable_summary_alt); } // Notification settings if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { addPreferencesFromResource(R.xml.settings_notifications_v26); Preference settingsPreference = findPreference(PreferenceConsts.KEY_NOTIFICATIONS_OPEN_SETTINGS); settingsPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS); intent.putExtra(Settings.EXTRA_APP_PACKAGE, NEKOSMS_PACKAGE); startActivity(intent); return true; } }); } else { addPreferencesFromResource(R.xml.settings_notifications); } }
Example 13
Source File: SettingsFragment.java From yahnac with Apache License 2.0 | 5 votes |
private void addPreferenceClickListenerForSoftwareLicenses() { Preference licensesPreference = findPreference(getString(R.string.settings_key_software_licences)); licensesPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Intent softwareLicenses = new Intent(getActivity(), SoftwareLicensesActivity.class); startActivity(softwareLicenses); return true; } }); }
Example 14
Source File: SettingsActivity.java From busybox with GNU General Public License v2.0 | 5 votes |
/** * Recursive set summaries * * @param pg group */ private void initSummaries(PreferenceGroup pg) { for (int i = 0; i < pg.getPreferenceCount(); ++i) { Preference p = pg.getPreference(i); if (p instanceof PreferenceGroup) initSummaries((PreferenceGroup) p); else setSummary(p, false); if (p instanceof PreferenceScreen) p.setOnPreferenceClickListener(this); } }
Example 15
Source File: Utils.java From VIA-AI with MIT License | 5 votes |
public static void setClickToSelectDirectory(final Context context, final Preference pref) { pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { postFileDialog(context, pref, "", false); return false; } }); }
Example 16
Source File: AdvancedPrefFragment.java From Onosendai with Apache License 2.0 | 5 votes |
private void addImportConfPref () { final Preference pref = new Preference(getActivity()); pref.setTitle("Import deck.conf"); //ES if (Config.isConfigFilePresent()) { pref.setSummary("Replace existing configuration"); //ES pref.setOnPreferenceClickListener(this.importClickListener); } else { pref.setSummary("File not found: " + Config.configFile().getAbsolutePath()); pref.setEnabled(false); } getPreferenceScreen().addPreference(pref); }
Example 17
Source File: AvailableDevicesFragment.java From wearmouse with Apache License 2.0 | 5 votes |
protected void initScanDevices(Preference pref) { if (bluetoothAdapter.isDiscovering()) { pref.setEnabled(false); } pref.setOnPreferenceClickListener( (p) -> { clearAvailableDevices(); startDiscovery(); return true; }); }
Example 18
Source File: BackupPreferenceFragment.java From SkyTube with GNU General Public License v3.0 | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preference_backup); subscriptionsBackupsManager = new SubscriptionsBackupsManager(getActivity(), this); // backup/export databases Preference backupDbsPref = findPreference(getString(R.string.pref_key_backup_dbs)); backupDbsPref.setOnPreferenceClickListener(preference -> { subscriptionsBackupsManager.backupDatabases(); return true; }); // import databases Preference importBackupsPref = findPreference(getString(R.string.pref_key_import_dbs)); importBackupsPref.setOnPreferenceClickListener(preference -> { subscriptionsBackupsManager.displayFilePicker(); return true; }); // import from youtube Preference importSubsPref = findPreference(getString(R.string.pref_key_import_subs)); importSubsPref.setOnPreferenceClickListener(preference -> { subscriptionsBackupsManager.displayImportSubscriptionsFromYouTubeDialog(); return true; }); }
Example 19
Source File: XmlSettingsActivity.java From WhereYouGo with GNU General Public License v3.0 | 4 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setTitle(R.string.settings); needRestart = false; /* workaround: I don't really know why I cannot call CustomActivity.customOnCreate(this); - OMG! */ switch (Preferences.APPEARANCE_FONT_SIZE) { case PreferenceValues.VALUE_FONT_SIZE_SMALL: this.setTheme(R.style.FontSizeSmall); break; case PreferenceValues.VALUE_FONT_SIZE_MEDIUM: this.setTheme(R.style.FontSizeMedium); break; case PreferenceValues.VALUE_FONT_SIZE_LARGE: this.setTheme(R.style.FontSizeLarge); break; } /* * */ addPreferencesFromResource(R.xml.whereyougo_preferences); PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this); /* * Remove internal preferences */ Preference somePreference = findPreference(R.string.pref_KEY_X_HIDDEN_PREFERENCES); PreferenceScreen preferenceScreen = getPreferenceScreen(); preferenceScreen.removePreference(somePreference); /* * Register OnClick handler */ Preference preferenceRoot = findPreference(R.string.pref_KEY_S_ROOT); preferenceRoot.setOnPreferenceClickListener(this); Preference preferenceAbout = findPreference(R.string.pref_KEY_X_ABOUT); if (preferenceAbout != null) { preferenceAbout.setOnPreferenceClickListener(this); } /* * Workaround: Update/set value preview */ // String dir = Preferences.getStringPreference( R.string.pref_KEY_S_ROOT ); // x.setSummary( "(" + dir + ") " + Locale.getString( R.string.pref_root_desc ) ); // TODO make it better :-( /* TODO - check this code */ if (!Utils.isAndroid201OrMore()) { Preference prefSensorFilter = findPreference(R.string.pref_KEY_S_SENSORS_ORIENT_FILTER); if (prefSensorFilter != null) { prefSensorFilter.setEnabled(false); } } if (getIntent() != null && getIntent().hasExtra(getString(R.string.pref_KEY_X_LOGIN_PREFERENCES))) { Preference preferenceLogin = findPreference(R.string.pref_KEY_X_LOGIN_PREFERENCES); if (preferenceLogin != null) { PreferenceScreen screen = getPreferenceScreen(); for (int i = 0; i < screen.getPreferenceCount(); ++i) { if (screen.getPreference(i) == preferenceLogin) { getIntent().putExtra(getString(R.string.pref_KEY_X_LOGIN_PREFERENCES), false); screen.onItemClick(null, null, i, 0); break; } } } } /* * Enable/disable status bar propertie */ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { CheckBoxPreference status_bar = (CheckBoxPreference) findPreference(R.string.pref_KEY_B_STATUSBAR); CheckBoxPreference gps_hide = (CheckBoxPreference) findPreference(R.string.pref_KEY_B_GPS_DISABLE_WHEN_HIDE); CheckBoxPreference gps_guiding = (CheckBoxPreference) findPreference(R.string.pref_KEY_B_GUIDING_GPS_REQUIRED); if (gps_hide.isChecked()) { status_bar.setEnabled(!gps_guiding.isChecked()); } else { status_bar.setEnabled(false); } } }
Example 20
Source File: GeneralSettingsFragment.java From NotificationPeekPort with Apache License 2.0 | 4 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); // Appearance settings entrance. Preference appearancePref = findPreference(PreferenceKeys.PREF_APPEARANCE); appearancePref.setOnPreferenceClickListener(this); // Clock preference. CheckBoxPreference clockPref = (CheckBoxPreference) findPreference(PreferenceKeys.PREF_CLOCK); clockPref.setOnPreferenceChangeListener(this); // Always show content preference. CheckBoxPreference alwaysShowContentPref = (CheckBoxPreference) findPreference(PreferenceKeys.PREF_ALWAYS_SHOW_CONTENT); alwaysShowContentPref.setOnPreferenceChangeListener(this); // Notification Peek timeout preference. ListPreference peekTimeoutPref = (ListPreference) findPreference(PreferenceKeys.PREF_PEEK_TIMEOUT); peekTimeoutPref.setOnPreferenceChangeListener(this); bindPreferenceSummaryToValue(peekTimeoutPref); // Listen forever preference. ListPreference sensorTimeoutPref = (ListPreference) findPreference(PreferenceKeys.PREF_SENSOR_TIMEOUT); sensorTimeoutPref.setOnPreferenceChangeListener(this); bindPreferenceSummaryToValue(sensorTimeoutPref); // Gyroscope sensor enable/disable preference. CheckBoxPreference gyroPref = (CheckBoxPreference) findPreference(PreferenceKeys.PREF_GYRO_SENSOR); if (!SensorHelper.checkSensorStatus(getActivity(), SensorHelper.SENSOR_GYRO, false)) { // No gyroscope sensor found. gyroPref.setEnabled(false); } else { gyroPref.setEnabled(true); gyroPref.setOnPreferenceChangeListener(this); } // Proximity/Light sensor enable/disable preference. CheckBoxPreference proxPref = (CheckBoxPreference) findPreference(PreferenceKeys.PREF_PROX_LIGHT_SENSOR); if (!SensorHelper .checkSensorStatus(getActivity(), SensorHelper.SENSOR_PROXIMITY_LIGHT, false)) { // No proximity or light sensor found. proxPref.setEnabled(false); } else { proxPref.setEnabled(true); proxPref.setOnPreferenceChangeListener(this); } }