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