Rect newRect = canvas.getClipBounds(); newRect.inset(-5, -5) //make the rect larger canvas.clipRect (newRect, Region.Op.REPLACE); //happily draw outside the bound now
void init(View delegateView, Rect delegateBounds) { mDelegateView = delegateView; mSlop = ViewConfiguration.get(delegateView.getContext()).getScaledTouchSlop(); mDelegateBounds.set(delegateBounds); mDelegateSlopBounds.set(delegateBounds); mDelegateSlopBounds.inset(-mSlop, -mSlop); }
@Override public void draw(Canvas canvas) { // We don't have access to the OverlayViewGroup instance directly, but we can manipulate // its Canvas via the Drawables' draw(). This allows us to draw outside the View bounds, // so we can position the margin overlays correctly. Rect newRect = canvas.getClipBounds(); // Make the Canvas Rect bigger according to the View margins. newRect.inset(-(mMargins.right + mMargins.left), -(mMargins.top + mMargins.bottom)); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { canvas.clipRect(newRect, Region.Op.REPLACE); } else { canvas.clipOutRect(newRect); } super.draw(canvas); } }
int dx = -Math.max(mlp.leftMargin, mlp.rightMargin); int dy = -Math.max(mlp.topMargin, mlp.bottomMargin); newRect.inset(dx, dy); canvas.clipRect(newRect, Region.Op.REPLACE);
void moveBy(float dx, float dy) { Rect invalRect = new Rect(drawRect); cropRect.offset(dx, dy); // Put the cropping rectangle inside image rectangle cropRect.offset( Math.max(0, imageRect.left - cropRect.left), Math.max(0, imageRect.top - cropRect.top)); cropRect.offset( Math.min(0, imageRect.right - cropRect.right), Math.min(0, imageRect.bottom - cropRect.bottom)); drawRect = computeLayout(); invalRect.union(drawRect); invalRect.inset(-(int) handleRadius, -(int) handleRadius); viewContext.invalidate(invalRect); }
int getOuterCircleRadius(int centerX, int centerY, Rect textBounds, Rect targetBounds) { final int targetCenterX = targetBounds.centerX(); final int targetCenterY = targetBounds.centerY(); final int expandedRadius = (int) (1.1f * TARGET_RADIUS); final Rect expandedBounds = new Rect(targetCenterX, targetCenterY, targetCenterX, targetCenterY); expandedBounds.inset(-expandedRadius, -expandedRadius); final int textRadius = maxDistanceToPoints(centerX, centerY, textBounds); final int targetRadius = maxDistanceToPoints(centerX, centerY, expandedBounds); return Math.max(textRadius, targetRadius) + CIRCLE_PADDING; }
public void explode(final View view) { Rect r = new Rect(); view.getGlobalVisibleRect(r); int[] location = new int[2]; getLocationOnScreen(location); r.offset(-location[0], -location[1]); r.inset(-mExpandInset[0], -mExpandInset[1]); int startDelay = 100; ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f).setDuration(150); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { Random random = new Random(); @Override public void onAnimationUpdate(ValueAnimator animation) { view.setTranslationX((random.nextFloat() - 0.5f) * view.getWidth() * 0.05f); view.setTranslationY((random.nextFloat() - 0.5f) * view.getHeight() * 0.05f); } }); animator.start(); view.animate().setDuration(150).setStartDelay(startDelay).scaleX(0f).scaleY(0f).alpha(0f).start(); explode(Utils.createBitmapFromView(view), r, startDelay, ExplosionAnimator.DEFAULT_DURATION); }
/** * Returns whether the specified points are near the scroll bar bounds. */ private boolean isNearPoint(int x, int y) { mTmpRect.set(mThumbPosition.x, mThumbPosition.y, mThumbPosition.x + mWidth, mThumbPosition.y + mThumbHeight); mTmpRect.inset(mTouchInset, mTouchInset); return mTmpRect.contains(x, y); }
croppedImage = Bitmap.createBitmap(mOutputX, mOutputY, Bitmap.Config.RGB_565); Canvas canvas = new Canvas(croppedImage); Rect srcRect = mCrop.getCropRect(); Rect dstRect = new Rect(0, 0, mOutputX, mOutputY); int dx = (srcRect.width() - dstRect.width()) / 2; int dy = (srcRect.height() - dstRect.height()) / 2; // If the srcRect is too big, use the center part of it. srcRect.inset(Math.max(0, dx), Math.max(0, dy)); // If the dstRect is too big, use the center part of it. dstRect.inset(Math.max(0, -dx), Math.max(0, -dy)); // Draw the cropped bitmap in the center canvas.drawBitmap(mBitmap, srcRect, dstRect, null);
expandedBounds.inset(-FLING_MARGIN, -FLING_MARGIN);
private void moveBy(float dx, float dy) { Rect invalRect = new Rect(mDrawRect); mCropRect.offset(dx, dy); // Put the cropping rectangle inside image rectangle. mCropRect.offset( Math.max(0, mImageRect.left - mCropRect.left), Math.max(0, mImageRect.top - mCropRect.top)); mCropRect.offset( Math.min(0, mImageRect.right - mCropRect.right), Math.min(0, mImageRect.bottom - mCropRect.bottom)); mDrawRect = computeLayout(); invalRect.union(mDrawRect); invalRect.inset(-10, -10); mContext.invalidate(invalRect); }
private void moveBy(float dx, float dy) { Rect invalRect = new Rect(mDrawRect); mCropRect.offset(dx, dy); // Put the cropping rectangle inside image rectangle. mCropRect.offset( Math.max(0, mImageRect.left - mCropRect.left), Math.max(0, mImageRect.top - mCropRect.top)); mCropRect.offset( Math.min(0, mImageRect.right - mCropRect.right), Math.min(0, mImageRect.bottom - mCropRect.bottom)); mDrawRect = computeLayout(); invalRect.union(mDrawRect); invalRect.inset(-10, -10); mContext.invalidate(invalRect); }
bounds.inset(mPadding, mPadding);
/** * Returns whether the specified points are near the scroll bar bounds. */ private boolean isNearPoint(int x, int y) { mTmpRect.set(mThumbPosition.x, mThumbPosition.y, mThumbPosition.x + mWidth, mThumbPosition.y + mThumbHeight); mTmpRect.inset(mTouchInset, mTouchInset); return mTmpRect.contains(x, y); }
/** * Returns whether the specified points are near the scroll bar bounds. */ private boolean isNearThumb(int x, int y) { mTmpRect.set(mThumbOffset.x, mThumbOffset.y, mThumbOffset.x + mThumbWidth, mThumbOffset.y + mThumbHeight); mTmpRect.inset(mTouchInset, mTouchInset); return mTmpRect.contains(x, y); } }
@Override protected void onBoundsChange(Rect bounds) { mIcon.setBounds(bounds); if (mBgDrawable != null) { sTempRect.set(bounds); sTempRect.inset(-mRingOutset, -mRingOutset); mBgDrawable.setBounds(sTempRect); } mIndicatorRectDirty = true; }
private final Rect mBounds = new Rect(); private final Date mDate = new Date(); private void measureText(final Paint p){ final String dummy = DateFormat.getDateTimeInstance().format(mDate); p.getTextBounds(dummy, 0, dummy.length(), mBounds); final int inset = (int) (mBounds.width()*0.1f); //add safety margin mBounds.inset(-inset, 0); }