Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4b60c308 authored by Fabrice Di Meglio's avatar Fabrice Di Meglio
Browse files

Fix bug #5175022 Easy mode in MeasuredText.setPara() is no more used

- use the real TextDirectionHeuristics constants
- make more formal that LayoutDirection should be resolved BEFORE TextDirection
- reset TextDirection if LayoutDirection is recomputed
- remove non used TextDirectionHeuristic.isRtl(CharSequence...)

Change-Id: I1d53a7e3ee324cfd27785bb4d715d93de8d9ff4d
parent 59607230
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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;
            }
+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;

@@ -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);
}
+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;

@@ -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
@@ -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,
@@ -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) {
+5 −0
Original line number Diff line number Diff line
@@ -9159,6 +9159,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();
@@ -9179,6 +9180,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:
+11 −25
Original line number Diff line number Diff line
@@ -10699,42 +10699,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;
@@ -10743,7 +10730,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                mTextDir = TextDirectionHeuristics.RTL;
                break;
        }

    }

    /**