androidx.core.view.MotionEventCompat Java Examples

The following examples show how to use androidx.core.view.MotionEventCompat. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SwipeableViewPager.java    From AsteroidOSSync with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onInterceptTouchEvent(final MotionEvent event) {
    int action = MotionEventCompat.getActionMasked(event);

    switch (action) {
        case (MotionEvent.ACTION_DOWN):
            return super.onInterceptTouchEvent(event);
        case (MotionEvent.ACTION_MOVE):
            if (!swipingAllowed) {
                return false;
            }
            return super.onInterceptTouchEvent(event);
        case (MotionEvent.ACTION_UP):
            if (!swipingAllowed) {
                return false;
            }
            return super.onInterceptTouchEvent(event);
        default:
            return super.onInterceptTouchEvent(event);
    }
}
 
Example #2
Source File: SwipeableViewPager.java    From AsteroidOSSync with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onTouchEvent(final MotionEvent event) {
    int action = MotionEventCompat.getActionMasked(event);

    switch (action) {
        case (MotionEvent.ACTION_DOWN):
            startPos = event.getX();
            currentIt = getCurrentItem();
            resolveSwipingRightAllowed();
            return super.onTouchEvent(event);
        case (MotionEvent.ACTION_MOVE):
            if (!swipingAllowed && startPos - event.getX() > 16) {
                return true;
            }
            return super.onTouchEvent(event);
        case (MotionEvent.ACTION_UP):
            if (!swipingAllowed && startPos - event.getX() > 16) {
                smoothScrollTo(getWidth() * currentIt, 0);
                return true;
            }
            startPos = 0;
            return super.onTouchEvent(event);
        default:
            return super.onTouchEvent(event);
    }
}
 
Example #3
Source File: ItemTouchHelperExtension.java    From CrazyDaily with Apache License 2.0 6 votes vote down vote up
private ViewHolder findSwipedView(MotionEvent motionEvent) {
    final RecyclerView.LayoutManager lm = mRecyclerView.getLayoutManager();
    if (mActivePointerId == ACTIVE_POINTER_ID_NONE) {
        return null;
    }
    final int pointerIndex = MotionEventCompat.findPointerIndex(motionEvent, mActivePointerId);
    final float dx = MotionEventCompat.getX(motionEvent, pointerIndex) - mInitialTouchX;
    final float dy = MotionEventCompat.getY(motionEvent, pointerIndex) - mInitialTouchY;
    final float absDx = Math.abs(dx);
    final float absDy = Math.abs(dy);

    if (absDx < mSlop && absDy < mSlop) {
        return null;
    }
    if (absDx > absDy && lm.canScrollHorizontally()) {
        return null;
    } else if (absDy > absDx && lm.canScrollVertically()) {
        return null;
    }
    View child = findChildView(motionEvent);
    if (child == null) {
        return null;
    }
    return mRecyclerView.getChildViewHolder(child);
}
 
Example #4
Source File: NestedScrollView.java    From AndroidAnimationExercise with Apache License 2.0 6 votes vote down vote up
private void onSecondaryPointerUp(MotionEvent ev) {
    final int pointerIndex = (ev.getAction() & MotionEventCompat.ACTION_POINTER_INDEX_MASK)
            >> MotionEventCompat.ACTION_POINTER_INDEX_SHIFT;
    final int pointerId = ev.getPointerId(pointerIndex);
    if (pointerId == mActivePointerId) {
        // This was our active pointer going up. Choose a new
        // active pointer and adjust accordingly.
        // TODO: Make this decision more intelligent.
        final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
        mLastMotionY = (int) ev.getY(newPointerIndex);
        mActivePointerId = ev.getPointerId(newPointerIndex);
        if (mVelocityTracker != null) {
            mVelocityTracker.clear();
        }
    }
}
 
