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

Click on number centres it #7

Closed
GoogleCodeExporter opened this issue Mar 15, 2016 · 2 comments
Closed

Click on number centres it #7

GoogleCodeExporter opened this issue Mar 15, 2016 · 2 comments

Comments

@GoogleCodeExporter
Copy link

This is more a request for enhancement, with the iPhone equivalent (yes I know 
android is not iPhone, but we can always 'steal' some of their usability 
ideas), in a number picker (could be any item though), if you click on a number 
that is not in the middle, that number is then pushed to the middle (as apposed 
to just dragging it to the middle). Its a neat enhancement. 

I didnt want to alter the core code to make upgrades possible in the future so 
I extended the class with the below, but you could potentially add the 
'(getHeight()/2) - event.getY())' bit into your action_up with some invalidates 
and it would be done. Its your code so your call, just a sugestion. Anyway, 
here is the important bits of the overriding class ...


public class TouchWheelView extends WheelView {
    private boolean isScrollingPerformed; 
    private float clickDownY = 0.0F ;

    /**
     * Constructor
     */
    public TouchWheelView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    /**
     * Constructor
     */
    public TouchWheelView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    /**
     * Constructor
     */
    public TouchWheelView(Context context) {
        super(context);
        this.onFinishInflate();
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();

        // Add listeners to emulate the isScrollingPerformed behaviour
        this.addScrollingListener(new OnWheelScrollListener() {
            public void onScrollingStarted(WheelView wheel) {
                isScrollingPerformed = true;

            }
            public void onScrollingFinished(WheelView wheel) {
                isScrollingPerformed = false;
            }
        });
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        WheelAdapter adapter = getAdapter();
        if (adapter == null) {
            return true;
        }
        // for my event, if an item is click (when button goes up), if click is outside focus region, emulate a move
        switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN: {
            clickDownY = event.getY();
            isScrollingPerformed = false ; 
            break;
        }
        case MotionEvent.ACTION_MOVE: {
            isScrollingPerformed = true ; 
            break;
        }
        case MotionEvent.ACTION_UP:
            if (!isScrollingPerformed) {
                // Pretend to to a move
                event.setAction(MotionEvent.ACTION_MOVE);
                event.setLocation(event.getX(),  clickDownY + ((getHeight()/2) - event.getY()));
                super.onTouchEvent(event);
                // Now reset back to what it was
                event.setAction(MotionEvent.ACTION_UP);
                event.setLocation(event.getX(), (getHeight()/2));
            }
            break;          
        }
        return super.onTouchEvent(event);
    }
}

Original issue reported on code.google.com by davidhil...@gmail.com on 5 Dec 2010 at 1:01

@GoogleCodeExporter
Copy link
Author

Thank you!
Will add this feature. It is really useful thing :)

Original comment by yuri.kan...@gmail.com on 25 Dec 2010 at 7:21

@GoogleCodeExporter
Copy link
Author

Should work now

Original comment by yuri.kan...@gmail.com on 27 Jan 2011 at 8:57

  • Changed state: Fixed

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