Esempio n. 1
0
    protected Spanned doInBackground(String... hrefs) {

      publishProgress(BookReadPhase.START);

      if (loader != null) {
        loader.clear();
      }

      if (BookView.this.book == null) {
        try {
          initBook();
        } catch (IOException io) {
          this.error = io.getMessage();
          return null;
        }
      }

      this.name = spine.getCurrentTitle();

      Resource resource;

      if (hrefs.length == 0) {
        resource = spine.getCurrentResource();
      } else {
        resource = book.getResources().getByHref(hrefs[0]);
      }

      if (resource == null) {
        return new SpannedString(
            "Sorry, it looks like you clicked a dead link.\nEven books have 404s these days.");
      }

      publishProgress(BookReadPhase.PARSE_TEXT);

      try {
        Spannable result = spanner.fromHtml(resource.getReader());
        loader.load(); // Load all image resources.

        // Highlight search results (if any)
        for (SearchTextTask.SearchResult searchResult : this.searchResults) {
          if (searchResult.getIndex() == spine.getPosition()) {
            result.setSpan(
                new BackgroundColorSpan(Color.YELLOW),
                searchResult.getStart(),
                searchResult.getEnd(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
          }
        }

        publishProgress(BookReadPhase.DONE);

        return result;
      } catch (IOException io) {
        return new SpannableString("Could not load text: " + io.getMessage());
      }
    }
Esempio n. 2
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);
  }
Esempio n. 3
0
    protected Spanned doInBackground(String... hrefs) {

      if (loader != null) {
        loader.clear();
      }

      if (BookView.this.book == null) {
        try {
          initBook();
        } catch (IOException io) {
          this.error = io.getMessage();
          return null;
        }
      }

      this.name = spine.getCurrentTitle();

      Resource resource;

      if (hrefs.length == 0) {
        resource = spine.getCurrentResource();
      } else {
        resource = book.getResources().getByHref(hrefs[0]);
      }

      if (resource == null) {
        return new SpannedString(
            "Sorry, it looks like you clicked a dead link.\nEven books have 404s these days.");
      }

      try {
        Spanned result = spanner.fromHtml(resource.getReader());
        loader.load(); // Load all image resources.
        return result;
      } catch (IOException io) {
        return new SpannableString("Could not load text: " + io.getMessage());
      }
    }