Example usage for android.graphics Rect contains

List of usage examples for android.graphics Rect contains

Introduction

In this page you can find the example usage for android.graphics Rect contains.

Prototype

public boolean contains(int x, int y) 

Source Link

Document

Returns true if (x,y) is inside the rectangle.

Usage

From source file:com.asc_ii.bangnote.bigbang.BigBangLayout.java

private View findChildByPoint(int x, int y) {
    int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = getChildAt(i);
        Rect rect = new Rect();
        child.getHitRect(rect);//  www  . java2  s .  c o  m
        if (rect.contains(x, y)) {
            return child;
        }
    }
    return null;
}

From source file:com.iangclifton.auid.horizontaliconview.HorizontalIconView.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    }//from   www.j a v  a2 s .c o  m
    mVelocityTracker.addMovement(ev);

    final int action = MotionEventCompat.getActionMasked(ev);
    switch (action) {
    case MotionEvent.ACTION_DOWN: {
        if (!mScroller.isFinished()) {
            mScroller.abortAnimation();
        }

        // Remember where the motion event started
        mPreviousX = (int) MotionEventCompat.getX(ev, 0);
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        if (activePointerIndex == INVALID_POINTER) {
            Log.e(TAG, "Invalid pointerId=" + mActivePointerId + " in onTouchEvent");
            break;
        }

        final int x = (int) MotionEventCompat.getX(ev, 0);
        int deltaX = (int) (mPreviousX - x);
        if (!mIsBeingDragged && Math.abs(deltaX) > mTouchSlop) {
            mIsBeingDragged = true;
            if (deltaX > 0) {
                deltaX -= mTouchSlop;
            } else {
                deltaX += mTouchSlop;
            }
        }
        if (mIsBeingDragged) {
            // Scroll to follow the motion event
            mPreviousX = x;

            final int oldX = getScrollX();
            final int range = mScrollRange;

            if (overScrollBy(deltaX, 0, oldX, 0, range, 0, mOverscrollDistance, 0, true)) {
                // Break our velocity if we hit a scroll barrier.
                mVelocityTracker.clear();
            }

            if (mEdgeEffectLeft != null) {
                final int pulledToX = oldX + deltaX;
                if (pulledToX < 0) {
                    mEdgeEffectLeft.onPull((float) deltaX / getWidth());
                    if (!mEdgeEffectRight.isFinished()) {
                        mEdgeEffectRight.onRelease();
                    }
                } else if (pulledToX > range) {
                    mEdgeEffectRight.onPull((float) deltaX / getWidth());
                    if (!mEdgeEffectLeft.isFinished()) {
                        mEdgeEffectLeft.onRelease();
                    }
                }
                if (!mEdgeEffectLeft.isFinished() || !mEdgeEffectRight.isFinished()) {
                    postInvalidateOnAnimation();
                }

            }

        }
        break;
    }
    case MotionEvent.ACTION_UP: {
        if (mIsBeingDragged) {
            mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
            int initialVelocity = (int) mVelocityTracker.getXVelocity(mActivePointerId);

            if ((Math.abs(initialVelocity) > mMinimumVelocity)) {
                fling(-initialVelocity);
            } else {
                if (mScroller.springBack(getScrollX(), 0, 0, mScrollRange, 0, 0)) {
                    postInvalidateOnAnimation();
                }
            }

            mActivePointerId = INVALID_POINTER;
            mIsBeingDragged = false;
            mVelocityTracker.recycle();
            mVelocityTracker = null;

            if (mEdgeEffectLeft != null) {
                mEdgeEffectLeft.onRelease();
                mEdgeEffectRight.onRelease();
            }
        } else {
            // Was not being dragged, was this a press on an icon?
            final int activePointerIndex = ev.findPointerIndex(mActivePointerId);
            if (activePointerIndex == INVALID_POINTER) {
                return false;
            }
            final int x = (int) ev.getX(activePointerIndex) + getScrollX();
            final int y = (int) ev.getY(activePointerIndex);
            int i = 0;
            for (Rect rect : mIconPositions) {
                if (rect.contains(x, y)) {
                    final int position = i + mSkippedIconCount;
                    Toast.makeText(getContext(),
                            "Pressed icon " + position + "; rect count: " + mIconPositions.size(),
                            Toast.LENGTH_SHORT).show();
                    break;
                }
                i++;
            }
        }
        break;
    }
    case MotionEvent.ACTION_CANCEL: {
        if (mIsBeingDragged) {
            if (mScroller.springBack(getScrollX(), 0, 0, mScrollRange, 0, 0)) {
                postInvalidateOnAnimation();
            }
            mActivePointerId = INVALID_POINTER;
            mIsBeingDragged = false;
            if (mVelocityTracker != null) {
                mVelocityTracker.recycle();
                mVelocityTracker = null;
            }

            if (mEdgeEffectLeft != null) {
                mEdgeEffectLeft.onRelease();
                mEdgeEffectRight.onRelease();
            }
        }
        break;
    }
    case MotionEvent.ACTION_POINTER_UP: {
        onSecondaryPointerUp(ev);
        break;
    }
    }
    return true;
}

