]> 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 d11cec05f6e6d7385db2481ffbb9d18bc855f940..028ddbcdd964ec8e4df19bd38d245ce3a3ef766f 100644 (file)
@@ -1,3 +1,4 @@
+
 package com.hughes.android.dictionary;
 
 import android.app.Activity;
@@ -10,29 +11,44 @@ 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);
     }
-    
+
     public MyWebView(Context context, AttributeSet attrs) {
         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();
                     return true;