Example usage for android.graphics Rect equals

List of usage examples for android.graphics Rect equals

Introduction

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

Prototype

@Override
    public boolean equals(Object o) 

Source Link

Usage

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

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    int width = getMeasuredWidth();
    int height = getMeasuredHeight();

    layoutSubView(mSearch, mActionGap, 0);
    layoutSubView(mShare, width - mActionGap * 2 - mShare.getMeasuredWidth() - mCopy.getMeasuredWidth(), 0);
    layoutSubView(mCopy, width - mActionGap - mCopy.getMeasuredWidth(), 0);

    Rect oldBounds = mBorder.getBounds();
    Rect newBounds = new Rect(0, mSearch.getMeasuredHeight() / 2, width, height);

    if (!oldBounds.equals(newBounds)) {
        ObjectAnimator.ofObject(mBorder, "bounds", new RectEvaluator(), oldBounds, newBounds).setDuration(200)
                .start();//  w  ww . j  av  a  2  s  .co  m
    }
}

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

/**
 * Check if this node has been found to have bounds matching an ancestor, which means it gets
 * special treatment during traversal./*from   w ww. j  a  v  a2s .  c o  m*/
 *
 * @return {@code true} if this node was found to have the same bounds as an ancestor.
 */
public boolean getHasSameBoundsAsAncestor() {
    // Only need to check parent
    if (mBoundsDuplicateAncestor == null) {
        SwitchAccessNodeCompat parent = getParent();
        if (parent == null) {
            mBoundsDuplicateAncestor = false;
        } else {
            Rect parentBounds = new Rect();
            Rect myBounds = new Rect();
            parent.getBoundsInScreen(parentBounds);
            getBoundsInScreen(myBounds);
            mBoundsDuplicateAncestor = myBounds.equals(parentBounds);
            parent.recycle();
        }
    }
    return mBoundsDuplicateAncestor;
}

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

private void addDescendantsWithBoundsToList(List<SwitchAccessNodeCompat> listOfNodes, Rect bounds) {
    Rect childBounds = new Rect();
    for (int i = 0; i < getChildCount(); i++) {
        SwitchAccessNodeCompat child = getChild(i);
        if (child == null) {
            continue;
        }//from w  ww .  jav  a 2 s  .com
        child.getBoundsInScreen(childBounds);
        if (bounds.equals(childBounds) && !listOfNodes.contains(child)) {
            child.mBoundsDuplicateAncestor = true;
            listOfNodes.add(child);
            child.addDescendantsWithBoundsToList(listOfNodes, bounds);
        } else {
            // Children can't be bigger than parents, so once the bounds are different they
            // must be smaller, and further descendants won't duplicate the bounds
            child.recycle();
        }
    }
}

From source file:android.support.transition.ChangeClipBounds.java

@Override
public Animator createAnimator(@NonNull final ViewGroup sceneRoot, TransitionValues startValues,
        TransitionValues endValues) {//  w  ww .j a v  a 2  s .c  o m
    if (startValues == null || endValues == null || !startValues.values.containsKey(PROPNAME_CLIP)
            || !endValues.values.containsKey(PROPNAME_CLIP)) {
        return null;
    }
    Rect start = (Rect) startValues.values.get(PROPNAME_CLIP);
    Rect end = (Rect) endValues.values.get(PROPNAME_CLIP);
    final boolean endIsNull = end == null;
    if (start == null && end == null) {
        return null; // No animation required since there is no clip.
    }

    if (start == null) {
        start = (Rect) startValues.values.get(PROPNAME_BOUNDS);
    } else if (end == null) {
        end = (Rect) endValues.values.get(PROPNAME_BOUNDS);
    }
    if (start.equals(end)) {
        return null;
    }

    ViewCompat.setClipBounds(endValues.view, start);
    RectEvaluator evaluator = new RectEvaluator(new Rect());
    ObjectAnimator animator = ObjectAnimator.ofObject(endValues.view, ViewUtils.CLIP_BOUNDS, evaluator, start,
            end);
    if (endIsNull) {
        final View endView = endValues.view;
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                ViewCompat.setClipBounds(endView, null);
            }
        });
    }
    return animator;
}

From source file:com.android.utils.AccessibilityNodeInfoUtils.java

/**
 * Determines whether the specified node has bounds identical to the bounds of its window.
 *///  w ww  .  j  av a 2  s  . c  o m
private static boolean areBoundsIdenticalToWindow(AccessibilityNodeInfoCompat node) {
    if (node == null) {
        return false;
    }

    AccessibilityWindowInfoCompat window = node.getWindow();
    if (window == null) {
        return false;
    }

    Rect windowBounds = new Rect();
    window.getBoundsInScreen(windowBounds);

    Rect nodeBounds = new Rect();
    node.getBoundsInScreen(nodeBounds);

    return windowBounds.equals(nodeBounds);
}

