summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/res/res/values/attrs.xml3
-rw-r--r--graphics/java/android/graphics/drawable/VectorDrawable.java31
-rw-r--r--tests/VectorDrawableTest/AndroidManifest.xml3
-rw-r--r--tests/VectorDrawableTest/res/drawable/vector_drawable03.xml3
-rw-r--r--tests/VectorDrawableTest/res/drawable/vector_drawable04.xml3
-rw-r--r--tests/VectorDrawableTest/res/drawable/vector_drawable05.xml3
6 files changed, 42 insertions, 4 deletions
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index ab19ad4..f57d61d 100644
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -5085,6 +5085,9 @@
<!-- When a tint color is set, specifies its Porter-Duff blending mode. The
default value is src_in, which treats the drawable as an alpha mask. -->
<attr name="tintMode" />
+ <!-- Indicates if the drawable needs to be mirrored when its layout direction is
+ RTL (right-to-left). -->
+ <attr name="autoMirrored" />
</declare-styleable>
<!-- Define the virtual size of the drawing surface paths will draw to. -->
diff --git a/graphics/java/android/graphics/drawable/VectorDrawable.java b/graphics/java/android/graphics/drawable/VectorDrawable.java
index 8c907b2..43e6509 100644
--- a/graphics/java/android/graphics/drawable/VectorDrawable.java
+++ b/graphics/java/android/graphics/drawable/VectorDrawable.java
@@ -33,6 +33,7 @@ import android.graphics.Region;
import android.graphics.PorterDuff.Mode;
import android.util.ArrayMap;
import android.util.AttributeSet;
+import android.util.LayoutDirection;
import android.util.Log;
import android.util.PathParser;
import android.util.Xml;
@@ -187,7 +188,13 @@ public class VectorDrawable extends Drawable {
public void draw(Canvas canvas) {
final int saveCount = canvas.save();
final Rect bounds = getBounds();
+ final boolean needMirroring = needMirroring();
+
canvas.translate(bounds.left, bounds.top);
+ if (needMirroring) {
+ canvas.translate(bounds.width(), 0);
+ canvas.scale(-1.0f, 1.0f);
+ }
if (!mAllowCaching) {
mVectorState.mVPathRenderer.draw(canvas, bounds.width(), bounds.height());
@@ -205,6 +212,7 @@ public class VectorDrawable extends Drawable {
}
canvas.drawBitmap(bitmap, null, bounds, null);
}
+
canvas.restoreToCount(saveCount);
}
@@ -352,6 +360,9 @@ public class VectorDrawable extends Drawable {
if (tint != null) {
state.mTint = tint;
}
+
+ state.mAutoMirrored = a.getBoolean(
+ R.styleable.VectorDrawable_autoMirrored, state.mAutoMirrored);
}
private void inflateInternal(Resources res, XmlPullParser parser, AttributeSet attrs,
@@ -469,12 +480,30 @@ public class VectorDrawable extends Drawable {
mAllowCaching = allowCaching;
}
+ private boolean needMirroring() {
+ return isAutoMirrored() && getLayoutDirection() == LayoutDirection.RTL;
+ }
+
+ @Override
+ public void setAutoMirrored(boolean mirrored) {
+ if (mVectorState.mAutoMirrored != mirrored) {
+ mVectorState.mAutoMirrored = mirrored;
+ invalidateSelf();
+ }
+ }
+
+ @Override
+ public boolean isAutoMirrored() {
+ return mVectorState.mAutoMirrored;
+ }
+
private static class VectorDrawableState extends ConstantState {
int[] mThemeAttrs;
int mChangingConfigurations;
VPathRenderer mVPathRenderer;
ColorStateList mTint;
Mode mTintMode;
+ boolean mAutoMirrored;
Bitmap mCachedBitmap;
int[] mCachedThemeAttrs;
@@ -490,6 +519,7 @@ public class VectorDrawable extends Drawable {
mVPathRenderer = new VPathRenderer(copy.mVPathRenderer);
mTint = copy.mTint;
mTintMode = copy.mTintMode;
+ mAutoMirrored = copy.mAutoMirrored;
}
}
@@ -497,6 +527,7 @@ public class VectorDrawable extends Drawable {
if (mCachedThemeAttrs == mThemeAttrs
&& mCachedTint == mTint
&& mCachedTintMode == mTintMode
+ && mAutoMirrored == mAutoMirrored
&& width == mCachedBitmap.getWidth()
&& height == mCachedBitmap.getHeight()
&& mCachedRootAlpha == mVPathRenderer.getRootAlpha()) {
diff --git a/tests/VectorDrawableTest/AndroidManifest.xml b/tests/VectorDrawableTest/AndroidManifest.xml
index 56fa0a9..a16b749 100644
--- a/tests/VectorDrawableTest/AndroidManifest.xml
+++ b/tests/VectorDrawableTest/AndroidManifest.xml
@@ -22,7 +22,8 @@
<application
android:hardwareAccelerated="true"
- android:label="vector" >
+ android:label="vector"
+ android:supportsRtl="true" >
<activity
android:name="VectorDrawablePerformance"
android:label="Vector Performance" >
diff --git a/tests/VectorDrawableTest/res/drawable/vector_drawable03.xml b/tests/VectorDrawableTest/res/drawable/vector_drawable03.xml
index 5b4c4ab..2fdb676 100644
--- a/tests/VectorDrawableTest/res/drawable/vector_drawable03.xml
+++ b/tests/VectorDrawableTest/res/drawable/vector_drawable03.xml
@@ -13,7 +13,8 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<vector xmlns:android="http://schemas.android.com/apk/res/android" >
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:autoMirrored="true" >
<size
android:height="64dp"
diff --git a/tests/VectorDrawableTest/res/drawable/vector_drawable04.xml b/tests/VectorDrawableTest/res/drawable/vector_drawable04.xml
index 90694fb..296e026 100644
--- a/tests/VectorDrawableTest/res/drawable/vector_drawable04.xml
+++ b/tests/VectorDrawableTest/res/drawable/vector_drawable04.xml
@@ -12,7 +12,8 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<vector xmlns:android="http://schemas.android.com/apk/res/android">
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:autoMirrored="true">
<size
android:width="64dp"
diff --git a/tests/VectorDrawableTest/res/drawable/vector_drawable05.xml b/tests/VectorDrawableTest/res/drawable/vector_drawable05.xml
index c6595fa..1633326 100644
--- a/tests/VectorDrawableTest/res/drawable/vector_drawable05.xml
+++ b/tests/VectorDrawableTest/res/drawable/vector_drawable05.xml
@@ -13,7 +13,8 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<vector xmlns:android="http://schemas.android.com/apk/res/android" >
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:autoMirrored="true">
<size
android:height="64dp"