Java Code Examples for android.text.method.TransformationMethod#getTransformation()
The following examples show how to use
android.text.method.TransformationMethod#getTransformation() .
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: AutoExpandTextView.java From Trebuchet with GNU General Public License v3.0 | 5 votes |
/** * Re size the font so the specified text fits in the text box assuming the text box is the * specified width. */ private void refitText() { CharSequence text = getText(); if (TextUtils.isEmpty(text)) { return; } TransformationMethod method = getTransformationMethod(); if (method != null) { text = method.getTransformation(text, this); } int targetWidth = getWidth() - getPaddingLeft() - getPaddingRight(); if (targetWidth > 0) { float high = 100; float low = 0; mPaint.set(getPaint()); mPaint.setTextSize(getTextSize()); float letterSpacing = getLetterSpacing(text, mPaint, targetWidth, low, high, mPrecision); mPaint.setLetterSpacing(letterSpacing); calculateSections(text); super.setLetterSpacing(letterSpacing); } }
Example 2
Source File: AutofitHelper.java From kAndroid with Apache License 2.0 | 4 votes |
/** * Re-sizes the textSize of the TextView so that the text fits within the bounds of the View. */ private static void autofit(TextView view, TextPaint paint, float minTextSize, float maxTextSize, int maxLines, float precision) { if (maxLines <= 0 || maxLines == Integer.MAX_VALUE) { // Don't auto-size since there's no limit on lines. return; } int targetWidth = view.getWidth() - view.getPaddingLeft() - view.getPaddingRight(); if (targetWidth <= 0) { return; } CharSequence text = view.getText(); TransformationMethod method = view.getTransformationMethod(); if (method != null) { text = method.getTransformation(text, view); } Context context = view.getContext(); Resources r = Resources.getSystem(); DisplayMetrics displayMetrics; float size = maxTextSize; float high = size; float low = 0; if (context != null) { r = context.getResources(); } displayMetrics = r.getDisplayMetrics(); paint.set(view.getPaint()); paint.setTextSize(size); if ((maxLines == 1 && paint.measureText(text, 0, text.length()) > targetWidth) || getLineCount(text, paint, size, targetWidth, displayMetrics) > maxLines) { size = getAutofitTextSize(text, paint, targetWidth, maxLines, low, high, precision, displayMetrics); } if (size < minTextSize) { size = minTextSize; } view.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); }
Example 3
Source File: TextUtil.java From VideoOS-Android-SDK with GNU General Public License v3.0 | 4 votes |
/** * Re-sizes the textSize of the TextView so that the text fits within the bounds of the View. */ static void adjustTextSize(TextView view, TextPaint paint, float minTextSize, float maxTextSize, int maxLines, float precision) { if (maxLines <= 0 || maxLines == Integer.MAX_VALUE) { // Don't auto-size since there's no limit on lines. return; } int targetWidth = view.getWidth() - view.getPaddingLeft() - view.getPaddingRight(); if (targetWidth <= 0) { return; } CharSequence text = view.getText(); TransformationMethod method = view.getTransformationMethod(); if (method != null) { text = method.getTransformation(text, view); } Context context = view.getContext(); Resources r = Resources.getSystem(); DisplayMetrics displayMetrics; float size = maxTextSize; float high = size; float low = 0; if (context != null) { r = context.getResources(); } displayMetrics = r.getDisplayMetrics(); paint.set(view.getPaint()); paint.setTextSize(size); if ((maxLines == 1 && paint.measureText(text, 0, text.length()) > targetWidth) || getLineCount(text, paint, size, targetWidth, displayMetrics) > maxLines) { size = getAutofitTextSize(text, paint, targetWidth, maxLines, low, high, precision, displayMetrics); } if (size < minTextSize) { size = minTextSize; } view.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); }
Example 4
Source File: AutofitHelper.java From stynico with MIT License | 4 votes |
/** * Re-sizes the textSize of the TextView so that the text fits within the bounds of the View. */ private static void autofit(AppCompatTextView view, TextPaint paint, float minTextSize, float maxTextSize, int maxLines, float precision) { if (maxLines <= 0 || maxLines == Integer.MAX_VALUE) { // Don't auto-size since there's no limit on lines. return; } int targetWidth = view.getWidth() - view.getPaddingLeft() - view.getPaddingRight(); if (targetWidth <= 0) { return; } CharSequence text = view.getText(); TransformationMethod method = view.getTransformationMethod(); if (method != null) { text = method.getTransformation(text, view); } Context context = view.getContext(); Resources r = Resources.getSystem(); DisplayMetrics displayMetrics; float size = maxTextSize; float high = size; float low = 0; if (context != null) { r = context.getResources(); } displayMetrics = r.getDisplayMetrics(); paint.set(view.getPaint()); paint.setTextSize(size); if ((maxLines == 1 && paint.measureText(text, 0, text.length()) > targetWidth) || getLineCount(text, paint, size, targetWidth, displayMetrics) > maxLines) { size = getAutofitTextSize(text, paint, targetWidth, maxLines, low, high, precision, displayMetrics); } if (size < minTextSize) { size = minTextSize; } view.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); }
Example 5
Source File: AutofitHelper.java From DarkCalculator with MIT License | 4 votes |
/** * Re-sizes the textSize of the TextView so that the text fits within the bounds of the View. */ private static void autofit(TextView view, TextPaint paint, float minTextSize, float maxTextSize, int maxLines, float precision) { if (maxLines <= 0 || maxLines == Integer.MAX_VALUE) { // Don't auto-size since there's no limit on lines. return; } int targetWidth = view.getWidth() - view.getPaddingLeft() - view.getPaddingRight(); if (targetWidth <= 0) { return; } CharSequence text = view.getText(); TransformationMethod method = view.getTransformationMethod(); if (method != null) { text = method.getTransformation(text, view); } Context context = view.getContext(); Resources r = Resources.getSystem(); DisplayMetrics displayMetrics; float size = maxTextSize; float high = size; float low = 0; if (context != null) { r = context.getResources(); } displayMetrics = r.getDisplayMetrics(); paint.set(view.getPaint()); paint.setTextSize(size); if ((maxLines == 1 && paint.measureText(text, 0, text.length()) > targetWidth) || getLineCount(text, paint, size, targetWidth, displayMetrics) > maxLines) { size = getAutofitTextSize(text, paint, targetWidth, maxLines, low, high, precision, displayMetrics); } if (size < minTextSize) { size = minTextSize; } view.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); }
Example 6
Source File: AutofitTextView.java From UltimateAndroid with Apache License 2.0 | 4 votes |
/** * Re size the font so the specified text fits in the text box assuming the text box is the * specified width. */ private void refitText() { if (!mSizeToFit) { return; } if (mMaxLines <= 0) { // Don't auto-size since there's no limit on lines. return; } CharSequence text = getText(); TransformationMethod method = getTransformationMethod(); if (method != null) { text = method.getTransformation(text, this); } int targetWidth = getWidth() - getPaddingLeft() - getPaddingRight(); if (targetWidth > 0) { Context context = getContext(); Resources r = Resources.getSystem(); DisplayMetrics displayMetrics; float size = mMaxTextSize; float high = size; float low = 0; if (context != null) { r = context.getResources(); } displayMetrics = r.getDisplayMetrics(); mPaint.set(getPaint()); mPaint.setTextSize(size); if ((mMaxLines == 1 && mPaint.measureText(text, 0, text.length()) > targetWidth) || getLineCount(text, mPaint, size, targetWidth, displayMetrics) > mMaxLines) { size = getTextSize(text, mPaint, targetWidth, mMaxLines, low, high, mPrecision, displayMetrics); } if (size < mMinTextSize) { size = mMinTextSize; } super.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); } }
Example 7
Source File: AutofitTextView.java From UltimateAndroid with Apache License 2.0 | 4 votes |
/** * Re size the font so the specified text fits in the text box assuming the text box is the * specified width. */ private void refitText() { if (!mSizeToFit) { return; } if (mMaxLines <= 0) { // Don't auto-size since there's no limit on lines. return; } CharSequence text = getText(); TransformationMethod method = getTransformationMethod(); if (method != null) { text = method.getTransformation(text, this); } int targetWidth = getWidth() - getPaddingLeft() - getPaddingRight(); if (targetWidth > 0) { Context context = getContext(); Resources r = Resources.getSystem(); DisplayMetrics displayMetrics; float size = mMaxTextSize; float high = size; float low = 0; if (context != null) { r = context.getResources(); } displayMetrics = r.getDisplayMetrics(); mPaint.set(getPaint()); mPaint.setTextSize(size); if ((mMaxLines == 1 && mPaint.measureText(text, 0, text.length()) > targetWidth) || getLineCount(text, mPaint, size, targetWidth, displayMetrics) > mMaxLines) { size = getTextSize(text, mPaint, targetWidth, mMaxLines, low, high, mPrecision, displayMetrics); } if (size < mMinTextSize) { size = mMinTextSize; } super.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); } }
Example 8
Source File: AutofitTextView.java From UltimateAndroid with Apache License 2.0 | 4 votes |
/** * Re size the font so the specified text fits in the text box assuming the text box is the * specified width. */ private void refitText() { if (!mSizeToFit) { return; } if (mMaxLines <= 0) { // Don't auto-size since there's no limit on lines. return; } CharSequence text = getText(); TransformationMethod method = getTransformationMethod(); if (method != null) { text = method.getTransformation(text, this); } int targetWidth = getWidth() - getPaddingLeft() - getPaddingRight(); if (targetWidth > 0) { Context context = getContext(); Resources r = Resources.getSystem(); DisplayMetrics displayMetrics; float size = mMaxTextSize; float high = size; float low = 0; if (context != null) { r = context.getResources(); } displayMetrics = r.getDisplayMetrics(); mPaint.set(getPaint()); mPaint.setTextSize(size); if ((mMaxLines == 1 && mPaint.measureText(text, 0, text.length()) > targetWidth) || getLineCount(text, mPaint, size, targetWidth, displayMetrics) > mMaxLines) { size = getTextSize(text, mPaint, targetWidth, mMaxLines, low, high, mPrecision, displayMetrics); } if (size < mMinTextSize) { size = mMinTextSize; } super.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); } }