Example usage for android.view MotionEvent getRawY

List of usage examples for android.view MotionEvent getRawY

Introduction

In this page you can find the example usage for android.view MotionEvent getRawY.

Prototype

public final float getRawY() 

Source Link

Document

Returns the original raw Y coordinate of this event.

Usage

From source file:com.wunderlist.slidinglayer.SlidingLayer.java

private float getViewY(MotionEvent event) {
    return event.getRawY();
}

From source file:org.connectbot.ConsoleFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View v = inflater.inflate(R.layout.frg_console, container, false);

    this.inflater = inflater;

    flip = (ViewFlipper) v.findViewById(R.id.console_flip);
    empty = (TextView) v.findViewById(android.R.id.empty);

    stringPromptGroup = (RelativeLayout) v.findViewById(R.id.console_password_group);
    stringPromptInstructions = (TextView) v.findViewById(R.id.console_password_instructions);
    stringPrompt = (EditText) v.findViewById(R.id.console_password);
    stringPrompt.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_UP)
                return false;
            if (keyCode != KeyEvent.KEYCODE_ENTER)
                return false;

            // pass collected password down to current terminal
            String value = stringPrompt.getText().toString();

            PromptHelper helper = getCurrentPromptHelper();
            if (helper == null)
                return false;
            helper.setResponse(value);/*from  www  . j  av a 2  s . com*/

            // finally clear password for next user
            stringPrompt.setText("");
            updatePromptVisible();

            return true;
        }
    });

    booleanPromptGroup = (RelativeLayout) v.findViewById(R.id.console_boolean_group);
    booleanPrompt = (TextView) v.findViewById(R.id.console_prompt);

    booleanYes = (Button) v.findViewById(R.id.console_prompt_yes);
    booleanYes.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            PromptHelper helper = getCurrentPromptHelper();
            if (helper == null)
                return;
            helper.setResponse(Boolean.TRUE);
            updatePromptVisible();
        }
    });

    booleanNo = (Button) v.findViewById(R.id.console_prompt_no);
    booleanNo.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            PromptHelper helper = getCurrentPromptHelper();
            if (helper == null)
                return;
            helper.setResponse(Boolean.FALSE);
            updatePromptVisible();
        }
    });

    // preload animations for terminal switching
    slide_left_in = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_left_in);
    slide_left_out = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_left_out);
    slide_right_in = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_right_in);
    slide_right_out = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_right_out);

    fade_out_delayed = AnimationUtils.loadAnimation(getActivity(), R.anim.fade_out_delayed);
    fade_stay_hidden = AnimationUtils.loadAnimation(getActivity(), R.anim.fade_stay_hidden);

    // Preload animation for keyboard button
    keyboard_fade_in = AnimationUtils.loadAnimation(getActivity(), R.anim.keyboard_fade_in);
    keyboard_fade_out = AnimationUtils.loadAnimation(getActivity(), R.anim.keyboard_fade_out);

    inputManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);

    final RelativeLayout keyboardGroup = (RelativeLayout) v.findViewById(R.id.keyboard_group);

    mKeyboardButton = (ImageView) v.findViewById(R.id.button_keyboard);
    mKeyboardButton.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            View flip = findCurrentView(R.id.console_flip);
            if (flip == null)
                return;

            inputManager.showSoftInput(flip, InputMethodManager.SHOW_FORCED);
            keyboardGroup.setVisibility(View.GONE);
        }
    });

    final ImageView ctrlButton = (ImageView) v.findViewById(R.id.button_ctrl);
    ctrlButton.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            View flip = findCurrentView(R.id.console_flip);
            if (flip == null)
                return;
            TerminalView terminal = (TerminalView) flip;

            TerminalKeyListener handler = terminal.bridge.getKeyHandler();
            handler.metaPress(TerminalKeyListener.META_CTRL_ON);

            keyboardGroup.setVisibility(View.GONE);
        }
    });

    final ImageView escButton = (ImageView) v.findViewById(R.id.button_esc);
    escButton.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            View flip = findCurrentView(R.id.console_flip);
            if (flip == null)
                return;
            TerminalView terminal = (TerminalView) flip;

            TerminalKeyListener handler = terminal.bridge.getKeyHandler();
            handler.sendEscape();

            keyboardGroup.setVisibility(View.GONE);
        }
    });

    // detect fling gestures to switch between terminals
    final GestureDetector detect = new GestureDetector(new GestureDetector.SimpleOnGestureListener() {
        private float totalY = 0;

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {

            final float distx = e2.getRawX() - e1.getRawX();
            final float disty = e2.getRawY() - e1.getRawY();
            final int goalwidth = flip.getWidth() / 2;

            // need to slide across half of display to trigger console change
            // make sure user kept a steady hand horizontally
            if (Math.abs(disty) < (flip.getHeight() / 4)) {
                if (distx > goalwidth) {
                    shiftCurrentTerminal(SHIFT_RIGHT);
                    return true;
                }

                if (distx < -goalwidth) {
                    shiftCurrentTerminal(SHIFT_LEFT);
                    return true;
                }

            }

            return false;
        }

        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {

            // if copying, then ignore
            if (copySource != null && copySource.isSelectingForCopy())
                return false;

            if (e1 == null || e2 == null)
                return false;

            // if releasing then reset total scroll
            if (e2.getAction() == MotionEvent.ACTION_UP) {
                totalY = 0;
            }

            // activate consider if within x tolerance
            if (Math.abs(e1.getX() - e2.getX()) < ViewConfiguration.getTouchSlop() * 4) {

                View flip = findCurrentView(R.id.console_flip);
                if (flip == null)
                    return false;
                TerminalView terminal = (TerminalView) flip;

                // estimate how many rows we have scrolled through
                // accumulate distance that doesn't trigger immediate scroll
                totalY += distanceY;
                final int moved = (int) (totalY / terminal.bridge.charHeight);

                // consume as scrollback only if towards right half of screen
                if (e2.getX() > flip.getWidth() / 2) {
                    if (moved != 0) {
                        int base = terminal.bridge.buffer.getWindowBase();
                        terminal.bridge.buffer.setWindowBase(base + moved);
                        totalY = 0;
                        return true;
                    }
                } else {
                    // otherwise consume as pgup/pgdown for every 5 lines
                    if (moved > 5) {
                        ((vt320) terminal.bridge.buffer).keyPressed(vt320.KEY_PAGE_DOWN, ' ', 0);
                        terminal.bridge.tryKeyVibrate();
                        totalY = 0;
                        return true;
                    } else if (moved < -5) {
                        ((vt320) terminal.bridge.buffer).keyPressed(vt320.KEY_PAGE_UP, ' ', 0);
                        terminal.bridge.tryKeyVibrate();
                        totalY = 0;
                        return true;
                    }

                }

            }

            return false;
        }

    });

    flip.setLongClickable(true);
    flip.setOnTouchListener(new OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {

            // when copying, highlight the area
            if (copySource != null && copySource.isSelectingForCopy()) {
                int row = (int) Math.floor(event.getY() / copySource.charHeight);
                int col = (int) Math.floor(event.getX() / copySource.charWidth);

                SelectionArea area = copySource.getSelectionArea();

                switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    // recording starting area
                    if (area.isSelectingOrigin()) {
                        area.setRow(row);
                        area.setColumn(col);
                        lastTouchRow = row;
                        lastTouchCol = col;
                        copySource.redraw();
                    }
                    return true;
                case MotionEvent.ACTION_MOVE:
                    /* ignore when user hasn't moved since last time so
                     * we can fine-tune with directional pad
                     */
                    if (row == lastTouchRow && col == lastTouchCol)
                        return true;

                    // if the user moves, start the selection for other corner
                    area.finishSelectingOrigin();

                    // update selected area
                    area.setRow(row);
                    area.setColumn(col);
                    lastTouchRow = row;
                    lastTouchCol = col;
                    copySource.redraw();
                    return true;
                case MotionEvent.ACTION_UP:
                    /* If they didn't move their finger, maybe they meant to
                     * select the rest of the text with the directional pad.
                     */
                    if (area.getLeft() == area.getRight() && area.getTop() == area.getBottom()) {
                        return true;
                    }

                    // copy selected area to clipboard
                    String copiedText = area.copyFrom(copySource.buffer);

                    clipboard.setText(copiedText);
                    Toast.makeText(getActivity(), getString(R.string.console_copy_done, copiedText.length()),
                            Toast.LENGTH_LONG).show();
                    // fall through to clear state

                case MotionEvent.ACTION_CANCEL:
                    // make sure we clear any highlighted area
                    area.reset();
                    copySource.setSelectingForCopy(false);
                    copySource.redraw();
                    return true;
                }
            }

            Configuration config = getResources().getConfiguration();

            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                lastX = event.getX();
                lastY = event.getY();
            } else if (event.getAction() == MotionEvent.ACTION_UP && keyboardGroup.getVisibility() == View.GONE
                    && event.getEventTime() - event.getDownTime() < CLICK_TIME
                    && Math.abs(event.getX() - lastX) < MAX_CLICK_DISTANCE
                    && Math.abs(event.getY() - lastY) < MAX_CLICK_DISTANCE) {
                keyboardGroup.startAnimation(keyboard_fade_in);
                keyboardGroup.setVisibility(View.VISIBLE);

                mUIHandler.postDelayed(new Runnable() {
                    public void run() {
                        if (keyboardGroup.getVisibility() == View.GONE)
                            return;

                        keyboardGroup.startAnimation(keyboard_fade_out);
                        keyboardGroup.setVisibility(View.GONE);
                    }
                }, KEYBOARD_DISPLAY_TIME);
            }

            // pass any touch events back to detector
            return detect.onTouchEvent(event);
        }

    });

    return v;
}

