Android: Change slider step size based on range

Credit to JosJuice for the slider formula
This commit is contained in:
Charles Lombardo 2023-01-06 22:51:58 -05:00
parent e70b57fe8a
commit 937e08980e
1 changed files with 12 additions and 1 deletions

View File

@ -286,7 +286,18 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
slider.setValueFrom(item.getMin());
slider.setValueTo(item.getMax());
slider.setValue(mSeekbarProgress);
slider.setStepSize(1);
// Sliders can get frustrating to use with a small step size and large ranges
int maxRange = item.getMax();
if (maxRange <= 100)
{
slider.setStepSize(1);
}
else
{
slider.setStepSize((int) Math.pow(10, Math.ceil(Math.log10(maxRange)) - 2));
}
slider.addOnChangeListener(this);
mDialog = new MaterialAlertDialogBuilder(mView.getActivity())