Java Code Examples for android.graphics.Rect#inset()
The following examples show how to use
android.graphics.Rect#inset() .
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: MyRoundCornerDrawable.java From PHONK with GNU General Public License v3.0 | 6 votes |
@Override public void draw(Canvas canvas) { int height = getBounds().height(); int width = getBounds().width(); // allow drawing out of bounds vertically Rect clipBounds = canvas.getClipBounds(); clipBounds.inset(-12, -12); // canvas.clipRect(clipBounds, Region.Op.DIFFERENCE); RectF rect = new RectF(0.0f, 0.0f, width, height); // background canvas.drawRoundRect(rect, mRadius, mRadius, mPaintBg); // border canvas.drawRoundRect(rect, mRadius, mRadius, mPaintBorder); }
Example 2
Source File: ViewHighlightOverlays.java From stetho with MIT License | 6 votes |
@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); }
Example 3
Source File: HighlightView.java From CloudPan with Apache License 2.0 | 6 votes |
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); }
Example 4
Source File: HighlightView.java From Android-RTEditor with Apache License 2.0 | 6 votes |
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); }
Example 5
Source File: CameraPreview.java From Viewer with Apache License 2.0 | 6 votes |
/** * Calculate framing rectangle, relative to the preview frame. * * Note that the SurfaceView may be larger than the container. * * Override this for more control over the framing rect calculations. * * @param container this container, with left = top = 0 * @param surface the SurfaceView, relative to this container * @return the framing rect, relative to this container */ protected Rect calculateFramingRect(Rect container, Rect surface) { // intersection is the part of the container that is used for the preview Rect intersection = new Rect(container); boolean intersects = intersection.intersect(surface); if(framingRectSize != null) { // Specific size is specified. Make sure it's not larger than the container or surface. int horizontalMargin = Math.max(0, (intersection.width() - framingRectSize.width) / 2); int verticalMargin = Math.max(0, (intersection.height() - framingRectSize.height) / 2); intersection.inset(horizontalMargin, verticalMargin); return intersection; } // margin as 10% (default) of the smaller of width, height int margin = (int)Math.min(intersection.width() * marginFraction, intersection.height() * marginFraction); intersection.inset(margin, margin); if (intersection.height() > intersection.width()) { // We don't want a frame that is taller than wide. intersection.inset(0, (intersection.height() - intersection.width()) / 2); } return intersection; }
Example 6
Source File: HighlightView.java From LockDemo with Apache License 2.0 | 6 votes |
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); }
Example 7
Source File: HighlightView.java From XERUNG with Apache License 2.0 | 6 votes |
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); }
Example 8
Source File: DiscreteSeekBar.java From PLDroidShortVideo with Apache License 2.0 | 6 votes |
private void updateThumbPos(int base, int value) { base += getPaddingLeft() + mAddedTouchBounds; value += getPaddingLeft() + mAddedTouchBounds; int start = Math.min(base, value); int end = Math.max(base, value); int thumbWidth = mThumb.getIntrinsicWidth(); int halfThumb = thumbWidth / 2; mThumb.copyBounds(mInvalidateRect); mThumb.setBounds(value, mInvalidateRect.top, value + thumbWidth, mInvalidateRect.bottom); mScrubber.getBounds().left = start + halfThumb; mScrubber.getBounds().right = end + halfThumb; final Rect finalBounds = mTempRect; mThumb.copyBounds(finalBounds); if (!isInEditMode()) { mIndicator.move(finalBounds.centerX()); } mTrackBase.getBounds().left = base + halfThumb - mTrackBaseHeight / 8; mTrackBase.getBounds().right = base + halfThumb + mTrackBaseHeight / 8; mInvalidateRect.inset(-mAddedTouchBounds, -mAddedTouchBounds); finalBounds.inset(-mAddedTouchBounds, -mAddedTouchBounds); mInvalidateRect.union(finalBounds); SeekBarCompat.setHotspotBounds(mRipple, finalBounds.left, finalBounds.top, finalBounds.right, finalBounds.bottom); invalidate(mInvalidateRect); }
Example 9
Source File: HighlightView.java From XERUNG with Apache License 2.0 | 6 votes |
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); }
Example 10
Source File: Workspace.java From Trebuchet with GNU General Public License v3.0 | 5 votes |
private static Rect getDrawableBounds(Drawable d) { Rect bounds = new Rect(); d.copyBounds(bounds); if (bounds.width() == 0 || bounds.height() == 0) { bounds.set(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); } else { bounds.offsetTo(0, 0); } if (d instanceof PreloadIconDrawable) { int inset = -((PreloadIconDrawable) d).getOutset(); bounds.inset(inset, inset); } return bounds; }
Example 11
Source File: TapTargetView.java From TapTargetView with Apache License 2.0 | 5 votes |
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; }
Example 12
Source File: DrawUtil.java From ViewInspector with Apache License 2.0 | 5 votes |
public static void drawMargin(View view, Canvas canvas) { if (view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) { int width = view.getWidth(); int height = view.getHeight(); ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); int lMargin = mlp.leftMargin; int tMargin = mlp.topMargin; int rMargin = mlp.rightMargin; int bMargin = mlp.bottomMargin; // extend canvas Rect newRect = canvas.getClipBounds(); 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); Rect lRect = new Rect(-lMargin, 0, 0, height); Rect ltRect = new Rect(-lMargin, -tMargin, 0, 0); Rect tRect = new Rect(0, -tMargin, width, 0); Rect trRect = new Rect(width, -tMargin, width + rMargin, 0); Rect rRect = new Rect(width, 0, width + rMargin, height); Rect rbRect = new Rect(width, height, width + rMargin, height + bMargin); Rect bRect = new Rect(0, height, width, height + bMargin); Rect blRect = new Rect(-lMargin, height, 0, height + bMargin); Paint paint = new Paint(); paint.setColor(MARGIN_COLOR); canvas.drawRect(lRect, paint); canvas.drawRect(ltRect, paint); canvas.drawRect(tRect, paint); canvas.drawRect(trRect, paint); canvas.drawRect(rRect, paint); canvas.drawRect(rbRect, paint); canvas.drawRect(bRect, paint); canvas.drawRect(blRect, paint); } }
Example 13
Source File: DiscreteSeekBar.java From Musicoco with Apache License 2.0 | 5 votes |
private void updateThumbPos(int posX) { int thumbWidth = mThumb.getIntrinsicWidth(); int halfThumb = thumbWidth / 2; int start; if (isRtl()) { start = getWidth() - getPaddingRight() - mAddedTouchBounds; posX = start - posX - thumbWidth; } else { start = getPaddingLeft() + mAddedTouchBounds; posX = start + posX; } mThumb.copyBounds(mInvalidateRect); mThumb.setBounds(posX, mInvalidateRect.top, posX + thumbWidth, mInvalidateRect.bottom); if (isRtl()) { mScrubber.getBounds().right = start - halfThumb; mScrubber.getBounds().left = posX + halfThumb; } else { mScrubber.getBounds().left = start + halfThumb; mScrubber.getBounds().right = posX + halfThumb; } final Rect finalBounds = mTempRect; mThumb.copyBounds(finalBounds); if (!isInEditMode()) { mIndicator.move(finalBounds.centerX()); } mInvalidateRect.inset(-mAddedTouchBounds, -mAddedTouchBounds); finalBounds.inset(-mAddedTouchBounds, -mAddedTouchBounds); mInvalidateRect.union(finalBounds); SeekBarCompat.setHotspotBounds(mRipple, finalBounds.left, finalBounds.top, finalBounds.right, finalBounds.bottom); invalidate(mInvalidateRect); }
Example 14
Source File: HighlightView.java From droidddle with Apache License 2.0 | 5 votes |
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); }
Example 15
Source File: DiscreteSeekBar.java From PLDroidShortVideo with Apache License 2.0 | 5 votes |
private boolean startDragging(MotionEvent ev, boolean ignoreTrackIfInScrollContainer) { final Rect bounds = mTempRect; mThumb.copyBounds(bounds); //Grow the current thumb rect for a bigger touch area bounds.inset(-mAddedTouchBounds, -mAddedTouchBounds); mIsDragging = (bounds.contains((int) ev.getX(), (int) ev.getY())); if (!mIsDragging && mAllowTrackClick && !ignoreTrackIfInScrollContainer) { //If the user clicked outside the thumb, we compute the current position //and force an immediate drag to it. mIsDragging = true; mDragOffset = (bounds.width() / 2) - mAddedTouchBounds; updateDragging(ev); //As the thumb may have moved, get the bounds again mThumb.copyBounds(bounds); bounds.inset(-mAddedTouchBounds, -mAddedTouchBounds); } if (mIsDragging) { setPressed(true); attemptClaimDrag(); setHotspot(ev.getX(), ev.getY()); mDragOffset = (int) (ev.getX() - bounds.left - mAddedTouchBounds); if (mPublicChangeListener != null) { mPublicChangeListener.onStartTrackingTouch(this); } } return mIsDragging; }
Example 16
Source File: DiscreteSeekBar.java From FuAgoraDemoDroid with MIT License | 5 votes |
private boolean startDragging(MotionEvent ev, boolean ignoreTrackIfInScrollContainer) { final Rect bounds = mTempRect; mThumb.copyBounds(bounds); //Grow the current thumb rect for a bigger touch area bounds.inset(-mAddedTouchBounds, -mAddedTouchBounds); mIsDragging = (bounds.contains((int) ev.getX(), (int) ev.getY())); if (!mIsDragging && mAllowTrackClick && !ignoreTrackIfInScrollContainer) { //If the user clicked outside the thumb, we compute the current position //and force an immediate drag to it. mIsDragging = true; mDragOffset = (bounds.width() / 2) - mAddedTouchBounds; updateDragging(ev); //As the thumb may have moved, get the bounds again mThumb.copyBounds(bounds); bounds.inset(-mAddedTouchBounds, -mAddedTouchBounds); } if (mIsDragging) { setPressed(true); attemptClaimDrag(); setHotspot(ev.getX(), ev.getY()); mDragOffset = (int) (ev.getX() - bounds.left - mAddedTouchBounds); if (mPublicChangeListener != null) { mPublicChangeListener.onStartTrackingTouch(this); } } return mIsDragging; }
Example 17
Source File: DiscreteSeekBar.java From android-open-project-demo with Apache License 2.0 | 5 votes |
private boolean startDragging(MotionEvent ev, boolean ignoreTrackIfInScrollContainer) { final Rect bounds = mTempRect; mThumb.copyBounds(bounds); //Grow the current thumb rect for a bigger touch area bounds.inset(-mAddedTouchBounds, -mAddedTouchBounds); mIsDragging = (bounds.contains((int) ev.getX(), (int) ev.getY())); if (!mIsDragging && mAllowTrackClick && !ignoreTrackIfInScrollContainer) { //If the user clicked outside the thumb, we compute the current position //and force an immediate drag to it. mIsDragging = true; mDragOffset = (bounds.width() / 2) - mAddedTouchBounds; updateDragging(ev); //As the thumb may have moved, get the bounds again mThumb.copyBounds(bounds); bounds.inset(-mAddedTouchBounds, -mAddedTouchBounds); } if (mIsDragging) { setPressed(true); attemptClaimDrag(); setHotspot(ev.getX(), ev.getY()); mDragOffset = (int) (ev.getX() - bounds.left - mAddedTouchBounds); if (mPublicChangeListener != null) { mPublicChangeListener.onStartTrackingTouch(this); } } return mIsDragging; }
Example 18
Source File: DiscreteSeekBar.java From Panoramic-Screenshot with GNU General Public License v3.0 | 5 votes |
private boolean startDragging(MotionEvent ev, boolean ignoreTrackIfInScrollContainer) { final Rect bounds = mTempRect; mThumb.copyBounds(bounds); //Grow the current thumb rect for a bigger touch area bounds.inset(-mAddedTouchBounds, -mAddedTouchBounds); mIsDragging = (bounds.contains((int) ev.getX(), (int) ev.getY())); if (!mIsDragging && mAllowTrackClick && !ignoreTrackIfInScrollContainer) { //If the user clicked outside the thumb, we compute the current position //and force an immediate drag to it. mIsDragging = true; mDragOffset = (bounds.width() / 2) - mAddedTouchBounds; updateDragging(ev); //As the thumb may have moved, get the bounds again mThumb.copyBounds(bounds); bounds.inset(-mAddedTouchBounds, -mAddedTouchBounds); } if (mIsDragging) { setPressed(true); attemptClaimDrag(); setHotspot(ev.getX(), ev.getY()); mDragOffset = (int) (ev.getX() - bounds.left - mAddedTouchBounds); if (mPublicChangeListener != null) { mPublicChangeListener.onStartTrackingTouch(this); } } return mIsDragging; }
Example 19
Source File: DraggableGridViewPager.java From UltimateAndroid with Apache License 2.0 | 5 votes |
private int getTargetByXY(int x, int y) { final int position = getPositionByXY(x, y); if (position < 0) { return -1; } final Rect r = getRectByPosition(position); final int page = position / mPageSize; r.inset(r.width() / 4, r.height() / 4); r.offset(-getWidth() * page, 0); if (!r.contains(x, y)) { return -1; } return position; }
Example 20
Source File: DiffLineSpan.java From GitDiffTextView with Apache License 2.0 | 5 votes |
@Override public void drawBackground(Canvas c, Paint p, int left, int right, int top, int baseline, int bottom, CharSequence text, int start, int end, int lnum) { // expand canvas bounds by padding Rect clipBounds = c.getClipBounds(); clipBounds.inset(- padding, 0); c.clipRect(clipBounds, Region.Op.REPLACE); final int paintColor = p.getColor(); p.setColor(color); mTmpRect.set(left - padding, top, right + padding, bottom); c.drawRect(mTmpRect, p); p.setColor(paintColor); }