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:Main.java

/**
 * <pre>/*w  w  w.  ja  v  a  2  s .co  m*/
 * Determine whether a {@link MotionEvent} is on a {@link View}
 * </pre>
 */
public static boolean motionEventOnView(MotionEvent event, View view) {
    int[] location = new int[2];
    view.getLocationOnScreen(location);
    int x = location[0];
    int y = location[1];
    int w = view.getWidth();
    int h = view.getHeight();
    Rect rect = new Rect(x, y, x + w, y + h);
    return rect.contains((int) event.getRawX(), (int) event.getRawY());
}

From source file:Main.java

public static boolean isMotionFocusOnView(View view, MotionEvent event) {
    Rect focusBound = new Rect();
    view.getFocusedRect(focusBound);//  ww w.  j av a  2  s  .  c  o  m
    return focusBound.contains((int) event.getX(), (int) event.getY());
}

From source file:Main.java

public static boolean inViewInBounds(View view, int x, int y) {
    Rect outRect = new Rect();
    int[] location = new int[2];

    view.getDrawingRect(outRect);//from   w  w  w .j  a  v a2 s.  c  o m
    view.getLocationOnScreen(location);
    outRect.offset(location[0], location[1]);
    return outRect.contains(x, y);
}

From source file:org.onebusaway.android.util.UIUtils.java

/**
 * Returns true if the provided touch event was within the provided view
 *
 * @return true if the provided touch event was within the provided view
 *///from   w  ww  .j a  v  a2  s .  c o m
public static boolean isTouchInView(View view, MotionEvent event) {
    Rect rect = new Rect();
    view.getGlobalVisibleRect(rect);
    return rect.contains((int) event.getRawX(), (int) event.getRawY());
}

From source file:com.ratebeer.android.app.location.TouchableMapViewPager.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    View map = findViewById(R.id.map_nearby);
    if (map != null) {
        Rect rect = new Rect();
        map.getHitRect(rect);/*from   ww w  .  j  a  va  2  s  .co m*/
        int pageOffset = getMeasuredWidth() * activePage;
        if (rect.contains(pageOffset + (int) ev.getX(), (int) ev.getY())) {
            return false;
        }
    }
    return super.onInterceptTouchEvent(ev);
}

From source file:com.todoroo.astrid.ui.TaskListFragmentPager.java

private boolean checkForPeopleHeaderScroll(MotionEvent ev) {
    TaskListFragment current = getCurrentFragment();
    if (current != null) {
        View v = current.getView();
        if (v != null) {
            View peopleView = v.findViewById(R.id.shared_with);
            if (peopleView != null) {
                Rect rect = new Rect();
                peopleView.getHitRect(rect);
                if (rect.contains((int) ev.getX(), (int) ev.getY()))
                    return true;
            }/*from   w  ww.  j ava  2 s  .  com*/
        }
    }
    return false;
}

From source file:com.ftinc.kit.attributr.ui.widget.StickyRecyclerHeadersElevationDecoration.java

/**
 * Gets the position of the header under the specified (x, y) coordinates.
 * @param x x-coordinate//from   w  w  w  .j  a v  a2 s  . c  o m
 * @param y y-coordinate
 * @return position of header, or -1 if not found
 */
public int findHeaderPositionUnder(int x, int y) {
    for (int i = 0; i < mHeaderRects.size(); i++) {
        Rect rect = mHeaderRects.get(mHeaderRects.keyAt(i));
        if (rect.contains(x, y)) {
            return mHeaderRects.keyAt(i);
        }
    }
    return -1;
}

From source file:individual.leobert.calendar.CalendarLayout.java

public boolean isClickView(View view, MotionEvent ev) {
    Rect rect = new Rect();
    view.getHitRect(rect);/*  www  .j  a v a 2s  .  c  o  m*/
    boolean isClick = rect.contains((int) ev.getX(), (int) ev.getY());
    Log.d(TAG, "isClickView() called with: isClick = [" + isClick + "]");
    return isClick;
}

From source file:com.xee.auth.SignInButton.java

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_UP) {
        // detect if user is clicking outside
        Rect viewRect = new Rect();
        getGlobalVisibleRect(viewRect);//from   w  w w.  ja v a2s  .  c  o m
        if (viewRect.contains((int) event.getRawX(), (int) event.getRawY())) {
            if (mListener != null) {
                mListener.onClick(this);
            }
            if (mConnectionCallback != null) {
                signIn();
            }
        }
    }
    return super.dispatchTouchEvent(event);
}

From source file:com.example.zw.demolist.widget.BigBangLayout.java

private View findChildFromPoint(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);/*ww w . j  a  v  a2  s  .c  o m*/
        if (rect.contains(x, y)) {
            return child;
        }
    }
    return null;
}