Example usage for android.graphics Rect intersect

List of usage examples for android.graphics Rect intersect

Introduction

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

Prototype

@CheckResult
public boolean intersect(Rect r) 

Source Link

Document

If the specified rectangle intersects this rectangle, return true and set this rectangle to that intersection, otherwise return false and do not change this rectangle.

Usage

From source file:Main.java

public static Rect calculateActivationIndicatorSize(int sensitivity, int offsetPosition, int offsetSize,
        boolean isOnRightSide, Rect availableRect) {

    int top = availableRect.top;
    int left = availableRect.left;
    int right = availableRect.right;
    int bottom = availableRect.bottom;

    if (isOnRightSide) {
        left = right - sensitivity;// ww w. ja  v a 2s.  c o  m
    } else {
        right = left + sensitivity;
    }

    int height = availableRect.height() - offsetSize;
    top = top + offsetPosition + (offsetSize / 2);
    bottom = top + height;

    Rect result = new Rect(left, top, right, bottom);

    if (!result.intersect(availableRect)) {
        return availableRect;
    }

    return result;
}

From source file:Main.java

/**
 * Returns the node's bounds clipped to the size of the display
 *
 * @param node//from   w w  w  . ja v a  2 s.  c o  m
 * @param width pixel width of the display
 * @param height pixel height of the display
 * @return null if node is null, else a Rect containing visible bounds
 */
public static Rect getVisibleBoundsInScreen(AccessibilityNodeInfo node, int width, int height) {
    if (node == null) {
        return null;
    }
    // targeted node's bounds
    Rect nodeRect = new Rect();
    node.getBoundsInScreen(nodeRect);

    Rect displayRect = new Rect();
    displayRect.top = 0;
    displayRect.left = 0;
    displayRect.right = width;
    displayRect.bottom = height;

    nodeRect.intersect(displayRect);
    return nodeRect;
}

From source file:Main.java

/**
 * Returns the node's bounds clipped to the size of the display
 *
 * @param node/*w  w w  . j ava  2  s. c o m*/
 * @param width pixel width of the display
 * @param height pixel height of the display
 * @return null if node is null, else a Rect containing visible bounds
 */
static Rect getVisibleBoundsInScreen(AccessibilityNodeInfo node, int width, int height) {
    if (node == null) {
        return null;
    }
    // targeted node's bounds
    Rect nodeRect = new Rect();
    node.getBoundsInScreen(nodeRect);

    Rect displayRect = new Rect();
    displayRect.top = 0;
    displayRect.left = 0;
    displayRect.right = width;
    displayRect.bottom = height;

    nodeRect.intersect(displayRect);
    return nodeRect;
}

From source file:Main.java

/**
 * Returns the node's bounds clipped to the size of the display
 *
 * @param node//from  w w  w .j  ava  2s .c o  m
 * @param width  pixel width of the display
 * @param height pixel height of the display
 * @return null if node is null, else a Rect containing visible bounds
 */
public static Rect getVisibleBoundsInScreen(AccessibilityNodeInfo node, int width, int height) {
    if (node == null) {
        return null;
    }
    // targeted node's bounds
    Rect nodeRect = new Rect();
    node.getBoundsInScreen(nodeRect);

    Rect displayRect = new Rect();
    displayRect.top = 0;
    displayRect.left = 0;
    displayRect.right = width;
    displayRect.bottom = height;
    boolean intersect = nodeRect.intersect(displayRect);
    return nodeRect;
}

From source file:Main.java

/**
 * Returns the node's bounds clipped to the size of the display
 *
 * @param node//from ww w.  java 2  s  .  co m
 * @param width pixel width of the display
 * @param height pixel height of the display
 * @return null if node is null, else a Rect containing visible bounds
 */
static Rect getVisibleBoundsInScreen(AccessibilityNodeInfo node, int width, int height) {
    if (node == null) {
        return null;
    }
    // targeted node's bounds
    Rect nodeRect = new Rect();
    node.getBoundsInScreen(nodeRect);

    Rect displayRect = new Rect();
    displayRect.top = 0;
    displayRect.left = 0;
    displayRect.right = width;
    displayRect.bottom = height;

    final boolean intersect = nodeRect.intersect(displayRect);
    return nodeRect;
}

From source file:com.agenmate.lollipop.util.ViewUtils.java

/**
 * Determines if two views intersect in the window.
 *///from  w w w  . j a  va 2  s.c o m
public static boolean viewsIntersect(View view1, View view2) {
    if (view1 == null || view2 == null)
        return false;

    final int[] view1Loc = new int[2];
    view1.getLocationOnScreen(view1Loc);
    final Rect view1Rect = new Rect(view1Loc[0], view1Loc[1], view1Loc[0] + view1.getWidth(),
            view1Loc[1] + view1.getHeight());
    int[] view2Loc = new int[2];
    view2.getLocationOnScreen(view2Loc);
    final Rect view2Rect = new Rect(view2Loc[0], view2Loc[1], view2Loc[0] + view2.getWidth(),
            view2Loc[1] + view2.getHeight());
    return view1Rect.intersect(view2Rect);
}

From source file:com.polyvi.xface.extension.capture.XCaptureScreenImpl.java

/**
 * ?xy??widthheight//from  w w w.  j  a  v  a 2s  .  co  m
 */
