Code example for MotionEvent

Methods: getActiongetXgetYsetLocation

0
    @Override 
    public boolean dispatchTouchEvent(MotionEvent event) {
        if(mTitleBar != null) {
            final int sy = getScrollY();
            final int visTitleHeight = getVisibleTitleHeightCompat();
            final float x = event.getX();
            float y = event.getY();
 
            switch(event.getAction() & MotionEvent.ACTION_MASK) {
                case MotionEvent.ACTION_DOWN:
                    if(y <= visTitleHeight) {
                        mTouchInTitleBar = true;
                    } 
                    break; 
 
                case MotionEvent.ACTION_MOVE:
                    mTouchMove = true;
                    break; 
 
                case MotionEvent.ACTION_UP:
                case MotionEvent.ACTION_CANCEL:
                    mTouchMove = false;
                    break; 
 
                default: 
            } 
 
            if(mTouchInTitleBar) {
                y += sy;
                event.setLocation(x, y);
 
                return mTitleBar.dispatchTouchEvent(event);
            } else { 
                if(Build.VERSION.SDK_INT < 16) {
                    if(!mTouchMove) {
                        mTitleBarOffs = getVisibleTitleHeightCompat();
                    } 
 
                    y -= mTitleBarOffs;
                    if(y < 0) y = 0;
                    event.setLocation(x, y);
                } 
 
                return super.dispatchTouchEvent(event);
            } 
        } else {