Java Code Examples for androidx.preference.ListPreference#setSummary()

The following examples show how to use androidx.preference.ListPreference#setSummary() . 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 vote down vote up
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: SettingsFragment.java    From Kore with Apache License 2.0 6 votes vote down vote up
/**
 * Sets up the preferences state and summaries
 */
private void setupPreferences() {
    // Theme preferences
    ListPreference themePref = (ListPreference)findPreference(Settings.KEY_PREF_THEME);
    themePref.setSummary(themePref.getEntry());

    // About preference
    String nameAndVersion = getActivity().getString(R.string.app_name);
    try {
        nameAndVersion += " " +
                          getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0).versionName;
    } catch (PackageManager.NameNotFoundException exc) {
    }
    Preference aboutPreference = findPreference(Settings.KEY_PREF_ABOUT);
    aboutPreference.setSummary(nameAndVersion);
    aboutPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            AboutDialogFragment aboutDialog = new AboutDialogFragment();
            aboutDialog.show(getFragmentManager(), null);
            return true;
        }
    });
}
 
Example 3
Source File: SettingsFragment.java    From fresco with MIT License 6 votes vote down vote up
private void updateGridRecyclerLayoutSummary() {
  final ListPreference listPreference =
      (ListPreference) findPreference(Const.RECYCLER_LAYOUT_KEY);
  // We have to enable the Grid settings only if the selection is the related on
  final ListPreference gridPreference =
      (ListPreference) findPreference(Const.GRID_SPAN_COUNT_KEY);
  final String value = listPreference.getValue();
  final boolean gridGroupVisible = Const.GRID_RECYCLER_VIEW_LAYOUT_VALUE.equals(value);
  // We update summary
  if (gridGroupVisible) {
    final String spanCountValue = gridPreference.getValue();
    gridPreference.setSummary(
        getString(R.string.label_grid_recycler_span_count_summary, spanCountValue));
  }
  gridPreference.setVisible(gridGroupVisible);
}
 
Example 4
Source File: ListSummaryPreferenceFragment.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
  ListPreference listPref   = (ListPreference) preference;
  int            entryIndex = Arrays.asList(listPref.getEntryValues()).indexOf(value);

  listPref.setSummary(entryIndex >= 0 && entryIndex < listPref.getEntries().length
                      ? listPref.getEntries()[entryIndex]
                      : getString(R.string.preferences__led_color_unknown));
  return true;
}
 
Example 5
Source File: GesturesPreference.java    From HgLauncher with GNU General Public License v3.0 5 votes vote down vote up
@Override public boolean onPreferenceChange(Preference preference, Object newValue) {
    ListPreference list = (ListPreference) preference;
    String value = (String) newValue;

    // Workaround due to the use of setSummary in onCreate.
    switch (value) {
        case "handler":
            list.setSummary(R.string.gesture_action_handler);
            break;
        case "widget":
            list.setSummary(R.string.gesture_action_widget);
            break;
        case "status":
            list.setSummary(R.string.gesture_action_status);
            break;
        case "list":
            list.setSummary(R.string.gesture_action_list);
            break;
        case "app":
            // Create the Bundle to pass to AppSelectionPreferenceDialog.
            Bundle appListBundle = new Bundle();
            appListBundle.putString("key", list.getKey());
            appListBundle.putCharSequenceArray("entries", appListEntries);
            appListBundle.putCharSequenceArray("entryValues", appListEntryValues);

            // Call and create AppSelectionPreferenceDialog.
            AppSelectionPreferenceDialog appList = new AppSelectionPreferenceDialog();
            appList.setTargetFragment(GesturesPreference.this, APPLICATION_DIALOG_CODE);
            appList.setArguments(appListBundle);
            appList.show(requireFragmentManager(), "AppSelectionDialog");
            break;
        case "none":
        default:
            list.setSummary(R.string.gesture_action_default);
            break;
    }
    return true;
}
 
