From 904fcdad411817fcd12c3e8b9e708b0c27bd6007 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Thu, 1 Mar 2018 14:29:34 -0800 Subject: [PATCH] Fix CTS TextViewTest Id65a7e36487375f0e3a2c2da44ad8d7c5ea49734 changes the typeface associated with the TextView. It used be null if no attribute was set, but after above change, it is now Typeface.DEFAULT. The typeface is null means Typeface.DEFAULT but there is an expectations in CTS that getTypeface must return null if no attribute was set. To keep this behavior, call setTypeface with null if no font weight value was set. Bug: 74080879 Test: atest CtsWidgetTestCases:EditTextTest CtsWidgetTestCases:TextViewFadingEdgeTest FrameworksCoreTests:TextViewFallbackLineSpacingTest FrameworksCoreTests:TextViewTest FrameworksCoreTests:TypefaceTest CtsGraphicsTestCases:TypefaceTest CtsWidgetTestCases:TextViewTest CtsTextTestCases FrameworksCoreTests:android.text Change-Id: Ic91827bbeed8a3a4b148dd8d305c78e384407ab0 --- core/java/android/widget/TextView.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 50e6393d2579..b482d4715d48 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -2025,7 +2025,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener final boolean italic = (style & Typeface.ITALIC) != 0; setTypeface(Typeface.create(typeface, weight, italic)); } else { - setTypeface(Typeface.create(typeface, style)); + setTypeface(typeface, style); } } @@ -2111,7 +2111,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener * @attr ref android.R.styleable#TextView_typeface * @attr ref android.R.styleable#TextView_textStyle */ - public void setTypeface(Typeface tf, int style) { + public void setTypeface(@Nullable Typeface tf, @Typeface.Style int style) { if (style > 0) { if (tf == null) { tf = Typeface.defaultFromStyle(style); @@ -3896,7 +3896,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener * @attr ref android.R.styleable#TextView_typeface * @attr ref android.R.styleable#TextView_textStyle */ - public void setTypeface(Typeface tf) { + public void setTypeface(@Nullable Typeface tf) { if (mTextPaint.getTypeface() != tf) { mTextPaint.setTypeface(tf); -- 2.11.0