From c7564a787ea3d6722d763575928cd2631fda6277 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 8 Jun 2012 22:36:17 +0900 Subject: [PATCH] Optimization This is much faster. It doesn't create messages, it doesn't post stuff in a queue, it doesn't delay execution of other messages. Also, it decouples the timer from the functionality of the Handler so this can be pulled up in another change to consolidate with mLastKeyTime or so. Change-Id: I9044fc031373e66b9b40eee8025633613d0945dc --- java/src/com/android/inputmethod/latin/LatinIME.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index c239f63d8..5236591f6 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -179,7 +179,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen public static class UIHandler extends StaticInnerHandlerWrapper { private static final int MSG_UPDATE_SHIFT_STATE = 1; - private static final int MSG_SPACE_TYPED = 4; private static final int MSG_SET_BIGRAM_PREDICTIONS = 5; private static final int MSG_PENDING_IMS_CALLBACK = 6; private static final int MSG_UPDATE_SUGGESTIONS = 7; @@ -187,6 +186,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private int mDelayUpdateSuggestions; private int mDelayUpdateShiftState; private long mDoubleSpacesTurnIntoPeriodTimeout; + private long mDoubleSpaceTimerStart; public UIHandler(LatinIME outerInstance) { super(outerInstance); @@ -251,16 +251,16 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } public void startDoubleSpacesTimer() { - removeMessages(MSG_SPACE_TYPED); - sendMessageDelayed(obtainMessage(MSG_SPACE_TYPED), mDoubleSpacesTurnIntoPeriodTimeout); + mDoubleSpaceTimerStart = SystemClock.uptimeMillis(); } public void cancelDoubleSpacesTimer() { - removeMessages(MSG_SPACE_TYPED); + mDoubleSpaceTimerStart = 0; } public boolean isAcceptingDoubleSpaces() { - return hasMessages(MSG_SPACE_TYPED); + return SystemClock.uptimeMillis() - mDoubleSpaceTimerStart + < mDoubleSpacesTurnIntoPeriodTimeout; } // Working variables for the following methods.