Ejemplo n.º 1
0
    @Override
    public void handleMessage(Message msg) {
      switch (msg.what) {
        case HANDLER_OPEN_IME_KEYBOARD:
          if (null != sGLSurfaceView.mCocosEditText
              && sGLSurfaceView.mCocosEditText.requestFocus()) {
            sGLSurfaceView.mCocosEditText.removeTextChangedListener(
                Cocos2dxGLSurfaceView.sTextInputWrapper);
            sGLSurfaceView.mCocosEditText.setText("");
            final String text = (String) msg.obj;
            sGLSurfaceView.mCocosEditText.append(text);
            Cocos2dxGLSurfaceView.sTextInputWrapper.setOriginText(text);
            sGLSurfaceView.mCocosEditText.addTextChangedListener(
                Cocos2dxGLSurfaceView.sTextInputWrapper);

            InputMethodManager imm =
                (InputMethodManager)
                    Cocos2dxActivity.COCOS_ACTIVITY.getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInput(sGLSurfaceView.mCocosEditText, 0);
            Log.d(TAG, "showSoftInput");
          }
          break;

        case HANDLER_CLOSE_IME_KEYBOARD:
          if (null != sGLSurfaceView.mCocosEditText) {
            sGLSurfaceView.mCocosEditText.removeTextChangedListener(
                Cocos2dxGLSurfaceView.sTextInputWrapper);
            InputMethodManager imm =
                (InputMethodManager)
                    Cocos2dxActivity.COCOS_ACTIVITY.getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(sGLSurfaceView.mCocosEditText.getWindowToken(), 0);
            sGLSurfaceView.requestFocus();
            Log.d(TAG, "HideSoftInput");
          }
          break;
      }
    }