private void detectAndSendKey(Key key, int x, int y, long eventTime) {
    final OnKeyboardActionListener listener = mListener;

    if (key == null) {
      if (listener != null) listener.onCancel();
    } else {
      if (key.text != null) {
        if (listener != null) {
          listener.onText(key.text);
          listener.onRelease(0); // dummy key code
        }
      } else {
        if (key.codes == null) return;
        int code = key.getPrimaryCode();
        int[] codes = mKeyDetector.newCodeArray();
        mKeyDetector.getKeyIndexAndNearbyCodes(x, y, codes);
        // Multi-tap
        if (mInMultiTap) {
          if (mTapCount != -1) {
            mListener.onKey(Keyboard.KEYCODE_DELETE, KEY_DELETE, x, y);
          } else {
            mTapCount = 0;
          }
          code = key.codes[mTapCount];
        }
        /*
         * Swap the first and second values in the codes array if the primary code is not
         * the first value but the second value in the array. This happens when key
         * debouncing is in effect.
         */
        if (codes.length >= 2 && codes[0] != code && codes[1] == code) {
          codes[1] = codes[0];
          codes[0] = code;
        }
        if (listener != null) {
          listener.onKey(code, codes, x, y);
          listener.onRelease(code);
        }
      }
      mLastTapTime = eventTime;
    }
  }
 private void debugLog(String title, int x, int y) {
   int keyIndex = mKeyDetector.getKeyIndexAndNearbyCodes(x, y, null);
   Key key = getKey(keyIndex);
   final String code;
   if (key == null || key.codes == null) {
     code = "----";
   } else {
     int primaryCode = key.codes[0];
     code = String.format((primaryCode < 0) ? "%4d" : "0x%02x", primaryCode);
   }
   Log.d(
       TAG,
       String.format(
           "%s%s[%d] %3d,%3d %3d(%s) %s",
           title,
           (mKeyAlreadyProcessed ? "-" : " "),
           mPointerId,
           x,
           y,
           keyIndex,
           code,
           (isModifier() ? "modifier" : "")));
 }
 private int onMoveKeyInternal(int x, int y) {
   mLastX = x;
   mLastY = y;
   return mKeyDetector.getKeyIndexAndNearbyCodes(x, y, null);
 }
 public boolean isOnModifierKey(int x, int y) {
   return isModifierInternal(mKeyDetector.getKeyIndexAndNearbyCodes(x, y, null));
 }
Example #5
0
 @Override
 public void setKeyboard(Keyboard keyboard) {
   super.setKeyboard(keyboard);
   mKeyDetector.setKeyboard(keyboard, -getPaddingLeft(), -getPaddingTop() + mVerticalCorrection);
 }