From 691d6c15adc33e580685949b1342828e15e5710e Mon Sep 17 00:00:00 2001 From: Zhanghu Date: Tue, 10 Mar 2026 10:45:46 +0800 Subject: [PATCH] =?UTF-8?q?*=20=E8=AE=BE=E7=BD=AE=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=94=B5=E6=BA=90=E5=BC=80=E5=85=B3=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=20*=20App=20=E5=90=AF=E5=8A=A8=E6=97=B6=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E4=B8=8D=E5=8F=91=E9=80=81=E5=BC=80=E6=9C=BA=E6=8C=87?= =?UTF-8?q?=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app_dashboard/changelog.md | 12 ++- .../dashboard/activity/SettingsActivity.java | 87 ++++++++++++++++--- .../perferences/PreferenceConfiguration.java | 2 +- .../src/main/res/xml/root_preferences.xml | 16 +++- 4 files changed, 100 insertions(+), 17 deletions(-) diff --git a/app_dashboard/changelog.md b/app_dashboard/changelog.md index dfa1e49..3df06bc 100644 --- a/app_dashboard/changelog.md +++ b/app_dashboard/changelog.md @@ -9,7 +9,17 @@ author: 2. $ {VERSION_CODE} (去掉空格),会自动替换实际修订号,比如 1.1.4.$ {VERSION_CODE} --> -### [1.0.5.${VERSION_CODE}] - 2026.3.5 +### [1.0.6.$ {VERSION_CODE}] - 2026.3.X + +#### 文件下载 + +* [dashboardclient_1.0.6.apk](dashboardclient_1.0.6.apk) + +#### 更新记录 +* 设置界面增加电源开关测试 +* App 启动时默认不发送开机指令 + +### [1.0.5.26] - 2026.3.5 #### 文件下载 diff --git a/app_dashboard/src/main/java/cn/ykbox/dashboard/activity/SettingsActivity.java b/app_dashboard/src/main/java/cn/ykbox/dashboard/activity/SettingsActivity.java index 85c5e26..eae4efe 100644 --- a/app_dashboard/src/main/java/cn/ykbox/dashboard/activity/SettingsActivity.java +++ b/app_dashboard/src/main/java/cn/ykbox/dashboard/activity/SettingsActivity.java @@ -2,15 +2,21 @@ package cn.ykbox.dashboard.activity; import android.content.SharedPreferences; import android.os.Bundle; +import android.text.TextUtils; +import android.widget.Toast; +import androidx.annotation.NonNull; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; +import com.blankj.utilcode.util.ToastUtils; + import cn.ykbox.dashboard.R; import cn.ykbox.dashboard.perferences.PreferenceConfiguration; +import cn.ykbox.dashboard.serial.SerialPortDetector; public class SettingsActivity extends AppCompatActivity { @@ -30,25 +36,82 @@ public class SettingsActivity extends AppCompatActivity { } } - public static class SettingsFragment extends PreferenceFragmentCompat { + public static class SettingsFragment extends PreferenceFragmentCompat + implements Preference.OnPreferenceClickListener { @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { setPreferencesFromResource(R.xml.root_preferences, rootKey); Preference clearDevicePref = findPreference("k_clear_device"); if (clearDevicePref != null) { - clearDevicePref.setOnPreferenceClickListener(preference -> { - new AlertDialog.Builder(requireContext()) - .setTitle("确认清除") - .setMessage("确定要清除当前串口设备路径吗?") - .setPositiveButton("确定", (dialog, which) -> { - PreferenceConfiguration.setSerialPortPath(requireContext(), ""); - }) - .setNegativeButton("取消", null) - .show(); - return true; - }); + clearDevicePref.setOnPreferenceClickListener(this); + } + + Preference testPowerOnPref = findPreference("k_test_power_on"); + if (testPowerOnPref != null) { + testPowerOnPref.setOnPreferenceClickListener(this); + } + + Preference testPowerOffPref = findPreference("k_test_power_off"); + if (testPowerOffPref != null) { + testPowerOffPref.setOnPreferenceClickListener(this); } } + + @Override + public boolean onPreferenceClick(@NonNull Preference preference) { + String key = preference.getKey(); + if(key.equals("k_clear_device")) { + clearSerialPath(); + return true; + } else if(key.equals("k_test_power_on")) { + testPowerOn(); + return true; + } else if(key.equals("k_test_power_off")) { + testPowerOff(); + return true; + } + + return false; + } + + private void clearSerialPath() { + new AlertDialog.Builder(requireContext()) + .setTitle("确认清除") + .setMessage("确定要清除当前串口设备路径吗?") + .setPositiveButton("确定", (dialog, which) -> { + PreferenceConfiguration.setSerialPortPath(requireContext(), ""); + }) + .setNegativeButton("取消", null) + .show(); + } + + private void testPowerOn() { + String portPath = PreferenceConfiguration.getSerialPortPath(getContext()); + int baudRate = PreferenceConfiguration.getSerialPortBaudRate(getContext()); + + if (TextUtils.isEmpty(portPath)) { + ToastUtils.showShort("串口路径未设置"); + return; + } + + SerialPortDetector detector = new SerialPortDetector(portPath, baudRate); + detector.sendPowerOnCommand(); + } + + + private void testPowerOff() { + String portPath = PreferenceConfiguration.getSerialPortPath(getContext()); + int baudRate = PreferenceConfiguration.getSerialPortBaudRate(getContext()); + + if (TextUtils.isEmpty(portPath)) { + ToastUtils.showShort("串口路径未设置"); + return; + } + + SerialPortDetector detector = new SerialPortDetector(portPath, baudRate); + detector.sendPowerOffCommand(); + } + } } \ No newline at end of file diff --git a/app_dashboard/src/main/java/cn/ykbox/dashboard/perferences/PreferenceConfiguration.java b/app_dashboard/src/main/java/cn/ykbox/dashboard/perferences/PreferenceConfiguration.java index 5039df1..7e0921a 100644 --- a/app_dashboard/src/main/java/cn/ykbox/dashboard/perferences/PreferenceConfiguration.java +++ b/app_dashboard/src/main/java/cn/ykbox/dashboard/perferences/PreferenceConfiguration.java @@ -33,6 +33,6 @@ public class PreferenceConfiguration { public static boolean getSendPowerOnCmd(Context context) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - return prefs.getBoolean(KEY_SEND_POWER_ON_CMD, true); + return prefs.getBoolean(KEY_SEND_POWER_ON_CMD, false); } } diff --git a/app_dashboard/src/main/res/xml/root_preferences.xml b/app_dashboard/src/main/res/xml/root_preferences.xml index c9c7c2d..ea45e01 100644 --- a/app_dashboard/src/main/res/xml/root_preferences.xml +++ b/app_dashboard/src/main/res/xml/root_preferences.xml @@ -14,7 +14,7 @@ app:defaultValue="@string/url_end_point_default_value" /> - + + app:summary="每次启动 App 时先发送关闭电源指令,再发送打开电源指令" + app:defaultValue="false" /> + + + + \ No newline at end of file