@Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); // Initialize the values; initializeValues(); // Build a new Dynamic Layout with the available width since we can only provide width when the dynamic layout is created mDynamicLayout = new DynamicLayout(mStringBuilder, mStringBuilder, mTextPaint, w, Layout.Alignment.ALIGN_CENTER, 1.0f, 1.0f, true); }
@Override public void draw(Canvas canvas, boolean hasPositionChanged) { if (shouldDrawText()) { float[] textPosition = getBestTextPosition(); if (!TextUtils.isEmpty(mTitle)) { canvas.save(); if (hasPositionChanged) { mDynamicTitleLayout = new DynamicLayout(mTitle, mPaintTitle, (int) textPosition[2], Layout.Alignment.ALIGN_NORMAL, 1.0f, 1.0f, true); } canvas.translate(textPosition[0], textPosition[1]); mDynamicTitleLayout.draw(canvas); canvas.restore(); } if (!TextUtils.isEmpty(mDetails)) { canvas.save(); if (hasPositionChanged) { mDynamicDetailLayout = new DynamicLayout(mDetails, mPaintDetail, (int) textPosition[2], Layout.Alignment.ALIGN_NORMAL, 1.2f, 1.0f, true); } canvas.translate(textPosition[0], textPosition[1] + mDynamicTitleLayout.getHeight()); mDynamicDetailLayout.draw(canvas); canvas.restore(); } } }
public void draw(Canvas canvas) { if (shouldDrawText()) { float[] textPosition = getBestTextPosition(); if (!TextUtils.isEmpty(mTitle)) { canvas.save(); if (hasRecalculated) { mDynamicTitleLayout = new DynamicLayout(mTitle, titlePaint, (int) textPosition[2], Layout.Alignment.ALIGN_NORMAL, 1.0f, 1.0f, true); } if (mDynamicTitleLayout != null) { canvas.translate(textPosition[0], textPosition[1]); mDynamicTitleLayout.draw(canvas); canvas.restore(); } } if (!TextUtils.isEmpty(mDetails)) { canvas.save(); if (hasRecalculated) { mDynamicDetailLayout = new DynamicLayout(mDetails, textPaint, (int) textPosition[2], Layout.Alignment.ALIGN_NORMAL, 1.2f, 1.0f, true); } float offsetForTitle = mDynamicTitleLayout != null ? mDynamicTitleLayout.getHeight() : 0; if (mDynamicDetailLayout != null) { canvas.translate(textPosition[0], textPosition[1] + offsetForTitle); mDynamicDetailLayout.draw(canvas); canvas.restore(); } } } hasRecalculated = false; }
@Override public void draw(Canvas canvas, boolean hasPositionChanged) { if (shouldDrawText()) { float[] textPosition = getBestTextPosition(); if (!TextUtils.isEmpty(mTitle)) { canvas.save(); if (hasPositionChanged) { mDynamicTitleLayout = new DynamicLayout(mTitle, mPaintTitle, (int) textPosition[2], Layout.Alignment.ALIGN_NORMAL, 1.0f, 1.0f, true); } canvas.translate(textPosition[0], textPosition[1] - textPosition[0]); mDynamicTitleLayout.draw(canvas); canvas.restore(); } if (!TextUtils.isEmpty(mDetails)) { canvas.save(); if (hasPositionChanged) { mDynamicDetailLayout = new DynamicLayout(mDetails, mPaintDetail, ((Number) textPosition[2]).intValue(), Layout.Alignment.ALIGN_NORMAL, 1.2f, 1.0f, true); } canvas.translate(textPosition[0], textPosition[1] + 12 * mDensityScale + ( mDynamicTitleLayout.getLineBottom(mDynamicTitleLayout.getLineCount() - 1) - mDynamicTitleLayout.getLineBottom(0))); mDynamicDetailLayout.draw(canvas); canvas.restore(); } } }
public void draw(Canvas canvas) { if (shouldDrawText()) { float[] textPosition = getBestTextPosition(); for (float position : textPosition) { if (position < 0) { return; } } if (!TextUtils.isEmpty(mTitle)) { canvas.save(); if (hasRecalculated) { mDynamicTitleLayout = new DynamicLayout(mTitle, titlePaint, (int) textPosition[2], Layout.Alignment.ALIGN_NORMAL, 1.0f, 1.0f, true); } if (mDynamicTitleLayout != null) { canvas.translate(textPosition[0], textPosition[1]); mDynamicTitleLayout.draw(canvas); canvas.restore(); } } if (!TextUtils.isEmpty(mDetails)) { canvas.save(); if (hasRecalculated) { mDynamicDetailLayout = new DynamicLayout(mDetails, textPaint, (int) textPosition[2], Layout.Alignment.ALIGN_NORMAL, 1.2f, 1.0f, true); } float offsetForTitle = mDynamicTitleLayout != null ? mDynamicTitleLayout.getHeight() : 0; if (mDynamicDetailLayout != null) { canvas.translate(textPosition[0], textPosition[1] + offsetForTitle); mDynamicDetailLayout.draw(canvas); canvas.restore(); } } } hasRecalculated = false; }
@Override protected void dispatchDraw(Canvas canvas) { if (showcaseX < 0 || showcaseY < 0 || isRedundant) { super.dispatchDraw(canvas); return; } Bitmap b = Bitmap.createBitmap(getMeasuredWidth(), getMeasuredHeight(), Bitmap.Config.ARGB_8888); Canvas c = new Canvas(b); // Draw the semi-transparent background c.drawColor(backColor); // Draw to the scale specified Matrix mm = new Matrix(); mm.postScale(scaleMultiplier, scaleMultiplier, showcaseX, showcaseY); c.setMatrix(mm); // Erase the area for the ring c.drawCircle(showcaseX, showcaseY, showcaseRadius, mEraser); boolean recalculateText = makeVoidedRect() || mAlteredText; mAlteredText = false; showcase.setBounds(voidedArea); showcase.draw(c); canvas.drawBitmap(b, 0, 0, null); // Clean up, as we no longer require these items. try { c.setBitmap(null); } catch (NullPointerException npe) { // TODO why does this NPE happen? npe.printStackTrace(); } b.recycle(); b = null; 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.save(); float width = mPaintTitle.measureText(mTitleText); canvas.rotate(mOrientation, mBestTextPosition[0] + width / 2.0f, mBestTextPosition[1] + mPaintTitle.getTextSize() / 2.0f); canvas.drawText(mTitleText, mBestTextPosition[0], mBestTextPosition[1], mPaintTitle); canvas.restore(); } 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); if (mOrientation % 180 == 0) { canvas.translate(mBestTextPosition[0], mBestTextPosition[1]); } else { canvas.rotate(mOrientation, mDynamicDetailLayout.getWidth() / 2, mDynamicDetailLayout.getHeight() / 2); } mDynamicDetailLayout.draw(canvas); canvas.restore(); } } super.dispatchDraw(canvas); }
public void createLayout(Canvas canvas, int padding) { Editable.Factory fac = Editable.Factory.getInstance(); edit = fac.newEditable(stringToShow); dynamicLayout = new DynamicLayout(edit, textPaint, canvas.getWidth() - padding, Layout.Alignment.ALIGN_CENTER, 1, 0, true); }
public DynamicLayout getLayout() { return this.dynamicLayout; }