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

Commit 5cfaae4a authored by James Cook's avatar James Cook
Browse files

assist: Fix reported colors/styles for TextView/Switch

Changes to the data provided to AssistStructure:
* Text foreground color is correct even if the view has not yet been
painted.
* Text background color is now always 1 (TEXT_COLOR_UNDEFINED) for a
TextView, as it has no separate concept of background color.
* Switch now reports the text size/color/style of the label text
(usually user visible) rather than the on/off text on the button
itself (usually hidden in Material, and not usually revelant when
visible).

Bug: 21080375
Change-Id: I7e15f68d89510a76cab76031c2c8ca6ca3f32435
parent f981ea95
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -36911,8 +36911,7 @@ package android.view {
    method public abstract void setStylusButtonPressable(boolean);
    method public abstract void setText(java.lang.CharSequence);
    method public abstract void setText(java.lang.CharSequence, int, int);
    method public abstract void setTextPaint(android.text.TextPaint);
    method public abstract void setTextStyle(int, int, int, int);
    method public abstract void setTextStyle(float, int, int, int);
    method public abstract void setVisibility(int);
  }
+1 −2
Original line number Diff line number Diff line
@@ -39170,8 +39170,7 @@ package android.view {
    method public abstract void setStylusButtonPressable(boolean);
    method public abstract void setText(java.lang.CharSequence);
    method public abstract void setText(java.lang.CharSequence, int, int);
    method public abstract void setTextPaint(android.text.TextPaint);
    method public abstract void setTextStyle(int, int, int, int);
    method public abstract void setTextStyle(float, int, int, int);
    method public abstract void setVisibility(int);
  }
+1 −29
Original line number Diff line number Diff line
@@ -607,35 +607,7 @@ final public class AssistStructure implements Parcelable {
        }

        @Override
        public void setTextPaint(TextPaint paint) {
            ViewNodeText t = getNodeText();
            t.mTextColor = paint.getColor();
            t.mTextBackgroundColor = paint.bgColor;
            t.mTextSize = paint.getTextSize();
            t.mTextStyle = 0;
            Typeface tf = paint.getTypeface();
            if (tf != null) {
                if (tf.isBold()) {
                    t.mTextStyle |= ViewNode.TEXT_STYLE_BOLD;
                }
                if (tf.isItalic()) {
                    t.mTextStyle |= ViewNode.TEXT_STYLE_ITALIC;
                }
            }
            int pflags = paint.getFlags();
            if ((pflags& Paint.FAKE_BOLD_TEXT_FLAG) != 0) {
                t.mTextStyle |= ViewNode.TEXT_STYLE_BOLD;
            }
            if ((pflags& Paint.UNDERLINE_TEXT_FLAG) != 0) {
                t.mTextStyle |= ViewNode.TEXT_STYLE_UNDERLINE;
            }
            if ((pflags& Paint.STRIKE_THRU_TEXT_FLAG) != 0) {
                t.mTextStyle |= ViewNode.TEXT_STYLE_STRIKE_THRU;
            }
        }

        @Override
        public void setTextStyle(int size, int fgColor, int bgColor, int style) {
        public void setTextStyle(float size, int fgColor, int bgColor, int style) {
            ViewNodeText t = getNodeText();
            t.mTextColor = fgColor;
            t.mTextBackgroundColor = bgColor;
+1 −8
Original line number Diff line number Diff line
@@ -144,13 +144,6 @@ public abstract class ViewStructure {
     */
    public abstract void setText(CharSequence text, int selectionStart, int selectionEnd);

    /**
     * Set default global style of the text previously set with
     * {@link #setText}, derived from the given TextPaint object.  Size, foreground color,
     * background color, and style information will be extracted from the paint.
     */
    public abstract void setTextPaint(TextPaint paint);

    /**
     * Explicitly set default global style information for text that was previously set with
     * {@link #setText}.
@@ -160,7 +153,7 @@ public abstract class ViewStructure {
     * @param bgColor The background color, packed as 0xAARRGGBB.
     * @param style Style flags, as defined by {@link android.app.AssistStructure.ViewNode}.
     */
    public abstract void setTextStyle(int size, int fgColor, int bgColor, int style);
    public abstract void setTextStyle(float size, int fgColor, int bgColor, int style);

    /**
     * Set optional hint text associated with this view; this is for example the text that is
+1 −6
Original line number Diff line number Diff line
@@ -132,12 +132,7 @@ public class ViewAssistStructure extends android.view.ViewAssistStructure {
    }

    @Override
    public  void setTextPaint(TextPaint paint) {
        mV.setTextPaint(paint);
    }

    @Override
    public void setTextStyle(int size, int fgColor, int bgColor, int style) {
    public void setTextStyle(float size, int fgColor, int bgColor, int style) {
        mV.setTextStyle(size, fgColor, bgColor, style);
    }

Loading