Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
p x
Hmct_PyTouch
Commits
c04039cd
Commit
c04039cd
authored
Oct 13, 2025
by
p x
Browse files
演示前准备
parent
46f764ee
Changes
2
Show whitespace changes
Inline
Side-by-side
app/src/main/java/com/sd/hmct_small_model/MainActivity.kt
View file @
c04039cd
...
...
@@ -4,6 +4,7 @@ import android.app.ProgressDialog
import
android.content.ComponentName
import
android.content.Intent
import
android.os.Bundle
import
android.widget.Toast
import
androidx.activity.enableEdgeToEdge
import
androidx.activity.viewModels
import
androidx.appcompat.app.AppCompatActivity
...
...
@@ -19,6 +20,9 @@ class MainActivity : AppCompatActivity() {
private
var
pd
:
ProgressDialog
?
=
null
//开始时间
private
var
starTime
=
0L
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
enableEdgeToEdge
()
...
...
@@ -29,7 +33,6 @@ class MainActivity : AppCompatActivity() {
// v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
// insets
// }
pyTorchVm
.
initialize
(
this
)
setLis
()
}
...
...
@@ -62,16 +65,35 @@ class MainActivity : AppCompatActivity() {
}
private
fun
setLis
()
{
//加载模型
binding
.
bt2
.
setOnClickListener
{
starTime
=
System
.
currentTimeMillis
()
pyTorchVm
.
initialize
(
this
)
Toast
.
makeText
(
this
,
"加载模型耗时:${System.currentTimeMillis() - starTime}ms"
,
Toast
.
LENGTH_LONG
).
show
()
starTime
=
0L
}
//开始计算
binding
.
bt1
.
setOnClickListener
{
if
(
pyTorchVm
.
isInitialized
)
{
showProgress
()
var
str
=
binding
.
et
.
text
.
toString
()
starTime
=
System
.
currentTimeMillis
()
pyTorchVm
.
analyzeText
(
str
)
}
else
{
Snackbar
.
make
(
binding
.
root
,
"请等待模型加载完成"
,
Snackbar
.
LENGTH_SHORT
).
show
()
}
}
pyTorchVm
.
starDemo
.
observe
(
this
)
{
it
->
Toast
.
makeText
(
this
,
"计算耗时:${System.currentTimeMillis() - starTime}ms"
,
Toast
.
LENGTH_LONG
).
show
()
starTime
=
0L
pd
?.
dismiss
()
binding
.
et
.
setHint
(
"打开车窗到60%"
)
starDemoApl
(
it
.
name
,
it
.
value
,
it
.
status
,
it
.
speed
)
...
...
@@ -81,7 +103,7 @@ class MainActivity : AppCompatActivity() {
private
fun
showProgress
()
{
pd
=
ProgressDialog
(
this
)
pd
?.
setProgressStyle
(
ProgressDialog
.
STYLE_SPINNER
);
pd
?.
setMessage
(
"
正在计算
,请稍后"
);
pd
?.
setMessage
(
"
推理中
,请稍后"
);
pd
?.
setIndeterminate
(
false
);
pd
?.
setCancelable
(
true
);
pd
?.
show
();
...
...
app/src/main/res/layout/activity_main.xml
View file @
c04039cd
...
...
@@ -13,7 +13,7 @@
android:layout_height=
"wrap_content"
android:layout_marginTop=
"20dp"
android:maxLines=
"1"
android:text=
""
android:text=
"
空调设置45
"
android:hint=
"空调设置45"
/>
...
...
@@ -24,4 +24,10 @@
android:text=
"开始计算"
/>
<Button
android:id=
"@+id/bt2"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:text=
"加载模型"
/>
</LinearLayout>
\ No newline at end of file
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