Example usage for android.graphics Rect intersects

List of usage examples for android.graphics Rect intersects

Introduction

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

Prototype

public static boolean intersects(Rect a, Rect b) 

Source Link

Document

Returns true iff the two specified rectangles intersect.

Usage

From source file:com.android.utils.traversal.DirectionalTraversalStrategy.java

/**
 * Goes through root and its descendant nodes, sorting out the focusable nodes and the
 * container nodes for use in finding focus.
 * @return whether the root is focusable or has focusable children in its hierarchy
 *//*  w w  w .  j  a v  a  2 s . c om*/
private boolean processNodes(AccessibilityNodeInfoCompat root, boolean forceRefresh) {
    if (root == null) {
        return false;
    }

    if (forceRefresh) {
        root.refresh();
    }

    Rect currentRect = new Rect();
    root.getBoundsInScreen(currentRect);

    // Determine if the node is inside mRootRect (within a fudge factor). If it is outside, we
    // will optimize by skipping its entire hierarchy.
    if (!Rect.intersects(currentRect, mRootRectPadded)) {
        return false;
    }

    AccessibilityNodeInfoCompat rootNode = AccessibilityNodeInfoCompat.obtain(root);
    mAllNodes.add(rootNode);

    boolean isFocusable = AccessibilityNodeInfoUtils.shouldFocusNode(rootNode, mSpeakingNodesCache);
    if (isFocusable) {
        mFocusables.add(rootNode);
    }

    boolean hasFocusableDescendants = false;
    int childCount = rootNode.getChildCount();
    for (int i = 0; i < childCount; ++i) {
        AccessibilityNodeInfoCompat child = rootNode.getChild(i);
        if (child != null) {
            hasFocusableDescendants |= processNodes(child, forceRefresh);
            child.recycle();
        }
    }

    if (hasFocusableDescendants) {
        mContainers.add(rootNode);
    }

    return isFocusable || hasFocusableDescendants;
}

From source file:com.android.switchaccess.SwitchAccessNodeCompat.java

private void updateVisibility() {
    if (!mVisibilityCalculated) {
        mVisibleBoundsInScreen = new Rect();
        getBoundsInScreen(mVisibleBoundsInScreen);
        /* Deal with visibility implications for windows above */
        Rect windowBoundsInScreen = new Rect();
        for (int i = 0; i < mWindowsAbove.size(); ++i) {
            mWindowsAbove.get(i).getBoundsInScreen(windowBoundsInScreen);
            mVisibleBoundsInScreen.sort();
            windowBoundsInScreen.sort();
            if (Rect.intersects(mVisibleBoundsInScreen, windowBoundsInScreen)) {
                adjustRectToAvoidIntersection(mVisibleBoundsInScreen, windowBoundsInScreen);
            }/*from  w ww .j  a v a  2s  . c  om*/
        }
        mVisibilityCalculated = true;
    }
}

From source file:com.facebook.litho.MountState.java

/**
 * Mount the layoutState on the pre-set HostView.
 * @param layoutState/*from w w  w  . ja  va 2  s  . co  m*/
 * @param localVisibleRect If this variable is null, then mount everything, since incremental
 *                         mount is not enabled.
 *                         Otherwise mount only what the rect (in local coordinates) contains
 */
