/**
   * called during app close down to save state
   *
   * @param outState
   */
  public void saveState(SharedPreferences outState) {
    Log.i(TAG, "save state");
    currentBiblePage.saveState(outState);
    currentCommentaryPage.saveState(outState);
    currentDictionaryPage.saveState(outState);
    currentGeneralBookPage.saveState(outState);

    SharedPreferences.Editor editor = outState.edit();
    editor.putString("currentPageCategory", currentDisplayedPage.getBookCategory().getName());
    editor.commit();
  }
  /** display a new Document and return the new Page */
  public CurrentPage setCurrentDocument(Book nextDocument) {
    CurrentPage nextPage = null;
    if (nextDocument != null) {
      PassageChangeMediator.getInstance().onBeforeCurrentPageChanged();

      nextPage = getBookPage(nextDocument);

      // is the next doc the same as the prev doc
      boolean sameDoc = nextDocument.equals(nextPage.getCurrentDocument());

      // must be in this order because History needs to grab the current doc before change
      nextPage.setCurrentDocument(nextDocument);
      currentDisplayedPage = nextPage;

      // page will change due to above
      // if there is a valid share key or the doc (hence the key) in the next page is the same then
      // show the page straight away
      if ((nextPage.isShareKeyBetweenDocs() || sameDoc) && nextPage.getKey() != null) {
        PassageChangeMediator.getInstance().onCurrentPageChanged();
      } else {
        Context context = CurrentActivityHolder.getInstance().getCurrentActivity();
        // pop up a key selection screen
        Intent intent = new Intent(context, nextPage.getKeyChooserActivity());
        context.startActivity(intent);
      }
    } else {
      // should never get here because a doc should always be passed in but I have seen errors lie
      // this once or twice
      nextPage = currentDisplayedPage;
    }

    return nextPage;
  }
  public CurrentPage setCurrentDocumentAndKeyAndOffset(
      Book currentBook, Key key, float yOffsetRatio) {
    PassageChangeMediator.getInstance().onBeforeCurrentPageChanged();

    CurrentPage nextPage = getBookPage(currentBook);
    if (nextPage != null) {
      try {
        nextPage.setInhibitChangeNotifications(true);
        nextPage.setCurrentDocument(currentBook);
        nextPage.setKey(key);
        nextPage.setCurrentYOffsetRatio(yOffsetRatio);
        currentDisplayedPage = nextPage;
      } finally {
        nextPage.setInhibitChangeNotifications(false);
      }
    }
    // valid key has been set so do not need to show a key chooser therefore just update main view
    PassageChangeMediator.getInstance().onCurrentPageChanged();

    return nextPage;
  }