From c1da65187a4b9de8f72bd617ef937030187c0a92 Mon Sep 17 00:00:00 2001 From: Fabrice Di Meglio Date: Thu, 31 May 2012 15:21:23 -0700 Subject: Clean up layout direction APIs for Drawable - see bug #6427629 Change-Id: I3119db3022bba0ee325b6d0d4471bfebd850ec10 --- .../android/graphics/drawable/BitmapDrawable.java | 2 +- .../android/graphics/drawable/ClipDrawable.java | 2 +- .../java/android/graphics/drawable/Drawable.java | 40 ++++++++++++---------- .../android/graphics/drawable/ScaleDrawable.java | 2 +- 4 files changed, 24 insertions(+), 22 deletions(-) (limited to 'graphics/java/android') diff --git a/graphics/java/android/graphics/drawable/BitmapDrawable.java b/graphics/java/android/graphics/drawable/BitmapDrawable.java index 87421b187eab..e82ccd4988b1 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 c41dd07c2e6f..bade9b4f54b2 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 6193ca72baf6..07bcbdcdeaac 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 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). @@ -295,18 +297,6 @@ public abstract class Drawable { public void unscheduleDrawable(Drawable who, Runnable what); } - /** - * 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 who. - * - * @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 ccad2503f6f9..bd2b2f0624a4 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) { -- cgit v1.2.3-59-g8ed1b