Fix bidi desired width calculation

Layout.getDesiredWidth measured text with TextDirectionHeuristics.LTR,
whereas the real calculations used the active direction heuristic set
in the TextView instance. This CL uses the same heuristics for both of
them by passing the value to Layout.getDesiredWidth function.

Bug: 28845953
Change-Id: I68d23f55fe5a86255d62e83bc62df38a047e4bca
diff --git a/core/java/android/widget/Switch.java b/core/java/android/widget/Switch.java
index c4a1771..eb81e6f 100644
--- a/core/java/android/widget/Switch.java
+++ b/core/java/android/widget/Switch.java
@@ -889,8 +889,9 @@
                     ? mSwitchTransformationMethod.getTransformation(text, this)
                     : text;
 
-        return new StaticLayout(transformed, mTextPaint,
-                (int) Math.ceil(Layout.getDesiredWidth(transformed, mTextPaint)),
+        int width = (int) Math.ceil(Layout.getDesiredWidth(transformed, 0,
+                transformed.length(), mTextPaint, getTextDirectionHeuristic()));
+        return new StaticLayout(transformed, mTextPaint, width,
                 Layout.Alignment.ALIGN_NORMAL, 1.f, 0, true);
     }