From edb39867c174d5125d39357932e32302f8c2be7a Mon Sep 17 00:00:00 2001
From: pppscn <35696959@qq.com>
Date: Sat, 8 Jan 2022 14:20:57 +0800
Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=85=81=E8=AE=B8?=
=?UTF-8?q?=E5=BC=80=E5=90=AF=E8=87=AA=E5=8A=A8=E5=85=B3=E9=97=AD=E9=80=9A?=
=?UTF-8?q?=E7=9F=A5=EF=BC=88=E5=8D=95=E6=9D=A1=E9=80=9A=E7=9F=A5=E5=A4=84?=
=?UTF-8?q?=E7=90=86=E5=AE=8C=E6=AF=95=E5=90=8E=E8=87=AA=E5=8A=A8=E5=85=B3?=
=?UTF-8?q?=E9=97=AD=EF=BC=8C=E9=81=BF=E5=85=8D=E5=A4=9A=E6=9D=A1=E9=80=9A?=
=?UTF-8?q?=E7=9F=A5=E5=A0=86=E5=8F=A0=EF=BC=89?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../idormy/sms/forwarder/SettingActivity.java | 17 +++++--
.../sms/forwarder/service/NotifyService.java | 10 +++--
.../idormy/sms/forwarder/utils/Define.java | 1 +
.../sms/forwarder/utils/SettingUtil.java | 10 +++++
app/src/main/res/layout/activity_setting.xml | 44 +++++++++++++++++++
app/src/main/res/values-en/strings.xml | 2 +
app/src/main/res/values/strings.xml | 2 +
7 files changed, 80 insertions(+), 6 deletions(-)
diff --git a/app/src/main/java/com/idormy/sms/forwarder/SettingActivity.java b/app/src/main/java/com/idormy/sms/forwarder/SettingActivity.java
index 61bfc09f..ca07b181 100644
--- a/app/src/main/java/com/idormy/sms/forwarder/SettingActivity.java
+++ b/app/src/main/java/com/idormy/sms/forwarder/SettingActivity.java
@@ -75,7 +75,8 @@ public class SettingActivity extends AppCompatActivity {
switchEnablePhone(switch_enable_phone);
@SuppressLint("UseSwitchCompatOrMaterialCode") Switch switch_enable_app_notify = findViewById(R.id.switch_enable_app_notify);
- switchEnableAppNotify(switch_enable_app_notify);
+ @SuppressLint("UseSwitchCompatOrMaterialCode") Switch switch_cancel_app_notify = findViewById(R.id.switch_cancel_app_notify);
+ switchEnableAppNotify(switch_enable_app_notify, switch_cancel_app_notify);
@SuppressLint("UseSwitchCompatOrMaterialCode") Switch switch_exclude_from_recents = findViewById(R.id.switch_exclude_from_recents);
switchExcludeFromRecents(switch_exclude_from_recents);
@@ -121,10 +122,14 @@ public class SettingActivity extends AppCompatActivity {
}
//设置转发APP通知
- private void switchEnableAppNotify(@SuppressLint("UseSwitchCompatOrMaterialCode") Switch switch_enable_app_notify) {
- switch_enable_app_notify.setChecked(SettingUtil.getSwitchEnableAppNotify());
+ private void switchEnableAppNotify(@SuppressLint("UseSwitchCompatOrMaterialCode") Switch switch_enable_app_notify, @SuppressLint("UseSwitchCompatOrMaterialCode") Switch switch_cancel_app_notify) {
+ final LinearLayout layout_cancel_app_notify = findViewById(R.id.layout_cancel_app_notify);
+ boolean isEnable = SettingUtil.getSwitchEnableAppNotify();
+ switch_enable_app_notify.setChecked(isEnable);
+ layout_cancel_app_notify.setVisibility(isEnable ? View.VISIBLE : View.GONE);
switch_enable_app_notify.setOnCheckedChangeListener((buttonView, isChecked) -> {
+ layout_cancel_app_notify.setVisibility(isChecked ? View.VISIBLE : View.GONE);
//TODO:校验使用APP通知转发必备的权限
if (isChecked) {
if (!CommonUtil.isNotificationListenerServiceEnabled(this)) {
@@ -139,6 +144,12 @@ public class SettingActivity extends AppCompatActivity {
SettingUtil.switchEnableAppNotify(isChecked);
Log.d(TAG, "switchEnableAppNotify:" + isChecked);
});
+
+ switch_cancel_app_notify.setChecked(SettingUtil.getSwitchCancelAppNotify());
+ switch_cancel_app_notify.setOnCheckedChangeListener((buttonView, isChecked) -> {
+ SettingUtil.switchCancelAppNotify(isChecked);
+ Log.d(TAG, "switchCancelAppNotify:" + isChecked);
+ });
}
//不在最近任务列表中显示
diff --git a/app/src/main/java/com/idormy/sms/forwarder/service/NotifyService.java b/app/src/main/java/com/idormy/sms/forwarder/service/NotifyService.java
index 1866db15..41747a5f 100644
--- a/app/src/main/java/com/idormy/sms/forwarder/service/NotifyService.java
+++ b/app/src/main/java/com/idormy/sms/forwarder/service/NotifyService.java
@@ -66,6 +66,12 @@ public class NotifyService extends NotificationListenerService {
packageName, title, text, time)
);
+ //自动关闭通知
+ if (SettingUtil.getSwitchCancelAppNotify()) {
+ String key = sbn.getKey();
+ cancelNotification(key);
+ }
+
//重复通知不再处理
String prevHash = SettingUtil.getPrevNoticeHash(packageName);
String currHash = CommonUtil.MD5(packageName + title + text + time);
@@ -82,7 +88,7 @@ public class NotifyService extends NotificationListenerService {
} catch (Exception e) {
Log.e(TAG, "onNotificationPosted:", e);
}
- //NotifyHelper.getInstance().onReceive(sbn);
+
}
/**
@@ -98,8 +104,6 @@ public class NotifyService extends NotificationListenerService {
if (sbn.getNotification() == null) return;
Log.d(TAG, sbn.getPackageName());
-
- //NotifyHelper.getInstance().onRemoved(sbn);
}
/**
diff --git a/app/src/main/java/com/idormy/sms/forwarder/utils/Define.java b/app/src/main/java/com/idormy/sms/forwarder/utils/Define.java
index ef9de3ac..1241b916 100644
--- a/app/src/main/java/com/idormy/sms/forwarder/utils/Define.java
+++ b/app/src/main/java/com/idormy/sms/forwarder/utils/Define.java
@@ -9,6 +9,7 @@ public class Define {
public static final String SP_MSG_KEY_STRING_ENABLE_SMS = "tsms_msg_key_switch_enable_sms";
public static final String SP_MSG_KEY_STRING_ENABLE_PHONE = "tsms_msg_key_switch_enable_phone";
public static final String SP_MSG_KEY_STRING_ENABLE_APP_NOTIFY = "tsms_msg_key_switch_enable_app_notify";
+ public static final String SP_MSG_KEY_STRING_CANCEL_APP_NOTIFY = "tsms_msg_key_switch_cancel_app_notify";
public static final String SP_MSG_KEY_STRING_ENABLE_EXCLUDE_FROM_RECENTS = "tsms_msg_key_switch_enable_exclude_from_recents";
public static final String SP_MSG_KEY_STRING_ADD_EXTRA_DEVICE_MARK = "tsms_msg_key_string_add_extra_device_mark";
public static final String SP_MSG_KEY_STRING_ADD_EXTRA_SIM1 = "tsms_msg_key_string_add_extra_sim1";
diff --git a/app/src/main/java/com/idormy/sms/forwarder/utils/SettingUtil.java b/app/src/main/java/com/idormy/sms/forwarder/utils/SettingUtil.java
index b7fe0a29..4bf2442f 100644
--- a/app/src/main/java/com/idormy/sms/forwarder/utils/SettingUtil.java
+++ b/app/src/main/java/com/idormy/sms/forwarder/utils/SettingUtil.java
@@ -78,6 +78,16 @@ public class SettingUtil {
return sp_setting.getBoolean(Define.SP_MSG_KEY_STRING_ENABLE_APP_NOTIFY, false);
}
+ public static void switchCancelAppNotify(Boolean enable) {
+ sp_setting.edit()
+ .putBoolean(Define.SP_MSG_KEY_STRING_CANCEL_APP_NOTIFY, enable)
+ .apply();
+ }
+
+ public static boolean getSwitchCancelAppNotify() {
+ return sp_setting.getBoolean(Define.SP_MSG_KEY_STRING_CANCEL_APP_NOTIFY, true);
+ }
+
public static void switchEnableBatteryReceiver(Boolean enable) {
sp_setting.edit()
.putBoolean(Define.SP_MSG_KEY_STRING_BATTERY_RECEIVER, enable)
diff --git a/app/src/main/res/layout/activity_setting.xml b/app/src/main/res/layout/activity_setting.xml
index d38726da..35f5d654 100644
--- a/app/src/main/res/layout/activity_setting.xml
+++ b/app/src/main/res/layout/activity_setting.xml
@@ -250,6 +250,50 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
Main switch, requires permissions to read call log and contacts.
Forward app notify
Main switch, requires permission to read notification.
+ Auto cancel app notify
+ After a single notification is processed, it is automatically disabled to avoid multiple notification stacking
Global custom template
Priority: custom template for forwarding rules > Global custom template > System default
Enable regular replacement content
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index d65a4525..3cceee33 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -169,6 +169,8 @@
总开关,请授予读取通话记录、联系人等权限
转发应用通知
总开关,请先授予通知使用权
+ 自动关闭通知
+ 单条通知处理完毕后,自动关闭,避免多条通知堆叠
启用自定义模版
优先级:转发规则的自定义模板 > 全局自定义模版 > 默认
启用正则替换内容