content: package org.tvp.kirikiri2;
  
  import android.content.Context;
  import android.view.KeyEvent;
  import android.view.View;
  import android.view.inputmethod.EditorInfo;
  import android.view.inputmethod.InputConnection;
  
  /* This is a fake invisible editor view that receives the input and defines the
   * pan&scan region
   */
  public class DummyEdit extends View implements View.OnKeyListener {
      InputConnection ic;
  
      public DummyEdit(Context context) {
          super(context);
          setFocusableInTouchMode(true);
          setFocusable(true);
          setOnKeyListener(this);
      }
  
      @Override
      public boolean onCheckIsTextEditor() {
          return true;
      }
  
      @Override
      public boolean onKey(View v, int keyCode, KeyEvent event) {
  
          // This handles the hardware keyboard input
          if (event.isPrintingKey()) {
              if (event.getAction() == KeyEvent.ACTION_DOWN) {
                  ic.commitText(String.valueOf((char) event.getUnicodeChar()), 1);
              }
              return true;
          }
          return false;
      }
  
      //
      @Override
      public boolean onKeyPreIme(int keyCode, KeyEvent event) {
          // As seen on StackOverflow: http://stackoverflow.com/questions/7634346/keyboard-hide-event
          // FIXME: Discussion at http://bugzilla.libsdl.org/show_bug.cgi?id=1639
          // FIXME: This is not a 100% effective solution to the problem of detecting if the keyboard is showing or not
          // FIXME: A more effective solution would be to change our Layout from AbsoluteLayout to Relative or Linear
          // FIXME: And determine the keyboard presence doing this: http://stackoverflow.com/questions/2150078/how-to-check-visibility-of-software-keyboard-in-android
          // FIXME: An even more effective way would be if Android provided this out of the box, but where would the fun be in that :)
          if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
              if (KR2Activity.mTextEdit != null && KR2Activity.mTextEdit.getVisibility() == View.VISIBLE) {
                  KR2Activity.hideTextInput();
                  //KR2Activity.nativeKeyboardFocusLost();
              }
          }
          return super.onKeyPreIme(keyCode, event);
      }
  
      @Override
      public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
          ic = new SDLInputConnection(this, true);
  
          outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI | 33554432 /* API 11: EditorInfo.IME_FLAG_NO_FULLSCREEN */;
  
          return ic;
      }
  }
  