From source file:com.fastaccess.ui.modules.repos.RepoPagerActivity.java

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    if (navType == RepoPagerMvp.ISSUES && filterLayout.isShown()) {
        Rect viewRect = ViewHelper.getLayoutPosition(filterLayout);
        if (!viewRect.contains((int) ev.getRawX(), (int) ev.getRawY())) {
            hideFilterLayout();/*from  w  w w.  j  a v  a 2  s.  c o  m*/
        }
    }
    return super.dispatchTouchEvent(ev);
}

From source file:org.odk.collect.android.widgets.ImageWebViewWidget.java

public boolean suppressFlingGesture(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
    if (mImageDisplay == null || mImageDisplay.getVisibility() != View.VISIBLE) {
        return false;
    }//w w  w.j  a  v  a 2  s.  co m

    Rect rect = new Rect();
    mImageDisplay.getHitRect(rect);

    // Log.i(t, "hitRect: " + rect.left + "," + rect.top + " : " +
    // rect.right + "," + rect.bottom );
    // Log.i(t, "e1 Raw, Clean: " + e1.getRawX() + "," + e1.getRawY() +
    // " : " + e1.getX() + "," + e1.getY());
    // Log.i(t, "e2 Raw, Clean: " + e2.getRawX() + "," + e2.getRawY() +
    // " : " + e2.getX() + "," + e2.getY());

    // starts in WebView
    if (rect.contains((int) e1.getRawX(), (int) e1.getRawY())) {
        return true;
    }

    // ends in WebView
    if (rect.contains((int) e2.getRawX(), (int) e2.getRawY())) {
        return true;
    }

    // transits WebView
    if (rect.contains((int) ((e1.getRawX() + e2.getRawX()) / 2.0),
            (int) ((e1.getRawY() + e2.getRawY()) / 2.0))) {
        return true;
    }
    // Log.i(t, "NOT SUPPRESSED");
    return false;
}

From source file:com.codingfeel.sm.views.superrecyclerview.swipe.SwipeDismissRecyclerViewTouchListener.java

private void caseMotionActionDown(MotionEvent motionEvent) {
    // Find the child view that was touched (perform a hit test)
    Rect rect = new Rect();
    int childCount = mRecyclerView.getChildCount();
    int[] listViewCoords = new int[2];
    mRecyclerView.getLocationOnScreen(listViewCoords);
    int x = (int) motionEvent.getRawX() - listViewCoords[0];
    int y = (int) motionEvent.getRawY() - listViewCoords[1];
    View child;//  w  w  w.ja  v a 2s  .  c  o  m
    for (int i = 0; i < childCount; i++) {
        child = mRecyclerView.getChildAt(i);
        child.getHitRect(rect);
        if (rect.contains(x, y)) {
            mDownView = child;
            break;
        }
    }

    if (mDownView != null) {
        mDownX = motionEvent.getRawX();
        mDownY = motionEvent.getRawY();
        mDownPosition = mRecyclerView.getChildAdapterPosition(mDownView);
        if (mCallbacks.canDismiss(mDownPosition)) {
            mVelocityTracker = VelocityTracker.obtain();
            mVelocityTracker.addMovement(motionEvent);
        } else {
            mDownView = null;
        }
    }
}

