示例#1
0
 @Override
 public boolean dispatchKeyEvent(KeyEvent event) {
   int keyCode = event.getKeyCode();
   // Ignore volume keys so they're handled by Android
   if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
     return false;
   }
   return super.dispatchKeyEvent(event);
 }
示例#2
0
 @Override
 public boolean dispatchKeyEvent(KeyEvent event) {
   int keyCode = event.getKeyCode();
   // Ignore certain special keys so they're handled by Android
   if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
       || keyCode == KeyEvent.KEYCODE_VOLUME_UP
       || keyCode == KeyEvent.KEYCODE_CAMERA
       || keyCode == 168
       || /* API 11: KeyEvent.KEYCODE_ZOOM_IN */ keyCode
           == 169 /* API 11: KeyEvent.KEYCODE_ZOOM_OUT */) {
     return false;
   }
   return super.dispatchKeyEvent(event);
 }
示例#3
0
  @Override
  public boolean sendKeyEvent(KeyEvent event) {

    /*
     * This handles the keycodes from soft keyboard (and IME-translated
     * input from hardkeyboard)
     */
    int keyCode = event.getKeyCode();
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
      if (event.isPrintingKey()) {
        commitText(String.valueOf((char) event.getUnicodeChar()), 1);
      }
      SDLActivity.onNativeKeyDown(keyCode);
      return true;
    } else if (event.getAction() == KeyEvent.ACTION_UP) {

      SDLActivity.onNativeKeyUp(keyCode);
      return true;
    }
    return super.sendKeyEvent(event);
  }
示例#4
0
  @Override
  public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
    Log.d(TAG, "onEditorAction: actionId: " + actionId + ", keyEvent: " + keyEvent);

    if ((actionId == EditorInfo.IME_ACTION_DONE)
        || ((keyEvent != null) && (keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER))) {
      Log.d(TAG, "onEditorAction: IME_ACTION_DONE || KEYCODE_ENTER");
      String input = textView.getText().toString().trim();

      if (input.length() > 0) {
        String result = "";

        try {
          result += calculator.calculate(input);
        } catch (Exception e) {
          result = "no result (" + e.getMessage() + ")";
        }

        if (listAdapter.getCount() > 0) {
          listAdapter.add("");
        }

        listAdapter.add(input + " =");
        if (input.indexOf("@") > -1) {
          listAdapter.add(calculator.getEquation() + " =");
        }
        listAdapter.add(result);
        listAdapter.notifyDataSetChanged();

        inputView.endBatchEdit();
        inputView.setText("");
        hideKeyboard();
      }
    }

    return false;
  }