From 49b4eedf24212cac7ae0b94b855b219e4f1ae86f Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Tue, 5 Feb 2013 15:44:05 +0000 Subject: Android: Avoid SEGV on reflow on HTC Desire HD Move the one time setup of the HTMLOUT javascript interface etc into the constructor. This seems to avoid the occasional SEGV caused while flipping pages on the HTC Desire in reflow mode. --- .../src/com/artifex/mupdfdemo/MuPDFReflowView.java | 27 ++++++++++++++-------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'android') diff --git a/android/src/com/artifex/mupdfdemo/MuPDFReflowView.java b/android/src/com/artifex/mupdfdemo/MuPDFReflowView.java index dbca5af1..d689e9b2 100644 --- a/android/src/com/artifex/mupdfdemo/MuPDFReflowView.java +++ b/android/src/com/artifex/mupdfdemo/MuPDFReflowView.java @@ -24,16 +24,6 @@ public class MuPDFReflowView extends WebView implements MuPDFView { mCore = core; mParentSize = parentSize; mContentHeight = parentSize.y; - } - - private void requestHeight() { - // Get the webview to report the content height via the interface setup - // above. Workaround for getContentHeight not working - loadUrl("javascript:elem=document.getElementById('content');window.HTMLOUT.reportContentHeight("+mParentSize.x+"*elem.offsetHeight/elem.offsetWidth)"); - } - - public void setPage(int page, PointF size) { - mPage = page; getSettings().setJavaScriptEnabled(true); addJavascriptInterface(new Object(){ public void reportContentHeight(String value) { @@ -46,6 +36,19 @@ public class MuPDFReflowView extends WebView implements MuPDFView { requestHeight(); } }); + } + + private void requestHeight() { + // Get the webview to report the content height via the interface setup + // above. Workaround for getContentHeight not working + loadUrl("javascript:elem=document.getElementById('content');window.HTMLOUT.reportContentHeight("+mParentSize.x+"*elem.offsetHeight/elem.offsetWidth)"); + } + + public void setPage(int page, PointF size) { + mPage = page; + if (mLoadHTML != null) { + mLoadHTML.cancel(true); + } mLoadHTML = new AsyncTask() { @Override protected byte[] doInBackground(Void... params) { @@ -112,6 +115,10 @@ public class MuPDFReflowView extends WebView implements MuPDFView { } public void releaseResources() { + if (mLoadHTML != null) { + mLoadHTML.cancel(true); + mLoadHTML = null; + } } @Override -- cgit v1.2.3