Merge "assist: Fix reported colors/styles for TextView/Switch" into mnc-dev

This commit is contained in:
James Cook
2015-05-29 17:30:21 +00:00
committed by Android (Google) Code Review
7 changed files with 36 additions and 49 deletions

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -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

View File

@@ -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);
}

View File

@@ -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.
}
}

View File

@@ -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());
}