Example usage for android.graphics Rect isEmpty

List of usage examples for android.graphics Rect isEmpty

Introduction

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

Prototype

public final boolean isEmpty() 

Source Link

Document

Returns true if the rectangle is empty (left >= right or top >= bottom)

Usage

From source file:com.mylikes.likes.etchasketch.Slate.java

@Override
public void invalidate(Rect r) {
    if (r.isEmpty()) {
        Log.w(TAG, "invalidating empty rect!");
    }/*from   ww  w  .ja  v a 2  s  .  co m*/
    super.invalidate(r);
}

From source file:org.androfarsh.widget.DragGridLayout.java

private boolean requestHoverRect(Rect rect) {
    rect.setEmpty();/*from   w ww.  j  a  v a  2 s .  c o  m*/
    for (final Cell cell : mHoveredCells) {
        if (!rect.isEmpty()) {
            rect.union(cell.rect);
        } else {
            rect.set(cell.rect);
        }
    }
    return !mHoveredCells.isEmpty() && !rect.isEmpty();
}

From source file:android.support.v7.widget.SwitchCompat.java

@Override
public void draw(Canvas c) {
    final Rect padding = mTempRect;
    final int switchLeft = mSwitchLeft;
    final int switchTop = mSwitchTop;
    final int switchRight = mSwitchRight;
    final int switchBottom = mSwitchBottom;

    int thumbInitialLeft = switchLeft + getThumbOffset();

    final Rect thumbInsets;
    if (mThumbDrawable != null) {
        thumbInsets = DrawableUtils.getOpticalBounds(mThumbDrawable);
    } else {/* ww  w  . j  ava2 s . c o m*/
        thumbInsets = DrawableUtils.INSETS_NONE;
    }

    // Layout the track.
    if (mTrackDrawable != null) {
        mTrackDrawable.getPadding(padding);

        // Adjust thumb position for track padding.
        thumbInitialLeft += padding.left;

        // If necessary, offset by the optical insets of the thumb asset.
        int trackLeft = switchLeft;
        int trackTop = switchTop;
        int trackRight = switchRight;
        int trackBottom = switchBottom;
        if (thumbInsets != null && !thumbInsets.isEmpty()) {
            if (thumbInsets.left > padding.left) {
                trackLeft += thumbInsets.left - padding.left;
            }
            if (thumbInsets.top > padding.top) {
                trackTop += thumbInsets.top - padding.top;
            }
            if (thumbInsets.right > padding.right) {
                trackRight -= thumbInsets.right - padding.right;
            }
            if (thumbInsets.bottom > padding.bottom) {
                trackBottom -= thumbInsets.bottom - padding.bottom;
            }
        }
        mTrackDrawable.setBounds(trackLeft, trackTop, trackRight, trackBottom);
    }

    // Layout the thumb.
    if (mThumbDrawable != null) {
        mThumbDrawable.getPadding(padding);

        final int thumbLeft = thumbInitialLeft - padding.left;
        final int thumbRight = thumbInitialLeft + mThumbWidth + padding.right;
        mThumbDrawable.setBounds(thumbLeft, switchTop, thumbRight, switchBottom);

        final Drawable background = getBackground();
        if (background != null) {
            DrawableCompat.setHotspotBounds(background, thumbLeft, switchTop, thumbRight, switchBottom);
        }
    }

    // Draw the background.
    super.draw(c);
}

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

private void setupPreviousMountableOutputData(LayoutState layoutState, Rect localVisibleRect) {
    if (localVisibleRect.isEmpty()) {
        return;//w ww.j  av a2  s . c om
    }

    final ArrayList<LayoutOutput> layoutOutputTops = layoutState.getMountableOutputTops();
    final ArrayList<LayoutOutput> layoutOutputBottoms = layoutState.getMountableOutputBottoms();
    final int mountableOutputCount = layoutState.getMountableOutputCount();

    mPreviousTopsIndex = layoutState.getMountableOutputCount();
    for (int i = 0; i < mountableOutputCount; i++) {
        if (localVisibleRect.bottom <= layoutOutputTops.get(i).getBounds().top) {
            mPreviousTopsIndex = i;
            break;
        }
    }

    mPreviousBottomsIndex = layoutState.getMountableOutputCount();
    for (int i = 0; i < mountableOutputCount; i++) {
        if (localVisibleRect.top < layoutOutputBottoms.get(i).getBounds().bottom) {
            mPreviousBottomsIndex = i;
            break;
        }
    }
}

From source file:com.androzic.MapFragment.java

