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
67c73370
authored
Feb 21, 2022
by
huangzhicong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加启动页,允许自定义要访问的url
parent
a2092b33
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
103 additions
and
3 deletions
+103
-3
app/src/main/java/com/maxrocky/nativeview/fragment/MainFragment.kt
+13
-2
app/src/main/java/com/maxrocky/nativeview/fragment/StartFragment.kt
+37
-0
app/src/main/res/layout/fragment_start.xml
+38
-0
app/src/main/res/navigation/nav_graph.xml
+13
-1
app/src/main/res/values/strings.xml
+2
-0
No files found.
app/src/main/java/com/maxrocky/nativeview/fragment/MainFragment.kt
View file @
67c73370
...
@@ -27,6 +27,14 @@ import kotlin.RuntimeException
...
@@ -27,6 +27,14 @@ import kotlin.RuntimeException
class
MainFragment
:
Fragment
()
{
class
MainFragment
:
Fragment
()
{
companion
object
{
companion
object
{
private
const
val
TAG
=
"MainFragment"
private
const
val
TAG
=
"MainFragment"
private
const
val
DEFAULT_URL
=
"file:///android_asset/index.html"
private
const
val
ARG_URL
=
"arg_url"
fun
createStartBundle
():
Bundle
=
Bundle
()
fun
createStartBundle
(
url
:
String
):
Bundle
=
Bundle
().
apply
{
putString
(
ARG_URL
,
url
)
}
}
}
private
lateinit
var
wv
:
WebView
private
lateinit
var
wv
:
WebView
...
@@ -68,8 +76,11 @@ class MainFragment : Fragment() {
...
@@ -68,8 +76,11 @@ class MainFragment : Fragment() {
javaScriptEnabled
=
true
javaScriptEnabled
=
true
}
}
wv
.
addJavascriptInterface
(
WebInterface
(),
"maxrocky"
)
wv
.
addJavascriptInterface
(
WebInterface
(),
"maxrocky"
)
wv
.
loadUrl
(
"file:///android_asset/index.html"
)
var
url
=
arguments
?.
getString
(
ARG_URL
)
// wv.loadUrl("http://114.115.202.253:8080/#/")
if
(
url
.
isNullOrEmpty
())
{
url
=
DEFAULT_URL
}
wv
.
loadUrl
(
url
)
videoContract
=
VideoContract
(
this
,
wv
)
videoContract
=
VideoContract
(
this
,
wv
)
cameraContract
=
CameraContract
(
this
,
wv
)
cameraContract
=
CameraContract
(
this
,
wv
)
...
...
app/src/main/java/com/maxrocky/nativeview/fragment/StartFragment.kt
0 → 100644
View file @
67c73370
package
com.maxrocky.nativeview.fragment
import
android.os.Bundle
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
android.widget.Button
import
android.widget.TextView
import
androidx.fragment.app.Fragment
import
androidx.navigation.fragment.findNavController
import
com.maxrocky.nativeview.R
class
StartFragment
:
Fragment
()
{
private
lateinit
var
urlTextView
:
TextView
private
lateinit
var
button
:
Button
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?
):
View
?
=
inflater
.
inflate
(
R
.
layout
.
fragment_start
,
container
,
false
)
override
fun
onViewCreated
(
view
:
View
,
savedInstanceState
:
Bundle
?)
{
super
.
onViewCreated
(
view
,
savedInstanceState
)
urlTextView
=
view
.
findViewById
(
R
.
id
.
url
)
button
=
view
.
findViewById
(
R
.
id
.
enter
)
button
.
setOnClickListener
{
val
url
=
urlTextView
.
text
.
trim
().
toString
()
findNavController
().
navigate
(
R
.
id
.
action_startFragment_to_mainFragment
,
MainFragment
.
createStartBundle
(
url
)
)
}
}
}
\ No newline at end of file
app/src/main/res/layout/fragment_start.xml
0 → 100644
View file @
67c73370
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
>
<TextView
android:id=
"@+id/url_label"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:text=
"@string/url_label"
android:layout_marginTop=
"20dp"
android:layout_marginStart=
"20dp"
app:layout_constraintTop_toTopOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
/>
<TextView
android:id=
"@+id/url"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"10dp"
android:layout_marginEnd=
"20dp"
app:layout_constraintTop_toTopOf=
"@id/url_label"
app:layout_constraintStart_toEndOf=
"@id/url_label"
app:layout_constraintEnd_toEndOf=
"parent"
/>
<Button
android:id=
"@+id/enter"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:text=
"@string/enter_button"
android:layout_marginTop=
"10dp"
app:layout_constraintStart_toStartOf=
"@id/url_label"
app:layout_constraintTop_toBottomOf=
"@id/url_label"
app:layout_constraintEnd_toEndOf=
"@id/url"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
app/src/main/res/navigation/nav_graph.xml
View file @
67c73370
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
<navigation
xmlns:android=
"http://schemas.android.com/apk/res/android"
<navigation
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
android:id=
"@+id/nav_graph"
android:id=
"@+id/nav_graph"
app:startDestination=
"@id/
main
Fragment"
>
app:startDestination=
"@id/
start
Fragment"
>
<fragment
<fragment
android:id=
"@+id/mainFragment"
android:id=
"@+id/mainFragment"
...
@@ -11,6 +11,9 @@
...
@@ -11,6 +11,9 @@
<action
<action
android:id=
"@+id/action_mainFragment_to_recorderBottomSheet"
android:id=
"@+id/action_mainFragment_to_recorderBottomSheet"
app:destination=
"@id/recorderBottomSheet"
/>
app:destination=
"@id/recorderBottomSheet"
/>
<argument
android:name=
"url"
app:argType=
"string"
/>
</fragment>
</fragment>
<dialog
<dialog
android:id=
"@+id/recorderBottomSheet"
android:id=
"@+id/recorderBottomSheet"
...
@@ -20,4 +23,12 @@
...
@@ -20,4 +23,12 @@
android:name=
"uri"
android:name=
"uri"
app:argType=
"string"
/>
app:argType=
"string"
/>
</dialog>
</dialog>
<fragment
android:id=
"@+id/startFragment"
android:name=
"com.maxrocky.nativeview.fragment.StartFragment"
android:label=
"StartFragment"
>
<action
android:id=
"@+id/action_startFragment_to_mainFragment"
app:destination=
"@id/mainFragment"
/>
</fragment>
</navigation>
</navigation>
\ No newline at end of file
app/src/main/res/values/strings.xml
View file @
67c73370
<resources>
<resources>
<string
name=
"app_name"
>
NativeView
</string>
<string
name=
"app_name"
>
NativeView
</string>
<string
name=
"url_label"
>
网址:
</string>
<string
name=
"enter_button"
>
启动
</string>
<string
name=
"camera_denied"
>
请到系统设置允许访问相机
</string>
<string
name=
"camera_denied"
>
请到系统设置允许访问相机
</string>
<string
name=
"record_audio_denied"
>
请到系统设置允许访问麦克风
</string>
<string
name=
"record_audio_denied"
>
请到系统设置允许访问麦克风
</string>
...
...
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