Example usage for android.graphics Rect union

List of usage examples for android.graphics Rect union

Introduction

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

Prototype

public void union(int left, int top, int right, int bottom) 

Source Link

Document

Update this Rect to enclose itself and the specified rectangle.

Usage

From source file:com.marshalchen.common.uimodule.modifysys.PagerTabStrip.java

@Override
void updateTextPositions(int position, float positionOffset, boolean force) {
    final Rect r = mTempRect;
    int bottom = getHeight();
    int left = mCurrText.getLeft() - mTabPadding;
    int right = mCurrText.getRight() + mTabPadding;
    int top = bottom - mIndicatorHeight;

    r.set(left, top, right, bottom);//from  ww  w. j  a  v a  2  s  .  co  m

    super.updateTextPositions(position, positionOffset, force);
    mTabAlpha = (int) (Math.abs(positionOffset - 0.5f) * 2 * 0xFF);

    left = mCurrText.getLeft() - mTabPadding;
    right = mCurrText.getRight() + mTabPadding;
    r.union(left, top, right, bottom);

    invalidate(r);
}

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

private boolean addViewsToTempLocation(ArrayList<View> views, Rect rectOccupiedByPotentialDrop, int[] direction,
        View dragView, ItemConfiguration currentState) {
    if (views.size() == 0)
        return true;

    boolean success = false;
    Rect boundingRect = null;
    // We construct a rect which represents the entire group of views passed in
    for (View v : views) {
        CellAndSpan c = currentState.map.get(v);
        if (boundingRect == null) {
            boundingRect = new Rect(c.x, c.y, c.x + c.spanX, c.y + c.spanY);
        } else {/*from   w  w w  .j  a  v a 2  s. co m*/
            boundingRect.union(c.x, c.y, c.x + c.spanX, c.y + c.spanY);
        }
    }

    // Mark the occupied state as false for the group of views we want to move.
    for (View v : views) {
        CellAndSpan c = currentState.map.get(v);
        markCellsForView(c.x, c.y, c.spanX, c.spanY, mTmpOccupied, false);
    }

    boolean[][] blockOccupied = new boolean[boundingRect.width()][boundingRect.height()];
    int top = boundingRect.top;
    int left = boundingRect.left;
    // We mark more precisely which parts of the bounding rect are truly occupied, allowing
    // for interlocking.
    for (View v : views) {
        CellAndSpan c = currentState.map.get(v);
        markCellsForView(c.x - left, c.y - top, c.spanX, c.spanY, blockOccupied, true);
    }

    markCellsForRect(rectOccupiedByPotentialDrop, mTmpOccupied, true);

    findNearestArea(boundingRect.left, boundingRect.top, boundingRect.width(), boundingRect.height(), direction,
            mTmpOccupied, blockOccupied, mTempLocation);

    // If we successfuly found a location by pushing the block of views, we commit it
    if (mTempLocation[0] >= 0 && mTempLocation[1] >= 0) {
        int deltaX = mTempLocation[0] - boundingRect.left;
        int deltaY = mTempLocation[1] - boundingRect.top;
        for (View v : views) {
            CellAndSpan c = currentState.map.get(v);
            c.x += deltaX;
            c.y += deltaY;
        }
        success = true;
    }

    // In either case, we set the occupied array as marked for the location of the views
    for (View v : views) {
        CellAndSpan c = currentState.map.get(v);
        markCellsForView(c.x, c.y, c.spanX, c.spanY, mTmpOccupied, true);
    }
    return success;
}