From source file:ac.robinson.paperchains.PaperChainsActivity.java

private void onImageClick() {
    resetAudioPlayer();//  ww  w.j  a v  a  2  s. com
    supportInvalidateOptionsMenu();

    Point touchPoint = mImageView.screenPointToImagePoint(mZoomListener.getLastTouchPoint());
    boolean rectTouched = false;
    for (AudioAreaHolder holder : mAudioAreas) {
        Rect rect = holder.imageRect;
        if (rect.contains(touchPoint.x, touchPoint.y)) {
            rectTouched = true;
            if (mCurrentMode == MODE_ADD) {
                if (rect.equals(mCurrentAudioRect)) {
                    mRecordButton.performClick();
                } else {
                    resetRecordingInterface();
                }
                break;
            } else if (mCurrentMode == MODE_LISTEN) {
                // TODO: handle overlapping rectangles (pop up several buttons as options?)
                initialisePlaybackButton(mZoomListener.getLastTouchPoint());
                mImageView.setDragCallback(new PaperChainsView.DragCallback() {
                    @Override
                    public void dragStarted() {
                        resetAudioPlayer(); // we don't update the button position on drag; for now, just stop play
                    }
                });
                new SoundCloudUrlFetcherTask(PaperChainsActivity.this, sSoundCloudPlayerApiWrapper)
                        .execute(holder.soundCloudId);
                break;
            }
        }
    }

    // remove a rect and re-enable scribbling when touching outside in add mode
    if (!rectTouched) {
        switch (mCurrentMode) {
        case MODE_ADD:
            resetRecordingInterface();
            break;
        case MODE_LISTEN:
            resetAudioPlayer();
            break;
        }
    }
}

From source file:android.support.transition.ChangeBounds.java

