gt:     protected void updateMenuItems(final Menu menu) {
context: package org.ebookdroid.ui.viewer;
  
  import org.ebookdroid.common.settings.types.DocumentViewMode;
  import org.ebookdroid.common.settings.types.RotationType;
  import org.emdev.ui.uimanager.UIManagerAppCompat;
  import org.sufficientlysecure.viewer.R;
  import org.ebookdroid.common.settings.AppSettings;
  import org.ebookdroid.common.settings.books.BookSettings;
  import org.ebookdroid.common.settings.books.Bookmark;
  import org.ebookdroid.common.settings.types.ToastPosition;
  import org.ebookdroid.common.touch.TouchManagerView;
  import org.ebookdroid.core.DecodeService;
  import org.ebookdroid.core.codec.CodecFeatures;
  import org.ebookdroid.ui.viewer.stubs.ViewStub;
  import org.ebookdroid.ui.viewer.viewers.GLView;
  import org.ebookdroid.ui.viewer.views.ManualCropView;
  import org.ebookdroid.ui.viewer.views.PageViewZoomControls;
  import org.ebookdroid.ui.viewer.views.SearchControls;
  
  import android.content.Intent;
  import android.os.Bundle;
  import android.support.v7.widget.Toolbar;
  import android.util.DisplayMetrics;
  import android.view.ContextMenu;
  import android.view.ContextMenu.ContextMenuInfo;
  import android.view.Gravity;
  import android.view.KeyEvent;
  import android.view.Menu;
  import android.view.MenuInflater;
  import android.view.MenuItem;
  import android.view.SubMenu;
  import android.view.View;
  import android.widget.FrameLayout;
  import android.widget.Toast;
  
  import org.emdev.common.android.AndroidVersion;
  import org.emdev.ui.AbstractActionActivity;
  import org.emdev.ui.actions.ActionDialogBuilder;
  import org.emdev.ui.actions.ActionMenuHelper;
  import org.emdev.ui.gl.GLConfiguration;
  import org.emdev.ui.uimanager.IUIManager;
  import org.emdev.utils.LayoutUtils;
  import org.emdev.utils.LengthUtils;
  
  public class ViewerActivity extends AbstractActionActivity<ViewerActivity, ViewerActivityController> {
  
      public static final DisplayMetrics DM = new DisplayMetrics();
  
      IView view;
  
      private Toast pageNumberToast;
  
      private Toast zoomToast;
  
      private PageViewZoomControls zoomControls;
  
      private SearchControls searchControls;
  
      private FrameLayout frameLayout;
  
      private TouchManagerView touchView;
  
      private boolean menuClosedCalled;
  
      private ManualCropView cropControls;
  
      /**
       * Instantiates a new base viewer activity.
       */
      public ViewerActivity() {
          super(false, ON_CREATE, ON_RESUME, ON_PAUSE, ON_DESTROY);
      }
  
      /**
       * {@inheritDoc}
       * 
       * @see org.emdev.ui.AbstractActionActivity#createController()
       */
      @Override
      protected ViewerActivityController createController() {
          return new ViewerActivityController(this);
      }
  
      /**
       * {@inheritDoc}
       * 
       * @see android.app.Activity#onNewIntent(android.content.Intent)
       */
      @Override
      protected void onNewIntent(final Intent intent) {
          super.onNewIntent(intent);
          if (LCTX.isDebugEnabled()) {
              LCTX.d("onNewIntent(): " + intent);
          }
      }
  
      /**
       * {@inheritDoc}
       * 
       * @see org.emdev.ui.AbstractActionActivity#onCreateImpl(android.os.Bundle)
       */
      @Override
      protected void onCreateImpl(final Bundle savedInstanceState) {
          getWindowManager().getDefaultDisplay().getMetrics(DM);
          LCTX.i("XDPI=" + DM.xdpi + ", YDPI=" + DM.ydpi);
  
          View rootLayout = getLayoutInflater().inflate(R.layout.viewer, null);
  
          frameLayout = (FrameLayout) rootLayout.findViewById(R.id.framelayout);
  
          view = ViewStub.STUB;
  
          try {
              GLConfiguration.checkConfiguration();
  
              view = new GLView(getController());
              this.registerForContextMenu(view.getView());
  
              LayoutUtils.fillInParent(frameLayout, view.getView());
  
              frameLayout.addView(view.getView());
              frameLayout.addView(getZoomControls());
              frameLayout.addView(getManualCropControls());
              frameLayout.addView(getSearchControls());
              frameLayout.addView(getTouchView());
  
          } catch (final Throwable th) {
              final ActionDialogBuilder builder = new ActionDialogBuilder(this, getController());
              builder.setTitle(R.string.error_dlg_title);
              builder.setMessage(th.getMessage());
              builder.setPositiveButton(R.string.error_close, R.id.mainmenu_close);
              builder.show();
          }
  
          setContentView(rootLayout);
  
          Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
          setSupportActionBar(toolbar);
  
          getSupportActionBar().setDisplayShowHomeEnabled(true);
          getSupportActionBar().setDisplayHomeAsUpEnabled(true);
      }
  
      /**
       * {@inheritDoc}
       * 
       * @see org.emdev.ui.AbstractActionActivity#onResumeImpl()
       */
      @Override
      protected void onResumeImpl() {
          IUIManager.instance.onResume(this);
      }
  
      /**
       * {@inheritDoc}
       * 
       * @see org.emdev.ui.AbstractActionActivity#onPauseImpl(boolean)
       */
      @Override
      protected void onPauseImpl(final boolean finishing) {
          IUIManager.instance.onPause(this);
      }
  
      /**
       * {@inheritDoc}
       * 
       * @see org.emdev.ui.AbstractActionActivity#onDestroyImpl(boolean)
       */
      @Override
      protected void onDestroyImpl(final boolean finishing) {
          view.onDestroy();
      }
  
      /**
       * {@inheritDoc}
       * 
       * @see android.app.Activity#onWindowFocusChanged(boolean)
       */
      @Override
      public void onWindowFocusChanged(final boolean hasFocus) {
          if (hasFocus && this.view != null) {
              IUIManager.instance.setFullScreenMode(this, this.view.getView(), AppSettings.current().fullScreen);
          }
      }
  
      public TouchManagerView getTouchView() {
          if (touchView == null) {
              touchView = new TouchManagerView(getController());
          }
          return touchView;
      }
  
      public void currentPageChanged(final String pageText) {
          if (LengthUtils.isEmpty(pageText)) {
              return;
          }
  
          final AppSettings app = AppSettings.current();
          if (UIManagerAppCompat.isToolbarVisible(this) && app.pageInTitle) {
              return;
          }
  
          if (app.pageNumberToastPosition == ToastPosition.Invisible) {
              return;
          }
          if (pageNumberToast != null) {
              pageNumberToast.setText(pageText);
          } else {
              pageNumberToast = Toast.makeText(this, pageText, Toast.LENGTH_SHORT);
          }
  
          pageNumberToast.setGravity(app.pageNumberToastPosition.position, 0, 0);
          pageNumberToast.show();
      }
  
      public void zoomChanged(final float zoom) {
          if (getZoomControls().isShown()) {
              return;
          }
  
          final AppSettings app = AppSettings.current();
  
          if (app.zoomToastPosition == ToastPosition.Invisible) {
              return;
          }
  
          final String zoomText = String.format("%.2f", zoom) + "x";
  
          if (zoomToast != null) {
              zoomToast.setText(zoomText);
          } else {
              zoomToast = Toast.makeText(this, zoomText, Toast.LENGTH_SHORT);
          }
  
          zoomToast.setGravity(app.zoomToastPosition.position, 0, 0);
          zoomToast.show();
      }
  
      public PageViewZoomControls getZoomControls() {
          if (zoomControls == null) {
              zoomControls = new PageViewZoomControls(this, getController().getZoomModel());
              zoomControls.setGravity(Gravity.RIGHT | Gravity.BOTTOM);
          }
          return zoomControls;
      }
  
      public SearchControls getSearchControls() {
          if (searchControls == null) {
              searchControls = new SearchControls(this);
          }
          return searchControls;
      }
  
      public ManualCropView getManualCropControls() {
          if (cropControls == null) {
              cropControls = new ManualCropView(getController());
          }
          return cropControls;
      }
  
      /**
       * {@inheritDoc}
       * 
       * @see android.app.Activity#onCreateContextMenu(android.view.ContextMenu, android.view.View,
       *      android.view.ContextMenu.ContextMenuInfo)
       */
      @Override
      public void onCreateContextMenu(final ContextMenu menu, final View v, final ContextMenuInfo menuInfo) {
          menu.clear();
          menu.setHeaderTitle(R.string.app_name);
          menu.setHeaderIcon(R.drawable.application_icon);
          final MenuInflater inflater = getMenuInflater();
          inflater.inflate(R.menu.mainmenu_context, menu);
          updateMenuItems(menu);
      }
  
      /**
       * {@inheritDoc}
       * 
       * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu)
       */
      @Override
      public boolean onCreateOptionsMenu(final Menu menu) {
          menu.clear();
  
          final MenuInflater inflater = getMenuInflater();
  
          if (hasNormalMenu()) {
              inflater.inflate(R.menu.mainmenu, menu);
          } else {
              inflater.inflate(R.menu.mainmenu_context, menu);
          }
  
          return true;
      }
  
      protected boolean hasNormalMenu() {
          return IUIManager.instance.isTabletUi(this) || AppSettings.current().showTitle;
      }
  
      /**
       * {@inheritDoc}
       * 
       * @see android.app.Activity#onMenuOpened(int, android.view.Menu)
       */
      @Override
      public boolean onMenuOpened(final int featureId, final Menu menu) {
          view.changeLayoutLock(true);
          IUIManager.instance.onMenuOpened(this);
          return super.onMenuOpened(featureId, menu);
      }
  
      /**
       * {@inheritDoc}
       * 
       * @see org.emdev.ui.AbstractActionActivity#updateMenuItems(android.view.Menu)
       */
      @Override
  