summaryrefslogtreecommitdiff
path: root/graphics/java/android
diff options
context:
space:
mode:
author Fabrice Di Meglio <fdimeglio@google.com> 2012-05-31 15:21:23 -0700
committer Fabrice Di Meglio <fdimeglio@google.com> 2012-06-01 11:39:10 -0700
commitc1da65187a4b9de8f72bd617ef937030187c0a92 (patch)
tree85af5f439c731625f5f6c442dc50147a23586eb0 /graphics/java/android
parentdb120c4dd21bc53c6f58d0140e3a9a3dc6e79b16 (diff)
Clean up layout direction APIs for Drawable
- see bug #6427629 Change-Id: I3119db3022bba0ee325b6d0d4471bfebd850ec10
Diffstat (limited to 'graphics/java/android')
-rw-r--r--graphics/java/android/graphics/drawable/BitmapDrawable.java2
-rw-r--r--graphics/java/android/graphics/drawable/ClipDrawable.java2
-rw-r--r--graphics/java/android/graphics/drawable/Drawable.java40
-rw-r--r--graphics/java/android/graphics/drawable/ScaleDrawable.java2
4 files changed, 24 insertions, 22 deletions
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<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 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) {