From 868ae2938c2eae6e44ee38de7adbce5feb0fc854 Mon Sep 17 00:00:00 2001 From: Chris Banes Date: Wed, 30 Nov 2016 01:18:56 +0000 Subject: [PATCH] am 2f50db18: am 5522362d: am 88099e98: am 252b1765: Merge "Fix TextInputLayout laying out RTL text as LTR" into lmp-mr1-ub-dev * commit '2f50db1865e1182e7574222c707003a1168298ee': Fix TextInputLayout laying out RTL text as LTR GitOrigin-RevId=e1300952cb43e49cebb185b826278f43c042d76a PiperOrigin-RevId: 140548720 --- .../design/widget/CollapsingTextHelper.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/android/support/design/widget/CollapsingTextHelper.java b/src/android/support/design/widget/CollapsingTextHelper.java index 328fcac42..437e2d195 100644 --- a/src/android/support/design/widget/CollapsingTextHelper.java +++ b/src/android/support/design/widget/CollapsingTextHelper.java @@ -24,6 +24,7 @@ import android.graphics.Paint; import android.graphics.Rect; import android.os.Build; import android.support.design.R; +import android.support.v4.text.TextDirectionHeuristicsCompat; import android.support.v4.view.ViewCompat; import android.text.TextPaint; import android.text.TextUtils; @@ -66,6 +67,7 @@ final class CollapsingTextHelper { private CharSequence mText; private CharSequence mTextToDraw; private float mTextWidth; + private boolean mIsRtl; private boolean mUseTexture; private Bitmap mExpandedTitleTexture; @@ -282,8 +284,7 @@ final class CollapsingTextHelper { final int saveCount = canvas.save(); if (mTextToDraw != null) { - final boolean isRtl = ViewCompat.getLayoutDirection(mView) - == ViewCompat.LAYOUT_DIRECTION_RTL; + final boolean isRtl = mIsRtl; float x = isRtl ? mCurrentRight : mCurrentLeft; float y = mCurrentTop; @@ -333,6 +334,14 @@ final class CollapsingTextHelper { canvas.restoreToCount(saveCount); } + private boolean calculateIsRtl(CharSequence text) { + final boolean defaultIsRtl = ViewCompat.getLayoutDirection(mView) + == ViewCompat.LAYOUT_DIRECTION_RTL; + return (defaultIsRtl + ? TextDirectionHeuristicsCompat.FIRSTSTRONG_RTL + : TextDirectionHeuristicsCompat.FIRSTSTRONG_LTR).isRtl(text, 0, text.length()); + } + private void setInterpolatedTextSize(final float textSize) { if (mText == null) return; @@ -371,6 +380,7 @@ final class CollapsingTextHelper { if (mTextToDraw == null || !mTextToDraw.equals(title)) { mTextToDraw = title; } + mIsRtl = calculateIsRtl(mTextToDraw); mTextWidth = mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()); }