From 03cc65446889fecbefd51258cbe8cb8b518b7d65 Mon Sep 17 00:00:00 2001
From: Sucan <632190820@qq.com>
Date: Tue, 10 Mar 2026 20:40:37 +0800
Subject: [PATCH] =?UTF-8?q?feat(=E8=AE=BE=E7=BD=AE=E7=95=8C=E9=9D=A2):=20?=
=?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=95=BF=E6=8C=89=E9=87=8D=E5=90=AF=E5=BA=94?=
=?UTF-8?q?=E7=94=A8=E5=8A=9F=E8=83=BD=E5=B9=B6=E4=BC=98=E5=8C=96=E7=95=8C?=
=?UTF-8?q?=E9=9D=A2=E5=B8=83=E5=B1=80?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 在设置界面新增长按重启按钮,包含进度条动画反馈
- 添加自定义进度条样式以增强视觉体验
- 优化IP配置区域的布局结构,将保存按钮与输入框水平排列
- 移除MqttManager中冗余的注释
- 更新字符串资源以支持新功能
---
.../lzwcai_terminal_temi/MqttManager.kt | 2 +-
.../lzwcai_terminal_temi/SettingsActivity.kt | 72 +++++++++++++--
.../main/res/drawable/custom_progress_bar.xml | 17 ++++
app/src/main/res/layout/activity_settings.xml | 90 +++++++++++--------
app/src/main/res/values/strings.xml | 1 +
5 files changed, 135 insertions(+), 47 deletions(-)
create mode 100644 app/src/main/res/drawable/custom_progress_bar.xml
diff --git a/app/src/main/java/com/example/lzwcai_terminal_temi/MqttManager.kt b/app/src/main/java/com/example/lzwcai_terminal_temi/MqttManager.kt
index a181d96..ec8e50c 100644
--- a/app/src/main/java/com/example/lzwcai_terminal_temi/MqttManager.kt
+++ b/app/src/main/java/com/example/lzwcai_terminal_temi/MqttManager.kt
@@ -56,7 +56,7 @@ class MqttManager(private val context: Context, private val serverIp: String) {
isAutomaticReconnect = false
isCleanSession = true
connectionTimeout = 10
- keepAliveInterval = 60 // 设置心跳间隔为60秒
+ keepAliveInterval = 60
userName = "lzwc"
password = "Lzwc@4187.".toCharArray()
}
diff --git a/app/src/main/java/com/example/lzwcai_terminal_temi/SettingsActivity.kt b/app/src/main/java/com/example/lzwcai_terminal_temi/SettingsActivity.kt
index c3a2f3c..5477968 100644
--- a/app/src/main/java/com/example/lzwcai_terminal_temi/SettingsActivity.kt
+++ b/app/src/main/java/com/example/lzwcai_terminal_temi/SettingsActivity.kt
@@ -1,35 +1,38 @@
package com.example.lzwcai_terminal_temi
+import android.animation.ValueAnimator
+import android.app.AlarmManager
+import android.app.PendingIntent
import android.content.Context
+import android.content.Intent
import android.os.Bundle
import android.util.Log
+import android.view.MotionEvent
import android.view.View
import android.view.WindowManager
import android.view.inputmethod.InputMethodManager
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.example.lzwcai_terminal_temi.databinding.ActivitySettingsBinding
+import kotlin.system.exitProcess
class SettingsActivity : AppCompatActivity() {
private lateinit var binding: ActivitySettingsBinding
+ private var restartAnimator: ValueAnimator? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivitySettingsBinding.inflate(layoutInflater)
setContentView(binding.root)
-
- // 默认隐藏软键盘
+
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)
val prefs = getSharedPreferences("app_prefs", Context.MODE_PRIVATE)
val savedIp = prefs.getString("network_ip", "")
binding.etIpAddress.setText(savedIp)
-
- // 点击外部隐藏键盘
- binding.root.setOnClickListener {
- hideKeyboard()
- }
+
+ binding.root.setOnClickListener { hideKeyboard() }
binding.btnSave.setOnClickListener {
hideKeyboard()
@@ -50,8 +53,61 @@ class SettingsActivity : AppCompatActivity() {
finish()
}
+ setupRestartButton()
}
-
+
+ private fun setupRestartButton() {
+ binding.btnRestart.setOnTouchListener { _, event ->
+ when (event.action) {
+ MotionEvent.ACTION_DOWN -> {
+ startRestartAnimation()
+ true
+ }
+ MotionEvent.ACTION_UP,
+ MotionEvent.ACTION_CANCEL -> {
+ cancelRestartAnimation()
+ true
+ }
+ else -> false
+ }
+ }
+ }
+
+ private fun startRestartAnimation() {
+ binding.restartProgressBar.visibility = View.VISIBLE
+ restartAnimator = ValueAnimator.ofInt(0, 100).apply {
+ duration = 3000
+ addUpdateListener { animation ->
+ binding.restartProgressBar.progress = animation.animatedValue as Int
+ }
+ addListener(object : android.animation.Animator.AnimatorListener {
+ override fun onAnimationEnd(animation: android.animation.Animator) {
+ if (binding.restartProgressBar.progress == 100) {
+ restartApplication()
+ }
+ }
+ override fun onAnimationStart(animation: android.animation.Animator) {}
+ override fun onAnimationCancel(animation: android.animation.Animator) {}
+ override fun onAnimationRepeat(animation: android.animation.Animator) {}
+ })
+ start()
+ }
+ }
+
+ private fun cancelRestartAnimation() {
+ restartAnimator?.cancel()
+ binding.restartProgressBar.progress = 0
+ binding.restartProgressBar.visibility = View.INVISIBLE
+ }
+
+ private fun restartApplication() {
+ val intent = packageManager.getLaunchIntentForPackage(packageName)
+ val pendingIntent = PendingIntent.getActivity(this, 123456, intent, PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE)
+ val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager
+ alarmManager.set(AlarmManager.RTC, System.currentTimeMillis() + 100, pendingIntent)
+ exitProcess(0)
+ }
+
private fun hideKeyboard() {
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
currentFocus?.let {
diff --git a/app/src/main/res/drawable/custom_progress_bar.xml b/app/src/main/res/drawable/custom_progress_bar.xml
new file mode 100644
index 0000000..43e124d
--- /dev/null
+++ b/app/src/main/res/drawable/custom_progress_bar.xml
@@ -0,0 +1,17 @@
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml
index 32e8838..dd82c8c 100644
--- a/app/src/main/res/layout/activity_settings.xml
+++ b/app/src/main/res/layout/activity_settings.xml
@@ -1,5 +1,6 @@
@@ -9,7 +10,6 @@
android:layout_height="wrap_content"
android:padding="24dp">
-
-
-
+ android:gravity="center_vertical"
+ android:orientation="horizontal">
-
+
+
-
-
-
-
-
-
-
+ android:layout_height="60dp"
+ android:text="@string/btn_save"
+ android:textSize="24sp" />
-
-
+
+
+
+
+
+
+
+
+
+
日志将显示在这里...
随机表情
让机器人说话
+ 长按重启应用
\ No newline at end of file