@Override
@Nullable//from   w w w  .j  a  v a 2s .  c om
public Animator createAnimator(@NonNull final ViewGroup sceneRoot, @Nullable TransitionValues startValues,
        @Nullable TransitionValues endValues) {
    if (startValues == null || endValues == null) {
        return null;
    }
    Map<String, Object> startParentVals = startValues.values;
    Map<String, Object> endParentVals = endValues.values;
    ViewGroup startParent = (ViewGroup) startParentVals.get(PROPNAME_PARENT);
    ViewGroup endParent = (ViewGroup) endParentVals.get(PROPNAME_PARENT);
    if (startParent == null || endParent == null) {
        return null;
    }
    final View view = endValues.view;
    if (parentMatches(startParent, endParent)) {
        Rect startBounds = (Rect) startValues.values.get(PROPNAME_BOUNDS);
        Rect endBounds = (Rect) endValues.values.get(PROPNAME_BOUNDS);
        final int startLeft = startBounds.left;
        final int endLeft = endBounds.left;
        final int startTop = startBounds.top;
        final int endTop = endBounds.top;
        final int startRight = startBounds.right;
        final int endRight = endBounds.right;
        final int startBottom = startBounds.bottom;
        final int endBottom = endBounds.bottom;
        final int startWidth = startRight - startLeft;
        final int startHeight = startBottom - startTop;
        final int endWidth = endRight - endLeft;
        final int endHeight = endBottom - endTop;
        Rect startClip = (Rect) startValues.values.get(PROPNAME_CLIP);
        Rect endClip = (Rect) endValues.values.get(PROPNAME_CLIP);
        int numChanges = 0;
        if ((startWidth != 0 && startHeight != 0) || (endWidth != 0 && endHeight != 0)) {
            if (startLeft != endLeft || startTop != endTop)
                ++numChanges;
            if (startRight != endRight || startBottom != endBottom)
                ++numChanges;
        }
        if ((startClip != null && !startClip.equals(endClip)) || (startClip == null && endClip != null)) {
            ++numChanges;
        }
        if (numChanges > 0) {
            Animator anim;
            if (!mResizeClip) {
                ViewUtils.setLeftTopRightBottom(view, startLeft, startTop, startRight, startBottom);
                if (numChanges == 2) {
                    if (startWidth == endWidth && startHeight == endHeight) {
                        Path topLeftPath = getPathMotion().getPath(startLeft, startTop, endLeft, endTop);
                        anim = ObjectAnimatorUtils.ofPointF(view, POSITION_PROPERTY, topLeftPath);
                    } else {
                        final ViewBounds viewBounds = new ViewBounds(view);
                        Path topLeftPath = getPathMotion().getPath(startLeft, startTop, endLeft, endTop);
                        ObjectAnimator topLeftAnimator = ObjectAnimatorUtils.ofPointF(viewBounds,
                                TOP_LEFT_PROPERTY, topLeftPath);

                        Path bottomRightPath = getPathMotion().getPath(startRight, startBottom, endRight,
                                endBottom);
                        ObjectAnimator bottomRightAnimator = ObjectAnimatorUtils.ofPointF(viewBounds,
                                BOTTOM_RIGHT_PROPERTY, bottomRightPath);
                        AnimatorSet set = new AnimatorSet();
                        set.playTogether(topLeftAnimator, bottomRightAnimator);
                        anim = set;
                        set.addListener(new AnimatorListenerAdapter() {
                            // We need a strong reference to viewBounds until the
                            // animator ends (The ObjectAnimator holds only a weak reference).
                            @SuppressWarnings("unused")
                            private ViewBounds mViewBounds = viewBounds;
                        });
                    }
                } else if (startLeft != endLeft || startTop != endTop) {
                    Path topLeftPath = getPathMotion().getPath(startLeft, startTop, endLeft, endTop);
                    anim = ObjectAnimatorUtils.ofPointF(view, TOP_LEFT_ONLY_PROPERTY, topLeftPath);
                } else {
                    Path bottomRight = getPathMotion().getPath(startRight, startBottom, endRight, endBottom);
                    anim = ObjectAnimatorUtils.ofPointF(view, BOTTOM_RIGHT_ONLY_PROPERTY, bottomRight);
                }
            } else {
                int maxWidth = Math.max(startWidth, endWidth);
                int maxHeight = Math.max(startHeight, endHeight);

                ViewUtils.setLeftTopRightBottom(view, startLeft, startTop, startLeft + maxWidth,
                        startTop + maxHeight);

                ObjectAnimator positionAnimator = null;
                if (startLeft != endLeft || startTop != endTop) {
                    Path topLeftPath = getPathMotion().getPath(startLeft, startTop, endLeft, endTop);
                    positionAnimator = ObjectAnimatorUtils.ofPointF(view, POSITION_PROPERTY, topLeftPath);
                }
                final Rect finalClip = endClip;
                if (startClip == null) {
                    startClip = new Rect(0, 0, startWidth, startHeight);
                }
                if (endClip == null) {
                    endClip = new Rect(0, 0, endWidth, endHeight);
                }
                ObjectAnimator clipAnimator = null;
                if (!startClip.equals(endClip)) {
                    ViewCompat.setClipBounds(view, startClip);
                    clipAnimator = ObjectAnimator.ofObject(view, "clipBounds", sRectEvaluator, startClip,
                            endClip);
                    clipAnimator.addListener(new AnimatorListenerAdapter() {
                        private boolean mIsCanceled;

                        @Override
                        public void onAnimationCancel(Animator animation) {
                            mIsCanceled = true;
                        }

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            if (!mIsCanceled) {
                                ViewCompat.setClipBounds(view, finalClip);
                                ViewUtils.setLeftTopRightBottom(view, endLeft, endTop, endRight, endBottom);
                            }
                        }
                    });
                }
                anim = TransitionUtils.mergeAnimators(positionAnimator, clipAnimator);
            }
            if (view.getParent() instanceof ViewGroup) {
                final ViewGroup parent = (ViewGroup) view.getParent();
                ViewGroupUtils.suppressLayout(parent, true);
                TransitionListener transitionListener = new TransitionListenerAdapter() {
                    boolean mCanceled = false;

                    @Override
                    public void onTransitionCancel(@NonNull Transition transition) {
                        ViewGroupUtils.suppressLayout(parent, false);
                        mCanceled = true;
                    }

                    @Override
                    public void onTransitionEnd(@NonNull Transition transition) {
                        if (!mCanceled) {
                            ViewGroupUtils.suppressLayout(parent, false);
                        }
                        transition.removeListener(this);
                    }

                    @Override
                    public void onTransitionPause(@NonNull Transition transition) {
                        ViewGroupUtils.suppressLayout(parent, false);
                    }

                    @Override
                    public void onTransitionResume(@NonNull Transition transition) {
                        ViewGroupUtils.suppressLayout(parent, true);
                    }
                };
                addListener(transitionListener);
            }
            return anim;
        }
    } else {
        int startX = (Integer) startValues.values.get(PROPNAME_WINDOW_X);
        int startY = (Integer) startValues.values.get(PROPNAME_WINDOW_Y);
        int endX = (Integer) endValues.values.get(PROPNAME_WINDOW_X);
        int endY = (Integer) endValues.values.get(PROPNAME_WINDOW_Y);
        // TODO: also handle size changes: check bounds and animate size changes
        if (startX != endX || startY != endY) {
            sceneRoot.getLocationInWindow(mTempLocation);
            Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(bitmap);
            view.draw(canvas);
            @SuppressWarnings("deprecation")
            final BitmapDrawable drawable = new BitmapDrawable(bitmap);
            final float transitionAlpha = ViewUtils.getTransitionAlpha(view);
            ViewUtils.setTransitionAlpha(view, 0);
            ViewUtils.getOverlay(sceneRoot).add(drawable);
            Path topLeftPath = getPathMotion().getPath(startX - mTempLocation[0], startY - mTempLocation[1],
                    endX - mTempLocation[0], endY - mTempLocation[1]);
            PropertyValuesHolder origin = PropertyValuesHolderUtils.ofPointF(DRAWABLE_ORIGIN_PROPERTY,
                    topLeftPath);
            ObjectAnimator anim = ObjectAnimator.ofPropertyValuesHolder(drawable, origin);
            anim.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    ViewUtils.getOverlay(sceneRoot).remove(drawable);
                    ViewUtils.setTransitionAlpha(view, transitionAlpha);
                }
            });
            return anim;
        }
    }
    return null;
}

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

