Skip to content

Commit 6ac63d0

Browse files
authored
Merge pull request #5 from Simon-Laux/html_and_main_screen
open plain HTML and main screen update
2 parents 405592b + 8e2bc21 commit 6ac63d0

File tree

7 files changed

+98
-15
lines changed

7 files changed

+98
-15
lines changed

Readme.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
This is an Android app.
33

44
Opens files with the extention `.html.zip` or `.htmlzip` and displays their content in a webview.
5+
The app can also open plain html files.
56

6-
It doesn't allow loading resoources from the web. Assets must be inline because it only loads from the index html file for now.
7+
It doesn't allow loading resources from the web. Assets must be inline because it only loads from the index html file for now.
78

89
## Zipped HTML format
910

app/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ android {
66
applicationId "de.simonlaux.ziphtmlviewer"
77
minSdkVersion 19
88
targetSdkVersion 26
9-
versionCode 1
10-
versionName "1.0"
9+
versionCode 2
10+
versionName "1.1"
1111
}
1212
signingConfigs {
1313

app/src/main/AndroidManifest.xml

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
<data android:pathPattern=".*\\..*\\.htmlzip" />
3131
<data android:pathPattern=".*\\..*\\..*\\.htmlzip" />
3232
<data android:pathPattern=".*\\..*\\..*\\..*\\.htmlzip" />
33+
<data android:mimeType="text/html"/>
34+
<data android:pathPattern=".*\\.html" />
35+
<data android:pathPattern=".*\\..*\\.html" />
36+
<data android:pathPattern=".*\\..*\\..*\\.html" />
37+
<data android:pathPattern=".*\\..*\\..*\\..*\\.html" />
3338
</intent-filter>
3439
</activity>
3540
</application>
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
package de.simonlaux.ziphtmlviewer;
22

33
import android.app.Activity;
4+
import android.view.View;
5+
import android.widget.TextView;
46
import android.os.Bundle;
57

68
public class MainActivity extends Activity {
79

10+
TextView trouble;
11+
812
@Override
913
protected void onCreate(Bundle savedInstanceState) {
1014
super.onCreate(savedInstanceState);
1115
setContentView(R.layout.activity_main);
16+
this.trouble = findViewById(R.id.troubleshooting);
17+
this.trouble.setVisibility(View.INVISIBLE);
18+
}
19+
20+
public void toggleTroubleshooting(View view) {
21+
if (this.trouble.getVisibility() == View.VISIBLE)
22+
this.trouble.setVisibility(View.INVISIBLE);
23+
else
24+
this.trouble.setVisibility(View.VISIBLE);
1225
}
26+
1327
}
1428

app/src/main/java/de/simonlaux/ziphtmlviewer/OpenActivity.java

+21-8
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ public class OpenActivity extends Activity {
2121
@Override
2222
protected void onCreate(Bundle savedInstanceState) {
2323
super.onCreate(savedInstanceState);
24-
try
25-
{
24+
try {
2625
this.getActionBar().hide();
26+
} catch (NullPointerException e) {
2727
}
28-
catch (NullPointerException e){}
2928

3029
setContentView(R.layout.activity_reader);
3130

@@ -43,7 +42,19 @@ private void handleIntent() {
4342
String text = null;
4443
try {
4544
InputStream inputStream = getContentResolver().openInputStream(uri);
46-
text = getStringFromInputStream(inputStream);
45+
if (!uri.getPath().contains("zip")) {
46+
// html mode
47+
ByteArrayOutputStream result = new ByteArrayOutputStream();
48+
byte[] buffer = new byte[1024];
49+
int length;
50+
while ((length = inputStream.read(buffer)) != -1) {
51+
result.write(buffer, 0, length);
52+
}
53+
text = result.toString();
54+
} else {
55+
// zip html mode
56+
text = getStringFromZip(inputStream);
57+
}
4758
} catch (FileNotFoundException e) {
4859
e.printStackTrace();
4960
} catch (IOException e) {
@@ -58,7 +69,7 @@ private void handleIntent() {
5869
WebView myWebView = findViewById(R.id.webview);
5970
WebSettings webSettings = myWebView.getSettings();
6071
webSettings.setJavaScriptEnabled(true);
61-
webSettings.setSupportZoom(true);
72+
webSettings.setSupportZoom(true);
6273
webSettings.setBuiltInZoomControls(true);
6374
myWebView.setWebChromeClient(new WebChromeClient());
6475
myWebView.loadDataWithBaseURL("file://index.html", text, "text/html", null, null);
@@ -68,7 +79,7 @@ private void tellUserThatCouldNotOpenFile() {
6879
Toast.makeText(this, getString(R.string.could_not_open_file), Toast.LENGTH_SHORT).show();
6980
}
7081

71-
public static String getStringFromInputStream(InputStream stream) throws IOException {
82+
public static String getStringFromZip(InputStream stream) throws IOException {
7283
ByteArrayOutputStream fout = new ByteArrayOutputStream();
7384
if (!unpackZip(stream, fout)) {
7485
throw new IOException();
@@ -84,8 +95,10 @@ private static boolean unpackZip(InputStream is, ByteArrayOutputStream fout) {
8495
byte[] buffer = new byte[1024];
8596
int count;
8697
while ((ze = zis.getNextEntry()) != null) {
87-
if(ze.isDirectory()) continue;
88-
if(!Objects.equals(ze.getName(), "index.html")) continue;
98+
if (ze.isDirectory())
99+
continue;
100+
if (!Objects.equals(ze.getName(), "index.html"))
101+
continue;
89102

90103
while ((count = zis.read(buffer)) != -1) {
91104
fout.write(buffer, 0, count);

app/src/main/res/layout/activity_main.xml

+50-4
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,58 @@
77
tools:context=".MainActivity">
88

99
<TextView
10+
android:id="@+id/textView"
11+
android:layout_width="0dp"
12+
android:layout_height="wrap_content"
13+
android:layout_marginStart="8dp"
14+
android:layout_marginEnd="8dp"
15+
android:text="@string/usage_description"
16+
android:textAlignment="center"
17+
app:layout_constraintBottom_toBottomOf="parent"
18+
app:layout_constraintEnd_toEndOf="parent"
19+
app:layout_constraintHorizontal_bias="0.5"
20+
app:layout_constraintStart_toStartOf="parent"
21+
app:layout_constraintTop_toTopOf="parent"
22+
app:layout_constraintVertical_bias="0.1" />
23+
24+
<Button
25+
android:id="@+id/button"
1026
android:layout_width="wrap_content"
1127
android:layout_height="wrap_content"
12-
android:text="Open '.html.zip' files with this app"
28+
android:onClick="toggleTroubleshooting"
29+
android:text="@string/troubleshooting_btn"
30+
app:layout_constraintBottom_toTopOf="@+id/troubleshooting"
31+
app:layout_constraintEnd_toEndOf="parent"
32+
app:layout_constraintHorizontal_bias="0.501"
33+
app:layout_constraintStart_toStartOf="parent"
34+
app:layout_constraintTop_toBottomOf="@+id/textView"
35+
app:layout_constraintVertical_chainStyle="spread" />
36+
37+
38+
<TextView
39+
android:id="@+id/troubleshooting"
40+
android:layout_width="0dp"
41+
android:layout_height="wrap_content"
42+
43+
android:layout_marginStart="8dp"
44+
android:layout_marginEnd="8dp"
45+
android:autoLink="web"
46+
android:text="@string/troubleshooting"
47+
android:textColor="@android:color/holo_red_dark"
48+
app:layout_constraintBottom_toBottomOf="parent"
49+
app:layout_constraintEnd_toEndOf="parent"
50+
app:layout_constraintStart_toStartOf="parent"
51+
app:layout_constraintTop_toBottomOf="@+id/button" />
52+
53+
<TextView
54+
android:id="@+id/textView2"
55+
android:layout_width="wrap_content"
56+
android:layout_height="18dp"
57+
android:layout_marginBottom="15dp"
58+
android:autoLink="web"
59+
android:text="@string/sources"
1360
app:layout_constraintBottom_toBottomOf="parent"
14-
app:layout_constraintLeft_toLeftOf="parent"
15-
app:layout_constraintRight_toRightOf="parent"
16-
app:layout_constraintTop_toTopOf="parent" />
61+
app:layout_constraintEnd_toEndOf="parent"
62+
app:layout_constraintStart_toStartOf="parent" />
1763

1864
</android.support.constraint.ConstraintLayout>

app/src/main/res/values/strings.xml

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
3+
<string name="usage_description">Open compressed HTML Files (\'.html.zip\' or \'.htmlzip\') or normal html files with this app</string>
4+
<string name="troubleshooting_btn">Problems?</string>
5+
<string name="troubleshooting">When you have problems: \n 1. Install and Update the WebView app or Chrome \n 2. If the problem persists please open an issue on https://github.com/Simon-Laux/ZHV/issues</string>
6+
<string name="sources">https://github.com/Simon-Laux/ZHV</string>
37
<string name="could_not_open_file">Could not open file</string>
48
</resources>

0 commit comments

Comments
 (0)