@Override public Footer getFooterArea() { switch (myViewOptions.ScrollbarType.getValue()) { case SCROLLBAR_SHOW_AS_FOOTER: if (!(myFooter instanceof FooterNewStyle)) { if (myFooter != null) { myReader.removeTimerTask(myFooter.UpdateTask); } myFooter = new FooterNewStyle(); myReader.addTimerTask(myFooter.UpdateTask, 15000); } break; case SCROLLBAR_SHOW_AS_FOOTER_OLD_STYLE: if (!(myFooter instanceof FooterOldStyle)) { if (myFooter != null) { myReader.removeTimerTask(myFooter.UpdateTask); } myFooter = new FooterOldStyle(); myReader.addTimerTask(myFooter.UpdateTask, 15000); } break; default: if (myFooter != null) { myReader.removeTimerTask(myFooter.UpdateTask); myFooter = null; } break; } return myFooter; }
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; } }
public void hideSelectionPanel() { final FBReaderApp fbReader = (FBReaderApp) FBReaderApp.Instance(); final FBReaderApp.PopupPanel popup = fbReader.getActivePopup(); if (popup != null && popup.getId() == SelectionPopup.ID) { FBReaderApp.Instance().hideActivePopup(); } }
@Override public void onFingerMove(int x, int y) { final SelectionCursor.Which cursor = getSelectionCursorInMovement(); if (cursor != null) { moveSelectionCursorTo(cursor, x, y); return; } synchronized (this) { if (myIsBrightnessAdjustmentInProgress) { if (x >= getContextWidth() / 5) { myIsBrightnessAdjustmentInProgress = false; startManualScrolling(x, y); } else { final int delta = (myStartBrightness + 30) * (myStartY - y) / getContextHeight(); myReader.getViewWidget().setScreenBrightness(myStartBrightness + delta); return; } } if (isFlickScrollingEnabled()) { myReader.getViewWidget().scrollManuallyTo(x, y); } } }
public void showSelectionPanel() { final FBReaderApp fbReader = (FBReaderApp) FBReaderApp.Instance(); final ZLTextView view = fbReader.getTextView(); ((SelectionPopup) fbReader.getPopupById(SelectionPopup.ID)) .move(view.getSelectionStartY(), view.getSelectionEndY()); fbReader.showPopup(SelectionPopup.ID); }
void openBookText(TOCTree tree) { final TOCTree.Reference reference = tree.getReference(); if (reference != null) { finish(); final FBReaderApp fbreader = (FBReaderApp) ZLApplication.Instance(); fbreader.addInvisibleBookmark(); fbreader.BookTextView.gotoPosition(reference.ParagraphIndex, 0, 0); fbreader.showBookTextView(); } }
@Override public void onFingerDoubleTap(int x, int y) { myReader.runAction(ActionCode.HIDE_TOAST); myReader.runAction( getZoneMap() .getActionByCoordinates( x, y, getContextWidth(), getContextHeight(), TapZoneMap.Tap.doubleTap), x, y); }
@Override public void onFingerMoveAfterLongPress(int x, int y) { final SelectionCursor.Which cursor = getSelectionCursorInMovement(); if (cursor != null) { moveSelectionCursorTo(cursor, x, y); return; } ZLTextRegion region = getOutlinedRegion(); if (region != null) { ZLTextRegion.Soul soul = region.getSoul(); if (soul instanceof ZLTextHyperlinkRegionSoul || soul instanceof ZLTextWordRegionSoul) { if (myReader.MiscOptions.WordTappingAction.getValue() != MiscOptions.WordTappingActionEnum.doNothing) { region = findRegion(x, y, maxSelectionDistance(), ZLTextRegion.AnyRegionFilter); if (region != null) { soul = region.getSoul(); if (soul instanceof ZLTextHyperlinkRegionSoul || soul instanceof ZLTextWordRegionSoul) { outlineRegion(region); myReader.getViewWidget().reset(); myReader.getViewWidget().repaint(); } } } } } }
@Override protected void releaseSelectionCursor() { super.releaseSelectionCursor(); if (getCountOfSelectedWords() > 0) { myReader.runAction(ActionCode.SELECTION_SHOW_PANEL); } }
@Override public void onFingerReleaseAfterLongPress(int x, int y) { final SelectionCursor.Which cursor = getSelectionCursorInMovement(); if (cursor != null) { releaseSelectionCursor(); return; } final ZLTextRegion region = getOutlinedRegion(); if (region != null) { final ZLTextRegion.Soul soul = region.getSoul(); boolean doRunAction = false; if (soul instanceof ZLTextWordRegionSoul) { doRunAction = myReader.MiscOptions.WordTappingAction.getValue() == MiscOptions.WordTappingActionEnum.openDictionary; } else if (soul instanceof ZLTextImageRegionSoul) { doRunAction = myReader.ImageOptions.TapAction.getValue() == ImageOptions.TapActionEnum.openImageView; } if (doRunAction) { myReader.runAction(ActionCode.PROCESS_HYPERLINK); } } }
boolean readBook(ZLFile file) { myFilePrefix = MiscUtil.htmlDirectoryPrefix(file); myIdToHref.clear(); myHtmlFileNames.clear(); myParagraphIndexList.clear(); myNCXTOCFileName = null; myTourTOC.clear(); myGuideTOC.clear(); myState = READ_NONE; if (!read(file)) { return false; } myModelReader.setMainTextModel(); myModelReader.pushKind(FBTextKind.REGULAR); int count = 0; for (String name : myHtmlFileNames) { final ZLFile xhtmlFile = ZLFile.createFileByPath(myFilePrefix + name); if (xhtmlFile == null) { // NPE fix: null for bad attributes in .opf XML file return false; } if (count++ == 0 && xhtmlFile.getPath().equals(myCoverFileName)) { continue; } final XHTMLReader reader = new XHTMLReader(myModelReader, myFileNumbers); final String referenceName = reader.getFileAlias(MiscUtil.archiveEntryName(xhtmlFile.getPath())); myModelReader.addHyperlinkLabel(referenceName); myParagraphIndexList.add(myModelReader.Model.BookTextModel.getParagraphsNumber()); myTOCLabels.put(referenceName, myModelReader.Model.BookTextModel.getParagraphsNumber()); reader.readFile(xhtmlFile, referenceName + '#'); myModelReader.insertEndOfSectionParagraph(); } final FBReaderApp fbreader = (FBReaderApp) ZLApplication.Instance(); // fbreader.setTOCLabels(myTOCLabels); fbreader.setParagraphIndexList(myParagraphIndexList); fbreader.setHtmlFileNames(myHtmlFileNames, myFilePrefix, myCoverFileName); generateTOC(); return true; }
@Override public boolean onSearchRequested() { final FBReaderApp fbreader = (FBReaderApp) FBReaderApp.Instance(); final FBReaderApp.PopupPanel popup = fbreader.getActivePopup(); fbreader.hideActivePopup(); final SearchManager manager = (SearchManager) getSystemService(SEARCH_SERVICE); manager.setOnCancelListener( new SearchManager.OnCancelListener() { public void onCancel() { if (popup != null) { fbreader.showPopup(popup.getId()); } manager.setOnCancelListener(null); } }); startSearch(fbreader.TextSearchPatternOption.getValue(), true, null, false); return true; }
private void startManualScrolling(int x, int y) { if (!isFlickScrollingEnabled()) { return; } final boolean horizontal = myReader.PageTurningOptions.Horizontal.getValue(); final Direction direction = horizontal ? Direction.rightToLeft : Direction.up; myReader.getViewWidget().startManualScrolling(x, y, direction); }
private void initPluginActions() { final FBReaderApp fbReader = (FBReaderApp) FBReaderApp.Instance(); synchronized (myPluginActions) { int index = 0; while (index < myPluginActions.size()) { fbReader.removeAction(PLUGIN_ACTION_PREFIX + index++); } myPluginActions.clear(); } sendOrderedBroadcast( new Intent(PluginApi.ACTION_REGISTER), null, myPluginInfoReceiver, null, RESULT_OK, null, null); }
@Override protected void onNewIntent(Intent intent) { final Uri data = intent.getData(); final FBReaderApp fbReader = (FBReaderApp) FBReaderApp.Instance(); if ((intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0) { super.onNewIntent(intent); } else if (Intent.ACTION_VIEW.equals(intent.getAction()) && data != null && "fbreader-action".equals(data.getScheme())) { fbReader.runAction(data.getEncodedSchemeSpecificPart(), data.getFragment()); } else if (Intent.ACTION_SEARCH.equals(intent.getAction())) { final String pattern = intent.getStringExtra(SearchManager.QUERY); final Runnable runnable = new Runnable() { public void run() { final TextSearchPopup popup = (TextSearchPopup) fbReader.getPopupById(TextSearchPopup.ID); popup.initPosition(); fbReader.TextSearchPatternOption.setValue(pattern); if (fbReader.getTextView().search(pattern, true, false, false, false) != 0) { runOnUiThread( new Runnable() { public void run() { fbReader.showPopup(popup.getId()); } }); } else { runOnUiThread( new Runnable() { public void run() { UIUtil.showErrorMessage(FBReader.this, "textNotFound"); popup.StartPosition = null; } }); } } }; UIUtil.wait("search", runnable, this); } else { super.onNewIntent(intent); } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_PREFERENCES: case REQUEST_BOOK_INFO: onPreferencesUpdate(resultCode); break; case REQUEST_CANCEL_MENU: ((FBReaderApp) FBReaderApp.Instance()).runCancelAction(resultCode - 1); break; } }
@Override public boolean onFingerLongPress(int x, int y) { myReader.runAction(ActionCode.HIDE_TOAST); final ZLTextRegion region = findRegion(x, y, maxSelectionDistance(), ZLTextRegion.AnyRegionFilter); if (region != null) { final ZLTextRegion.Soul soul = region.getSoul(); boolean doSelectRegion = false; if (soul instanceof ZLTextWordRegionSoul) { switch (myReader.MiscOptions.WordTappingAction.getValue()) { case startSelecting: myReader.runAction(ActionCode.SELECTION_HIDE_PANEL); initSelection(x, y); final SelectionCursor.Which cursor = findSelectionCursor(x, y); if (cursor != null) { moveSelectionCursorTo(cursor, x, y); } return true; case selectSingleWord: case openDictionary: doSelectRegion = true; break; } } else if (soul instanceof ZLTextImageRegionSoul) { doSelectRegion = myReader.ImageOptions.TapAction.getValue() != ImageOptions.TapActionEnum.doNothing; } else if (soul instanceof ZLTextHyperlinkRegionSoul) { doSelectRegion = true; } if (doSelectRegion) { outlineRegion(region); myReader.getViewWidget().reset(); myReader.getViewWidget().repaint(); return true; } } return false; }
@Override public void onFingerRelease(int x, int y) { final SelectionCursor.Which cursor = getSelectionCursorInMovement(); if (cursor != null) { releaseSelectionCursor(); } else if (myIsBrightnessAdjustmentInProgress) { myIsBrightnessAdjustmentInProgress = false; } else if (isFlickScrollingEnabled()) { myReader .getViewWidget() .startAnimatedScrolling(x, y, myReader.PageTurningOptions.AnimationSpeed.getValue()); } }
@Override public void onFingerPress(int x, int y) { myReader.runAction(ActionCode.HIDE_TOAST); final float maxDist = ZLibrary.Instance().getDisplayDPI() / 4; final SelectionCursor.Which cursor = findSelectionCursor(x, y, maxDist * maxDist); if (cursor != null) { myReader.runAction(ActionCode.SELECTION_HIDE_PANEL); moveSelectionCursorTo(cursor, x, y); return; } if (myReader.MiscOptions.AllowScreenBrightnessAdjustment.getValue() && x < getContextWidth() / 10) { myIsBrightnessAdjustmentInProgress = true; myStartY = y; myStartBrightness = myReader.getViewWidget().getScreenBrightness(); return; } startManualScrolling(x, y); }
@Override public void onReceive(Context context, Intent intent) { final ArrayList<PluginApi.ActionInfo> actions = getResultExtras(true) .<PluginApi.ActionInfo>getParcelableArrayList(PluginApi.PluginInfo.KEY); if (actions != null) { synchronized (myPluginActions) { final FBReaderApp fbReader = (FBReaderApp) FBReaderApp.Instance(); int index = 0; while (index < myPluginActions.size()) { fbReader.removeAction(PLUGIN_ACTION_PREFIX + index++); } myPluginActions.addAll(actions); index = 0; for (PluginApi.ActionInfo info : myPluginActions) { fbReader.addAction( PLUGIN_ACTION_PREFIX + index++, new RunPluginAction(FBReader.this, fbReader, info.getId())); } } } }
/* * private class TipRunner extends Thread { TipRunner() { * setPriority(MIN_PRIORITY); } * * public void run() { final TipsManager manager = TipsManager.Instance(); * switch (manager.requiredAction()) { case Initialize: startActivity(new * Intent(TipsActivity.INITIALIZE_ACTION, null, FBReader.this, * TipsActivity.class)); break; case Show: startActivity(new * Intent(TipsActivity.SHOW_TIP_ACTION, null, FBReader.this, * TipsActivity.class)); break; case Download: manager.startDownloading(); * break; case None: break; } } } */ @Override public void onResume() { super.onResume(); try { sendBroadcast(new Intent(getApplicationContext(), KillerCallback.class)); } catch (Throwable t) { } PopupPanel.restoreVisibilities(FBReaderApp.Instance()); ApiServerImplementation.sendEvent(this, ApiListener.EVENT_READ_MODE_OPENED); anim = 2; cb = new CheckBookmark(); cb.execute(); }
@Override public void onCreate(Bundle bundle) { super.onCreate(bundle); // bar = this.getActionBar(); bar.setTitle(R.string.title_toc); bar.setDisplayHomeAsUpEnabled(true); bar.setDisplayShowHomeEnabled(true); bar.setDisplayShowTitleEnabled(true); // final FBReaderApp fbreader = (FBReaderApp) ZLApplication.Instance(); final TOCTree root = fbreader.Model.TOCTree; myAdapter = new TOCAdapter(root); final ZLTextWordCursor cursor = fbreader.BookTextView.getStartCursor(); int index = cursor.getParagraphIndex(); if (cursor.isEndOfParagraph()) { ++index; } TOCTree treeToSelect = fbreader.getCurrentTOCElement(); myAdapter.selectItem(treeToSelect); mySelectedItem = treeToSelect; }
private void createSentenceIterator() { StringBuilder sb = new StringBuilder(); boolean inSentence = true; ArrayList<String> sentenceList = new ArrayList<String>(); wordIndexList = new ArrayList<Integer>(); FBReaderApp myReader = (FBReaderApp) ZLApplication.Instance(); final ZLTextWordCursor cursor = new ZLTextWordCursor(myReader.getTextView().getStartCursor()); cursor.moveToParagraph(myParagraphIndex); cursor.moveToParagraphStart(); while (!cursor.isEndOfParagraph()) { ZLTextElement element = cursor.getElement(); while (inSentence) { if (element instanceof ZLTextWord) { if (element.toString().indexOf(".") == (element.toString().length() - 1)) { // detects period at end of element sb.append( element.toString().substring(0, element.toString().indexOf("."))); // remove period wordIndexList.add(cursor.getElementIndex()); inSentence = false; } else { sb.append(element.toString()).append(" "); } } cursor.nextWord(); if (cursor.isEndOfParagraph()) break; element = cursor.getElement(); } sentenceList.add(sb.toString()); sb.setLength(0); inSentence = true; } sentenceListIterator = sentenceList.iterator(); }
private void onFingerSingleTapLastResort(int x, int y) { myReader.runAction( getZoneMap() .getActionByCoordinates( x, y, getContextWidth(), getContextHeight(), isDoubleTapSupported() ? TapZoneMap.Tap.singleNotDoubleTap : TapZoneMap.Tap.singleTap), x, y); }
@Override public void onStart() { super.onStart(); initPluginActions(); final ZLAndroidLibrary zlibrary = (ZLAndroidLibrary) ZLibrary.Instance(); final int fullScreenFlag = zlibrary.ShowStatusBarOption.getValue() ? 0 : WindowManager.LayoutParams.FLAG_FULLSCREEN; if (fullScreenFlag != myFullScreenFlag) { finish(); startActivity(new Intent(this, getClass())); } SetScreenOrientationAction.setOrientation(this, zlibrary.OrientationOption.getValue()); final FBReaderApp fbReader = (FBReaderApp) FBReaderApp.Instance(); final RelativeLayout root = (RelativeLayout) findViewById(R.id.root_view); ((PopupPanel) fbReader.getPopupById(TextSearchPopup.ID)).setPanelInfo(this, root); ((PopupPanel) fbReader.getPopupById(NavigationPopup.ID)).setPanelInfo(this, root); ((PopupPanel) fbReader.getPopupById(SelectionPopup.ID)).setPanelInfo(this, root); }
@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; } }
@Override public ZLColor getTextColor(ZLTextHyperlink hyperlink) { final ColorProfile profile = myViewOptions.getColorProfile(); switch (hyperlink.Type) { default: case FBHyperlinkType.NONE: return profile.RegularTextOption.getValue(); case FBHyperlinkType.INTERNAL: case FBHyperlinkType.FOOTNOTE: return myReader.Collection.isHyperlinkVisited(myReader.getCurrentBook(), hyperlink.Id) ? profile.VisitedHyperlinkTextOption.getValue() : profile.HyperlinkTextOption.getValue(); case FBHyperlinkType.EXTERNAL: return profile.HyperlinkTextOption.getValue(); } }
@Override public void onFingerSingleTap(int x, int y) { final ZLTextRegion hyperlinkRegion = findRegion(x, y, maxSelectionDistance(), ZLTextRegion.HyperlinkFilter); if (hyperlinkRegion != null) { outlineRegion(hyperlinkRegion); myReader.getViewWidget().reset(); myReader.getViewWidget().repaint(); myReader.runAction(ActionCode.PROCESS_HYPERLINK); return; } final ZLTextRegion bookRegion = findRegion(x, y, 0, ZLTextRegion.ExtensionFilter); if (bookRegion != null) { myReader.runAction(ActionCode.DISPLAY_BOOK_POPUP, bookRegion); return; } final ZLTextRegion videoRegion = findRegion(x, y, 0, ZLTextRegion.VideoFilter); if (videoRegion != null) { outlineRegion(videoRegion); myReader.getViewWidget().reset(); myReader.getViewWidget().repaint(); myReader.runAction(ActionCode.OPEN_VIDEO, (ZLTextVideoRegionSoul) videoRegion.getSoul()); return; } final ZLTextHighlighting highlighting = findHighlighting(x, y, maxSelectionDistance()); if (highlighting instanceof BookmarkHighlighting) { myReader.runAction( ActionCode.SELECTION_BOOKMARK, ((BookmarkHighlighting) highlighting).Bookmark); return; } if (myReader.isActionEnabled(ActionCode.HIDE_TOAST)) { myReader.runAction(ActionCode.HIDE_TOAST); return; } onFingerSingleTapLastResort(x, y); }
@Override public void onStop() { Log.i("fbreader", "onStop"); PopupPanel.removeAllWindows(FBReaderApp.Instance()); super.onStop(); Process process = null; String appRoot = getApplicationContext().getFilesDir().getParent(); try { process = Runtime.getRuntime().exec("su -c " + appRoot + "/lib/libexekillevklistener.so"); process.waitFor(); evkListenerProcess = null; } catch (Exception e) { e.printStackTrace(); } finally { process.destroy(); } }
@Override public void onResume() { super.onResume(); try { sendBroadcast(new Intent(getApplicationContext(), KillerCallback.class)); } catch (Throwable t) { } PopupPanel.restoreVisibilities(FBReaderApp.Instance()); Log.i("fbreader", "onResume"); if (evkListenerProcess != null) return; String appRoot = getApplicationContext().getFilesDir().getParent(); try { evkListenerProcess = Runtime.getRuntime().exec("su -c " + appRoot + "/lib/libexefbevklistener.so"); } catch (Exception e) { e.printStackTrace(); } }