void mount(LayoutState layoutState, Rect localVisibleRect) {
    assertMainThread();

    ComponentsSystrace.beginSection("mount");

    final ComponentTree componentTree = mLithoView.getComponentTree();
    final ComponentsLogger logger = componentTree.getContext().getLogger();
    final int componentTreeId = layoutState.getComponentTreeId();

    LogEvent mountEvent = null;
    if (logger != null) {
        mountEvent = logger.newPerformanceEvent(EVENT_MOUNT);
    }

    // the isDirty check here prevents us from animating for incremental mounts
    final boolean shouldAnimateTransitions = mIsDirty && layoutState.shouldAnimateTransitions()
            && layoutState.hasTransitionContext() && mLastMountedComponentTreeId == componentTreeId;

    prepareTransitionManager(layoutState);
    if (shouldAnimateTransitions) {
        collectPendingAnimations(layoutState);
        createAutoMountTransitions(layoutState);
        mTransitionManager.onNewTransitionContext(layoutState.getTransitionContext());

        recordMountedItemsWithTransitionKeys(mTransitionManager, mIndexToItemMap, true /* isPreMount */);
    }

    if (mIsDirty) {
        suppressInvalidationsOnHosts(true);

        // Prepare the data structure for the new LayoutState and removes mountItems
        // that are not present anymore if isUpdateMountInPlace is enabled.
        prepareMount(layoutState);
    }

    mMountStats.reset();

    final boolean isIncrementalMountEnabled = localVisibleRect != null;

    if (!isIncrementalMountEnabled || !performIncrementalMount(layoutState, localVisibleRect)) {
        final MountItem rootMountItem = mIndexToItemMap.get(ROOT_HOST_ID);

        for (int i = 0, size = layoutState.getMountableOutputCount(); i < size; i++) {
            final LayoutOutput layoutOutput = layoutState.getMountableOutputAt(i);
            final Component component = layoutOutput.getComponent();
            ComponentsSystrace.beginSection(component.getSimpleName());
            final MountItem currentMountItem = getItemAt(i);

            final boolean isMounted = currentMountItem != null;
            final boolean isMountable = !isIncrementalMountEnabled
                    || isMountedHostWithChildContent(currentMountItem)
                    || Rect.intersects(localVisibleRect, layoutOutput.getBounds())
                    || (currentMountItem != null && currentMountItem == rootMountItem);

            if (isMountable && !isMounted) {
                mountLayoutOutput(i, layoutOutput, layoutState);
            } else if (!isMountable && isMounted) {
                unmountItem(mContext, i, mHostsByMarker);
            } else if (isMounted) {
                if (isIncrementalMountEnabled && canMountIncrementally(component)) {
                    mountItemIncrementally(currentMountItem, layoutOutput.getBounds(), localVisibleRect);
                }

                if (mIsDirty) {
                    final boolean useUpdateValueFromLayoutOutput = (componentTreeId >= 0)
                            && (componentTreeId == mLastMountedComponentTreeId);

                    final boolean itemUpdated = updateMountItemIfNeeded(layoutOutput, currentMountItem,
                            useUpdateValueFromLayoutOutput, logger, componentTreeId);

                    if (itemUpdated) {
                        mMountStats.updatedCount++;
                    } else {
                        mMountStats.noOpCount++;
                    }
                }
            }

            ComponentsSystrace.endSection();
        }

        if (isIncrementalMountEnabled) {
            setupPreviousMountableOutputData(layoutState, localVisibleRect);
        }
    }

    mIsDirty = false;
    if (localVisibleRect != null) {
        mPreviousLocalVisibleRect.set(localVisibleRect);
    }

    processVisibilityOutputs(layoutState, localVisibleRect);

    if (shouldAnimateTransitions) {
        recordMountedItemsWithTransitionKeys(mTransitionManager, mIndexToItemMap, false /* isPreMount */);
        mTransitionManager.runTransitions();
    }

    processTestOutputs(layoutState);

    suppressInvalidationsOnHosts(false);

    mLastMountedComponentTreeId = componentTreeId;

    if (logger != null) {
        mountEvent.addParam(PARAM_LOG_TAG, componentTree.getContext().getLogTag());
        mountEvent.addParam(PARAM_MOUNTED_COUNT, String.valueOf(mMountStats.mountedCount));
        mountEvent.addParam(PARAM_UNMOUNTED_COUNT, String.valueOf(mMountStats.unmountedCount));
        mountEvent.addParam(PARAM_UPDATED_COUNT, String.valueOf(mMountStats.updatedCount));
        mountEvent.addParam(PARAM_NO_OP_COUNT, String.valueOf(mMountStats.noOpCount));
        mountEvent.addParam(PARAM_IS_DIRTY, String.valueOf(mIsDirty));
        logger.log(mountEvent);
    }

    ComponentsSystrace.endSection();
}

From source file:com.marlonjones.voidlauncher.CellLayout.java

