From c7405e7b18d2fe49a118c676a67400b3b4e66b26 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 17 Oct 2012 13:16:29 +0400 Subject: further webview stuff --- src/org/fox/ttcomics/ComicFragment.java | 71 +++++++++------------------------ 1 file changed, 18 insertions(+), 53 deletions(-) (limited to 'src') diff --git a/src/org/fox/ttcomics/ComicFragment.java b/src/org/fox/ttcomics/ComicFragment.java index 46223e1..aed247b 100644 --- a/src/org/fox/ttcomics/ComicFragment.java +++ b/src/org/fox/ttcomics/ComicFragment.java @@ -22,6 +22,7 @@ import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.webkit.WebSettings; +import android.webkit.WebSettings.ZoomDensity; import android.webkit.WebView; import android.widget.ImageView; import android.widget.TextView; @@ -32,7 +33,6 @@ public class ComicFragment extends Fragment { private SharedPreferences m_prefs; private int m_page; private CommonActivity m_activity; - private File m_imageFile; public ComicFragment() { super(); @@ -43,33 +43,6 @@ public class ComicFragment extends Fragment { m_page = page; } - /* public Bitmap loadImage(ComicArchive archive, int page) { - CommonActivity activity = (CommonActivity) getActivity(); - - try { - final BitmapFactory.Options options = new BitmapFactory.Options(); - options.inJustDecodeBounds = true; - BitmapFactory.decodeStream(archive.getItem(page), null, options); - - options.inSampleSize = CommonActivity.calculateInSampleSize(options, 512, 512); - options.inJustDecodeBounds = false; - - return BitmapFactory.decodeStream(archive.getItem(page), null, options); - } catch (OutOfMemoryError e) { - if (activity != null) { - activity.toast(R.string.error_out_of_memory); - } - e.printStackTrace(); - } catch (IOException e) { - if (activity != null) { - activity.toast(R.string.error_loading_image); - } - e.printStackTrace(); - } - - return null; - } */ - @SuppressLint("NewApi") @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -91,9 +64,10 @@ public class ComicFragment extends Fragment { WebSettings ws = web.getSettings(); ws.setSupportZoom(true); - ws.setBuiltInZoomControls(true); - ws.setCacheMode(WebSettings.LOAD_NO_CACHE); - //ws.setUseWideViewPort(true); + ws.setBuiltInZoomControls(false); // http://code.google.com/p/android/issues/detail?id=36713 + //ws.setCacheMode(WebSettings.LOAD_NO_CACHE); + //ws.setDefaultZoom(ZoomDensity.FAR); + ws.setUseWideViewPort(true); ws.setLoadWithOverviewMode(true); // prevent flicker in ics @@ -101,24 +75,22 @@ public class ComicFragment extends Fragment { web.setLayerType(View.LAYER_TYPE_SOFTWARE, null); } - AsyncTask loadTask = new AsyncTask() { + AsyncTask loadTask = new AsyncTask() { @Override - protected File doInBackground(InputStream... params) { + protected ByteArrayOutputStream doInBackground(InputStream... params) { try { - File imageFile = File.createTempFile("tcrview", ".jpg", getActivity().getExternalCacheDir()); - - InputStream in = params[0]; - FileOutputStream out = new FileOutputStream(imageFile); + InputStream in = params[0]; + ByteArrayOutputStream out = new ByteArrayOutputStream(); int c; while ((c = in.read()) != -1) { out.write(c); } - out.close(); + out.flush(); in.close(); - return imageFile; + return out; } catch (IOException e) { e.printStackTrace(); @@ -130,27 +102,24 @@ public class ComicFragment extends Fragment { } @Override - protected void onPostExecute(File result) { + protected void onPostExecute(ByteArrayOutputStream result) { if (getActivity() != null && isAdded()) { if (result != null) { - String url = "file://" + result.getAbsolutePath(); + String url = "data:image/jpeg;base64," + Base64.encodeToString(result.toByteArray(), Base64.DEFAULT | Base64.NO_WRAP); String content = "" + - "" + + "" + "" + "" + "" + - "" + - "" + - "
"; - - Log.d(TAG, content); + "" + + "
" + + ""; web.loadDataWithBaseURL(null, content, "text/html", "utf-8", null); - - m_imageFile = result; } else { ((CommonActivity) getActivity()).toast(R.string.error_loading_image); } @@ -218,10 +187,6 @@ public class ComicFragment extends Fragment { @Override public void onPause() { super.onPause(); - - if (m_imageFile != null) { - m_imageFile.delete(); - } } @Override -- cgit v1.2.3