OSDN Git Service

Fix View reset of layoutDirection and textDirection
authorFabrice Di Meglio <fdimeglio@google.com>
Fri, 1 Jul 2011 22:09:24 +0000 (15:09 -0700)
committerFabrice Di Meglio <fdimeglio@google.com>
Mon, 11 Jul 2011 17:39:29 +0000 (10:39 -0700)
- do it in onDetachedFromWindow()
- make naming consistent too
- update unit tests

Change-Id: I320fcdbf75166bae793c4409e7344608b696667f

api/current.txt
core/java/android/view/View.java
core/java/android/view/ViewGroup.java
core/java/android/widget/TextView.java
core/tests/coretests/AndroidManifest.xml
core/tests/coretests/res/layout/textview_test.xml [new file with mode: 0644]
core/tests/coretests/res/values/strings.xml
core/tests/coretests/src/android/widget/TextViewTest.java
core/tests/coretests/src/android/widget/TextViewTestActivity.java [new file with mode: 0644]

index 559672f..2923805 100644 (file)
@@ -22740,7 +22740,7 @@ package android.view {
     method public void requestDisallowInterceptTouchEvent(boolean);
     method public boolean requestSendAccessibilityEvent(android.view.View, android.view.accessibility.AccessibilityEvent);
     method public void requestTransparentRegion(android.view.View);
-    method protected void resetLayoutDirectionResolution();
+    method protected void resetResolvedLayoutDirection();
     method public void scheduleLayoutAnimation();
     method public void setAddStatesFromChildren(boolean);
     method public void setAlwaysDrawnWithCacheEnabled(boolean);
@@ -26417,7 +26417,7 @@ package android.widget {
     method protected void onTextChanged(java.lang.CharSequence, int, int, int);
     method public boolean onTextContextMenuItem(int);
     method public void removeTextChangedListener(android.text.TextWatcher);
-    method protected void resetLayoutDirectionResolution();
+    method protected void resetResolvedLayoutDirection();
     method public void setAllCaps(boolean);
     method public final void setAutoLinkMask(int);
     method public void setCompoundDrawablePadding(int);
index 1245898..74dc100 100644 (file)
@@ -4474,7 +4474,7 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit
     @RemotableViewMethod
     public void setLayoutDirection(int layoutDirection) {
         if (getLayoutDirection() != layoutDirection) {
-            resetLayoutDirectionResolution();
+            resetResolvedLayoutDirection();
             // Setting the flag will also request a layout.
             setFlags(layoutDirection, LAYOUT_DIRECTION_MASK);
         }
@@ -9043,10 +9043,8 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit
             mPrivateFlags &= ~AWAKEN_SCROLL_BARS_ON_ATTACH;
         }
         jumpDrawablesToCurrentState();
-        resetLayoutDirectionResolution();
         resolveLayoutDirectionIfNeeded();
         resolvePadding();
-        resetResolvedTextDirection();
         resolveTextDirection();
         if (isFocused()) {
             InputMethodManager imm = InputMethodManager.peekInstance();
@@ -9143,7 +9141,7 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit
      *
      * @hide
      */
-    protected void resetLayoutDirectionResolution() {
+    protected void resetResolvedLayoutDirection() {
         // Reset the current View resolution
         mPrivateFlags2 &= ~LAYOUT_DIRECTION_RESOLVED;
     }
@@ -9190,6 +9188,9 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit
         }
 
         mCurrentAnimation = null;
+
+        resetResolvedLayoutDirection();
+        resetResolvedTextDirection();
     }
 
     /**
index e6fdb17..752fd5a 100644 (file)
@@ -4999,15 +4999,15 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
     }
 
     @Override
-    protected void resetLayoutDirectionResolution() {
-        super.resetLayoutDirectionResolution();
+    protected void resetResolvedLayoutDirection() {
+        super.resetResolvedLayoutDirection();
 
         // Take care of resetting the children resolution too
         final int count = getChildCount();
         for (int i = 0; i < count; i++) {
             final View child = getChildAt(i);
             if (child.getLayoutDirection() == LAYOUT_DIRECTION_INHERIT) {
-                child.resetLayoutDirectionResolution();
+                child.resetResolvedLayoutDirection();
             }
         }
     }
index 1e63e26..e350ec4 100644 (file)
@@ -5571,8 +5571,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
     }
 
     @Override
-    protected void resetLayoutDirectionResolution() {
-        super.resetLayoutDirectionResolution();
+    protected void resetResolvedLayoutDirection() {
+        super.resetResolvedLayoutDirection();
 
         if (mLayoutAlignment != null &&
                 (mTextAlign == TextAlign.VIEW_START ||
index 8e2d925..40fa552 100644 (file)
             </intent-filter>
         </activity>
 
+        <activity android:name="android.widget.TextViewTestActivity" android:label="TextViewTestActivity">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST" />
+            </intent-filter>
+        </activity>
+
 
 
         <!-- Activity-level metadata -->
diff --git a/core/tests/coretests/res/layout/textview_test.xml b/core/tests/coretests/res/layout/textview_test.xml
new file mode 100644 (file)
index 0000000..f0c7b9e
--- /dev/null
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 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.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+              android:id="@+id/textviewtest_layout"
+              android:layout_width="fill_parent"
+              android:layout_height="fill_parent">
+
+    <TextView android:id="@+id/textviewtest_textview"
+              android:layout_height="wrap_content"
+              android:layout_width="wrap_content"
+              android:text="@string/textview_hebrew_text"/>
+
+</LinearLayout>
\ No newline at end of file
index f51b08e..71f3520 100644 (file)
     <string name="button8">Button8</string>
     <string name="button9">Button9</string>
 
+    <string name="textview_hebrew_text">&#x05DD;&#x05DE;ab?!</string>
+
 </resources>
index 6db67c0..c54e4a1 100644 (file)
 
 package android.widget;
 
-import com.google.android.collect.Lists;
-import com.google.android.collect.Maps;
+import com.android.frameworks.coretests.R;
 
-import android.test.AndroidTestCase;
+import android.test.ActivityInstrumentationTestCase2;
 import android.test.suitebuilder.annotation.SmallTest;
 import android.text.GetChars;
 import android.view.View;
-import android.widget.TextView;
 
 /**
  * TextViewTest tests {@link TextView}.
  */
-public class TextViewTest extends AndroidTestCase {
+public class TextViewTest extends ActivityInstrumentationTestCase2<TextViewTestActivity> {
+
+    public TextViewTest() {
+        super(TextViewTestActivity.class);
+    }
 
     @SmallTest
     public void testArray() throws Exception {
-        TextView tv = new TextView(mContext);
+        TextView tv = new TextView(getActivity());
 
         char[] c = new char[] { 'H', 'e', 'l', 'l', 'o', ' ',
                                 'W', 'o', 'r', 'l', 'd', '!' };
@@ -62,13 +64,13 @@ public class TextViewTest extends AndroidTestCase {
 
     @SmallTest
     public void testTextDirectionDefault() {
-        TextView tv = new TextView(mContext);
+        TextView tv = new TextView(getActivity());
         assertEquals(View.TEXT_DIRECTION_INHERIT, tv.getTextDirection());
     }
 
     @SmallTest
     public void testSetGetTextDirection() {
-        TextView tv = new TextView(mContext);
+        TextView tv = new TextView(getActivity());
 
         tv.setTextDirection(View.TEXT_DIRECTION_FIRST_STRONG);
         assertEquals(View.TEXT_DIRECTION_FIRST_STRONG, tv.getTextDirection());
@@ -88,7 +90,7 @@ public class TextViewTest extends AndroidTestCase {
 
     @SmallTest
     public void testGetResolvedTextDirectionLtr() {
-        TextView tv = new TextView(mContext);
+        TextView tv = new TextView(getActivity());
         tv.setText("this is a test");
 
         tv.setTextDirection(View.TEXT_DIRECTION_FIRST_STRONG);
@@ -109,10 +111,10 @@ public class TextViewTest extends AndroidTestCase {
 
     @SmallTest
     public void testGetResolvedTextDirectionLtrWithInheritance() {
-        LinearLayout ll = new LinearLayout(mContext);
+        LinearLayout ll = new LinearLayout(getActivity());
         ll.setTextDirection(View.TEXT_DIRECTION_RTL);
 
-        TextView tv = new TextView(mContext);
+        TextView tv = new TextView(getActivity());
         tv.setText("this is a test");
         ll.addView(tv);
 
@@ -134,7 +136,7 @@ public class TextViewTest extends AndroidTestCase {
 
     @SmallTest
     public void testGetResolvedTextDirectionRtl() {
-        TextView tv = new TextView(mContext);
+        TextView tv = new TextView(getActivity());
         tv.setText("\u05DD\u05DE"); // hebrew
 
         tv.setTextDirection(View.TEXT_DIRECTION_FIRST_STRONG);
@@ -155,10 +157,9 @@ public class TextViewTest extends AndroidTestCase {
 
     @SmallTest
     public void testGetResolvedTextDirectionRtlWithInheritance() {
-        LinearLayout ll = new LinearLayout(mContext);
-        ll.setTextDirection(View.TEXT_DIRECTION_RTL);
+        LinearLayout ll = new LinearLayout(getActivity());
 
-        TextView tv = new TextView(mContext);
+        TextView tv = new TextView(getActivity());
         tv.setText("\u05DD\u05DE"); // hebrew
         ll.addView(tv);
 
@@ -169,6 +170,24 @@ public class TextViewTest extends AndroidTestCase {
         assertEquals(View.TEXT_DIRECTION_RTL, tv.getResolvedTextDirection());
 
         tv.setTextDirection(View.TEXT_DIRECTION_INHERIT);
+        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());
+
+        // 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());
+
+        tv.setTextDirection(View.TEXT_DIRECTION_ANY_RTL);
+        assertEquals(View.TEXT_DIRECTION_RTL, tv.getResolvedTextDirection());
+
+        tv.setTextDirection(View.TEXT_DIRECTION_INHERIT);
         assertEquals(View.TEXT_DIRECTION_RTL, tv.getResolvedTextDirection());
 
         tv.setTextDirection(View.TEXT_DIRECTION_LTR);
@@ -180,10 +199,10 @@ public class TextViewTest extends AndroidTestCase {
 
     @SmallTest
     public void testCharCountHeuristic() {
-        LinearLayout ll = new LinearLayout(mContext);
+        LinearLayout ll = new LinearLayout(getActivity());
         ll.setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
 
-        TextView tv = new TextView(mContext);
+        TextView tv = new TextView(getActivity());
         ll.addView(tv);
 
         tv.setTextDirection(View.TEXT_DIRECTION_CHAR_COUNT);
@@ -211,4 +230,23 @@ public class TextViewTest extends AndroidTestCase {
         tv.setText("ab \u05DD\u05DE"); // latin + hebrew at 50% each
         assertEquals(View.TEXT_DIRECTION_RTL, tv.getResolvedTextDirection());
     }
+
+    @SmallTest
+    public void testResetTextDirection() {
+        final TextViewTestActivity activity = getActivity();
+
+        final LinearLayout ll = (LinearLayout) activity.findViewById(R.id.textviewtest_layout);
+        final TextView tv = (TextView) activity.findViewById(R.id.textviewtest_textview);
+
+        getActivity().runOnUiThread(new Runnable() {
+            public void run() {
+                tv.setTextDirection(View.TEXT_DIRECTION_FIRST_STRONG);
+                assertEquals(View.TEXT_DIRECTION_RTL, tv.getResolvedTextDirection());
+                assertEquals(true, tv.isResolvedTextDirection());
+
+                ll.removeView(tv);
+                assertEquals(false, tv.isResolvedTextDirection());
+            }
+        });
+    }
 }
diff --git a/core/tests/coretests/src/android/widget/TextViewTestActivity.java b/core/tests/coretests/src/android/widget/TextViewTestActivity.java
new file mode 100644 (file)
index 0000000..1bb4d24
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2011 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.widget;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+import com.android.frameworks.coretests.R;
+
+public class TextViewTestActivity extends Activity {
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.textview_test);
+    }
+}