Example #5
Source File: SuperRecyclerView.java    From NewFastFrame with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onInterceptTouchEvent(MotionEvent e) {
    if (mRefreshEnabled) {
        final int action = MotionEventCompat.getActionMasked(e);
        final int actionIndex = MotionEventCompat.getActionIndex(e);
        switch (action) {
            case MotionEvent.ACTION_DOWN: {
                mActivePointerId = MotionEventCompat.getPointerId(e, 0);
                mLastTouchX = (int) (MotionEventCompat.getX(e, actionIndex) + 0.5f);
                mLastTouchY = (int) (MotionEventCompat.getY(e, actionIndex) + 0.5f);
            }
            break;
            case MotionEvent.ACTION_POINTER_DOWN: {
                mActivePointerId = MotionEventCompat.getPointerId(e, actionIndex);
                mLastTouchX = (int) (MotionEventCompat.getX(e, actionIndex) + 0.5f);
                mLastTouchY = (int) (MotionEventCompat.getY(e, actionIndex) + 0.5f);
            }
            break;
            case MotionEventCompat.ACTION_POINTER_UP: {
                onPointerUp(e);
            }
            break;
        }
    }
    return super.onInterceptTouchEvent(e);
}
 
Example #6
Source File: FloatingNavigationView.java    From Floating-Navigation-View with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onTouch(@NonNull View v, @NonNull MotionEvent event) {
    final int x = (int) event.getX();
    final int y = (int) event.getY();
    if ((MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN)
            && ((x < 0) || (x >= mNavigationView.getWidth())
            || (y < 0) || (y >= mNavigationView.getHeight()))) {
        close();
        return true;
    } else if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_OUTSIDE) {
        close();
        return true;
    }
    return false;
}
 
Example #7
Source File: ItemTouchHelperExtension.java    From CrazyDaily with Apache License 2.0 5 votes vote down vote up
@Override
public void onLongPress(MotionEvent e) {
    View child = findChildView(e);
    if (child != null) {
        ViewHolder vh = mRecyclerView.getChildViewHolder(child);
        if (vh != null) {
            if (!mCallback.hasDragFlag(mRecyclerView, vh)) {
                return;
            }
            int pointerId = MotionEventCompat.getPointerId(e, 0);
            // Long press is deferred.
            // Check w/ active pointer id to avoid selecting after motion
            // event is canceled.
            if (pointerId == mActivePointerId) {
                final int index = MotionEventCompat
                        .findPointerIndex(e, mActivePointerId);
                final float x = MotionEventCompat.getX(e, index);
                final float y = MotionEventCompat.getY(e, index);
                mInitialTouchX = x;
                mInitialTouchY = y;
                mDx = mDy = 0f;
                if (DEBUG) {
                    Log.d(TAG,
                            "onlong press: x:" + mInitialTouchX + ",y:" + mInitialTouchY);
                }
                if (mCallback.isLongPressDragEnabled()) {
                    select(vh, ACTION_STATE_DRAG);
                }
            }
            handleTouch(e);
        }
    }
}
 
Example #8
Source File: DuoDrawerLayout.java    From duo-navigation-drawer with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    final int action = MotionEventCompat.getActionMasked(ev);

    switch (action) {
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP: {
            mViewDragHelper.cancel();
            return false;
        }
    }

    return mViewDragHelper.shouldInterceptTouchEvent(ev);
}
 
Example #9
Source File: DragLayout.java    From UIWidget with Apache License 2.0 5 votes vote down vote up
private float getMotionEventY(MotionEvent ev, int activePointerId) {
    final int index = MotionEventCompat.findPointerIndex(ev, activePointerId);
    if (index < 0) {
        return -1;
    }
    return MotionEventCompat.getY(ev, index);
}
 
Example #10
Source File: CustomViewPager.java    From AsteroidOSSync with GNU General Public License v3.0 5 votes vote down vote up
private void onSecondaryPointerUp(MotionEvent ev) {
    final int pointerIndex = MotionEventCompat.getActionIndex(ev);
    final int pointerId = ev.getPointerId(pointerIndex);
    if (pointerId == mActivePointerId) {
        // This was our active pointer going up. Choose a new
        // active pointer and adjust accordingly.
        final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
        mLastMotionX = ev.getX(newPointerIndex);
        mActivePointerId = ev.getPointerId(newPointerIndex);
        if (mVelocityTracker != null) {
            mVelocityTracker.clear();
        }
    }
}
 
