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

Clickable items in the displayed (current) wheel element #19

Open
GoogleCodeExporter opened this issue Oct 26, 2015 · 4 comments
Open

Comments

@GoogleCodeExporter
Copy link

Inside a wheel I spin a whole custom view instead of text\pictures. So I've 
found out that view buttons didn't work. 

I tried OnWheelClickedListener, overrided onItemClicked, and after gettig 
displayed View I get children items and perform click on buttons in case 
coordinates of the TouchEvent are in button's bounds. You see my way isn't 
graceful. Moreover buttons' animation doesn't work.

Could you please explain, what prevents displayed buttons from being pressed?

Original issue reported on code.google.com by ufo....@gmail.com on 5 Aug 2011 at 11:59

@GoogleCodeExporter
Copy link
Author

At the beginning the wheel control was designed only for displaying simple 
items w/o any control specific features like click events or animation.

It is a base control and of course it does not meet all your expectation :)
But it is possible to extend its functionality according to your needs.

Original comment by yuri.kan...@gmail.com on 12 Aug 2011 at 8:25

@GoogleCodeExporter
Copy link
Author

I've observed differences between ListView and your Wheel sources with respect 
to handling onTouch events (and applying them to children items) and coundn't 
find out how to 'fix' wheel.

What exactly I need to change to get desirable functionality?

Thank you.

Original comment by ufo....@gmail.com on 12 Aug 2011 at 8:59

@GoogleCodeExporter
Copy link
Author

I'll investigate and let you know.
Thank you

Original comment by yuri.kan...@gmail.com on 12 Aug 2011 at 9:09

@GoogleCodeExporter
Copy link
Author

To allow clicks on the current item look for the onTouchEvent method in 
WheelView and replace the line:
  if (items != 0 && isValidItemIndex(currentItem + items)) {
with:
  if (isValidItemIndex(currentItem + items)) {
or if you want to allow ONLY clicks on the current item:
  if (items == 0 && isValidItemIndex(currentItem)) {

Unfortunately even a 1 pixel movement with cause a scroll instead of a click. 
You might have to tweak the scrolling mechanism to consider a scroll < 10 
pixels (or something) a click too. For example by creating a member and 
constant:
  protected int scrolledDistance;
  private static final int MIN_DELTA_FOR_CLICKING = 25;
in WheelView and replacing the scrolling listener code with:

    // Scrolling listener
    WheelScroller.ScrollingListener scrollingListener = new WheelScroller.ScrollingListener() {
        public void onStarted() {
            isScrollingPerformed = false;
            scrolledDistance = 0;
            notifyScrollingListenersAboutStart();
        }

        public void onScroll(int distance) {
            doScroll(distance);

            scrolledDistance += Math.abs(distance);
            if (scrolledDistance > MIN_DELTA_FOR_CLICKING) {
                isScrollingPerformed = true;
            }

            int height = getHeight();
            if (scrollingOffset > height) {
                scrollingOffset = height;
                scroller.stopScrolling();
            } else if (scrollingOffset < -height) {
                scrollingOffset = -height;
                scroller.stopScrolling();
            }
        }

        public void onFinished() {
            notifyScrollingListenersAboutEnd();

            scrollingOffset = 0;
            invalidate();
        }

        public void onJustify() {
            if (Math.abs(scrollingOffset) > WheelScroller.MIN_DELTA_FOR_SCROLLING) {
                scroller.scroll(scrollingOffset, 0);
            }
        }
    };

Original comment by erickok@gmail.com on 9 Nov 2011 at 11:07

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

No branches or pull requests

1 participant