@Override protected void onDraw(Canvas canvas) { mDrawable.setBounds(mRect); float r = 16; canvas.save(); canvas.translate(10, 10); mDrawable.setGradientType(GradientDrawable.LINEAR_GRADIENT); setCornerRadii(mDrawable, r, r, 0, 0); mDrawable.draw(canvas); canvas.restore(); canvas.save(); canvas.translate(10 + mRect.width() + 10, 10); mDrawable.setGradientType(GradientDrawable.RADIAL_GRADIENT); setCornerRadii(mDrawable, 0, 0, r, r); mDrawable.draw(canvas); canvas.restore(); canvas.translate(0, mRect.height() + 10); canvas.save(); canvas.translate(10, 10); mDrawable.setGradientType(GradientDrawable.SWEEP_GRADIENT); setCornerRadii(mDrawable, 0, r, r, 0); mDrawable.draw(canvas); canvas.restore(); canvas.save(); canvas.translate(10 + mRect.width() + 10, 10); mDrawable.setGradientType(GradientDrawable.LINEAR_GRADIENT); setCornerRadii(mDrawable, r, 0, 0, r); mDrawable.draw(canvas); canvas.restore(); canvas.translate(0, mRect.height() + 10); canvas.save(); canvas.translate(10, 10); mDrawable.setGradientType(GradientDrawable.RADIAL_GRADIENT); setCornerRadii(mDrawable, r, 0, r, 0); mDrawable.draw(canvas); canvas.restore(); canvas.save(); canvas.translate(10 + mRect.width() + 10, 10); mDrawable.setGradientType(GradientDrawable.SWEEP_GRADIENT); setCornerRadii(mDrawable, 0, r, 0, r); mDrawable.draw(canvas); canvas.restore(); }
@Override protected void dispatchDraw(Canvas canvas) { if (showcaseX < 0 || showcaseY < 0 || isRedundant) { super.dispatchDraw(canvas); return; } // Draw the semi-transparent background canvas.drawColor(backColor); // Draw to the scale specified Matrix mm = new Matrix(); mm.postScale(scaleMultiplier, scaleMultiplier, showcaseX, showcaseY); canvas.setMatrix(mm); // Erase the area for the ring canvas.drawCircle(showcaseX, showcaseY, showcaseRadius, mEraser); boolean recalculateText = makeVoidedRect() || mAlteredText; mAlteredText = false; showcase.setBounds(voidedArea); showcase.draw(canvas); canvas.setMatrix(new Matrix()); if (!TextUtils.isEmpty(mTitleText) || !TextUtils.isEmpty(mSubText)) { if (recalculateText) mBestTextPosition = getBestTextPosition(canvas.getWidth(), canvas.getHeight()); if (!TextUtils.isEmpty(mTitleText)) { // TODO: use a dynamic detail layout canvas.drawText(mTitleText, mBestTextPosition[0], mBestTextPosition[1], mPaintTitle); } if (!TextUtils.isEmpty(mSubText)) { canvas.save(); if (recalculateText) mDynamicDetailLayout = new DynamicLayout( mSubText, mPaintDetail, ((Number) mBestTextPosition[2]).intValue(), Layout.Alignment.ALIGN_NORMAL, 1.2f, 1.0f, true); canvas.translate(mBestTextPosition[0], mBestTextPosition[1] + 12 * metricScale); mDynamicDetailLayout.draw(canvas); canvas.restore(); } } super.dispatchDraw(canvas); }