Exemplo n.º 1
0
 private void onPreferencesUpdate(int resultCode) {
   final FBReaderApp fbReader = (FBReaderApp) FBReaderApp.Instance();
   switch (resultCode) {
     case RESULT_DO_NOTHING:
       break;
     case RESULT_REPAINT:
       {
         AndroidFontUtil.clearFontCache();
         final BookModel model = fbReader.Model;
         if (model != null) {
           final Book book = model.Book;
           if (book != null) {
             book.reloadInfoFromDatabase();
             ZLTextHyphenator.Instance().load(book.getLanguage());
           }
         }
         fbReader.clearTextCaches();
         fbReader.getViewWidget().repaint();
         break;
       }
     case RESULT_RELOAD_BOOK:
       fbReader.reloadBook();
       break;
   }
 }
Exemplo n.º 2
0
  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();
  }
Exemplo n.º 3
0
  LanguagePreference(Context context, ZLResource rootResource, String resourceKey, Book book) {
    super(context, rootResource, resourceKey);
    myBook = book;
    final TreeSet<String> set = new TreeSet<String>(new ZLLanguageUtil.CodeComparator());
    set.addAll(ZLTextHyphenator.Instance().languageCodes());
    set.add(ZLLanguageUtil.OTHER_LANGUAGE_CODE);

    final int size = set.size();
    String[] codes = new String[size];
    String[] names = new String[size];
    int index = 0;
    for (String code : set) {
      codes[index] = code;
      names[index] = ZLLanguageUtil.languageName(code);
      ++index;
    }
    setLists(codes, names);
    final String language = myBook.getLanguage();
    if (language == null || !setInitialValue(language)) {
      setInitialValue(ZLLanguageUtil.OTHER_LANGUAGE_CODE);
    }
  }
Exemplo n.º 4
0
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   final FBReaderApp fbreader = (FBReaderApp) FBReaderApp.Instance();
   switch (requestCode) {
     case REPAINT_CODE:
       {
         final BookModel model = fbreader.Model;
         if (model != null) {
           final Book book = model.Book;
           if (book != null) {
             book.reloadInfoFromDatabase();
             ZLTextHyphenator.Instance().load(book.getLanguage());
           }
         }
         fbreader.clearTextCaches();
         fbreader.getViewWidget().repaint();
         break;
       }
     case CANCEL_CODE:
       fbreader.runCancelAction(resultCode - 1);
       break;
   }
 }