public List<CancelActionDescription> getCancelActionsList() { myCancelActionsList.clear(); if (ShowLibraryInCancelMenuOption.getValue()) { myCancelActionsList.add(new CancelActionDescription(CancelActionType.library, null)); } if (ShowNetworkLibraryInCancelMenuOption.getValue()) { myCancelActionsList.add(new CancelActionDescription(CancelActionType.networkLibrary, null)); } if (ShowPreviousBookInCancelMenuOption.getValue()) { final Book previousBook = Library.Instance().getPreviousBook(); if (previousBook != null) { myCancelActionsList.add( new CancelActionDescription(CancelActionType.previousBook, previousBook.getTitle())); } } if (ShowPositionsInCancelMenuOption.getValue()) { if (Model != null && Model.Book != null) { for (Bookmark bookmark : Library.Instance().invisibleBookmarks(Model.Book)) { myCancelActionsList.add(new BookmarkDescription(bookmark)); } } } myCancelActionsList.add(new CancelActionDescription(CancelActionType.close, null)); return myCancelActionsList; }
synchronized void openBookInternal(Book book, Bookmark bookmark) { if (book == null) { book = Library.Instance().getRecentBook(); if (book == null || !book.File.exists()) { book = Book.getByFile(Library.getHelpFile()); } if (book == null) { return; } } if (Model != null) { if (bookmark == null & book.File.getPath().equals(Model.Book.File.getPath())) { return; } } if (book != null) { onViewChanged(); if (Model != null) { Model.Book.storePosition(BookTextView.getStartCursor()); } BookTextView.setModel(null); FootnoteView.setModel(null); clearTextCaches(); Model = null; System.gc(); System.gc(); try { Model = BookModel.createModel(book); ZLTextHyphenator.Instance().load(book.getLanguage()); BookTextView.setModel(Model.getTextModel()); BookTextView.gotoPosition(book.getStoredPosition()); if (bookmark == null) { setView(BookTextView); } else { gotoBookmark(bookmark); } Library.Instance().addBookToRecentList(book); final StringBuilder title = new StringBuilder(book.getTitle()); if (!book.authors().isEmpty()) { boolean first = true; for (Author a : book.authors()) { title.append(first ? " (" : ", "); title.append(a.DisplayName); first = false; } title.append(")"); } setTitle(title.toString()); } catch (BookReadingException e) { processException(e); } } getViewWidget().reset(); getViewWidget().repaint(); }
private synchronized void updateInvisibleBookmarksList(Bookmark b) { if (Model != null && Model.Book != null && b != null) { for (Bookmark bm : Library.Instance().invisibleBookmarks(Model.Book)) { if (b.equals(bm)) { bm.delete(); } } b.save(); final List<Bookmark> bookmarks = Library.Instance().invisibleBookmarks(Model.Book); for (int i = 3; i < bookmarks.size(); ++i) { bookmarks.get(i).delete(); } } }
public void runCancelAction(int index) { if (index < 0 || index >= myCancelActionsList.size()) { return; } final CancelActionDescription description = myCancelActionsList.get(index); switch (description.Type) { case library: runAction(ActionCode.SHOW_LIBRARY); break; case networkLibrary: runAction(ActionCode.SHOW_NETWORK_LIBRARY); break; case previousBook: openBook(Library.Instance().getPreviousBook(), null, null); break; case returnTo: { final Bookmark b = ((BookmarkDescription) description).Bookmark; b.delete(); gotoBookmark(b); break; } case close: closeWindow(); break; } }
public boolean jumpBack() { try { if (getTextView() != BookTextView) { showBookTextView(); return true; } if (myJumpEndPosition == null || myJumpTimeStamp == null) { return false; } // more than 2 minutes ago if (myJumpTimeStamp.getTime() + 2 * 60 * 1000 < new Date().getTime()) { return false; } if (!myJumpEndPosition.equals(BookTextView.getStartCursor())) { return false; } final List<Bookmark> bookmarks = Library.Instance().invisibleBookmarks(Model.Book); if (bookmarks.isEmpty()) { return false; } final Bookmark b = bookmarks.get(0); b.delete(); gotoBookmark(b); return true; } finally { myJumpEndPosition = null; myJumpTimeStamp = null; } }
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); myDatabase = SQLiteBooksDatabase.Instance(); if (myDatabase == null) { myDatabase = new SQLiteBooksDatabase(this, "LIBRARY"); } if (myLibrary == null) { myLibrary = Library.Instance(); myLibrary.addChangeListener(this); myLibrary.startBuild(); } final String selectedBookPath = getIntent().getStringExtra(SELECTED_BOOK_PATH_KEY); mySelectedBook = null; if (selectedBookPath != null) { final ZLFile file = ZLFile.createFileByPath(selectedBookPath); if (file != null) { mySelectedBook = Book.getByFile(file); } } new LibraryTreeAdapter(this); myActivity = this; init(getIntent()); // commenting out to prevent soft keyboard when using Eyes-Free keyboard // getListView().setTextFilterEnabled(true); getListView().setOnCreateContextMenuListener(this); dialog = new Dialog(this); dialog.setContentView(R.layout.accessible_long_press_dialog); list = (ListView) dialog.findViewById(R.id.accessible_list); }