Java Code Examples for android.text.TextPaint#setTextScaleX()

The following examples show how to use android.text.TextPaint#setTextScaleX() . 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: SuggestionStripLayoutHelper.java    From openboard with GNU General Public License v3.0 5 votes vote down vote up
private static float getTextScaleX(@Nullable final CharSequence text, final int maxWidth,
        final TextPaint paint) {
    paint.setTextScaleX(1.0f);
    final int width = getTextWidth(text, paint);
    if (width <= maxWidth || maxWidth <= 0) {
        return 1.0f;
    }
    return maxWidth / (float) width;
}
 
Example 2
Source File: SuggestionStripLayoutHelper.java    From openboard with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
private static CharSequence getEllipsizedTextWithSettingScaleX(
        @Nullable final CharSequence text, final int maxWidth, @Nonnull final TextPaint paint) {
    if (text == null) {
        return null;
    }
    final float scaleX = getTextScaleX(text, maxWidth, paint);
    if (scaleX >= MIN_TEXT_XSCALE) {
        paint.setTextScaleX(scaleX);
        return text;
    }

    // <code>text</code> must be ellipsized with minimum text scale x.
    paint.setTextScaleX(MIN_TEXT_XSCALE);
    final boolean hasBoldStyle = hasStyleSpan(text, BOLD_SPAN);
    final boolean hasUnderlineStyle = hasStyleSpan(text, UNDERLINE_SPAN);
    // TextUtils.ellipsize erases any span object existed after ellipsized point.
    // We have to restore these spans afterward.
    final CharSequence ellipsizedText = TextUtils.ellipsize(
            text, paint, maxWidth, TextUtils.TruncateAt.MIDDLE);
    if (!hasBoldStyle && !hasUnderlineStyle) {
        return ellipsizedText;
    }
    final Spannable spannableText = (ellipsizedText instanceof Spannable)
            ? (Spannable)ellipsizedText : new SpannableString(ellipsizedText);
    if (hasBoldStyle) {
        addStyleSpan(spannableText, BOLD_SPAN);
    }
    if (hasUnderlineStyle) {
        addStyleSpan(spannableText, UNDERLINE_SPAN);
    }
    return spannableText;
}
 
Example 3
Source File: SuggestionStripLayoutHelper.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
private static float getTextScaleX(@Nullable final CharSequence text, final int maxWidth,
        final TextPaint paint) {
    paint.setTextScaleX(1.0f);
    final int width = getTextWidth(text, paint);
    if (width <= maxWidth || maxWidth <= 0) {
        return 1.0f;
    }
    return maxWidth / (float) width;
}
 
Example 4
Source File: SuggestionStripLayoutHelper.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
@Nullable
private static CharSequence getEllipsizedTextWithSettingScaleX(
        @Nullable final CharSequence text, final int maxWidth, @Nonnull final TextPaint paint) {
    if (text == null) {
        return null;
    }
    final float scaleX = getTextScaleX(text, maxWidth, paint);
    if (scaleX >= MIN_TEXT_XSCALE) {
        paint.setTextScaleX(scaleX);
        return text;
    }

    // <code>text</code> must be ellipsized with minimum text scale x.
    paint.setTextScaleX(MIN_TEXT_XSCALE);
    final boolean hasBoldStyle = hasStyleSpan(text, BOLD_SPAN);
    final boolean hasUnderlineStyle = hasStyleSpan(text, UNDERLINE_SPAN);
    // TextUtils.ellipsize erases any span object existed after ellipsized point.
    // We have to restore these spans afterward.
    final CharSequence ellipsizedText = TextUtils.ellipsize(
            text, paint, maxWidth, TextUtils.TruncateAt.MIDDLE);
    if (!hasBoldStyle && !hasUnderlineStyle) {
        return ellipsizedText;
    }
    final Spannable spannableText = (ellipsizedText instanceof Spannable)
            ? (Spannable)ellipsizedText : new SpannableString(ellipsizedText);
    if (hasBoldStyle) {
        addStyleSpan(spannableText, BOLD_SPAN);
    }
    if (hasUnderlineStyle) {
        addStyleSpan(spannableText, UNDERLINE_SPAN);
    }
    return spannableText;
}
 
