diff options
| author | 2012-01-09 10:46:03 -0800 | |
|---|---|---|
| committer | 2012-01-09 10:46:03 -0800 | |
| commit | 7d5178e9fbfe6fa8d473ecb7848fba05e90134bd (patch) | |
| tree | 891ff9d9ceefe28d4810c3f7d52bd7d88a8b5185 | |
| parent | 3d00578529966ba3ad8d6440d47d6c506e1fe0fe (diff) | |
| parent | 4c1e00a8c29e532a5b0fce755bead691797eff94 (diff) | |
Merge "Add textDirection="locale""
| -rw-r--r-- | core/java/android/util/LocaleUtil.java | 2 | ||||
| -rw-r--r-- | core/java/android/view/View.java | 20 | ||||
| -rw-r--r-- | core/java/android/widget/TextView.java | 3 | ||||
| -rwxr-xr-x | core/res/res/values/attrs.xml | 2 | ||||
| -rw-r--r-- | core/tests/coretests/src/android/widget/TextViewTest.java | 51 |
5 files changed, 58 insertions, 20 deletions
diff --git a/core/java/android/util/LocaleUtil.java b/core/java/android/util/LocaleUtil.java index 763af73fd502..4d773f678839 100644 --- a/core/java/android/util/LocaleUtil.java +++ b/core/java/android/util/LocaleUtil.java @@ -39,8 +39,6 @@ public class LocaleUtil { */ public static final int TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE = 1; - private static final char UNDERSCORE_CHAR = '_'; - private static String ARAB_SCRIPT_SUBTAG = "Arab"; private static String HEBR_SCRIPT_SUBTAG = "Hebr"; diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index de3f00f2aa82..64f862aa0ea1 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -2626,7 +2626,7 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal /** * Text direction is using "first strong algorithm". The first strong directional character * determines the paragraph direction. If there is no strong directional character, the - * paragraph direction is the view's resolved ayout direction. + * paragraph direction is the view's resolved layout direction. * * @hide */ @@ -2656,6 +2656,13 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal public static final int TEXT_DIRECTION_RTL = 4; /** + * Text direction is coming from the system Locale. + * + * @hide + */ + public static final int TEXT_DIRECTION_LOCALE = 5; + + /** * Default text direction is inherited * * @hide @@ -2672,13 +2679,14 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal @ViewDebug.IntToString(from = TEXT_DIRECTION_FIRST_STRONG, to = "FIRST_STRONG"), @ViewDebug.IntToString(from = TEXT_DIRECTION_ANY_RTL, to = "ANY_RTL"), @ViewDebug.IntToString(from = TEXT_DIRECTION_LTR, to = "LTR"), - @ViewDebug.IntToString(from = TEXT_DIRECTION_RTL, to = "RTL") + @ViewDebug.IntToString(from = TEXT_DIRECTION_RTL, to = "RTL"), + @ViewDebug.IntToString(from = TEXT_DIRECTION_LOCALE, to = "LOCALE") }) private int mTextDirection = DEFAULT_TEXT_DIRECTION; /** * The resolved text direction. This needs resolution if the value is - * TEXT_DIRECTION_INHERIT. The resolution matches mTextDirection if that is + * TEXT_DIRECTION_INHERIT. The resolution matches mTextDirection if it is * not TEXT_DIRECTION_INHERIT, otherwise resolution proceeds up the parent * chain of the view. * @@ -2689,7 +2697,8 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal @ViewDebug.IntToString(from = TEXT_DIRECTION_FIRST_STRONG, to = "FIRST_STRONG"), @ViewDebug.IntToString(from = TEXT_DIRECTION_ANY_RTL, to = "ANY_RTL"), @ViewDebug.IntToString(from = TEXT_DIRECTION_LTR, to = "LTR"), - @ViewDebug.IntToString(from = TEXT_DIRECTION_RTL, to = "RTL") + @ViewDebug.IntToString(from = TEXT_DIRECTION_RTL, to = "RTL"), + @ViewDebug.IntToString(from = TEXT_DIRECTION_LOCALE, to = "LOCALE") }) private int mResolvedTextDirection = TEXT_DIRECTION_INHERIT; @@ -13791,6 +13800,7 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal * {@link #TEXT_DIRECTION_ANY_RTL}, * {@link #TEXT_DIRECTION_LTR}, * {@link #TEXT_DIRECTION_RTL}, + * {@link #TEXT_DIRECTION_LOCALE}, * * @hide */ @@ -13808,6 +13818,7 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal * {@link #TEXT_DIRECTION_ANY_RTL}, * {@link #TEXT_DIRECTION_LTR}, * {@link #TEXT_DIRECTION_RTL}, + * {@link #TEXT_DIRECTION_LOCALE}, * * @hide */ @@ -13828,6 +13839,7 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal * {@link #TEXT_DIRECTION_ANY_RTL}, * {@link #TEXT_DIRECTION_LTR}, * {@link #TEXT_DIRECTION_RTL}, + * {@link #TEXT_DIRECTION_LOCALE}, * * @hide */ diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 81fc069acaf3..3dd7a9f2832e 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -11378,6 +11378,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener case TEXT_DIRECTION_RTL: mTextDir = TextDirectionHeuristics.RTL; break; + case TEXT_DIRECTION_LOCALE: + mTextDir = TextDirectionHeuristics.LOCALE; + break; } } diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index af59198fcef1..fea852382f08 100755 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -2066,6 +2066,8 @@ <enum name="ltr" value="4" /> <!-- The paragraph direction is right to left. --> <enum name="rtl" value="5" /> + <!-- The paragraph direction is coming from the system Locale. --> + <enum name="locale" value="6" /> </attr> </declare-styleable> diff --git a/core/tests/coretests/src/android/widget/TextViewTest.java b/core/tests/coretests/src/android/widget/TextViewTest.java index 5f65fafa21c1..d4dbced42ece 100644 --- a/core/tests/coretests/src/android/widget/TextViewTest.java +++ b/core/tests/coretests/src/android/widget/TextViewTest.java @@ -86,6 +86,9 @@ public class TextViewTest extends ActivityInstrumentationTestCase2<TextViewTestA tv.setTextDirection(View.TEXT_DIRECTION_RTL); assertEquals(View.TEXT_DIRECTION_RTL, tv.getTextDirection()); + + tv.setTextDirection(View.TEXT_DIRECTION_LOCALE); + assertEquals(View.TEXT_DIRECTION_LOCALE, tv.getTextDirection()); } @SmallTest @@ -93,45 +96,53 @@ public class TextViewTest extends ActivityInstrumentationTestCase2<TextViewTestA TextView tv = new TextView(getActivity()); tv.setText("this is a test"); + assertEquals(View.TEXT_DIRECTION_FIRST_STRONG, tv.getResolvedTextDirection()); + tv.setTextDirection(View.TEXT_DIRECTION_FIRST_STRONG); - assertEquals(View.TEXT_DIRECTION_LTR, tv.getResolvedTextDirection()); + assertEquals(View.TEXT_DIRECTION_FIRST_STRONG, tv.getResolvedTextDirection()); tv.setTextDirection(View.TEXT_DIRECTION_ANY_RTL); - assertEquals(View.TEXT_DIRECTION_LTR, tv.getResolvedTextDirection()); + assertEquals(View.TEXT_DIRECTION_ANY_RTL, tv.getResolvedTextDirection()); tv.setTextDirection(View.TEXT_DIRECTION_INHERIT); - assertEquals(View.TEXT_DIRECTION_LTR, tv.getResolvedTextDirection()); + assertEquals(View.TEXT_DIRECTION_FIRST_STRONG, tv.getResolvedTextDirection()); tv.setTextDirection(View.TEXT_DIRECTION_LTR); assertEquals(View.TEXT_DIRECTION_LTR, tv.getResolvedTextDirection()); tv.setTextDirection(View.TEXT_DIRECTION_RTL); assertEquals(View.TEXT_DIRECTION_RTL, tv.getResolvedTextDirection()); + + tv.setTextDirection(View.TEXT_DIRECTION_LOCALE); + assertEquals(View.TEXT_DIRECTION_LOCALE, tv.getResolvedTextDirection()); } @SmallTest public void testGetResolvedTextDirectionLtrWithInheritance() { LinearLayout ll = new LinearLayout(getActivity()); - ll.setTextDirection(View.TEXT_DIRECTION_RTL); + ll.setTextDirection(View.TEXT_DIRECTION_ANY_RTL); TextView tv = new TextView(getActivity()); tv.setText("this is a test"); ll.addView(tv); tv.setTextDirection(View.TEXT_DIRECTION_FIRST_STRONG); - assertEquals(View.TEXT_DIRECTION_LTR, tv.getResolvedTextDirection()); + assertEquals(View.TEXT_DIRECTION_FIRST_STRONG, tv.getResolvedTextDirection()); tv.setTextDirection(View.TEXT_DIRECTION_ANY_RTL); - assertEquals(View.TEXT_DIRECTION_LTR, tv.getResolvedTextDirection()); + assertEquals(View.TEXT_DIRECTION_ANY_RTL, tv.getResolvedTextDirection()); tv.setTextDirection(View.TEXT_DIRECTION_INHERIT); - assertEquals(View.TEXT_DIRECTION_RTL, tv.getResolvedTextDirection()); + assertEquals(View.TEXT_DIRECTION_ANY_RTL, tv.getResolvedTextDirection()); tv.setTextDirection(View.TEXT_DIRECTION_LTR); assertEquals(View.TEXT_DIRECTION_LTR, tv.getResolvedTextDirection()); tv.setTextDirection(View.TEXT_DIRECTION_RTL); assertEquals(View.TEXT_DIRECTION_RTL, tv.getResolvedTextDirection()); + + tv.setTextDirection(View.TEXT_DIRECTION_LOCALE); + assertEquals(View.TEXT_DIRECTION_LOCALE, tv.getResolvedTextDirection()); } @SmallTest @@ -139,35 +150,41 @@ public class TextViewTest extends ActivityInstrumentationTestCase2<TextViewTestA TextView tv = new TextView(getActivity()); tv.setText("\u05DD\u05DE"); // hebrew + assertEquals(View.TEXT_DIRECTION_FIRST_STRONG, tv.getResolvedTextDirection()); + tv.setTextDirection(View.TEXT_DIRECTION_FIRST_STRONG); - assertEquals(View.TEXT_DIRECTION_RTL, tv.getResolvedTextDirection()); + assertEquals(View.TEXT_DIRECTION_FIRST_STRONG, tv.getResolvedTextDirection()); tv.setTextDirection(View.TEXT_DIRECTION_ANY_RTL); - assertEquals(View.TEXT_DIRECTION_RTL, tv.getResolvedTextDirection()); + assertEquals(View.TEXT_DIRECTION_ANY_RTL, tv.getResolvedTextDirection()); tv.setTextDirection(View.TEXT_DIRECTION_INHERIT); - assertEquals(View.TEXT_DIRECTION_LTR, tv.getResolvedTextDirection()); + assertEquals(View.TEXT_DIRECTION_FIRST_STRONG, tv.getResolvedTextDirection()); tv.setTextDirection(View.TEXT_DIRECTION_LTR); assertEquals(View.TEXT_DIRECTION_LTR, tv.getResolvedTextDirection()); tv.setTextDirection(View.TEXT_DIRECTION_RTL); assertEquals(View.TEXT_DIRECTION_RTL, tv.getResolvedTextDirection()); + + tv.setTextDirection(View.TEXT_DIRECTION_LOCALE); + assertEquals(View.TEXT_DIRECTION_LOCALE, tv.getResolvedTextDirection()); } @SmallTest public void testGetResolvedTextDirectionRtlWithInheritance() { LinearLayout ll = new LinearLayout(getActivity()); + ll.setTextDirection(View.TEXT_DIRECTION_FIRST_STRONG); TextView tv = new TextView(getActivity()); tv.setText("\u05DD\u05DE"); // hebrew ll.addView(tv); tv.setTextDirection(View.TEXT_DIRECTION_FIRST_STRONG); - assertEquals(View.TEXT_DIRECTION_RTL, tv.getResolvedTextDirection()); + assertEquals(View.TEXT_DIRECTION_FIRST_STRONG, tv.getResolvedTextDirection()); tv.setTextDirection(View.TEXT_DIRECTION_ANY_RTL); - assertEquals(View.TEXT_DIRECTION_RTL, tv.getResolvedTextDirection()); + assertEquals(View.TEXT_DIRECTION_ANY_RTL, tv.getResolvedTextDirection()); tv.setTextDirection(View.TEXT_DIRECTION_INHERIT); assertEquals(View.TEXT_DIRECTION_FIRST_STRONG, tv.getResolvedTextDirection()); @@ -178,14 +195,17 @@ public class TextViewTest extends ActivityInstrumentationTestCase2<TextViewTestA tv.setTextDirection(View.TEXT_DIRECTION_RTL); assertEquals(View.TEXT_DIRECTION_RTL, tv.getResolvedTextDirection()); + tv.setTextDirection(View.TEXT_DIRECTION_LOCALE); + assertEquals(View.TEXT_DIRECTION_LOCALE, tv.getResolvedTextDirection()); + // Force to RTL text direction on the layout ll.setTextDirection(View.TEXT_DIRECTION_RTL); tv.setTextDirection(View.TEXT_DIRECTION_FIRST_STRONG); - assertEquals(View.TEXT_DIRECTION_RTL, tv.getResolvedTextDirection()); + assertEquals(View.TEXT_DIRECTION_FIRST_STRONG, tv.getResolvedTextDirection()); tv.setTextDirection(View.TEXT_DIRECTION_ANY_RTL); - assertEquals(View.TEXT_DIRECTION_RTL, tv.getResolvedTextDirection()); + assertEquals(View.TEXT_DIRECTION_ANY_RTL, tv.getResolvedTextDirection()); tv.setTextDirection(View.TEXT_DIRECTION_INHERIT); assertEquals(View.TEXT_DIRECTION_RTL, tv.getResolvedTextDirection()); @@ -195,6 +215,9 @@ public class TextViewTest extends ActivityInstrumentationTestCase2<TextViewTestA tv.setTextDirection(View.TEXT_DIRECTION_RTL); assertEquals(View.TEXT_DIRECTION_RTL, tv.getResolvedTextDirection()); + + tv.setTextDirection(View.TEXT_DIRECTION_LOCALE); + assertEquals(View.TEXT_DIRECTION_LOCALE, tv.getResolvedTextDirection()); } @SmallTest |