@Override
  public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    _menu = menu;

    try {
      if (content != null) {
        setPrevNextButtonState(content.getPageModel());
        _menu.findItem(R.id.menu_save_external).setVisible(false);
        _menu.findItem(R.id.menu_browser_back).setVisible(false);
      } else {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
          _menu.findItem(R.id.menu_save_external).setVisible(true);
        _menu.findItem(R.id.menu_browser_back).setVisible(true);
        if (webView != null) _menu.findItem(R.id.menu_browser_back).setEnabled(webView.canGoBack());
      }
    } catch (Exception e) {
      Log.w(TAG, "Cannot get current page model");
    }

    return true;
  }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case R.id.menu_settings:
        Intent launchNewIntent = new Intent(this, DisplaySettingsActivity.class);
        startActivity(launchNewIntent);
        return true;
      case R.id.menu_refresh_chapter_content:

        /*
         * Implement code to refresh chapter content
         */
        PageModel page = null;
        if (content != null) {
          try {
            page = content.getPageModel();
          } catch (Exception e) {
            Log.e(TAG, "Cannot get current chapter.", e);
          }
        } else {
          String pageStr = getIntent().getStringExtra(Constants.EXTRA_PAGE);
          try {
            page = NovelsDao.getInstance().getExistingPageModel(new PageModel(pageStr), null);
            if (page == null) {
              // no page model, just url
              page = new PageModel(pageStr);
              page.setExternal(true);
            }
          } catch (Exception e) {
            Log.e(TAG, "Cannot get current chapter.", e);
          }
        }

        if (page != null) {
          executeTask(page, true);
        }
        return true;
      case R.id.invert_colors:

        /*
         * Implement code to invert colors
         */
        UIHelper.ToggleColorPref(this);
        UIHelper.Recreate(this);
        return true;
      case R.id.menu_chapter_previous:

        /*
         * Implement code to move to previous chapter
         */
        String currentPage = getIntent().getStringExtra(Constants.EXTRA_PAGE);
        try {
          if (novelDetails == null)
            novelDetails =
                NovelsDao.getInstance().getNovelDetails(content.getPageModel(), null, false);
          PageModel prev =
              novelDetails.getPrev(
                  currentPage, UIHelper.getShowMissing(this), UIHelper.getShowRedlink(this));
          if (prev != null) {
            jumpTo(prev);
          } else {
            Toast.makeText(
                    this,
                    getResources().getString(R.string.first_available_chapter),
                    Toast.LENGTH_SHORT)
                .show();
          }
        } catch (Exception e) {
          Log.e(TAG, "Cannot get previous chapter.", e);
        }
        return true;
      case R.id.menu_chapter_next:

        /*
         * Implement code to move to next chapter
         */
        String currentPage2 = getIntent().getStringExtra(Constants.EXTRA_PAGE);
        try {
          if (novelDetails == null)
            novelDetails =
                NovelsDao.getInstance().getNovelDetails(content.getPageModel(), null, false);

          PageModel next =
              novelDetails.getNext(
                  currentPage2, UIHelper.getShowMissing(this), UIHelper.getShowRedlink(this));
          if (next != null) {
            jumpTo(next);
          } else {
            Toast.makeText(
                    this,
                    getResources().getString(R.string.last_available_chapter),
                    Toast.LENGTH_SHORT)
                .show();
          }
        } catch (Exception e) {
          Log.e(TAG, "Cannot get next chapter.", e);
        }
        return true;
      case R.id.menu_chapter_toc:
        if (tocMenu != null) tocMenu.show();
        return true;
      case R.id.menu_search:
        showSearchBox();
        return true;
      case R.id.menu_bookmarks_here:
        if (bookmarkMenu != null) bookmarkMenu.show();
        return true;
      case R.id.menu_bookmarks:
        Intent bookmarkIntent = new Intent(this, DisplayBookmarkActivity.class);
        startActivity(bookmarkIntent);
        return true;
      case R.id.menu_downloads_list:
        Intent downloadsItent = new Intent(this, DownloadListActivity.class);
        startActivity(downloadsItent);
        return true;
      case R.id.menu_speak:
        tts.start(webView, content.getLastYScroll());
        return true;
      case R.id.menu_pause_tts:
        tts.pause();
        return true;
      case R.id.menu_save_external:
        // save based on current intent page name.
        String url = getIntent().getStringExtra(Constants.EXTRA_PAGE);
        NonLeakingWebView wv = (NonLeakingWebView) findViewById(R.id.webViewContent);
        if (!url.startsWith("http")) {
          url = getTitle().toString();
          Log.w(
              TAG,
              "Current page is not started with http, resolve from current webView url: " + url);
        }

        if (wv != null && !Util.isStringNullOrEmpty(url)) wv.saveMyWebArchive(url);
        return true;
      case R.id.menu_browser_back:
        if (webView != null && webView.canGoBack()) {
          // only good for android 4.4++
          webView.goBack();
        }
        return true;
      case android.R.id.home:
        finish();
        return true;
      default:
        return super.onOptionsItemSelected(item);
    }
  }