diff options
| -rw-r--r-- | api/current.txt | 3 | ||||
| -rw-r--r-- | api/system-current.txt | 3 | ||||
| -rw-r--r-- | core/java/android/app/AssistStructure.java | 30 | ||||
| -rw-r--r-- | core/java/android/view/ViewStructure.java | 9 | ||||
| -rw-r--r-- | core/java/android/webkit/ViewAssistStructure.java | 7 | ||||
| -rw-r--r-- | core/java/android/widget/Switch.java | 4 | ||||
| -rw-r--r-- | core/java/android/widget/TextView.java | 29 |
7 files changed, 36 insertions, 49 deletions
diff --git a/api/current.txt b/api/current.txt index 39444bcf40d5..a2dfb85ebc28 100644 --- a/api/current.txt +++ b/api/current.txt @@ -36923,8 +36923,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); } diff --git a/api/system-current.txt b/api/system-current.txt index d75a9a08069d..a9c1f2aca341 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -39181,8 +39181,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); } diff --git a/core/java/android/app/AssistStructure.java b/core/java/android/app/AssistStructure.java index bb9cb3bf1b9b..ca47a5ebcef9 100644 --- a/core/java/android/app/AssistStructure.java +++ b/core/java/android/app/AssistStructure.java @@ -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; diff --git a/core/java/android/view/ViewStructure.java b/core/java/android/view/ViewStructure.java index 5c8b0230ab39..886547ac42e4 100644 --- a/core/java/android/view/ViewStructure.java +++ b/core/java/android/view/ViewStructure.java @@ -145,13 +145,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 diff --git a/core/java/android/webkit/ViewAssistStructure.java b/core/java/android/webkit/ViewAssistStructure.java index bbaceeee1c48..afa5ab817f1b 100644 --- a/core/java/android/webkit/ViewAssistStructure.java +++ b/core/java/android/webkit/ViewAssistStructure.java @@ -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); } diff --git a/core/java/android/widget/Switch.java b/core/java/android/widget/Switch.java index f42959ffe28f..49226cd0fff6 100644 --- a/core/java/android/widget/Switch.java +++ b/core/java/android/widget/Switch.java @@ -1374,7 +1374,9 @@ public class Switch extends CompoundButton { newText.append(oldText).append(' ').append(switchText); structure.setText(newText); } - structure.setTextPaint(mTextPaint); + // The style of the label text is provided via the base TextView class. This is more + // relevant than the style of the (optional) on/off text on the switch button itself, + // so ignore the size/color/style stored this.mTextPaint. } } diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 9de77782eb95..15d796c46b07 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -25,6 +25,7 @@ import android.annotation.StringRes; import android.annotation.StyleRes; import android.annotation.XmlRes; import android.app.Activity; +import android.app.AssistStructure; import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; @@ -8785,7 +8786,33 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener final boolean isPassword = hasPasswordTransformationMethod(); if (!isPassword) { structure.setText(getText(), getSelectionStart(), getSelectionEnd()); - structure.setTextPaint(mTextPaint); + + // Extract style information that applies to the TextView as a whole. + int style = 0; + int typefaceStyle = getTypefaceStyle(); + if ((typefaceStyle & Typeface.BOLD) != 0) { + style |= AssistStructure.ViewNode.TEXT_STYLE_BOLD; + } + if ((typefaceStyle & Typeface.ITALIC) != 0) { + style |= AssistStructure.ViewNode.TEXT_STYLE_ITALIC; + } + + // Global styles can also be set via TextView.setPaintFlags(). + int paintFlags = mTextPaint.getFlags(); + if ((paintFlags & Paint.FAKE_BOLD_TEXT_FLAG) != 0) { + style |= AssistStructure.ViewNode.TEXT_STYLE_BOLD; + } + if ((paintFlags & Paint.UNDERLINE_TEXT_FLAG) != 0) { + style |= AssistStructure.ViewNode.TEXT_STYLE_UNDERLINE; + } + if ((paintFlags & Paint.STRIKE_THRU_TEXT_FLAG) != 0) { + style |= AssistStructure.ViewNode.TEXT_STYLE_STRIKE_THRU; + } + + // TextView does not have its own text background color. A background is either part + // of the View (and can be any drawable) or a BackgroundColorSpan inside the text. + structure.setTextStyle(getTextSize(), getCurrentTextColor(), + AssistStructure.ViewNode.TEXT_COLOR_UNDEFINED /* bgColor */, style); } structure.setHint(getHint()); } |