Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1456f29a authored by czq's avatar czq
Browse files

Fix TextAppearanceInfo related APIs

1. Add a builder for TextAppearanceInfo, remove the constructor using TextView.
2. Remove maxLength attribute, add shadowColor.
3. Replace -1 with FontStyle.FONT_WEIGHT_UNSPECIFIED for textFontWeight.

Bug: 256995042

Test: atest android.view.inputmethod.cts.CursorAnchorInfoTest#testBuilder
atest android.view.inputmethod.cts.CursorAnchorInfoTest#testEquality
atest android.view.inputmethod.cts.CursorAnchorInfoTest#testTextAppearanceInfoWithEmptyEditText
atest android.view.inputmethod.cts.InputMethodServiceTest#testOnUpdateCursorAnchorInfo

Change-Id: I80faea43e6a96110171f61e18a6d744e719bdf58
parent 2111954a
Loading
Loading
Loading
Loading
+33 −7
Original line number Diff line number Diff line
@@ -53961,23 +53961,22 @@ package android.view.inputmethod {
  }
  public final class TextAppearanceInfo implements android.os.Parcelable {
    ctor public TextAppearanceInfo(@NonNull android.widget.TextView);
    method public int describeContents();
    method @Nullable public String getFontFamilyName();
    method @Nullable public String getFontFeatureSettings();
    method @Nullable public String getFontVariationSettings();
    method @ColorInt public int getHighlightTextColor();
    method @ColorInt public int getHintTextColor();
    method public float getLetterSpacing();
    method public int getLineBreakStyle();
    method public int getLineBreakWordStyle();
    method public int getMaxLength();
    method @ColorInt public int getLinkTextColor();
    method @ColorInt public int getShadowColor();
    method @Px public float getShadowDx();
    method @Px public float getShadowDy();
    method @Px public float getShadowRadius();
    method @Nullable public String getSystemFontFamilyName();
    method @ColorInt public int getTextColor();
    method @ColorInt public int getTextColorHighlight();
    method @ColorInt public int getTextColorHint();
    method @Nullable public android.content.res.ColorStateList getTextColorLink();
    method @IntRange(from=0xffffffff, to=android.graphics.fonts.FontStyle.FONT_WEIGHT_MAX) public int getTextFontWeight();
    method @IntRange(from=android.graphics.fonts.FontStyle.FONT_WEIGHT_UNSPECIFIED, to=android.graphics.fonts.FontStyle.FONT_WEIGHT_MAX) public int getTextFontWeight();
    method @NonNull public android.os.LocaleList getTextLocales();
    method public float getTextScaleX();
    method @Px public float getTextSize();
@@ -53989,6 +53988,33 @@ package android.view.inputmethod {
    field @NonNull public static final android.os.Parcelable.Creator<android.view.inputmethod.TextAppearanceInfo> CREATOR;
  }
  public static final class TextAppearanceInfo.Builder {
    ctor public TextAppearanceInfo.Builder();
    method @NonNull public android.view.inputmethod.TextAppearanceInfo build();
    method @NonNull public android.view.inputmethod.TextAppearanceInfo.Builder setAllCaps(boolean);
    method @NonNull public android.view.inputmethod.TextAppearanceInfo.Builder setElegantTextHeight(boolean);
    method @NonNull public android.view.inputmethod.TextAppearanceInfo.Builder setFallbackLineSpacing(boolean);
    method @NonNull public android.view.inputmethod.TextAppearanceInfo.Builder setFontFeatureSettings(@Nullable String);
    method @NonNull public android.view.inputmethod.TextAppearanceInfo.Builder setFontVariationSettings(@Nullable String);
    method @NonNull public android.view.inputmethod.TextAppearanceInfo.Builder setHighlightTextColor(@ColorInt int);
    method @NonNull public android.view.inputmethod.TextAppearanceInfo.Builder setHintTextColor(@ColorInt int);
    method @NonNull public android.view.inputmethod.TextAppearanceInfo.Builder setLetterSpacing(float);
    method @NonNull public android.view.inputmethod.TextAppearanceInfo.Builder setLineBreakStyle(int);
    method @NonNull public android.view.inputmethod.TextAppearanceInfo.Builder setLineBreakWordStyle(int);
    method @NonNull public android.view.inputmethod.TextAppearanceInfo.Builder setLinkTextColor(@ColorInt int);
    method @NonNull public android.view.inputmethod.TextAppearanceInfo.Builder setShadowColor(@ColorInt int);
    method @NonNull public android.view.inputmethod.TextAppearanceInfo.Builder setShadowDx(@Px float);
    method @NonNull public android.view.inputmethod.TextAppearanceInfo.Builder setShadowDy(@Px float);
    method @NonNull public android.view.inputmethod.TextAppearanceInfo.Builder setShadowRadius(@Px float);
    method @NonNull public android.view.inputmethod.TextAppearanceInfo.Builder setSystemFontFamilyName(@Nullable String);
    method @NonNull public android.view.inputmethod.TextAppearanceInfo.Builder setTextColor(@ColorInt int);
    method @NonNull public android.view.inputmethod.TextAppearanceInfo.Builder setTextFontWeight(@IntRange(from=android.graphics.fonts.FontStyle.FONT_WEIGHT_UNSPECIFIED, to=android.graphics.fonts.FontStyle.FONT_WEIGHT_MAX) int);
    method @NonNull public android.view.inputmethod.TextAppearanceInfo.Builder setTextLocales(@NonNull android.os.LocaleList);
    method @NonNull public android.view.inputmethod.TextAppearanceInfo.Builder setTextScaleX(float);
    method @NonNull public android.view.inputmethod.TextAppearanceInfo.Builder setTextSize(@Px float);
    method @NonNull public android.view.inputmethod.TextAppearanceInfo.Builder setTextStyle(int);
  }
  public final class TextAttribute implements android.os.Parcelable {
    method public int describeContents();
    method @NonNull public android.os.PersistableBundle getExtras();
+403 −114

File changed.

Preview size limit exceeded, changes collapsed.

+39 −2
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.widget.TextView.ACCESSIBILITY_ACTION_SMART_START_ID;

import android.R;
import android.animation.ValueAnimator;
import android.annotation.ColorInt;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -37,6 +38,7 @@ import android.content.UndoOperation;
import android.content.UndoOwner;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
@@ -49,8 +51,10 @@ import android.graphics.RecordingCanvas;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.RenderNode;
import android.graphics.Typeface;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.fonts.FontStyle;
import android.os.Build;
import android.os.Bundle;
import android.os.LocaleList;
@@ -4762,8 +4766,41 @@ public class Editor {
            }

            if (includeTextAppearance) {
                TextAppearanceInfo textAppearanceInfo = new TextAppearanceInfo(mTextView);
                builder.setTextAppearanceInfo(textAppearanceInfo);
                Typeface typeface = mTextView.getPaint().getTypeface();
                String systemFontFamilyName = null;
                int textFontWeight = FontStyle.FONT_WEIGHT_UNSPECIFIED;
                if (typeface != null) {
                    systemFontFamilyName = typeface.getSystemFontFamilyName();
                    textFontWeight = typeface.getWeight();
                }
                ColorStateList linkTextColors = mTextView.getLinkTextColors();
                @ColorInt int linkTextColor = linkTextColors != null
                        ? linkTextColors.getDefaultColor() : 0;

                TextAppearanceInfo.Builder appearanceBuilder = new TextAppearanceInfo.Builder();
                appearanceBuilder.setTextSize(mTextView.getTextSize())
                        .setTextLocales(mTextView.getTextLocales())
                        .setSystemFontFamilyName(systemFontFamilyName)
                        .setTextFontWeight(textFontWeight)
                        .setTextStyle(mTextView.getTypefaceStyle())
                        .setAllCaps(mTextView.isAllCaps())
                        .setShadowDx(mTextView.getShadowDx())
                        .setShadowDy(mTextView.getShadowDy())
                        .setShadowRadius(mTextView.getShadowRadius())
                        .setShadowColor(mTextView.getShadowColor())
                        .setElegantTextHeight(mTextView.isElegantTextHeight())
                        .setFallbackLineSpacing(mTextView.isFallbackLineSpacing())
                        .setLetterSpacing(mTextView.getLetterSpacing())
                        .setFontFeatureSettings(mTextView.getFontFeatureSettings())
                        .setFontVariationSettings(mTextView.getFontVariationSettings())
                        .setLineBreakStyle(mTextView.getLineBreakStyle())
                        .setLineBreakWordStyle(mTextView.getLineBreakWordStyle())
                        .setTextScaleX(mTextView.getTextScaleX())
                        .setHighlightTextColor(mTextView.getHighlightColor())
                        .setTextColor(mTextView.getCurrentTextColor())
                        .setHintTextColor(mTextView.getCurrentHintTextColor())
                        .setLinkTextColor(linkTextColor);
                builder.setTextAppearanceInfo(appearanceBuilder.build());
            }
            imm.updateCursorAnchorInfo(mTextView, builder.build());