Skip to content

Commit 1957d28

Browse files
author
Fabrice Di Meglio
committed
Fix bug #7419054 TextView Drawables resolution is broken in RTL mode
- check layout direction previous value in the onResolveDrawables(int) callback - dont do any Drawables resolution if we cannot resolve the layout direction - also remove unnecessary call to resolveRtlPropertiesIfNeeded() in ViewGroup when adding a child as the call to resolveRtlPropertiesIfNeeded() will be done into the measure() call itself later Change-Id: I62237af3d307dfea203f7f2865551d1c61a0e0b8
1 parent f704e9f commit 1957d28

File tree

4 files changed

+29
-20
lines changed

4 files changed

+29
-20
lines changed

core/java/android/view/View.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14198,11 +14198,13 @@ public void unscheduleDrawable(Drawable who) {
1419814198
* @hide
1419914199
*/
1420014200
protected void resolveDrawables() {
14201-
if (mBackground != null) {
14202-
mBackground.setLayoutDirection(getLayoutDirection());
14201+
if (canResolveLayoutDirection()) {
14202+
if (mBackground != null) {
14203+
mBackground.setLayoutDirection(getLayoutDirection());
14204+
}
14205+
mPrivateFlags2 |= PFLAG2_DRAWABLE_RESOLVED;
14206+
onResolveDrawables(getLayoutDirection());
1420314207
}
14204-
mPrivateFlags2 |= PFLAG2_DRAWABLE_RESOLVED;
14205-
onResolveDrawables(getLayoutDirection());
1420614208
}
1420714209

1420814210
/**

core/java/android/view/ViewGroup.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3384,7 +3384,6 @@ private void addViewInner(View child, int index, LayoutParams params,
33843384

33853385
if (child.isLayoutDirectionInherited()) {
33863386
child.resetRtlProperties();
3387-
child.resolveRtlPropertiesIfNeeded();
33883387
}
33893388

33903389
onViewAdded(child);

core/java/android/widget/Editor.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ public class Editor {
144144
CharSequence mError;
145145
boolean mErrorWasChanged;
146146
ErrorPopup mErrorPopup;
147+
private int mLastLayoutDirection = -1;
148+
147149
/**
148150
* This flag is set if the TextView tries to display an error before it
149151
* is attached to the window (so its position is still unknown).
@@ -288,23 +290,30 @@ private void showError() {
288290
public void setError(CharSequence error, Drawable icon) {
289291
mError = TextUtils.stringOrSpannedString(error);
290292
mErrorWasChanged = true;
291-
final Drawables dr = mTextView.mDrawables;
292-
if (dr != null) {
293-
switch (mTextView.getLayoutDirection()) {
293+
final int layoutDirection = mTextView.getLayoutDirection();
294+
if (mLastLayoutDirection != layoutDirection) {
295+
final Drawables dr = mTextView.mDrawables;
296+
switch (layoutDirection) {
294297
default:
295298
case View.LAYOUT_DIRECTION_LTR:
296-
mTextView.setCompoundDrawables(dr.mDrawableLeft, dr.mDrawableTop, icon,
297-
dr.mDrawableBottom);
299+
if (dr != null) {
300+
mTextView.setCompoundDrawables(dr.mDrawableLeft, dr.mDrawableTop, icon,
301+
dr.mDrawableBottom);
302+
} else {
303+
mTextView.setCompoundDrawables(null, null, icon, null);
304+
}
298305
break;
299306
case View.LAYOUT_DIRECTION_RTL:
300-
mTextView.setCompoundDrawables(icon, dr.mDrawableTop, dr.mDrawableRight,
301-
dr.mDrawableBottom);
307+
if (dr != null) {
308+
mTextView.setCompoundDrawables(icon, dr.mDrawableTop, dr.mDrawableRight,
309+
dr.mDrawableBottom);
310+
} else {
311+
mTextView.setCompoundDrawables(icon, null, null, null);
312+
}
302313
break;
303314
}
304-
} else {
305-
mTextView.setCompoundDrawables(null, null, icon, null);
315+
mLastLayoutDirection = layoutDirection;
306316
}
307-
308317
if (mError == null) {
309318
if (mErrorPopup != null) {
310319
if (mErrorPopup.isShowing()) {

core/java/android/widget/TextView.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ static class Drawables {
306306
private Layout.Alignment mLayoutAlignment;
307307
private int mResolvedTextAlignment;
308308

309-
private boolean mResolvedDrawables;
309+
private int mLastLayoutDirection = -1;
310310

311311
/**
312312
* On some devices the fading edges add a performance penalty if used
@@ -8260,16 +8260,16 @@ TextDirectionHeuristic getTextDirectionHeuristic() {
82608260
@Override
82618261
public void onResolveDrawables(int layoutDirection) {
82628262
// No need to resolve twice
8263-
if (mResolvedDrawables) {
8263+
if (mLastLayoutDirection == layoutDirection) {
82648264
return;
82658265
}
8266+
mLastLayoutDirection = layoutDirection;
82668267
// No drawable to resolve
82678268
if (mDrawables == null) {
82688269
return;
82698270
}
82708271
// No relative drawable to resolve
82718272
if (mDrawables.mDrawableStart == null && mDrawables.mDrawableEnd == null) {
8272-
mResolvedDrawables = true;
82738273
return;
82748274
}
82758275

@@ -8307,7 +8307,6 @@ public void onResolveDrawables(int layoutDirection) {
83078307
break;
83088308
}
83098309
updateDrawablesLayoutDirection(dr, layoutDirection);
8310-
mResolvedDrawables = true;
83118310
}
83128311

83138312
private void updateDrawablesLayoutDirection(Drawables dr, int layoutDirection) {
@@ -8329,7 +8328,7 @@ private void updateDrawablesLayoutDirection(Drawables dr, int layoutDirection) {
83298328
* @hide
83308329
*/
83318330
protected void resetResolvedDrawables() {
8332-
mResolvedDrawables = false;
8331+
mLastLayoutDirection = -1;
83338332
}
83348333

83358334
/**

0 commit comments

Comments
 (0)