Java Code Examples for android.graphics.Region#translate()

The following examples show how to use android.graphics.Region#translate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DisplayCutout.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Insets the reference frame of the cutout in the given directions.
 *
 * @return a copy of this instance which has been inset
 * @hide
 */
public DisplayCutout inset(int insetLeft, int insetTop, int insetRight, int insetBottom) {
    if (mBounds.isEmpty()
            || insetLeft == 0 && insetTop == 0 && insetRight == 0 && insetBottom == 0) {
        return this;
    }

    Rect safeInsets = new Rect(mSafeInsets);
    Region bounds = Region.obtain(mBounds);

    // Note: it's not really well defined what happens when the inset is negative, because we
    // don't know if the safe inset needs to expand in general.
    if (insetTop > 0 || safeInsets.top > 0) {
        safeInsets.top = atLeastZero(safeInsets.top - insetTop);
    }
    if (insetBottom > 0 || safeInsets.bottom > 0) {
        safeInsets.bottom = atLeastZero(safeInsets.bottom - insetBottom);
    }
    if (insetLeft > 0 || safeInsets.left > 0) {
        safeInsets.left = atLeastZero(safeInsets.left - insetLeft);
    }
    if (insetRight > 0 || safeInsets.right > 0) {
        safeInsets.right = atLeastZero(safeInsets.right - insetRight);
    }

    bounds.translate(-insetLeft, -insetTop);
    return new DisplayCutout(safeInsets, bounds, false /* copyArguments */);
}
 
Example 2
Source File: GridDrawable.java    From ProjectX with Apache License 2.0 5 votes vote down vote up
@Override
public Region getTransparentRegion() {
    if (mRowCount <= 0 || mColumnCount <= 0)
        return null;
    final Drawable drawable = getWrappedDrawable();
    if (drawable == null)
        return null;
    final Region ir = drawable.getTransparentRegion();
    if (ir == null)
        return null;
    final Region region = new Region();
    final Rect itemBound = drawable.getBounds();
    final int itemWidth = itemBound.width();
    final int itemHeight = itemBound.height();
    int dx;
    int dy;
    for (int i = 0; i < mRowCount; i++) {
        for (int j = 0; j < mColumnCount; j++) {
            dx = Math.round(j * itemWidth + (j > 0 ? (mHorizontalSpacing * j) : 0));
            dy = Math.round(i * itemHeight + (i > 0 ? (mVerticalSpacing * i) : 0));
            ir.translate(dx, dy);
            region.op(ir, Region.Op.UNION);
            ir.translate(-dx, -dy);
        }
    }
    return region;
}
 
Example 3
Source File: ForegroundDrawableRelativeLayout.java    From cathode with Apache License 2.0 5 votes vote down vote up
public void applyDrawableToTransparentRegion(Drawable dr, Region region) {
  final Region r = dr.getTransparentRegion();
  final Rect db = dr.getBounds();
  if (r != null) {
    final int[] location = new int[2];
    getLocationInWindow(location);
    r.translate(location[0], location[1]);
    region.op(r, Region.Op.INTERSECT);
  } else {
    region.op(db, Region.Op.DIFFERENCE);
  }
}
 
Example 4
Source File: SafeTranslatedCanvas.java    From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public boolean clipRegion(final Region region, final Op op) {
    region.translate(xOffset, yOffset);
    return getWrappedCanvas().clipRegion(region, op);
}
 
Example 5
Source File: SafeTranslatedCanvas.java    From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public boolean clipRegion(final Region region) {
    region.translate(xOffset, yOffset);
    return getWrappedCanvas().clipRegion(region);
}