Пример #1
0
  private CharSequence applySpans(CharSequence text, int offset) {
    List<HighLight> highLights = highlightManager.getHighLights(bookView.getFileName());
    int end = offset + text.length() - 1;

    for (final HighLight highLight : highLights) {
      if (highLight.getIndex() == bookView.getIndex()
          && highLight.getStart() >= offset
          && highLight.getStart() < end) {

        LOG.debug(
            "Got highlight from "
                + highLight.getStart()
                + " to "
                + highLight.getEnd()
                + " with offset "
                + offset);

        int highLightEnd = Math.min(end, highLight.getEnd());

        ((Spannable) text)
            .setSpan(
                new HighlightSpan(highLight),
                highLight.getStart() - offset,
                highLightEnd - offset,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
      }
    }

    return text;
  }
Пример #2
0
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {

    View rowView;

    if (convertView == null) {
      LayoutInflater inflater = PlatformUtil.getLayoutInflater(getContext());

      rowView = inflater.inflate(R.layout.progress_row, parent, false);
    } else {
      rowView = convertView;
    }

    TextView deviceView = (TextView) rowView.findViewById(R.id.deviceName);
    TextView percentageView = (TextView) rowView.findViewById(R.id.timeStamp);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
      deviceView.setTextColor(Color.BLACK);
      percentageView.setTextColor(Color.BLACK);
    }

    SearchResult progress = results.get(position);

    deviceView.setText(progress.getDisplay());

    int progressPercentage = bookView.getPercentageFor(progress.getIndex(), progress.getStart());
    int pageNumber = bookView.getPageNumberFor(progress.getIndex(), progress.getStart());
    int totalPages = bookView.getTotalNumberOfPages();

    String text = progressPercentage + "%";

    if (pageNumber != -1) {
      text =
          String.format(getContext().getString(R.string.page_number_of), pageNumber, totalPages)
              + " ("
              + progressPercentage
              + "%)";
    }

    percentageView.setText(text);

    return rowView;
  }
Пример #3
0
  @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();
    }
  }
Пример #4
0
  @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();
    }
  }
Пример #5
0
 public boolean dispatchKeyEvent(KeyEvent event) {
   return bookView.dispatchKeyEvent(event);
 }
Пример #6
0
 protected void onSizeChanged(int w, int h, int oldw, int oldh) {
   super.onSizeChanged(w, h, oldw, oldh);
   bookView.onInnerViewResize();
 }
Пример #7
0
 @Override
 public void onClick(DialogInterface dialog, int which) {
   bookView.navigateBySearchResult(this.results.get(which));
 }
Пример #8
0
 @Override
 public void setBookView(BookView bookView) {
   this.bookView = bookView;
   this.childView = bookView.getInnerView();
 }
Пример #9
0
  public List<Integer> getPageOffsets(CharSequence text, boolean includePageNumbers) {

    if (text == null) {
      return new ArrayList<Integer>();
    }

    List<Integer> pageOffsets = new ArrayList<Integer>();

    TextPaint textPaint = bookView.getInnerView().getPaint();
    int boundedWidth = bookView.getInnerView().getWidth();

    LOG.debug("Page width: " + boundedWidth);

    StaticLayout layout =
        layoutFactory.create(text, textPaint, boundedWidth, bookView.getLineSpacing());
    LOG.debug("Layout height: " + layout.getHeight());

    layout.draw(new Canvas());

    // Subtract the height of the top margin
    int pageHeight = bookView.getHeight() - bookView.getVerticalMargin();

    if (includePageNumbers) {
      String bottomSpace = "0\n";

      StaticLayout numLayout =
          layoutFactory.create(bottomSpace, textPaint, boundedWidth, bookView.getLineSpacing());
      numLayout.draw(new Canvas());

      // Subtract the height needed to show page numbers, or the
      // height of the margin, whichever is more
      pageHeight = pageHeight - Math.max(numLayout.getHeight(), bookView.getVerticalMargin());
    } else {
      // Just subtract the bottom margin
      pageHeight = pageHeight - bookView.getVerticalMargin();
    }

    LOG.debug("Got pageHeight " + pageHeight);

    int totalLines = layout.getLineCount();
    int topLineNextPage = -1;
    int pageStartOffset = 0;

    while (topLineNextPage < totalLines - 1) {

      LOG.debug("Processing line " + topLineNextPage + " / " + totalLines);

      int topLine = layout.getLineForOffset(pageStartOffset);
      topLineNextPage = layout.getLineForVertical(layout.getLineTop(topLine) + pageHeight);

      LOG.debug("topLine " + topLine + " / " + topLineNextPage);
      if (topLineNextPage == topLine) { // If lines are bigger than can fit on a page
        topLineNextPage = topLine + 1;
      }

      int pageEnd = layout.getLineEnd(topLineNextPage - 1);

      LOG.debug("pageStartOffset=" + pageStartOffset + ", pageEnd=" + pageEnd);

      if (pageEnd > pageStartOffset) {
        if (text.subSequence(pageStartOffset, pageEnd).toString().trim().length() > 0) {
          pageOffsets.add(pageStartOffset);
        }
        pageStartOffset = layout.getLineStart(topLineNextPage);
      }
    }

    return pageOffsets;
  }