Java Code Examples for androidx.preference.ListPreference#setEntries()
The following examples show how to use
androidx.preference.ListPreference#setEntries() .
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: GeneralPreferenceFragment.java From NClientV2 with Apache License 2.0 | 6 votes |
private void initStoragePaths(ListPreference storagePreference) { if(Build.VERSION.SDK_INT<Build.VERSION_CODES.KITKAT||!Global.hasStoragePermission(act)){ storagePreference.setVisible(false); return; } List<File>files=Global.getUsableFolders(act); List<CharSequence>strings=new ArrayList<>(files.size()); for(File f:files)strings.add(f.getAbsolutePath()); storagePreference.setEntries(strings.toArray(new CharSequence[0])); storagePreference.setEntryValues(strings.toArray(new CharSequence[0])); storagePreference.setSummary( act.getSharedPreferences("Settings",Context.MODE_PRIVATE) .getString(getString(R.string.key_save_path),Global.MAINFOLDER.getParent()) ); storagePreference.setOnPreferenceChangeListener((preference, newValue) -> { preference.setSummary(newValue.toString()); return true; }); }
Example 2
Source File: WebSearchPreference.java From HgLauncher with GNU General Public License v3.0 | 6 votes |
private void setProviderList(ListPreference list) { List<String> entries = new ArrayList<>(); List<String> entryValues = new ArrayList<>(); entries.add(getString(R.string.search_provider_none)); entryValues.add(getString(R.string.gesture_action_default_value)); // We only need the key as the value is stored in PreferenceHelper's Map. for (Map.Entry<String, String> provider : PreferenceHelper .getProviderList().entrySet()) { entries.add(provider.getKey()); entryValues.add(provider.getKey()); } CharSequence[] finalEntries = entries.toArray(new CharSequence[0]); CharSequence[] finalEntryValues = entryValues.toArray(new CharSequence[0]); list.setEntries(finalEntries); list.setEntryValues(finalEntryValues); }
Example 3
Source File: NotificationPreferenceFragment.java From intra42 with Apache License 2.0 | 6 votes |
private void updateCalendarList() { SparseArray<String> calendar = Calendar.getCalendarList(requireActivity()); ListPreference prefListCalendar = findPreference(AppSettings.Notifications.SELECTED_CALENDAR); if (prefListCalendar == null) return; if (calendar != null) { CharSequence[] entryKey = new String[calendar.size()]; CharSequence[] entryValues = new String[calendar.size()]; for (int i = 0; i < calendar.size(); i++) { int key = calendar.keyAt(i); entryKey[i] = String.valueOf(key); entryValues[i] = calendar.get(key); } prefListCalendar.setEntries(entryValues); prefListCalendar.setEntryValues(entryKey); } }
Example 4
Source File: WebSearchPreference.java From HgLauncher with GNU General Public License v3.0 | 6 votes |
private void setProviderList(ListPreference list) { List<String> entries = new ArrayList<>(); List<String> entryValues = new ArrayList<>(); entries.add(getString(R.string.search_provider_none)); entryValues.add(getString(R.string.gesture_action_default_value)); // We only need the key as the value is stored in PreferenceHelper's Map. for (Map.Entry<String, String> provider : PreferenceHelper .getProviderList().entrySet()) { entries.add(provider.getKey()); entryValues.add(provider.getKey()); } CharSequence[] finalEntries = entries.toArray(new CharSequence[0]); CharSequence[] finalEntryValues = entryValues.toArray(new CharSequence[0]); list.setEntries(finalEntries); list.setEntryValues(finalEntryValues); }
Example 5
Source File: RtspPreferenceActivity.java From DeviceConnect-Android with MIT License | 6 votes |
@Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { setPreferencesFromResource(R.xml.preferences, rootKey); EditTextPreference url = findPreference(getString(R.string.key_server_url)); if (url != null) { url.setText(getServerUrl()); } ListPreference videoResolution = findPreference(getString(R.string.key_video_resolution)); if (videoResolution != null) { String[] entries = createCameraResolutions(getContext()); videoResolution.setEntries(entries); videoResolution.setEntryValues(entries); } setInputTypeNumber(R.string.key_server_port); setInputTypeNumber(R.string.key_video_bit_rate); setInputTypeNumber(R.string.key_video_frame_rate); setInputTypeNumber(R.string.key_video_iframe_interval); setInputTypeNumber(R.string.key_audio_bit_rate); }
Example 6
Source File: SettingsActivity.java From call_manage with MIT License | 5 votes |
private void setupSimSelection() { if (!Utilities.checkPermissionGranted(getContext(), READ_PHONE_STATE)) { Toast.makeText(getContext(), "No permission, please give permission to read phone state", Toast.LENGTH_LONG).show(); return; } ListPreference simSelectionPreference = (ListPreference) findPreference(getString(R.string.pref_sim_select_key)); @SuppressLint("MissingPermission") List<SubscriptionInfo> subscriptionInfoList = SubscriptionManager.from(getContext()).getActiveSubscriptionInfoList(); int simCount = subscriptionInfoList.size(); if (simCount == 1) { simSelectionPreference.setSummary(getString(R.string.pref_sim_select_disabled)); simSelectionPreference.setEnabled(false); } else { List<CharSequence> simsEntries = new ArrayList<>(); for (int i = 0; i < simCount; i++) { SubscriptionInfo si = subscriptionInfoList.get(i); Timber.i("Sim info " + i + " : " + si.getDisplayName()); simsEntries.add(si.getDisplayName()); } CharSequence[] simsEntriesList = simsEntries.toArray(new CharSequence[simsEntries.size()]); simSelectionPreference.setEntries(simsEntriesList); // simsEntries.add(getString(R.string.pref_sim_select_ask_entry)); // CharSequence[] simsEntryValues = {"0", "1", "2"}; CharSequence[] simsEntryValues = {"0", "1"}; simSelectionPreference.setEntryValues(simsEntryValues); } }
Example 7
Source File: GeneralPreferenceFragment.java From green_android with GNU General Public License v3.0 | 5 votes |
private void setTimeoutValues(final ListPreference preference) { final CharSequence[] entries = preference.getEntryValues(); final int length = entries.length; final String[] entryValues = new String[length]; for (int i = 0; i < length; i++) { final int currentMinutes = Integer.valueOf(entries[i].toString()); final String minutesText = currentMinutes == 1 ? "1 " + getString(R.string.id_minute) : getString(R.string.id_1d_minutes, currentMinutes); entryValues[i] = minutesText; } preference.setEntries(entryValues); }
Example 8
Source File: AppListPreference.java From HgLauncher with GNU General Public License v3.0 | 5 votes |
private void setIconList(ListPreference list) { PackageManager manager = requireActivity().getPackageManager(); List<String> entries = new ArrayList<>(); List<String> entryValues = new ArrayList<>(); // Get default value. entries.add(getString(R.string.icon_pack_default)); entryValues.add(getString(R.string.icon_pack_default_value)); // Fetch all available icon pack. Intent intent = new Intent("org.adw.launcher.THEMES"); List<ResolveInfo> info = manager.queryIntentActivities(intent, PackageManager.GET_META_DATA); for (ResolveInfo resolveInfo : info) { ActivityInfo activityInfo = resolveInfo.activityInfo; String packageName = activityInfo.packageName; String appName = activityInfo.loadLabel(manager).toString(); entries.add(appName); entryValues.add(packageName); } CharSequence[] finalEntries = entries.toArray(new CharSequence[0]); CharSequence[] finalEntryValues = entryValues.toArray(new CharSequence[0]); list.setEntries(finalEntries); list.setEntryValues(finalEntryValues); }
Example 9
Source File: GesturesPreference.java From HgLauncher with GNU General Public License v3.0 | 5 votes |
private void setGestureHandlerList(ListPreference list) { PackageManager manager = requireActivity().getPackageManager(); List<String> entries = new ArrayList<>(); List<String> entryValues = new ArrayList<>(); // Get default value. entries.add(getString(R.string.gesture_handler_default)); entryValues.add(getString(R.string.gesture_handler_default_value)); // Fetch all available icon pack. Intent intent = new Intent("mono.hg.GESTURE_HANDLER"); List<ResolveInfo> info = manager.queryIntentActivities(intent, PackageManager.GET_RESOLVED_FILTER); for (ResolveInfo resolveInfo : info) { ActivityInfo activityInfo = resolveInfo.activityInfo; String className = activityInfo.name; String packageName = activityInfo.packageName; String componentName = packageName + "/" + className; String appName = activityInfo.loadLabel(manager).toString(); entries.add(appName); entryValues.add(componentName); } CharSequence[] finalEntries = entries.toArray(new CharSequence[0]); CharSequence[] finalEntryValues = entryValues.toArray(new CharSequence[0]); list.setEntries(finalEntries); list.setEntryValues(finalEntryValues); }
Example 10
Source File: PolicyManagementFragment.java From android-testdpc with Apache License 2.0 | 5 votes |
private void onCreateSetNewPasswordWithComplexityPreference() { ListPreference complexityPref = (ListPreference) findPreference(SET_NEW_PASSWORD_WITH_COMPLEXITY); List<CharSequence> entries = new ArrayList<>(); List<CharSequence> values = new ArrayList<>(); int size = PASSWORD_COMPLEXITY.size(); for (int i = 0; i < size; i++) { entries.add(getString(PASSWORD_COMPLEXITY.valueAt(i))); values.add(Integer.toString(PASSWORD_COMPLEXITY.keyAt(i))); } complexityPref.setEntries(entries.toArray(new CharSequence[size])); complexityPref.setEntryValues(values.toArray(new CharSequence[size])); complexityPref.setOnPreferenceChangeListener(this); }
Example 11
Source File: AppListPreference.java From HgLauncher with GNU General Public License v3.0 | 5 votes |
private void setIconList(ListPreference list) { PackageManager manager = requireActivity().getPackageManager(); List<String> entries = new ArrayList<>(); List<String> entryValues = new ArrayList<>(); // Get default value. entries.add(getString(R.string.icon_pack_default)); entryValues.add(getString(R.string.icon_pack_default_value)); // Fetch all available icon pack. Intent intent = new Intent("org.adw.launcher.THEMES"); List<ResolveInfo> info = manager.queryIntentActivities(intent, PackageManager.GET_META_DATA); for (ResolveInfo resolveInfo : info) { ActivityInfo activityInfo = resolveInfo.activityInfo; String packageName = activityInfo.packageName; String appName = activityInfo.loadLabel(manager).toString(); entries.add(appName); entryValues.add(packageName); } CharSequence[] finalEntries = entries.toArray(new CharSequence[0]); CharSequence[] finalEntryValues = entryValues.toArray(new CharSequence[0]); list.setEntries(finalEntries); list.setEntryValues(finalEntryValues); }
Example 12
Source File: GesturesPreference.java From HgLauncher with GNU General Public License v3.0 | 5 votes |
private void setGestureHandlerList(ListPreference list) { PackageManager manager = requireActivity().getPackageManager(); List<String> entries = new ArrayList<>(); List<String> entryValues = new ArrayList<>(); // Get default value. entries.add(getString(R.string.gesture_handler_default)); entryValues.add(getString(R.string.gesture_handler_default_value)); // Fetch all available icon pack. Intent intent = new Intent("mono.hg.GESTURE_HANDLER"); List<ResolveInfo> info = manager.queryIntentActivities(intent, PackageManager.GET_RESOLVED_FILTER); for (ResolveInfo resolveInfo : info) { ActivityInfo activityInfo = resolveInfo.activityInfo; String className = activityInfo.name; String packageName = activityInfo.packageName; String componentName = packageName + "/" + className; String appName = activityInfo.loadLabel(manager).toString(); entries.add(appName); entryValues.add(componentName); } CharSequence[] finalEntries = entries.toArray(new CharSequence[0]); CharSequence[] finalEntryValues = entryValues.toArray(new CharSequence[0]); list.setEntries(finalEntries); list.setEntryValues(finalEntryValues); }
Example 13
Source File: SettingsFragment.java From Kore with Apache License 2.0 | 5 votes |
private void setupLanguagePreference(final ListPreference languagePref) { Locale[] locales = getLocales(); final Locale currentLocale = getCurrentLocale(); Arrays.sort(locales, new Comparator<Locale>() { @Override public int compare(Locale o1, Locale o2) { return o1.getDisplayName().compareToIgnoreCase(o2.getDisplayName()); } }); String[] displayNames = new String[locales.length]; String[] entryValues = new String[locales.length]; for(int index = 0; index < locales.length; index++) { Locale locale = locales[index]; displayNames[index] = locale.getDisplayName(locale); entryValues[index] = getLanguageCountryCode(locale); } languagePref.setValue(getLanguageCountryCode(currentLocale)); languagePref.setEntries(displayNames); languagePref.setEntryValues(entryValues); languagePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object o) { languagePref.setValue(o.toString()); updatePreferredLanguage(o.toString()); return true; } }); }
Example 14
Source File: PasswordConstraintsFragment.java From android-testdpc with Apache License 2.0 | 4 votes |
@Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { addPreferencesFromResource(R.xml.password_constraint_preferences); mMinLength = (DpcPreferenceBase) findPreference(Keys.MIN_LENGTH); mMinLetters = (DpcPreferenceBase) findPreference(Keys.MIN_LETTERS); mMinNumeric = (DpcPreferenceBase) findPreference(Keys.MIN_NUMERIC); mMinLower = (DpcPreferenceBase) findPreference(Keys.MIN_LOWERCASE); mMinUpper = (DpcPreferenceBase) findPreference(Keys.MIN_UPPERCASE); mMinSymbols = (DpcPreferenceBase) findPreference(Keys.MIN_SYMBOLS); mMinNonLetter = (DpcPreferenceBase) findPreference(Keys.MIN_NONLETTER); // Populate password quality settings - messy because the only API for this requires two // separate String[]s. List<CharSequence> entries = new ArrayList<>(); List<CharSequence> values = new ArrayList<>(); for (Map.Entry<Integer, Integer> entry : PASSWORD_QUALITIES.entrySet()) { values.add(Integer.toString(entry.getKey())); entries.add(getString(entry.getValue())); } ListPreference quality = (ListPreference) findPreference(Keys.QUALITY); quality.setEntries(entries.toArray(new CharSequence[0])); quality.setEntryValues(values.toArray(new CharSequence[0])); // Expiration times. setup(Keys.EXPIRATION_TIME, null); setup(Keys.HISTORY_LENGTH, getDpm().getPasswordHistoryLength(getAdmin())); // Minimum quality requirement. setup(Keys.QUALITY, PASSWORD_QUALITIES.floorKey(getDpm().getPasswordQuality(getAdmin()))); // Minimum length requirements. setup(Keys.MIN_LENGTH, getDpm().getPasswordMinimumLength(getAdmin())); setup(Keys.MIN_LETTERS, getDpm().getPasswordMinimumLetters(getAdmin())); setup(Keys.MIN_NUMERIC, getDpm().getPasswordMinimumNumeric(getAdmin())); setup(Keys.MIN_LOWERCASE, getDpm().getPasswordMinimumLowerCase(getAdmin())); setup(Keys.MIN_UPPERCASE, getDpm().getPasswordMinimumUpperCase(getAdmin())); setup(Keys.MIN_SYMBOLS, getDpm().getPasswordMinimumSymbols(getAdmin())); setup(Keys.MIN_NONLETTER, getDpm().getPasswordMinimumNonLetter(getAdmin())); setPreferencesConstraint(); }
Example 15
Source File: SettingsFragment.java From mlkit-material-android with Apache License 2.0 | 4 votes |
private void setUpRearCameraPreviewSizePreference() { ListPreference previewSizePreference = (ListPreference) findPreference(getString(R.string.pref_key_rear_camera_preview_size)); if (previewSizePreference == null) { return; } Camera camera = null; try { camera = Camera.open(CameraSource.CAMERA_FACING_BACK); List<CameraSizePair> previewSizeList = Utils.generateValidPreviewSizeList(camera); String[] previewSizeStringValues = new String[previewSizeList.size()]; Map<String, String> previewToPictureSizeStringMap = new HashMap<>(); for (int i = 0; i < previewSizeList.size(); i++) { CameraSizePair sizePair = previewSizeList.get(i); previewSizeStringValues[i] = sizePair.preview.toString(); if (sizePair.picture != null) { previewToPictureSizeStringMap.put( sizePair.preview.toString(), sizePair.picture.toString()); } } previewSizePreference.setEntries(previewSizeStringValues); previewSizePreference.setEntryValues(previewSizeStringValues); previewSizePreference.setSummary(previewSizePreference.getEntry()); previewSizePreference.setOnPreferenceChangeListener( (preference, newValue) -> { String newPreviewSizeStringValue = (String) newValue; previewSizePreference.setSummary(newPreviewSizeStringValue); PreferenceUtils.saveStringPreference( getActivity(), R.string.pref_key_rear_camera_picture_size, previewToPictureSizeStringMap.get(newPreviewSizeStringValue)); return true; }); } catch (Exception e) { // If there's no camera for the given camera id, hide the corresponding preference. if (previewSizePreference.getParent() != null) { previewSizePreference.getParent().removePreference(previewSizePreference); } } finally { if (camera != null) { camera.release(); } } }
Example 16
Source File: SettingsFragment.java From prayer-times-android with Apache License 2.0 | 4 votes |
@Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { addPreferencesFromResource(R.xml.settings); if (getArguments() != null && getArguments().getBoolean("showKerahatDuration")) setPreferenceScreen((PreferenceScreen) findPreference("kerahatDuration")); else { /* findPreference("language").setIcon(MaterialDrawableBuilder.with(getActivity()).setIcon(MaterialDrawableBuilder.IconValue.TRANSLATE) .setColor(getResources().getColor(R.color.foregroundSecondary)).build()); findPreference("arabicNames").setIcon(MaterialDrawableBuilder.with(getActivity()).setIcon(MaterialDrawableBuilder.IconValue.CLOCK_OUT) .setColor(getResources().getColor(R.color.foregroundSecondary)).build()); findPreference("digits").setIcon(MaterialDrawableBuilder.with(getActivity()).setIcon(MaterialDrawableBuilder.IconValue.NUMERIC) .setColor(getResources().getColor(R.color.foregroundSecondary)).build()); findPreference("calendarIntegration").setIcon( MaterialDrawableBuilder.with(getActivity()).setIcon(MaterialDrawableBuilder.IconValue.CALENDAR) .setColor(getResources().getColor(R.color.foregroundSecondary)).build()); findPreference("kerahatDuration").setIcon( MaterialDrawableBuilder.with(getActivity()).setIcon(MaterialDrawableBuilder.IconValue.CLOCK_ALERT) .setColor(getResources().getColor(R.color.foregroundSecondary)).build()); */ findPreference("numbers").setOnPreferenceChangeListener(this); findPreference("backupRestore").setOnPreferenceClickListener(this); findPreference("calendarIntegration").setOnPreferenceChangeListener(this); findPreference("ongoingIcon").setOnPreferenceClickListener(this); findPreference("ongoingNumber").setOnPreferenceClickListener(this); findPreference("kerahatDuration").setOnPreferenceClickListener(this); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { findPreference("ongoingNumber").setEnabled(false); } if (Build.VERSION.SDK_INT < 24) findPreference("showLegacyWidgets").setEnabled(false); findPreference("arabicNames").setEnabled(!new Locale("ar").getLanguage().equals(LocaleUtils.getLocale().getLanguage())); ListPreference lang = (ListPreference) findPreference("language"); lang.setOnPreferenceChangeListener(this); List<LocaleUtils.Translation> languages = LocaleUtils.getSupportedLanguages(getActivity()); CharSequence[] entries = new CharSequence[languages.size()]; CharSequence[] values = new CharSequence[languages.size()]; for (int i = 0; i < languages.size(); i++) { LocaleUtils.Translation trans = languages.get(i); entries[i] = trans.getDisplayText(); values[i] = trans.getLanguage(); } lang.setEntries(entries); lang.setEntryValues(values); int[][] colors = {{0, 0}, {0xFFFFFFFF, 0xFF333333}, {0xFFDDDDDD, 0xFF222222}, {0xFFBBBBBB, 0xFF111111}, {0xFF999999, 0xFF000000}, {0xFF666666, 0xFFFFFFFF}, {0xFF444444, 0xFFEEEEEE}, {0xFF222222, 0xFFDDDDDD}, {0xFF000000, 0xFFCCCCCC} }; Preference ongoingColor = findPreference("ongoingColor"); ongoingColor.setOnPreferenceClickListener(e -> { AlertDialog.Builder dlg = new AlertDialog.Builder(getActivity()); dlg.setAdapter(new ArrayAdapter(getActivity(), android.R.layout.select_dialog_singlechoice) { @Override public int getCount() { return colors.length; } @NonNull @Override public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { CheckedTextView v = (CheckedTextView) LayoutInflater.from(getContext()).inflate(android.R.layout.select_dialog_singlechoice, parent, false); int p = (int) Utils.convertDpToPixel(getContext(), 4); v.setPadding(4 * p, p, 4 * p, p); v.setText(position == 0 ? "System" : "Abc"); v.setBackgroundColor(position == 0 ? Color.WHITE : colors[position][0]); v.setTextColor(position == 0 ? Color.BLACK : colors[position][1]); v.setChecked(colors[position][0] == Preferences.ONGOING_BG_COLOR.get() && colors[position][1] == Preferences.ONGOING_TEXT_COLOR.get()); return v; } }, (dialog, which) -> { Preferences.ONGOING_BG_COLOR.set(colors[which][0]); Preferences.ONGOING_TEXT_COLOR.set(colors[which][1]); }); dlg.show(); return true; }); } }
Example 17
Source File: TalkBackShortcutPreferencesActivity.java From talkback with Apache License 2.0 | 4 votes |
@Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { Context context = getActivity().getApplicationContext(); PreferenceSettingsUtils.addPreferencesFromResource(this, R.xml.gesture_preferences); prefs = SharedPreferencesUtils.getSharedPreferences(context); final boolean treeDebugEnabled = prefs.getBoolean(getString(R.string.pref_tree_debug_key), false); final boolean performanceStatsEnabled = prefs.getBoolean(getString(R.string.pref_performance_stats_key), false); final boolean selectorEnabled = prefs.getBoolean(getString(R.string.pref_selector_activation_key), false); final boolean isWatch = FeatureSupport.isWatch(context); // Manipulate shortcutEntries and shortcutEntryValues to alter the list of assignable actions // to gestures. final String[] shortcutEntries = readShortcutEntries(selectorEnabled, treeDebugEnabled, performanceStatsEnabled, isWatch); final String[] shortcutEntryValues = readShortcutEntryValues( selectorEnabled, treeDebugEnabled, performanceStatsEnabled, isWatch); // Reference to the string resources used as keys customizable gesture mapping preferences. final String[] gesturePrefKeys = getResources().getStringArray(R.array.pref_shortcut_keys); // Update list preference entries and entryValues. for (int i = 0; i < gesturePrefKeys.length; i++) { ListPreference listPreference = (ListPreference) findPreference(gesturePrefKeys[i]); listPreference.setEntries(shortcutEntries); listPreference.setEntryValues(shortcutEntryValues); listPreference.setOnPreferenceChangeListener(preferenceChangeListener); } // Hide fingerprint gesture setting if it's not supported. if (!BuildVersionUtils.isAtLeastO() || !FeatureSupport.isFingerprintSupported(context)) { PreferenceSettingsUtils.hidePreference( context, getPreferenceScreen(), R.string.pref_category_fingerprint_touch_shortcuts_key); } }
Example 18
Source File: SettingsFragment.java From prayer-times-android with Apache License 2.0 | 4 votes |
@Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { addPreferencesFromResource(R.xml.settings); if (getArguments() != null && getArguments().getBoolean("showKerahatDuration")) setPreferenceScreen((PreferenceScreen) findPreference("kerahatDuration")); else { /* findPreference("language").setIcon(MaterialDrawableBuilder.with(getActivity()).setIcon(MaterialDrawableBuilder.IconValue.TRANSLATE) .setColor(getResources().getColor(R.color.foregroundSecondary)).build()); findPreference("arabicNames").setIcon(MaterialDrawableBuilder.with(getActivity()).setIcon(MaterialDrawableBuilder.IconValue.CLOCK_OUT) .setColor(getResources().getColor(R.color.foregroundSecondary)).build()); findPreference("digits").setIcon(MaterialDrawableBuilder.with(getActivity()).setIcon(MaterialDrawableBuilder.IconValue.NUMERIC) .setColor(getResources().getColor(R.color.foregroundSecondary)).build()); findPreference("calendarIntegration").setIcon( MaterialDrawableBuilder.with(getActivity()).setIcon(MaterialDrawableBuilder.IconValue.CALENDAR) .setColor(getResources().getColor(R.color.foregroundSecondary)).build()); findPreference("kerahatDuration").setIcon( MaterialDrawableBuilder.with(getActivity()).setIcon(MaterialDrawableBuilder.IconValue.CLOCK_ALERT) .setColor(getResources().getColor(R.color.foregroundSecondary)).build()); */ findPreference("numbers").setOnPreferenceChangeListener(this); findPreference("backupRestore").setOnPreferenceClickListener(this); findPreference("calendarIntegration").setOnPreferenceChangeListener(this); findPreference("ongoingIcon").setOnPreferenceClickListener(this); findPreference("ongoingNumber").setOnPreferenceClickListener(this); findPreference("kerahatDuration").setOnPreferenceClickListener(this); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { findPreference("ongoingNumber").setEnabled(false); } if (Build.VERSION.SDK_INT < 24) findPreference("showLegacyWidgets").setEnabled(false); findPreference("arabicNames").setEnabled(!new Locale("ar").getLanguage().equals(LocaleUtils.getLocale().getLanguage())); ListPreference lang = (ListPreference) findPreference("language"); lang.setOnPreferenceChangeListener(this); List<LocaleUtils.Translation> languages = LocaleUtils.getSupportedLanguages(getActivity()); CharSequence[] entries = new CharSequence[languages.size()]; CharSequence[] values = new CharSequence[languages.size()]; for (int i = 0; i < languages.size(); i++) { LocaleUtils.Translation trans = languages.get(i); entries[i] = trans.getDisplayText(); values[i] = trans.getLanguage(); } lang.setEntries(entries); lang.setEntryValues(values); int[][] colors = {{0, 0}, {0xFFFFFFFF, 0xFF333333}, {0xFFDDDDDD, 0xFF222222}, {0xFFBBBBBB, 0xFF111111}, {0xFF999999, 0xFF000000}, {0xFF666666, 0xFFFFFFFF}, {0xFF444444, 0xFFEEEEEE}, {0xFF222222, 0xFFDDDDDD}, {0xFF000000, 0xFFCCCCCC} }; Preference ongoingColor = findPreference("ongoingColor"); ongoingColor.setOnPreferenceClickListener(e -> { AlertDialog.Builder dlg = new AlertDialog.Builder(getActivity()); dlg.setAdapter(new ArrayAdapter(getActivity(), android.R.layout.select_dialog_singlechoice) { @Override public int getCount() { return colors.length; } @NonNull @Override public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { CheckedTextView v = (CheckedTextView) LayoutInflater.from(getContext()).inflate(android.R.layout.select_dialog_singlechoice, parent, false); int p = (int) Utils.convertDpToPixel(getContext(), 4); v.setPadding(4 * p, p, 4 * p, p); v.setText(position == 0 ? "System" : "Abc"); v.setBackgroundColor(position == 0 ? Color.WHITE : colors[position][0]); v.setTextColor(position == 0 ? Color.BLACK : colors[position][1]); v.setChecked(colors[position][0] == Preferences.ONGOING_BG_COLOR.get() && colors[position][1] == Preferences.ONGOING_TEXT_COLOR.get()); return v; } }, (dialog, which) -> { Preferences.ONGOING_BG_COLOR.set(colors[which][0]); Preferences.ONGOING_TEXT_COLOR.set(colors[which][1]); }); dlg.show(); return true; }); } }
Example 19
Source File: SettingsFragment.java From vinyl-cast with MIT License | 4 votes |
@Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { Timber.d("onCreatePreferences"); setPreferencesFromResource(R.xml.preferences, rootKey); AudioDevicePreference recordingDevicePref = findPreference(R.string.prefs_key_recording_device_id); AudioDevicePreference playbackDevicePref = findPreference(R.string.prefs_key_local_playback_device_id); CheckBoxPreference lowLatencyPref = findPreference(R.string.prefs_key_low_latency); ListPreference audioEncodingPref = findPreference(R.string.prefs_key_audio_encoding); Preference feedbackPref = findPreference(R.string.prefs_key_feedback); Preference androidApiLevelPref = findPreference(R.string.prefs_key_android_api_level); Preference appVersionPref = findPreference(R.string.prefs_key_app_version); if (recordingDevicePref != null) { recordingDevicePref.setDirectionType(AudioManager.GET_DEVICES_INPUTS); recordingDevicePref.setOnPreferenceClickListener(disabledPreferenceClickListener); recordingDevicePref.setOnPreferenceChangeListener(audioDeviceOnChangeListener); } if (playbackDevicePref != null) { playbackDevicePref.setDirectionType(AudioManager.GET_DEVICES_OUTPUTS); playbackDevicePref.setOnPreferenceClickListener(disabledPreferenceClickListener); playbackDevicePref.setOnPreferenceChangeListener(audioDeviceOnChangeListener); } if (lowLatencyPref != null) { lowLatencyPref.setOnPreferenceClickListener(disabledPreferenceClickListener); } if (audioEncodingPref != null) { audioEncodingPref.setEntries(R.array.prefs_audio_encoding_entries); audioEncodingPref.setEntryValues(R.array.prefs_audio_encoding_entry_values); audioEncodingPref.setOnPreferenceClickListener(disabledPreferenceClickListener); } if (feedbackPref != null && BuildConfig.FLAVOR.equals("playstore")) { feedbackPref.setVisible(true); feedbackPref.setOnPreferenceClickListener(preference -> { try { // Use reflection to get Instabug since only available in playstore product flavor Class instabugClazz = Class.forName("com.instabug.library.Instabug"); if (binder != null) { //Instabug.setUserAttribute("Audio API", getAudioApiVersionString()); Method setUserAttributeMethod = instabugClazz.getMethod("setUserAttribute", String.class, String.class); setUserAttributeMethod.invoke(null, "Audio API", getAudioApiVersionString()); } //Instabug.show(); Method showMethod = instabugClazz.getMethod("show"); showMethod.invoke(null); } catch (ReflectiveOperationException e) { e.printStackTrace(); } return true; }); } if (androidApiLevelPref != null) { androidApiLevelPref.setSummaryProvider(preference -> Integer.toString(Build.VERSION.SDK_INT) ); } if (appVersionPref != null) { appVersionPref.setSummaryProvider(preference -> String.format(Locale.getDefault(), "%s (%d)", BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE) ); } // set initial state of dynamic preferences updateDynamicPreferences(); }