From 5dded1e3847bc091c09e49ee083a7586d30335f8 Mon Sep 17 00:00:00 2001 From: Paul Gardiner Date: Tue, 5 Feb 2013 10:19:19 +0000 Subject: Android: avoid byte[] -> String -> byte[] --- android/src/com/artifex/mupdfdemo/MuPDFCore.java | 13 ++----------- android/src/com/artifex/mupdfdemo/MuPDFReflowView.java | 16 +++++----------- 2 files changed, 7 insertions(+), 22 deletions(-) (limited to 'android') diff --git a/android/src/com/artifex/mupdfdemo/MuPDFCore.java b/android/src/com/artifex/mupdfdemo/MuPDFCore.java index af726760..a432371a 100644 --- a/android/src/com/artifex/mupdfdemo/MuPDFCore.java +++ b/android/src/com/artifex/mupdfdemo/MuPDFCore.java @@ -201,18 +201,9 @@ public class MuPDFCore return searchPage(text); } - public synchronized String html(int page) { + public synchronized byte[] html(int page) { gotoPage(page); - byte chars[] = textAsHtml(); - String res = new String(); - int i; - int len = chars.length; - - for (i = 0; i < len; i++) { - res += (char)(chars[i] & 0xFF); - } - - return res; + return textAsHtml(); } public synchronized TextWord [][] textLines(int page) { diff --git a/android/src/com/artifex/mupdfdemo/MuPDFReflowView.java b/android/src/com/artifex/mupdfdemo/MuPDFReflowView.java index 8824436f..90d0ec8e 100644 --- a/android/src/com/artifex/mupdfdemo/MuPDFReflowView.java +++ b/android/src/com/artifex/mupdfdemo/MuPDFReflowView.java @@ -17,7 +17,7 @@ public class MuPDFReflowView extends WebView implements MuPDFView { private final Point mParentSize; private int mPage; private int mContentHeight; - AsyncTask mLoadHTML; + AsyncTask mLoadHTML; public MuPDFReflowView(Context c, MuPDFCore core, Point parentSize) { super(c); @@ -46,20 +46,14 @@ public class MuPDFReflowView extends WebView implements MuPDFView { requestHeight(); } }); - mLoadHTML = new AsyncTask() { + mLoadHTML = new AsyncTask() { @Override - protected String doInBackground(Void... params) { + protected byte[] doInBackground(Void... params) { return mCore.html(mPage); } @Override - protected void onPostExecute(String result) { - byte [] utf8; - try { - utf8 = result.getBytes("UTF-8"); - } catch (UnsupportedEncodingException e) { - utf8 = result.getBytes(); - } - String b64 = Base64.encodeToString(utf8, Base64.DEFAULT); + protected void onPostExecute(byte[] result) { + String b64 = Base64.encodeToString(result, Base64.DEFAULT); loadData(b64, "text/html; charset=utf-8", "base64"); } }; -- cgit v1.2.3