Esempio n. 1
0
  /** Called whenever an action bar button is pressed. */
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case R.id.actionbar_keyboard:
        ((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).toggleSoftInput(0, 0);
        return true;

      case R.id.actionbar_hide:
        hideActionBar();
        return true;

      case R.id.actionbar_disconnect:
        JniInterface.disconnectFromHost();
        return true;

      case R.id.actionbar_send_ctrl_alt_del:
        {
          int[] keys = {
            KeyEvent.KEYCODE_CTRL_LEFT, KeyEvent.KEYCODE_ALT_LEFT, KeyEvent.KEYCODE_FORWARD_DEL,
          };
          for (int key : keys) {
            JniInterface.keyboardAction(key, true);
          }
          for (int key : keys) {
            JniInterface.keyboardAction(key, false);
          }
        }
        return true;

      default:
        return super.onOptionsItemSelected(item);
    }
  }
Esempio n. 2
0
  /**
   * Called once when a keyboard key is pressed, then again when that same key is released. This is
   * not guaranteed to be notified of all soft keyboard events: certian keyboards might not call it
   * at all, while others might skip it in certain situations (e.g. swipe input).
   */
  @Override
  public boolean dispatchKeyEvent(KeyEvent event) {
    boolean depressed = event.getAction() == KeyEvent.ACTION_DOWN;

    switch (event.getKeyCode()) {
      case KeyEvent.KEYCODE_AT:
        JniInterface.keyboardAction(KeyEvent.KEYCODE_SHIFT_LEFT, depressed);
        JniInterface.keyboardAction(KeyEvent.KEYCODE_2, depressed);
        break;

      case KeyEvent.KEYCODE_POUND:
        JniInterface.keyboardAction(KeyEvent.KEYCODE_SHIFT_LEFT, depressed);
        JniInterface.keyboardAction(KeyEvent.KEYCODE_3, depressed);
        break;

      case KeyEvent.KEYCODE_STAR:
        JniInterface.keyboardAction(KeyEvent.KEYCODE_SHIFT_LEFT, depressed);
        JniInterface.keyboardAction(KeyEvent.KEYCODE_8, depressed);
        break;

      case KeyEvent.KEYCODE_PLUS:
        JniInterface.keyboardAction(KeyEvent.KEYCODE_SHIFT_LEFT, depressed);
        JniInterface.keyboardAction(KeyEvent.KEYCODE_EQUALS, depressed);
        break;

      default:
        // We try to send all other key codes to the host directly.
        JniInterface.keyboardAction(event.getKeyCode(), depressed);
    }

    return super.dispatchKeyEvent(event);
  }