/**
 * Returns true if the component is in the focused visible range.
 *///from   w w w  .j  av  a  2s  .c om
private boolean isInFocusedRange(Rect componentBounds, Rect componentVisibleBounds) {
    final View parent = (View) mLithoView.getParent();
    final int halfViewportArea = parent.getWidth() * parent.getHeight() / 2;
    final int totalComponentArea = computeRectArea(componentBounds);
    final int visibleComponentArea = computeRectArea(componentVisibleBounds);

    // The component has entered the focused range either if it is larger than half of the viewport
    // and it occupies at least half of the viewport or if it is smaller than half of the viewport
    // and it is fully visible.
    return (totalComponentArea >= halfViewportArea) ? (visibleComponentArea >= halfViewportArea)
            : componentBounds.equals(componentVisibleBounds);
}

From source file:android.support.designox.widget.CoordinatorLayout.java

/**
 * Dispatch any dependent view changes to the relevant {@link Behavior} instances.
 *
 * Usually run as part of the pre-draw step when at least one child view has a reported
 * dependency on another view. This allows CoordinatorLayout to account for layout
 * changes and animations that occur outside of the normal layout pass.
 *
 * It can also be ran as part of the nested scrolling dispatch to ensure that any offsetting
 * is completed within the correct coordinate window.
 *
 * The offsetting behavior implemented here does not store the computed offset in
 * the LayoutParams; instead it expects that the layout process will always reconstruct
 * the proper positioning.// w ww.  j  av  a  2 s. c  om
 *
 * @param fromNestedScroll true if this is being called from one of the nested scroll methods,
 *                         false if run as part of the pre-draw step.
 */
void dispatchOnDependentViewChanged(final boolean fromNestedScroll) {
    final int layoutDirection = ViewCompat.getLayoutDirection(this);
    final int childCount = mDependencySortedChildren.size();
    for (int i = 0; i < childCount; i++) {
        final View child = mDependencySortedChildren.get(i);
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        // Check child views before for anchor
        for (int j = 0; j < i; j++) {
            final View checkChild = mDependencySortedChildren.get(j);

            if (lp.mAnchorDirectChild == checkChild) {
                offsetChildToAnchor(child, layoutDirection);
            }
        }

        // Did it change? if not continue
        final Rect oldRect = mTempRect1;
        final Rect newRect = mTempRect2;
        getLastChildRect(child, oldRect);
        getChildRect(child, true, newRect);
        if (oldRect.equals(newRect)) {
            continue;
        }
        recordLastChildRect(child, newRect);

        // Update any behavior-dependent views for the change
        for (int j = i + 1; j < childCount; j++) {
            final View checkChild = mDependencySortedChildren.get(j);
            final LayoutParams checkLp = (LayoutParams) checkChild.getLayoutParams();
            final Behavior b = checkLp.getBehavior();

            if (b != null && b.layoutDependsOn(this, checkChild, child)) {
                if (!fromNestedScroll && checkLp.getChangedAfterNestedScroll()) {
                    // If this is not from a nested scroll and we have already been changed
                    // from a nested scroll, skip the dispatch and reset the flag
                    checkLp.resetChangedAfterNestedScroll();
                    continue;
                }

                final boolean handled = b.onDependentViewChanged(this, checkChild, child);

                if (fromNestedScroll) {
                    // If this is from a nested scroll, set the flag so that we may skip
                    // any resulting onPreDraw dispatch (if needed)
                    checkLp.setChangedAfterNestedScroll(handled);
                }
            }
        }
    }
}

