From 812a374ecce45a41a186b5e9aadc1c909273f6c2 Mon Sep 17 00:00:00 2001 From: Simon Laux Date: Fri, 21 Jun 2019 22:22:58 +0200 Subject: [PATCH 1/3] open plain html files closes #3 --- app/src/main/AndroidManifest.xml | 5 ++++ .../simonlaux/ziphtmlviewer/OpenActivity.java | 29 ++++++++++++++----- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 94ffc09..1785848 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -30,6 +30,11 @@ + + + + + diff --git a/app/src/main/java/de/simonlaux/ziphtmlviewer/OpenActivity.java b/app/src/main/java/de/simonlaux/ziphtmlviewer/OpenActivity.java index 737c1a9..c48f746 100644 --- a/app/src/main/java/de/simonlaux/ziphtmlviewer/OpenActivity.java +++ b/app/src/main/java/de/simonlaux/ziphtmlviewer/OpenActivity.java @@ -21,11 +21,10 @@ public class OpenActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - try - { + try { this.getActionBar().hide(); + } catch (NullPointerException e) { } - catch (NullPointerException e){} setContentView(R.layout.activity_reader); @@ -43,7 +42,19 @@ private void handleIntent() { String text = null; try { InputStream inputStream = getContentResolver().openInputStream(uri); - text = getStringFromInputStream(inputStream); + if (!uri.getPath().contains("zip")) { + // html mode + ByteArrayOutputStream result = new ByteArrayOutputStream(); + byte[] buffer = new byte[1024]; + int length; + while ((length = inputStream.read(buffer)) != -1) { + result.write(buffer, 0, length); + } + text = result.toString(); + } else { + // zip html mode + text = getStringFromZip(inputStream); + } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { @@ -58,7 +69,7 @@ private void handleIntent() { WebView myWebView = findViewById(R.id.webview); WebSettings webSettings = myWebView.getSettings(); webSettings.setJavaScriptEnabled(true); - webSettings.setSupportZoom(true); + webSettings.setSupportZoom(true); webSettings.setBuiltInZoomControls(true); myWebView.setWebChromeClient(new WebChromeClient()); myWebView.loadDataWithBaseURL("file://index.html", text, "text/html", null, null); @@ -68,7 +79,7 @@ private void tellUserThatCouldNotOpenFile() { Toast.makeText(this, getString(R.string.could_not_open_file), Toast.LENGTH_SHORT).show(); } - public static String getStringFromInputStream(InputStream stream) throws IOException { + public static String getStringFromZip(InputStream stream) throws IOException { ByteArrayOutputStream fout = new ByteArrayOutputStream(); if (!unpackZip(stream, fout)) { throw new IOException(); @@ -84,8 +95,10 @@ private static boolean unpackZip(InputStream is, ByteArrayOutputStream fout) { byte[] buffer = new byte[1024]; int count; while ((ze = zis.getNextEntry()) != null) { - if(ze.isDirectory()) continue; - if(!Objects.equals(ze.getName(), "index.html")) continue; + if (ze.isDirectory()) + continue; + if (!Objects.equals(ze.getName(), "index.html")) + continue; while ((count = zis.read(buffer)) != -1) { fout.write(buffer, 0, count); From 5ffa639f95b5b5c2d37004d73bedddfdf00f0c35 Mon Sep 17 00:00:00 2001 From: Simon Laux Date: Fri, 21 Jun 2019 22:46:44 +0200 Subject: [PATCH 2/3] add some troubleshooting information closes #1 --- Readme.md | 3 +- .../simonlaux/ziphtmlviewer/MainActivity.java | 14 +++++ app/src/main/res/layout/activity_main.xml | 54 +++++++++++++++++-- app/src/main/res/values/strings.xml | 4 ++ 4 files changed, 70 insertions(+), 5 deletions(-) diff --git a/Readme.md b/Readme.md index 4de1869..229b73e 100644 --- a/Readme.md +++ b/Readme.md @@ -2,8 +2,9 @@ This is an Android app. Opens files with the extention `.html.zip` or `.htmlzip` and displays their content in a webview. +The app can also open plain html files. -It doesn't allow loading resoources from the web. Assets must be inline because it only loads from the index html file for now. +It doesn't allow loading resources from the web. Assets must be inline because it only loads from the index html file for now. ## Zipped HTML format diff --git a/app/src/main/java/de/simonlaux/ziphtmlviewer/MainActivity.java b/app/src/main/java/de/simonlaux/ziphtmlviewer/MainActivity.java index e61df1a..d1b8a01 100644 --- a/app/src/main/java/de/simonlaux/ziphtmlviewer/MainActivity.java +++ b/app/src/main/java/de/simonlaux/ziphtmlviewer/MainActivity.java @@ -1,14 +1,28 @@ package de.simonlaux.ziphtmlviewer; import android.app.Activity; +import android.view.View; +import android.widget.TextView; import android.os.Bundle; public class MainActivity extends Activity { + TextView trouble; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + this.trouble = findViewById(R.id.troubleshooting); + this.trouble.setVisibility(View.INVISIBLE); + } + + public void toggleTroubleshooting(View view) { + if (this.trouble.getVisibility() == View.VISIBLE) + this.trouble.setVisibility(View.INVISIBLE); + else + this.trouble.setVisibility(View.VISIBLE); } + } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 67bd5e1..7fbaac2 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -7,12 +7,58 @@ tools:context=".MainActivity"> + +