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

Commit beb08b39 authored by Tadashi G. Takaoka's avatar Tadashi G. Takaoka
Browse files

Remove unnecessary and harmful KeyboardState.onUpdateShiftState call

This change also cancels double tap and long press timers if other
letter key is pressed after shift key.

Bug: 5693999
Bug: 6017610
Change-Id: I3b5f3debfb8915fa73a93b409a38afadf24132e9
parent 25ff89a7
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -266,6 +266,16 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
        }
    }

    // Implements {@link KeyboardState.SwitchActions}.
    @Override
    public void cancelDoubleTapTimer() {
        final LatinKeyboardView keyboardView = getKeyboardView();
        if (keyboardView != null) {
            final TimerProxy timer = keyboardView.getTimerProxy();
            timer.cancelDoubleTapTimer();
        }
    }

    // Implements {@link KeyboardState.SwitchActions}.
    @Override
    public boolean isInDoubleTapTimeout() {
@@ -284,6 +294,16 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
        }
    }

    // Implements {@link KeyboardState.SwitchActions}.
    @Override
    public void cancelLongPressTimer() {
        final LatinKeyboardView keyboardView = getKeyboardView();
        if (keyboardView != null) {
            final TimerProxy timer = keyboardView.getTimerProxy();
            timer.cancelLongPressTimer();
        }
    }

    // Implements {@link KeyboardState.SwitchActions}.
    @Override
    public void hapticAndAudioFeedback(int code) {
+5 −0
Original line number Diff line number Diff line
@@ -232,6 +232,11 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
                    ViewConfiguration.getDoubleTapTimeout());
        }

        @Override
        public void cancelDoubleTapTimer() {
            removeMessages(MSG_DOUBLE_TAP);
        }

        @Override
        public boolean isInDoubleTapTimeout() {
            return hasMessages(MSG_DOUBLE_TAP);
+3 −0
Original line number Diff line number Diff line
@@ -77,6 +77,7 @@ public class PointerTracker {
        public void startLongPressTimer(int code);
        public void cancelLongPressTimer();
        public void startDoubleTapTimer();
        public void cancelDoubleTapTimer();
        public boolean isInDoubleTapTimeout();
        public void cancelKeyTimers();

@@ -96,6 +97,8 @@ public class PointerTracker {
            @Override
            public void startDoubleTapTimer() {}
            @Override
            public void cancelDoubleTapTimer() {}
            @Override
            public boolean isInDoubleTapTimeout() { return false; }
            @Override
            public void cancelKeyTimers() {}
+10 −1
Original line number Diff line number Diff line
@@ -54,7 +54,9 @@ public class KeyboardState {

        public void startDoubleTapTimer();
        public boolean isInDoubleTapTimeout();
        public void cancelDoubleTapTimer();
        public void startLongPressTimer(int code);
        public void cancelLongPressTimer();
        public void hapticAndAudioFeedback(int code);
    }

@@ -300,6 +302,8 @@ public class KeyboardState {
        } else if (code == Keyboard.CODE_SWITCH_ALPHA_SYMBOL) {
            onPressSymbol();
        } else {
            mSwitchActions.cancelDoubleTapTimer();
            mSwitchActions.cancelLongPressTimer();
            mShiftKeyState.onOtherKeyPressed();
            mSymbolKeyState.onOtherKeyPressed();
        }
@@ -348,7 +352,7 @@ public class KeyboardState {
                // state. And mark as if shift key is released.
                mShiftKeyState.onRelease();
            } else {
                // Shift key is long pressed while shift unloked state.
                // Shift key is long pressed while shift unlocked state.
                setShiftLocked(true);
            }
            mSwitchActions.hapticAndAudioFeedback(code);
@@ -364,6 +368,11 @@ public class KeyboardState {

    private void updateAlphabetShiftState(boolean autoCaps) {
        if (!mIsAlphabetMode) return;
        if (!mShiftKeyState.isReleasing()) {
            // Ignore update shift state event while the shift key is being pressed (including
            // chording).
            return;
        }
        if (!mAlphabetShiftState.isShiftLocked() && !mShiftKeyState.isIgnoring()) {
            if (mShiftKeyState.isReleasing() && autoCaps) {
                // Only when shift key is releasing, automatic temporary upper case will be set.
+21 −3
Original line number Diff line number Diff line
@@ -16,12 +16,18 @@

package com.android.inputmethod.keyboard.internal;

import android.util.Log;

import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.PointerTracker;

import java.util.Iterator;
import java.util.LinkedList;

public class PointerTrackerQueue {
    private static final String TAG = PointerTrackerQueue.class.getSimpleName();
    private static final boolean DEBUG = false;

    private final LinkedList<PointerTracker> mQueue = new LinkedList<PointerTracker>();

    public synchronized void add(PointerTracker tracker) {
@@ -32,7 +38,11 @@ public class PointerTrackerQueue {
        mQueue.remove(tracker);
    }

    public synchronized void releaseAllPointersOlderThan(PointerTracker tracker, long eventTime) {
    public synchronized void releaseAllPointersOlderThan(PointerTracker tracker,
            long eventTime) {
        if (DEBUG) {
            Log.d(TAG, "releaseAllPoniterOlderThan: [" + tracker.mPointerId + "] " + this);
        }
        if (!mQueue.contains(tracker)) {
            return;
        }
@@ -54,6 +64,13 @@ public class PointerTrackerQueue {
    }

    public synchronized void releaseAllPointersExcept(PointerTracker tracker, long eventTime) {
        if (DEBUG) {
            if (tracker == null) {
                Log.d(TAG, "releaseAllPoniters: " + this);
            } else {
                Log.d(TAG, "releaseAllPoniterExcept: [" + tracker.mPointerId + "] " + this);
            }
        }
        final Iterator<PointerTracker> it = mQueue.iterator();
        while (it.hasNext()) {
            final PointerTracker t = it.next();
@@ -79,8 +96,9 @@ public class PointerTrackerQueue {
        for (final PointerTracker tracker : mQueue) {
            if (sb.length() > 0)
                sb.append(" ");
            sb.append(tracker.mPointerId);
            sb.append("[" + tracker.mPointerId + " "
                + Keyboard.printableCode(tracker.getKey().mCode) + "]");
        }
        return "[" + sb + "]";
        return sb.toString();
    }
}
Loading