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

Commit d365d82d authored by Tadashi G. Takaoka's avatar Tadashi G. Takaoka Committed by Android (Google) Code Review
Browse files

Merge "Handling key repeat by emulating key press and code input"

parents 07718a5e f87e8f7e
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.InputPointers;

public interface KeyboardActionListener {

    /**
     * Called when the user presses a key. This is sent before the {@link #onCodeInput} is called.
     * For keys that repeat, this is only called once.
@@ -99,9 +98,9 @@ public interface KeyboardActionListener {
     */
    public boolean onCustomRequest(int requestCode);

    public static class Adapter implements KeyboardActionListener {
        public static final Adapter EMPTY_LISTENER = new Adapter();
    public static final KeyboardActionListener EMPTY_LISTENER = new Adapter();

    public static class Adapter implements KeyboardActionListener {
        @Override
        public void onPressKey(int primaryCode, boolean isSinglePointer) {}
        @Override
+0 −9
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@ import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
import com.android.inputmethod.keyboard.KeyboardLayoutSet.KeyboardLayoutSetException;
import com.android.inputmethod.keyboard.PointerTracker.TimerProxy;
import com.android.inputmethod.keyboard.internal.KeyboardState;
import com.android.inputmethod.latin.AudioAndHapticFeedbackManager;
import com.android.inputmethod.latin.InputView;
import com.android.inputmethod.latin.LatinIME;
import com.android.inputmethod.latin.LatinImeLogger;
@@ -210,7 +209,6 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
    }

    public void onPressKey(final int code, final boolean isSinglePointer) {
        hapticAndAudioFeedback(code);
        mState.onPressKey(code, isSinglePointer, mLatinIME.getCurrentAutoCapsState());
    }

@@ -299,13 +297,6 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
                ? keyboardView.getTimerProxy().isInDoubleTapShiftKeyTimeout() : false;
    }

    private void hapticAndAudioFeedback(final int code) {
        if (mKeyboardView == null || mKeyboardView.isInSlidingKeyInput()) {
            return;
        }
        AudioAndHapticFeedbackManager.getInstance().hapticAndAudioFeedback(code, mKeyboardView);
    }

    /**
     * Updates state machine to figure out when to automatically switch back to the previous mode.
     */
+19 −26
Original line number Diff line number Diff line
@@ -57,10 +57,8 @@ import com.android.inputmethod.keyboard.internal.KeyPreviewDrawParams;
import com.android.inputmethod.keyboard.internal.PreviewPlacerView;
import com.android.inputmethod.keyboard.internal.SlidingKeyInputPreview;
import com.android.inputmethod.keyboard.internal.TouchScreenRegulator;
import com.android.inputmethod.latin.AudioAndHapticFeedbackManager;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.DebugSettings;
import com.android.inputmethod.latin.LatinIME;
import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.Settings;
@@ -240,11 +238,15 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
                break;
            case MSG_REPEAT_KEY:
                final Key currentKey = tracker.getKey();
                if (currentKey != null && currentKey.mCode == msg.arg1) {
                    tracker.onRepeatKey(currentKey);
                    AudioAndHapticFeedbackManager.getInstance().hapticAndAudioFeedback(
                            currentKey.mCode, keyboardView);
                final int code = msg.arg1;
                if (currentKey != null && currentKey.mCode == code) {
                    startKeyRepeatTimer(tracker, mKeyRepeatInterval);
                    startTypingStateTimer(currentKey);
                    final KeyboardActionListener listener =
                            keyboardView.getKeyboardActionListener();
                    listener.onPressKey(code, true /* isSinglePointer */);
                    listener.onCodeInput(code,
                            Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE);
                }
                break;
            case MSG_LONGPRESS_KEY:
@@ -564,6 +566,8 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
                altCodeKeyWhileTypingFadeoutAnimatorResId, this);
        mAltCodeKeyWhileTypingFadeinAnimator = loadObjectAnimator(
                altCodeKeyWhileTypingFadeinAnimatorResId, this);

