Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bar size and max value not in sync #33

Open
ProfPh opened this issue Jul 4, 2016 · 7 comments
Open

Bar size and max value not in sync #33

ProfPh opened this issue Jul 4, 2016 · 7 comments

Comments

@ProfPh
Copy link
Contributor

ProfPh commented Jul 4, 2016

Tested with SeekBarPreference

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

screenshot_2016-07-04-17-58-23

@ProfPh
Copy link
Contributor Author

ProfPh commented Jul 4, 2016

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

@ProfPh
Copy link
Contributor Author

ProfPh commented Jul 4, 2016

Opened a pull request with the fix

@tikismoke
Copy link

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

@polaris0227
Copy link

polaris0227 commented Oct 27, 2016

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);
    }
}`

@johnperry-math
Copy link

johnperry-math commented Aug 18, 2017

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.

@DanChaltiel
Copy link

DanChaltiel commented Jun 2, 2018

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

@johnperry-math
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants