From 4a144b9b4d9e78bff7662001c97430491f9747a0 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Wed, 25 Dec 2013 18:35:32 +0900 Subject: [PATCH] [IL47] Inline getSuggestedWordsGestureLocked This method is confusing with the *Locked convention, and the two-step call creates a useless callback object. This is better inlined both for readability and for performance. Bug: 8636060 Change-Id: I7c427c3ca4e831388a6d54de6728b32206a45d80 --- .../android/inputmethod/latin/LatinIME.java | 33 ++++++------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index d2d44cce6..68818b824 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1334,13 +1334,21 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // Batch input has ended or canceled while the message was being delivered. return; } - getSuggestedWordsGestureLocked(batchPointers, sequenceNumber, + mLatinIme.mInputLogic.mWordComposer.setBatchInputPointers(batchPointers); + getSuggestedWords(Suggest.SESSION_GESTURE, sequenceNumber, new OnGetSuggestedWordsCallback() { @Override - public void onGetSuggestedWords(final SuggestedWords suggestedWords) { + public void onGetSuggestedWords(SuggestedWords suggestedWords) { // We're now inside the callback. This always runs on the // InputUpdater thread, no matter what thread updateBatchInput // was called on. + if (suggestedWords.isEmpty()) { + // Use old suggestions if we don't have any new ones. + // Previous suggestions are found in InputLogic#mSuggestedWords. + // Since these are the most recent ones and we just recomputed + // new ones to update them, then the previous ones are there. + suggestedWords = mLatinIme.mInputLogic.mSuggestedWords; + } mLatinIme.mHandler.showGesturePreviewAndSuggestionStrip( suggestedWords, forEnd /* dismissGestureFloatingPreviewText */); @@ -1397,27 +1405,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen updateBatchInput(batchPointers, sequenceNumber, true /* forEnd */); } - // {@link LatinIME#getSuggestedWords(int)} method calls with same session id have to - // be synchronized. - private void getSuggestedWordsGestureLocked(final InputPointers batchPointers, - final int sequenceNumber, final OnGetSuggestedWordsCallback callback) { - mLatinIme.mInputLogic.mWordComposer.setBatchInputPointers(batchPointers); - getSuggestedWords(Suggest.SESSION_GESTURE, sequenceNumber, - new OnGetSuggestedWordsCallback() { - @Override - public void onGetSuggestedWords(SuggestedWords suggestedWords) { - if (suggestedWords.isEmpty()) { - // Previous suggestions are found in InputLogic#mSuggestedWords. - // Since these are the most recent ones and we just recomputed new - // ones to update them, it means the previous ones are there. - callback.onGetSuggestedWords(mLatinIme.mInputLogic.mSuggestedWords); - } else { - callback.onGetSuggestedWords(suggestedWords); - } - } - }); - } - public void getSuggestedWords(final int sessionId, final int sequenceNumber, final OnGetSuggestedWordsCallback callback) { mHandler.obtainMessage(MSG_GET_SUGGESTED_WORDS, sessionId, sequenceNumber, callback)