diff options
Diffstat (limited to 'graphics/java/android')
4 files changed, 22 insertions, 24 deletions
diff --git a/graphics/java/android/graphics/drawable/BitmapDrawable.java b/graphics/java/android/graphics/drawable/BitmapDrawable.java index e82ccd4988b1..87421b187eab 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 bade9b4f54b2..c41dd07c2e6f 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 07bcbdcdeaac..6193ca72baf6 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 bd2b2f0624a4..ccad2503f6f9 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) { |