Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
IBMS
/
nativeview
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a5fee3d8
authored
Feb 22, 2022
by
huangzhicong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
webview界面调整
1、增加js响应函数link 2、调整storage接口的参数接收
parent
d8200ebf
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
18 deletions
+20
-18
app/src/main/java/com/maxrocky/nativeview/fragment/MainFragment.kt
+19
-17
app/src/main/java/com/maxrocky/nativeview/model/Options.kt
+1
-1
No files found.
app/src/main/java/com/maxrocky/nativeview/fragment/MainFragment.kt
View file @
a5fee3d8
...
...
@@ -11,12 +11,15 @@ import android.webkit.*
import
androidx.fragment.app.Fragment
import
androidx.fragment.app.clearFragmentResultListener
import
androidx.fragment.app.setFragmentResultListener
import
androidx.lifecycle.lifecycleScope
import
com.google.gson.Gson
import
com.maxrocky.nativeview.R
import
com.maxrocky.nativeview.WebViewProxy
import
com.maxrocky.nativeview.contract.*
import
com.maxrocky.nativeview.model.
Pair
Options
import
com.maxrocky.nativeview.model.
Storage
Options
import
com.maxrocky.nativeview.model.SingleOptions
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.launch
class
MainFragment
:
Fragment
()
{
companion
object
{
...
...
@@ -68,12 +71,6 @@ class MainFragment : Fragment() {
result
:
JsResult
?
):
Boolean
=
false
}
wv
.
webViewClient
=
object
:
WebViewClient
()
{
override
fun
onPageFinished
(
view
:
WebView
?,
url
:
String
?)
{
Log
.
d
(
TAG
,
"onPageFinished: $url"
)
view
?.
evaluateJavascript
(
"javascript:onMaxrockyReady()"
,
null
)
}
}
wv
.
settings
.
apply
{
javaScriptEnabled
=
true
}
...
...
@@ -104,6 +101,13 @@ class MainFragment : Fragment() {
private
val
gson
=
Gson
()
@JavascriptInterface
fun
link
()
{
lifecycleScope
.
launch
(
Dispatchers
.
Main
)
{
wv
.
evaluateJavascript
(
"javascript:onMaxrockyReady()"
,
null
)
}
}
@JavascriptInterface
fun
execute
(
sessionId
:
Int
,
method
:
String
,
args
:
String
)
{
when
(
method
)
{
"selectFile"
->
{
...
...
@@ -113,8 +117,12 @@ class MainFragment : Fragment() {
"selectPhoto"
->
selectPhotoContract
.
selectPhoto
(
sessionId
)
"openCamera"
->
cameraContract
.
openCamera
(
sessionId
)
"recordAudio"
->
{
if
(
args
.
isNotEmpty
())
{
val
options
=
gson
.
fromJson
<
SingleOptions
<
Int
>>(
args
,
SingleOptions
::
class
.
java
)
recordAudioContract
.
recordAudio
(
sessionId
,
options
.
data1
)
}
else
{
recordAudioContract
.
recordAudio
(
sessionId
)
}
}
"cropPhoto"
->
{
val
options
=
gson
.
fromJson
<
SingleOptions
<
String
>>(
args
,
SingleOptions
::
class
.
java
)
...
...
@@ -123,17 +131,11 @@ class MainFragment : Fragment() {
"captureVideo"
->
videoContract
.
captureVideo
(
sessionId
)
"qrcode"
->
qrCodeContract
.
qrcode
(
sessionId
)
"storageValue"
->
{
val
options
=
gson
.
fromJson
<
PairOptions
<
String
,
String
>>(
args
,
PairOptions
::
class
.
java
)
storageContract
.
storageValue
(
sessionId
,
options
.
data1
,
options
.
data2
)
}
"acquireValue"
->
{
val
options
=
gson
.
fromJson
<
SingleOptions
<
String
>>(
args
,
SingleOptions
::
class
.
java
)
storageContract
.
acquireValue
(
sessionId
,
options
.
data1
)
}
"clearValue"
->
{
val
options
=
gson
.
fromJson
<
SingleOptions
<
String
>>(
args
,
SingleOptions
::
class
.
java
)
storageContract
.
clearValue
(
sessionId
,
options
.
data1
)
val
options
=
gson
.
fromJson
<
StorageOptions
<
String
,
String
>>(
args
,
StorageOptions
::
class
.
java
)
storageContract
.
storageValue
(
sessionId
,
options
.
key
,
options
.
value
)
}
"acquireValue"
->
storageContract
.
acquireValue
(
sessionId
,
args
)
"clearValue"
->
storageContract
.
clearValue
(
sessionId
,
args
)
}
}
}
...
...
app/src/main/java/com/maxrocky/nativeview/model/Options.kt
View file @
a5fee3d8
...
...
@@ -2,4 +2,4 @@ package com.maxrocky.nativeview.model
data class
SingleOptions
<
T
>(
val
data1
:
T
)
data class
PairOptions
<
T
,
U
>(
val
data1
:
T
,
val
data2
:
U
)
data class
StorageOptions
<
T
,
U
>(
val
key
:
T
,
val
value
:
U
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment