public void onDownEvent(int x, int y, long eventTime) {
   if (DEBUG) debugLog("onDownEvent:", x, y);
   int keyIndex = mKeyState.onDownKey(x, y, eventTime);
   mKeyboardLayoutHasBeenChanged = false;
   mKeyAlreadyProcessed = false;
   mIsRepeatableKey = false;
   mIsInSlidingKeyInput = false;
   checkMultiTap(eventTime, keyIndex);
   if (mListener != null) {
     if (isValidKeyIndex(keyIndex)) {
       Key key = mKeys[keyIndex];
       if (key.codes != null) mListener.onPress(key.getPrimaryCode());
       // This onPress call may have changed keyboard layout. Those cases are detected at
       // {@link #setKeyboard}. In those cases, we should update keyIndex according to the
       // new keyboard layout.
       if (mKeyboardLayoutHasBeenChanged) {
         mKeyboardLayoutHasBeenChanged = false;
         keyIndex = mKeyState.onDownKey(x, y, eventTime);
       }
     }
   }
   if (isValidKeyIndex(keyIndex)) {
     if (mKeys[keyIndex].repeatable) {
       repeatKey(keyIndex);
       mHandler.startKeyRepeatTimer(mDelayBeforeKeyRepeatStart, keyIndex, this);
       mIsRepeatableKey = true;
     }
     startLongPressTimer(keyIndex);
   }
   showKeyPreviewAndUpdateKey(keyIndex);
 }
 public void onMoveEvent(int x, int y, long eventTime) {
   if (DEBUG_MOVE) debugLog("onMoveEvent:", x, y);
   if (mKeyAlreadyProcessed) return;
   final KeyState keyState = mKeyState;
   int keyIndex = keyState.onMoveKey(x, y);
   final Key oldKey = getKey(keyState.getKeyIndex());
   if (isValidKeyIndex(keyIndex)) {
     boolean isMinorMoveBounce = isMinorMoveBounce(x, y, keyIndex);
     if (DEBUG_MOVE)
       Log.i(
           TAG,
           "isMinorMoveBounce="
               + isMinorMoveBounce
               + " oldKey="
               + (oldKey == null ? "null" : oldKey));
     if (oldKey == null) {
       // The pointer has been slid in to the new key, but the finger was not on any keys.
       // In this case, we must call onPress() to notify that the new key is being pressed.
       if (mListener != null) {
         Key key = getKey(keyIndex);
         if (key.codes != null) mListener.onPress(key.getPrimaryCode());
         // This onPress call may have changed keyboard layout. Those cases are detected
         // at {@link #setKeyboard}. In those cases, we should update keyIndex according
         // to the new keyboard layout.
         if (mKeyboardLayoutHasBeenChanged) {
           mKeyboardLayoutHasBeenChanged = false;
           keyIndex = keyState.onMoveKey(x, y);
         }
       }
       keyState.onMoveToNewKey(keyIndex, x, y);
       startLongPressTimer(keyIndex);
     } else if (!isMinorMoveBounce) {
       // The pointer has been slid in to the new key from the previous key, we must call
       // onRelease() first to notify that the previous key has been released, then call
       // onPress() to notify that the new key is being pressed.
       mIsInSlidingKeyInput = true;
       if (mListener != null && oldKey.codes != null) mListener.onRelease(oldKey.getPrimaryCode());
       resetMultiTap();
       if (mListener != null) {
         Key key = getKey(keyIndex);
         if (key.codes != null) mListener.onPress(key.getPrimaryCode());
         // This onPress call may have changed keyboard layout. Those cases are detected
         // at {@link #setKeyboard}. In those cases, we should update keyIndex according
         // to the new keyboard layout.
         if (mKeyboardLayoutHasBeenChanged) {
           mKeyboardLayoutHasBeenChanged = false;
           keyIndex = keyState.onMoveKey(x, y);
         }
         addSlideKey(oldKey);
       }
       keyState.onMoveToNewKey(keyIndex, x, y);
       startLongPressTimer(keyIndex);
     }
   } else {
     if (oldKey != null && !isMinorMoveBounce(x, y, keyIndex)) {
       // The pointer has been slid out from the previous key, we must call onRelease() to
       // notify that the previous key has been released.
       mIsInSlidingKeyInput = true;
       if (mListener != null && oldKey.codes != null) mListener.onRelease(oldKey.getPrimaryCode());
       resetMultiTap();
       keyState.onMoveToNewKey(keyIndex, x, y);
       mHandler.cancelLongPressTimer();
     }
   }
   showKeyPreviewAndUpdateKey(keyState.getKeyIndex());
 }