Example #11
Source File: PlaylistAdapter.java    From YouTube-In-Background with MIT License 5 votes vote down vote up
@Override
public boolean onTouch(View v, MotionEvent event)
{
    // Start a drag whenever the handle view it touched
    if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
        playlistAdapter.onItemHolderStartDrag(this);
    }
    return false;
}
 
Example #12
Source File: SwipeBackLayout.java    From AndroidAnimationExercise with Apache License 2.0 5 votes vote down vote up
@Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        switch (MotionEventCompat.getActionMasked(ev)) {
            case MotionEvent.ACTION_DOWN:
                downX = ev.getRawX();
                downY = ev.getRawY();
                break;
            case MotionEvent.ACTION_MOVE:
                if (innerScrollView != null && Util.contains(innerScrollView, downX, downY)) {
                    float distanceX = Math.abs(ev.getRawX() - downX);
                    float distanceY = Math.abs(ev.getRawY() - downY);
                    if (mDirectionMode == FROM_LEFT || mDirectionMode == FROM_RIGHT) {
                        if (distanceY > mTouchSlop && distanceY > distanceX) {
                            return super.onInterceptTouchEvent(ev);
                        }
                    } else if (mDirectionMode == FROM_TOP || mDirectionMode == FROM_BOTTOM) {
                        if (distanceX > mTouchSlop && distanceX > distanceY) {
                            return super.onInterceptTouchEvent(ev);
                        }
                    } else {
//                        return super.onInterceptTouchEvent(ev);
                    }
                }
                break;
        }
        boolean handled = mDragHelper.shouldInterceptTouchEvent(ev);
        return handled ? handled : super.onInterceptTouchEvent(ev);
    }
 
Example #13
Source File: FlipView.java    From AndroidAnimationExercise with Apache License 2.0 5 votes vote down vote up
private void onSecondaryPointerUp(MotionEvent ev) {
    final int pointerIndex = MotionEventCompat.getActionIndex(ev);
    final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
    if (pointerId == mActivePointerId) {
        // This was our active pointer going up. Choose a new
        // active pointer and adjust accordingly.
        final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
        mLastX = MotionEventCompat.getX(ev, newPointerIndex);
        mActivePointerId = MotionEventCompat.getPointerId(ev,
                newPointerIndex);
        if (mVelocityTracker != null) {
            mVelocityTracker.clear();
        }
    }
}
 
Example #14
Source File: NestedScrollView.java    From AndroidAnimationExercise with Apache License 2.0 5 votes vote down vote up
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDeviceCompat.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
            case MotionEventCompat.ACTION_SCROLL: {
                if (!mIsBeingDragged) {
                    final float vscroll = MotionEventCompat.getAxisValue(event,
                            MotionEventCompat.AXIS_VSCROLL);
                    if (vscroll != 0) {
                        final int delta = (int) (vscroll * getVerticalScrollFactorCompat());
                        final int range = getScrollRange();
                        int oldScrollY = getScrollY();
                        int newScrollY = oldScrollY - delta;
                        if (newScrollY < 0) {
                            newScrollY = 0;
                        } else if (newScrollY > range) {
                            newScrollY = range;
                        }
                        if (newScrollY != oldScrollY) {
                            super.scrollTo(getScrollX(), newScrollY);
                            return true;
                        }
                    }
                }
            }
        }
    }
    return false;
}
 
Example #15
Source File: ViewDragHelper.java    From AndroidAnimationExercise with Apache License 2.0 5 votes vote down vote up
private void saveLastMotion(MotionEvent ev) {
    final int pointerCount = MotionEventCompat.getPointerCount(ev);
    for (int i = 0; i < pointerCount; i++) {
        final int pointerId = MotionEventCompat.getPointerId(ev, i);
        final float x = MotionEventCompat.getX(ev, i);
        final float y = MotionEventCompat.getY(ev, i);
        // Sometimes we can try and save last motion for a pointer never recorded in initial motion. In this case we just discard it.
        if (mLastMotionX != null && mLastMotionY != null
                && mLastMotionX.length > pointerId && mLastMotionY.length > pointerId) {
            mLastMotionX[pointerId] = x;
            mLastMotionY[pointerId] = y;
        }
    }
}
 
