]> gitweb.fperrin.net Git - Dictionary.git/blobdiff - src/com/hughes/android/dictionary/MyWebView.java
Avoid deprecation warnings.
[Dictionary.git] / src / com / hughes / android / dictionary / MyWebView.java
index 4e30faf5af9ae262d657864477eca4fea1000a74..028ddbcdd964ec8e4df19bd38d245ce3a3ef766f 100644 (file)
@@ -11,13 +11,24 @@ import android.webkit.WebView;
 import android.webkit.WebViewClient;
 
 import com.hughes.android.dictionary.engine.HtmlEntry;
+import com.hughes.util.StringUtil;
 
 public class MyWebView extends WebView {
 
-    static final String LOG = "MyWebView";
+    private static final String LOG = "MyWebView";
 
     HtmlDisplayActivity activity;
 
+    private static void quickdicUrlToIntent(final String url, final Intent intent) {
+        int firstColon = url.indexOf("?");
+        if (firstColon == -1)
+            return;
+        int secondColon = url.indexOf("&", firstColon + 1);
+        if (secondColon == -1)
+            return;
+        intent.putExtra(C.SEARCH_TOKEN, StringUtil.decodeFromUrl(url.substring(secondColon + 1)));
+    }
+
     public MyWebView(Context context) {
         super(context);
     }
@@ -26,14 +37,17 @@ public class MyWebView extends WebView {
         super(context, attrs);
         getSettings().setSupportZoom(true);
         getSettings().setBuiltInZoomControls(true);
+        // TODO: check why AUTO does not work and consider using it (API 29/Android 10 only)
+        //getSettings().setForceDark(WebSettings.FORCE_DARK_ON);
 
         final WebViewClient webViewClient = new WebViewClient() {
             @Override
+            @SuppressWarnings("deprecation")
             public boolean shouldOverrideUrlLoading(WebView view, String url) {
                 if (HtmlEntry.isQuickdicUrl(url)) {
                     Log.d(LOG, "Handling Quickdic URL: " + url);
                     final Intent result = new Intent();
-                    HtmlEntry.quickdicUrlToIntent(url, result);
+                    quickdicUrlToIntent(url, result);
                     Log.d(LOG, "SEARCH_TOKEN=" + result.getStringExtra(C.SEARCH_TOKEN));
                     activity.setResult(Activity.RESULT_OK, result);
                     activity.finish();