From source file:radu.pidroid.Controller.java

private boolean isTouchOnView(View view, MotionEvent motionEvent) {
    ///*w w  w. j ava  2 s.  c  o m*/
    int viewPosition[] = new int[4];
    view.getLocationOnScreen(viewPosition);

    viewPosition[2] = viewPosition[0] + view.getWidth();
    viewPosition[3] = viewPosition[1] + view.getHeight();

    //
    return motionEvent.getRawX() >= viewPosition[0] && motionEvent.getRawX() <= viewPosition[2]
            && motionEvent.getRawY() >= viewPosition[1] && motionEvent.getRawY() <= viewPosition[3];
}

From source file:com.devbrackets.android.recyclerext.decoration.ReorderDecoration.java

/**
 * This will determine two things./*from w  w w . java  2  s. c  om*/
 * 1. If we need to handle the touch event
 * 2. If reordering needs to start due to dragHandle being clicked
 */
@Override
public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent event) {
    if (dragState == DragState.DRAGGING) {
        return true;
    }

    if (dragHandleId == INVALID_RESOURCE_ID) {
        return false;
    }

    View itemView = recyclerView.findChildViewUnder(event.getX(), event.getY());
    if (itemView == null) {
        return false;
    }

    View handleView = itemView.findViewById(dragHandleId);
    if (handleView == null || handleView.getVisibility() != View.VISIBLE) {
        return false;
    }

    int[] handlePosition = new int[2];
    handleView.getLocationOnScreen(handlePosition);

    //Determine if the MotionEvent is inside the handle
    if ((event.getRawX() >= handlePosition[0] && event.getRawX() <= handlePosition[0] + handleView.getWidth())
            && (event.getRawY() >= handlePosition[1]
                    && event.getRawY() <= handlePosition[1] + handleView.getHeight())) {
        startReorder(itemView, event);
        return true;
    }

    return false;
}