From source file:com.huyn.demogroup.bahavior.widget.CoordinatorLayout.java

/**
 * Dispatch any dependent view changes to the relevant {@link Behavior} instances.
 *
 * Usually run as part of the pre-draw step when at least one child view has a reported
 * dependency on another view. This allows CoordinatorLayout to account for layout
 * changes and animations that occur outside of the normal layout pass.
 *
 * It can also be ran as part of the nested scrolling dispatch to ensure that any offsetting
 * is completed within the correct coordinate window.
 *
 * The offsetting behavior implemented here does not store the computed offset in
 * the LayoutParams; instead it expects that the layout process will always reconstruct
 * the proper positioning.//  ww  w.ja  va  2 s  .co m
 *
 * @param type the type of event which has caused this call
 */
final void onChildViewsChanged(@DispatchChangeEvent final int type) {
    final int layoutDirection = ViewCompat.getLayoutDirection(this);
    final int childCount = mDependencySortedChildren.size();
    final Rect inset = mTempRect4;
    inset.setEmpty();
    for (int i = 0; i < childCount; i++) {
        final View child = mDependencySortedChildren.get(i);
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        // Check child views before for anchor
        for (int j = 0; j < i; j++) {
            final View checkChild = mDependencySortedChildren.get(j);

            if (lp.mAnchorDirectChild == checkChild) {
                offsetChildToAnchor(child, layoutDirection);
            }
        }

        // Get the current draw rect of the view
        final Rect drawRect = mTempRect1;
        getChildRect(child, true, drawRect);

        // Accumulate inset sizes
        if (lp.insetEdge != Gravity.NO_GRAVITY && !drawRect.isEmpty()) {
            final int absInsetEdge = GravityCompat.getAbsoluteGravity(lp.insetEdge, layoutDirection);
            switch (absInsetEdge & Gravity.VERTICAL_GRAVITY_MASK) {
            case Gravity.TOP:
                inset.top = Math.max(inset.top, drawRect.bottom);
                break;
            case Gravity.BOTTOM:
                inset.bottom = Math.max(inset.bottom, getHeight() - drawRect.top);
                break;
            }
            switch (absInsetEdge & Gravity.HORIZONTAL_GRAVITY_MASK) {
            case Gravity.LEFT:
                inset.left = Math.max(inset.left, drawRect.right);
                break;
            case Gravity.RIGHT:
                inset.right = Math.max(inset.right, getWidth() - drawRect.left);
                break;
            }
        }

        // Dodge inset edges if necessary
        if (lp.dodgeInsetEdges != Gravity.NO_GRAVITY && child.getVisibility() == View.VISIBLE) {
            offsetChildByInset(child, inset, layoutDirection);
        }

        if (type == EVENT_PRE_DRAW) {
            // Did it change? if not continue
            final Rect lastDrawRect = mTempRect2;
            getLastChildRect(child, lastDrawRect);
            if (lastDrawRect.equals(drawRect)) {
                continue;
            }
            recordLastChildRect(child, drawRect);
        }

        // Update any behavior-dependent views for the change
        for (int j = i + 1; j < childCount; j++) {
            final View checkChild = mDependencySortedChildren.get(j);
            final LayoutParams checkLp = (LayoutParams) checkChild.getLayoutParams();
            final Behavior b = checkLp.getBehavior();

            if (b != null && b.layoutDependsOn(this, checkChild, child)) {
                if (type == EVENT_PRE_DRAW && checkLp.getChangedAfterNestedScroll()) {
                    // If this is from a pre-draw and we have already been changed
                    // from a nested scroll, skip the dispatch and reset the flag
                    checkLp.resetChangedAfterNestedScroll();
                    continue;
                }

                final boolean handled;
                switch (type) {
                case EVENT_VIEW_REMOVED:
                    // EVENT_VIEW_REMOVED means that we need to dispatch
                    // onDependentViewRemoved() instead
                    b.onDependentViewRemoved(this, checkChild, child);
                    handled = true;
                    break;
                default:
                    // Otherwise we dispatch onDependentViewChanged()
                    handled = b.onDependentViewChanged(this, checkChild, child);
                    break;
                }

                if (type == EVENT_NESTED_SCROLL) {
                    // If this is from a nested scroll, set the flag so that we may skip
                    // any resulting onPreDraw dispatch (if needed)
                    checkLp.setChangedAfterNestedScroll(handled);
                }
            }
        }
    }
}