summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFeng Cao <fengcao@google.com>2020-06-24 16:25:39 -0700
committerFeng Cao <fengcao@google.com>2020-06-24 20:09:04 -0700
commit2b2bc37a669184a769fb52aad027a70d8996d80a (patch)
treec99158856e5f978277f65f069263dd848be93c45
parentbbba16a2c9ff1560ad7ea5787f65500b0224fa82 (diff)
downloaddevelopment-2b2bc37a669184a769fb52aad027a70d8996d80a.tar.gz
Post the inline suggestion response handling to next message
* so that it can determine whether to delay the deletion or not * also fix sample IME to clear suggestions when asked to Test: manual Bug: 159479887 Bug: 157515522 Change-Id: I71e6ac9f3593cdfa4e40b7664cbd2eec6343b5af
-rw-r--r--samples/AutofillKeyboard/src/com/example/android/autofillkeyboard/AutofillImeService.java48
1 files changed, 32 insertions, 16 deletions
diff --git a/samples/AutofillKeyboard/src/com/example/android/autofillkeyboard/AutofillImeService.java b/samples/AutofillKeyboard/src/com/example/android/autofillkeyboard/AutofillImeService.java
index 32f765a3f..681601acb 100644
--- a/samples/AutofillKeyboard/src/com/example/android/autofillkeyboard/AutofillImeService.java
+++ b/samples/AutofillKeyboard/src/com/example/android/autofillkeyboard/AutofillImeService.java
@@ -104,6 +104,7 @@ public class AutofillImeService extends InputMethodService {
private ResponseState mResponseState = ResponseState.RESET;
private Runnable mDelayedDeletion;
+ private Runnable mPendingResponse;
@Override
public View onCreateInputView() {
@@ -125,7 +126,7 @@ public class AutofillImeService extends InputMethodService {
if(mKeyboard != null) {
mKeyboard.reset();
}
- if (mResponseState == ResponseState.FINISH_INPUT) {
+ if (mResponseState == ResponseState.RECEIVE_RESPONSE) {
mResponseState = ResponseState.START_INPUT;
} else {
mResponseState = ResponseState.RESET;
@@ -135,13 +136,32 @@ public class AutofillImeService extends InputMethodService {
@Override
public void onFinishInput() {
super.onFinishInput();
- if (mResponseState == ResponseState.RECEIVE_RESPONSE) {
- mResponseState = ResponseState.FINISH_INPUT;
- } else {
- mResponseState = ResponseState.RESET;
+ }
+
+ private void cancelPendingResponse() {
+ if (mPendingResponse != null) {
+ Log.d(TAG, "Canceling pending response");
+ mHandler.removeCallbacks(mPendingResponse);
+ mPendingResponse = null;
}
}
+ private void postPendingResponse(InlineSuggestionsResponse response) {
+ cancelPendingResponse();
+ final List<InlineSuggestion> inlineSuggestions = response.getInlineSuggestions();
+ mResponseState = ResponseState.RECEIVE_RESPONSE;
+ mPendingResponse = () -> {
+ mPendingResponse = null;
+ if (mResponseState == ResponseState.START_INPUT && inlineSuggestions.isEmpty()) {
+ scheduleDelayedDeletion();
+ } else {
+ inflateThenShowSuggestions(inlineSuggestions);
+ }
+ mResponseState = ResponseState.RESET;
+ };
+ mHandler.post(mPendingResponse);
+ }
+
private void cancelDelayedDeletion(String msg) {
if(mDelayedDeletion != null) {
Log.d(TAG, msg + " canceling delayed deletion");
@@ -263,16 +283,7 @@ public class AutofillImeService extends InputMethodService {
Log.d(TAG,
"onInlineSuggestionsResponse() called: " + response.getInlineSuggestions().size());
cancelDelayedDeletion("onInlineSuggestionsResponse");
- final List<InlineSuggestion> inlineSuggestions = response.getInlineSuggestions();
- mResponseState = ResponseState.RECEIVE_RESPONSE;
- mHandler.post(() -> {
- if (mResponseState == ResponseState.START_INPUT && inlineSuggestions.isEmpty()) {
- scheduleDelayedDeletion();
- } else {
- inflateThenShowSuggestions(inlineSuggestions);
- }
- mResponseState = ResponseState.RESET;
- });
+ postPendingResponse(response);
return true;
}
@@ -333,6 +344,12 @@ public class AutofillImeService extends InputMethodService {
private void inflateThenShowSuggestions( List<InlineSuggestion> inlineSuggestions) {
final int totalSuggestionsCount = inlineSuggestions.size();
+ if (inlineSuggestions.isEmpty()) {
+ // clear the suggestions and then return
+ getMainExecutor().execute(() -> updateInlineSuggestionStrip(Collections.EMPTY_LIST));
+ return;
+ }
+
final Map<Integer, SuggestionItem> suggestionMap = Collections.synchronizedMap((
new TreeMap<>()));
final ExecutorService executor = Executors.newSingleThreadExecutor();
@@ -388,7 +405,6 @@ public class AutofillImeService extends InputMethodService {
enum ResponseState {
RESET,
RECEIVE_RESPONSE,
- FINISH_INPUT,
START_INPUT,
}
}