JunyeongEvanSon / android-wheel

Automatically exported from code.google.com/p/android-wheel
0 stars 0 forks source link

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

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
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 commented 8 years ago
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 commented 8 years ago
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 commented 8 years ago
I'll investigate and let you know.
Thank you

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

GoogleCodeExporter commented 8 years ago
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