diff options
author | Jean-Baptiste Queru <jbq@google.com> | 2012-06-02 05:46:20 -0700 |
---|---|---|
committer | Jean-Baptiste Queru <jbq@google.com> | 2012-06-02 05:46:20 -0700 |
commit | c96132ff53e5c26f5b0170edd85072006fb2bc70 (patch) | |
tree | 672fc65ce1e5d7766fd4ba947363aef345318982 /core/java/android | |
parent | 78068825416a4a0f3b2fdf57491ba4932c2bb6c4 (diff) | |
download | frameworks_base-c96132ff53e5c26f5b0170edd85072006fb2bc70.zip frameworks_base-c96132ff53e5c26f5b0170edd85072006fb2bc70.tar.gz frameworks_base-c96132ff53e5c26f5b0170edd85072006fb2bc70.tar.bz2 |
Revert "Clean up layout direction APIs for Drawable"
This reverts commit c1da65187a4b9de8f72bd617ef937030187c0a92.
Diffstat (limited to 'core/java/android')
-rw-r--r-- | core/java/android/view/View.java | 43 | ||||
-rw-r--r-- | core/java/android/widget/ImageView.java | 7 | ||||
-rw-r--r-- | core/java/android/widget/ProgressBar.java | 10 | ||||
-rw-r--r-- | core/java/android/widget/TextView.java | 41 |
4 files changed, 42 insertions, 59 deletions
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index f74f969..61b2352 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -660,7 +660,7 @@ import java.util.concurrent.CopyOnWriteArrayList; * * @see android.view.ViewGroup */ -public class View implements Drawable.Callback, KeyEvent.Callback, +public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Callback, AccessibilityEventSource { private static final boolean DBG = false; @@ -3838,15 +3838,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback, scrollabilityCache.scrollBar.setAlwaysDrawVerticalTrack(true); } - // Apply layout direction to the new Drawables if needed - final int layoutDirection = getResolvedLayoutDirection(); - if (track != null) { - track.setLayoutDirection(layoutDirection); - } - if (thumb != null) { - thumb.setLayoutDirection(layoutDirection); - } - // Re-apply user/background padding so that scrollbar(s) get added resolvePadding(); } @@ -13875,29 +13866,12 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } /** - * Resolve the Drawables depending on the layout direction. This is implicitly supposing - * that the View directionality can and will be resolved before its Drawables. - * - * Will call {@link View#onResolveDrawables} when resolution is done. - */ - public void resolveDrawables() { - if (mBackground != null) { - mBackground.setLayoutDirection(getResolvedLayoutDirection()); - } - onResolveDrawables(getResolvedLayoutDirection()); - } - - /** - * Called when layout direction has been resolved. - * - * The default implementation does nothing. - * - * @param layoutDirection The resolved layout direction. - * - * @see {@link #LAYOUT_DIRECTION_LTR} - * @see {@link #LAYOUT_DIRECTION_RTL} - */ - public void onResolveDrawables(int layoutDirection) { + * Return the layout direction of a given Drawable. + * + * @param who the Drawable to query + */ + public int getResolvedLayoutDirection(Drawable who) { + return (who == mBackground) ? getResolvedLayoutDirection() : LAYOUT_DIRECTION_DEFAULT; } /** @@ -14166,9 +14140,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, padding = new Rect(); sThreadLocal.set(padding); } - background.setLayoutDirection(getResolvedLayoutDirection()); if (background.getPadding(padding)) { - switch (background.getLayoutDirection()) { + switch (background.getResolvedLayoutDirectionSelf()) { case LAYOUT_DIRECTION_RTL: setPadding(padding.right, padding.top, padding.left, padding.bottom); break; diff --git a/core/java/android/widget/ImageView.java b/core/java/android/widget/ImageView.java index f259597..7593bff 100644 --- a/core/java/android/widget/ImageView.java +++ b/core/java/android/widget/ImageView.java @@ -194,6 +194,12 @@ public class ImageView extends View { } @Override + public int getResolvedLayoutDirection(Drawable dr) { + return (dr == mDrawable) ? + getResolvedLayoutDirection() : super.getResolvedLayoutDirection(dr); + } + + @Override public boolean hasOverlappingRendering() { return (getBackground() != null); } @@ -666,7 +672,6 @@ public class ImageView extends View { d.setState(getDrawableState()); } d.setLevel(mLevel); - d.setLayoutDirection(getLayoutDirection()); mDrawableWidth = d.getIntrinsicWidth(); mDrawableHeight = d.getIntrinsicHeight(); applyColorMod(); diff --git a/core/java/android/widget/ProgressBar.java b/core/java/android/widget/ProgressBar.java index 1c6a406..e26620f 100644 --- a/core/java/android/widget/ProgressBar.java +++ b/core/java/android/widget/ProgressBar.java @@ -478,9 +478,6 @@ public class ProgressBar extends View { d.setCallback(this); } mIndeterminateDrawable = d; - if (mIndeterminateDrawable != null) { - mIndeterminateDrawable.setLayoutDirection(getLayoutDirection()); - } if (mIndeterminate) { mCurrentDrawable = d; postInvalidate(); @@ -520,7 +517,6 @@ public class ProgressBar extends View { if (d != null) { d.setCallback(this); - d.setLayoutDirection(getLayoutDirection()); // Make sure the ProgressBar is always tall enough int drawableHeight = d.getMinimumHeight(); @@ -980,6 +976,12 @@ public class ProgressBar extends View { } @Override + public int getResolvedLayoutDirection(Drawable who) { + return (who == mProgressDrawable || who == mIndeterminateDrawable) ? + getResolvedLayoutDirection() : super.getResolvedLayoutDirection(who); + } + + @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { updateDrawableBounds(w, h); } diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 91dd297..d70bfb1 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -4579,6 +4579,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; } |