예제 #1
0
 public void setOnThumbnailUpdatedListener(OnThumbnailUpdatedListener listener) {
   mOnThumbnailUpdatedListener = listener;
   for (Tab t : mTabs) {
     WebView web = t.getWebView();
     if (web != null) {
       web.setPictureListener(listener != null ? t : null);
     }
   }
 }
예제 #2
0
  @Test
  public void shouldRecordPictureListener() {
    WebView.PictureListener pictureListener =
        new WebView.PictureListener() {
          @Override
          public void onNewPicture(WebView view, Picture picture) {
            ;
          }
        };

    assertThat(shadowWebView.getPictureListener()).isNull();
    webView.setPictureListener(pictureListener);
    assertThat(shadowWebView.getPictureListener()).isSameAs(pictureListener);
  }
    @SuppressWarnings("deprecation")
    protected void onPostExecute(AsyncTaskResult<NovelContentModel> result) {
      Exception e = result.getError();

      if (e == null) {
        content = result.getResult();

        if (content.getLastUpdate().getTime() != pageModel.getLastUpdate().getTime())
          Toast.makeText(
                  getApplicationContext(),
                  "Content might be updated: "
                      + content.getLastUpdate().toString()
                      + " != "
                      + pageModel.getLastUpdate().toString(),
                  Toast.LENGTH_LONG)
              .show();

        // load the contents here
        final WebView wv = (WebView) findViewById(R.id.webView1);
        wv.getSettings().setAllowFileAccess(true);
        wv.getSettings().setSupportZoom(true);
        wv.getSettings().setBuiltInZoomControls(true);
        wv.getSettings().setLoadWithOverviewMode(true);
        // wv.getSettings().setUseWideViewPort(true);
        wv.getSettings()
            .setLoadsImagesAutomatically(
                PreferenceManager.getDefaultSharedPreferences(getApplicationContext())
                    .getBoolean("show_images", false));
        // wv.setBackgroundColor(0);
        wv.setBackgroundColor(Color.TRANSPARENT);

        // custom link handler
        BakaTsukiWebViewClient client = new BakaTsukiWebViewClient(activity);
        wv.setWebViewClient(client);

        int styleId = -1;
        if (getColorPreferences()) {
          styleId = R.raw.style_dark;
          Log.d("CSS", "CSS = dark");
        } else {
          styleId = R.raw.style;
          Log.d("CSS", "CSS = normal");
        }
        LNReaderApplication app = (LNReaderApplication) getApplication();
        String html =
            "<html><head><style type=\"text/css\">"
                + app.ReadCss(styleId)
                + "</style></head><body>"
                + content.getContent()
                + "</body></html>";
        wv.loadDataWithBaseURL(Constants.BASE_URL, html, "text/html", "utf-8", "");

        wv.setInitialScale((int) (content.getLastZoom() * 100));

        wv.setPictureListener(
            new PictureListener() {
              boolean needScroll = true;

              @Deprecated
              public void onNewPicture(WebView arg0, Picture arg1) {
                Log.d(
                    TAG,
                    "Content Height: " + wv.getContentHeight() + " : " + content.getLastYScroll());
                if (needScroll
                    && wv.getContentHeight() * content.getLastZoom() > content.getLastYScroll()) {
                  wv.scrollTo(0, content.getLastYScroll());
                  needScroll = false;
                }
              }
            });
        try {
          novelDetails = dao.getNovelDetails(pageModel.getParentPageModel(), null);

          volume =
              pageModel
                  .getParent()
                  .replace(
                      pageModel.getParentPageModel().getPage() + Constants.NOVEL_BOOK_DIVIDER, "");

          setTitle(pageModel.getTitle() + " (" + volume + ")");
        } catch (Exception ex) {
          Log.e(TAG, "Error when setting title: " + ex.getMessage(), ex);
        }
        Log.d(
            TAG,
            "Load Content: "
                + content.getLastXScroll()
                + " "
                + content.getLastYScroll()
                + " "
                + content.getLastZoom());

        buildTOCMenu();
      } else {
        Log.e(TAG, "Error when loading novel content: " + e.getMessage(), e);
        Toast.makeText(
                getApplicationContext(),
                e.getClass().toString() + ": " + e.getMessage(),
                Toast.LENGTH_SHORT)
            .show();
      }
      ToggleProgressBar(false);
      refresh = false;
    }