Example 5
Source File: SuggestionStripLayoutHelper.java    From Indic-Keyboard with Apache License 2.0 5 votes vote down vote up
private static float getTextScaleX(@Nullable final CharSequence text, final int maxWidth,
        final TextPaint paint) {
    paint.setTextScaleX(1.0f);
    final int width = getTextWidth(text, paint);
    if (width <= maxWidth || maxWidth <= 0) {
        return 1.0f;
    }
    return maxWidth / (float) width;
}
 
Example 6
Source File: SuggestionStripLayoutHelper.java    From Indic-Keyboard with Apache License 2.0 5 votes vote down vote up
@Nullable
private static CharSequence getEllipsizedTextWithSettingScaleX(
        @Nullable final CharSequence text, final int maxWidth, @Nonnull final TextPaint paint) {
    if (text == null) {
        return null;
    }
    final float scaleX = getTextScaleX(text, maxWidth, paint);
    if (scaleX >= MIN_TEXT_XSCALE) {
        paint.setTextScaleX(scaleX);
        return text;
    }

    // <code>text</code> must be ellipsized with minimum text scale x.
    paint.setTextScaleX(MIN_TEXT_XSCALE);
    final boolean hasBoldStyle = hasStyleSpan(text, BOLD_SPAN);
    final boolean hasUnderlineStyle = hasStyleSpan(text, UNDERLINE_SPAN);
    // TextUtils.ellipsize erases any span object existed after ellipsized point.
    // We have to restore these spans afterward.
    final CharSequence ellipsizedText = TextUtils.ellipsize(
            text, paint, maxWidth, TextUtils.TruncateAt.MIDDLE);
    if (!hasBoldStyle && !hasUnderlineStyle) {
        return ellipsizedText;
    }
    final Spannable spannableText = (ellipsizedText instanceof Spannable)
            ? (Spannable)ellipsizedText : new SpannableString(ellipsizedText);
    if (hasBoldStyle) {
        addStyleSpan(spannableText, BOLD_SPAN);
    }
    if (hasUnderlineStyle) {
        addStyleSpan(spannableText, UNDERLINE_SPAN);
    }
    return spannableText;
}
 
Example 7
Source File: ScaleXSpan.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public void updateDrawState(TextPaint ds) {
    ds.setTextScaleX(ds.getTextScaleX() * mProportion);
}
 
Example 8
Source File: ScaleXSpan.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public void updateMeasureState(TextPaint ds) {
    ds.setTextScaleX(ds.getTextScaleX() * mProportion);
}
 
Example 9
Source File: ScaleXSpan.java    From PowerFileExplorer with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void updateDrawState(TextPaint ds) {
	ds.setTextScaleX(ds.getTextScaleX() * mProportion);
}
 
Example 10
Source File: ScaleXSpan.java    From PowerFileExplorer with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void updateMeasureState(TextPaint ds) {
	ds.setTextScaleX(ds.getTextScaleX() * mProportion);
}
 
Example 11
Source File: ScaleXSpan.java    From JotaTextEditor with Apache License 2.0 4 votes vote down vote up
@Override
public void updateDrawState(TextPaint ds) {
	ds.setTextScaleX(ds.getTextScaleX() * mProportion);
}
 
Example 12
Source File: ScaleXSpan.java    From JotaTextEditor with Apache License 2.0 4 votes vote down vote up
@Override
public void updateMeasureState(TextPaint ds) {
	ds.setTextScaleX(ds.getTextScaleX() * mProportion);
}
 
Example 13
Source File: Justify.java    From justified with Apache License 2.0 4 votes vote down vote up
@Override
public void updateDrawState(final @NotNull TextPaint ds) {
  ds.setTextScaleX(ds.getTextScaleX() * mProportion);
}
 
Example 14
Source File: Justify.java    From justified with Apache License 2.0 4 votes vote down vote up
@Override
public void updateMeasureState(final @NotNull TextPaint ds) {
  ds.setTextScaleX(ds.getTextScaleX() * mProportion);
}