Java Code Examples for android.text.DynamicLayout

The following are top voted examples for showing how to use android.text.DynamicLayout. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Dash-Spinner   File: DashSpinner.java   Source Code and License 5 votes vote down vote up
@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);
}
 
Example 2
Project: DVBViewerController   File: TextDrawerImpl.java   Source Code and License 5 votes vote down vote up
@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();

        }
    }
}
 
Example 3
Project: WeiboWeiBaTong   File: TextDrawerImpl.java   Source Code and License 5 votes vote down vote up
@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();

        }
    }
}
 
Example 4
Project: yelo-android   File: TextDrawer.java   Source Code and License 5 votes vote down vote up
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;
}
 
Example 5
Project: System-Monitor   File: TextDrawer.java   Source Code and License 5 votes vote down vote up
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;
}
 
Example 6
Project: android-app-framework   File: TextDrawerImpl.java   Source Code and License 5 votes vote down vote up
@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();

        }
    }
}
 
Example 7
Project: WeiboWeiBaTong   File: TextDrawerImpl.java   Source Code and License 5 votes vote down vote up
@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();

        }
    }
}
 
Example 8
Project: OurDailyBread   File: TextDrawerImpl.java   Source Code and License 5 votes vote down vote up
@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();

        }
    }
}
 
Example 9
Project: siciyuan   File: TextDrawerImpl.java   Source Code and License 5 votes vote down vote up
@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();

        }
    }
}
 
Example 10
Project: 30-android-libraries-in-30-days   File: TextDrawer.java   Source Code and License 5 votes vote down vote up
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;
}
 
Example 11
Project: UltimateAndroid   File: TextDrawer.java   Source Code and License 5 votes vote down vote up
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;
}
 
Example 12
Project: math-dragon   File: TextDrawerImpl.java   Source Code and License 5 votes vote down vote up
@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();

        }
    }
}
 
Example 13
Project: AomYim-Pantip   File: TextDrawer.java   Source Code and License 4 votes vote down vote up
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;
}
 
Example 14
Project: OmniSnitch   File: ShowcaseView.java   Source Code and License 4 votes vote down vote up
@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);
}
 
Example 15
Project: miswordfighting   File: Text.java   Source Code and License 4 votes vote down vote up
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);
}
 
Example 16
Project: miswordfighting   File: Text.java   Source Code and License 4 votes vote down vote up
public DynamicLayout getLayout() {
	return this.dynamicLayout;
}