Loading core/java/android/widget/Editor.java +22 −9 Original line number Diff line number Diff line Loading @@ -2705,11 +2705,22 @@ public class Editor { mIsShowingUp = false; } private class SuggestionInfo { private final class SuggestionInfo { int suggestionStart, suggestionEnd; // range of actual suggestion within text SuggestionSpan suggestionSpan; // the SuggestionSpan that this TextView represents // the SuggestionSpan that this TextView represents @Nullable SuggestionSpan suggestionSpan; int suggestionIndex; // the index of this suggestion inside suggestionSpan SpannableStringBuilder text = new SpannableStringBuilder(); @Nullable final SpannableStringBuilder text = new SpannableStringBuilder(); void clear() { suggestionSpan = null; text.clear(); } } private class SuggestionAdapter extends BaseAdapter { Loading Loading @@ -2863,9 +2874,11 @@ public class Editor { return Math.min(positionY, displayMetrics.heightPixels - height); } @Override public void hide() { super.hide(); private void hideWithCleanUp() { for (final SuggestionInfo info : mSuggestionInfos) { info.clear(); } hide(); } private boolean updateSuggestions() { Loading Loading @@ -3017,7 +3030,7 @@ public class Editor { } mTextView.deleteText_internal(spanUnionStart, spanUnionEnd); } hide(); hideWithCleanUp(); return; } Loading @@ -3025,7 +3038,7 @@ public class Editor { final int spanEnd = editable.getSpanEnd(suggestionInfo.suggestionSpan); if (spanStart < 0 || spanEnd <= spanStart) { // Span has been removed hide(); hideWithCleanUp(); return; } Loading Loading @@ -3100,7 +3113,7 @@ public class Editor { mTextView.setCursorPosition_internal(newCursorPosition, newCursorPosition); } hide(); hideWithCleanUp(); } } Loading core/tests/coretests/src/android/widget/SuggestionsPopupWindowTest.java +26 −5 Original line number Diff line number Diff line Loading @@ -61,11 +61,13 @@ public class SuggestionsPopupWindowTest extends ActivityInstrumentationTestCase2 final int expectedHighlightTextColor = tmpTp.getColor(); final float expectedHighlightTextSize = tmpTp.getTextSize(); // Create and wait until SuggestionsPopupWindow is shown. final EditText editText = (EditText) activity.findViewById(R.id.textview); final Editor editor = editText.getEditorForTesting(); assertNotNull(editor); activity.runOnUiThread(new Runnable() { // Request to show SuggestionsPopupWindow. Runnable showSuggestionWindowRunner = new Runnable() { @Override public void run() { SpannableStringBuilder ssb = new SpannableStringBuilder(); ssb.append(sampleText); Loading @@ -78,8 +80,7 @@ public class SuggestionsPopupWindowTest extends ActivityInstrumentationTestCase2 Selection.setSelection(editText.getText(), singleWordSpanStart, singleWordSpanEnd); editText.onTextContextMenuItem(TextView.ID_REPLACE); } }); getInstrumentation().waitForIdleSync(); }; // In this test, the SuggestionsPopupWindow looks like // abc def ghi Loading @@ -91,7 +92,8 @@ public class SuggestionsPopupWindowTest extends ActivityInstrumentationTestCase2 // | DELETE | // ----------------- // *XX* means that XX is highlighted. activity.runOnUiThread(new Runnable() { Runnable popupVaridator = new Runnable() { @Override public void run() { Editor.SuggestionsPopupWindow popupWindow = editor.getSuggestionsPopupWindowForTesting(); Loading Loading @@ -155,6 +157,25 @@ public class SuggestionsPopupWindowTest extends ActivityInstrumentationTestCase2 assertEquals(multiWordSpanEnd, spanned.getSpanEnd(taSpan[0])); } } }; // Show the SuggestionWindow and verify the contents. activity.runOnUiThread(showSuggestionWindowRunner); getInstrumentation().waitForIdleSync(); activity.runOnUiThread(popupVaridator); // Request to hide the SuggestionPopupWindow and wait until it is hidden. activity.runOnUiThread(new Runnable() { @Override public void run() { editText.setText(""); } }); getInstrumentation().waitForIdleSync(); // Show and verify the contents again. activity.runOnUiThread(showSuggestionWindowRunner); getInstrumentation().waitForIdleSync(); activity.runOnUiThread(popupVaridator); } } Loading
core/java/android/widget/Editor.java +22 −9 Original line number Diff line number Diff line Loading @@ -2705,11 +2705,22 @@ public class Editor { mIsShowingUp = false; } private class SuggestionInfo { private final class SuggestionInfo { int suggestionStart, suggestionEnd; // range of actual suggestion within text SuggestionSpan suggestionSpan; // the SuggestionSpan that this TextView represents // the SuggestionSpan that this TextView represents @Nullable SuggestionSpan suggestionSpan; int suggestionIndex; // the index of this suggestion inside suggestionSpan SpannableStringBuilder text = new SpannableStringBuilder(); @Nullable final SpannableStringBuilder text = new SpannableStringBuilder(); void clear() { suggestionSpan = null; text.clear(); } } private class SuggestionAdapter extends BaseAdapter { Loading Loading @@ -2863,9 +2874,11 @@ public class Editor { return Math.min(positionY, displayMetrics.heightPixels - height); } @Override public void hide() { super.hide(); private void hideWithCleanUp() { for (final SuggestionInfo info : mSuggestionInfos) { info.clear(); } hide(); } private boolean updateSuggestions() { Loading Loading @@ -3017,7 +3030,7 @@ public class Editor { } mTextView.deleteText_internal(spanUnionStart, spanUnionEnd); } hide(); hideWithCleanUp(); return; } Loading @@ -3025,7 +3038,7 @@ public class Editor { final int spanEnd = editable.getSpanEnd(suggestionInfo.suggestionSpan); if (spanStart < 0 || spanEnd <= spanStart) { // Span has been removed hide(); hideWithCleanUp(); return; } Loading Loading @@ -3100,7 +3113,7 @@ public class Editor { mTextView.setCursorPosition_internal(newCursorPosition, newCursorPosition); } hide(); hideWithCleanUp(); } } Loading
core/tests/coretests/src/android/widget/SuggestionsPopupWindowTest.java +26 −5 Original line number Diff line number Diff line Loading @@ -61,11 +61,13 @@ public class SuggestionsPopupWindowTest extends ActivityInstrumentationTestCase2 final int expectedHighlightTextColor = tmpTp.getColor(); final float expectedHighlightTextSize = tmpTp.getTextSize(); // Create and wait until SuggestionsPopupWindow is shown. final EditText editText = (EditText) activity.findViewById(R.id.textview); final Editor editor = editText.getEditorForTesting(); assertNotNull(editor); activity.runOnUiThread(new Runnable() { // Request to show SuggestionsPopupWindow. Runnable showSuggestionWindowRunner = new Runnable() { @Override public void run() { SpannableStringBuilder ssb = new SpannableStringBuilder(); ssb.append(sampleText); Loading @@ -78,8 +80,7 @@ public class SuggestionsPopupWindowTest extends ActivityInstrumentationTestCase2 Selection.setSelection(editText.getText(), singleWordSpanStart, singleWordSpanEnd); editText.onTextContextMenuItem(TextView.ID_REPLACE); } }); getInstrumentation().waitForIdleSync(); }; // In this test, the SuggestionsPopupWindow looks like // abc def ghi Loading @@ -91,7 +92,8 @@ public class SuggestionsPopupWindowTest extends ActivityInstrumentationTestCase2 // | DELETE | // ----------------- // *XX* means that XX is highlighted. activity.runOnUiThread(new Runnable() { Runnable popupVaridator = new Runnable() { @Override public void run() { Editor.SuggestionsPopupWindow popupWindow = editor.getSuggestionsPopupWindowForTesting(); Loading Loading @@ -155,6 +157,25 @@ public class SuggestionsPopupWindowTest extends ActivityInstrumentationTestCase2 assertEquals(multiWordSpanEnd, spanned.getSpanEnd(taSpan[0])); } } }; // Show the SuggestionWindow and verify the contents. activity.runOnUiThread(showSuggestionWindowRunner); getInstrumentation().waitForIdleSync(); activity.runOnUiThread(popupVaridator); // Request to hide the SuggestionPopupWindow and wait until it is hidden. activity.runOnUiThread(new Runnable() { @Override public void run() { editText.setText(""); } }); getInstrumentation().waitForIdleSync(); // Show and verify the contents again. activity.runOnUiThread(showSuggestionWindowRunner); getInstrumentation().waitForIdleSync(); activity.runOnUiThread(popupVaridator); } }