changeset 2505:a149dabf6a1f

Android: HTML touchups, implement DW_SIGNAL_HTML_CHANGED: STARTED and COMPLETE. Make sure Javascript is enabled and that links open in the same WebView.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 06 May 2021 22:02:49 +0000
parents 25c56d77d016
children fa976a5bc7bd
files android/DWindows.kt android/dw.cpp
diffstat 2 files changed, 36 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/android/DWindows.kt	Thu May 06 11:22:41 2021 +0000
+++ b/android/DWindows.kt	Thu May 06 22:02:49 2021 +0000
@@ -3,8 +3,10 @@
 import android.content.ClipData
 import android.content.ClipboardManager
 import android.content.DialogInterface
+import android.content.Intent
 import android.content.pm.ActivityInfo
 import android.content.res.Configuration
+import android.graphics.Bitmap
 import android.graphics.drawable.GradientDrawable
 import android.media.AudioManager
 import android.media.ToneGenerator
@@ -20,6 +22,7 @@
 import android.view.View
 import android.view.ViewGroup
 import android.webkit.WebView
+import android.webkit.WebViewClient
 import android.widget.*
 import android.widget.SeekBar.OnSeekBarChangeListener
 import androidx.appcompat.app.AlertDialog
@@ -31,7 +34,6 @@
 import com.google.android.material.tabs.TabLayout.OnTabSelectedListener
 import com.google.android.material.tabs.TabLayoutMediator
 import java.util.*
-import java.util.concurrent.locks.Lock
 import java.util.concurrent.locks.ReentrantLock
 
 
@@ -54,6 +56,26 @@
     class DWEventViewHolder(var view: View) : RecyclerView.ViewHolder(view)
 }
 
+private class DWWebViewClient : WebViewClient() {
+    //Implement shouldOverrideUrlLoading//
+    override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
+        // We always want to load in our own WebView,
+        // to match the behavior on the other platforms
+        return false
+    }
+    override fun onPageStarted(view: WebView, url: String, favicon: Bitmap?) {
+        // Handle the DW_HTML_CHANGE_STARTED event
+        eventHandlerHTMLChanged(view, 19, url, 1)
+    }
+
+    override fun onPageFinished(view: WebView, url: String) {
+        // Handle the DW_HTML_CHANGE_COMPLETE event
+        eventHandlerHTMLChanged(view, 19, url, 4)
+    }
+
+    external fun eventHandlerHTMLChanged(obj1: View, message: Int, URI: String, status: Int)
+}
+
 class DWindows : AppCompatActivity() {
     var firstWindow: Boolean = true
     var windowLayout: LinearLayout? = null
@@ -812,6 +834,9 @@
             html = WebView(this)
             html!!.tag = dataArrayMap
             html!!.id = cid
+            // Configure a few settings to make it behave as we expect
+            html!!.webViewClient = DWWebViewClient()
+            html!!.settings.javaScriptEnabled = true
         }
         return html
     }
--- a/android/dw.cpp	Thu May 06 11:22:41 2021 +0000
+++ b/android/dw.cpp	Thu May 06 22:02:49 2021 +0000
@@ -377,7 +377,7 @@
     _dw_event_handler(obj1, params, message);
 }
 
-/* Handler for HTML events */
+/* Handlers for HTML events */
 JNIEXPORT void JNICALL
 Java_org_dbsoft_dwindows_DWindows_eventHandlerHTMLResult(JNIEnv* env, jobject obj, jobject obj1,
                                                jint message, jstring htmlResult, jlong data) {
@@ -388,6 +388,15 @@
 }
 
 JNIEXPORT void JNICALL
+Java_org_dbsoft_dwindows_DWWebViewClient_eventHandlerHTMLChanged(JNIEnv* env, jobject obj, jobject obj1,
+                                                         jint message, jstring URI, jint status) {
+    const char *uri = env->GetStringUTFChars(URI, NULL);
+    void *params[8] = { NULL, DW_POINTER(uri), NULL, DW_INT_TO_POINTER(status), 0, 0, 0, 0 };
+
+    _dw_event_handler(obj1, params, message);
+}
+
+JNIEXPORT void JNICALL
 Java_org_dbsoft_dwindows_DWindows_eventHandlerInt(JNIEnv* env, jobject obj, jobject obj1, jint message,
                                                jint inta, jint intb, jint intc, jint intd) {
     void *params[8] = { NULL, NULL, NULL,