X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=src%2Fcom%2Fhughes%2Fandroid%2Fdictionary%2FMyWebView.java;h=d57ad0bc80cd621a82addb20d739a706317fb7e8;hb=934313102f9cae5e845ceae738685848a1d272cc;hp=ebec47cb30bf7278398056c7b79c5f37bffd594e;hpb=3137880a2137e96b7cee8a02e1e2a055e37f04db;p=Dictionary.git diff --git a/src/com/hughes/android/dictionary/MyWebView.java b/src/com/hughes/android/dictionary/MyWebView.java index ebec47c..d57ad0b 100644 --- a/src/com/hughes/android/dictionary/MyWebView.java +++ b/src/com/hughes/android/dictionary/MyWebView.java @@ -1,3 +1,4 @@ + package com.hughes.android.dictionary; import android.app.Activity; @@ -10,29 +11,42 @@ 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 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();