Loading core/java/android/view/textclassifier/TextClassifierImpl.java +3 −1 Original line number Diff line number Diff line Loading @@ -102,7 +102,9 @@ final class TextClassifierImpl implements TextClassifier { string, selectionStartIndex, selectionEndIndex); final int start = startEnd[0]; final int end = startEnd[1]; if (start >= 0 && end <= string.length() && start <= end) { if (start <= end && start >= 0 && end <= string.length() && start <= selectionStartIndex && end >= selectionEndIndex) { final TextSelection.Builder tsBuilder = new TextSelection.Builder(start, end); final SmartSelection.ClassificationResult[] results = smartSelection.classifyText( Loading core/tests/coretests/src/android/view/textclassifier/TextClassificationManagerTest.java +21 −2 Original line number Diff line number Diff line Loading @@ -40,6 +40,7 @@ import java.util.Locale; public class TextClassificationManagerTest { private static final LocaleList LOCALES = LocaleList.forLanguageTags("en"); private static final String NO_TYPE = null; private TextClassificationManager mTcm; private TextClassifier mClassifier; Loading Loading @@ -101,6 +102,19 @@ public class TextClassificationManagerTest { isTextSelection(smartStartIndex, smartEndIndex, TextClassifier.TYPE_URL)); } @Test public void testSmartSelection_withEmoji() { if (isTextClassifierDisabled()) return; String text = "\uD83D\uDE02 Hello."; String selected = "Hello"; int startIndex = text.indexOf(selected); int endIndex = startIndex + selected.length(); assertThat(mClassifier.suggestSelection(text, startIndex, endIndex, LOCALES), isTextSelection(startIndex, endIndex, NO_TYPE)); } @Test public void testClassifyText() { if (isTextClassifierDisabled()) return; Loading Loading @@ -172,12 +186,17 @@ public class TextClassificationManagerTest { TextSelection selection = (TextSelection) o; return startIndex == selection.getSelectionStartIndex() && endIndex == selection.getSelectionEndIndex() && selection.getEntityCount() > 0 && type.equals(selection.getEntity(0)); && typeMatches(selection, type); } return false; } private boolean typeMatches(TextSelection selection, String type) { return type == null || (selection.getEntityCount() > 0 && type.trim().equalsIgnoreCase(selection.getEntity(0))); } @Override public void describeTo(Description description) { description.appendValue( Loading Loading
core/java/android/view/textclassifier/TextClassifierImpl.java +3 −1 Original line number Diff line number Diff line Loading @@ -102,7 +102,9 @@ final class TextClassifierImpl implements TextClassifier { string, selectionStartIndex, selectionEndIndex); final int start = startEnd[0]; final int end = startEnd[1]; if (start >= 0 && end <= string.length() && start <= end) { if (start <= end && start >= 0 && end <= string.length() && start <= selectionStartIndex && end >= selectionEndIndex) { final TextSelection.Builder tsBuilder = new TextSelection.Builder(start, end); final SmartSelection.ClassificationResult[] results = smartSelection.classifyText( Loading
core/tests/coretests/src/android/view/textclassifier/TextClassificationManagerTest.java +21 −2 Original line number Diff line number Diff line Loading @@ -40,6 +40,7 @@ import java.util.Locale; public class TextClassificationManagerTest { private static final LocaleList LOCALES = LocaleList.forLanguageTags("en"); private static final String NO_TYPE = null; private TextClassificationManager mTcm; private TextClassifier mClassifier; Loading Loading @@ -101,6 +102,19 @@ public class TextClassificationManagerTest { isTextSelection(smartStartIndex, smartEndIndex, TextClassifier.TYPE_URL)); } @Test public void testSmartSelection_withEmoji() { if (isTextClassifierDisabled()) return; String text = "\uD83D\uDE02 Hello."; String selected = "Hello"; int startIndex = text.indexOf(selected); int endIndex = startIndex + selected.length(); assertThat(mClassifier.suggestSelection(text, startIndex, endIndex, LOCALES), isTextSelection(startIndex, endIndex, NO_TYPE)); } @Test public void testClassifyText() { if (isTextClassifierDisabled()) return; Loading Loading @@ -172,12 +186,17 @@ public class TextClassificationManagerTest { TextSelection selection = (TextSelection) o; return startIndex == selection.getSelectionStartIndex() && endIndex == selection.getSelectionEndIndex() && selection.getEntityCount() > 0 && type.equals(selection.getEntity(0)); && typeMatches(selection, type); } return false; } private boolean typeMatches(TextSelection selection, String type) { return type == null || (selection.getEntityCount() > 0 && type.trim().equalsIgnoreCase(selection.getEntity(0))); } @Override public void describeTo(Description description) { description.appendValue( Loading