Loading core/java/android/text/BoringLayout.java +1 −1 Original line number Diff line number Diff line Loading @@ -280,7 +280,7 @@ public class BoringLayout extends Layout implements TextUtils.EllipsizeCallback } } if (textDir.isRtl(temp, 0, n)) { if (textDir != null && textDir.isRtl(temp, 0, n)) { boring = false; break outer; } Loading core/java/android/text/TextDirectionHeuristic.java +15 −2 Original line number Diff line number Diff line // Copyright 2011 Google Inc. All Rights Reserved. /* * 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.text; Loading @@ -8,6 +22,5 @@ package android.text; * @hide */ public interface TextDirectionHeuristic { /** @hide */ boolean isRtl(CharSequence text, int start, int end); /** @hide */ boolean isRtl(char[] text, int start, int count); } core/java/android/text/TextDirectionHeuristics.java +35 −18 Original line number Diff line number Diff line // Copyright 2011 Google Inc. All Rights Reserved. /* * 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.text; Loading Loading @@ -36,12 +50,12 @@ public class TextDirectionHeuristics { new TextDirectionHeuristicInternal(FirstStrong.INSTANCE, true); /** * If the text contains any strong right to left non-format character, determines * that the direction is right to left, falling back to left to right if it * If the text contains any strong left to right non-format character, determines * that the direction is left to right, falling back to left to right if it * finds none. */ public static final TextDirectionHeuristic ANYRTL_LTR = new TextDirectionHeuristicInternal(AnyStrong.INSTANCE_RTL, false); public static final TextDirectionHeuristic ANYLTR_LTR = new TextDirectionHeuristicInternal(AnyStrong.INSTANCE_LTR, false); /** * If the text contains any strong left to right non-format character, determines Loading @@ -51,6 +65,22 @@ public class TextDirectionHeuristics { public static final TextDirectionHeuristic ANYLTR_RTL = new TextDirectionHeuristicInternal(AnyStrong.INSTANCE_LTR, true); /** * If the text contains any strong right to left non-format character, determines * that the direction is right to left, falling back to left to right if it * finds none. */ public static final TextDirectionHeuristic ANYRTL_LTR = new TextDirectionHeuristicInternal(AnyStrong.INSTANCE_RTL, false); /** * If the text contains any strong right to left non-format character, determines * that the direction is right to left, falling back to right to left if it * finds none. */ public static final TextDirectionHeuristic ANYRTL_RTL = new TextDirectionHeuristicInternal(AnyStrong.INSTANCE_RTL, true); /** * Examines only the strong directional non-format characters, and if either * left to right or right to left characters are 60% or more of this total, Loading Loading @@ -91,19 +121,6 @@ public class TextDirectionHeuristics { */ abstract protected boolean defaultIsRtl(); @Override public boolean isRtl(CharSequence text, int start, int end) { if (text == null || start < 0 || end < start || text.length() < end) { throw new IllegalArgumentException(); } if (mAlgorithm == null) { return defaultIsRtl(); } text = text.subSequence(start, end); char[] chars = text.toString().toCharArray(); return doCheck(chars, 0, chars.length); } @Override public boolean isRtl(char[] chars, int start, int count) { if (chars == null || start < 0 || count < 0 || chars.length - count < start) { Loading core/java/android/view/View.java +5 −0 Original line number Diff line number Diff line Loading @@ -9165,6 +9165,7 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit mPrivateFlags &= ~AWAKEN_SCROLL_BARS_ON_ATTACH; } jumpDrawablesToCurrentState(); // Order is important here: LayoutDirection should be resolved before Padding and TextDirection resolveLayoutDirectionIfNeeded(); resolvePadding(); resolveTextDirection(); Loading @@ -9185,6 +9186,10 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit // Clear any previous layout direction resolution mPrivateFlags2 &= ~LAYOUT_DIRECTION_RESOLVED_RTL; // Reset also TextDirection as a change into LayoutDirection may impact the selected // TextDirectionHeuristic resetResolvedTextDirection(); // Set resolved depending on layout direction switch (getLayoutDirection()) { case LAYOUT_DIRECTION_INHERIT: Loading core/java/android/widget/TextView.java +11 −25 Original line number Diff line number Diff line Loading @@ -10728,42 +10728,29 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener return mInBatchEditControllers; } private class TextViewDirectionHeuristic extends TextDirectionHeuristicImpl { private TextViewDirectionHeuristic(TextDirectionAlgorithm algorithm) { super(algorithm); } @Override protected boolean defaultIsRtl() { return getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL; } } /** * Resolve the text direction. * * Text direction of paragraphs in a TextView is determined using a heuristic. If the correct * text direction cannot be determined by the heuristic, the view's resolved layout direction * determines the direction. * * This heuristic and result is applied individually to each paragraph in a TextView, based on * the text and style content of that paragraph. Paragraph text styles can also be used to force * a particular direction. */ @Override protected void resolveTextDirection() { // Always need to resolve layout direction first final boolean defaultIsRtl = (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL); // Then resolve text direction on the parent super.resolveTextDirection(); // Now, we can select the heuristic int textDir = getResolvedTextDirection(); switch (textDir) { default: case TEXT_DIRECTION_FIRST_STRONG: mTextDir = new TextViewDirectionHeuristic(FirstStrong.INSTANCE); mTextDir = (defaultIsRtl ? TextDirectionHeuristics.FIRSTSTRONG_RTL : TextDirectionHeuristics.FIRSTSTRONG_LTR); break; case TEXT_DIRECTION_ANY_RTL: mTextDir = new TextViewDirectionHeuristic(AnyStrong.INSTANCE_RTL); mTextDir = (defaultIsRtl ? TextDirectionHeuristics.ANYRTL_RTL: TextDirectionHeuristics.ANYRTL_LTR); break; case TEXT_DIRECTION_CHAR_COUNT: mTextDir = new TextViewDirectionHeuristic(CharCount.INSTANCE_DEFAULT); mTextDir = (defaultIsRtl ? TextDirectionHeuristics.CHARCOUNT_RTL: TextDirectionHeuristics.CHARCOUNT_LTR); break; case TEXT_DIRECTION_LTR: mTextDir = TextDirectionHeuristics.LTR; Loading @@ -10772,7 +10759,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener mTextDir = TextDirectionHeuristics.RTL; break; } } /** Loading Loading
core/java/android/text/BoringLayout.java +1 −1 Original line number Diff line number Diff line Loading @@ -280,7 +280,7 @@ public class BoringLayout extends Layout implements TextUtils.EllipsizeCallback } } if (textDir.isRtl(temp, 0, n)) { if (textDir != null && textDir.isRtl(temp, 0, n)) { boring = false; break outer; } Loading
core/java/android/text/TextDirectionHeuristic.java +15 −2 Original line number Diff line number Diff line // Copyright 2011 Google Inc. All Rights Reserved. /* * 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.text; Loading @@ -8,6 +22,5 @@ package android.text; * @hide */ public interface TextDirectionHeuristic { /** @hide */ boolean isRtl(CharSequence text, int start, int end); /** @hide */ boolean isRtl(char[] text, int start, int count); }
core/java/android/text/TextDirectionHeuristics.java +35 −18 Original line number Diff line number Diff line // Copyright 2011 Google Inc. All Rights Reserved. /* * 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.text; Loading Loading @@ -36,12 +50,12 @@ public class TextDirectionHeuristics { new TextDirectionHeuristicInternal(FirstStrong.INSTANCE, true); /** * If the text contains any strong right to left non-format character, determines * that the direction is right to left, falling back to left to right if it * If the text contains any strong left to right non-format character, determines * that the direction is left to right, falling back to left to right if it * finds none. */ public static final TextDirectionHeuristic ANYRTL_LTR = new TextDirectionHeuristicInternal(AnyStrong.INSTANCE_RTL, false); public static final TextDirectionHeuristic ANYLTR_LTR = new TextDirectionHeuristicInternal(AnyStrong.INSTANCE_LTR, false); /** * If the text contains any strong left to right non-format character, determines Loading @@ -51,6 +65,22 @@ public class TextDirectionHeuristics { public static final TextDirectionHeuristic ANYLTR_RTL = new TextDirectionHeuristicInternal(AnyStrong.INSTANCE_LTR, true); /** * If the text contains any strong right to left non-format character, determines * that the direction is right to left, falling back to left to right if it * finds none. */ public static final TextDirectionHeuristic ANYRTL_LTR = new TextDirectionHeuristicInternal(AnyStrong.INSTANCE_RTL, false); /** * If the text contains any strong right to left non-format character, determines * that the direction is right to left, falling back to right to left if it * finds none. */ public static final TextDirectionHeuristic ANYRTL_RTL = new TextDirectionHeuristicInternal(AnyStrong.INSTANCE_RTL, true); /** * Examines only the strong directional non-format characters, and if either * left to right or right to left characters are 60% or more of this total, Loading Loading @@ -91,19 +121,6 @@ public class TextDirectionHeuristics { */ abstract protected boolean defaultIsRtl(); @Override public boolean isRtl(CharSequence text, int start, int end) { if (text == null || start < 0 || end < start || text.length() < end) { throw new IllegalArgumentException(); } if (mAlgorithm == null) { return defaultIsRtl(); } text = text.subSequence(start, end); char[] chars = text.toString().toCharArray(); return doCheck(chars, 0, chars.length); } @Override public boolean isRtl(char[] chars, int start, int count) { if (chars == null || start < 0 || count < 0 || chars.length - count < start) { Loading
core/java/android/view/View.java +5 −0 Original line number Diff line number Diff line Loading @@ -9165,6 +9165,7 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit mPrivateFlags &= ~AWAKEN_SCROLL_BARS_ON_ATTACH; } jumpDrawablesToCurrentState(); // Order is important here: LayoutDirection should be resolved before Padding and TextDirection resolveLayoutDirectionIfNeeded(); resolvePadding(); resolveTextDirection(); Loading @@ -9185,6 +9186,10 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit // Clear any previous layout direction resolution mPrivateFlags2 &= ~LAYOUT_DIRECTION_RESOLVED_RTL; // Reset also TextDirection as a change into LayoutDirection may impact the selected // TextDirectionHeuristic resetResolvedTextDirection(); // Set resolved depending on layout direction switch (getLayoutDirection()) { case LAYOUT_DIRECTION_INHERIT: Loading
core/java/android/widget/TextView.java +11 −25 Original line number Diff line number Diff line Loading @@ -10728,42 +10728,29 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener return mInBatchEditControllers; } private class TextViewDirectionHeuristic extends TextDirectionHeuristicImpl { private TextViewDirectionHeuristic(TextDirectionAlgorithm algorithm) { super(algorithm); } @Override protected boolean defaultIsRtl() { return getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL; } } /** * Resolve the text direction. * * Text direction of paragraphs in a TextView is determined using a heuristic. If the correct * text direction cannot be determined by the heuristic, the view's resolved layout direction * determines the direction. * * This heuristic and result is applied individually to each paragraph in a TextView, based on * the text and style content of that paragraph. Paragraph text styles can also be used to force * a particular direction. */ @Override protected void resolveTextDirection() { // Always need to resolve layout direction first final boolean defaultIsRtl = (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL); // Then resolve text direction on the parent super.resolveTextDirection(); // Now, we can select the heuristic int textDir = getResolvedTextDirection(); switch (textDir) { default: case TEXT_DIRECTION_FIRST_STRONG: mTextDir = new TextViewDirectionHeuristic(FirstStrong.INSTANCE); mTextDir = (defaultIsRtl ? TextDirectionHeuristics.FIRSTSTRONG_RTL : TextDirectionHeuristics.FIRSTSTRONG_LTR); break; case TEXT_DIRECTION_ANY_RTL: mTextDir = new TextViewDirectionHeuristic(AnyStrong.INSTANCE_RTL); mTextDir = (defaultIsRtl ? TextDirectionHeuristics.ANYRTL_RTL: TextDirectionHeuristics.ANYRTL_LTR); break; case TEXT_DIRECTION_CHAR_COUNT: mTextDir = new TextViewDirectionHeuristic(CharCount.INSTANCE_DEFAULT); mTextDir = (defaultIsRtl ? TextDirectionHeuristics.CHARCOUNT_RTL: TextDirectionHeuristics.CHARCOUNT_LTR); break; case TEXT_DIRECTION_LTR: mTextDir = TextDirectionHeuristics.LTR; Loading @@ -10772,7 +10759,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener mTextDir = TextDirectionHeuristics.RTL; break; } } /** Loading