1
1
package com.tencent.iot.explorer.link.kitlink.activity
2
2
3
3
import android.annotation.SuppressLint
4
+ import android.app.Activity
4
5
import android.content.Intent
5
6
import android.net.Uri
6
7
import android.os.Build
7
8
import android.text.TextUtils
9
+ import android.util.Log
8
10
import android.view.View
9
11
import android.webkit.*
10
12
import com.alibaba.fastjson.JSON
@@ -22,6 +24,9 @@ import com.tencent.iot.explorer.link.kitlink.popup.EditPopupWindow
22
24
import com.tencent.iot.explorer.link.kitlink.util.HttpRequest
23
25
import com.tencent.iot.explorer.link.core.auth.callback.MyCallback
24
26
import com.tencent.iot.explorer.link.kitlink.util.RequestCode
27
+ import com.tencent.iot.explorer.link.kitlink.webview.BridgeImpl
28
+ import com.tencent.iot.explorer.link.kitlink.webview.JSBridgeKt
29
+ import com.tencent.iot.explorer.link.kitlink.webview.OnEventCallback
25
30
import com.tencent.iot.explorer.link.kitlink.webview.WebCallBack
26
31
import kotlinx.android.synthetic.main.activity_device_details.*
27
32
import kotlinx.android.synthetic.main.activity_device_panel.*
@@ -33,6 +38,7 @@ class DevicePanelActivity: BaseActivity(), View.OnClickListener, MyCallback, App
33
38
private var callback: WebCallBack ? = null
34
39
private var deviceEntity: DeviceEntity ? = null
35
40
private var editPopupWindow: EditPopupWindow ? = null
41
+ private var onEventCallback: OnEventCallback ? = null
36
42
37
43
override fun getContentView (): Int {
38
44
return R .layout.activity_device_panel
@@ -64,6 +70,7 @@ class DevicePanelActivity: BaseActivity(), View.OnClickListener, MyCallback, App
64
70
when (reqCode) {
65
71
RequestCode .token_ticket -> {
66
72
if (response.isSuccess()) {
73
+ JSBridgeKt .register(" help_center_bridge" , BridgeImpl ::class .java)
67
74
val ticketResponse = JSON .parse(response.data.toString()) as JSONObject
68
75
var url = H5_PANEL_BASE_URL +
69
76
" ?deviceId=${deviceEntity?.DeviceId } " +
@@ -153,10 +160,18 @@ class DevicePanelActivity: BaseActivity(), View.OnClickListener, MyCallback, App
153
160
override fun onReceivedTouchIconUrl (view : WebView ? , url : String? , precomposed : Boolean ) { }
154
161
155
162
override fun onJsPrompt (view : WebView , url : String , message : String , defaultValue : String , result : JsPromptResult ): Boolean {
163
+ result.confirm(JSBridgeKt .callNative(view, message))
156
164
return true
157
165
}
158
166
}
159
167
168
+ override fun onActivityResult (requestCode : Int , resultCode : Int , data : Intent ? ) {
169
+ super .onActivityResult(requestCode, resultCode, data)
170
+ if (resultCode == Activity .RESULT_OK && requestCode == JSBridgeKt .OPEN_BULE_TOOTH_REQ_CODE ) {
171
+ onEventCallback!! .onActivityShow()
172
+ }
173
+ }
174
+
160
175
private val webViewClient = object : WebViewClient () {
161
176
override fun shouldOverrideUrlLoading (view : WebView , url : String ): Boolean {
162
177
L .e(" shouldOverrideUrlLoading: " + url)
@@ -199,6 +214,13 @@ class DevicePanelActivity: BaseActivity(), View.OnClickListener, MyCallback, App
199
214
url.contains(" goFirmwareUpgradePage" ) -> {
200
215
callBackToH5(getCallbackId(url))
201
216
}
217
+ url.contains(" openBluetoothAdapter" ) -> {
218
+ JSBridgeKt .callNative(view, url)
219
+ onEventCallback = JSBridgeKt .onEventCallback
220
+ }
221
+ else -> {
222
+ JSBridgeKt .callNative(view, url)
223
+ }
202
224
}
203
225
return true
204
226
}
0 commit comments