Loading api/current.txt +1 −0 Original line number Diff line number Diff line Loading @@ -50313,6 +50313,7 @@ package android.view.textclassifier { method public default android.view.textclassifier.TextLinks generateLinks(java.lang.CharSequence); method public default java.util.Collection<java.lang.String> getEntitiesForPreset(int); method public default android.view.textclassifier.logging.Logger getLogger(android.view.textclassifier.logging.Logger.Config); method public default int getMaxGenerateLinksTextLength(); method public default android.view.textclassifier.TextSelection suggestSelection(java.lang.CharSequence, int, int, android.view.textclassifier.TextSelection.Options); method public default android.view.textclassifier.TextSelection suggestSelection(java.lang.CharSequence, int, int); method public default android.view.textclassifier.TextSelection suggestSelection(java.lang.CharSequence, int, int, android.os.LocaleList); core/java/android/provider/Settings.java +3 −0 Original line number Diff line number Diff line Loading @@ -10457,6 +10457,9 @@ public final class Settings { * <pre> * smart_selection_dark_launch (boolean) * smart_selection_enabled_for_edit_text (boolean) * suggest_selection_max_range_length (int) * classify_text_max_range_length (int) * generate_links_max_text_length (int) * </pre> * * <p> Loading core/java/android/text/util/Linkify.java +11 −3 Original line number Diff line number Diff line Loading @@ -644,7 +644,13 @@ public class Linkify { @Nullable Runnable modifyTextView) { Preconditions.checkNotNull(text); Preconditions.checkNotNull(classifier); final Supplier<TextLinks> supplier = () -> classifier.generateLinks(text, options); // The input text may exceed the maximum length the text classifier can handle. In such // cases, we process the text up to the maximum length. final CharSequence truncatedText = text.subSequence( 0, Math.min(text.length(), classifier.getMaxGenerateLinksTextLength())); final Supplier<TextLinks> supplier = () -> classifier.generateLinks(truncatedText, options); final Consumer<TextLinks> consumer = links -> { if (links.getLinks().isEmpty()) { if (callback != null) { Loading @@ -653,7 +659,8 @@ public class Linkify { return; } final TextLinkSpan[] old = text.getSpans(0, text.length(), TextLinkSpan.class); // Remove spans only for the part of the text we generated links for. final TextLinkSpan[] old = text.getSpans(0, truncatedText.length(), TextLinkSpan.class); for (int i = old.length - 1; i >= 0; i--) { text.removeSpan(old[i]); } Loading @@ -662,7 +669,8 @@ public class Linkify { ? null : options.getSpanFactory(); final @TextLinks.ApplyStrategy int applyStrategy = (options == null) ? TextLinks.APPLY_STRATEGY_IGNORE : options.getApplyStrategy(); final @TextLinks.Status int result = links.apply(text, applyStrategy, spanFactory); final @TextLinks.Status int result = links.apply(text, applyStrategy, spanFactory, true /*allowPrefix*/); if (result == TextLinks.STATUS_LINKS_APPLIED) { if (modifyTextView != null) { modifyTextView.run(); Loading core/java/android/view/textclassifier/SystemTextClassifier.java +9 −0 Original line number Diff line number Diff line Loading @@ -121,6 +121,15 @@ final class SystemTextClassifier implements TextClassifier { return mFallback.generateLinks(text, options); } /** * @inheritDoc */ @Override public int getMaxGenerateLinksTextLength() { // TODO: retrieve this from the bound service. return mFallback.getMaxGenerateLinksTextLength(); } private static final class TextSelectionCallback extends ITextSelectionCallback.Stub { final ResponseReceiver<TextSelection> mReceiver = new ResponseReceiver<>(); Loading core/java/android/view/textclassifier/TextClassifier.java +25 −2 Original line number Diff line number Diff line Loading @@ -276,9 +276,11 @@ public interface TextClassifier { * @param text the text to generate annotations for * @param options configuration for link generation * * @throws IllegalArgumentException if text is null * @throws IllegalArgumentException if text is null or the text is too long for the * TextClassifier implementation. * * @see #generateLinks(CharSequence) * @see #getMaxGenerateLinksTextLength() */ @WorkerThread default TextLinks generateLinks( Loading @@ -299,15 +301,27 @@ public interface TextClassifier { * * @param text the text to generate annotations for * * @throws IllegalArgumentException if text is null * @throws IllegalArgumentException if text is null or the text is too long for the * TextClassifier implementation. * * @see #generateLinks(CharSequence, TextLinks.Options) * @see #getMaxGenerateLinksTextLength() */ @WorkerThread default TextLinks generateLinks(@NonNull CharSequence text) { return generateLinks(text, null); } /** * Returns the maximal length of text that can be processed by generateLinks. * * @see #generateLinks(CharSequence) * @see #generateLinks(CharSequence, TextLinks.Options) */ default int getMaxGenerateLinksTextLength() { return Integer.MAX_VALUE; } /** * Returns a {@link Collection} of the entity types in the specified preset. * Loading Loading @@ -461,6 +475,15 @@ public interface TextClassifier { checkMainThread(allowInMainThread); } /** * @throws IllegalArgumentException if text is null; the text is too long or options is null */ public static void validate(@NonNull CharSequence text, int maxLength, boolean allowInMainThread) { validate(text, allowInMainThread); Preconditions.checkArgumentInRange(text.length(), 0, maxLength, "text.length()"); } private static void checkMainThread(boolean allowInMainThread) { if (!allowInMainThread && Looper.myLooper() == Looper.getMainLooper()) { Slog.w(DEFAULT_LOG_TAG, "TextClassifier called on main thread"); Loading Loading
api/current.txt +1 −0 Original line number Diff line number Diff line Loading @@ -50313,6 +50313,7 @@ package android.view.textclassifier { method public default android.view.textclassifier.TextLinks generateLinks(java.lang.CharSequence); method public default java.util.Collection<java.lang.String> getEntitiesForPreset(int); method public default android.view.textclassifier.logging.Logger getLogger(android.view.textclassifier.logging.Logger.Config); method public default int getMaxGenerateLinksTextLength(); method public default android.view.textclassifier.TextSelection suggestSelection(java.lang.CharSequence, int, int, android.view.textclassifier.TextSelection.Options); method public default android.view.textclassifier.TextSelection suggestSelection(java.lang.CharSequence, int, int); method public default android.view.textclassifier.TextSelection suggestSelection(java.lang.CharSequence, int, int, android.os.LocaleList);
core/java/android/provider/Settings.java +3 −0 Original line number Diff line number Diff line Loading @@ -10457,6 +10457,9 @@ public final class Settings { * <pre> * smart_selection_dark_launch (boolean) * smart_selection_enabled_for_edit_text (boolean) * suggest_selection_max_range_length (int) * classify_text_max_range_length (int) * generate_links_max_text_length (int) * </pre> * * <p> Loading
core/java/android/text/util/Linkify.java +11 −3 Original line number Diff line number Diff line Loading @@ -644,7 +644,13 @@ public class Linkify { @Nullable Runnable modifyTextView) { Preconditions.checkNotNull(text); Preconditions.checkNotNull(classifier); final Supplier<TextLinks> supplier = () -> classifier.generateLinks(text, options); // The input text may exceed the maximum length the text classifier can handle. In such // cases, we process the text up to the maximum length. final CharSequence truncatedText = text.subSequence( 0, Math.min(text.length(), classifier.getMaxGenerateLinksTextLength())); final Supplier<TextLinks> supplier = () -> classifier.generateLinks(truncatedText, options); final Consumer<TextLinks> consumer = links -> { if (links.getLinks().isEmpty()) { if (callback != null) { Loading @@ -653,7 +659,8 @@ public class Linkify { return; } final TextLinkSpan[] old = text.getSpans(0, text.length(), TextLinkSpan.class); // Remove spans only for the part of the text we generated links for. final TextLinkSpan[] old = text.getSpans(0, truncatedText.length(), TextLinkSpan.class); for (int i = old.length - 1; i >= 0; i--) { text.removeSpan(old[i]); } Loading @@ -662,7 +669,8 @@ public class Linkify { ? null : options.getSpanFactory(); final @TextLinks.ApplyStrategy int applyStrategy = (options == null) ? TextLinks.APPLY_STRATEGY_IGNORE : options.getApplyStrategy(); final @TextLinks.Status int result = links.apply(text, applyStrategy, spanFactory); final @TextLinks.Status int result = links.apply(text, applyStrategy, spanFactory, true /*allowPrefix*/); if (result == TextLinks.STATUS_LINKS_APPLIED) { if (modifyTextView != null) { modifyTextView.run(); Loading
core/java/android/view/textclassifier/SystemTextClassifier.java +9 −0 Original line number Diff line number Diff line Loading @@ -121,6 +121,15 @@ final class SystemTextClassifier implements TextClassifier { return mFallback.generateLinks(text, options); } /** * @inheritDoc */ @Override public int getMaxGenerateLinksTextLength() { // TODO: retrieve this from the bound service. return mFallback.getMaxGenerateLinksTextLength(); } private static final class TextSelectionCallback extends ITextSelectionCallback.Stub { final ResponseReceiver<TextSelection> mReceiver = new ResponseReceiver<>(); Loading
core/java/android/view/textclassifier/TextClassifier.java +25 −2 Original line number Diff line number Diff line Loading @@ -276,9 +276,11 @@ public interface TextClassifier { * @param text the text to generate annotations for * @param options configuration for link generation * * @throws IllegalArgumentException if text is null * @throws IllegalArgumentException if text is null or the text is too long for the * TextClassifier implementation. * * @see #generateLinks(CharSequence) * @see #getMaxGenerateLinksTextLength() */ @WorkerThread default TextLinks generateLinks( Loading @@ -299,15 +301,27 @@ public interface TextClassifier { * * @param text the text to generate annotations for * * @throws IllegalArgumentException if text is null * @throws IllegalArgumentException if text is null or the text is too long for the * TextClassifier implementation. * * @see #generateLinks(CharSequence, TextLinks.Options) * @see #getMaxGenerateLinksTextLength() */ @WorkerThread default TextLinks generateLinks(@NonNull CharSequence text) { return generateLinks(text, null); } /** * Returns the maximal length of text that can be processed by generateLinks. * * @see #generateLinks(CharSequence) * @see #generateLinks(CharSequence, TextLinks.Options) */ default int getMaxGenerateLinksTextLength() { return Integer.MAX_VALUE; } /** * Returns a {@link Collection} of the entity types in the specified preset. * Loading Loading @@ -461,6 +475,15 @@ public interface TextClassifier { checkMainThread(allowInMainThread); } /** * @throws IllegalArgumentException if text is null; the text is too long or options is null */ public static void validate(@NonNull CharSequence text, int maxLength, boolean allowInMainThread) { validate(text, allowInMainThread); Preconditions.checkArgumentInRange(text.length(), 0, maxLength, "text.length()"); } private static void checkMainThread(boolean allowInMainThread) { if (!allowInMainThread && Looper.myLooper() == Looper.getMainLooper()) { Slog.w(DEFAULT_LOG_TAG, "TextClassifier called on main thread"); Loading