Example #16
Source File: DragLinearLayout.java    From opentasks with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onTouch(View v, MotionEvent event)
{
    if (MotionEvent.ACTION_DOWN == MotionEventCompat.getActionMasked(event))
    {
        startDetectingDrag(view);
    }
    return false;
}
 
Example #17
Source File: SortFragment.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(@NonNull final ViewHolder vh, int position) {

    final Times c = getItem(position);
    if (c == null) {
        return;
    }
    vh.city.setText(c.getName());
    vh.source.setText(c.getSource().name);
    vh.gps.setVisibility(c.isAutoLocation() ? View.VISIBLE : View.GONE);
    vh.delete.setVisibility(mDeleteMode ? View.VISIBLE : View.GONE);

    vh.delete.setOnClickListener(view -> onItemDismiss(vh.getAdapterPosition()));
    vh.handler.setOnTouchListener((view, event) -> {
        if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
            mItemTouchHelper.startDrag(vh);
        }

        return false;
    });

    vh.itemView.setOnClickListener(view -> act.onItemClick(vh.getAdapterPosition()));
    vh.itemView.setOnLongClickListener(c instanceof CalcTimes ? (View.OnLongClickListener) v -> {
        CalcTimeConfDialogFragment.forCity((CalcTimes) c).show(getChildFragmentManager(), "calcconfig");
        return true;
    } : null);
}
 
Example #18
Source File: NestedWebview.java    From SimplicityBrowser with MIT License 5 votes vote down vote up
private void onSecondaryPointerUp(MotionEvent ev) {
    //noinspection deprecation
    final int pointerIndex = (ev.getAction() & MotionEventCompat.ACTION_POINTER_INDEX_MASK)
            >> MotionEventCompat.ACTION_POINTER_INDEX_SHIFT;
    final int pointerId = ev.getPointerId(pointerIndex);
    if (pointerId == mActivePointerId) {
        final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
        int mLastMotionY = (int) ev.getY(newPointerIndex);
        mActivePointerId = ev.getPointerId(newPointerIndex);
        if (mVelocityTracker != null) {
            mVelocityTracker.clear();
        }
    }
}
 
Example #19
Source File: AdapterBookmarks.java    From SimplicityBrowser with MIT License 5 votes vote down vote up
@SuppressWarnings("deprecation")
@SuppressLint("ClickableViewAccessibility")
public void onBindViewHolder(@NonNull final ViewHolderBookmark holder, int position) {
    holder.bind(filteredBookmarks.get(position));
    holder.letter.setOnTouchListener((v, event) -> {
        if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
            mDragStartListener.onStartDrag(holder);
        }
        return false;
    });
}
 
Example #20
Source File: PullRefreshLayout.java    From QuickDevFramework with Apache License 2.0 5 votes vote down vote up
private float getMotionY(MotionEvent ev, int activePointerId) {
    final int index = MotionEventCompat.findPointerIndex(ev, activePointerId);
    if (index < 0) {
        return -1;
    }
    return MotionEventCompat.getY(ev, index);
}
 
Example #21
Source File: PullRefreshLayout.java    From QuickDevFramework with Apache License 2.0 5 votes vote down vote up
private void onSecondaryPointerUp(MotionEvent ev) {
    final int pointerIndex = MotionEventCompat.getActionIndex(ev);
    final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
    if (pointerId == mActivePointerId) {
        final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
        mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
    }
}
 
Example #22
Source File: BaseItemDraggableAdapter.java    From BaseProject with Apache License 2.0 5 votes vote down vote up
/**
 * Set the drag event should be trigger on long press.
 * Work when the toggleViewId has been set.
 *
 * @param longPress by default is true.
 */