From source file:com.malinskiy.superrecyclerview.swipe.SwipeDismissRecyclerViewTouchListener.java

private void caseMotionActionDown(MotionEvent motionEvent) {
    // Find the child view that was touched (perform a hit test)
    Rect rect = new Rect();
    int childCount = mRecyclerView.getChildCount();
    int[] listViewCoords = new int[2];
    mRecyclerView.getLocationOnScreen(listViewCoords);
    int x = (int) motionEvent.getRawX() - listViewCoords[0];
    int y = (int) motionEvent.getRawY() - listViewCoords[1];
    View child;// w  w  w  .jav a2 s . c  o m
    for (int i = 0; i < childCount; i++) {
        child = mRecyclerView.getChildAt(i);
        child.getHitRect(rect);
        if (rect.contains(x, y)) {
            mDownView = child;
            break;
        }
    }

    if (mDownView != null) {
        mDownX = motionEvent.getRawX();
        mDownY = motionEvent.getRawY();
        mDownPosition = mRecyclerView.getChildLayoutPosition(mDownView);
        if (mCallbacks.canDismiss(mDownPosition)) {
            mVelocityTracker = VelocityTracker.obtain();
            mVelocityTracker.addMovement(motionEvent);
        } else {
            mDownView = null;
        }
    }
}

From source file:com.actionbarsherlock.internal.widget.IcsAbsSpinner.java

/**
 * Maps a point to a position in the list.
 *
 * @param x X in local coordinate/*from   w w w .java  2s .c  om*/
 * @param y Y in local coordinate
 * @return The position of the item which contains the specified point, or
 *         {@link #INVALID_POSITION} if the point does not intersect an item.
 */
public int pointToPosition(int x, int y) {
    Rect frame = mTouchFrame;
    if (frame == null) {
        mTouchFrame = new Rect();
        frame = mTouchFrame;
    }

    final int count = getChildCount();
    for (int i = count - 1; i >= 0; i--) {
        View child = getChildAt(i);
        if (child.getVisibility() == View.VISIBLE) {
            child.getHitRect(frame);
            if (frame.contains(x, y)) {
                return mFirstPosition + i;
            }
        }
    }
    return INVALID_POSITION;
}

From source file:com.manuelpeinado.numericpageindicator.NumericPageIndicator.java

private boolean isEventOnRect(MotionEvent event, Rect rect) {
    return rect.contains((int) event.getX(), (int) event.getY());
}

From source file:com.daycle.daycleapp.custom.swipelistview.itemmanipulation.swipedismiss.SwipeTouchListener.java

private void disableHorizontalScrollContainerIfNecessary(@NonNull final MotionEvent motionEvent,
        @NonNull final View view) {
    if (mParentIsHorizontalScrollContainer) {
        mListViewWrapper.getListView().requestDisallowInterceptTouchEvent(true);
    } else if (mTouchChildResId != 0) {
        mParentIsHorizontalScrollContainer = false;

        final View childView = view.findViewById(mTouchChildResId);
        if (childView != null) {
            final Rect childRect = getChildViewRect(mListViewWrapper.getListView(), childView);
            if (childRect.contains((int) motionEvent.getX(), (int) motionEvent.getY())) {
                mListViewWrapper.getListView().requestDisallowInterceptTouchEvent(true);
            }//from ww  w. ja  v  a2s  . c  o m
        }
    }
}

From source file:org.faudroids.boredrudolf.ui.CustomSwipeRefreshLayout.java

private boolean canChildrenScrollUp(View view, MotionEvent event) {
    if (view instanceof ViewGroup) {
        final ViewGroup viewgroup = (ViewGroup) view;
        int count = viewgroup.getChildCount();
        for (int i = 0; i < count; ++i) {
            View child = viewgroup.getChildAt(i);
            Rect bounds = new Rect();
            child.getHitRect(bounds);/*from   w w w.  j  a  va 2s  .co  m*/
            if (bounds.contains((int) event.getX(), (int) event.getY())) {
                return canViewScrollUp(child, event);
            }
        }
    }

    return false;
}