diff options
| author | Fabrice Di Meglio <fdimeglio@google.com> | 2012-10-25 17:42:39 -0700 |
|---|---|---|
| committer | Fabrice Di Meglio <fdimeglio@google.com> | 2012-10-26 10:55:02 -0700 |
| commit | 1957d281ea123e4925e51fa5ad22ce239ef2a07d (patch) | |
| tree | 1b72094e04a5df8cfa6b61849d66b641c599819d /core | |
| parent | f704e9f67745d1f1c01058f4c74b06d157b4054d (diff) | |
| download | frameworks_base-1957d281ea123e4925e51fa5ad22ce239ef2a07d.zip frameworks_base-1957d281ea123e4925e51fa5ad22ce239ef2a07d.tar.gz frameworks_base-1957d281ea123e4925e51fa5ad22ce239ef2a07d.tar.bz2 | |
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
Diffstat (limited to 'core')
| -rw-r--r-- | core/java/android/view/View.java | 10 | ||||
| -rw-r--r-- | core/java/android/view/ViewGroup.java | 1 | ||||
| -rw-r--r-- | core/java/android/widget/Editor.java | 29 | ||||
| -rw-r--r-- | core/java/android/widget/TextView.java | 9 |
4 files changed, 29 insertions, 20 deletions
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index f5e259e..6b4e64c 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -14198,11 +14198,13 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * @hide */ protected void resolveDrawables() { - if (mBackground != null) { - mBackground.setLayoutDirection(getLayoutDirection()); + if (canResolveLayoutDirection()) { + if (mBackground != null) { + mBackground.setLayoutDirection(getLayoutDirection()); + } + mPrivateFlags2 |= PFLAG2_DRAWABLE_RESOLVED; + onResolveDrawables(getLayoutDirection()); } - mPrivateFlags2 |= PFLAG2_DRAWABLE_RESOLVED; - onResolveDrawables(getLayoutDirection()); } /** diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java index c252c77..dc73e85 100644 --- a/core/java/android/view/ViewGroup.java +++ b/core/java/android/view/ViewGroup.java @@ -3384,7 +3384,6 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager if (child.isLayoutDirectionInherited()) { child.resetRtlProperties(); - child.resolveRtlPropertiesIfNeeded(); } onViewAdded(child); diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java index 19b825c..495e46b 100644 --- a/core/java/android/widget/Editor.java +++ b/core/java/android/widget/Editor.java @@ -144,6 +144,8 @@ public class Editor { CharSequence mError; boolean mErrorWasChanged; ErrorPopup mErrorPopup; + private int mLastLayoutDirection = -1; + /** * This flag is set if the TextView tries to display an error before it * is attached to the window (so its position is still unknown). @@ -288,23 +290,30 @@ public class Editor { public void setError(CharSequence error, Drawable icon) { mError = TextUtils.stringOrSpannedString(error); mErrorWasChanged = true; - final Drawables dr = mTextView.mDrawables; - if (dr != null) { - switch (mTextView.getLayoutDirection()) { + final int layoutDirection = mTextView.getLayoutDirection(); + if (mLastLayoutDirection != layoutDirection) { + final Drawables dr = mTextView.mDrawables; + switch (layoutDirection) { default: case View.LAYOUT_DIRECTION_LTR: - mTextView.setCompoundDrawables(dr.mDrawableLeft, dr.mDrawableTop, icon, - dr.mDrawableBottom); + if (dr != null) { + mTextView.setCompoundDrawables(dr.mDrawableLeft, dr.mDrawableTop, icon, + dr.mDrawableBottom); + } else { + mTextView.setCompoundDrawables(null, null, icon, null); + } break; case View.LAYOUT_DIRECTION_RTL: - mTextView.setCompoundDrawables(icon, dr.mDrawableTop, dr.mDrawableRight, - dr.mDrawableBottom); + if (dr != null) { + mTextView.setCompoundDrawables(icon, dr.mDrawableTop, dr.mDrawableRight, + dr.mDrawableBottom); + } else { + mTextView.setCompoundDrawables(icon, null, null, null); + } break; } - } else { - mTextView.setCompoundDrawables(null, null, icon, null); + mLastLayoutDirection = layoutDirection; } - if (mError == null) { if (mErrorPopup != null) { if (mErrorPopup.isShowing()) { diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 8e5ff40..a46481c 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -306,7 +306,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener private Layout.Alignment mLayoutAlignment; private int mResolvedTextAlignment; - private boolean mResolvedDrawables; + private int mLastLayoutDirection = -1; /** * On some devices the fading edges add a performance penalty if used @@ -8260,16 +8260,16 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener @Override public void onResolveDrawables(int layoutDirection) { // No need to resolve twice - if (mResolvedDrawables) { + if (mLastLayoutDirection == layoutDirection) { return; } + mLastLayoutDirection = layoutDirection; // No drawable to resolve if (mDrawables == null) { return; } // No relative drawable to resolve if (mDrawables.mDrawableStart == null && mDrawables.mDrawableEnd == null) { - mResolvedDrawables = true; return; } @@ -8307,7 +8307,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener break; } updateDrawablesLayoutDirection(dr, layoutDirection); - mResolvedDrawables = true; } private void updateDrawablesLayoutDirection(Drawables dr, int layoutDirection) { @@ -8329,7 +8328,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener * @hide */ protected void resetResolvedDrawables() { - mResolvedDrawables = false; + mLastLayoutDirection = -1; } /** |
