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

Commit 2ea18b46 authored by Justin Ghan's avatar Justin Ghan
Browse files

Make Layout#getRangeForRect public

To avoid making WordIterator public, WordSegmentFinder has a public
constructor taking a Locale parameter. The constructor taking a
WordIterator parameter is kept but hidden so TextView can use it.

LayoutGetRangeForRectTest is moved to CTS.

Bug: 243969224
Test: atest android.text.cts.LayoutGetRangeForRectTest
Test: atest android.widget.cts.TextViewHandwritingGestureTest
Change-Id: Ibb829af0324c47e4d275b0ccd69d0f95601e3c08
parent 3cc4fa15
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
@@ -45192,6 +45192,14 @@ package android.text {
    method public void getChars(int, int, char[], int);
  }
  public class GraphemeClusterSegmentFinder extends android.text.SegmentFinder {
    ctor public GraphemeClusterSegmentFinder(@NonNull CharSequence, @NonNull android.text.TextPaint);
    method public int nextEndBoundary(@IntRange(from=0) int);
    method public int nextStartBoundary(@IntRange(from=0) int);
    method public int previousEndBoundary(@IntRange(from=0) int);
    method public int previousStartBoundary(@IntRange(from=0) int);
  }
  public class Html {
    method public static String escapeHtml(CharSequence);
    method @Deprecated public static android.text.Spanned fromHtml(String);
@@ -45321,6 +45329,7 @@ package android.text {
    method public final int getParagraphLeft(int);
    method public final int getParagraphRight(int);
    method public float getPrimaryHorizontal(int);
    method @Nullable public int[] getRangeForRect(@NonNull android.graphics.RectF, @NonNull android.text.SegmentFinder, @NonNull android.text.Layout.TextInclusionStrategy);
    method public float getSecondaryHorizontal(int);
    method public void getSelectionPath(int, int, android.graphics.Path);
    method public final float getSpacingAdd();
@@ -45344,6 +45353,9 @@ package android.text {
    field public static final int HYPHENATION_FREQUENCY_NONE = 0; // 0x0
    field public static final int HYPHENATION_FREQUENCY_NORMAL = 1; // 0x1
    field public static final int HYPHENATION_FREQUENCY_NORMAL_FAST = 3; // 0x3
    field @NonNull public static final android.text.Layout.TextInclusionStrategy INCLUSION_STRATEGY_ANY_OVERLAP;
    field @NonNull public static final android.text.Layout.TextInclusionStrategy INCLUSION_STRATEGY_CONTAINS_ALL;
    field @NonNull public static final android.text.Layout.TextInclusionStrategy INCLUSION_STRATEGY_CONTAINS_CENTER;
    field public static final int JUSTIFICATION_MODE_INTER_WORD = 1; // 0x1
    field public static final int JUSTIFICATION_MODE_NONE = 0; // 0x0
  }
@@ -45357,6 +45369,10 @@ package android.text {
  public static class Layout.Directions {
  }
  @java.lang.FunctionalInterface public static interface Layout.TextInclusionStrategy {
    method public boolean isSegmentInside(@NonNull android.graphics.RectF, @NonNull android.graphics.RectF);
  }
  @Deprecated public abstract class LoginFilter implements android.text.InputFilter {
    method @Deprecated public CharSequence filter(CharSequence, int, int, android.text.Spanned, int, int);
    method @Deprecated public abstract boolean isAllowed(char);
@@ -45433,6 +45449,15 @@ package android.text {
    method public android.text.PrecomputedText.Params.Builder setTextDirection(@NonNull android.text.TextDirectionHeuristic);
  }
  public abstract class SegmentFinder {
    ctor public SegmentFinder();
    method public abstract int nextEndBoundary(@IntRange(from=0) int);
    method public abstract int nextStartBoundary(@IntRange(from=0) int);
    method public abstract int previousEndBoundary(@IntRange(from=0) int);
    method public abstract int previousStartBoundary(@IntRange(from=0) int);
    field public static final int DONE = -1; // 0xffffffff
  }
  public class Selection {
    method public static boolean extendDown(android.text.Spannable, android.text.Layout);
    method public static boolean extendLeft(android.text.Spannable, android.text.Layout);
@@ -45718,6 +45743,14 @@ package android.text {
    method public void onTextChanged(CharSequence, int, int, int);
  }
  public class WordSegmentFinder extends android.text.SegmentFinder {
    ctor public WordSegmentFinder(@NonNull CharSequence, @NonNull java.util.Locale);
    method public int nextEndBoundary(@IntRange(from=0) int);
    method public int nextStartBoundary(@IntRange(from=0) int);
    method public int previousEndBoundary(@IntRange(from=0) int);
    method public int previousStartBoundary(@IntRange(from=0) int);
  }
}
package android.text.format {
+5 −1
Original line number Diff line number Diff line
@@ -24,7 +24,11 @@ import android.graphics.Paint;
 * Implementation of {@code SegmentFinder} using grapheme clusters as the text segment. Whitespace
 * characters are included as segments.
 *
 * @hide
 * <p>For example, the text "a pot" would be divided into five text segments: "a", " ", "p", "o",
 * "t".
 *
 * @see <a href="https://unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries">Unicode Text
 *     Segmentation - Grapheme Cluster Boundaries</a>
 */
public class GraphemeClusterSegmentFinder extends SegmentFinder {
    private final CharSequence mText;
+1 −9
Original line number Diff line number Diff line
@@ -170,8 +170,6 @@ public abstract class Layout {
    /**
     * Strategy which considers a text segment to be inside a rectangle area if the segment bounds
     * intersect the rectangle.
     *
     * @hide
     */
    @NonNull
    public static final TextInclusionStrategy INCLUSION_STRATEGY_ANY_OVERLAP =
@@ -180,8 +178,6 @@ public abstract class Layout {
    /**
     * Strategy which considers a text segment to be inside a rectangle area if the center of the
     * segment bounds is inside the rectangle.
     *
     * @hide
     */
    @NonNull
    public static final TextInclusionStrategy INCLUSION_STRATEGY_CONTAINS_CENTER =
@@ -191,8 +187,6 @@ public abstract class Layout {
    /**
     * Strategy which considers a text segment to be inside a rectangle area if the segment bounds
     * are completely contained within the rectangle.
     *
     * @hide
     */
    @NonNull
    public static final TextInclusionStrategy INCLUSION_STRATEGY_CONTAINS_ALL =
@@ -1867,7 +1861,6 @@ public abstract class Layout {
     *          specified area
     * @return int array of size 2 containing the start (inclusive) and end (exclusive) character
     *     offsets of the range, or null if there are no text segments inside the area
     * @hide
     */
    @Nullable
    public int[] getRangeForRect(@NonNull RectF area, @NonNull SegmentFinder segmentFinder,
@@ -3215,8 +3208,7 @@ public abstract class Layout {
    /**
     * Strategy for determining whether a text segment is inside a rectangle area.
     *
     * @see #getRangeForRect(RectF, SegmentIterator, TextInclusionStrategy)
     * @hide
     * @see #getRangeForRect(RectF, SegmentFinder, TextInclusionStrategy)
     */
    @FunctionalInterface
    public interface TextInclusionStrategy {
+6 −5
Original line number Diff line number Diff line
@@ -17,19 +17,20 @@
package android.text;

import android.annotation.IntRange;
import android.graphics.RectF;

/**
 * Finds text segment boundaries within text. Subclasses can implement different types of text
 * segments. Grapheme clusters and words are examples of possible text segments.
 * segments. Grapheme clusters and words are examples of possible text segments. These are
 * implemented by {@link GraphemeClusterSegmentFinder} and {@link WordSegmentFinder}.
 *
 * <p>Text segments may not overlap, so every character belongs to at most one text segment. A
 * character may belong to no text segments.
 *
 * <p>For example, a word level text segment finder may subdivide the text "Hello, World!" into four
 * text segments: "Hello", ",", "World", "!". The space character does not belong to any text
 * segments.
 * <p>For example, WordSegmentFinder subdivides the text "Hello, World!" into four text segments:
 * "Hello", ",", "World", "!". The space character does not belong to any text segments.
 *
 * @hide
 * @see Layout#getRangeForRect(RectF, SegmentFinder, Layout.TextInclusionStrategy)
 */
public abstract class SegmentFinder {
    public static final int DONE = -1;
+18 −3
Original line number Diff line number Diff line
@@ -18,20 +18,35 @@ package android.text;

import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.SuppressLint;
import android.icu.text.BreakIterator;
import android.text.method.WordIterator;

import java.util.Locale;

/**
 * Implementation of {@code SegmentFinder} using words as the text segment. Word boundaries are
 * found using {@code WordIterator}. Whitespace characters are excluded, so they are not included in
 * Implementation of {@link SegmentFinder} using words as the text segment. Word boundaries are
 * found using {@link WordIterator}. Whitespace characters are excluded, so they are not included in
 * any text segments.
 *
 * @hide
 * <p>For example, the text "Hello, World!" would be subdivided into four text segments: "Hello",
 * ",", "World", "!". The space character does not belong to any text segments.
 *
 * @see <a href="https://unicode.org/reports/tr29/#Word_Boundaries">Unicode Text Segmentation - Word
 *     Boundaries</a>
 */
public class WordSegmentFinder extends SegmentFinder {
    private final CharSequence mText;
    private final WordIterator mWordIterator;

    public WordSegmentFinder(
            @NonNull CharSequence text, @SuppressLint("UseIcu") @NonNull Locale locale) {
        mText = text;
        mWordIterator = new WordIterator(locale);
        mWordIterator.setCharSequence(text, 0, text.length());
    }

    /** @hide */
    public WordSegmentFinder(@NonNull CharSequence text, @NonNull WordIterator wordIterator) {
        mText = text;
        mWordIterator = wordIterator;
Loading