mirror of
https://github.com/pppscn/SmsForwarder
synced 2025-08-03 01:17:41 +08:00
新增:不在最近任务列表中显示(有利于保活?)
This commit is contained in:
parent
37ecb346a9
commit
64f6ec1369
@ -1,9 +1,12 @@
|
||||
package com.idormy.sms.forwarder;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.ActivityManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
@ -22,6 +25,7 @@ import com.idormy.sms.forwarder.service.NotifyService;
|
||||
import com.idormy.sms.forwarder.utils.KeepAliveUtils;
|
||||
import com.idormy.sms.forwarder.utils.SettingUtil;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class SettingActivity extends AppCompatActivity {
|
||||
@ -71,6 +75,9 @@ public class SettingActivity extends AppCompatActivity {
|
||||
@SuppressLint("UseSwitchCompatOrMaterialCode") Switch switch_enable_app_notify = findViewById(R.id.switch_enable_app_notify);
|
||||
switchEnableAppNotify(switch_enable_app_notify);
|
||||
|
||||
@SuppressLint("UseSwitchCompatOrMaterialCode") Switch switch_exclude_from_recents = findViewById(R.id.switch_exclude_from_recents);
|
||||
switchExcludeFromRecents(switch_exclude_from_recents);
|
||||
|
||||
EditText textSmsTemplate = findViewById(R.id.text_sms_template);
|
||||
editSmsTemplate(textSmsTemplate);
|
||||
}
|
||||
@ -105,6 +112,26 @@ public class SettingActivity extends AppCompatActivity {
|
||||
});
|
||||
}
|
||||
|
||||
//不在最近任务列表中显示
|
||||
@SuppressLint("ObsoleteSdkInt")
|
||||
private void switchExcludeFromRecents(Switch switch_exclude_from_recents) {
|
||||
switch_exclude_from_recents.setChecked(SettingUtil.getExcludeFromRecents());
|
||||
|
||||
switch_exclude_from_recents.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
SettingUtil.switchExcludeFromRecents(isChecked);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
ActivityManager am = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
|
||||
if (am != null) {
|
||||
List<ActivityManager.AppTask> appTasks = am.getAppTasks();
|
||||
if (appTasks != null && !appTasks.isEmpty()) {
|
||||
appTasks.get(0).setExcludeFromRecents(isChecked);
|
||||
}
|
||||
}
|
||||
}
|
||||
Log.d(TAG, "onCheckedChanged:" + isChecked);
|
||||
});
|
||||
}
|
||||
|
||||
//设置设备名称
|
||||
private void editAddExtraDeviceMark(final EditText et_add_extra_device_mark) {
|
||||
et_add_extra_device_mark.setText(SettingUtil.getAddExtraDeviceMark());
|
||||
@ -196,7 +223,6 @@ public class SettingActivity extends AppCompatActivity {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//接口请求失败重试
|
||||
private void editRetryDelayTime(final EditText et_retry_delay_time, final int index) {
|
||||
et_retry_delay_time.setText(String.valueOf(SettingUtil.getRetryDelayTime(index)));
|
||||
@ -314,6 +340,7 @@ public class SettingActivity extends AppCompatActivity {
|
||||
|
||||
}
|
||||
|
||||
//电池优化设置
|
||||
public void batterySetting(View view) {
|
||||
if (KeepAliveUtils.isIgnoreBatteryOptimization(this)) {
|
||||
Toast.makeText(this, R.string.isIgnored, Toast.LENGTH_SHORT).show();
|
||||
@ -322,12 +349,12 @@ public class SettingActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 请求权限
|
||||
*
|
||||
* @param view 控件
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public void requestPermission(View view) {
|
||||
if (!isNLServiceEnabled()) {
|
||||
Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
|
||||
@ -360,7 +387,6 @@ public class SettingActivity extends AppCompatActivity {
|
||||
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
@ -374,7 +400,6 @@ public class SettingActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void showMsg(String msg) {
|
||||
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
@ -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_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";
|
||||
public static final String SP_MSG_KEY_STRING_ADD_EXTRA_SIM2 = "tsms_msg_key_string_add_extra_sim2";
|
||||
|
@ -73,7 +73,17 @@ public class SettingUtil {
|
||||
}
|
||||
|
||||
public static boolean getSwitchEnableAppNotify() {
|
||||
return sp_setting.getBoolean(Define.SP_MSG_KEY_STRING_ENABLE_APP_NOTIFY, true);
|
||||
return sp_setting.getBoolean(Define.SP_MSG_KEY_STRING_ENABLE_APP_NOTIFY, false);
|
||||
}
|
||||
|
||||
public static void switchExcludeFromRecents(Boolean enable) {
|
||||
sp_setting.edit()
|
||||
.putBoolean(Define.SP_MSG_KEY_STRING_ENABLE_EXCLUDE_FROM_RECENTS, enable)
|
||||
.apply();
|
||||
}
|
||||
|
||||
public static boolean getExcludeFromRecents() {
|
||||
return sp_setting.getBoolean(Define.SP_MSG_KEY_STRING_ENABLE_EXCLUDE_FROM_RECENTS, false);
|
||||
}
|
||||
|
||||
public static void switchSmsTemplate(Boolean switchSmsTemplate) {
|
||||
|
@ -349,6 +349,33 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="2dp"
|
||||
android:background="@android:color/white"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:padding="15dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="3"
|
||||
android:text="@string/enable_exclude_from_recents"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<Switch
|
||||
android:id="@+id/switch_exclude_from_recents"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="3"
|
||||
android:gravity="end"
|
||||
android:textSize="18sp"
|
||||
tools:ignore="UseSwitchCompatOrMaterialXml" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@ -415,7 +442,7 @@
|
||||
android:gravity="left|top"
|
||||
android:minLines="1"
|
||||
android:text=""
|
||||
tools:ignore="LabelFor" />
|
||||
tools:ignore="LabelFor,RtlHardcoded" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
@ -432,7 +459,7 @@
|
||||
android:background="@color/colorPrimary"
|
||||
android:onClick="toInsertLabel"
|
||||
android:text="@string/insert_sender"
|
||||
tools:ignore="ButtonStyle,NestedWeights" />
|
||||
tools:ignore="ButtonStyle,NestedWeights,UsingOnClickInXml" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/bt_insert_content"
|
||||
@ -445,7 +472,7 @@
|
||||
android:background="@color/colorPrimary"
|
||||
android:onClick="toInsertLabel"
|
||||
android:text="@string/insert_content"
|
||||
tools:ignore="ButtonStyle,NestedWeights" />
|
||||
tools:ignore="ButtonStyle,NestedWeights,UsingOnClickInXml" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/bt_insert_extra"
|
||||
@ -458,7 +485,7 @@
|
||||
android:background="@color/colorPrimary"
|
||||
android:onClick="toInsertLabel"
|
||||
android:text="@string/insert_extra"
|
||||
tools:ignore="ButtonStyle,NestedWeights" />
|
||||
tools:ignore="ButtonStyle,NestedWeights,UsingOnClickInXml" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/bt_insert_time"
|
||||
@ -471,7 +498,7 @@
|
||||
android:background="@color/colorPrimary"
|
||||
android:onClick="toInsertLabel"
|
||||
android:text="@string/insert_time"
|
||||
tools:ignore="ButtonStyle,NestedWeights" />
|
||||
tools:ignore="ButtonStyle,NestedWeights,UsingOnClickInXml" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/bt_insert_device_name"
|
||||
@ -484,7 +511,7 @@
|
||||
android:background="@color/colorPrimary"
|
||||
android:onClick="toInsertLabel"
|
||||
android:text="@string/insert_device_name"
|
||||
tools:ignore="ButtonStyle,NestedWeights" />
|
||||
tools:ignore="ButtonStyle,NestedWeights,UsingOnClickInXml" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@ -506,7 +533,7 @@
|
||||
android:background="@color/colorPrimary"
|
||||
android:onClick="batterySetting"
|
||||
android:text="@string/battery_setting"
|
||||
tools:ignore="ButtonStyle,NestedWeights" />
|
||||
tools:ignore="ButtonStyle,NestedWeights,UsingOnClickInXml" />
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
@ -516,7 +543,7 @@
|
||||
android:background="@color/colorPrimary"
|
||||
android:onClick="requestPermission"
|
||||
android:text="@string/request_permission"
|
||||
tools:ignore="ButtonStyle,NestedWeights" />
|
||||
tools:ignore="ButtonStyle,NestedWeights,UsingOnClickInXml" />
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
@ -526,7 +553,7 @@
|
||||
android:background="@color/colorBlueGreyDark"
|
||||
android:onClick="initSetting"
|
||||
android:text="@string/init_setting"
|
||||
tools:ignore="ButtonStyle,NestedWeights" />
|
||||
tools:ignore="ButtonStyle,NestedWeights,UsingOnClickInXml" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
@ -158,6 +158,7 @@
|
||||
<string name="forward_missed_calls">Forward missed calls</string>
|
||||
<string name="forward_app_notify">Forward app notify</string>
|
||||
<string name="enable_custom_templates">Enable custom templates</string>
|
||||
<string name="enable_exclude_from_recents">Exclude from recents</string>
|
||||
<string name="custom_templates">Custom templates</string>
|
||||
<string name="custom_templates_tips">Tip:Insert labels as needed;Leave blank to default template</string>
|
||||
<string name="insert_sender">Phone</string>
|
||||
|
@ -158,6 +158,7 @@
|
||||
<string name="forward_missed_calls">转发未接来电</string>
|
||||
<string name="forward_app_notify">转发APP通知</string>
|
||||
<string name="enable_custom_templates">启用自定义模版</string>
|
||||
<string name="enable_exclude_from_recents">不在最近任务列表中显示</string>
|
||||
<string name="custom_templates">转发信息模版</string>
|
||||
<string name="custom_templates_tips">Tip:按需插入内容标签;留空使用默认模版</string>
|
||||
<string name="insert_sender">来源号码</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user