From c96132ff53e5c26f5b0170edd85072006fb2bc70 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Queru Date: Sat, 2 Jun 2012 05:46:20 -0700 Subject: Revert "Clean up layout direction APIs for Drawable" This reverts commit c1da65187a4b9de8f72bd617ef937030187c0a92. --- core/java/android/widget/TextView.java | 41 ++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'core/java/android/widget/TextView.java') diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 91dd29711cf7..d70bfb191506 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -4578,6 +4578,20 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } } + @Override + public int getResolvedLayoutDirection(Drawable who) { + if (who == null) return View.LAYOUT_DIRECTION_LTR; + if (mDrawables != null) { + final Drawables drawables = mDrawables; + if (who == drawables.mDrawableLeft || who == drawables.mDrawableRight || + who == drawables.mDrawableTop || who == drawables.mDrawableBottom || + who == drawables.mDrawableStart || who == drawables.mDrawableEnd) { + return getResolvedLayoutDirection(); + } + } + return super.getResolvedLayoutDirection(who); + } + @Override public boolean hasOverlappingRendering() { return (getBackground() != null || mText instanceof Spannable || hasSelection()); @@ -8189,8 +8203,13 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } } - @Override - public void onResolveDrawables(int layoutDirection) { + /** + * Subclasses will need to override this method to implement their own way of resolving + * drawables depending on the layout direction. + * + * A call to the super method will be required from the subclasses implementation. + */ + protected void resolveDrawables() { // No need to resolve twice if (mResolvedDrawables) { return; @@ -8206,7 +8225,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } Drawables dr = mDrawables; - switch(layoutDirection) { + switch(getResolvedLayoutDirection()) { case LAYOUT_DIRECTION_RTL: if (dr.mDrawableStart != null) { dr.mDrawableRight = dr.mDrawableStart; @@ -8238,25 +8257,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } break; } - updateDrawablesLayoutDirection(dr, layoutDirection); mResolvedDrawables = true; } - private void updateDrawablesLayoutDirection(Drawables dr, int layoutDirection) { - if (dr.mDrawableLeft != null) { - dr.mDrawableLeft.setLayoutDirection(layoutDirection); - } - if (dr.mDrawableRight != null) { - dr.mDrawableRight.setLayoutDirection(layoutDirection); - } - if (dr.mDrawableTop != null) { - dr.mDrawableTop.setLayoutDirection(layoutDirection); - } - if (dr.mDrawableBottom != null) { - dr.mDrawableBottom.setLayoutDirection(layoutDirection); - } - } - protected void resetResolvedDrawables() { mResolvedDrawables = false; } -- cgit v1.2.3