mirror of
https://github.com/material-components/material-components-android.git
synced 2026-02-20 08:39:55 +08:00
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
This commit is contained in:
parent
2b80392e4e
commit
868ae2938c
@ -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());
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user