From source file:com.androzic.MapFragment.java

@SuppressLint("ClickableViewAccessibility")
@Override//from   w w  w . j  ava 2s .  com
public boolean onTouch(View v, MotionEvent event) {
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        zoom100X = (int) event.getRawX();
        zoom100Y = (int) event.getRawY();
        zoomHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                zoom100X = 0;
                zoom100Y = 0;
            }
        }, 2000);
        break;
    case MotionEvent.ACTION_UP:
        int dx = Math.abs((int) event.getRawX() - zoom100X);
        int dy = (int) event.getRawY() - zoom100Y;
        int h = v.getHeight();
        int w = v.getWidth() >> 1;
        if (dy > h * 0.8 && dy < h * 2 && dx < w) {
            wait(new Waitable() {
                @Override
                public void waitFor() {
                    synchronized (map) {
                        if (application.setZoom(1.)) {
                            map.updateMapInfo();
                            map.updateMapCenter();
                        }
                    }
                }
            });
            zoom100X = 0;
            zoom100Y = 0;
        }
        break;
    }
    return false;
}

From source file:com.grottworkshop.gwsswipelayout.SwipeLayout.java

/**
 * if the view (v) wants to handle this event.
 * @param v the v//from  w w  w  .j  av a2  s  .c  o m
 * @param event the event
 * @return v touch event or false
 */
