From 6a17d3d7f9f9c301dcdc54795f0140addc4bca56 Mon Sep 17 00:00:00 2001 From: ZhanGSKen Date: Sat, 28 Feb 2026 21:15:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AF=AD=E9=9F=B3=E6=92=AD?= =?UTF-8?q?=E6=94=BE=E6=A8=A1=E5=9D=97=E5=AE=9E=E7=8E=B0=E9=83=A8=E5=88=86?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- powerbell/build.properties | 4 +- .../handlers/ControlCenterServiceHandler.java | 2 + .../powerbell/threads/RemindThread.java | 4 + .../powerbell/threads/TTSRemindThread.java | 122 ++++++++++++++++++ 4 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 powerbell/src/main/java/cc/winboll/studio/powerbell/threads/TTSRemindThread.java diff --git a/powerbell/build.properties b/powerbell/build.properties index be3f803..a934daf 100644 --- a/powerbell/build.properties +++ b/powerbell/build.properties @@ -1,8 +1,8 @@ #Created by .winboll/winboll_app_build.gradle -#Sat Feb 28 12:14:20 GMT 2026 +#Sat Feb 28 13:13:09 GMT 2026 stageCount=9 libraryProject= baseVersion=15.15 publishVersion=15.15.8 -buildCount=3 +buildCount=11 baseBetaVersion=15.15.9 diff --git a/powerbell/src/main/java/cc/winboll/studio/powerbell/handlers/ControlCenterServiceHandler.java b/powerbell/src/main/java/cc/winboll/studio/powerbell/handlers/ControlCenterServiceHandler.java index 3c33ce1..eb349d4 100644 --- a/powerbell/src/main/java/cc/winboll/studio/powerbell/handlers/ControlCenterServiceHandler.java +++ b/powerbell/src/main/java/cc/winboll/studio/powerbell/handlers/ControlCenterServiceHandler.java @@ -4,7 +4,9 @@ import android.os.Handler; import android.os.Message; import cc.winboll.studio.libappbase.LogUtils; import cc.winboll.studio.powerbell.models.NotificationMessage; +import cc.winboll.studio.powerbell.models.ThoughtfulServiceBean; import cc.winboll.studio.powerbell.services.ControlCenterService; +import cc.winboll.studio.powerbell.threads.TTSRemindThread; import java.lang.ref.WeakReference; /** diff --git a/powerbell/src/main/java/cc/winboll/studio/powerbell/threads/RemindThread.java b/powerbell/src/main/java/cc/winboll/studio/powerbell/threads/RemindThread.java index ad05f6f..07a448a 100644 --- a/powerbell/src/main/java/cc/winboll/studio/powerbell/threads/RemindThread.java +++ b/powerbell/src/main/java/cc/winboll/studio/powerbell/threads/RemindThread.java @@ -188,6 +188,9 @@ public class RemindThread extends Thread { LogUtils.d(TAG, String.format("未有合适类型提醒,退出提醒线程 | threadId=%d", getId())); break; } + + // 启动电量通知 TTS 语音提醒线程 + TTSRemindThread.start(this.mContext, App.sQuantityOfElectricity, isCharging); // 安全休眠,保留中断标记 safeSleepInternal(sleepTime); @@ -280,6 +283,7 @@ public class RemindThread extends Thread { */ private void cleanThreadStateInternal() { LogUtils.d(TAG, String.format("cleanThreadStateInternal() 调用 | threadId=%d", getId())); + TTSRemindThread.stopTTS(); isReminding = false; isExist = true; // 中断当前线程(如果存活) diff --git a/powerbell/src/main/java/cc/winboll/studio/powerbell/threads/TTSRemindThread.java b/powerbell/src/main/java/cc/winboll/studio/powerbell/threads/TTSRemindThread.java new file mode 100644 index 0000000..fdc8a60 --- /dev/null +++ b/powerbell/src/main/java/cc/winboll/studio/powerbell/threads/TTSRemindThread.java @@ -0,0 +1,122 @@ +package cc.winboll.studio.powerbell.threads; + +import android.content.Context; +import cc.winboll.studio.libappbase.LogUtils; +import cc.winboll.studio.libappbase.ToastUtils; +import cc.winboll.studio.powerbell.models.ThoughtfulServiceBean; +import cc.winboll.studio.powerbell.services.TTSPlayService; + +/** + * @Author 豆包&ZhanGSKen + * @Date 2026/02/28 20:41 + * @Describe TTS 语音通知线程(单例 + 继承 Thread) + */ +public class TTSRemindThread extends Thread { + + public static final String TAG = "TTSRemindThread"; + + // 单例实例 + private static TTSRemindThread sInstance; + + // 运行标志 + private volatile boolean mIsRunning = false; + private volatile int mBattery; + private volatile boolean mIsCharging; + + private Context mContext; + + /** + * 私有构造,单例禁用外部 new + */ + private TTSRemindThread(Context context) { + this.mContext = context.getApplicationContext(); + } + + /** + * 获取单例(DCL 双重校验) + */ + public static TTSRemindThread getInstance(Context context) { + if (sInstance == null) { + synchronized (TTSRemindThread.class) { + if (sInstance == null) { + sInstance = new TTSRemindThread(context); + } + } + } + return sInstance; + } + + /** + * 对外静态启动入口 + */ + public static void start(Context context, int battery, boolean isCharging) { + TTSRemindThread instance = getInstance(context); + instance.mBattery = battery; + instance.mIsCharging = isCharging; + if (!instance.mIsRunning) { + LogUtils.d(TAG, "start() TTS 提醒线程启动"); + instance.mIsRunning = true; + instance.start(); // 启动线程 + } + } + + /** + * 对外静态停止入口 + */ + public static void stopTTS() { + if (sInstance != null) { + LogUtils.d(TAG, "stopTTS() TTS 提醒线程停止"); + sInstance.mIsRunning = false; + sInstance = null; + } + } + + /** + * 线程主逻辑 + */ + @Override + public void run() { + super.run(); + LogUtils.d(TAG, "run() TTS 线程已开始循环"); + + while (mIsRunning) { + try { + // ====================== + // 在这里写你的循环 TTS 逻辑 + // ====================== + + // TTS 语音通知模块 + // 读取 TTS 语音通知配置 + ThoughtfulServiceBean ttsBean = ThoughtfulServiceBean.loadBean(mContext, ThoughtfulServiceBean.class); + if (ttsBean == null) { + ttsBean = new ThoughtfulServiceBean(); + } + if (ttsBean.isEnableTtsWhenNotifyBattery()) { + //ToastUtils.show("Test"); + // 启动 + ToastUtils.show(String.format("mIsCharging %s, mBattery %d", mIsCharging, mBattery)); + String text = mIsCharging ?"充电": "用电"; + text += String.format("已达预定值百分之%d", mBattery); + TTSPlayService.startPlayTTS(mContext, text); + } + + // 防止死循环疯狂跑,加一点休眠 + sleep(5000); + } catch (InterruptedException e) { + LogUtils.e(TAG, "TTS 线程被中断", e); + break; + } + } + + mIsRunning = false; + LogUtils.d(TAG, "run() TTS 线程已退出"); + } + + /** + * 是否正在运行 + */ + public boolean isRunning() { + return mIsRunning; + } +} +