Merge "Throw an exception in case of parameter mismatch of precomputed text" into pi-dev
am: a4d970ea40
Change-Id: I588313c38683f0fcd003f77e909e23d6b3df83ce
This commit is contained in:
@@ -211,7 +211,8 @@ public class PrecomputedText implements Spanned {
|
|||||||
return mHyphenationFrequency;
|
return mHyphenationFrequency;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isSameTextMetricsInternal(@NonNull TextPaint paint,
|
/** @hide */
|
||||||
|
public boolean isSameTextMetricsInternal(@NonNull TextPaint paint,
|
||||||
@NonNull TextDirectionHeuristic textDir, @Layout.BreakStrategy int strategy,
|
@NonNull TextDirectionHeuristic textDir, @Layout.BreakStrategy int strategy,
|
||||||
@Layout.HyphenationFrequency int frequency) {
|
@Layout.HyphenationFrequency int frequency) {
|
||||||
return mTextDir == textDir
|
return mTextDir == textDir
|
||||||
@@ -247,6 +248,23 @@ public class PrecomputedText implements Spanned {
|
|||||||
mPaint.getFontVariationSettings(), mPaint.isElegantTextHeight(), mTextDir,
|
mPaint.getFontVariationSettings(), mPaint.isElegantTextHeight(), mTextDir,
|
||||||
mBreakStrategy, mHyphenationFrequency);
|
mBreakStrategy, mHyphenationFrequency);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "{"
|
||||||
|
+ "textSize=" + mPaint.getTextSize()
|
||||||
|
+ ", textScaleX=" + mPaint.getTextScaleX()
|
||||||
|
+ ", textSkewX=" + mPaint.getTextSkewX()
|
||||||
|
+ ", letterSpacing=" + mPaint.getLetterSpacing()
|
||||||
|
+ ", textLocale=" + mPaint.getTextLocales()
|
||||||
|
+ ", typeface=" + mPaint.getTypeface()
|
||||||
|
+ ", variationSettings=" + mPaint.getFontVariationSettings()
|
||||||
|
+ ", elegantTextHeight=" + mPaint.isElegantTextHeight()
|
||||||
|
+ ", textDir=" + mTextDir
|
||||||
|
+ ", breakStrategy=" + mBreakStrategy
|
||||||
|
+ ", hyphenationFrequency=" + mHyphenationFrequency
|
||||||
|
+ "}";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// The original text.
|
// The original text.
|
||||||
|
|||||||
@@ -4141,6 +4141,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
*/
|
*/
|
||||||
public void setTextMetricsParams(@NonNull PrecomputedText.Params params) {
|
public void setTextMetricsParams(@NonNull PrecomputedText.Params params) {
|
||||||
mTextPaint.set(params.getTextPaint());
|
mTextPaint.set(params.getTextPaint());
|
||||||
|
mUserSetTextScaleX = true;
|
||||||
mTextDir = params.getTextDirection();
|
mTextDir = params.getTextDirection();
|
||||||
mBreakStrategy = params.getBreakStrategy();
|
mBreakStrategy = params.getBreakStrategy();
|
||||||
mHyphenationFrequency = params.getHyphenationFrequency();
|
mHyphenationFrequency = params.getHyphenationFrequency();
|
||||||
@@ -5528,9 +5529,16 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
* {@link android.text.Editable.Factory} to create final or intermediate
|
* {@link android.text.Editable.Factory} to create final or intermediate
|
||||||
* {@link Editable Editables}.
|
* {@link Editable Editables}.
|
||||||
*
|
*
|
||||||
|
* If the passed text is a {@link PrecomputedText} but the parameters used to create the
|
||||||
|
* PrecomputedText mismatches with this TextView, IllegalArgumentException is thrown. To ensure
|
||||||
|
* the parameters match, you can call {@link TextView#setTextMetricsParams} before calling this.
|
||||||
|
*
|
||||||
* @param text text to be displayed
|
* @param text text to be displayed
|
||||||
*
|
*
|
||||||
* @attr ref android.R.styleable#TextView_text
|
* @attr ref android.R.styleable#TextView_text
|
||||||
|
* @throws IllegalArgumentException if the passed text is a {@link PrecomputedText} but the
|
||||||
|
* parameters used to create the PrecomputedText mismatches
|
||||||
|
* with this TextView.
|
||||||
*/
|
*/
|
||||||
@android.view.RemotableViewMethod
|
@android.view.RemotableViewMethod
|
||||||
public final void setText(CharSequence text) {
|
public final void setText(CharSequence text) {
|
||||||
@@ -5644,7 +5652,21 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
if (imm != null) imm.restartInput(this);
|
if (imm != null) imm.restartInput(this);
|
||||||
} else if (type == BufferType.SPANNABLE || mMovement != null) {
|
} else if (type == BufferType.SPANNABLE || mMovement != null) {
|
||||||
text = mSpannableFactory.newSpannable(text);
|
text = mSpannableFactory.newSpannable(text);
|
||||||
} else if (!(text instanceof PrecomputedText || text instanceof CharWrapper)) {
|
} else if (text instanceof PrecomputedText) {
|
||||||
|
PrecomputedText precomputed = (PrecomputedText) text;
|
||||||
|
if (mTextDir == null) {
|
||||||
|
mTextDir = getTextDirectionHeuristic();
|
||||||
|
}
|
||||||
|
if (!precomputed.getParams().isSameTextMetricsInternal(
|
||||||
|
getPaint(), mTextDir, mBreakStrategy, mHyphenationFrequency)) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"PrecomputedText's Parameters don't match the parameters of this TextView."
|
||||||
|
+ "Consider using setTextMetricsParams(precomputedText.getParams()) "
|
||||||
|
+ "to override the settings of this TextView: "
|
||||||
|
+ "PrecomputedText: " + precomputed.getParams()
|
||||||
|
+ "TextView: " + getTextMetricsParams());
|
||||||
|
}
|
||||||
|
} else if (!(text instanceof CharWrapper)) {
|
||||||
text = TextUtils.stringOrSpannedString(text);
|
text = TextUtils.stringOrSpannedString(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user