/** * Setup the chapter from DB, Internal page only Including JS for Bookmark highlighting, last read * position, and CSS * * @param loadedContent */ @SuppressLint("NewApi") public void setContent(NovelContentModel loadedContent) { this.content = loadedContent; try { PageModel pageModel = content.getPageModel(); if (content.getLastUpdate().getTime() < pageModel.getLastUpdate().getTime()) Toast.makeText( this, getResources() .getString( R.string.content_may_updated, content.getLastUpdate().toString(), pageModel.getLastUpdate().toString()), Toast.LENGTH_LONG) .show(); // load the contents here final NonLeakingWebView wv = (NonLeakingWebView) findViewById(R.id.webViewContent); setWebViewSettings(); int lastPos = content.getLastYScroll(); int pIndex = getIntent().getIntExtra(Constants.EXTRA_P_INDEX, -1); if (pIndex > 0) lastPos = pIndex; if (content.getLastZoom() > 0) { wv.setInitialScale((int) (content.getLastZoom() * 100)); } else { wv.setInitialScale(100); } StringBuilder html = new StringBuilder(); html.append("<html><head>"); html.append(DisplayNovelContentHtmlHelper.getCSSSheet()); html.append(DisplayNovelContentHtmlHelper.getViewPortMeta()); html.append( DisplayNovelContentHtmlHelper.prepareJavaScript( lastPos, content.getBookmarks(), getBookmarkPreferences())); html.append("</head><body onclick='toogleHighlight(this, event);' onload='setup();'>"); html.append(content.getContent()); html.append("</body></html>"); wv.loadDataWithBaseURL( UIHelper.getBaseUrl(this), html.toString(), "text/html", "utf-8", NonLeakingWebView.PREFIX_PAGEMODEL + content.getPage()); setChapterTitle(pageModel); Log.d( TAG, "Load Content: " + content.getLastXScroll() + " " + content.getLastYScroll() + " " + content.getLastZoom()); buildTOCMenu(pageModel); buildBookmarkMenu(); invalidateOptionsMenu(); Log.d(TAG, "Loaded: " + content.getPage()); Intent currIntent = this.getIntent(); currIntent.putExtra(Constants.EXTRA_PAGE, content.getPage()); currIntent.putExtra(Constants.EXTRA_PAGE_IS_EXTERNAL, false); } catch (Exception e) { Log.e(TAG, "Cannot load content.", e); } }