@ActionMethod(
      ids = {
        R.id.mainmenu_zoom,
        R.id.actions_toggleTouchManagerView,
        R.id.mainmenu_search,
        R.id.mainmenu_crop
      })
  public void toggleControls(final ActionEx action) {
    final View view = action.getParameter("view");
    final DocumentViewMode mode = action.getParameter("mode");
    if (mode != null && bookSettings != null && bookSettings.viewMode != mode) {

      final ActionDialogBuilder builder = new ActionDialogBuilder(getContext(), this);
      builder.setTitle(android.R.string.dialog_alert_title);
      builder.setMessage(R.string.error_invalid_view_mode, mode.getResValue());
      builder.setNegativeButton();
      builder.show();
      return;
    }
    ViewEffects.toggleControls(view);
    if (view instanceof ManualCropView) {
      final ManualCropView mcv = (ManualCropView) view;
      if (mcv.getVisibility() == View.VISIBLE) {
        mcv.initControls();
      }
    }
    IUIManager.instance.invalidateOptionsMenu(getManagedComponent());
  }
  public final boolean dispatchKeyEvent(final KeyEvent event) {
    final int action = event.getAction();
    final int keyCode = event.getKeyCode();

    if (getManagedComponent().getSearchControls().getVisibility() == View.VISIBLE) {
      if (action == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_BACK) {
        toggleControls(getAction(R.id.mainmenu_search));
        return true;
      }
      return false;
    }

    if (getDocumentController().dispatchKeyEvent(event)) {
      return true;
    }

    if (action == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_BACK) {
      if (event.getRepeatCount() == 0) {
        if (getManagedComponent().getTouchView().isShown()) {
          ViewEffects.toggleControls(getManagedComponent().getTouchView());
        } else if (getManagedComponent().getManualCropControls().isShown()) {
          ViewEffects.toggleControls(getManagedComponent().getManualCropControls());
        } else {

          if (history.goBack()) {
            return true;
          }

          if (AppSettings.current().confirmClose) {
            final ActionDialogBuilder builder =
                new ActionDialogBuilder(getManagedComponent(), this);
            builder.setTitle(R.string.confirmclose_title);
            builder.setMessage(R.string.confirmclose_msg);
            builder.setPositiveButton(R.id.mainmenu_close);
            builder.setNegativeButton().show();
          } else {
            getOrCreateAction(R.id.mainmenu_close).run();
          }
        }
      }
      return true;
    }
    return false;
  }