MaterialSeekBarPreference icon indicating copy to clipboard operation
MaterialSeekBarPreference copied to clipboard

Bar size and max value not in sync

Open ProfPh opened this issue 9 years ago • 7 comments
trafficstars

Tested with SeekBarPreference

Default: 25, Min: 10, Max: 50, Interval: 1

screenshot_2016-07-04-17-58-23

ProfPh avatar Jul 04 '16 17:07 ProfPh

Confirmed that it is a seekbar problem, the seekbar does not respect the maximum value set.

ProfPh avatar Jul 04 '16 19:07 ProfPh

Opened a pull request with the fix

ProfPh avatar Jul 04 '16 21:07 ProfPh

Hi what's the status of the PR/ISSUE i'm issueing also this bug.

tikismoke avatar Oct 20 '16 11:10 tikismoke

This is a bug. I've fixed with some changing. Below is original code of PreferenceControllerDelegate.java :

`void setMaxValue(int maxValue) { this.maxValue = maxValue;

    if (seekBarView != null) {
        if (minValue <= 0 && maxValue >= 0) {
            seekBarView.setMax(maxValue - minValue);
        }
        else {
            seekBarView.setMax(maxValue);
        }

        seekBarView.setProgress(currentValue - minValue);
    }
}`

Have to change as below :

`void setMaxValue(int maxValue) { this.maxValue = maxValue;

    if (seekBarView != null) {
        seekBarView.setMax(maxValue - minValue);

        seekBarView.setProgress(currentValue - minValue);
    }
}`

polaris0227 avatar Oct 27 '16 19:10 polaris0227

This does not strike me as the correct solution. The if-else is there in case there are negative numbers, and in that case it is indeed necessary to fix as they have it.

I'm not 100% sure what the fix is, but one problem lies in setCurrentValue(), line 295 (of the version I just cloned) of PreferenceControllerDelegate.java:

if(value > maxValue) value = maxValue

This is because value has minValue baked into it; see for instance line 155, where onProgressChanged() adds minValue into currentValue, which is passed to setCurrentValue() in line 172 of onStopTrackingTouch(). Line 295 should read

if(value - minValue > maxValue) value = maxValue

That seems to fix my problems, but it may not fix all of them; there may be an issue with intervals. I'm using an interval of 1, and I'm too tired to think it through right now (had to battle Android Studio to get it to use a local copy of MBSP).

Edit: Had a couple of wrong line numbers in there for a moment, sorry.

johnperry-math avatar Aug 18 '17 21:08 johnperry-math

Is there any news on this bug ?

It seems to me that @polaris0227 is right. The condition on negative value appears to be wrong: you always want to set the max of seekBarView to the distance between minValue and maxValue.

There are only 3 possibilities : both are positive, both are negative and only minValue is negative. But in all those cases, the distance is always equal to maxValue - minValue. For instance:

  • both are positive: minValue = 10 and maxValue = 25, so the distance is 25-10==15
  • both are negative: minValue = -25 and maxValue = -10, so the distance is -10-(-25)==15
  • only minValue is negative: minValue = -10 and maxValue = 25, so the distance is -25-(-10)==35

DanChaltiel avatar Jun 02 '18 16:06 DanChaltiel

@DanChaltiel Your best bet is probably to import the source, make the change I described, and go from there. The question is a year and a half old; there are pretty old pull requests on the project; it looks like abandonware.

johnperry-math avatar Jun 02 '18 17:06 johnperry-math