diff android/DWindows.kt @ 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 1c2a79313b04
children f54051c3f2a5
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
     }