private XCaptureScreenOptions getValidOptions(Bitmap bitmap) {
    int captureRectX = mOptions.getX();
    int captureRectY = mOptions.getY();
    int bitmapWidth = bitmap.getWidth();
    int bitmapHeight = bitmap.getHeight();
    int width = mOptions.getWidth();
    int height = mOptions.getHeight();
    Rect captureRect = new Rect(0, 0, 0, 0);
    /**?x y??xy*/
    if (mOptions.iSOnlyXAndYInput()) {
        captureRect = new Rect(captureRectX, captureRectY, bitmapWidth + captureRectX,
                bitmapHeight + captureRectY);
    } else {
        captureRect = new Rect(captureRectX, captureRectY, width + captureRectX, height + captureRectY);
    }
    Rect bitmapRect = new Rect(0, 0, bitmapWidth, bitmapHeight);
    if (captureRect.intersect(bitmapRect)) {
        mOptions.setX(captureRect.left);
        mOptions.setY(captureRect.top);
        mOptions.setWidth(captureRect.right - captureRect.left);
        mOptions.setHeight(captureRect.bottom - captureRect.top);
        /** ???*/
        if (mOptions.getWidth() <= 0 || mOptions.getHeight() <= 0) {
            return null;
        }
        return mOptions;
    } else {
        return null;
    }
}

From source file:com.android.yijiang.kzx.widget.betterpickers.TouchExplorationHelper.java

/**
 * Computes whether the specified {@link android.graphics.Rect} intersects with the visible portion of its parent
 * {@link android.view.View}. Modifies {@code localRect} to contain only the visible portion.
 *
 * @param localRect A rectangle in local (parent) coordinates.
 * @return Whether the specified {@link android.graphics.Rect} is visible on the screen.
 *//*from  w w  w  .  j  a v a2s. co  m*/
private boolean intersectVisibleToUser(Rect localRect) {
    // Missing or empty bounds mean this view is not visible.
    if ((localRect == null) || localRect.isEmpty()) {
        return false;
    }

    // Attached to invisible window means this view is not visible.
    if (mParentView.getWindowVisibility() != View.VISIBLE) {
        return false;
    }

    // An invisible predecessor or one with alpha zero means
    // that this view is not visible to the user.
    Object current = this;
    while (current instanceof View) {
        final View view = (View) current;
        // We have attach info so this view is attached and there is no
        // need to check whether we reach to ViewRootImpl on the way up.
        if ((view.getAlpha() <= 0) || (view.getVisibility() != View.VISIBLE)) {
            return false;
        }
        current = view.getParent();
    }

    // If no portion of the parent is visible, this view is not visible.
    if (!mParentView.getLocalVisibleRect(mTempVisibleRect)) {
        return false;
    }

    // Check if the view intersects the visible portion of the parent.
    return localRect.intersect(mTempVisibleRect);
}

From source file:com.doomonafireball.betterpickers.TouchExplorationHelper.java

/**
 * Computes whether the specified {@link android.graphics.Rect} intersects
 * with the visible portion of its parent {@link android.view.View}.
 * Modifies {@code localRect} to contain only the visible portion.
 * /*from   w  ww. ja v a2  s.c  o  m*/
 * @param localRect
 *            A rectangle in local (parent) coordinates.
 * @return Whether the specified {@link android.graphics.Rect} is visible on
 *         the screen.
 */
@SuppressLint("NewApi")
private boolean intersectVisibleToUser(Rect localRect) {
    // Missing or empty bounds mean this view is not visible.
    if ((localRect == null) || localRect.isEmpty()) {
        return false;
    }

    // Attached to invisible window means this view is not visible.
    if (mParentView.getWindowVisibility() != View.VISIBLE) {
        return false;
    }

    // An invisible predecessor or one with alpha zero means
    // that this view is not visible to the user.
    Object current = this;
    while (current instanceof View) {
        final View view = (View) current;
        // We have attach info so this view is attached and there is no
        // need to check whether we reach to ViewRootImpl on the way up.
        if ((view.getAlpha() <= 0) || (view.getVisibility() != View.VISIBLE)) {
            return false;
        }
        current = view.getParent();
    }

    // If no portion of the parent is visible, this view is not visible.
    if (!mParentView.getLocalVisibleRect(mTempVisibleRect)) {
        return false;
    }

    // Check if the view intersects the visible portion of the parent.
    return localRect.intersect(mTempVisibleRect);
}

From source file:org.holoeverywhere.widget.datetimepicker.TouchExplorationHelper.java

/**
 * Computes whether the specified {@link Rect} intersects with the visible
 * portion of its parent {@link View}. Modifies {@code localRect} to
 * contain only the visible portion.// w  w w.jav a2 s  .c om
 *
 * @param localRect A rectangle in local (parent) coordinates.
 * @return Whether the specified {@link Rect} is visible on the screen.
 */
private boolean intersectVisibleToUser(Rect localRect) {
    // Missing or empty bounds mean this view is not visible.
    if ((localRect == null) || localRect.isEmpty()) {
        return false;
    }

    // Attached to invisible window means this view is not visible.
    if (mParentView.getWindowVisibility() != View.VISIBLE) {
        return false;
    }

    // An invisible predecessor or one with alpha zero means
    // that this view is not visible to the user.
    Object current = this;
    while (current instanceof View) {
        final View view = (View) current;
        // We have attach info so this view is attached and there is no
        // need to check whether we reach to ViewRootImpl on the way up.

        if ((ViewHelper.getAlpha(view) <= 0) || (view.getVisibility() != View.VISIBLE)) {
            return false;
        }
        current = view.getParent();
    }

    // If no portion of the parent is visible, this view is not visible.
    if (!mParentView.getLocalVisibleRect(mTempVisibleRect)) {
        return false;
    }

    // Check if the view intersects the visible portion of the parent.
    return localRect.intersect(mTempVisibleRect);
}