diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2020-06-26 14:42:34 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-06-26 14:42:34 +0000 |
commit | 6fa41dc45712728d6e4995bf3a58fad77e2d0b00 (patch) | |
tree | 538febeab9305024f3e3f27c2d77a8300faafc1b | |
parent | 8ae3714bb3a78a8806777a59f24aeef9040448b1 (diff) | |
parent | b0e8892f5e2ceefcc2f9b0321f0b88251871bef3 (diff) | |
download | development-6fa41dc45712728d6e4995bf3a58fad77e2d0b00.tar.gz |
Merge "Post the inline suggestion response handling to next message" into rvc-dev am: b0e8892f5e
Original change: https://googleplex-android-review.googlesource.com/c/platform/development/+/11995060
Change-Id: I29b0eeca9101ff31197fecb0bbfd02b0883d9549
-rw-r--r-- | samples/AutofillKeyboard/src/com/example/android/autofillkeyboard/AutofillImeService.java | 48 |
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, } } |