Exemple #1
1
    @Override
    public void handleMessage(Message msg) {
      Context context = getContext();
      if (context == null) {
        Log.e(TAG, "error handling message, getContext() returned null");
        return;
      }
      switch (msg.arg1) {
        case COMMAND_CHANGE_TITLE:
          if (context instanceof Activity) {
            ((Activity) context).setTitle((String) msg.obj);
          } else {
            Log.e(TAG, "error handling message, getContext() returned no Activity");
          }
          break;
        case COMMAND_TEXTEDIT_HIDE:
          if (mTextEdit != null) {
            mTextEdit.setVisibility(View.GONE);

            InputMethodManager imm =
                (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(mTextEdit.getWindowToken(), 0);
          }
          break;

        default:
          if ((context instanceof SDLActivity)
              && !((SDLActivity) context).onUnhandledMessage(msg.arg1, msg.obj)) {
            Log.e(TAG, "error handling message, command is " + msg.arg1);
          }
      }
    }
    @Override
    public void handleMessage(Message msg) {
      Context context = getContext();
      if (context == null) {
        Log.e(TAG, "error handling message, getContext() returned null");
        return;
      }
      switch (msg.arg1) {
        case COMMAND_CHANGE_TITLE:
          if (context instanceof Activity) {
            ((Activity) context).setTitle((String) msg.obj);
          } else {
            Log.e(TAG, "error handling message, getContext() returned no Activity");
          }
          break;
        case COMMAND_TEXTEDIT_HIDE:
          if (mTextEdit != null) {
            mTextEdit.setVisibility(View.GONE);

            InputMethodManager imm =
                (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(mTextEdit.getWindowToken(), 0);
          }
          break;
        case COMMAND_SET_KEEP_SCREEN_ON:
          {
            Window window = ((Activity) context).getWindow();
            if (window != null) {
              if ((msg.obj instanceof Integer) && (((Integer) msg.obj).intValue() != 0)) {
                window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
              } else {
                window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
              }
            }
            break;
          }
        default:
          if ((context instanceof SDLActivity)
              && !((SDLActivity) context).onUnhandledMessage(msg.arg1, msg.obj)) {
            Log.e(TAG, "error handling message, command is " + msg.arg1);
          }
      }
    }