@@ -21,11 +21,10 @@ public class OpenActivity extends Activity {
21
21
@ Override
22
22
protected void onCreate (Bundle savedInstanceState ) {
23
23
super .onCreate (savedInstanceState );
24
- try
25
- {
24
+ try {
26
25
this .getActionBar ().hide ();
26
+ } catch (NullPointerException e ) {
27
27
}
28
- catch (NullPointerException e ){}
29
28
30
29
setContentView (R .layout .activity_reader );
31
30
@@ -43,7 +42,19 @@ private void handleIntent() {
43
42
String text = null ;
44
43
try {
45
44
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
+ }
47
58
} catch (FileNotFoundException e ) {
48
59
e .printStackTrace ();
49
60
} catch (IOException e ) {
@@ -58,7 +69,7 @@ private void handleIntent() {
58
69
WebView myWebView = findViewById (R .id .webview );
59
70
WebSettings webSettings = myWebView .getSettings ();
60
71
webSettings .setJavaScriptEnabled (true );
61
- webSettings .setSupportZoom (true );
72
+ webSettings .setSupportZoom (true );
62
73
webSettings .setBuiltInZoomControls (true );
63
74
myWebView .setWebChromeClient (new WebChromeClient ());
64
75
myWebView .loadDataWithBaseURL ("file://index.html" , text , "text/html" , null , null );
@@ -68,7 +79,7 @@ private void tellUserThatCouldNotOpenFile() {
68
79
Toast .makeText (this , getString (R .string .could_not_open_file ), Toast .LENGTH_SHORT ).show ();
69
80
}
70
81
71
- public static String getStringFromInputStream (InputStream stream ) throws IOException {
82
+ public static String getStringFromZip (InputStream stream ) throws IOException {
72
83
ByteArrayOutputStream fout = new ByteArrayOutputStream ();
73
84
if (!unpackZip (stream , fout )) {
74
85
throw new IOException ();
@@ -84,8 +95,10 @@ private static boolean unpackZip(InputStream is, ByteArrayOutputStream fout) {
84
95
byte [] buffer = new byte [1024 ];
85
96
int count ;
86
97
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 ;
89
102
90
103
while ((count = zis .read (buffer )) != -1 ) {
91
104
fout .write (buffer , 0 , count );
0 commit comments