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 eb349d4..b4c2fe1 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 @@ -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: 提醒流程执行完毕"); } } 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 84e66d9..2a138c3 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 @@ -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; diff --git a/powerbell/src/main/res/layout/view_charge_mail_notify.xml b/powerbell/src/main/res/layout/view_charge_mail_notify.xml index 69c163a..773372d 100644 --- a/powerbell/src/main/res/layout/view_charge_mail_notify.xml +++ b/powerbell/src/main/res/layout/view_charge_mail_notify.xml @@ -15,11 +15,32 @@ android:src="@drawable/ic_email" android:layout_marginRight="8dp"/> - + android:layout_height="wrap_content"> + + + + + + + +