private boolean childNeedHandleTouchEvent(View v, MotionEvent event) {
    if (v == null)
        return false;

    int[] loc = new int[2];
    v.getLocationOnScreen(loc);
    int left = loc[0], top = loc[1];

    return event.getRawX() > left && event.getRawX() < left + v.getWidth() && event.getRawY() > top
            && event.getRawY() < top + v.getHeight() && v.onTouchEvent(event);

}

From source file:net.osmand.plus.views.controls.SwipeDismissListViewTouchListener.java

@Override
public boolean onTouch(View view, MotionEvent ev) {
    if (mViewWidth < 2) {
        mViewWidth = mListView.getWidth();
    }/*  w ww .ja v a 2s .co m*/

    switch (ev.getActionMasked()) {
    case MotionEvent.ACTION_DOWN: {
        if (mSwipePaused) {
            return false;
        }

        // Find the child view that was touched (perform a hit test)
        Rect rect = new Rect();
        int childCount = mListView.getChildCount();
        int[] listViewCoords = new int[2];
        mListView.getLocationOnScreen(listViewCoords);
        int x = (int) ev.getRawX() - listViewCoords[0];
        int y = (int) ev.getRawY() - listViewCoords[1];
        View child;
        for (int i = mListView.getHeaderViewsCount(); i < childCount; i++) {
            child = mListView.getChildAt(i);
            if (child != null) {
                child.getHitRect(rect);
                if (rect.contains(x, y)) {
                    // if a specific swiping layout has been giving, use this to swipe.
                    if (mSwipingLayout > 0) {
                        View swipingView = child.findViewById(mSwipingLayout);
                        if (swipingView != null) {
                            mSwipeDownView = swipingView;
                            mSwipeDownChild = child;
                            break;
                        }
                    }
                    // If no swiping layout has been found, swipe the whole child
                    mSwipeDownView = mSwipeDownChild = child;
                    break;
                }
            }
        }

        if (mSwipeDownView != null) {
            // test if the item should be swiped
            int position = mListView.getPositionForView(mSwipeDownView) - mListView.getHeaderViewsCount();
            if (mCallbacks == null || mCallbacks.canDismiss(position)) {
                mDownX = ev.getRawX();
                mDownY = ev.getRawY();
                mDownPosition = position;

                mVelocityTracker = VelocityTracker.obtain();
                mVelocityTracker.addMovement(ev);
            } else {
                // set back to null to revert swiping
                mSwipeDownView = mSwipeDownChild = null;
            }
        }
        return false;
    }

    case MotionEvent.ACTION_CANCEL: {
        if (mVelocityTracker == null) {
            break;
        }

        if (mSwipeDownView != null && mSwiping) {
            // cancel
            ViewCompat.animate(mSwipeDownView).translationX(0).alpha(1).setDuration(mAnimationTime)
                    .setListener(null);
        }
        mVelocityTracker.recycle();
        mVelocityTracker = null;
        mDownX = 0;
        mDownY = 0;
        mSwipeDownView = mSwipeDownChild = null;
        mDownPosition = ListView.INVALID_POSITION;
        mSwiping = false;
        break;
    }

    case MotionEvent.ACTION_UP: {
        if (mVelocityTracker == null) {
            break;
        }

        float deltaX = ev.getRawX() - mDownX;
        mVelocityTracker.addMovement(ev);
        mVelocityTracker.computeCurrentVelocity(1000);
        float velocityX = Math.abs(mVelocityTracker.getXVelocity());
        float velocityY = Math.abs(mVelocityTracker.getYVelocity());
        boolean dismiss = false;
        boolean dismissRight = false;
        if (Math.abs(deltaX) > mViewWidth / 2 && mSwiping) {
            dismiss = true;
            dismissRight = deltaX > 0;
        } else if (mMinFlingVelocity <= velocityX && velocityX <= mMaxFlingVelocity && velocityY < velocityX
                && mSwiping && isSwipeDirectionValid(mVelocityTracker.getXVelocity())
                && deltaX >= mViewWidth * 0.2f) {
            dismiss = true;
            dismissRight = mVelocityTracker.getXVelocity() > 0;
        }
        if (dismiss) {
            // dismiss
            slideOutView(mSwipeDownView, mSwipeDownChild, mDownPosition, dismissRight);
        } else if (mSwiping) {
            // Swipe back to regular position
            ViewCompat.animate(mSwipeDownView).translationX(0).alpha(1).setDuration(mAnimationTime)
                    .setListener(null);
        }
        mVelocityTracker = null;
        mDownX = 0;
        mDownY = 0;
        mSwipeDownView = null;
        mSwipeDownChild = null;
        mDownPosition = AbsListView.INVALID_POSITION;
        mSwiping = false;
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        if (mVelocityTracker == null || mSwipePaused) {
            break;
        }

        mVelocityTracker.addMovement(ev);
        float deltaX = ev.getRawX() - mDownX;
        float deltaY = ev.getRawY() - mDownY;
        // Only start swipe in correct direction
        if (isSwipeDirectionValid(deltaX)) {
            ViewParent parent = mListView.getParent();
            if (parent != null) {
                // If we swipe don't allow parent to intercept touch (e.g. like NavigationDrawer does)
                // otherwise swipe would not be working.
                parent.requestDisallowInterceptTouchEvent(true);
            }
            if (Math.abs(deltaX) > mSlop && Math.abs(deltaY) < Math.abs(deltaX) / 2) {
                mSwiping = true;
                mListView.requestDisallowInterceptTouchEvent(true);

                // Cancel ListView's touch (un-highlighting the item)
                MotionEvent cancelEvent = MotionEvent.obtain(ev);
                cancelEvent.setAction(MotionEvent.ACTION_CANCEL
                        | (ev.getActionIndex() << MotionEvent.ACTION_POINTER_INDEX_SHIFT));
                mListView.onTouchEvent(cancelEvent);
            }
        } else {
            // If we swiped into wrong direction, act like this was the new
            // touch down point
            mDownX = ev.getRawX();
            deltaX = 0;
        }

        if (mSwiping) {
            ViewCompat.setTranslationX(mSwipeDownView, deltaX);
            ViewCompat.setAlpha(mSwipeDownView,
                    Math.max(0f, Math.min(1f, 1f - 2f * Math.abs(deltaX) / mViewWidth)));
            return true;
        }
        break;
    }
    }
    return false;
}

