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

    return spine.getPosition() >= spine.size() - 1 && strategy.isAtEnd();
  }
Beispiel #3
0
  private void setImageSpan(SpannableStringBuilder builder, Drawable drawable, int start, int end) {
    builder.setSpan(new ImageSpan(drawable), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    if (spine.isCover()) {
      builder.setSpan(new CenterSpan(), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
  }
Beispiel #4
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();
  }
  @Override
  public void pageUp() {

    this.storedPosition = -1;

    if (isAtStart()) {
      PageTurnerSpine spine = bookView.getSpine();

      if (spine == null || !spine.navigateBack()) {
        return;
      }

      this.clearText();
      this.storedPosition = Integer.MAX_VALUE;
      this.bookView.loadText();
    } else {
      this.pageNum = Math.max(pageNum - 1, 0);
      updatePosition();
    }
  }
  @Override
  public void pageDown() {

    this.storedPosition = -1;

    if (isAtEnd()) {
      PageTurnerSpine spine = bookView.getSpine();

      if (spine == null || !spine.navigateForward()) {
        return;
      }

      this.clearText();
      this.pageNum = 0;
      bookView.loadText();

    } else {
      this.pageNum = Math.min(pageNum + 1, this.pageOffsets.size() - 1);
      updatePosition();
    }
  }
Beispiel #7
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);
  }
Beispiel #8
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);
        }
      }
    }
  }
Beispiel #9
0
  private int[] calculateSize(int originalWidth, int originalHeight) {
    int[] result = new int[] {originalWidth, originalHeight};

    int screenHeight = getHeight() - (verticalMargin * 2);
    int screenWidth = getWidth() - (horizontalMargin * 2);

    // We scale to screen width for the cover or if the image is too
    // wide.
    if (originalWidth > screenWidth || originalHeight > screenHeight || spine.isCover()) {

      float ratio = (float) originalWidth / (float) originalHeight;

      int targetHeight = screenHeight - 1;
      int targetWidth = (int) (targetHeight * ratio);

      if (targetWidth > screenWidth - 1) {
        targetWidth = screenWidth - 1;
        targetHeight = (int) (targetWidth * (1 / ratio));
      }

      LOG.debug(
          "Rescaling from "
              + originalWidth
              + "x"
              + originalHeight
              + " to "
              + targetWidth
              + "x"
              + targetHeight);

      if (targetWidth > 0 || targetHeight > 0) {
        result[0] = targetWidth;
        result[1] = targetHeight;
      }
    }

    return result;
  }
Beispiel #10
0
  private void flatten(List<TOCReference> refs, List<TocEntry> entries, int level) {

    if (refs == null || refs.isEmpty()) {
      return;
    }

    for (TOCReference ref : refs) {

      String title = "";

      for (int i = 0; i < level; i++) {
        title += "-";
      }

      title += ref.getTitle();

      if (ref.getResource() != null) {
        entries.add(new TocEntry(title, spine.resolveTocHref(ref.getCompleteHref())));
      }

      flatten(ref.getChildren(), entries, level + 1);
    }
  }