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 | |
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.
-rw-r--r-- | api/current.txt | 13 | ||||
-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 | ||||
-rw-r--r-- | graphics/java/android/graphics/drawable/BitmapDrawable.java | 2 | ||||
-rw-r--r-- | graphics/java/android/graphics/drawable/ClipDrawable.java | 2 | ||||
-rw-r--r-- | graphics/java/android/graphics/drawable/Drawable.java | 40 | ||||
-rw-r--r-- | graphics/java/android/graphics/drawable/ScaleDrawable.java | 2 |
9 files changed, 72 insertions, 88 deletions
diff --git a/api/current.txt b/api/current.txt index 4a292ad..a7c89fa 100644 --- a/api/current.txt +++ b/api/current.txt @@ -9251,12 +9251,12 @@ package android.graphics.drawable { method public android.graphics.drawable.Drawable getCurrent(); method public int getIntrinsicHeight(); method public int getIntrinsicWidth(); - method public int getLayoutDirection(); method public final int getLevel(); method public int getMinimumHeight(); method public int getMinimumWidth(); method public abstract int getOpacity(); method public boolean getPadding(android.graphics.Rect); + method public int getResolvedLayoutDirectionSelf(); method public int[] getState(); method public android.graphics.Region getTransparentRegion(); method public void inflate(android.content.res.Resources, org.xmlpull.v1.XmlPullParser, android.util.AttributeSet) throws java.io.IOException, org.xmlpull.v1.XmlPullParserException; @@ -9279,7 +9279,6 @@ package android.graphics.drawable { method public void setColorFilter(int, android.graphics.PorterDuff.Mode); method public void setDither(boolean); method public void setFilterBitmap(boolean); - method public void setLayoutDirection(int); method public final boolean setLevel(int); method public boolean setState(int[]); method public boolean setVisible(boolean, boolean); @@ -9292,6 +9291,10 @@ package android.graphics.drawable { method public abstract void unscheduleDrawable(android.graphics.drawable.Drawable, java.lang.Runnable); } + public static abstract interface Drawable.Callback2 implements android.graphics.drawable.Drawable.Callback { + method public abstract int getResolvedLayoutDirection(android.graphics.drawable.Drawable); + } + public static abstract class Drawable.ConstantState { ctor public Drawable.ConstantState(); method public abstract int getChangingConfigurations(); @@ -23902,7 +23905,7 @@ package android.view { method public void recycle(); } - public class View implements android.view.accessibility.AccessibilityEventSource android.graphics.drawable.Drawable.Callback android.view.KeyEvent.Callback { + public class View implements android.view.accessibility.AccessibilityEventSource android.graphics.drawable.Drawable.Callback android.graphics.drawable.Drawable.Callback2 android.view.KeyEvent.Callback { ctor public View(android.content.Context); ctor public View(android.content.Context, android.util.AttributeSet); ctor public View(android.content.Context, android.util.AttributeSet, int); @@ -24047,6 +24050,7 @@ package android.view { method public float getPivotX(); method public float getPivotY(); method public int getResolvedLayoutDirection(); + method public int getResolvedLayoutDirection(android.graphics.drawable.Drawable); method public int getResolvedTextAlignment(); method public int getResolvedTextDirection(); method public android.content.res.Resources getResources(); @@ -24178,7 +24182,6 @@ package android.view { method protected void onOverScrolled(int, int, boolean, boolean); method public void onPaddingChanged(int); method public void onPopulateAccessibilityEvent(android.view.accessibility.AccessibilityEvent); - method public void onResolveDrawables(int); method public void onResolvedLayoutDirectionChanged(); method public void onResolvedLayoutDirectionReset(); method public void onResolvedTextAlignmentChanged(); @@ -24230,7 +24233,6 @@ package android.view { method public void resetResolvedLayoutDirection(); method public void resetResolvedTextAlignment(); method public void resetResolvedTextDirection(); - method public void resolveDrawables(); method public void resolveLayoutDirection(); method public void resolvePadding(); method public static int resolveSize(int, int); @@ -28723,6 +28725,7 @@ package android.widget { method public boolean onTextContextMenuItem(int); method public void removeTextChangedListener(android.text.TextWatcher); method protected void resetResolvedDrawables(); + method protected void resolveDrawables(); method public void setAllCaps(boolean); method public final void setAutoLinkMask(int); method public void setCompoundDrawablePadding(int); 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; } diff --git a/graphics/java/android/graphics/drawable/BitmapDrawable.java b/graphics/java/android/graphics/drawable/BitmapDrawable.java index e82ccd4..87421b1 100644 --- a/graphics/java/android/graphics/drawable/BitmapDrawable.java +++ b/graphics/java/android/graphics/drawable/BitmapDrawable.java @@ -385,7 +385,7 @@ public class BitmapDrawable extends Drawable { Shader shader = state.mPaint.getShader(); if (shader == null) { if (mApplyGravity) { - final int layoutDirection = getLayoutDirection(); + final int layoutDirection = getResolvedLayoutDirectionSelf(); Gravity.apply(state.mGravity, mBitmapWidth, mBitmapHeight, getBounds(), mDstRect, layoutDirection); mApplyGravity = false; diff --git a/graphics/java/android/graphics/drawable/ClipDrawable.java b/graphics/java/android/graphics/drawable/ClipDrawable.java index bade9b4..c41dd07 100644 --- a/graphics/java/android/graphics/drawable/ClipDrawable.java +++ b/graphics/java/android/graphics/drawable/ClipDrawable.java @@ -209,7 +209,7 @@ public class ClipDrawable extends Drawable implements Drawable.Callback { if ((mClipState.mOrientation & VERTICAL) != 0) { h -= (h - ih) * (10000 - level) / 10000; } - final int layoutDirection = getLayoutDirection(); + final int layoutDirection = getResolvedLayoutDirectionSelf(); Gravity.apply(mClipState.mGravity, w, h, bounds, r, layoutDirection); if (w > 0 && h > 0) { diff --git a/graphics/java/android/graphics/drawable/Drawable.java b/graphics/java/android/graphics/drawable/Drawable.java index 07bcbdc..6193ca7 100644 --- a/graphics/java/android/graphics/drawable/Drawable.java +++ b/graphics/java/android/graphics/drawable/Drawable.java @@ -124,8 +124,6 @@ public abstract class Drawable { private WeakReference<Callback> mCallback = null; private boolean mVisible = true; - private int mLayoutDirection; - /** * Draw in its bounds (set via setBounds) respecting optional effects such * as alpha (set via setAlpha) and color filter (set via setColorFilter). @@ -298,6 +296,18 @@ public abstract class Drawable { } /** + * Implement this interface if you want to create an drawable that is RTL aware + */ + public static interface Callback2 extends Callback { + /** + * A Drawable can call this to get the resolved layout direction of the <var>who</var>. + * + * @param who The drawable being queried. + */ + public int getResolvedLayoutDirection(Drawable who); + } + + /** * Bind a {@link Callback} object to this Drawable. Required for clients * that want to support animated drawables. * @@ -374,27 +384,15 @@ public abstract class Drawable { } /** - * Returns the resolved layout direction for this Drawable. - * - * @return One of {@link View#LAYOUT_DIRECTION_LTR}, - * {@link View#LAYOUT_DIRECTION_RTL} - */ - public int getLayoutDirection() { - return mLayoutDirection; - } - - /** - * Set the layout direction for this drawable. Should be a resolved direction as the - * Drawable as no capacity to do the resolution on his own. - * - * @param layoutDirection One of {@link View#LAYOUT_DIRECTION_LTR}, - * {@link View#LAYOUT_DIRECTION_RTL}, - * + * Use the current {@link android.graphics.drawable.Drawable.Callback2} implementation to get + * the resolved layout direction of this Drawable. */ - public void setLayoutDirection(int layoutDirection) { - if (getLayoutDirection() != layoutDirection) { - mLayoutDirection = layoutDirection; + public int getResolvedLayoutDirectionSelf() { + final Callback callback = getCallback(); + if (callback == null || !(callback instanceof Callback2)) { + return View.LAYOUT_DIRECTION_LTR; } + return ((Callback2) callback).getResolvedLayoutDirection(this); } /** diff --git a/graphics/java/android/graphics/drawable/ScaleDrawable.java b/graphics/java/android/graphics/drawable/ScaleDrawable.java index bd2b2f0..ccad250 100644 --- a/graphics/java/android/graphics/drawable/ScaleDrawable.java +++ b/graphics/java/android/graphics/drawable/ScaleDrawable.java @@ -221,7 +221,7 @@ public class ScaleDrawable extends Drawable implements Drawable.Callback { final int ih = min ? mScaleState.mDrawable.getIntrinsicHeight() : 0; h -= (int) ((h - ih) * (10000 - level) * mScaleState.mScaleHeight / 10000); } - final int layoutDirection = getLayoutDirection(); + final int layoutDirection = getResolvedLayoutDirectionSelf(); Gravity.apply(mScaleState.mGravity, w, h, bounds, r, layoutDirection); if (w > 0 && h > 0) { |