content: package org.tvp.kirikiri2;
  
  
  import android.view.KeyEvent;
  import android.view.View;
  import android.view.inputmethod.BaseInputConnection;
  
  public class SDLInputConnection extends BaseInputConnection {
  
      public SDLInputConnection(View targetView, boolean fullEditor) {
          super(targetView, fullEditor);
  
      }
  
      @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);
                  KR2Activity.nativeCharInput(keyCode);
              } else if (keyCode == KeyEvent.KEYCODE_DEL) {
                  KR2Activity.nativeKeyAction(keyCode, true);
              }
              return true;
          } else if (event.getAction() == KeyEvent.ACTION_UP) {
              if (keyCode == KeyEvent.KEYCODE_DEL) {
                  KR2Activity.nativeKeyAction(keyCode, false);
              }
              //KR2Activity.nativeKeyAction(keyCode, false);
              return true;
          }
          return super.sendKeyEvent(event);
      }
  
      @Override
      public boolean commitText(CharSequence text, int newCursorPosition) {
  
          KR2Activity.nativeCommitText(text.toString(), newCursorPosition);
  
          return super.commitText(text, newCursorPosition);
      }
  
      @Override
      public boolean setComposingText(CharSequence text, int newCursorPosition) {
  
          //nativeSetComposingText(text.toString(), newCursorPosition);
  
          return super.setComposingText(text, newCursorPosition);
      }
  
      //public native void nativeSetComposingText(String text, int newCursorPosition);
  
      @Override
      public boolean deleteSurroundingText(int beforeLength, int afterLength) {
          // Workaround to capture backspace key. Ref: http://stackoverflow.com/questions/14560344/android-backspace-in-webview-baseinputconnection
          if (beforeLength == 1 && afterLength == 0) {
              // backspace
              return super.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL))
                      && super.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DEL));
          }
  
          return super.deleteSurroundingText(beforeLength, afterLength);
      }
  }
  