]> gitweb.fperrin.net Git - Dictionary.git/commitdiff
Restore Android 10 API compatibility.
authorReimar Döffinger <Reimar.Doeffinger@gmx.de>
Sat, 18 Apr 2020 11:33:03 +0000 (13:33 +0200)
committerReimar Döffinger <Reimar.Doeffinger@gmx.de>
Sat, 18 Apr 2020 11:33:03 +0000 (13:33 +0200)
Util
src/com/hughes/android/dictionary/HtmlDisplayActivity.java
src/com/hughes/android/dictionary/engine/HtmlEntry.java

diff --git a/Util b/Util
index dccff891ce76045d8de2b1000798c1eb452359f2..695e457b4c2f8f8d18b7f39e07999df1f4c44320 160000 (submodule)
--- a/Util
+++ b/Util
@@ -1 +1 @@
-Subproject commit dccff891ce76045d8de2b1000798c1eb452359f2
+Subproject commit 695e457b4c2f8f8d18b7f39e07999df1f4c44320
index 5e9815902aef187cedd70d4fc288da95686c2974..e2e3d606b05be941d5fd722243e7f87e1a4118e8 100644 (file)
@@ -31,7 +31,7 @@ import com.hughes.util.StringUtil;
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
+import java.io.UnsupportedEncodingException;
 
 public final class HtmlDisplayActivity extends AppCompatActivity {
 
@@ -101,8 +101,13 @@ public final class HtmlDisplayActivity extends AppCompatActivity {
             fontSizeSp = 14;
         }
         webView.getSettings().setDefaultFontSize(fontSizeSp);
-        // No way to get pure UTF-8 data into WebView
-        html = Base64.encodeToString(html.getBytes(StandardCharsets.UTF_8), Base64.DEFAULT);
+        try {
+            // No way to get pure UTF-8 data into WebView
+            // Cannot use StandardCharsets due to older Android.
+            html = Base64.encodeToString(html.getBytes("UTF-8"), Base64.DEFAULT);
+        } catch (UnsupportedEncodingException e) {
+            throw new RuntimeException("Missing UTF-8 support?!", e);
+        }
         // Use loadURL to allow specifying a charset
         webView.loadUrl("data:text/html;charset=utf-8;base64," + html);
         webView.activity = this;
index fc15c788b41ef31f23cb9ac631cb8dbc9ad1cc26..7aa43d5340d41d2f8153b8b479957e59a04ffe04 100644 (file)
@@ -267,7 +267,8 @@ public class HtmlEntry extends AbstractEntry implements Comparable<HtmlEntry> {
             buf.readFully(zipBytes);
             try {
                 final byte[] bytes = StringUtil.unzipFully(zipBytes, numBytes);
-                html = new String(bytes, StandardCharsets.UTF_8);
+                // Cannot use StandardCharsets due to older Android.
+                html = new String(bytes, "UTF-8");
             } catch (IOException e) {
                 throw new RuntimeException("Dictionary HTML data corrupted", e);
             }