        mKeyboardActionListener = KeyboardActionListener.EMPTY_LISTENER;
    }

    private ObjectAnimator loadObjectAnimator(final int resId, final Object target) {
@@ -977,39 +981,28 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
        if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
            ResearchLogger.mainKeyboardView_onLongPress();
        }
        final int code = key.mCode;
        final KeyboardActionListener listener = mKeyboardActionListener;
        if (key.hasNoPanelAutoMoreKey()) {
            final int embeddedCode = key.mMoreKeys[0].mCode;
            final int moreKeyCode = key.mMoreKeys[0].mCode;
            tracker.onLongPressed();
            invokeCodeInput(embeddedCode);
            invokeReleaseKey(code);
            AudioAndHapticFeedbackManager.getInstance().hapticAndAudioFeedback(code, this);
            listener.onPressKey(moreKeyCode, true /* isSinglePointer */);
            listener.onCodeInput(moreKeyCode,
                    Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE);
            listener.onReleaseKey(moreKeyCode, false /* withSliding */);
            return;
        }
        final int code = key.mCode;
        if (code == Constants.CODE_SPACE || code == Constants.CODE_LANGUAGE_SWITCH) {
            // Long pressing the space key invokes IME switcher dialog.
            if (invokeCustomRequest(LatinIME.CODE_SHOW_INPUT_METHOD_PICKER)) {
            if (listener.onCustomRequest(Constants.CUSTOM_CODE_SHOW_INPUT_METHOD_PICKER)) {
                tracker.onLongPressed();
                invokeReleaseKey(code);
                listener.onReleaseKey(code, false /* withSliding */);
                return;
            }
        }
        openMoreKeysPanel(key, tracker);
    }

    private boolean invokeCustomRequest(final int requestCode) {
        return mKeyboardActionListener.onCustomRequest(requestCode);
    }

    private void invokeCodeInput(final int code) {
        mKeyboardActionListener.onCodeInput(
                code, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE);
    }

    private void invokeReleaseKey(final int code) {
        mKeyboardActionListener.onReleaseKey(code, false);
    }

    private void openMoreKeysPanel(final Key key, final PointerTracker tracker) {
        final MoreKeysPanel moreKeysPanel = onCreateMoreKeysPanel(key, getContext());
        if (moreKeysPanel == null) {
+2 −7
Original line number Diff line number Diff line
@@ -175,7 +175,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
    private DrawingProxy mDrawingProxy;
    private TimerProxy mTimerProxy;
    private KeyDetector mKeyDetector;
    private KeyboardActionListener mListener = KeyboardActionListener.Adapter.EMPTY_LISTENER;
    private KeyboardActionListener mListener = KeyboardActionListener.EMPTY_LISTENER;

    private Keyboard mKeyboard;
    private int mPhantonSuddenMoveThreshold;
@@ -1263,13 +1263,8 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
        if (!key.isRepeatable()) return;
        // Don't start key repeat when we are in sliding input mode.
        if (mIsInSlidingKeyInput) return;
        onRepeatKey(key);
        mTimerProxy.startKeyRepeatTimer(this);
    }

    public void onRepeatKey(final Key key) {
        detectAndSendKey(key, key.mX, key.mY, SystemClock.uptimeMillis());
        mTimerProxy.startTypingStateTimer(key);
        mTimerProxy.startKeyRepeatTimer(this);
    }

    private boolean isMajorEnoughMoveToBeOnNewKey(final int x, final int y, final long eventTime,
+4 −13
Original line number Diff line number Diff line
@@ -81,9 +81,6 @@ public final class KeyboardState {
    private boolean mPrevSymbolsKeyboardWasShifted;
    private int mRecapitalizeMode;

    // For handling long press.
    private boolean mLongPressShiftLockFired;

    // For handling double tap.
    private boolean mIsInAlphabetUnshiftedFromShifted;
    private boolean mIsInDoubleTapShiftKey;
@@ -325,10 +322,11 @@ public final class KeyboardState {
        }
        if (code == Constants.CODE_SHIFT) {
            onPressShift();
        } else if (code == Constants.CODE_CAPSLOCK) {
            // Nothing to do here. See {@link #onReleaseKey(int,boolean)}.
        } else if (code == Constants.CODE_SWITCH_ALPHA_SYMBOL) {
            onPressSymbol();
        } else {
            mLongPressShiftLockFired = false;
            mShiftKeyState.onOtherKeyPressed();
            mSymbolKeyState.onOtherKeyPressed();
            // It is required to reset the auto caps state when all of the following conditions
@@ -356,6 +354,8 @@ public final class KeyboardState {
        }
        if (code == Constants.CODE_SHIFT) {
            onReleaseShift(withSliding);
        } else if (code == Constants.CODE_CAPSLOCK) {
            setShiftLocked(!mAlphabetShiftState.isShiftLocked());
        } else if (code == Constants.CODE_SWITCH_ALPHA_SYMBOL) {
            onReleaseSymbol(withSliding);
        }
@@ -437,7 +437,6 @@ public final class KeyboardState {
    }

    private void onPressShift() {
        mLongPressShiftLockFired = false;
        // If we are recapitalizing, we don't do any of the normal processing, including
        // importantly the double tap timer.
        if (RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE != mRecapitalizeMode) {
@@ -499,8 +498,6 @@ public final class KeyboardState {
                // Double tap shift key has been handled in {@link #onPressShift}, so that just
                // ignore this release shift key here.
                mIsInDoubleTapShiftKey = false;
            } else if (mLongPressShiftLockFired) {
                setShiftLocked(!mAlphabetShiftState.isShiftLocked());
            } else if (mShiftKeyState.isChording()) {
                if (mAlphabetShiftState.isShiftLockShifted()) {
                    // After chording input while shift locked state.
@@ -610,12 +607,6 @@ public final class KeyboardState {
            break;
        }

        if (code == Constants.CODE_CAPSLOCK) {
            // Changing shift lock state will be handled at {@link #onPressShift()} when the shift
            // key is released.
            mLongPressShiftLockFired = true;
        }

        // If the code is a letter, update keyboard shift state.
        if (Constants.isLetterCode(code)) {
            updateAlphabetShiftState(autoCaps, RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE);
Loading