public void setToggleDragOnLongPress(boolean longPress) {
    mDragOnLongPress = longPress;
    if (mDragOnLongPress) {
        mOnToggleViewTouchListener = null;
        mOnToggleViewLongClickListener = new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                if (mItemTouchHelper != null && itemDragEnabled) {
                    mItemTouchHelper.startDrag((RecyclerView.ViewHolder) v.getTag(R.id.BaseQuickAdapter_viewholder_support));
                }
                return true;
            }
        };
    } else {
        mOnToggleViewTouchListener = new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN
                        && !mDragOnLongPress) {
                    if (mItemTouchHelper != null && itemDragEnabled) {
                        mItemTouchHelper.startDrag((RecyclerView.ViewHolder) v.getTag(R.id.BaseQuickAdapter_viewholder_support));
                    }
                    return true;
                } else {
                    return false;
                }
            }
        };
        mOnToggleViewLongClickListener = null;
    }
}
 
Example #23
Source File: VRefreshLayout.java    From BaseProject with Apache License 2.0 5 votes vote down vote up
private void checkOtherPointerUp(MotionEvent ev) {
    int pointIndex = MotionEventCompat.getActionIndex(ev);
    int pointerId = ev.getPointerId(pointIndex);
    if (pointerId == mActivePointerId) {
        int newPointIndex = pointIndex == 0 ? 1 : 0;
        mActivePointerId = ev.getPointerId(newPointIndex);
    }
}
 
Example #24
Source File: QuickAttachmentDrawer.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
  final int action = MotionEventCompat.getActionMasked(event);

  if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
    dragHelper.cancel();
    return false;
  }

  final float x = event.getX();
  final float y = event.getY();

  switch (action) {
  case MotionEvent.ACTION_DOWN:
    initialMotionX = x;
    initialMotionY = y;
    break;

  case MotionEvent.ACTION_MOVE:
    final float adx = Math.abs(x - initialMotionX);
    final float ady = Math.abs(y - initialMotionY);
    final int dragSlop = dragHelper.getTouchSlop();

    if (adx > dragSlop && ady < dragSlop) {
      return super.onInterceptTouchEvent(event);
    }

    if ((ady > dragSlop && adx > ady) || !isDragViewUnder((int) initialMotionX, (int) initialMotionY)) {
      dragHelper.cancel();
      return false;
    }
    break;
  }
  return dragHelper.shouldInterceptTouchEvent(event);
}
 
Example #25
Source File: SlidingLayout.java    From CloudReader with Apache License 2.0 5 votes vote down vote up
private float getMotionEventY(MotionEvent ev, int activePointerId) {
    final int index = MotionEventCompat.findPointerIndex(ev, activePointerId);
    if (index < 0) {
        return -1;
    }
    return MotionEventCompat.getY(ev, index);
}
 
Example #26
Source File: SortFragment.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(@NonNull final ViewHolder vh, int position) {

    final Times c = getItem(position);
    if (c == null) {
        return;
    }
    vh.city.setText(c.getName());
    vh.source.setText(c.getSource().name);
    vh.gps.setVisibility(c.isAutoLocation() ? View.VISIBLE : View.GONE);
    vh.delete.setVisibility(mDeleteMode ? View.VISIBLE : View.GONE);

    vh.delete.setOnClickListener(view -> onItemDismiss(vh.getAdapterPosition()));
    vh.handler.setOnTouchListener((view, event) -> {
        if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
            mItemTouchHelper.startDrag(vh);
        }

        return false;
    });

    vh.itemView.setOnClickListener(view -> act.onItemClick(vh.getAdapterPosition()));
    vh.itemView.setOnLongClickListener(c instanceof CalcTimes ? (View.OnLongClickListener) v -> {
        CalcTimeConfDialogFragment.forCity((CalcTimes) c).show(getChildFragmentManager(), "calcconfig");
        return true;
    } : null);
}
 