From source file:com.example.appdetail_optimization.HorizontalListView.java

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN:
        scrollMode = SCROLL_MODE_IDLE;//from w  w w.  j  a va 2 s  . co m
        downEventX = ev.getRawX();
        downEventY = ev.getRawY();
        isFullScroll = false;

        int lastVisiblePos = getLastVisiblePosition();
        if (lastVisiblePos >= mAdapter.getCount() - 1) {
            View view = getChildAt(getChildCount() - 1);
            if (Math.abs(view.getRight() - getWidth()) < 10) {
                isFullScroll = true;
            }
        }
        getParent().requestDisallowInterceptTouchEvent(true);
        break;
    case MotionEvent.ACTION_MOVE:
        if (scrollMode == SCROLL_MODE_HORIZONTAL) {
            // view
        } else if (scrollMode == SCROLL_MODE_VERTICAL) {
            // viewtouch
            return false;
        } else if (scrollMode == SCROLL_MODE_IDLE) {
            float distanceX = Math.abs(ev.getRawX() - downEventX);
            float distanceY = Math.abs(ev.getRawY() - downEventY);
            if (distanceX > distanceY && distanceX > 5) {
                if (isFullScroll) {
                    if (ev.getRawX() < downEventX) {
                        Log.i("LeiTest", "viewpager");
                        scrollMode = SCROLL_MODE_VERTICAL;
                        getParent().requestDisallowInterceptTouchEvent(false);
                        return super.dispatchTouchEvent(ev);
                    }
                }

                scrollMode = SCROLL_MODE_HORIZONTAL;
                getParent().requestDisallowInterceptTouchEvent(true);
            } else if (distanceY > distanceX && distanceY > 5) {
                scrollMode = SCROLL_MODE_VERTICAL;
                getParent().requestDisallowInterceptTouchEvent(false);
                return false;
            }
        }

        break;
    case MotionEvent.ACTION_UP:
        scrollMode = SCROLL_MODE_IDLE;
        getParent().requestDisallowInterceptTouchEvent(false);
        break;

    case MotionEvent.ACTION_CANCEL:
        scrollMode = SCROLL_MODE_IDLE;
        getParent().requestDisallowInterceptTouchEvent(false);
        break;

    default:
        break;
    }

    return super.dispatchTouchEvent(ev);
}

