mirror of
https://gitea.winboll.cc/Studio/OriginMaster.git
synced 2026-02-04 08:21:30 +08:00
TTS贴心服务加入当前电量语音提醒功能。
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Tue Jan 13 11:47:03 HKT 2026
|
||||
#Mon Jan 19 11:57:03 GMT 2026
|
||||
stageCount=1
|
||||
libraryProject=
|
||||
baseVersion=15.15
|
||||
publishVersion=15.15.0
|
||||
buildCount=0
|
||||
buildCount=5
|
||||
baseBetaVersion=15.15.1
|
||||
|
||||
@@ -56,13 +56,17 @@ public class SettingsActivity extends WinBoLLActivity implements IWinBoLLActivit
|
||||
|
||||
// 初始化工具栏
|
||||
initToolbar();
|
||||
|
||||
|
||||
ThoughtfulServiceBean thoughtfulServiceBean = ThoughtfulServiceBean.loadBean(this, ThoughtfulServiceBean.class);
|
||||
if (thoughtfulServiceBean == null) {
|
||||
thoughtfulServiceBean = new ThoughtfulServiceBean();
|
||||
}
|
||||
// 原有2个复选框赋值
|
||||
((CheckBox)findViewById(R.id.activitysettingsCheckBox1)).setChecked(thoughtfulServiceBean.isEnableUsePowerTts());
|
||||
((CheckBox)findViewById(R.id.activitysettingsCheckBox2)).setChecked(thoughtfulServiceBean.isEnableChargeTts());
|
||||
// 新增2个复选框赋值
|
||||
((CheckBox)findViewById(R.id.activitysettingsCheckBox3)).setChecked(thoughtfulServiceBean.isEnableUseageTtsWithBattary());
|
||||
((CheckBox)findViewById(R.id.activitysettingsCheckBox4)).setChecked(thoughtfulServiceBean.isEnableChargeTtsWithBattary());
|
||||
|
||||
LogUtils.d(TAG, "【onCreate】SettingsActivity 初始化完成");
|
||||
}
|
||||
@@ -94,6 +98,7 @@ public class SettingsActivity extends WinBoLLActivity implements IWinBoLLActivit
|
||||
canDrawOverlays();
|
||||
}
|
||||
|
||||
// 原有方法
|
||||
public void onEnableChargeTts(View view) {
|
||||
ThoughtfulServiceBean thoughtfulServiceBean = ThoughtfulServiceBean.loadBean(this, ThoughtfulServiceBean.class);
|
||||
if (thoughtfulServiceBean == null) {
|
||||
@@ -103,6 +108,7 @@ public class SettingsActivity extends WinBoLLActivity implements IWinBoLLActivit
|
||||
ThoughtfulServiceBean.saveBean(this, thoughtfulServiceBean);
|
||||
}
|
||||
|
||||
// 原有方法
|
||||
public void onEnableUsePowerTts(View view) {
|
||||
ThoughtfulServiceBean thoughtfulServiceBean = ThoughtfulServiceBean.loadBean(this, ThoughtfulServiceBean.class);
|
||||
if (thoughtfulServiceBean == null) {
|
||||
@@ -112,6 +118,26 @@ public class SettingsActivity extends WinBoLLActivity implements IWinBoLLActivit
|
||||
ThoughtfulServiceBean.saveBean(this, thoughtfulServiceBean);
|
||||
}
|
||||
|
||||
// 新增:用电TTS加入电量提醒
|
||||
public void onEnableUseageTtsWithBattary(View view) {
|
||||
ThoughtfulServiceBean thoughtfulServiceBean = ThoughtfulServiceBean.loadBean(this, ThoughtfulServiceBean.class);
|
||||
if (thoughtfulServiceBean == null) {
|
||||
thoughtfulServiceBean = new ThoughtfulServiceBean();
|
||||
}
|
||||
thoughtfulServiceBean.setIsEnableUseageTtsWithBattary(((CheckBox)view).isChecked());
|
||||
ThoughtfulServiceBean.saveBean(this, thoughtfulServiceBean);
|
||||
}
|
||||
|
||||
// 新增:充电TTS加入电量提醒
|
||||
public void onEnableChargeTtsWithBattary(View view) {
|
||||
ThoughtfulServiceBean thoughtfulServiceBean = ThoughtfulServiceBean.loadBean(this, ThoughtfulServiceBean.class);
|
||||
if (thoughtfulServiceBean == null) {
|
||||
thoughtfulServiceBean = new ThoughtfulServiceBean();
|
||||
}
|
||||
thoughtfulServiceBean.setIsEnableChargeTtsWithBattary(((CheckBox)view).isChecked());
|
||||
ThoughtfulServiceBean.saveBean(this, thoughtfulServiceBean);
|
||||
}
|
||||
|
||||
/**
|
||||
* 悬浮窗权限检查与请求
|
||||
*/
|
||||
|
||||
@@ -24,10 +24,15 @@ public class ThoughtfulServiceBean extends BaseBean implements Parcelable, Seria
|
||||
// JSON序列化字段常量 杜绝硬编码
|
||||
public static final String JSON_FIELD_IS_ENABLE_CHARGE_TTS = "isEnableChargeTts";
|
||||
public static final String JSON_FIELD_IS_ENABLE_USE_POWER_TTS = "isEnableUsePowerTts";
|
||||
// 新增字段JSON常量
|
||||
public static final String JSON_FIELD_IS_ENABLE_USAGE_TTS_WITH_BATTERY = "isEnableUseageTtsWithBattary";
|
||||
public static final String JSON_FIELD_IS_ENABLE_CHARGE_TTS_WITH_BATTERY = "isEnableChargeTtsWithBattary";
|
||||
|
||||
// ====================== 核心成员变量 - 私有封装 ======================
|
||||
private boolean isEnableChargeTts = false; // 是否启用 充电TTS贴心语音服务
|
||||
private boolean isEnableUsePowerTts = false; // 是否启用 用电TTS贴心语音服务
|
||||
private boolean isEnableUseageTtsWithBattary = false; // 用电TTS加入电量提醒
|
||||
private boolean isEnableChargeTtsWithBattary = false;// 充电TTS加入电量提醒
|
||||
|
||||
// ====================== Parcelable 静态创建器 (API30标准写法 必须public static final) ======================
|
||||
public static final Creator<ThoughtfulServiceBean> CREATOR = new Creator<ThoughtfulServiceBean>() {
|
||||
@@ -55,11 +60,17 @@ public class ThoughtfulServiceBean extends BaseBean implements Parcelable, Seria
|
||||
* 全参构造 - 手动配置所有服务状态
|
||||
* @param isEnableChargeTts 充电TTS服务开关
|
||||
* @param isEnableUsePowerTts 用电TTS服务开关
|
||||
* @param isEnableUseageTtsWithBattary 用电TTS加电量提醒开关
|
||||
* @param isEnableChargeTtsWithBattary 充电TTS加电量提醒开关
|
||||
*/
|
||||
public ThoughtfulServiceBean(boolean isEnableChargeTts, boolean isEnableUsePowerTts) {
|
||||
public ThoughtfulServiceBean(boolean isEnableChargeTts, boolean isEnableUsePowerTts,
|
||||
boolean isEnableUseageTtsWithBattary, boolean isEnableChargeTtsWithBattary) {
|
||||
this.isEnableChargeTts = isEnableChargeTts;
|
||||
this.isEnableUsePowerTts = isEnableUsePowerTts;
|
||||
LogUtils.d(TAG, "ThoughtfulServiceBean: 全参构造 | isEnableChargeTts=" + isEnableChargeTts + " | isEnableUsePowerTts=" + isEnableUsePowerTts);
|
||||
this.isEnableUseageTtsWithBattary = isEnableUseageTtsWithBattary;
|
||||
this.isEnableChargeTtsWithBattary = isEnableChargeTtsWithBattary;
|
||||
LogUtils.d(TAG, "ThoughtfulServiceBean: 全参构造 | 充电TTS=" + isEnableChargeTts + " | 用电TTS=" + isEnableUsePowerTts
|
||||
+ " | 用电TTS加电量=" + isEnableUseageTtsWithBattary + " | 充电TTS加电量=" + isEnableChargeTtsWithBattary);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,7 +79,11 @@ public class ThoughtfulServiceBean extends BaseBean implements Parcelable, Seria
|
||||
private ThoughtfulServiceBean(Parcel in) {
|
||||
this.isEnableChargeTts = in.readByte() != 0;
|
||||
this.isEnableUsePowerTts = in.readByte() != 0;
|
||||
LogUtils.d(TAG, "ThoughtfulServiceBean: Parcel构造解析完成 | isEnableChargeTts=" + isEnableChargeTts + " | isEnableUsePowerTts=" + isEnableUsePowerTts);
|
||||
// 新增字段反序列化
|
||||
this.isEnableUseageTtsWithBattary = in.readByte() != 0;
|
||||
this.isEnableChargeTtsWithBattary = in.readByte() != 0;
|
||||
LogUtils.d(TAG, "ThoughtfulServiceBean: Parcel构造解析完成 | 充电TTS=" + isEnableChargeTts + " | 用电TTS=" + isEnableUsePowerTts
|
||||
+ " | 用电TTS加电量=" + isEnableUseageTtsWithBattary + " | 充电TTS加电量=" + isEnableChargeTtsWithBattary);
|
||||
}
|
||||
|
||||
// ====================== Getter/Setter 方法区 (封装成员变量 统一访问) ======================
|
||||
@@ -90,6 +105,26 @@ public class ThoughtfulServiceBean extends BaseBean implements Parcelable, Seria
|
||||
this.isEnableUsePowerTts = isEnableUsePowerTts;
|
||||
}
|
||||
|
||||
// 新增 用电TTS加入电量提醒 Getter/Setter
|
||||
public boolean isEnableUseageTtsWithBattary() {
|
||||
return isEnableUseageTtsWithBattary;
|
||||
}
|
||||
|
||||
public void setIsEnableUseageTtsWithBattary(boolean isEnableUseageTtsWithBattary) {
|
||||
LogUtils.d(TAG, "setIsEnableUseageTtsWithBattary: 旧值=" + this.isEnableUseageTtsWithBattary + " | 新值=" + isEnableUseageTtsWithBattary);
|
||||
this.isEnableUseageTtsWithBattary = isEnableUseageTtsWithBattary;
|
||||
}
|
||||
|
||||
// 新增 充电TTS加入电量提醒 Getter/Setter
|
||||
public boolean isEnableChargeTtsWithBattary() {
|
||||
return isEnableChargeTtsWithBattary;
|
||||
}
|
||||
|
||||
public void setIsEnableChargeTtsWithBattary(boolean isEnableChargeTtsWithBattary) {
|
||||
LogUtils.d(TAG, "setIsEnableChargeTtsWithBattary: 旧值=" + this.isEnableChargeTtsWithBattary + " | 新值=" + isEnableChargeTtsWithBattary);
|
||||
this.isEnableChargeTtsWithBattary = isEnableChargeTtsWithBattary;
|
||||
}
|
||||
|
||||
// ====================== 重写父类 BaseBean 核心方法 (JSON序列化/反序列化 业务核心) ======================
|
||||
@Override
|
||||
public String getName() {
|
||||
@@ -106,6 +141,9 @@ public class ThoughtfulServiceBean extends BaseBean implements Parcelable, Seria
|
||||
super.writeThisToJsonWriter(jsonWriter);
|
||||
jsonWriter.name(JSON_FIELD_IS_ENABLE_CHARGE_TTS).value(this.isEnableChargeTts);
|
||||
jsonWriter.name(JSON_FIELD_IS_ENABLE_USE_POWER_TTS).value(this.isEnableUsePowerTts);
|
||||
// 新增字段JSON序列化
|
||||
jsonWriter.name(JSON_FIELD_IS_ENABLE_USAGE_TTS_WITH_BATTERY).value(this.isEnableUseageTtsWithBattary);
|
||||
jsonWriter.name(JSON_FIELD_IS_ENABLE_CHARGE_TTS_WITH_BATTERY).value(this.isEnableChargeTtsWithBattary);
|
||||
LogUtils.d(TAG, "writeThisToJsonWriter: JSON序列化完成,所有TTS服务状态已写入");
|
||||
}
|
||||
|
||||
@@ -124,6 +162,13 @@ public class ThoughtfulServiceBean extends BaseBean implements Parcelable, Seria
|
||||
break;
|
||||
case JSON_FIELD_IS_ENABLE_USE_POWER_TTS:
|
||||
bean.setIsEnableUsePowerTts(jsonReader.nextBoolean());
|
||||
break;
|
||||
// 新增字段反序列化
|
||||
case JSON_FIELD_IS_ENABLE_USAGE_TTS_WITH_BATTERY:
|
||||
bean.setIsEnableUseageTtsWithBattary(jsonReader.nextBoolean());
|
||||
break;
|
||||
case JSON_FIELD_IS_ENABLE_CHARGE_TTS_WITH_BATTERY:
|
||||
bean.setIsEnableChargeTtsWithBattary(jsonReader.nextBoolean());
|
||||
break;
|
||||
default:
|
||||
jsonReader.skipValue();
|
||||
@@ -149,6 +194,9 @@ public class ThoughtfulServiceBean extends BaseBean implements Parcelable, Seria
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeByte((byte) (isEnableChargeTts ? 1 : 0));
|
||||
dest.writeByte((byte) (isEnableUsePowerTts ? 1 : 0));
|
||||
// 新增字段Parcel序列化
|
||||
dest.writeByte((byte) (isEnableUseageTtsWithBattary ? 1 : 0));
|
||||
dest.writeByte((byte) (isEnableChargeTtsWithBattary ? 1 : 0));
|
||||
LogUtils.d(TAG, "writeToParcel: Parcel序列化完成,所有TTS服务状态已写入");
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.powerbell.App;
|
||||
import cc.winboll.studio.powerbell.models.AppConfigBean;
|
||||
import cc.winboll.studio.powerbell.models.ThoughtfulServiceBean;
|
||||
import cc.winboll.studio.powerbell.utils.AppConfigUtils;
|
||||
@@ -31,7 +32,7 @@ public class ThoughtfulService extends Service {
|
||||
*/
|
||||
public enum ServiceType {
|
||||
CHARGE_STATE, //充电状态服务
|
||||
DISCHARGE_STATE //放电状态服务
|
||||
DISCHARGE_STATE, //放电状态服务
|
||||
}
|
||||
|
||||
// ====================================== 对外公开静态启动函数【新增核心】入参Context + 枚举 ======================================
|
||||
@@ -95,7 +96,7 @@ public class ThoughtfulService extends Service {
|
||||
case DISCHARGE_STATE:
|
||||
// 执行【放电状态】对应的业务任务
|
||||
executeDischargeStateTask();
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
LogUtils.d(TAG, "【onStartCommand】未知的服务类型,不执行任何任务");
|
||||
break;
|
||||
@@ -129,10 +130,16 @@ public class ThoughtfulService extends Service {
|
||||
return;
|
||||
}
|
||||
|
||||
ThoughtfulServiceBean thoughtfulServiceBean = ThoughtfulServiceBean.loadBean(this, ThoughtfulServiceBean.class);
|
||||
if (thoughtfulServiceBean == null) {
|
||||
thoughtfulServiceBean = new ThoughtfulServiceBean();
|
||||
}
|
||||
|
||||
if (latestConfig.isEnableChargeReminder()) {
|
||||
int nChargeReminderValue = latestConfig.getChargeReminderValue();
|
||||
String szCurrentBattery = thoughtfulServiceBean.isEnableChargeTtsWithBattary()? String.format("现在电量为百分之%d。", App.sQuantityOfElectricity) : "";
|
||||
String szRemind = String.format("限量充电提醒已启用,限量值为百分之%d。", nChargeReminderValue);
|
||||
szRemind = szRemind + szRemind + szRemind;
|
||||
szRemind = szCurrentBattery + szRemind + szRemind + szRemind;
|
||||
TTSPlayService.startPlayTTS(this, szRemind);
|
||||
}
|
||||
}
|
||||
@@ -151,14 +158,22 @@ public class ThoughtfulService extends Service {
|
||||
LogUtils.e(TAG, "handleNotifyAppConfigUpdate() 终止 | 最新配置为空");
|
||||
return;
|
||||
}
|
||||
|
||||
ThoughtfulServiceBean thoughtfulServiceBean = ThoughtfulServiceBean.loadBean(this, ThoughtfulServiceBean.class);
|
||||
if (thoughtfulServiceBean == null) {
|
||||
thoughtfulServiceBean = new ThoughtfulServiceBean();
|
||||
}
|
||||
|
||||
if (latestConfig.isEnableUsageReminder()) {
|
||||
int nUsageReminderValue = latestConfig.getUsageReminderValue();
|
||||
String szRemind = String.format("电量不足提醒已启用,低电值为百分之%d。", nUsageReminderValue);
|
||||
String szCurrentBattery = thoughtfulServiceBean.isEnableUseageTtsWithBattary()? String.format("现在电量为百分之%d。", App.sQuantityOfElectricity) : "";
|
||||
String szRemind = szCurrentBattery + String.format("电量不足提醒已启用,低电值为百分之%d。", nUsageReminderValue);
|
||||
|
||||
//szRemind = szRemind + szRemind + szRemind;
|
||||
TTSPlayService.startPlayTTS(this, szRemind);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,14 @@
|
||||
android:text="用电提醒启用时的TTS贴心服务"
|
||||
android:onClick="onEnableUsePowerTts"
|
||||
android:id="@+id/activitysettingsCheckBox1"/>
|
||||
|
||||
|
||||
<CheckBox
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="用电TTS加入电量提醒"
|
||||
android:onClick="onEnableUseageTtsWithBattary"
|
||||
android:id="@+id/activitysettingsCheckBox3"/>
|
||||
|
||||
<CheckBox
|
||||
android:layout_width="wrap_content"
|
||||
@@ -68,6 +76,14 @@
|
||||
android:text="充电提醒启用时的TTS贴心服务"
|
||||
android:onClick="onEnableChargeTts"
|
||||
android:id="@+id/activitysettingsCheckBox2"/>
|
||||
|
||||
|
||||
<CheckBox
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="充电TTS加入电量提醒"
|
||||
android:onClick="onEnableChargeTtsWithBattary"
|
||||
android:id="@+id/activitysettingsCheckBox4"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user