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:org.awesomeapp.messenger.ui.ConversationView.java

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

    view.getHitRect(outRect);/*from w ww.  java 2  s .c  o m*/

    return outRect.contains(x, y);
}

From source file:chan.android.app.bitwise.util.StaggeredGridView.java

/**
 * Maps a point to a position in the list.
 *
 * @param x X in local coordinate/*from  www. ja  v  a2s.co  m*/
 * @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--) {
        final 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:android.support.design.widget.CoordinatorLayout.java

/**
 * Check if a given point in the CoordinatorLayout's coordinates are within the view bounds
 * of the given direct child view./*  w  w  w.ja va 2s.c o  m*/
 *
 * @param child child view to test
 * @param x X coordinate to test, in the CoordinatorLayout's coordinate system
 * @param y Y coordinate to test, in the CoordinatorLayout's coordinate system
 * @return true if the point is within the child view's bounds, false otherwise
 */
public boolean isPointInChildBounds(View child, int x, int y) {
    final Rect r = acquireTempRect();
    getDescendantRect(child, r);
    try {
        return r.contains(x, y);
    } finally {
        releaseTempRect(r);
    }
}

From source file:com.zyk.launcher.AsyncTaskCallback.java

@Override
public boolean onEnterScrollArea(int x, int y, int direction) {
    // Ignore the scroll area if we are dragging over the hot seat
    boolean isPortrait = !LauncherAppState.isScreenLandscape(getContext());
    if (mLauncher.getHotseat() != null && isPortrait) {
        Rect r = new Rect();
        mLauncher.getHotseat().getHitRect(r);
        if (r.contains(x, y)) {
            return false;
        }/*from  w w  w.  java 2  s . c  om*/
    }

    boolean result = false;
    //        if (!workspaceInModalState() && !mIsSwitchingState && mDragUtils.getOpenFolder() == null) {
    if (!workspaceInModalState() && mDragUtils.getOpenFolder() == null) {
        mInScrollArea = true;

        final int page = getNextPage() + (direction == DragController.SCROLL_LEFT ? -1 : 1);
        // We always want to exit the current layout to ensure parity of enter / exit
        setCurrentDropLayout(null);

        if (0 <= page && page < getChildCount()) {
            // Ensure that we are not dragging over to the custom content screen
            //FIXME
            //                if (getScreenIdForPageIndex(page) == Workspace.CUSTOM_CONTENT_SCREEN_ID) {
            //                    return false;
            //                }

            CellLayout layout = (CellLayout) getChildAt(page);
            setCurrentDragOverlappingLayout(layout);

            // Workspace is responsible for drawing the edge glow on adjacent pages,
            // so we need to redraw the workspace when this may have changed.
            invalidate();
            result = true;
        }
    }
    return result;
}

From source file:com.bolaa.medical.view.pulltorefreshgrid.StaggeredGridView.java

public int getLastPosition() {
    Rect frame = mTouchFrame;
    if (frame == null) {
        mTouchFrame = new Rect();
        frame = mTouchFrame;//from w  ww.ja  v a 2s .  co m
    }

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

From source file:com.bolaa.medical.view.pulltorefreshgrid.StaggeredGridView.java

public int getFirstVisiblePosition() {
    Rect frame = mTouchFrame;
    if (frame == null) {
        mTouchFrame = new Rect();
        frame = mTouchFrame;//  ww  w .j ava2 s  . com
    }

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

From source file:com.android.launcher2.Workspace.java

@Override
public boolean onEnterScrollArea(int x, int y, int direction) {
    // Ignore the scroll area if we are dragging over the hot seat
    boolean isPortrait = !LauncherApplication.isScreenLandscape(getContext());
    if (mLauncher.getHotseat() != null && isPortrait) {
        Rect r = new Rect();
        mLauncher.getHotseat().getHitRect(r);
        if (r.contains(x, y)) {
            return false;
        }//from  ww  w .j  a  v a2 s.  c  o m
    }

    boolean result = false;
    if (!isSmall() && !mIsSwitchingState) {
        mInScrollArea = true;

        final int page = getNextPage() + (direction == DragController.SCROLL_LEFT ? -1 : 1);

        // We always want to exit the current layout to ensure parity of enter / exit
        setCurrentDropLayout(null);

        if (0 <= page && page < getChildCount()) {
            CellLayout layout = (CellLayout) getChildAt(page);
            setCurrentDragOverlappingLayout(layout);

            // Workspace is responsible for drawing the edge glow on adjacent pages,
            // so we need to redraw the workspace when this may have changed.
            invalidate();
            result = true;
        }
    }
    return result;
}

From source file:app.umitems.greenclock.widget.sgv.StaggeredGridView.java

/**
 * Return the child view specified by the coordinates if
 * there exists a child there./* www  .  jav  a2 s.co  m*/
 *
 * @return the child in this StaggeredGridView at the coordinates, null otherwise.
 */
private View getChildAtCoordinate(int x, int y) {
    if (y < 0) {
        // TODO: If we've dragged off the screen, return null for now until we know what
        // we'd like the experience to be like.
        return null;
    }

    final Rect frame = new Rect();
    final int count = getChildCount();
    for (int i = 0; i < count; i++) {

        final View childView = getChildAt(i);
        childView.getHitRect(frame);
        if (frame.contains(x, y)) {
            return getChildAt(i);
        }
    }

    // No child view at this coordinate.
    return null;
}

From source file:cc.flydev.launcher.Workspace.java

@Override
public boolean onEnterScrollArea(int x, int y, int direction) {
    // Ignore the scroll area if we are dragging over the hot seat
    boolean isPortrait = !LauncherAppState.isScreenLandscape(getContext());
    if (mLauncher.getHotseat() != null && isPortrait) {
        Rect r = new Rect();
        mLauncher.getHotseat().getHitRect(r);
        if (r.contains(x, y)) {
            return false;
        }/*from   w w  w  .ja  va2 s.c  o m*/
    }

    boolean result = false;
    if (!isSmall() && !mIsSwitchingState && getOpenFolder() == null) {
        mInScrollArea = true;

        final int page = getNextPage() + (direction == DragController.SCROLL_LEFT ? -1 : 1);
        // We always want to exit the current layout to ensure parity of enter / exit
        setCurrentDropLayout(null);

        if (0 <= page && page < getChildCount()) {
            // Ensure that we are not dragging over to the custom content screen
            if (getScreenIdForPageIndex(page) == CUSTOM_CONTENT_SCREEN_ID) {
                return false;
            }

            CellLayout layout = (CellLayout) getChildAt(page);
            setCurrentDragOverlappingLayout(layout);

            // Workspace is responsible for drawing the edge glow on adjacent pages,
            // so we need to redraw the workspace when this may have changed.
            invalidate();
            result = true;
        }
    }
    return result;
}

From source file:com.kogitune.launcher3.Workspace.java

@Override
public boolean onEnterScrollArea(int x, int y, int direction) {
    // Ignore the scroll area if we are dragging over the hot seat
    boolean isPortrait = !LauncherAppState.isScreenLandscape(getContext());
    if (mLauncher.getHotseat() != null && isPortrait) {
        Rect r = new Rect();
        mLauncher.getHotseat().getHitRect(r);
        if (r.contains(x, y)) {
            return false;
        }//from w  ww . j  ava2  s  . c  o m
    }

    boolean result = false;
    // can move in Small
    if (/*!isSmall() && */!mIsSwitchingState && getOpenFolder() == null) {
        mInScrollArea = true;

        final int page = getNextPage() + (direction == DragController.SCROLL_LEFT ? -1 : 1);
        // We always want to exit the current layout to ensure parity of enter / exit
        setCurrentDropLayout(null);

        if (0 <= page && page < getChildCount()) {
            // Ensure that we are not dragging over to the custom content screen
            if (getScreenIdForPageIndex(page) == CUSTOM_CONTENT_SCREEN_ID) {
                return false;
            }

            CellLayout layout = (CellLayout) getChildAt(page);
            setCurrentDragOverlappingLayout(layout);

            // Workspace is responsible for drawing the edge glow on adjacent pages,
            // so we need to redraw the workspace when this may have changed.
            invalidate();
            result = true;
        }
    }
    return result;
}