mirror of
https://gitea.winboll.cc/ZhanGSKen/MyWinBoLL.git
synced 2026-08-14 05:27:10 +08:00
<powerbell> 新增 APPMSGMailRemindThread 邮件提醒线程及 SMTPConfigView 配置界面
- 新增 APPMSGMailRemindThread 单实例线程,定时30秒发送电量状态邮件 - SettingsActivity 添加 SMTPConfigView 控件,支持 SMTP 配置与测试发送 - build.gradle 添加 android-mail/android-activation 1.6.7 依赖 - build.gradle 添加 packagingOptions 排除重复 META-INF 文件 - build.properties: 构建计数器自动更新
This commit is contained in:
@@ -42,7 +42,10 @@ android {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
packagingOptions {
|
||||
exclude 'META-INF/NOTICE.md'
|
||||
exclude 'META-INF/LICENSE.md'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -90,4 +93,8 @@ dependencies {
|
||||
|
||||
//api fileTree(dir: 'libs', include: ['*.aar'])
|
||||
api fileTree(dir: 'libs', include: ['*.jar'])
|
||||
|
||||
// JavaMail(APPMSGMailUtils 发送邮件依赖,Android 专用版)
|
||||
implementation 'com.sun.mail:android-mail:1.6.7'
|
||||
implementation 'com.sun.mail:android-activation:1.6.7'
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Fri Jul 17 15:59:06 CST 2026
|
||||
#Fri Jul 17 17:35:09 CST 2026
|
||||
stageCount=19
|
||||
libraryProject=
|
||||
baseVersion=15.15
|
||||
publishVersion=15.15.18
|
||||
buildCount=6
|
||||
buildCount=13
|
||||
baseBetaVersion=15.15.19
|
||||
|
||||
@@ -14,6 +14,7 @@ import android.widget.Toast;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
|
||||
import cc.winboll.studio.libaes.views.SMTPConfigView;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.libappbase.ToastUtils;
|
||||
import cc.winboll.studio.powerbell.R;
|
||||
@@ -40,6 +41,7 @@ public class SettingsActivity extends WinBoLLActivity implements IWinBoLLActivit
|
||||
private CheckBox cbUseageTtsBattary; // 用电TTS带电量提醒(子开关)
|
||||
private CheckBox cbChargeTtsBattary; // 充电TTS带电量提醒(子开关)
|
||||
private CheckBox cbTtsWhenNotifyBattery; // 👉 新增:通知电量时同时播放TTS
|
||||
private SMTPConfigView smtpConfigView; // SMTP邮件配置视图
|
||||
|
||||
// ======================== 接口实现区 =========================
|
||||
@Override
|
||||
@@ -62,6 +64,7 @@ public class SettingsActivity extends WinBoLLActivity implements IWinBoLLActivit
|
||||
initToolbar();
|
||||
initTtsCheckBoxes();
|
||||
initTtsCheckBoxStatus();
|
||||
initSMTPConfigView();
|
||||
|
||||
LogUtils.d(TAG, "onCreate: 应用设置页面初始化完成");
|
||||
}
|
||||
@@ -126,6 +129,15 @@ public class SettingsActivity extends WinBoLLActivity implements IWinBoLLActivit
|
||||
LogUtils.d(TAG, "initTtsCheckBoxStatus: TTS复选框状态初始化完成");
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化SMTP邮件配置视图
|
||||
*/
|
||||
private void initSMTPConfigView() {
|
||||
LogUtils.d(TAG, "initSMTPConfigView: SMTP邮件配置视图初始化开始");
|
||||
smtpConfigView = findViewById(R.id.smtp_config_view);
|
||||
LogUtils.d(TAG, "initSMTPConfigView: SMTP邮件配置视图初始化完成");
|
||||
}
|
||||
|
||||
// ======================== 事件响应区 =========================
|
||||
/**
|
||||
* 悬浮窗权限检查入口
|
||||
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
package cc.winboll.studio.powerbell.threads;
|
||||
|
||||
import android.content.Context;
|
||||
import cc.winboll.studio.libaes.utils.APPMSGMailUtils;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.powerbell.App;
|
||||
|
||||
/**
|
||||
* APPMSG 邮件通知提醒线程(单例 + 继承 Thread)
|
||||
* 功能:定时每30秒调用 APPMSGMailUtils 发送电量状态邮件给预设收件人
|
||||
* 适配:Java7 | API30
|
||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2026/07/17
|
||||
*/
|
||||
public class APPMSGMailRemindThread extends Thread {
|
||||
|
||||
public static final String TAG = "APPMSGMailRemindThread";
|
||||
|
||||
// 邮件发送间隔(毫秒)
|
||||
private static final long MAIL_SEND_INTERVAL = 30000;
|
||||
|
||||
// 单例实例
|
||||
private static APPMSGMailRemindThread sInstance;
|
||||
|
||||
// 运行标志
|
||||
private volatile boolean mIsRunning = false;
|
||||
private volatile int mBattery;
|
||||
private volatile boolean mIsCharging;
|
||||
|
||||
private Context mContext;
|
||||
|
||||
/**
|
||||
* 私有构造,单例禁用外部 new
|
||||
*/
|
||||
private APPMSGMailRemindThread(Context context) {
|
||||
this.mContext = context.getApplicationContext();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单例(DCL 双重校验)
|
||||
*/
|
||||
public static APPMSGMailRemindThread getInstance(Context context) {
|
||||
if (sInstance == null) {
|
||||
synchronized (APPMSGMailRemindThread.class) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new APPMSGMailRemindThread(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对外静态启动入口
|
||||
*/
|
||||
public static void start(Context context, int battery, boolean isCharging) {
|
||||
APPMSGMailRemindThread instance = getInstance(context);
|
||||
instance.mBattery = battery;
|
||||
instance.mIsCharging = isCharging;
|
||||
if (!instance.mIsRunning) {
|
||||
LogUtils.d(TAG, "start() 邮件提醒线程启动");
|
||||
instance.mIsRunning = true;
|
||||
instance.start();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 对外静态停止入口
|
||||
*/
|
||||
public static void stopMail() {
|
||||
if (sInstance != null) {
|
||||
LogUtils.d(TAG, "stopMail() 邮件提醒线程停止");
|
||||
sInstance.mIsRunning = false;
|
||||
sInstance = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 线程主逻辑:定时发送邮件
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
super.run();
|
||||
LogUtils.d(TAG, "run() 邮件线程已开始循环");
|
||||
|
||||
while (mIsRunning) {
|
||||
try {
|
||||
String chargingText = mIsCharging ? "充电" : "用电";
|
||||
String subject = "PowerBell 电量状态通知";
|
||||
String content = String.format(
|
||||
"当前状态:%s,电量为百分之%d",
|
||||
chargingText, mBattery);
|
||||
String recipient = APPMSGMailUtils.getRecipient(mContext);
|
||||
|
||||
LogUtils.d(TAG, String.format("run() 发送邮件 | 收件人:%s | 内容:%s", recipient, content));
|
||||
APPMSGMailUtils.sendMail(mContext, subject, content, recipient);
|
||||
|
||||
sleep(MAIL_SEND_INTERVAL);
|
||||
} catch (InterruptedException e) {
|
||||
LogUtils.e(TAG, "邮件线程被中断", e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mIsRunning = false;
|
||||
LogUtils.d(TAG, "run() 邮件线程已退出");
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否正在运行
|
||||
*/
|
||||
public boolean isRunning() {
|
||||
return mIsRunning;
|
||||
}
|
||||
}
|
||||
@@ -153,6 +153,12 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<cc.winboll.studio.libaes.views.SMTPConfigView
|
||||
android:id="@+id/smtp_config_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="300dp"
|
||||
|
||||
Reference in New Issue
Block a user