From 585a074ae50a2122e6637cebcfe2ca5e45eea36f Mon Sep 17 00:00:00 2001 From: afohrman Date: Fri, 29 Sep 2017 14:53:17 -0400 Subject: [PATCH] Automated g4 rollback of changelist 170486018 PiperOrigin-RevId: 170512542 --- .../design/widget/CollapsingTextHelper.java | 27 ------------------- .../design/widget/TextInputLayout.java | 22 +++++++-------- 2 files changed, 10 insertions(+), 39 deletions(-) diff --git a/lib/src/android/support/design/widget/CollapsingTextHelper.java b/lib/src/android/support/design/widget/CollapsingTextHelper.java index 702b665a6..58e9a1e0b 100644 --- a/lib/src/android/support/design/widget/CollapsingTextHelper.java +++ b/lib/src/android/support/design/widget/CollapsingTextHelper.java @@ -99,7 +99,6 @@ final class CollapsingTextHelper { private boolean mBoundsChanged; private final TextPaint mTextPaint; - private final TextPaint mTmpPaint; private TimeInterpolator mPositionInterpolator; private TimeInterpolator mTextSizeInterpolator; @@ -118,7 +117,6 @@ final class CollapsingTextHelper { mView = view; mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); - mTmpPaint = new TextPaint(mTextPaint); mCollapsedBounds = new Rect(); mExpandedBounds = new Rect(); @@ -179,31 +177,6 @@ final class CollapsingTextHelper { } } - float calculateCollapsedTextWidth() { - if (mTextToDraw == null) { - return 0; - } - getTextPaintCollapsed(mTmpPaint); - return mTmpPaint.measureText(mTextToDraw, 0, mTextToDraw.length()); - } - - float getCollapsedTextHeight() { - getTextPaintCollapsed(mTmpPaint); - return mTmpPaint.descent() - mTmpPaint.ascent(); - } - - void getCollapsedTextActualBounds(RectF bounds) { - bounds.left = mCollapsedBounds.left; - bounds.top = mCollapsedBounds.top; - bounds.right = bounds.left + calculateCollapsedTextWidth(); - bounds.bottom = mCollapsedBounds.top + getCollapsedTextHeight(); - } - - private void getTextPaintCollapsed(TextPaint textPaint) { - textPaint.setTextSize(mCollapsedTextSize); - textPaint.setTypeface(mCollapsedTypeface); - } - void onBoundsChanged() { mDrawTitle = mCollapsedBounds.width() > 0 diff --git a/lib/src/android/support/design/widget/TextInputLayout.java b/lib/src/android/support/design/widget/TextInputLayout.java index 93cb41065..28ee97e53 100644 --- a/lib/src/android/support/design/widget/TextInputLayout.java +++ b/lib/src/android/support/design/widget/TextInputLayout.java @@ -23,6 +23,7 @@ import android.content.Context; import android.content.res.ColorStateList; import android.graphics.Canvas; import android.graphics.Color; +import android.graphics.Paint; import android.graphics.PorterDuff; import android.graphics.Rect; import android.graphics.Typeface; @@ -165,6 +166,7 @@ public class TextInputLayout extends LinearLayout { public static final int BOX_BACKGROUND_FILLED = 1; public static final int BOX_BACKGROUND_OUTLINE = 2; + private Paint mTmpPaint; private final Rect mTmpRect = new Rect(); private Typeface mTypeface; @@ -348,23 +350,17 @@ public class TextInputLayout extends LinearLayout { private void onApplyBoxBackgroundMode() { if (mBoxBackgroundMode == BOX_BACKGROUND_NONE) { mBoxBackground = null; + return; } if (mBoxBackground == null) { mBoxBackground = new GradientDrawable(); } - - if (mBoxBackgroundMode != BOX_BACKGROUND_NONE) { - updateInputLayoutMargins(); - } updateTextInputBoxBounds(); setEditTextBoxPadding(); } private void setEditTextBoxPadding() { - if (mBoxBackgroundMode == BOX_BACKGROUND_NONE) { - return; - } // Set box padding on the edit text. if (mEditText != null) { mEditText.setPadding( @@ -568,7 +564,12 @@ public class TextInputLayout extends LinearLayout { final int newTopMargin; if (mHintEnabled) { - newTopMargin = (int) mCollapsingTextHelper.getCollapsedTextHeight(); + if (mTmpPaint == null) { + mTmpPaint = new Paint(); + } + mTmpPaint.setTypeface(mCollapsingTextHelper.getCollapsedTypeface()); + mTmpPaint.setTextSize(mCollapsingTextHelper.getCollapsedTextSize()); + newTopMargin = (int) -mTmpPaint.ascent(); } else { newTopMargin = 0; } @@ -965,10 +966,7 @@ public class TextInputLayout extends LinearLayout { } private void updateTextInputBoxBounds() { - if (mBoxBackgroundMode == BOX_BACKGROUND_NONE - || mBoxBackground == null - || mEditText == null - || getRight() == 0) { + if (mBoxBackground == null || mEditText == null || getRight() == 0) { return; }