private void drawCurrentPageArea(Canvas canvas, Bitmap bitmap, Path path) { mPath0.reset(); mPath0.moveTo(mBezierStart1.x, mBezierStart1.y); mPath0.quadTo(mBezierControl1.x, mBezierControl1.y, mBezierEnd1.x, mBezierEnd1.y); mPath0.lineTo(mTouch.x, mTouch.y); mPath0.lineTo(mBezierEnd2.x, mBezierEnd2.y); mPath0.quadTo(mBezierControl2.x, mBezierControl2.y, mBezierStart2.x, mBezierStart2.y); mPath0.lineTo(mCornerX, mCornerY); mPath0.close(); canvas.save(); canvas.clipPath(path, Region.Op.XOR); canvas.drawBitmap(bitmap, 0, 0, null); try { canvas.restore(); } catch (Exception e) { } }
@Override protected void drawCurrentPageArea(Canvas canvas) { mPath0.reset(); mPath0.moveTo(mBezierStart1.x, mBezierStart1.y); mPath0.quadTo(mBezierControl1.x, mBezierControl1.y, mBezierEnd1.x, mBezierEnd1.y); mPath0.lineTo(mTouch.x, mTouch.y); mPath0.lineTo(mBezierEnd2.x, mBezierEnd2.y); mPath0.quadTo(mBezierControl2.x, mBezierControl2.y, mBezierStart2.x, mBezierStart2.y); mPath0.lineTo(mCornerX, mCornerY); mPath0.close(); canvas.save(); canvas.clipPath(mPath0, Region.Op.XOR); canvas.drawBitmap(mCurPageBitmap, 0, 0, null); try { canvas.restore(); } catch (Exception e) { } }
public void draw(Canvas canvas, Paint paint, float opacity) { opacity *= mOpacity; if (opacity > MIN_OPACITY_FOR_DRAW) { saveAndSetupCanvas(canvas); if (mClipping != null) { canvas.clipRect( mClipping.left * mScale, mClipping.top * mScale, mClipping.right * mScale, mClipping.bottom * mScale, Region.Op.REPLACE); } for (int i = 0; i < getChildCount(); i++) { ARTVirtualNode child = (ARTVirtualNode) getChildAt(i); child.draw(canvas, paint, opacity); child.markUpdateSeen(); } restoreCanvas(canvas); } }
@Override protected void drawNextPageAreaAndShadow(Canvas canvas) { canvas.save(); if (actiondownX > mScreenWidth >> 1) { canvas.clipPath(mPath0); canvas.drawBitmap(mNextPageBitmap, 0, 0, null); } else { canvas.clipPath(mPath0, Region.Op.XOR); canvas.drawBitmap(mNextPageBitmap, 0, 0, null); } try { canvas.restore(); } catch (Exception e) { } }
public CardItemView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mPaint.setStyle(Paint.Style.FILL); TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.Card, defStyleAttr, 0); mSize = ta.getDimensionPixelSize(R.styleable.Card_size, 10); mPaint.setColor(ta.getColor(R.styleable.Card_bgColor, 0)); ta.recycle(); mRegion = new Region(); mDrawPath = new Path(); mDrawPath.moveTo(0, mSize / 2); mDrawPath.lineTo(mSize / 2, 0); mDrawPath.lineTo(mSize, mSize / 2); mDrawPath.lineTo(mSize / 2, mSize); mDrawPath.close(); }
@Override protected void dispatchDraw(Canvas canvas) { // Draw the background below children. if (mBackgroundAlpha > 0.0f) { // Update the scroll position first to ensure scrim cutout is in the right place. mLauncher.getWorkspace().computeScrollWithoutInvalidation(); int alpha = (int) (mBackgroundAlpha * 255); CellLayout currCellLayout = mLauncher.getWorkspace().getCurrentDragOverlappingLayout(); canvas.save(); if (currCellLayout != null && currCellLayout != mLauncher.getHotseat().getLayout()) { // Cut a hole in the darkening scrim on the page that should be highlighted, if any. getDescendantRectRelativeToSelf(currCellLayout, mHighlightRect); canvas.clipRect(mHighlightRect, Region.Op.DIFFERENCE); } canvas.drawColor((alpha << 24) | SCRIM_COLOR); canvas.restore(); } mFocusIndicatorHelper.draw(canvas); super.dispatchDraw(canvas); }
private void drawCurrentPageArea(Canvas canvas, Bitmap bitmap, Path path) { mPath0.reset(); mPath0.moveTo(mBezierStart1.x, mBezierStart1.y); mPath0.quadTo(mBezierControl1.x, mBezierControl1.y, mBezierEnd1.x, mBezierEnd1.y); mPath0.lineTo(mTouchX, mTouchY); mPath0.lineTo(mBezierEnd2.x, mBezierEnd2.y); mPath0.quadTo(mBezierControl2.x, mBezierControl2.y, mBezierStart2.x, mBezierStart2.y); mPath0.lineTo(mCornerX, mCornerY); mPath0.close(); canvas.save(); canvas.clipPath(path, Region.Op.XOR); canvas.drawBitmap(bitmap, 0, 0, null); try { canvas.restore(); } catch (Exception e) { } }
private void drawProgressRectWithClip(Canvas canvas) { mPaint.setColor(mProgressBarColor); mPaint.setStyle(Paint.Style.FILL); //根据进度比率计算出当前的进度值对应的宽度 int progress = (int) (mValidWidth * (getProgress() * 1.0f / getMax())); canvas.save(); canvas.translate(getPaddingLeft(), getPaddingTop()); //裁剪圆角矩形路径 drawRoundRectPath(); canvas.clipPath(mRoundRectPath);//裁剪之后此时画布就变成了裁剪之后的圆角矩形 //裁剪进度路径 drawProgressPath(progress); canvas.clipPath(mProgressPath, Region.Op.INTERSECT); canvas.drawColor(mProgressBarColor); canvas.restore(); }
private void initData() { //关闭硬件加速,为了可以设置阴影 setLayerType(LAYER_TYPE_SOFTWARE, null); mOuterPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mOuterPaint.setStyle(Paint.Style.STROKE); mOuterPaint.setStrokeWidth(mOuterWidth); mOuterPaint.setColor(mOuterColor); mInnerPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mInnerPaint.setStyle(Paint.Style.FILL_AND_STROKE); mInnerPaint.setColor(mInnerColor); mRegion = new Region(); mViewPath = new Path(); }
/** * 绘制A区域水平翻页阴影 * @param canvas */ private void drawPathAHorizontalShadow(Canvas canvas, Path pathA){ canvas.restore(); canvas.save(); canvas.clipPath(pathA, Region.Op.INTERSECT); int maxShadowWidth = 30;//阴影矩形最大的宽度 int left = (int) (a.x - Math.min(maxShadowWidth,(rPathAShadowDis/2))); int right = (int) (a.x); int top = 0; int bottom = viewHeight; GradientDrawable gradientDrawable = drawableHorizontalLowerRight; gradientDrawable.setBounds(left,top,right,bottom); float mDegrees = (float) Math.toDegrees(Math.atan2(f.x-a.x,f.y-h.y)); canvas.rotate(mDegrees, a.x, a.y); gradientDrawable.draw(canvas); }
/** * 绘制C区域内容 * @param canvas * @param pathA */ private void drawPathCContent(Canvas canvas, Path pathA){ canvas.save(); canvas.clipPath(pathA); canvas.clipPath(getPathC(), Region.Op.REVERSE_DIFFERENCE);//裁剪出C区域不同于A区域的部分 // canvas.drawPath(getPathC(),pathCPaint); float eh = (float) Math.hypot(f.x - e.x,h.y - f.y); float sin0 = (f.x - e.x) / eh; float cos0 = (h.y - f.y) / eh; //设置翻转和旋转矩阵 mMatrixArray[0] = -(1-2 * sin0 * sin0); mMatrixArray[1] = 2 * sin0 * cos0; mMatrixArray[3] = 2 * sin0 * cos0; mMatrixArray[4] = 1 - 2 * sin0 * sin0; mMatrix.reset(); mMatrix.setValues(mMatrixArray);//翻转和旋转 mMatrix.preTranslate(-e.x, -e.y);//沿当前XY轴负方向位移得到 矩形A₃B₃C₃D₃ mMatrix.postTranslate(e.x, e.y);//沿原XY轴方向位移得到 矩形A4 B4 C4 D4 canvas.drawBitmap(pathCContentBitmap, mMatrix, null); drawPathCShadow(canvas); canvas.restore(); }
@Override protected void dispatchDraw(Canvas canvas) { width = getWidth(); height = getHeight(); mClipPath.reset(); if (position == ElasticDrawer.Position.LEFT) { drawLeftMenu(); } else { drawRightMenu(); } canvas.save(); canvas.drawPath(mClipPath, mPaint); canvas.clipPath(mClipPath, Region.Op.REPLACE); super.dispatchDraw(canvas); canvas.restore(); }
@Override public void draw(Canvas canvas) { int w = getWidth(); int h = getHeight(); canvas.clipPath(innerRoundPath(w, h), Region.Op.DIFFERENCE); super.draw(canvas); degree += speed; degree %= 360; matrix.setRotate(degree, w / 2, h / 2); shader.setLocalMatrix(matrix); rectF.left = 0; rectF.top = 0; rectF.right = w; rectF.bottom = h; canvas.drawRoundRect(rectF, radius, radius, paint); invalidate(); }
private void drawMinutes(Canvas canvas, Path selectorPath, float alphaMod) { final int minutesAlpha = (int) (255f * mHoursToMinutes * alphaMod + 0.5f); if (minutesAlpha > 0) { // Exclude the selector region, then draw minutes with no // activated states. canvas.save(Canvas.CLIP_SAVE_FLAG); canvas.clipPath(selectorPath, Region.Op.DIFFERENCE); drawMinutesClipped(canvas, minutesAlpha, false); canvas.restore(); // Intersect the selector region, then draw minutes with only // activated states. canvas.save(Canvas.CLIP_SAVE_FLAG); canvas.clipPath(selectorPath, Region.Op.INTERSECT); drawMinutesClipped(canvas, minutesAlpha, true); canvas.restore(); } }
@Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); mLayer = new RectF(0, 0, w, h); RectF areas = new RectF(); areas.left = getPaddingLeft(); areas.top = getPaddingTop(); areas.right = w - getPaddingRight(); areas.bottom = h - getPaddingBottom(); mClipPath.reset(); if (mRoundAsCircle) { float d = areas.width() >= areas.height() ? areas.height() : areas.width(); float r = d / 2; PointF center = new PointF(w / 2, h / 2); mClipPath.addCircle(center.x, center.y, r, Path.Direction.CW); mClipPath.moveTo(-mEdgeFix, -mEdgeFix); // 通过空操作让Path区域占满画布 mClipPath.moveTo(w + mEdgeFix, h + mEdgeFix); } else { mClipPath.addRoundRect(areas, radii, Path.Direction.CW); } Region clip = new Region((int) areas.left, (int) areas.top, (int) areas.right, (int) areas.bottom); mAreaRegion.setPath(mClipPath, clip); }
/** * 绘制外发光阴影 * * @param canvas */ private void onDrawShadow(Canvas canvas) { if (mShadowWidth > 0) { canvas.save(); // 裁剪处理(使阴影矩形框内变为透明) if (mRoundRadius > 0) { canvas.clipRect(0, 0, getWidth(), getHeight()); mTempRectF.set(mFrameRectF); mTempRectF.inset(mRoundRadius / 2f, mRoundRadius / 2f); canvas.clipRect(mTempRectF, Region.Op.DIFFERENCE); } // 绘制外发光阴影效果 canvas.drawRoundRect(mFrameRectF, mRoundRadius, mRoundRadius, mShadowPaint); canvas.restore(); } }
private void drawCurrentPageArea(Canvas canvas, Bitmap bitmap) { mPath1.reset(); mPath1.moveTo(mBzStart1.x, mBzStart1.y); mPath1.quadTo(mBzControl1.x, mBzControl1.y, mBzEnd1.x, mBzEnd1.y); mPath1.lineTo(mTouch.x, mTouch.y); mPath1.lineTo(mBzEnd2.x, mBzEnd2.y); mPath1.quadTo(mBzControl2.x, mBzControl2.y, mBzStart2.x, mBzStart2.y); mPath1.lineTo(mCornerX, mCornerY); mPath1.close(); canvas.save(); canvas.clipPath(mPath1, Region.Op.XOR); canvas.drawBitmap(bitmap, 0, 0, null); canvas.restore(); }
@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.REPLACE); RectF rect = new RectF(0.0f, 0.0f, width, height); // background canvas.drawRoundRect(rect, mRadius, mRadius, mPaintBg); // border canvas.drawRoundRect(rect, mRadius, mRadius, mPaintBorder); }
private void drawTimeColumnAndAxes(Canvas canvas) { // Draw the background color for the header column. canvas.drawRect(0, mHeaderTextHeight + mHeaderRowPadding * 2, mHeaderColumnWidth, getHeight(), mHeaderColumnBackgroundPaint); // Clip to paint in left column only. canvas.clipRect(0, mHeaderTextHeight + mHeaderRowPadding * 2, mHeaderColumnWidth, getHeight(), Region.Op.REPLACE); for (int i = 0; i < 24; i++) { float top = mHeaderTextHeight + mHeaderRowPadding * 2 + mCurrentOrigin.y + mHourHeight * i + mHeaderMarginBottom; // Draw the text if its y position is not outside of the visible area. The pivot point of the text is the point at the bottom-right corner. String time = getDateTimeInterpreter().interpretTime(i); if (time == null) throw new IllegalStateException("A DateTimeInterpreter must not return null time"); if (top < getHeight()) canvas.drawText(time, mTimeTextWidth + mHeaderColumnPadding, top + mTimeTextHeight, mTimeTextPaint); } }
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { Integer index = (Integer) child.getTag(); VoronoiRegion region = mRegions.get(index); // firstly clip and draw children canvas.clipPath(region.path, Region.Op.REPLACE); boolean result = super.drawChild(canvas, child, drawingTime); // then draw borders if (mBorderEnabled) canvas.drawPath(region.path, p); // draw site // canvas.drawCircle((float)region.site.x, (float)region.site.y, 10, p); return result; }
private Bitmap clippedRotatedOval(Bitmap bitmap) { Bitmap bmp; float width = bitmap.getWidth(); float height = bitmap.getHeight(); bmp = Bitmap.createBitmap((int) width, (int) height, Bitmap.Config.ARGB_8888); BitmapShader shader = new BitmapShader(bitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP); Canvas canvas = new Canvas(bmp); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setShader(shader); Path oval = new Path(); Matrix matrix = new Matrix(); Region region = new Region(); RectF ovalRect = new RectF(width / OVAL_FACTOR, 0, width - (width / OVAL_FACTOR), height); oval.addOval(ovalRect, Path.Direction.CW); matrix.postRotate(ROTATION, width / 2, height / 2); oval.transform(matrix, oval); region.setPath(oval, new Region((int) width / 2, 0, (int) width, (int) height)); canvas.drawPath(region.getBoundaryPath(), paint); return bmp; }
@Override protected void draw(Canvas canvas, Rect bounds) { int saveCount = canvas.save(); RectF arcBounds = mTempBounds; arcBounds.set(bounds); mPaint.setColor(mColor); //calculate fish clip bounds //clip the width of the fish need to increase mPathDottedLineSize * 1.2f RectF fishRectF = new RectF(mFishHeadPos[0] - mFishWidth / 2.0f - mPathDottedLineSize * 1.2f, mFishHeadPos[1] - mFishHeight / 2.0f, mFishHeadPos[0] + mFishWidth / 2.0f + mPathDottedLineSize * 1.2f, mFishHeadPos[1] + mFishHeight / 2.0f); Matrix matrix = new Matrix(); matrix.postRotate(mFishRotateDegrees, fishRectF.centerX(), fishRectF.centerY()); matrix.mapRect(fishRectF); //draw river int riverSaveCount = canvas.save(); mPaint.setStyle(Paint.Style.STROKE); canvas.clipRect(fishRectF, Region.Op.DIFFERENCE); canvas.drawPath(createRiverPath(arcBounds), mPaint); canvas.restoreToCount(riverSaveCount); //draw fish int fishSaveCount = canvas.save(); mPaint.setStyle(Paint.Style.FILL); canvas.rotate(mFishRotateDegrees, mFishHeadPos[0], mFishHeadPos[1]); canvas.clipPath(createFishEyePath(mFishHeadPos[0], mFishHeadPos[1] - mFishHeight * 0.06f), Region.Op.DIFFERENCE); canvas.drawPath(createFishPath(mFishHeadPos[0], mFishHeadPos[1]), mPaint); canvas.restoreToCount(fishSaveCount); canvas.restoreToCount(saveCount); }
@Override protected void drawNextPageAreaAndShadow(Canvas canvas) { mPath1.reset(); mPath1.moveTo(mBezierStart1.x, mBezierStart1.y); mPath1.lineTo(mBeziervertex1.x, mBeziervertex1.y); mPath1.lineTo(mBeziervertex2.x, mBeziervertex2.y); mPath1.lineTo(mBezierStart2.x, mBezierStart2.y); mPath1.lineTo(mCornerX, mCornerY); mPath1.close(); mDegrees = (float) Math.toDegrees(Math.atan2(mBezierControl1.x - mCornerX, mBezierControl2.y - mCornerY)); int leftx; int rightx; GradientDrawable mBackShadowDrawable; if (mIsRTandLB) { //左下及右上 leftx = (int) (mBezierStart1.x); rightx = (int) (mBezierStart1.x + mTouchToCornerDis / 4); mBackShadowDrawable = mBackShadowDrawableLR; } else { leftx = (int) (mBezierStart1.x - mTouchToCornerDis / 4); rightx = (int) mBezierStart1.x; mBackShadowDrawable = mBackShadowDrawableRL; } canvas.save(); try { canvas.clipPath(mPath0); canvas.clipPath(mPath1, Region.Op.INTERSECT); } catch (Exception e) { } canvas.drawBitmap(mNextPageBitmap, 0, 0, null); canvas.rotate(mDegrees, mBezierStart1.x, mBezierStart1.y); mBackShadowDrawable.setBounds(leftx, (int) mBezierStart1.y, rightx, (int) (mMaxLength + mBezierStart1.y));//左上及右下角的xy坐标值,构成一个矩形 mBackShadowDrawable.draw(canvas); canvas.restore(); }
private boolean isEventInPath(MotionEvent event) { RectF bounds = new RectF(); mDrawPath.computeBounds(bounds, true); mRegion.setPath(mDrawPath, new Region((int)bounds.left, (int)bounds.top, (int)bounds.right, (int)bounds.bottom)); return mRegion.contains((int) event.getX(), (int) event.getY()); }
private void drawNextPageAreaAndShadow(Canvas canvas, Bitmap bitmap) { mPath1.reset(); mPath1.moveTo(mBezierStart1.x, mBezierStart1.y); mPath1.lineTo(mBeziervertex1.x, mBeziervertex1.y); mPath1.lineTo(mBeziervertex2.x, mBeziervertex2.y); mPath1.lineTo(mBezierStart2.x, mBezierStart2.y); mPath1.lineTo(mCornerX, mCornerY); mPath1.close(); mDegrees = (float) Math.toDegrees(Math.atan2(mBezierControl1.x - mCornerX, mBezierControl2.y - mCornerY)); int leftx; int rightx; GradientDrawable mBackShadowDrawable; if (mIsRTandLB) { //左下及右上 leftx = (int) (mBezierStart1.x); rightx = (int) (mBezierStart1.x + mTouchToCornerDis / 4); mBackShadowDrawable = mBackShadowDrawableLR; } else { leftx = (int) (mBezierStart1.x - mTouchToCornerDis / 4); rightx = (int) mBezierStart1.x; mBackShadowDrawable = mBackShadowDrawableRL; } canvas.save(); try { canvas.clipPath(mPath0); canvas.clipPath(mPath1, Region.Op.INTERSECT); } catch (Exception e) { } canvas.drawBitmap(bitmap, 0, 0, null); canvas.rotate(mDegrees, mBezierStart1.x, mBezierStart1.y); mBackShadowDrawable.setBounds(leftx, (int) mBezierStart1.y, rightx, (int) (mMaxLength + mBezierStart1.y));//左上及右下角的xy坐标值,构成一个矩形 mBackShadowDrawable.draw(canvas); canvas.restore(); }
@Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); mCirclePath.addCircle(w / 2, h / 2, 300, Path.Direction.CW); Region globalRegion = new Region(-w, -h, w, h); mCircleRegion.setPath(mCirclePath, globalRegion); }
private void drawShadow(Canvas canvas) { if (shadowDrawable != null) { Rect newRect = canvas.getClipBounds(); Log.d(TAG,"ShadowParentView has blur! " + newRect); newRect.inset(-shadowPadding, -shadowPadding); canvas.clipRect (newRect, Region.Op.REPLACE); shadowDrawable.draw(canvas); } }
/** * 绘制A区域左阴影 * @param canvas */ private void drawPathALeftShadow(Canvas canvas, Path pathA){ canvas.restore(); canvas.save(); int left; int right; int top = (int) e.y; int bottom = (int) (e.y+viewHeight); GradientDrawable gradientDrawable; if (style.equals(STYLE_TOP_RIGHT)) { gradientDrawable = drawableLeftTopRight; left = (int) (e.x - lPathAShadowDis /2); right = (int) (e.x); } else { gradientDrawable = drawableLeftLowerRight; left = (int) (e.x); right = (int) (e.x + lPathAShadowDis /2); } Path mPath = new Path(); mPath.moveTo(a.x- Math.max(rPathAShadowDis, lPathAShadowDis) /2,a.y); mPath.lineTo(d.x,d.y); mPath.lineTo(e.x,e.y); mPath.lineTo(a.x,a.y); mPath.close(); canvas.clipPath(pathA); canvas.clipPath(mPath, Region.Op.INTERSECT); float mDegrees = (float) Math.toDegrees(Math.atan2(e.x-a.x, a.y-e.y)); canvas.rotate(mDegrees, e.x, e.y); gradientDrawable.setBounds(left,top,right,bottom); gradientDrawable.draw(canvas); }
/** * 绘制A区域右阴影 * @param canvas */ private void drawPathARightShadow(Canvas canvas, Path pathA){ canvas.restore(); canvas.save(); float viewDiagonalLength = (float) Math.hypot(viewWidth, viewHeight);//view对角线长度 int left = (int) h.x; int right = (int) (h.x + viewDiagonalLength*10);//需要足够长的长度 int top; int bottom; GradientDrawable gradientDrawable; if (style.equals(STYLE_TOP_RIGHT)) { gradientDrawable = drawableRightTopRight; top = (int) (h.y- rPathAShadowDis /2); bottom = (int) h.y; } else { gradientDrawable = drawableRightLowerRight; top = (int) h.y; bottom = (int) (h.y+ rPathAShadowDis /2); } gradientDrawable.setBounds(left,top,right,bottom); Path mPath = new Path(); mPath.moveTo(a.x- Math.max(rPathAShadowDis, lPathAShadowDis) /2,a.y); // mPath.lineTo(i.x,i.y); mPath.lineTo(h.x,h.y); mPath.lineTo(a.x,a.y); mPath.close(); canvas.clipPath(pathA); canvas.clipPath(mPath, Region.Op.INTERSECT); float mDegrees = (float) Math.toDegrees(Math.atan2(a.y-h.y, a.x-h.x)); canvas.rotate(mDegrees, h.x, h.y); gradientDrawable.draw(canvas); }
/** * 绘制B区域内容 * @param canvas * @param pathA */ private void drawPathBContent(Canvas canvas, Path pathA){ canvas.save(); canvas.clipPath(pathA);//裁剪出A区域 canvas.clipPath(getPathC(),Region.Op.UNION);//裁剪出A和C区域的全集 canvas.clipPath(getPathB(), Region.Op.REVERSE_DIFFERENCE);//裁剪出B区域中不同于与AC区域的部分 canvas.drawBitmap(pathBContentBitmap, 0, 0, null); drawPathBShadow(canvas); canvas.restore(); }
@Override public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) { if (mPinnedHeaderView != null) { c.save(); mClipBounds.top = 0; c.clipRect(mClipBounds, Region.Op.UNION); c.translate(0, mPinnedHeaderTop); mPinnedHeaderView.draw(c); c.restore(); } }
protected void draw(Canvas canvas) { canvas.save(); Path path = new Path(); outlinePaint.setStrokeWidth(outlineWidth); if (!hasFocus()) { outlinePaint.setColor(Color.BLACK); canvas.drawRect(drawRect, outlinePaint); } else { Rect viewDrawingRect = new Rect(); viewContext.getDrawingRect(viewDrawingRect); path.addRect(new RectF(drawRect), Path.Direction.CW); outlinePaint.setColor(highlightColor); if (isClipPathSupported(canvas)) { canvas.clipPath(path, Region.Op.DIFFERENCE); canvas.drawRect(viewDrawingRect, outsidePaint); } else { drawOutsideFallback(canvas); } canvas.restore(); canvas.drawPath(path, outlinePaint); if (showThirds) { drawThirds(canvas); } if (showCircle) { drawCircle(canvas); } if (handleMode == HandleMode.Always || (handleMode == HandleMode.Changing && modifyMode == ModifyMode.Grow)) { drawHandles(canvas); } } }
@Override public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { RectF r = new RectF(); mPath.computeBounds(r, true); mRegion.setPath(mPath, new Region((int) r.left, (int) r.top, (int) r.right, (int) r.bottom)); if (!mRegion.contains((int) event.getX(), (int) event.getY())) { mListener.edge(); } } return super.onTouchEvent(event); }
@Override public void draw(final Canvas canvas) { final Rect r = getBounds(); final int saveCount = canvas.save(); canvas.clipRect(r, Region.Op.REPLACE); canvas.translate(r.left, r.top); canvas.drawBitmap(background, 0, 0, paint); drawCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); drawCanvas.drawBitmap(dynamic, 0, 0, null); final float angle; if (maxAngle >= 0) angle = -(float) (360d - (maxAngle * value)); else angle = (float) (360d - (-maxAngle * value)); drawCanvas.drawArc(ovalRect, startAngle, angle, true, erasePaint); canvas.drawBitmap(drawBitmap, 0, 0, paint); canvas.drawBitmap(foreground, 0, 0, paint); // canvas.drawText(formatter.format(value), textX, textY, textPaint); canvas.restoreToCount(saveCount); }