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

Commit dfd366ed authored by Sally Yuen's avatar Sally Yuen Committed by Android (Google) Code Review
Browse files

Merge "Add support for Force Bold Text"

parents 22b7c8fc 5670baef
Loading
Loading
Loading
Loading
+23 −1
Original line number Diff line number Diff line
@@ -741,6 +741,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
    private boolean mLocalesChanged = false;
    private int mTextSizeUnit = -1;
    // True if force bold text feature is enabled. This feature makes all text bolder.
    private boolean mForceBoldTextEnabled;
    private Typeface mOriginalTypeface;
    // True if setKeyListener() has been explicitly called
    private boolean mListenerChanged = false;
    // True if internationalized input should be used for numbers and date and time.
@@ -1649,6 +1653,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
            attributes.mTypefaceIndex = MONOSPACE;
        }
        mForceBoldTextEnabled = getContext().getResources().getConfiguration().forceBoldText
                == Configuration.FORCE_BOLD_TEXT_YES;
        applyTextAppearance(attributes);
        if (isPassword) {
@@ -4276,6 +4282,14 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                invalidate();
            }
        }
        if (newConfig.forceBoldText == Configuration.FORCE_BOLD_TEXT_YES) {
            mForceBoldTextEnabled = true;
            setTypeface(getTypeface());
        } else  if (newConfig.forceBoldText == Configuration.FORCE_BOLD_TEXT_NO
                || newConfig.forceBoldText == Configuration.FORCE_BOLD_TEXT_UNDEFINED) {
            mForceBoldTextEnabled = false;
            setTypeface(getTypeface());
        }
    }
    /**
@@ -4427,6 +4441,14 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
     * @attr ref android.R.styleable#TextView_textStyle
     */
    public void setTypeface(@Nullable Typeface tf) {
        mOriginalTypeface = tf;
        if (mForceBoldTextEnabled) {
            int newWeight = tf != null ? tf.getWeight() + 300 : 400;
            newWeight = Math.min(newWeight, 1000);
            int typefaceStyle = tf != null ? tf.getStyle() : 0;
            boolean italic = (typefaceStyle & Typeface.ITALIC) != 0;
            tf = Typeface.create(tf, newWeight, italic);
        }
        if (mTextPaint.getTypeface() != tf) {
            mTextPaint.setTypeface(tf);
@@ -4450,7 +4472,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
     */
    @InspectableProperty
    public Typeface getTypeface() {
        return mTextPaint.getTypeface();
        return mOriginalTypeface;
    }
    /**