From 8e264f38ba4fccf3c4b605ed1d55ed48999a9bd8 Mon Sep 17 00:00:00 2001 From: AndroidUserDelta <47091244+RubenDavidPerezJimenez@users.noreply.github.com> Date: Mon, 14 Sep 2020 14:35:04 -0400 Subject: [PATCH 1/4] Update OpenActivity.java --- .../simonlaux/ziphtmlviewer/OpenActivity.java | 161 ++++++++---------- 1 file changed, 73 insertions(+), 88 deletions(-) diff --git a/app/src/main/java/de/simonlaux/ziphtmlviewer/OpenActivity.java b/app/src/main/java/de/simonlaux/ziphtmlviewer/OpenActivity.java index 216f725..927cb30 100644 --- a/app/src/main/java/de/simonlaux/ziphtmlviewer/OpenActivity.java +++ b/app/src/main/java/de/simonlaux/ziphtmlviewer/OpenActivity.java @@ -2,11 +2,8 @@ import android.annotation.SuppressLint; import android.app.Activity; -import android.content.Intent; import android.net.Uri; import android.os.Bundle; -import android.util.Log; -import android.view.ContextMenu; import android.view.Menu; import android.view.View; import android.view.inputmethod.EditorInfo; @@ -21,31 +18,34 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import java.util.Objects; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; +import de.simonlaux.ziphtmlviewer.R; + public class OpenActivity extends Activity implements View.OnClickListener { + private static final String MD_TEXT = "MD_TEXT"; private static final String FIRST_TIME_INIT = "FirstTimeInit"; private static final String IS_SEARCHING = "Searching"; - private static final String ONE_TIME = "OneTime"; - private static final String TITLEWEB = "TitleWeb"; + private static final String TITLE_WEB = "TitleWeb"; private boolean firstTimeInit = true; - private boolean isSearching = true; - private boolean onetime = false; + private boolean isSearching = false; + private JsObject jsObject; private String titleWEB ="ZHV"; - + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - if (onetime) { - Toast.makeText(this, R.string.image_click_explain, Toast.LENGTH_SHORT).show(); - } if (savedInstanceState != null) { firstTimeInit = savedInstanceState.getBoolean(FIRST_TIME_INIT, true); isSearching = savedInstanceState.getBoolean(IS_SEARCHING, false); - onetime = savedInstanceState.getBoolean(ONE_TIME, false); - titleWEB =savedInstanceState.getString(TITLEWEB, titleWEB); + titleWEB =savedInstanceState.getString(TITLE_WEB, titleWEB); + String text=savedInstanceState.getString(MD_TEXT,""); + if(text==""){ + jsObject=new JsObject("",false); + }else{ + jsObject=new JsObject(text,true); + } } /*Don't hide the bar for use it try { @@ -63,7 +63,7 @@ protected void onCreate(Bundle savedInstanceState) { this.setTitle(titleWEB); } } - + @SuppressLint("SetJavaScriptEnabled") public void configureWebView(WebView web) { WebSettings webSettings = web.getSettings(); @@ -71,14 +71,24 @@ public void configureWebView(WebView web) { webSettings.setSupportZoom(true); webSettings.setBuiltInZoomControls(true); webSettings.setDomStorageEnabled(true); + web.addJavascriptInterface(jsObject, "zhv"); + web.setWebChromeClient(new WebChromeClient() { + + @Override + public void onReceivedTitle(WebView view, String title) { + super.onReceivedTitle(view, title); + OpenActivity.this.titleWEB = title; + OpenActivity.this.setTitle(title); + } + }); } - + @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.search_menu, menu); final SearchView searchView = (SearchView) menu.findItem(R.id.search_menu_item).getActionView(); searchView.setIconifiedByDefault(true); - searchView.setIconified(true); + //searchView.setIconified(true); searchView.setImeOptions(EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS | EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NAVIGATE_NEXT); searchView.setOnSearchClickListener(this); searchView.setSubmitButtonEnabled(true); @@ -93,10 +103,10 @@ public boolean onClose() { @Override public boolean onQueryTextSubmit(String query) { WebView myWebView = findViewById(R.id.webview); - myWebView.findAllAsync(query); + myWebView.findNext(true); return false; } - + @Override public boolean onQueryTextChange(String newText) { WebView myWebView = findViewById(R.id.webview); @@ -105,9 +115,9 @@ public boolean onQueryTextChange(String newText) { } }); return super.onCreateOptionsMenu(menu); - + } - + @Override public void onBackPressed() { if (isSearching) { @@ -119,9 +129,9 @@ public void onBackPressed() { } else { super.onBackPressed(); } - + } - + private void handleIntent() { Uri uri = getIntent().getData(); if (uri == null) { @@ -155,83 +165,33 @@ private void handleIntent() { } catch (IOException e) { e.printStackTrace(); } - + if (text == null) { tellUserThatCouldNotOpenFile(); return; } - + WebView myWebView = findViewById(R.id.webview); - + jsObject = new JsObject(text, isMarkdown); configureWebView(myWebView); - - registerForContextMenu(myWebView); - + // myWebView.setWebContentsDebuggingEnabled(true); - - final boolean isMarkdownReader = isMarkdown; - final String contentText = text; - class JsObject { - @JavascriptInterface - public int getVersion() { - return BuildConfig.VERSION_CODE; - } - - @JavascriptInterface - public String toString() { - return "[ZippedHTMLViewer Object]"; - } - - @JavascriptInterface - public String getMarkdown() { - if (isMarkdownReader) { - return contentText; - } else { - return ""; - } - } - } - myWebView.addJavascriptInterface(new JsObject(), "zhv"); - myWebView.setWebChromeClient(new WebChromeClient() { - @Override - public void onReceivedTitle(WebView view, String title) { - super.onReceivedTitle(view, title); - OpenActivity.this.titleWEB = title; - OpenActivity.this.setTitle(title); - } - }); + myWebView.loadData("", "text/html", null); - if (isMarkdown) { + if(isMarkdown){ // markdown mode myWebView.loadUrl("file:///android_asset/markdown-reader.html"); } else { // html mode - myWebView.loadDataWithBaseURL("file://index.html", contentText, "text/html", null, null); + myWebView.loadDataWithBaseURL("file://index.html", text, "text/html", null, null); } firstTimeInit = false; } - - //on Long touch Not Seen Images send to bot - @Override - public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { - super.onCreateContextMenu(menu, v, menuInfo); - Log.d("TAG", "onCreateContextMenu: " + v.toString()); - WebView myWebView = findViewById(R.id.webview); - WebView.HitTestResult hitTestResult = myWebView.getHitTestResult(); - if (hitTestResult.getType() == WebView.HitTestResult.IMAGE_TYPE) { - Intent intent = new Intent(Intent.ACTION_SEND); - intent.putExtra(Intent.EXTRA_EMAIL, ""); - intent.putExtra(Intent.EXTRA_HTML_TEXT, "/web " + hitTestResult.getExtra()); - intent.putExtra(Intent.EXTRA_TEXT, "/web " + hitTestResult.getExtra()); - intent.setType("text/html"); - startActivity(Intent.createChooser(intent, getString(R.string.open_delta))); - } - } - + private void tellUserThatCouldNotOpenFile() { Toast.makeText(this, getString(R.string.could_not_open_file), Toast.LENGTH_SHORT).show(); } - + public static String getStringFromZip(InputStream stream) throws IOException { ByteArrayOutputStream fout = new ByteArrayOutputStream(); if (!unpackZip(stream, fout)) { @@ -239,7 +199,7 @@ public static String getStringFromZip(InputStream stream) throws IOException { } return fout.toString(); } - + private static boolean unpackZip(InputStream is, ByteArrayOutputStream fout) { ZipInputStream zis; try { @@ -250,9 +210,10 @@ private static boolean unpackZip(InputStream is, ByteArrayOutputStream fout) { while ((ze = zis.getNextEntry()) != null) { if (ze.isDirectory()) continue; - if (!Objects.equals(ze.getName(), "index.html")) + //Objects esta del api 19 en adelante + if (!ze.getName().contentEquals("index.html")) continue; - + while ((count = zis.read(buffer)) != -1) { fout.write(buffer, 0, count); } @@ -265,19 +226,43 @@ private static boolean unpackZip(InputStream is, ByteArrayOutputStream fout) { } return true; } - + @Override protected void onSaveInstanceState(Bundle outState) { WebView myWebView = findViewById(R.id.webview); myWebView.saveState(outState); outState.putBoolean(IS_SEARCHING, isSearching); outState.putBoolean(FIRST_TIME_INIT, firstTimeInit); - outState.putString(TITLEWEB,titleWEB); + outState.putString(TITLE_WEB,titleWEB); + outState.putString(MD_TEXT,jsObject.getMarkdown()); super.onSaveInstanceState(outState); } - + @Override public void onClick(View v) { isSearching = true; } + + + class JsObject { + String contentText=""; + boolean isMarkdownReader=false; + public JsObject(String contentText,boolean isMarkdownReader){ + this.contentText=contentText; + this.isMarkdownReader=isMarkdownReader; + } + + @JavascriptInterface + public int getVersion() { return 15; } + @JavascriptInterface + public String toString() { return "[ZippedHTMLViewer Object]"; } + @JavascriptInterface + public String getMarkdown() { + if(isMarkdownReader){ + return contentText; + } else { + return ""; + } + } + } } From 26e89c09869aa71ec8183f7787ef182ae3accb5b Mon Sep 17 00:00:00 2001 From: AndroidUserDelta <47091244+RubenDavidPerezJimenez@users.noreply.github.com> Date: Mon, 14 Sep 2020 14:39:43 -0400 Subject: [PATCH 2/4] Update Changelog.md --- Changelog.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Changelog.md b/Changelog.md index 1f45549..bdd0dc7 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,6 +1,11 @@ # Changelog ## Unreleased +## 1.5.1 +Version code **8** +- Fixed some bugs in search +- Fixed rotation on MD file not working +- Removed on long click image to bot ## 1.5.0 Version code **7** From 30f8bbf229d59bb92f6104c95857ed033a00e4e8 Mon Sep 17 00:00:00 2001 From: AndroidUserDelta <47091244+RubenDavidPerezJimenez@users.noreply.github.com> Date: Mon, 14 Sep 2020 14:40:42 -0400 Subject: [PATCH 3/4] Update build.gradle --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index bac4b07..5ecd72f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,8 +7,8 @@ android { // don't go bellow 19, otherwise you may introduce web-view security risks minSdkVersion 19 targetSdkVersion 28 - versionCode 7 - versionName "1.5.0" + versionCode 8 + versionName "1.5.1" } signingConfigs { From 8fc0d1297f47a5500c22f7892821dee73fdb41a5 Mon Sep 17 00:00:00 2001 From: AndroidUserDelta <47091244+RubenDavidPerezJimenez@users.noreply.github.com> Date: Mon, 14 Sep 2020 14:42:14 -0400 Subject: [PATCH 4/4] Update OpenActivity.java --- app/src/main/java/de/simonlaux/ziphtmlviewer/OpenActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/de/simonlaux/ziphtmlviewer/OpenActivity.java b/app/src/main/java/de/simonlaux/ziphtmlviewer/OpenActivity.java index 927cb30..c68ff15 100644 --- a/app/src/main/java/de/simonlaux/ziphtmlviewer/OpenActivity.java +++ b/app/src/main/java/de/simonlaux/ziphtmlviewer/OpenActivity.java @@ -253,7 +253,7 @@ public JsObject(String contentText,boolean isMarkdownReader){ } @JavascriptInterface - public int getVersion() { return 15; } + public int getVersion() { return BuildConfig.VERSION_CODE; } @JavascriptInterface public String toString() { return "[ZippedHTMLViewer Object]"; } @JavascriptInterface