예제 #1
0
  /**
   * This translates incoming hard key events in to edit operations on an InputConnection. It is
   * only needed when using the PROCESS_HARD_KEYS option.
   */
  private boolean translateKeyDown(int keyCode, KeyEvent event) {
    mMetaState = MetaKeyKeyListener.handleKeyDown(mMetaState, keyCode, event);
    int c = event.getUnicodeChar(MetaKeyKeyListener.getMetaState(mMetaState));
    mMetaState = MetaKeyKeyListener.adjustMetaAfterKeypress(mMetaState);
    InputConnection ic = getCurrentInputConnection();
    if (c == 0 || ic == null) {
      return false;
    }

    boolean dead = false;

    if ((c & KeyCharacterMap.COMBINING_ACCENT) != 0) {
      dead = true;
      c = c & KeyCharacterMap.COMBINING_ACCENT_MASK;
    }

    if (mComposing.length() > 0) {
      char accent = mComposing.charAt(mComposing.length() - 1);
      int composed = KeyEvent.getDeadChar(accent, c);

      if (composed != 0) {
        c = composed;
        mComposing.setLength(mComposing.length() - 1);
      }
    }

    onKey(c, null);

    return true;
  }
  @Override
  public int translateKeyDown(int unicodeChar) {
    if (!Strings.isEmpty(typedText)) {
      char accent = typedText.charAt(typedText.length() - 1);
      int composed = KeyEvent.getDeadChar(accent, unicodeChar);

      if (composed != 0) {
        unicodeChar = composed;
        typedText.setLength(typedText.length() - 1);
      }
    }

    return unicodeChar;
  }
예제 #3
0
  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (!m_started) return false;
    m_metaState = MetaKeyKeyListener.handleKeyDown(m_metaState, keyCode, event);
    int c = event.getUnicodeChar(MetaKeyKeyListener.getMetaState(m_metaState));
    int lc = c;
    m_metaState = MetaKeyKeyListener.adjustMetaAfterKeypress(m_metaState);

    if ((c & KeyCharacterMap.COMBINING_ACCENT) != 0) {
      c = c & KeyCharacterMap.COMBINING_ACCENT_MASK;
      int composed = KeyEvent.getDeadChar(m_lastChar, c);
      c = composed;
    }
    m_lastChar = lc;
    if (keyCode != KeyEvent.KEYCODE_BACK) QtApplication.keyDown(keyCode, c, event.getMetaState());
    return true;
  }
  /** @see BaseInputConnection#sendKeyEvent(android.view.KeyEvent) */
  @Override
  public boolean sendKeyEvent(KeyEvent event) {
    if (DEBUG) {
      Log.w(
          TAG,
          "sendKeyEvent ["
              + event.getAction()
              + "] ["
              + event.getKeyCode()
              + "] ["
              + event.getUnicodeChar()
              + "]");
    }

    int action = event.getAction();
    int keycode = event.getKeyCode();
    int unicodeChar = event.getUnicodeChar();

    // If this isn't a KeyDown event, no need to update composition state; just pass the key
    // event through and return. But note that some keys, such as enter, may actually be
    // handled on ACTION_UP in Blink.
    if (action != KeyEvent.ACTION_DOWN) {
      mImeAdapter.translateAndSendNativeEvents(event);
      return true;
    }

    // If this is backspace/del or if the key has a character representation,
    // need to update the underlying Editable (i.e. the local representation of the text
    // being edited).  Some IMEs like Jellybean stock IME and Samsung IME mix in delete
    // KeyPress events instead of calling deleteSurroundingText.
    if (keycode == KeyEvent.KEYCODE_DEL) {
      deleteSurroundingTextImpl(1, 0, true);
    } else if (keycode == KeyEvent.KEYCODE_FORWARD_DEL) {
      deleteSurroundingTextImpl(0, 1, true);
    } else if (keycode == KeyEvent.KEYCODE_ENTER) {
      // Finish text composition when pressing enter, as that may submit a form field.
      // TODO(aurimas): remove this workaround when crbug.com/278584 is fixed.
      finishComposingText();
    } else if ((unicodeChar & KeyCharacterMap.COMBINING_ACCENT) != 0) {
      // Store a pending accent character and make it the current composition.
      int pendingAccent = unicodeChar & KeyCharacterMap.COMBINING_ACCENT_MASK;
      StringBuilder builder = new StringBuilder();
      builder.appendCodePoint(pendingAccent);
      setComposingText(builder.toString(), 1);
      mPendingAccent = pendingAccent;
      return true;
    } else if (mPendingAccent != 0 && unicodeChar != 0) {
      int combined = KeyEvent.getDeadChar(mPendingAccent, unicodeChar);
      if (combined != 0) {
        StringBuilder builder = new StringBuilder();
        builder.appendCodePoint(combined);
        commitText(builder.toString(), 1);
        return true;
      }
      // Noncombinable character; commit the accent character and fall through to sending
      // the key event for the character afterwards.
      finishComposingText();
    }
    replaceSelectionWithUnicodeChar(unicodeChar);
    mImeAdapter.translateAndSendNativeEvents(event);
    return true;
  }