summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorFabrice Di Meglio <fdimeglio@google.com>2013-06-24 19:22:25 -0700
committerFabrice Di Meglio <fdimeglio@google.com>2013-08-01 15:15:10 -0700
commit3f5a90b2fbba2a83a8a2c5babd5d466a5e0ad2aa (patch)
tree666fee2554ad0f795380960d425606804e8b7ede /core
parent851761574a775c6447ab2393d1ba42568ba08c1b (diff)
downloadframeworks_base-3f5a90b2fbba2a83a8a2c5babd5d466a5e0ad2aa.zip
frameworks_base-3f5a90b2fbba2a83a8a2c5babd5d466a5e0ad2aa.tar.gz
frameworks_base-3f5a90b2fbba2a83a8a2c5babd5d466a5e0ad2aa.tar.bz2
Add automatic Drawable mirroring capability when in RTL layout direction
- default value is "no mirroring" - introduce android:autoMirrored as a new attribute for Drawable, BitmapDrawable, LayerDrawable, StateListDrawable and NinePatchDrawable - setting android:autoMirrored="true" means that the drawable will be mirrored when the layout direction is RTL (right-to-left) - also fix an issue with ImageView drawable layout direction not updated correctly when RTL properties were changed See bug #7034321 Need Drawable RTL support Change-Id: If595ee5106c786f38e786d3a032e182f784a9d97
Diffstat (limited to 'core')
-rw-r--r--core/java/android/util/LayoutDirection.java44
-rw-r--r--core/java/android/view/View.java9
-rw-r--r--core/java/android/widget/ImageView.java9
-rw-r--r--core/java/android/widget/TextView.java2
-rw-r--r--core/res/res/values/attrs.xml16
-rw-r--r--core/res/res/values/public.xml2
6 files changed, 78 insertions, 4 deletions
diff --git a/core/java/android/util/LayoutDirection.java b/core/java/android/util/LayoutDirection.java
new file mode 100644
index 0000000..e37d2f2
--- /dev/null
+++ b/core/java/android/util/LayoutDirection.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.util;
+
+/**
+ * An interface for defining layout directions. A layout direction can be left-to-right (LTR)
+ * or right-to-left (RTL). It can also be inherited (from a parent) or deduced from the default
+ * language script of a locale.
+ */
+public interface LayoutDirection {
+ /**
+ * Horizontal layout direction is from Left to Right.
+ */
+ public static final int LTR = 0;
+
+ /**
+ * Horizontal layout direction is from Right to Left.
+ */
+ public static final int RTL = 1;
+
+ /**
+ * Horizontal layout direction is inherited.
+ */
+ public static final int INHERIT = 2;
+
+ /**
+ * Horizontal layout direction is deduced from the default language script for the locale.
+ */
+ public static final int LOCALE = 3;
+}
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 299c4a2..7624b56 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -51,6 +51,7 @@ import android.os.SystemProperties;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.FloatProperty;
+import android.util.LayoutDirection;
import android.util.Log;
import android.util.LongSparseLongArray;
import android.util.Pools.SynchronizedPool;
@@ -1801,25 +1802,25 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* Horizontal layout direction of this view is from Left to Right.
* Use with {@link #setLayoutDirection}.
*/
- public static final int LAYOUT_DIRECTION_LTR = 0;
+ public static final int LAYOUT_DIRECTION_LTR = LayoutDirection.LTR;
/**
* Horizontal layout direction of this view is from Right to Left.
* Use with {@link #setLayoutDirection}.
*/
- public static final int LAYOUT_DIRECTION_RTL = 1;
+ public static final int LAYOUT_DIRECTION_RTL = LayoutDirection.RTL;
/**
* Horizontal layout direction of this view is inherited from its parent.
* Use with {@link #setLayoutDirection}.
*/
- public static final int LAYOUT_DIRECTION_INHERIT = 2;
+ public static final int LAYOUT_DIRECTION_INHERIT = LayoutDirection.INHERIT;
/**
* Horizontal layout direction of this view is from deduced from the default language
* script for the locale. Use with {@link #setLayoutDirection}.
*/
- public static final int LAYOUT_DIRECTION_LOCALE = 3;
+ public static final int LAYOUT_DIRECTION_LOCALE = LayoutDirection.LOCALE;
/**
* Bit shift to get the horizontal layout direction. (bits after DRAG_HOVERED)
diff --git a/core/java/android/widget/ImageView.java b/core/java/android/widget/ImageView.java
index 33fd8ce..3e53b91 100644
--- a/core/java/android/widget/ImageView.java
+++ b/core/java/android/widget/ImageView.java
@@ -732,6 +732,15 @@ public class ImageView extends View {
}
}
+ @Override
+ public void onRtlPropertiesChanged(int layoutDirection) {
+ super.onRtlPropertiesChanged(layoutDirection);
+
+ if (mDrawable != null) {
+ mDrawable.setLayoutDirection(layoutDirection);
+ }
+ }
+
private static final Matrix.ScaleToFit[] sS2FArray = {
Matrix.ScaleToFit.FILL,
Matrix.ScaleToFit.START,
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 816bb18..3181164 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -2042,6 +2042,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
dr.mDrawableRightInitial = right;
}
+ resetResolvedDrawables();
+ resolveDrawables();
invalidate();
requestLayout();
}
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index 2096f66..67a32fd 100644
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -3905,6 +3905,10 @@
value is false. See
{@link android.graphics.drawable.Drawable#setVisible}. -->
<attr name="visible" format="boolean" />
+ <!-- Indicates if the drawable needs to be mirrored when its layout direction is
+ RTL (right-to-left). See
+ {@link android.graphics.drawable.Drawable#setAutoMirrored}. -->
+ <attr name="autoMirrored" format="boolean" />
</declare-styleable>
<!-- Drawable used to render several states. Each state is represented by
@@ -3932,6 +3936,9 @@
<attr name="enterFadeDuration" format="integer" />
<!-- Amount of time (in milliseconds) to fade out an old state drawable. -->
<attr name="exitFadeDuration" format="integer" />
+ <!-- Indicates if the drawable needs to be mirrored when its layout direction is
+ RTL (right-to-left). -->
+ <attr name="autoMirrored"/>
</declare-styleable>
<!-- Drawable used to render several animated frames. -->
@@ -4083,6 +4090,9 @@
<!-- The layer has translucent pixels. -->
<enum name="translucent" value="-3" />
</attr>
+ <!-- Indicates if the drawable needs to be mirrored when its layout direction is
+ RTL (right-to-left). -->
+ <attr name="autoMirrored" />
</declare-styleable>
<!-- Describes an item (or child) of a LayerDrawable. -->
@@ -4172,6 +4182,9 @@
{@link android.graphics.Bitmap#setHasMipMap(boolean)} for more information.
Default value is false. -->
<attr name="mipMap" format="boolean" />
+ <!-- Indicates if the drawable needs to be mirrored when its layout direction is
+ RTL (right-to-left). -->
+ <attr name="autoMirrored" />
</declare-styleable>
<!-- Drawable used to draw 9-patches. -->
@@ -4182,6 +4195,9 @@
same pixel configuration as the screen (for instance: a ARGB 8888 bitmap with
an RGB 565 screen). -->
<attr name="dither" />
+ <!-- Indicates if the drawable needs to be mirrored when its layout direction is
+ RTL (right-to-left). -->
+ <attr name="autoMirrored" />
</declare-styleable>
<!-- Drawable used to draw a single color. -->
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index 0eaab65..80c9184 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -2071,4 +2071,6 @@
<public type="attr" name="category" />
<public type="attr" name="isAsciiCapable" />
<public type="attr" name="customRoots" />
+ <public type="attr" name="autoMirrored" />
+
</resources>