From ee3e1603fdbbe24b0cbf3cb85c456696cf3b7941 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Tue, 1 Oct 2013 15:32:13 -0700 Subject: Fix animations, padding in RTL mode. Show directory animations coming in from left-side when in RTL language. Also fix NinePatchDrawable to correctly mirror its padding when auto-mirrored, and fix InsetDrawable to propagate the layout direction to the wrapped Drawable. Bug: 10987190, 11030793 Change-Id: I1213802a07d0c4ced93438df1e6ddf5aed3df677 --- .../android/graphics/drawable/InsetDrawable.java | 8 +++++++- .../graphics/drawable/NinePatchDrawable.java | 24 ++++++++++++++++------ 2 files changed, 25 insertions(+), 7 deletions(-) (limited to 'graphics') diff --git a/graphics/java/android/graphics/drawable/InsetDrawable.java b/graphics/java/android/graphics/drawable/InsetDrawable.java index e3a7e2b..8188782 100644 --- a/graphics/java/android/graphics/drawable/InsetDrawable.java +++ b/graphics/java/android/graphics/drawable/InsetDrawable.java @@ -202,7 +202,13 @@ public class InsetDrawable extends Drawable implements Drawable.Callback public void setColorFilter(ColorFilter cf) { mInsetState.mDrawable.setColorFilter(cf); } - + + /** {@hide} */ + @Override + public void setLayoutDirection(int layoutDirection) { + mInsetState.mDrawable.setLayoutDirection(layoutDirection); + } + @Override public int getOpacity() { return mInsetState.mDrawable.getOpacity(); diff --git a/graphics/java/android/graphics/drawable/NinePatchDrawable.java b/graphics/java/android/graphics/drawable/NinePatchDrawable.java index 720494b..ab34c0f 100644 --- a/graphics/java/android/graphics/drawable/NinePatchDrawable.java +++ b/graphics/java/android/graphics/drawable/NinePatchDrawable.java @@ -219,16 +219,15 @@ public class NinePatchDrawable extends Drawable { @Override public void draw(Canvas canvas) { final Rect bounds = getBounds(); - final boolean needMirroring = isAutoMirrored() && - getLayoutDirection() == LayoutDirection.RTL; - if (needMirroring) { + final boolean needsMirroring = needsMirroring(); + if (needsMirroring) { canvas.save(); // Mirror the 9patch canvas.translate(bounds.right - bounds.left, 0); canvas.scale(-1.0f, 1.0f); } mNinePatch.draw(canvas, bounds, mPaint); - if (needMirroring) { + if (needsMirroring) { canvas.restore(); } } @@ -240,7 +239,11 @@ public class NinePatchDrawable extends Drawable { @Override public boolean getPadding(Rect padding) { - padding.set(mPadding); + if (needsMirroring()) { + padding.set(mPadding.right, mPadding.top, mPadding.left, mPadding.bottom); + } else { + padding.set(mPadding); + } return true; } @@ -249,7 +252,12 @@ public class NinePatchDrawable extends Drawable { */ @Override public Insets getOpticalInsets() { - return mOpticalInsets; + if (needsMirroring()) { + return Insets.of(mOpticalInsets.right, mOpticalInsets.top, mOpticalInsets.right, + mOpticalInsets.bottom); + } else { + return mOpticalInsets; + } } @Override @@ -297,6 +305,10 @@ public class NinePatchDrawable extends Drawable { mNinePatchState.mAutoMirrored = mirrored; } + private boolean needsMirroring() { + return isAutoMirrored() && getLayoutDirection() == LayoutDirection.RTL; + } + @Override public boolean isAutoMirrored() { return mNinePatchState.mAutoMirrored; -- cgit v1.1