Example 6
Source File: SettingsActivity.java    From call_manage with MIT License 5 votes vote down vote up
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: PreferencesMain.java    From onpc with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("SameReturnValue")
private static void prepareListPreference(final ListPreference listPreference, final Activity activity)
{
    if (listPreference == null)
    {
        return;
    }

    if (listPreference.getValue() == null)
    {
        // to ensure we don't get a null value
        // set first value by default
        listPreference.setValueIndex(0);
    }

    if (listPreference.getEntry() != null)
    {
        listPreference.setSummary(listPreference.getEntry().toString());
    }
    listPreference.setOnPreferenceChangeListener((preference, newValue) ->
    {
        listPreference.setValue(newValue.toString());
        preference.setSummary(listPreference.getEntry().toString());
        if (activity != null)
        {
            final Intent intent = activity.getIntent();
            activity.finish();
            activity.startActivity(intent);
        }
        return true;
    });
}
 
Example 8
Source File: SettingsFragment.java    From SmsCode with GNU General Public License v3.0 5 votes vote down vote up
private void refreshListenModePreference(ListPreference listenModePref, String newValue) {
    if (TextUtils.isEmpty(newValue))
        return;
    CharSequence[] entries = listenModePref.getEntries();
    int index = listenModePref.findIndexOfValue(newValue);
    try {
        listenModePref.setSummary(entries[index]);
    } catch (Exception e) {
        //ignore
    }
}
 
Example 9
Source File: NotificationColorSettingsFragment.java    From GeometricWeather with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void initNotificationPart() {
    // notification custom color.
    findPreference(getString(R.string.key_notification_custom_color)).setOnPreferenceChangeListener((p, newValue) -> {
        getSettingsOptionManager().setNotificationCustomColorEnabled((Boolean) newValue);
        initNotificationPart();
        PollingManager.resetNormalBackgroundTask(getActivity(), true);
        return true;
    });

    // notification background.
    ColorPreferenceCompat notificationBackgroundColor = findPreference(getString(R.string.key_notification_background_color));
    notificationBackgroundColor.setEnabled(getSettingsOptionManager().isNotificationCustomColorEnabled());
    notificationBackgroundColor.setOnPreferenceChangeListener((preference, newValue) -> {
        getSettingsOptionManager().setNotificationBackgroundColor((Integer) newValue);
        PollingManager.resetNormalBackgroundTask(getActivity(), true);
        return true;
    });

    // notification text color.
    ListPreference notificationTextColor = findPreference(getString(R.string.key_notification_text_color));
    notificationTextColor.setSummary(
            getSettingsOptionManager().getNotificationTextColor().getNotificationTextColorName(
                    getActivity()
            )
    );
    notificationTextColor.setOnPreferenceChangeListener((preference, newValue) -> {
        PollingManager.resetNormalBackgroundTask(getActivity(), true);
        preference.setSummary(
                getSettingsOptionManager().getNotificationTextColor().getNotificationTextColorName(
                        getActivity()
                )
        );
        return true;
    });
}
 
Example 10
Source File: SettingsActivity.java    From microMathematics with GNU General Public License v3.0 5 votes vote down vote up
private static void prepareListPreference(final Activity activity, final ListPreference listPreference)
{
    if (listPreference == null)
    {
        return;
    }

    if (listPreference.getValue() == null)
    {
        // to ensure we don't get a null value
        // set first value by default
        listPreference.setValueIndex(0);
    }

    if (listPreference.getEntry() != null)
    {
        listPreference.setSummary(listPreference.getEntry().toString());
    }
    listPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
    {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue)
        {
            listPreference.setValue(newValue.toString());
            preference.setSummary(listPreference.getEntry().toString());
            if (activity != null)
            {
                final Intent intent = activity.getIntent();
                activity.finish();
                activity.startActivity(intent);
            }
            return true;
        }
    });
}
 
