新增:仅锁屏状态转发APP通知开关
This commit is contained in:
parent
0beec2953d
commit
60dde070b5
|
@ -163,7 +163,7 @@
|
|||
<action android:name="android.intent.action.PHONE_STATE" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<receiver android:name=".receiver.OnePixelReceiver" />
|
||||
<receiver android:name=".receiver.ScreenBroadcastReceiver" />
|
||||
|
||||
<service
|
||||
android:name=".service.FrontService"
|
||||
|
|
|
@ -118,8 +118,8 @@ public class MainActivity extends AppCompatActivity implements RefreshListView.I
|
|||
}
|
||||
}
|
||||
|
||||
//1像素透明Activity保活
|
||||
if (SettingUtil.getOnePixelActivity()) {
|
||||
//1像素透明Activity保活 or 仅锁屏状态转发APP通知
|
||||
if (SettingUtil.getOnePixelActivity() || SettingUtil.getSwitchNotUserPresent()) {
|
||||
try {
|
||||
onePixelManager = new OnePixelManager();
|
||||
onePixelManager.registerOnePixelReceiver(this);//注册广播接收者
|
||||
|
|
|
@ -40,6 +40,8 @@ public class MyApplication extends Application {
|
|||
public static boolean allowPrivacyPolicy = false;
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private static Context context;
|
||||
//是否已解锁
|
||||
public static boolean isUserPresent = true;
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context base) {
|
||||
|
|
|
@ -93,7 +93,7 @@ public class SettingActivity extends AppCompatActivity {
|
|||
//转发通话记录
|
||||
switchEnablePhone(findViewById(R.id.switch_enable_phone), findViewById(R.id.cbCallType1), findViewById(R.id.cbCallType2), findViewById(R.id.cbCallType3));
|
||||
//转发应用通知 & 自动关闭通知
|
||||
switchEnableAppNotify(findViewById(R.id.switch_enable_app_notify), findViewById(R.id.checkbox_cancel_app_notify));
|
||||
switchEnableAppNotify(findViewById(R.id.switch_enable_app_notify), findViewById(R.id.checkbox_cancel_app_notify), findViewById(R.id.checkbox_not_user_present));
|
||||
|
||||
//HttpServer
|
||||
switchEnableHttpServer(findViewById(R.id.switch_enable_http_server));
|
||||
|
@ -280,7 +280,7 @@ public class SettingActivity extends AppCompatActivity {
|
|||
|
||||
//转发应用通知 & 自动关闭通知
|
||||
@SuppressLint("UseSwitchCompatOrMaterialCode")
|
||||
private void switchEnableAppNotify(Switch switch_enable_app_notify, CheckBox checkbox_cancel_app_notify) {
|
||||
private void switchEnableAppNotify(Switch switch_enable_app_notify, CheckBox checkbox_cancel_app_notify, CheckBox checkbox_not_user_present) {
|
||||
final LinearLayout layout_cancel_app_notify = findViewById(R.id.layout_cancel_app_notify);
|
||||
boolean isEnable = SettingUtil.getSwitchEnableAppNotify();
|
||||
switch_enable_app_notify.setChecked(isEnable);
|
||||
|
@ -308,6 +308,20 @@ public class SettingActivity extends AppCompatActivity {
|
|||
SettingUtil.switchCancelAppNotify(isChecked);
|
||||
Log.d(TAG, "switchCancelAppNotify:" + isChecked);
|
||||
});
|
||||
|
||||
checkbox_not_user_present.setChecked(SettingUtil.getSwitchNotUserPresent());
|
||||
checkbox_not_user_present.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
SettingUtil.switchNotUserPresent(isChecked);
|
||||
Log.d(TAG, "switchNotUserPresent:" + isChecked);
|
||||
|
||||
//1像素透明Activity保活 or 仅锁屏状态转发APP通知
|
||||
OnePixelManager onePixelManager = new OnePixelManager();
|
||||
if (SettingUtil.getOnePixelActivity() || SettingUtil.getSwitchNotUserPresent()) {
|
||||
onePixelManager.registerOnePixelReceiver(this);//注册广播接收者
|
||||
} else {
|
||||
onePixelManager.unregisterOnePixelReceiver(this);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//请求通知使用权限
|
||||
|
@ -770,14 +784,15 @@ public class SettingActivity extends AppCompatActivity {
|
|||
|
||||
switch_one_pixel_activity.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
SettingUtil.switchOnePixelActivity(isChecked);
|
||||
Log.d(TAG, "onCheckedChanged:" + isChecked);
|
||||
|
||||
//1像素透明Activity保活 or 仅锁屏状态转发APP通知
|
||||
OnePixelManager onePixelManager = new OnePixelManager();
|
||||
if (isChecked) {
|
||||
if (SettingUtil.getOnePixelActivity() || SettingUtil.getSwitchNotUserPresent()) {
|
||||
onePixelManager.registerOnePixelReceiver(this);//注册广播接收者
|
||||
} else {
|
||||
onePixelManager.unregisterOnePixelReceiver(this);
|
||||
}
|
||||
Log.d(TAG, "onCheckedChanged:" + isChecked);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
package com.idormy.sms.forwarder.receiver;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.idormy.sms.forwarder.utils.OnePixelManager;
|
||||
|
||||
|
||||
public class OnePixelReceiver extends BroadcastReceiver {
|
||||
private static final String TAG = "OnePixelReceiver";
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
OnePixelManager manager = new OnePixelManager();
|
||||
if (Intent.ACTION_SCREEN_ON.equals(action)) {//如果亮屏,则关闭1像素Activity
|
||||
manager.finishOnePixelActivity();
|
||||
} else if (Intent.ACTION_SCREEN_OFF.equals(action)) {//如果息屏,则开启1像素Activity
|
||||
manager.startOnePixelActivity(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package com.idormy.sms.forwarder.receiver;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
import com.idormy.sms.forwarder.MyApplication;
|
||||
import com.idormy.sms.forwarder.utils.OnePixelManager;
|
||||
import com.idormy.sms.forwarder.utils.SettingUtil;
|
||||
|
||||
//监听屏幕状态变换广播(开屏、锁屏、解锁)
|
||||
public class ScreenBroadcastReceiver extends BroadcastReceiver {
|
||||
private static final String TAG = "ScreenBroadcastReceiver";
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
|
||||
//1像素透明Activity保活
|
||||
if (SettingUtil.getOnePixelActivity()) {
|
||||
OnePixelManager manager = new OnePixelManager();
|
||||
if (Intent.ACTION_SCREEN_ON.equals(action)) {//如果亮屏,则关闭1像素Activity
|
||||
manager.finishOnePixelActivity();
|
||||
} else if (Intent.ACTION_SCREEN_OFF.equals(action)) {//如果息屏,则开启1像素Activity
|
||||
manager.startOnePixelActivity(context);
|
||||
}
|
||||
}
|
||||
|
||||
//是否已解锁
|
||||
MyApplication.isUserPresent = Intent.ACTION_USER_PRESENT.equals(action);
|
||||
Log.d(TAG, String.format("isUserPresent=%s", MyApplication.isUserPresent));
|
||||
}
|
||||
}
|
||||
|
|
@ -42,6 +42,9 @@ public class NotifyService extends NotificationListenerService {
|
|||
if (sbn.getNotification() == null) return;
|
||||
if (sbn.getNotification().extras == null) return;
|
||||
|
||||
//仅锁屏状态转发APP通知
|
||||
if (SettingUtil.getSwitchNotUserPresent() && MyApplication.isUserPresent) return;
|
||||
|
||||
//推送通知的应用包名
|
||||
String packageName = sbn.getPackageName();
|
||||
//自身通知跳过
|
||||
|
|
|
@ -10,6 +10,7 @@ public class Define {
|
|||
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_NOT_USER_PRESENT = "tsms_msg_key_switch_not_user_present";
|
||||
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_ENABLE_PLAY_SILENCE_MUSIC = "tsms_msg_key_switch_enable_play_silence_music";
|
||||
public static final String SP_MSG_KEY_STRING_ENABLE_ONE_PIXEL_ACTIVITY = "tsms_msg_key_switch_enable_one_pixel_activity";
|
||||
|
|
|
@ -6,14 +6,14 @@ import android.content.Intent;
|
|||
import android.content.IntentFilter;
|
||||
|
||||
import com.idormy.sms.forwarder.OnePixelActivity;
|
||||
import com.idormy.sms.forwarder.receiver.OnePixelReceiver;
|
||||
import com.idormy.sms.forwarder.receiver.ScreenBroadcastReceiver;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
public class OnePixelManager {
|
||||
private static final String TAG = "OnePixelManager";
|
||||
private WeakReference<Activity> mActivity;
|
||||
private OnePixelReceiver onePixelReceiver;
|
||||
private ScreenBroadcastReceiver screenBroadcastReceiver;
|
||||
|
||||
/**
|
||||
* 一像素广播接收者注册方法。该方法中初始化OnePixelReceiver,并添加了过滤条件
|
||||
|
@ -24,16 +24,16 @@ public class OnePixelManager {
|
|||
filter.addAction(Intent.ACTION_SCREEN_OFF);
|
||||
filter.addAction(Intent.ACTION_SCREEN_ON);
|
||||
filter.addAction(Intent.ACTION_USER_PRESENT);
|
||||
onePixelReceiver = new OnePixelReceiver();
|
||||
context.registerReceiver(onePixelReceiver, filter);
|
||||
screenBroadcastReceiver = new ScreenBroadcastReceiver();
|
||||
context.registerReceiver(screenBroadcastReceiver, filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对广播接收者进行解注册
|
||||
*/
|
||||
public void unregisterOnePixelReceiver(Context context) {
|
||||
if (null != onePixelReceiver) {
|
||||
context.unregisterReceiver(onePixelReceiver);
|
||||
if (null != screenBroadcastReceiver) {
|
||||
context.unregisterReceiver(screenBroadcastReceiver);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -77,6 +77,14 @@ public class SettingUtil {
|
|||
return sp_setting.getBoolean(Define.SP_MSG_KEY_STRING_CANCEL_APP_NOTIFY, false);
|
||||
}
|
||||
|
||||
public static void switchNotUserPresent(Boolean enable) {
|
||||
sp_setting.edit().putBoolean(Define.SP_MSG_KEY_STRING_NOT_USER_PRESENT, enable).apply();
|
||||
}
|
||||
|
||||
public static boolean getSwitchNotUserPresent() {
|
||||
return sp_setting.getBoolean(Define.SP_MSG_KEY_STRING_NOT_USER_PRESENT, false);
|
||||
}
|
||||
|
||||
public static void switchEnableBatteryReceiver(Boolean enable) {
|
||||
sp_setting.edit().putBoolean(Define.SP_MSG_KEY_STRING_BATTERY_RECEIVER, enable).apply();
|
||||
}
|
||||
|
|
|
@ -222,6 +222,16 @@
|
|||
android:scaleX="0.7"
|
||||
android:scaleY="0.7"
|
||||
android:text="@string/cancel_app_notify" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/checkbox_not_user_present"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="-25dp"
|
||||
android:scaleX="0.7"
|
||||
android:scaleY="0.7"
|
||||
android:text="@string/not_user_present" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -189,6 +189,7 @@
|
|||
<string name="forward_app_notify">Forward app Ntf.</string>
|
||||
<string name="forward_app_notify_tips">Main switch, requires permission to read notification.</string>
|
||||
<string name="cancel_app_notify">Auto close Ntf.</string>
|
||||
<string name="not_user_present">Not User Present</string>
|
||||
<string name="enable_custom_templates">Global Custom Template</string>
|
||||
<string name="enable_custom_templates_tips">Priority: custom template for forwarding rules > Global custom template > System default</string>
|
||||
<string name="enable_regex_replace">Enable regular replacement content</string>
|
||||
|
|
|
@ -189,6 +189,7 @@
|
|||
<string name="forward_app_notify">转发应用通知</string>
|
||||
<string name="forward_app_notify_tips">请授予通知使用权再开启;开启“自动消除”可避免多条通知堆叠</string>
|
||||
<string name="cancel_app_notify">自动消除通知</string>
|
||||
<string name="not_user_present">仅锁屏状态</string>
|
||||
<string name="enable_custom_templates">启用自定义模版</string>
|
||||
<string name="enable_custom_templates_tips">优先级:转发规则的自定义模板 > 全局自定义模版 > 默认</string>
|
||||
<string name="enable_regex_replace">启用正则替换内容</string>
|
||||
|
|
Loading…
Reference in New Issue