private void progressUpdate() { if (this.spine != null && this.strategy.getText() != null && this.strategy.getText().length() > 0) { double progressInPart = (double) this.getPosition() / (double) this.strategy.getText().length(); if (strategy.getText().length() > 0 && strategy.isAtEnd()) { progressInPart = 1d; } int progress = spine.getProgressPercentage(progressInPart); if (progress != -1) { int pageNumber = spine.getPageNumberFor(getIndex(), getPosition()); for (BookViewListener listener : this.listeners) { listener.progressUpdate(progress, pageNumber, spine.getTotalNumberOfPages()); } } } }
public boolean isAtEnd() { if (spine == null) { return false; } return spine.getPosition() >= spine.size() - 1 && strategy.isAtEnd(); }
/** * Returns if we're at the start of the book, i.e. displaying the title page. * * @return */ public boolean isAtStart() { if (spine == null) { return true; } return spine.getPosition() == 0 && strategy.isAtStart(); }
@Override public boolean onTouchEvent(MotionEvent ev) { if (strategy.isScrolling()) { return super.onTouchEvent(ev); } else { return childView.onTouchEvent(ev); } }
/** * Scrolls to a previously stored point. * * <p>Call this after setPosition() to actually go there. */ private void restorePosition() { if (this.storedAnchor != null && this.anchors.containsKey(storedAnchor)) { strategy.setPosition(anchors.get(storedAnchor)); this.storedAnchor = null; } this.strategy.updatePosition(); }
public void setVerticalMargin(int verticalMargin) { if (verticalMargin != this.verticalMargin) { this.verticalMargin = verticalMargin; setPadding( this.horizontalMargin, this.verticalMargin, this.horizontalMargin, this.verticalMargin); if (strategy != null) { strategy.updatePosition(); } } }
public void setLineSpacing(int lineSpacing) { if (lineSpacing != this.lineSpacing) { this.lineSpacing = lineSpacing; this.childView.setLineSpacing(lineSpacing, 1); if (strategy != null) { strategy.updatePosition(); } } }
public void goBackInHistory() { this.strategy.clearText(); this.spine.navigateByIndex(this.prevIndex); strategy.setPosition(this.prevPos); this.storedAnchor = null; this.prevIndex = -1; this.prevPos = -1; loadText(); }
private void progressUpdate() { if (this.spine != null && this.strategy.getText() != null && this.strategy.getText().length() > 0) { double progressInPart = (double) this.getPosition() / (double) this.strategy.getText().length(); if (strategy.getText().length() > 0 && strategy.isAtEnd()) { progressInPart = 1d; } int progress = spine.getProgressPercentage(progressInPart); if (progress != -1) { for (BookViewListener listener : this.listeners) { listener.progressUpdate(progress); } } } }
public void goBackInHistory() { if (this.prevIndex == this.getIndex()) { strategy.setPosition(prevPos); this.storedAnchor = null; this.prevIndex = -1; this.prevPos = -1; restorePosition(); } else { this.strategy.clearText(); this.spine.navigateByIndex(this.prevIndex); strategy.setPosition(this.prevPos); this.storedAnchor = null; this.prevIndex = -1; this.prevPos = -1; loadText(); } }
private List<Integer> getOffsetsForResource(int spineIndex) throws IOException { HtmlSpanner mySpanner = new HtmlSpanner(); mySpanner.registerHandler("table", tableHandler); mySpanner.registerHandler("img", new ImageTagHandler(true)); mySpanner.registerHandler("image", new ImageTagHandler(true)); CharSequence text; if (spineIndex == getIndex()) { text = strategy.getText(); } else { Resource res = spine.getResourceForIndex(spineIndex); text = mySpanner.fromHtml(res.getReader()); loader.load(); } return FixedPagesStrategy.getPageOffsets(this, text, true); }
public int getPosition() { return strategy.getPosition(); }
@Override public void fling(int velocityY) { strategy.clearStoredPosition(); super.fling(velocityY); }
public void pageUp() { strategy.pageUp(); progressUpdate(); }
/** Loads the text and saves the restored position. */ public void restore() { strategy.clearText(); loadText(); }
public void pageDown() { strategy.pageDown(); }
public void pageUp() { strategy.pageUp(); }