private void updateMapViewArea() {
    final ViewTreeObserver vto = map.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @SuppressLint("NewApi")
        @SuppressWarnings("deprecation")
        public void onGlobalLayout() {
            View root = getView();
            Rect area = new Rect();
            map.getLocalVisibleRect(area);
            View v = root.findViewById(R.id.topbar);
            if (v != null)
                area.top = v.getBottom();
            v = root.findViewById(R.id.bottombar);
            if (v != null)
                area.bottom = v.getTop();
            v = root.findViewById(R.id.rightbar);
            if (v != null)
                area.right = v.getLeft();
            if (mapButtons.isShown()) {
                // Landscape mode
                if (v != null)
                    area.bottom = mapButtons.getTop();
                else
                    area.right = mapButtons.getLeft();
            }/*from www . j  a v  a2 s.  c  o m*/
            if (!area.isEmpty())
                map.updateViewArea(area);
            ViewTreeObserver ob;
            if (vto.isAlive())
                ob = vto;
            else
                ob = map.getViewTreeObserver();

            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                ob.removeGlobalOnLayoutListener(this);
            } else {
                ob.removeOnGlobalLayoutListener(this);
            }
        }
    });
}

From source file:com.androzic.MapActivity.java

private void updateMapViewArea() {
    final ViewTreeObserver vto = map.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        public void onGlobalLayout() {
            Rect area = new Rect();
            map.getLocalVisibleRect(area);
            View v = findViewById(R.id.topbar);
            if (v != null)
                area.top = v.getBottom();
            v = findViewById(R.id.bottombar);
            if (v != null)
                area.bottom = v.getTop();
            v = findViewById(R.id.rightbar);
            if (v != null)
                area.right = v.getLeft();
            if (!area.isEmpty())
                map.updateViewArea(area);
            if (vto.isAlive()) {
                vto.removeGlobalOnLayoutListener(this);
            } else {
                final ViewTreeObserver vto1 = map.getViewTreeObserver();
                vto1.removeGlobalOnLayoutListener(this);
            }/*from  w ww. jav a 2 s .  c o m*/
        }
    });
}

From source file:com.androzic.vnspeech.MapFragment.java

private void updateMapViewArea() {
    final ViewTreeObserver vto = map.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @SuppressLint("NewApi")
        @SuppressWarnings("deprecation")
        public void onGlobalLayout() {
            View root = getView();
            Rect area = new Rect();
            map.getLocalVisibleRect(area);
            View v = root.findViewById(R.id.topbar);
            if (v != null)
                area.top = v.getBottom();
            v = root.findViewById(R.id.bottombar);
            if (v != null)
                area.bottom = v.getTop();
            if (mapLicense.isShown()) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && mapLicense.getRotation() != 0f)
                    area.left = mapLicense.getHeight(); // rotated view does not correctly report it's position
                else
                    area.bottom = mapLicense.getTop();
            }//from  ww w.jav a2s . c o  m
            v = root.findViewById(R.id.rightbar);
            if (v != null)
                area.right = v.getLeft();
            if (mapButtons.isShown()) {
                // Landscape mode
                if (v != null)
                    area.bottom = mapButtons.getTop();
                else
                    area.right = mapButtons.getLeft();
            }
            if (!area.isEmpty())
                map.updateViewArea(area);
            ViewTreeObserver ob;
            if (vto.isAlive())
                ob = vto;
            else
                ob = map.getViewTreeObserver();

            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                ob.removeGlobalOnLayoutListener(this);
            } else {
                ob.removeOnGlobalLayoutListener(this);
            }
        }
    });
}

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./*from w  ww .j av  a 2 s  . c om*/
 *
 * @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);
                }
            }
        }
    }
}

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