Example #27
Source File: SwipeListView.java    From UltimateRecyclerView with Apache License 2.0 5 votes vote down vote up
/**
 * @see ListView#onInterceptTouchEvent(MotionEvent)
 */
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    int action = MotionEventCompat.getActionMasked(ev);
    final float x = ev.getX();
    final float y = ev.getY();

    if (isEnabled() && touchListener.isSwipeEnabled()) {

        if (touchState == TOUCH_STATE_SCROLLING_X) {
            return touchListener.onTouch(this, ev);
        }

        switch (action) {
            case MotionEvent.ACTION_MOVE:
                checkInMoving(x, y);
                return touchState == TOUCH_STATE_SCROLLING_Y;
            case MotionEvent.ACTION_DOWN:
                super.onInterceptTouchEvent(ev);
                touchListener.onTouch(this, ev);
                touchState = TOUCH_STATE_REST;
                lastMotionX = x;
                lastMotionY = y;
                return false;
            case MotionEvent.ACTION_CANCEL:
                touchState = TOUCH_STATE_REST;
                break;
            case MotionEvent.ACTION_UP:
                touchListener.onTouch(this, ev);
                return touchState == TOUCH_STATE_SCROLLING_Y;
            default:
                break;
        }
    }

    return super.onInterceptTouchEvent(ev);
}
 
Example #28
Source File: ViewDragHelper.java    From toktok-android with GNU General Public License v3.0 5 votes vote down vote up
private void saveLastMotion(@NonNull MotionEvent ev) {
    final int pointerCount = MotionEventCompat.getPointerCount(ev);
    for (int i = 0; i < pointerCount; i++) {
        final int pointerId = MotionEventCompat.getPointerId(ev, i);
        final float x = MotionEventCompat.getX(ev, i);
        final float y = MotionEventCompat.getY(ev, i);
        // Sometimes we can try and save last motion for a pointer never recorded in initial motion. In this case we just discard it.
        if (mLastMotionX != null && mLastMotionY != null
                && mLastMotionX.length > pointerId && mLastMotionY.length > pointerId) {
            mLastMotionX[pointerId] = x;
            mLastMotionY[pointerId] = y;
        }
    }
}
 
Example #29
Source File: ViewDragHelper.java    From hipda with GNU General Public License v2.0 5 votes vote down vote up
private void saveLastMotion(MotionEvent ev) {
    final int pointerCount = MotionEventCompat.getPointerCount(ev);
    for (int i = 0; i < pointerCount; i++) {
        final int pointerId = MotionEventCompat.getPointerId(ev, i);
        final float x = MotionEventCompat.getX(ev, i);
        final float y = MotionEventCompat.getY(ev, i);
        mLastMotionX[pointerId] = x;
        mLastMotionY[pointerId] = y;
    }
}
 
Example #30
Source File: ListPopupWindow.java    From material with Apache License 2.0 5 votes vote down vote up
/**
 * Handled forwarded motion events and determines when to stop forwarding.
 *
 * @param srcEvent motion event in source view coordinates
 * @return true to continue forwarding motion events, false to cancel
 */
private boolean onTouchForwarded(MotionEvent srcEvent) {
    final View src = mSrc;
    final ListPopupWindow popup = getPopup();
    if (popup == null || !popup.isShowing()) {
        return false;
    }

    final DropDownListView dst = popup.mDropDownList;
    if (dst == null || !dst.isShown()) {
        return false;
    }

    // Convert event to destination-local coordinates.
    final MotionEvent dstEvent = MotionEvent.obtainNoHistory(srcEvent);
    toGlobalMotionEvent(src, dstEvent);
    toLocalMotionEvent(dst, dstEvent);

    // Forward converted event to destination view, then recycle it.
    final boolean handled = dst.onForwardedEvent(dstEvent, mActivePointerId);
    dstEvent.recycle();

    // Always cancel forwarding when the touch stream ends.
    final int action = MotionEventCompat.getActionMasked(srcEvent);
    final boolean keepForwarding = action != MotionEvent.ACTION_UP
            && action != MotionEvent.ACTION_CANCEL;

    return handled && keepForwarding;
}