示例#1
0
  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());
        }
      }
    }
  }
示例#2
0
  public boolean isAtEnd() {
    if (spine == null) {
      return false;
    }

    return spine.getPosition() >= spine.size() - 1 && strategy.isAtEnd();
  }
示例#3
0
  /**
   * 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();
  }
示例#4
0
  @Override
  public boolean onTouchEvent(MotionEvent ev) {

    if (strategy.isScrolling()) {
      return super.onTouchEvent(ev);
    } else {
      return childView.onTouchEvent(ev);
    }
  }
示例#5
0
  /**
   * 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();
  }
示例#6
0
 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();
     }
   }
 }
示例#7
0
  public void setLineSpacing(int lineSpacing) {
    if (lineSpacing != this.lineSpacing) {
      this.lineSpacing = lineSpacing;
      this.childView.setLineSpacing(lineSpacing, 1);

      if (strategy != null) {
        strategy.updatePosition();
      }
    }
  }
示例#8
0
  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();
  }
示例#9
0
  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);
        }
      }
    }
  }
示例#10
0
  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();
    }
  }
示例#11
0
  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);
  }
示例#12
0
 public int getPosition() {
   return strategy.getPosition();
 }
示例#13
0
 @Override
 public void fling(int velocityY) {
   strategy.clearStoredPosition();
   super.fling(velocityY);
 }
示例#14
0
 public void pageUp() {
   strategy.pageUp();
   progressUpdate();
 }
示例#15
0
 /** Loads the text and saves the restored position. */
 public void restore() {
   strategy.clearText();
   loadText();
 }
示例#16
0
 public void pageDown() {
   strategy.pageDown();
 }
示例#17
0
 public void pageUp() {
   strategy.pageUp();
 }