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

Not correct position for alphaSlideBar after first init colorPickerView color. #64

Open
demoCrash opened this issue Jan 10, 2021 · 8 comments
Assignees
Labels
Released Released already on the latest version.

Comments

@demoCrash
Copy link

open demo ,you can find the alpha is 0xff, but not at the end of the sliderbar.
the problem is in your class file AbstractSlider.java

  protected int getSelectorHalfSize() {
    return (int) (selector.getMeasuredWidth());
  }

not divide by two.
brightnessSlideBar extends this class may be the same problem.
Hope it is useful to you.

@demoCrash demoCrash changed the title Not correct position for alphaSlideBar after first init colorPickerView color data. Not correct position for alphaSlideBar after first init colorPickerView color. Jan 10, 2021
@skydoves skydoves self-assigned this Jan 12, 2021
@PierfrancescoSoffritti
Copy link

hey @skydoves, do you have plans for fixing this?

@skydoves
Copy link
Owner

Hi, @PierfrancescoSoffritti !

I've already fixed this issue in my local repository, but I missed push and release a new version because of migrating to maven central. I will let you know about the next release soon. Thanks!

@skydoves
Copy link
Owner

It has been released a snapshot 2.2.3.
Please test work as well using the new snapshot.
Thanks for your issue :)

implementation "com.github.skydoves:colorpickerview:2.2.3-SNAPSHOT"

@skydoves skydoves added the Released Released already on the latest version. label Feb 19, 2021
@PierfrancescoSoffritti
Copy link

Hey I just had time to try this out, version 2.2.3 still has the same issue.

When dragging the slider, when approaching the end of the bar it snaps to the end of it.

@skydoves
Copy link
Owner

@PierfrancescoSoffritti
Oh, I think that's another issue. 🤦‍♂
I will look into the details. Thanks!

@kovadam69
Copy link

Hi!

I found several problems regarding initial selector positioning and also regarding touch events which makes the selector to snap either to the front or to the end of the bar within certain distance.
The initial positioning is wrong in the onInflateFinished method, since it sets the default position to getMeasuredWidth, which actually places the selector outside the visible area, which means if there is no color selected (eg. color is black and the alpha and also the brightness is 0) the selector is set outside the visible area (and not to 0 position where it should be and regardless how many times you set it to 0, the onInflateFinished is called later, and you loose what you were setting during onCreate for example). May be the default position should be initialized as 0.
Other problems I've found are in the onTouchReceived method, which calculates the position of the selector totally wrong.
I've modified it like this, and works like a charm:
`if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE)
{
// position thumb into click center, this will be the left side of the selector's new position
float x = (eventX - (getSelectorSize() / 2f));

        if (x < 0) x = 0; // if user dragged the selector below the left bound, correct it to 0, we reached left side
        if (x > getMeasuredWidth() - getSelectorSize()) x = getMeasuredWidth() - getSelectorSize(); // if user dragged the selector above the right bound (minus the selectors width) then correct it to the maximum possible position

        // calculate new selector position according to the clicked position
        selectorPosition = x / (getMeasuredWidth() - getSelectorSize());

        // to be sure, but normally it cannot happen
        if (selectorPosition > 1f) selectorPosition = 1f;
        else if (selectorPosition < 0f) selectorPosition = 0f;

        // set the position of the selector
        selectedX = (int) x;
        selector.setX(x);
    }
    else if (event.getAction() == MotionEvent.ACTION_UP...`

This way the selector is positioned always into the click point center and does not snap to 0 or max width, like it did before... The getBoundaryX is totally useless, it modifies the X rather wrong than correct, the modification can be made during touch event or selector positioning.

Also setSelectorPosition had to be adjusted:

public void setSelectorPosition(@FloatRange(from = 0.0, to = 1.0) float selectorPosition) { this.selectorPosition = Math.min(selectorPosition, 1.0f); float x = (getMeasuredWidth() - getSelectorSize()) * selectorPosition; selectedX = (int) x; selector.setX(x); invalidate(); }

I did not touch the setSelectorByHalfSelectorPosition method, I don't know how that can be useful since it should also position the selector like the normal positioning... (if you set position to 0, the selector should start with x = 0, regardless if you are positioning it ByHalfSelector or by normal Selector position...

May be my case was special, since I use the brightnessslidebar separately not attached to the colorpicker, since I need them to be separated, therefore I subclassed it and also added a listener to get the position of the selector when the user releases the thumb, but it was acting wrong until I modified those things.

@aadeshrana
Copy link

Has this issue been resolved? The selector is still snapping to the end of the bar when dragging. Using version 2.2.4

@skydoves
Copy link
Owner

skydoves commented Apr 8, 2023

#97

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

No branches or pull requests

5 participants