mirror of
https://gitea.winboll.cc/ZhanGSKen/MyWinBoLL.git
synced 2026-08-14 05:27:11 +08:00
<powerbell> 优化 ChargeMailNotify 提醒方式切换逻辑
1. RemindThread 提醒线程 - ChargeMailNotify 启用:使用 APPMSGMailRemindThread 邮件提醒 - ChargeMailNotify 未启用:使用 TTSRemindThread 语音提醒 - 停止线程时同步切换逻辑 2. ControlCenterServiceHandler 消息处理 - ChargeMailNotify 启用:使用 Toast 代替通知栏提醒 - ChargeMailNotify 未启用:正常发送通知栏提醒 3. 悬浮窗提示信息更新 - 新增TTS语音播放功能已禁用提示 - 新增电量提醒通知栏功能已禁用提示
This commit is contained in:
+32
-18
@@ -3,10 +3,12 @@ package cc.winboll.studio.powerbell.handlers;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.libappbase.ToastUtils;
|
||||
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 cc.winboll.studio.powerbell.utils.ChargeMailNotifyHelper;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
/**
|
||||
@@ -85,11 +87,7 @@ public class ControlCenterServiceHandler extends Handler {
|
||||
private void handleRemindMessage(ControlCenterService service, String remindType, int currentBattery, boolean isCharging) {
|
||||
LogUtils.d(TAG, "handleRemindMessage: 开始处理提醒消息 | type=" + remindType + " | battery=" + currentBattery + " | isCharging=" + isCharging);
|
||||
|
||||
// 1. 前置校验:通知工具类+参数有效性
|
||||
if (service.getNotificationManager() == null) {
|
||||
LogUtils.e(TAG, "handleRemindMessage: 通知管理工具类未初始化,无法发送提醒");
|
||||
return;
|
||||
}
|
||||
// 1. 前置校验:参数有效性
|
||||
if (!REMIND_TYPE_CHARGE.equals(remindType) && !REMIND_TYPE_USAGE.equals(remindType)) {
|
||||
LogUtils.w(TAG, "handleRemindMessage: 提醒类型无效,忽略 | type=" + remindType + " | 允许值:" + REMIND_TYPE_CHARGE + "/" + REMIND_TYPE_USAGE);
|
||||
return;
|
||||
@@ -99,24 +97,40 @@ public class ControlCenterServiceHandler extends Handler {
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 构建通知模型,使用统一格式
|
||||
NotificationMessage remindMsg = new NotificationMessage();
|
||||
// 2. 构建提醒内容
|
||||
String chargeStateDesc = isCharging ? CHARGE_STATE_CHARGING : CHARGE_STATE_NOT_CHARGING;
|
||||
String content;
|
||||
if (REMIND_TYPE_CHARGE.equals(remindType)) {
|
||||
remindMsg.setTitle(CHARGE_REMIND_TITLE);
|
||||
remindMsg.setContent(String.format(CHARGE_REMIND_CONTENT_FORMAT, currentBattery, chargeStateDesc));
|
||||
remindMsg.setRemindMSG("charge_remind");
|
||||
content = String.format(CHARGE_REMIND_CONTENT_FORMAT, currentBattery, chargeStateDesc);
|
||||
} else {
|
||||
remindMsg.setTitle(USAGE_REMIND_TITLE);
|
||||
remindMsg.setContent(String.format(USAGE_REMIND_CONTENT_FORMAT, currentBattery, chargeStateDesc));
|
||||
remindMsg.setRemindMSG("usage_remind");
|
||||
content = String.format(USAGE_REMIND_CONTENT_FORMAT, currentBattery, chargeStateDesc);
|
||||
}
|
||||
LogUtils.d(TAG, "handleRemindMessage: 通知模型构建完成 | title=" + remindMsg.getTitle() + " | content=" + remindMsg.getContent());
|
||||
LogUtils.d(TAG, "handleRemindMessage: 提醒内容构建完成 | content=" + content);
|
||||
|
||||
// 3. 调用通知工具类发送提醒
|
||||
LogUtils.d(TAG, "handleRemindMessage: 调用通知工具类发送提醒 | remindMSG=" + remindMsg.getRemindMSG());
|
||||
service.getNotificationManager().showRemindNotification(service, remindMsg);
|
||||
LogUtils.d(TAG, "handleRemindMessage: 提醒通知发送流程执行完毕");
|
||||
// 3. 根据 ChargeMailNotify 状态选择提醒方式
|
||||
if (ChargeMailNotifyHelper.isEnabled(service)) {
|
||||
// 启用邮件通知时,使用 Toast 代替通知栏
|
||||
LogUtils.d(TAG, "handleRemindMessage: 充电邮件通知已启用,使用 Toast 提醒");
|
||||
ToastUtils.show(content);
|
||||
} else {
|
||||
// 未启用邮件通知时,使用通知栏提醒
|
||||
if (service.getNotificationManager() == null) {
|
||||
LogUtils.e(TAG, "handleRemindMessage: 通知管理工具类未初始化,无法发送提醒");
|
||||
return;
|
||||
}
|
||||
NotificationMessage remindMsg = new NotificationMessage();
|
||||
if (REMIND_TYPE_CHARGE.equals(remindType)) {
|
||||
remindMsg.setTitle(CHARGE_REMIND_TITLE);
|
||||
remindMsg.setRemindMSG("charge_remind");
|
||||
} else {
|
||||
remindMsg.setTitle(USAGE_REMIND_TITLE);
|
||||
remindMsg.setRemindMSG("usage_remind");
|
||||
}
|
||||
remindMsg.setContent(content);
|
||||
LogUtils.d(TAG, "handleRemindMessage: 调用通知工具类发送提醒 | remindMSG=" + remindMsg.getRemindMSG());
|
||||
service.getNotificationManager().showRemindNotification(service, remindMsg);
|
||||
}
|
||||
LogUtils.d(TAG, "handleRemindMessage: 提醒流程执行完毕");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -190,11 +190,13 @@ public class RemindThread extends Thread {
|
||||
break;
|
||||
}
|
||||
|
||||
// 启动电量通知 TTS 语音提醒线程
|
||||
TTSRemindThread.start(this.mContext, App.sQuantityOfElectricity, isCharging);
|
||||
// 启动电量通知邮件提醒线程(仅在充电邮件通知功能启用时)
|
||||
// 根据 ChargeMailNotify 功能状态选择提醒方式
|
||||
if (ChargeMailNotifyHelper.isEnabled(this.mContext)) {
|
||||
// 启用电邮件提醒,不使用 TTS
|
||||
APPMSGMailRemindThread.start(this.mContext, App.sQuantityOfElectricity, isCharging);
|
||||
} else {
|
||||
// 未启用邮件提醒,使用 TTS 语音提醒
|
||||
TTSRemindThread.start(this.mContext, App.sQuantityOfElectricity, isCharging);
|
||||
}
|
||||
|
||||
// 安全休眠,保留中断标记
|
||||
@@ -288,10 +290,11 @@ public class RemindThread extends Thread {
|
||||
*/
|
||||
private void cleanThreadStateInternal() {
|
||||
LogUtils.d(TAG, String.format("cleanThreadStateInternal() 调用 | threadId=%d", getId()));
|
||||
TTSRemindThread.stopTTS();
|
||||
// 仅在充电邮件通知功能启用时停止邮件提醒线程
|
||||
// 根据 ChargeMailNotify 功能状态停止对应的提醒线程
|
||||
if (ChargeMailNotifyHelper.isEnabled(this.mContext)) {
|
||||
APPMSGMailRemindThread.stopMail();
|
||||
} else {
|
||||
TTSRemindThread.stopTTS();
|
||||
}
|
||||
isReminding = false;
|
||||
isExist = true;
|
||||
|
||||
@@ -15,11 +15,32 @@
|
||||
android:src="@drawable/ic_email"
|
||||
android:layout_marginRight="8dp"/>
|
||||
|
||||
<TextView
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="充电邮件通知服务已启用"
|
||||
android:textColor="#FF000000"
|
||||
android:textSize="14sp"/>
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="充电邮件通知服务已启用"
|
||||
android:textColor="#FF000000"
|
||||
android:textSize="14sp"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="TTS语音播放功能已禁用"
|
||||
android:textColor="#FF666666"
|
||||
android:textSize="12sp"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="电量提醒通知栏功能已禁用"
|
||||
android:textColor="#FF666666"
|
||||
android:textSize="12sp"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
Reference in New Issue
Block a user