Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c7564a78 authored by Jean Chalard's avatar Jean Chalard
Browse files

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
parent 72b358aa
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -179,7 +179,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen

    public static class UIHandler extends StaticInnerHandlerWrapper<LatinIME> {
        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.