private boolean rearrangementExists(int cellX, int cellY, int spanX, int spanY, int[] direction,
        View ignoreView, ItemConfiguration solution) {
    // Return early if get invalid cell positions
    if (cellX < 0 || cellY < 0)
        return false;

    mIntersectingViews.clear();/*w  w w. j ava  2s  .c o m*/
    mOccupiedRect.set(cellX, cellY, cellX + spanX, cellY + spanY);

    // Mark the desired location of the view currently being dragged.
    if (ignoreView != null) {
        CellAndSpan c = solution.map.get(ignoreView);
        if (c != null) {
            c.cellX = cellX;
            c.cellY = cellY;
        }
    }
    Rect r0 = new Rect(cellX, cellY, cellX + spanX, cellY + spanY);
    Rect r1 = new Rect();
    for (View child : solution.map.keySet()) {
        if (child == ignoreView)
            continue;
        CellAndSpan c = solution.map.get(child);
        LayoutParams lp = (LayoutParams) child.getLayoutParams();
        r1.set(c.cellX, c.cellY, c.cellX + c.spanX, c.cellY + c.spanY);
        if (Rect.intersects(r0, r1)) {
            if (!lp.canReorder) {
                return false;
            }
            mIntersectingViews.add(child);
        }
    }

    solution.intersectingViews = new ArrayList<View>(mIntersectingViews);

    // First we try to find a solution which respects the push mechanic. That is,
    // we try to find a solution such that no displaced item travels through another item
    // without also displacing that item.
    if (attemptPushInDirection(mIntersectingViews, mOccupiedRect, direction, ignoreView, solution)) {
        return true;
    }

    // Next we try moving the views as a block, but without requiring the push mechanic.
    if (addViewsToTempLocation(mIntersectingViews, mOccupiedRect, direction, ignoreView, solution)) {
        return true;
    }

    // Ok, they couldn't move as a block, let's move them individually
    for (View v : mIntersectingViews) {
        if (!addViewToTempLocation(v, mOccupiedRect, direction, solution)) {
            return false;
        }
    }
    return true;
}

From source file:com.android.launcher3.CellLayout.java

private boolean rearrangementExists(int cellX, int cellY, int spanX, int spanY, int[] direction,
        View ignoreView, ItemConfiguration solution) {
    // Return early if get invalid cell positions
    if (cellX < 0 || cellY < 0)
        return false;

    mIntersectingViews.clear();/*  w ww .  j  a  va  2s  .c  o  m*/
    mOccupiedRect.set(cellX, cellY, cellX + spanX, cellY + spanY);

    // Mark the desired location of the view currently being dragged.
    if (ignoreView != null) {
        CellAndSpan c = solution.map.get(ignoreView);
        if (c != null) {
            c.x = cellX;
            c.y = cellY;
        }
    }
    Rect r0 = new Rect(cellX, cellY, cellX + spanX, cellY + spanY);
    Rect r1 = new Rect();
    for (View child : solution.map.keySet()) {
        if (child == ignoreView)
            continue;
        CellAndSpan c = solution.map.get(child);
        LayoutParams lp = (LayoutParams) child.getLayoutParams();
        r1.set(c.x, c.y, c.x + c.spanX, c.y + c.spanY);
        if (Rect.intersects(r0, r1)) {
            if (!lp.canReorder) {
                return false;
            }
            mIntersectingViews.add(child);
        }
    }

    solution.intersectingViews = new ArrayList<View>(mIntersectingViews);

    // First we try to find a solution which respects the push mechanic. That is,
    // we try to find a solution such that no displaced item travels through another item
    // without also displacing that item.
    if (attemptPushInDirection(mIntersectingViews, mOccupiedRect, direction, ignoreView, solution)) {
        return true;
    }

    // Next we try moving the views as a block, but without requiring the push mechanic.
    if (addViewsToTempLocation(mIntersectingViews, mOccupiedRect, direction, ignoreView, solution)) {
        return true;
    }

    // Ok, they couldn't move as a block, let's move them individually
    for (View v : mIntersectingViews) {
        if (!addViewToTempLocation(v, mOccupiedRect, direction, solution)) {
            return false;
        }
    }
    return true;
}

From source file:com.android.launcher3.CellLayout.java

private void getViewsIntersectingRegion(int cellX, int cellY, int spanX, int spanY, View dragView,
        Rect boundingRect, ArrayList<View> intersectingViews) {
    if (boundingRect != null) {
        boundingRect.set(cellX, cellY, cellX + spanX, cellY + spanY);
    }/*from www  .j a v  a2  s. c  o  m*/
    intersectingViews.clear();
    Rect r0 = new Rect(cellX, cellY, cellX + spanX, cellY + spanY);
    Rect r1 = new Rect();
    final int count = mShortcutsAndWidgets.getChildCount();
    for (int i = 0; i < count; i++) {
        View child = mShortcutsAndWidgets.getChildAt(i);
        if (child == dragView)
            continue;
        LayoutParams lp = (LayoutParams) child.getLayoutParams();
        r1.set(lp.cellX, lp.cellY, lp.cellX + lp.cellHSpan, lp.cellY + lp.cellVSpan);
        if (Rect.intersects(r0, r1)) {
            mIntersectingViews.add(child);
            if (boundingRect != null) {
                boundingRect.union(r1);
            }
        }
    }
}