Example 11
Source File: GesturesPreference.java    From HgLauncher with GNU General Public License v3.0 5 votes vote down vote up
@Override public boolean onPreferenceChange(Preference preference, Object newValue) {
    ListPreference list = (ListPreference) preference;
    String value = (String) newValue;

    // Workaround due to the use of setSummary in onCreate.
    switch (value) {
        case "handler":
            list.setSummary(R.string.gesture_action_handler);
            break;
        case "widget":
            list.setSummary(R.string.gesture_action_widget);
            break;
        case "status":
            list.setSummary(R.string.gesture_action_status);
            break;
        case "list":
            list.setSummary(R.string.gesture_action_list);
            break;
        case "app":
            // Create the Bundle to pass to AppSelectionPreferenceDialog.
            Bundle appListBundle = new Bundle();
            appListBundle.putString("key", list.getKey());
            appListBundle.putCharSequenceArray("entries", appListEntries);
            appListBundle.putCharSequenceArray("entryValues", appListEntryValues);

            // Call and create AppSelectionPreferenceDialog.
            AppSelectionPreferenceDialog appList = new AppSelectionPreferenceDialog();
            appList.setTargetFragment(GesturesPreference.this, APPLICATION_DIALOG_CODE);
            appList.setArguments(appListBundle);
            appList.show(requireFragmentManager(), "AppSelectionDialog");
            break;
        case "none":
        default:
            list.setSummary(R.string.gesture_action_default);
            break;
    }
    return true;
}
 
Example 12
Source File: SettingsActivity.java    From APDE with GNU General Public License v2.0 5 votes vote down vote up
protected void updateSketchbookDrivePref(ListPreference sketchbookDrive, Preference sketchbookLocation, ArrayList<APDE.StorageDrive> drives) {
	int selectedIndex = sketchbookDrive.findIndexOfValue(sketchbookDrive.getValue());
	
	if (selectedIndex == -1) {
		//Uh-oh
		return;
	}
	
	APDE.StorageDrive selected = drives.get(selectedIndex);
	
	sketchbookLocation.setEnabled(!(selected.type.equals(APDE.StorageDrive.StorageDriveType.INTERNAL) || selected.type.equals(APDE.StorageDrive.StorageDriveType.SECONDARY_EXTERNAL)));
	sketchbookDrive.setSummary(selected.space + " " + selected.type.title);
}
 
Example 13
Source File: SettingsFragment.java    From fastnfitness with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void updateSummary(ListPreference pref, String val, String prefix) {
    int prefIndex = pref.findIndexOfValue(val);
    if (prefIndex >= 0) {
        //finally set's it value changed
        pref.setSummary(prefix + pref.getEntries()[prefIndex]);
    }
}
 
Example 14
Source File: ListSummaryPreferenceFragment.java    From deltachat-android with GNU General Public License v3.0 4 votes vote down vote up
protected void updateListSummary(Preference preference, Object value) {
  ListPreference listPref = (ListPreference) preference;
  listPref.setSummary(getSelectedSummary(preference, value));
}
 
Example 15
Source File: SettingsFragment.java    From fresco with MIT License 4 votes vote down vote up
private static void updateListPreference(
    Resources resources, ListPreference preference, int arrayValuesId) {
  final int valueIndex = preference.findIndexOfValue(preference.getValue());
  final String summary = resources.getStringArray(arrayValuesId)[valueIndex];
  preference.setSummary(summary);
}
 
Example 16
Source File: SettingsFragment.java    From Mysplash with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void initDisplayPart() {
    // saturation animation enabled.
    SwitchPreference saturationEnabled = findPreference(getString(R.string.key_saturation_animation_enabled));
    saturationEnabled.setOnPreferenceChangeListener((preference, newValue) -> {
        SettingsServiceIMP.getInstance(requireActivity())
                .setSaturationAnimationEnabled((Boolean) newValue);
        return true;
    });

    // saturation animation duration.
    ListPreference duration = findPreference(getString(R.string.key_saturation_animation_duration));
    duration.setSummary(
            getNameByValue(
                    ComponentFactory.getSettingsService().getSaturationAnimationDuration(),
                    R.array.saturation_animation_durations,
                    R.array.saturation_animation_duration_values
            )
    );
    duration.setOnPreferenceChangeListener((preference, newValue) -> {
        SettingsServiceIMP.getInstance(requireActivity())
                .setSaturationAnimationDuration((String) newValue);
        preference.setSummary(
                getNameByValue(
                        (String) newValue,
                        R.array.saturation_animation_durations,
                        R.array.saturation_animation_duration_values
                )
        );
        return true;
    });

    // grid list in port.
    SwitchPreference gridPort = findPreference(getString(R.string.key_grid_list_in_port));
    gridPort.setVisible(DisplayUtils.isTabletDevice(requireActivity()));
    gridPort.setOnPreferenceChangeListener((preference, newValue) -> {
        showRebootSnackbar();
        return true;
    });

    // grid list in land.
    findPreference(getString(R.string.key_grid_list_in_land)).setOnPreferenceChangeListener((p, v) -> {
        showRebootSnackbar();
        return true;
    });
}
 