private void offsetChildByInset(final View child, final Rect inset, final int layoutDirection) {
    if (!ViewCompat.isLaidOut(child)) {
        // The view has not been laid out yet,
        // so we can't obtain its bounds.
        return;/*from  w  w  w.j ava  2s.com*/
    }

    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    final int absDodgeInsetEdges = GravityCompat.getAbsoluteGravity(lp.dodgeInsetEdges, layoutDirection);

    final Behavior behavior = lp.getBehavior();
    final Rect rect = mTempRect3;
    if (behavior != null && behavior.getInsetDodgeRect(this, child, rect)) {
        // Make sure that it intersects the views bounds
        if (!rect.intersect(child.getLeft(), child.getTop(), child.getRight(), child.getBottom())) {
            throw new IllegalArgumentException("Rect should intersect with child's bounds.");
        }
    } else {
        rect.set(child.getLeft(), child.getTop(), child.getRight(), child.getBottom());
    }

    if (rect.isEmpty()) {
        // Rect is empty so there is nothing to dodge against, skip...
        return;
    }

    boolean offsetY = false;
    if ((absDodgeInsetEdges & Gravity.TOP) == Gravity.TOP) {
        int distance = rect.top - lp.topMargin - lp.mInsetOffsetY;
        if (distance < inset.top) {
            setInsetOffsetY(child, inset.top - distance);
            offsetY = true;
        }
    }
    if ((absDodgeInsetEdges & Gravity.BOTTOM) == Gravity.BOTTOM) {
        int distance = getHeight() - rect.bottom - lp.bottomMargin + lp.mInsetOffsetY;
        if (distance < inset.bottom) {
            setInsetOffsetY(child, distance - inset.bottom);
            offsetY = true;
        }
    }
    if (!offsetY) {
        SysoutUtil.sysout("CoordinatorLayout", "offsetChildByInset");
        setInsetOffsetY(child, 0);
    }

    boolean offsetX = false;
    if ((absDodgeInsetEdges & Gravity.LEFT) == Gravity.LEFT) {
        int distance = rect.left - lp.leftMargin - lp.mInsetOffsetX;
        if (distance < inset.left) {
            setInsetOffsetX(child, inset.left - distance);
            offsetX = true;
        }
    }
    if ((absDodgeInsetEdges & Gravity.RIGHT) == Gravity.RIGHT) {
        int distance = getWidth() - rect.right - lp.rightMargin + lp.mInsetOffsetX;
        if (distance < inset.right) {
            setInsetOffsetX(child, distance - inset.right);
            offsetX = true;
        }
    }
    if (!offsetX) {
        setInsetOffsetX(child, 0);
    }
}

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

private void offsetChildByInset(final View child, final Rect inset, final int layoutDirection) {
    if (!ViewCompat.isLaidOut(child)) {
        // The view has not been laid out yet, so we can't obtain its bounds.
        return;/*from   w  w  w  . j a  va 2  s.c  o m*/
    }

    if (child.getWidth() <= 0 || child.getHeight() <= 0) {
        // Bounds are empty so there is nothing to dodge against, skip...
        return;
    }

    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    final Behavior behavior = lp.getBehavior();
    final Rect dodgeRect = acquireTempRect();
    final Rect bounds = acquireTempRect();
    bounds.set(child.getLeft(), child.getTop(), child.getRight(), child.getBottom());

    if (behavior != null && behavior.getInsetDodgeRect(this, child, dodgeRect)) {
        // Make sure that the rect is within the view's bounds
        if (!bounds.contains(dodgeRect)) {
            throw new IllegalArgumentException("Rect should be within the child's bounds." + " Rect:"
                    + dodgeRect.toShortString() + " | Bounds:" + bounds.toShortString());
        }
    } else {
        dodgeRect.set(bounds);
    }

    // We can release the bounds rect now
    releaseTempRect(bounds);

    if (dodgeRect.isEmpty()) {
        // Rect is empty so there is nothing to dodge against, skip...
        releaseTempRect(dodgeRect);
        return;
    }

    final int absDodgeInsetEdges = GravityCompat.getAbsoluteGravity(lp.dodgeInsetEdges, layoutDirection);

    boolean offsetY = false;
    if ((absDodgeInsetEdges & Gravity.TOP) == Gravity.TOP) {
        int distance = dodgeRect.top - lp.topMargin - lp.mInsetOffsetY;
        if (distance < inset.top) {
            setInsetOffsetY(child, inset.top - distance);
            offsetY = true;
        }
    }
    if ((absDodgeInsetEdges & Gravity.BOTTOM) == Gravity.BOTTOM) {
        int distance = getHeight() - dodgeRect.bottom - lp.bottomMargin + lp.mInsetOffsetY;
        if (distance < inset.bottom) {
            setInsetOffsetY(child, distance - inset.bottom);
            offsetY = true;
        }
    }
    if (!offsetY) {
        setInsetOffsetY(child, 0);
    }

    boolean offsetX = false;
    if ((absDodgeInsetEdges & Gravity.LEFT) == Gravity.LEFT) {
        int distance = dodgeRect.left - lp.leftMargin - lp.mInsetOffsetX;
        if (distance < inset.left) {
            setInsetOffsetX(child, inset.left - distance);
            offsetX = true;
        }
    }
    if ((absDodgeInsetEdges & Gravity.RIGHT) == Gravity.RIGHT) {
        int distance = getWidth() - dodgeRect.right - lp.rightMargin + lp.mInsetOffsetX;
        if (distance < inset.right) {
            setInsetOffsetX(child, distance - inset.right);
            offsetX = true;
        }
    }
    if (!offsetX) {
        setInsetOffsetX(child, 0);
    }

    releaseTempRect(dodgeRect);
}