From source file:com.shuxiangbaima.task.view.HorizontalListView.java

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN:
        scrollMode = SCROLL_MODE_IDLE;//from w w w  . j  av a  2 s  . c  o  m
        downEventX = ev.getRawX();
        downEventY = ev.getRawY();
        isFullScroll = false;

        int lastVisiblePos = getLastVisiblePosition();
        if (lastVisiblePos >= mAdapter.getCount() - 1) {
            View view = getChildAt(getChildCount() - 1);
            if (Math.abs(view.getRight() - getWidth()) < 10) {
                isFullScroll = true;
            }
        }
        getParent().requestDisallowInterceptTouchEvent(true);
        break;
    case MotionEvent.ACTION_MOVE:
        if (scrollMode == SCROLL_MODE_HORIZONTAL) {
            // view
        } else if (scrollMode == SCROLL_MODE_VERTICAL) {
            // viewtouch
            return false;
        } else if (scrollMode == SCROLL_MODE_IDLE) {
            float distanceX = Math.abs(ev.getRawX() - downEventX);
            float distanceY = Math.abs(ev.getRawY() - downEventY);
            if (distanceX > distanceY && distanceX > 5) {
                if (isFullScroll) {
                    if (ev.getRawX() < downEventX) {
                        Log.i("LeiTest", "viewpager");
                        scrollMode = SCROLL_MODE_VERTICAL;
                        getParent().requestDisallowInterceptTouchEvent(false);
                        return super.dispatchTouchEvent(ev);
                    }
                }

                scrollMode = SCROLL_MODE_HORIZONTAL;
                getParent().requestDisallowInterceptTouchEvent(true);
            } else if (distanceY > distanceX && distanceY > 5) {
                scrollMode = SCROLL_MODE_VERTICAL;
                getParent().requestDisallowInterceptTouchEvent(false);
                return false;
            }
        }

        break;
    case MotionEvent.ACTION_UP:
        scrollMode = SCROLL_MODE_IDLE;
        getParent().requestDisallowInterceptTouchEvent(false);
        break;

    case MotionEvent.ACTION_CANCEL:
        scrollMode = SCROLL_MODE_IDLE;
        getParent().requestDisallowInterceptTouchEvent(false);
        break;

    default:
        break;
    }

    return super.dispatchTouchEvent(ev);
}

From source file:com.fancyfamily.primarylibrary.commentlibrary.widget.HorizontalListView.java

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN:
        scrollMode = SCROLL_MODE_IDLE;/*ww w . j  a  va2  s  .c  o  m*/
        downEventX = ev.getRawX();
        downEventY = ev.getRawY();
        isFullScroll = false;

        int lastVisiblePos = getLastVisiblePosition();
        if (lastVisiblePos >= mAdapter.getCount() - 1) {
            View view = getChildAt(getChildCount() - 1);

            if (view != null && Math.abs(view.getRight() - getWidth()) < 10) {
                isFullScroll = true;
            }
        }
        getParent().requestDisallowInterceptTouchEvent(true);
        break;
    case MotionEvent.ACTION_MOVE:
        if (scrollMode == SCROLL_MODE_HORIZONTAL) {
            // view
        } else if (scrollMode == SCROLL_MODE_VERTICAL) {
            // viewtouch
            return false;
        } else if (scrollMode == SCROLL_MODE_IDLE) {
            float distanceX = Math.abs(ev.getRawX() - downEventX);
            float distanceY = Math.abs(ev.getRawY() - downEventY);
            if (distanceX > distanceY && distanceX > 5) {
                if (isFullScroll) {
                    if (ev.getRawX() < downEventX) {
                        Log.i("LeiTest", "viewpager");
                        scrollMode = SCROLL_MODE_VERTICAL;
                        getParent().requestDisallowInterceptTouchEvent(false);
                        return super.dispatchTouchEvent(ev);
                    }
                }

                scrollMode = SCROLL_MODE_HORIZONTAL;
                getParent().requestDisallowInterceptTouchEvent(true);
            } else if (distanceY > distanceX && distanceY > 5) {
                scrollMode = SCROLL_MODE_VERTICAL;
                getParent().requestDisallowInterceptTouchEvent(false);
                return false;
            }
        }

        break;
    case MotionEvent.ACTION_UP:
        scrollMode = SCROLL_MODE_IDLE;
        getParent().requestDisallowInterceptTouchEvent(false);
        break;

    case MotionEvent.ACTION_CANCEL:
        scrollMode = SCROLL_MODE_IDLE;
        getParent().requestDisallowInterceptTouchEvent(false);
        break;

    default:
        break;
    }

    return super.dispatchTouchEvent(ev);
}