diff options
author | Fabrice Di Meglio <fdimeglio@google.com> | 2012-06-04 12:55:30 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-06-04 12:55:30 -0700 |
commit | b03b434089cf2106c467b2827a65e5c589c91d01 (patch) | |
tree | 9222343e85cac935144cc6bd2320a7ce434620ec | |
parent | c96132ff53e5c26f5b0170edd85072006fb2bc70 (diff) | |
download | frameworks_base-b03b434089cf2106c467b2827a65e5c589c91d01.zip frameworks_base-b03b434089cf2106c467b2827a65e5c589c91d01.tar.gz frameworks_base-b03b434089cf2106c467b2827a65e5c589c91d01.tar.bz2 |
Revert "Revert "Clean up layout direction APIs for Drawable""
This reverts commit c96132ff53e5c26f5b0170edd85072006fb2bc70
-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, 88 insertions, 72 deletions
diff --git a/api/current.txt b/api/current.txt index a7c89fa..4a292ad 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,6 +9279,7 @@ 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); @@ -9291,10 +9292,6 @@ 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(); @@ -23905,7 +23902,7 @@ package android.view { method public void recycle(); } - public class View implements android.view.accessibility.AccessibilityEventSource android.graphics.drawable.Drawable.Callback android.graphics.drawable.Drawable.Callback2 android.view.KeyEvent.Callback { + public class View implements android.view.accessibility.AccessibilityEventSource android.graphics.drawable.Drawable.Callback 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); @@ -24050,7 +24047,6 @@ 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(); @@ -24182,6 +24178,7 @@ 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(); @@ -24233,6 +24230,7 @@ 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); @@ -28725,7 +28723,6 @@ 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 61b2352..f74f969 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, Drawable.Callback2, KeyEvent.Callback, +public class View implements Drawable.Callback, KeyEvent.Callback, AccessibilityEventSource { private static final boolean DBG = false; @@ -3838,6 +3838,15 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal 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(); } @@ -13866,12 +13875,29 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal } /** - * 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; + * 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) { } /** @@ -14140,8 +14166,9 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal padding = new Rect(); sThreadLocal.set(padding); } + background.setLayoutDirection(getResolvedLayoutDirection()); if (background.getPadding(padding)) { - switch (background.getResolvedLayoutDirectionSelf()) { + switch (background.getLayoutDirection()) { 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 7593bff..f259597 100644 --- a/core/java/android/widget/ImageView.java +++ b/core/java/android/widget/ImageView.java @@ -194,12 +194,6 @@ 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); } @@ -672,6 +666,7 @@ 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 e26620f..1c6a406 100644 --- a/core/java/android/widget/ProgressBar.java +++ b/core/java/android/widget/ProgressBar.java @@ -478,6 +478,9 @@ public class ProgressBar extends View { d.setCallback(this); } mIndeterminateDrawable = d; + if (mIndeterminateDrawable != null) { + mIndeterminateDrawable.setLayoutDirection(getLayoutDirection()); + } if (mIndeterminate) { mCurrentDrawable = d; postInvalidate(); @@ -517,6 +520,7 @@ 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(); @@ -976,12 +980,6 @@ 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 d70bfb1..91dd297 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -4579,20 +4579,6 @@ 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()); } @@ -8203,13 +8189,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } } - /** - * 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() { + @Override + public void onResolveDrawables(int layoutDirection) { // No need to resolve twice if (mResolvedDrawables) { return; @@ -8225,7 +8206,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } Drawables dr = mDrawables; - switch(getResolvedLayoutDirection()) { + switch(layoutDirection) { case LAYOUT_DIRECTION_RTL: if (dr.mDrawableStart != null) { dr.mDrawableRight = dr.mDrawableStart; @@ -8257,9 +8238,25 @@ 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 87421b1..e82ccd4 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 = getResolvedLayoutDirectionSelf(); + final int layoutDirection = getLayoutDirection(); 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 c41dd07..bade9b4 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 = getResolvedLayoutDirectionSelf(); + final int layoutDirection = getLayoutDirection(); 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 6193ca7..07bcbdc 100644 --- a/graphics/java/android/graphics/drawable/Drawable.java +++ b/graphics/java/android/graphics/drawable/Drawable.java @@ -124,6 +124,8 @@ 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). @@ -296,18 +298,6 @@ 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. * @@ -384,15 +374,27 @@ public abstract class Drawable { } /** - * Use the current {@link android.graphics.drawable.Drawable.Callback2} implementation to get - * the resolved layout direction of this Drawable. + * Returns the resolved layout direction for this Drawable. + * + * @return One of {@link View#LAYOUT_DIRECTION_LTR}, + * {@link View#LAYOUT_DIRECTION_RTL} */ - public int getResolvedLayoutDirectionSelf() { - final Callback callback = getCallback(); - if (callback == null || !(callback instanceof Callback2)) { - return View.LAYOUT_DIRECTION_LTR; + 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}, + * + */ + public void setLayoutDirection(int layoutDirection) { + if (getLayoutDirection() != layoutDirection) { + mLayoutDirection = layoutDirection; } - return ((Callback2) callback).getResolvedLayoutDirection(this); } /** diff --git a/graphics/java/android/graphics/drawable/ScaleDrawable.java b/graphics/java/android/graphics/drawable/ScaleDrawable.java index ccad250..bd2b2f0 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 = getResolvedLayoutDirectionSelf(); + final int layoutDirection = getLayoutDirection(); Gravity.apply(mScaleState.mGravity, w, h, bounds, r, layoutDirection); if (w > 0 && h > 0) { |