OSDN Git Service

Pass text direction from DynamicLayout to Layout
authorRoozbeh Pournader <roozbeh@google.com>
Wed, 20 Sep 2017 23:07:13 +0000 (16:07 -0700)
committerRoozbeh Pournader <roozbeh@google.com>
Wed, 20 Sep 2017 23:31:35 +0000 (16:31 -0700)
Previously, we were calling the wrong constructor for Layout, which
didn't have a text direction.

Bug: 65330510
Test: bit FrameworksCoreTests:android.widget.EditorCursorTest
Test: bit FrameworksCoreTests:android.text.DynamicLayoutTest
Test: bit CtsTextTestCases:android.text.cts.DynamicLayoutTest
Change-Id: Idf0ac781dc8d6641184b7deabe990cd0e451ad26

core/java/android/text/DynamicLayout.java
core/tests/coretests/src/android/text/DynamicLayoutTest.java

index 5e40935..24260c4 100644 (file)
@@ -384,7 +384,7 @@ public class DynamicLayout extends Layout
 
     private DynamicLayout(@NonNull Builder b) {
         super(createEllipsizer(b.mEllipsize, b.mDisplay),
-                b.mPaint, b.mWidth, b.mAlignment, b.mSpacingMult, b.mSpacingAdd);
+                b.mPaint, b.mWidth, b.mAlignment, b.mTextDir, b.mSpacingMult, b.mSpacingAdd);
 
         mDisplay = b.mDisplay;
         mIncludePad = b.mIncludePad;
index ed6bfbf..639cefb 100644 (file)
@@ -259,4 +259,21 @@ public class DynamicLayoutTest {
             assertEquals(2 * textSize, layout.getLineDescent(2));
         }
     }
+
+    @Test
+    public void testBuilder_defaultTextDirection() {
+        final DynamicLayout.Builder builder = DynamicLayout.Builder
+                .obtain("", new TextPaint(), WIDTH);
+        final DynamicLayout layout = builder.build();
+        assertEquals(TextDirectionHeuristics.FIRSTSTRONG_LTR, layout.getTextDirectionHeuristic());
+    }
+
+    @Test
+    public void testBuilder_setTextDirection() {
+        final DynamicLayout.Builder builder = DynamicLayout.Builder
+                .obtain("", new TextPaint(), WIDTH)
+                .setTextDirection(TextDirectionHeuristics.ANYRTL_LTR);
+        final DynamicLayout layout = builder.build();
+        assertEquals(TextDirectionHeuristics.ANYRTL_LTR, layout.getTextDirectionHeuristic());
+    }
 }