Example 17
Source File: FormEntryPreferences.java    From commcare-android with Apache License 2.0 4 votes vote down vote up
private void updateFontSize() {
    ListPreference lp = (ListPreference)findPreference(KEY_FONT_SIZE);
    lp.setSummary(lp.getEntry());
}
 
Example 18
Source File: SettingsFragment.java    From mlkit-material-android with Apache License 2.0 4 votes vote down vote up
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 19
Source File: MuzeiSettingsFragment.java    From Mysplash with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.perference_muzei);

    MuzeiOptionManager manager = MuzeiOptionManager.getInstance(requireActivity());

    // muzei source.
    ListPreference source = findPreference(getString(R.string.key_muzei_source));
    source.setSummary(
            getNameByValue(
                    manager.getSource(),
                    R.array.muzei_sources,
                    R.array.muzei_source_values
            )
    );
    source.setOnPreferenceChangeListener((preference, newValue) -> {
        manager.setSource((String) newValue);
        preference.setSummary(
                getNameByValue(
                        manager.getSource(),
                        R.array.muzei_sources,
                        R.array.muzei_source_values
                )
        );

        findPreference(getString(R.string.key_muzei_collection_source)).setEnabled(
                manager.getSource().equals(MuzeiOptionManager.SOURCE_COLLECTIONS)
        );
        return true;
    });

    // screen size.
    SwitchPreference screenSizeImage = findPreference(getString(R.string.key_muzei_screen_size_image));
    int[] size = MuzeiUpdateHelper.getScreenSize(requireActivity());
    screenSizeImage.setSummaryOn(size[1] + "×" + size[0]);
    screenSizeImage.setSummaryOff(R.string.muzei_settings_title_screen_size_image_summary_off);
    screenSizeImage.setOnPreferenceChangeListener((preference, newValue) -> {
        manager.setScreenSizeImage((Boolean) newValue);
        return true;
    });

    // cache mode.
    ListPreference cacheMode = findPreference(getString(R.string.key_muzei_cache_mode));
    cacheMode.setSummary(
            getNameByValue(
                    manager.getCacheMode(),
                    R.array.muzei_cache_modes,
                    R.array.muzei_cache_mode_values
            )
    );
    cacheMode.setOnPreferenceChangeListener((preference, newValue) -> {
        manager.setCacheMode((String) newValue);
        preference.setSummary(
                getNameByValue(
                        manager.getCacheMode(),
                        R.array.muzei_cache_modes,
                        R.array.muzei_cache_mode_values
                )
        );
        return true;
    });

    // collections.
    Preference collectionSource = findPreference(getString(R.string.key_muzei_collection_source));
    collectionSource.setEnabled(manager.getSource().equals(MuzeiOptionManager.SOURCE_COLLECTIONS));
    collectionSource.setOnPreferenceClickListener(preference -> {
        ComponentFactory.getMuzeiService()
                .startMuzeiCollectionSourceConfigActivity(requireActivity());
        return true;
    });

    // query.
    Preference query = findPreference(getString(R.string.key_muzei_query));
    query.setSummary(manager.getQuery());
    query.setOnPreferenceClickListener(preference -> {
        MuzeiQueryDialog dialog = new MuzeiQueryDialog();
        dialog.setOnQueryChangedListener(query1 -> {
            MuzeiOptionManager.updateQuery(requireActivity(), query1);
            Preference q = findPreference(getString(R.string.key_muzei_query));
            q.setSummary(MuzeiOptionManager.getInstance(requireActivity()).getQuery());
        });
        dialog.show(requireFragmentManager(), null);
        return true;
    });
}
 
Example 20
Source File: ListSummaryPreferenceFragment.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
protected void initializeListSummary(ListPreference pref) {
  pref.setSummary(pref.getEntry());
}