重新梳理代码

This commit is contained in:
pppscn 2021-09-29 00:23:44 +08:00
parent 99718c0b5e
commit c2d2beb8ef
95 changed files with 2129 additions and 1816 deletions

3
.gitignore vendored
View File

@ -3,6 +3,7 @@
.git
build
local.properties
gradle.properties
*.iml
*.project
*/*.project
@ -11,4 +12,6 @@ local.properties
.settings/*
*/.settings/*
/app/pppscn.jks
/app/release/*
/app/build/*
/psd

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "keystore"]
path = keystore
url = https://github.com/pppscn/keystore.git

View File

@ -1,10 +1,21 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
//apply plugin: 'kotlin-android-extensions'
apply from: 'version.gradle'
def keyProps = new Properties()
def keyPropsFile = rootProject.file('keystore/keystore.properties')
if (keyPropsFile.exists()) {
keyProps.load(new FileInputStream(keyPropsFile))
}
// version.properties
def versionProps = new Properties()
def versionPropsFile = rootProject.file('version.properties')
if (versionPropsFile.exists()) {
versionProps.load(new FileInputStream(versionPropsFile))
}
android {
compileSdkVersion 29
buildToolsVersion '30.0.3'
compileSdkVersion 30
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
@ -12,74 +23,115 @@ android {
defaultConfig {
applicationId "com.idormy.sms.forwarder"
minSdkVersion 23
targetSdkVersion 29
versionCode appVersionCode
versionName appVersionName
targetSdkVersion 30
versionCode versionProps['versionCode'].toInteger()
versionName versionProps['versionName']
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
lintOptions {
checkReleaseBuilds false
}
signingConfigs {
// C:\Users\<Username>\.gradle\gradle.properties
release {
storeFile file(RELEASE_STORE_FILE)
keyAlias RELEASE_KEY_ALIAS
storePassword RELEASE_KEY_PASSWORD
keyPassword RELEASE_STORE_PASSWORD
keyAlias keyProps['keyAlias']
keyPassword keyProps['keyPassword']
storeFile keyProps['storeFile'] ? file(keyProps['storeFile']) : null
storePassword keyProps['storePassword']
}
debug {
keyAlias keyProps['keyAlias']
keyPassword keyProps['keyPassword']
storeFile keyProps['storeFile'] ? file(keyProps['storeFile']) : null
storePassword keyProps['storePassword']
}
}
buildTypes {
release {
minifyEnabled false
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
debug {
signingConfig signingConfigs.release
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.debug
}
}
//apk file name
android.applicationVariants.all { variant ->
/* android.applicationVariants.all { variant ->
variant.outputs.all {
//def date = new Date().format("yyyyMMdd" , TimeZone.getTimeZone("Asia/Shanghai"))
def date = new Date().format("yyyyMMdd", TimeZone.getTimeZone("GMT+08"))
if (variant.buildType.name.equals('debug')) {
if (variant.buildType.name == 'debug') {
outputFileName = "SmsForwarder_debug_${date}_${versionName}.apk"
}
if (variant.buildType.name.equals('release')) {
if (variant.buildType.name == 'release') {
outputFileName = "SmsForwarder_release_${date}_${versionName}.apk"
}
}
}*/
}
task upgradeVersion {
group 'help'
description '构建新版本'
doLast {
println("---自动升级版本号---\n")
String oldVersionCode = versionProps['versionCode']
String oldVersionName = versionProps['versionName']
if (oldVersionCode == null || oldVersionName == null ||
oldVersionCode.isEmpty() || oldVersionName.isEmpty()) {
println("error:版本号不能为空")
return
}
versionProps['versionCode'] = String.valueOf(versionProps['versionCode'].toInteger() + 1)
String str = versionProps['versionName'].toString()
versionProps['versionName'] = str.substring(0, str.lastIndexOf('.') + 1) +
(str.substring(str.lastIndexOf('.') + 1).toInteger() + 1)
String tip =
"版本号从$oldVersionName($oldVersionCode)升级到${versionProps['versionName']}(${versionProps['versionCode']})"
println(tip)
def writer = new FileWriter(versionPropsFile)
versionProps.store(writer, null)
writer.flush()
writer.close()
def tag = "v${versionProps['versionName']}"
cmdExecute("git pull")
cmdExecute("git add version.properties")
cmdExecute("git commit -m \"版本号升级为:$tag\"")
cmdExecute("git push origin")
cmdExecute("git tag $tag")
cmdExecute("git push origin $tag")
}
}
void cmdExecute(String cmd) {
println "\n执行$cmd"
println cmd.execute().text
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
//testImplementation 'junit:junit:4.12'
//androidTestImplementation 'androidx.test.ext:junit:1.1.1'
//androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
//okhttp
implementation 'com.squareup.okhttp3:okhttp:4.9.0'
implementation 'com.squareup.okhttp3:okhttp:4.9.1'
implementation 'com.squareup.okio:okio:2.10.0'
//fastjson
implementation "com.alibaba:fastjson:1.2.75"
//android8.0使api和动态代理隐藏的抽象类回调
//使ProxyBuilder类
//implementation 'com.linkedin.dexmaker:dexmaker-mockito:2.12.1'
implementation "com.alibaba:fastjson:1.2.78"
// SDK
implementation 'com.umeng.umsdk:common:9.4.4'//
implementation 'com.umeng.umsdk:asms:1.4.1'//
implementation 'com.umeng.umsdk:apm:1.4.2' // SDKcrash数据请一定集成
implementation 'com.umeng.umsdk:abtest:1.0.0'//使U-App中ABTest能力
//XUpdate
implementation 'com.github.xuexiangjys:XUpdate:2.1.0'
@ -88,8 +140,6 @@ dependencies {
//EmailKit
implementation 'com.github.mailhu:emailkit:4.2.2'
implementation 'androidx.test.ext:junit-ktx:1.1.2'
testImplementation 'junit:junit:4.12'
//Lombok
compileOnly 'org.projectlombok:lombok:1.18.20'

View File

@ -19,3 +19,4 @@
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
-keep class com.idormy.sms.forwarder.model.**{*;}

View File

@ -16,7 +16,7 @@ class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getTargetContext()
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.idormy.sms.forwarder", appContext.packageName)
}
}

View File

@ -2,6 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.idormy.sms.forwarder">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<!-- 授予应用程序访问系统开机事件的权限 -->
@ -10,16 +11,21 @@
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_NUMBERS" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<!--Android 9API 级别 28或更高版本并使用前台服务则其必须请求 FOREGROUND_SERVICE 权限-->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<uses-permission android:name="android.permission.BATTERY_STATS"
<uses-permission
android:name="android.permission.BATTERY_STATS"
tools:ignore="ProtectedPermissions" />
<application
@ -31,7 +37,8 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
android:usesCleartextTraffic="true"
android:fullBackupContent="@xml/backup_descriptor">
<meta-data
android:name="UPDATE_APP_KEY"
@ -43,16 +50,20 @@
android:name="UMENG_CHANNEL"
android:value="Umeng" />
<activity android:name=".MainActivity">
<activity
android:name=".MainActivity"
tools:ignore="IntentFilterExportedReceiver">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<!--协议部分,随便设置-->
<data android:scheme="forwarder" android:host="main"/>
<data
android:scheme="forwarder"
android:host="main" />
<!--下面这几行也必须得设置-->
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
<activity
@ -68,21 +79,34 @@
android:name=".SenderActivity"
android:label="发送方" />
<receiver android:name=".BroadCastReceiver.RebootBroadcastReceiver">
<receiver
android:name=".receiver.RebootBroadcastReceiver"
tools:ignore="IntentFilterExportedReceiver">
<intent-filter android:priority="2147483647">
<!--重启广播-->
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<receiver
android:name=".BroadCastReceiver.SmsForwarderBroadcastReceiver"
android:permission="android.permission.BROADCAST_SMS">
android:name=".receiver.SmsForwarderBroadcastReceiver"
android:permission="android.permission.BROADCAST_SMS"
tools:ignore="IntentFilterExportedReceiver">
<intent-filter android:priority="2147483647">
<!--短信广播-->
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
<receiver
android:name=".receiver.PhoneStateReceiver"
tools:ignore="IntentFilterExportedReceiver">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
<service android:name=".service.FrontService" />
<service android:name=".service.BatteryService" />
</application>
</manifest>

View File

@ -1,5 +1,6 @@
package com.idormy.sms.forwarder;
import android.annotation.SuppressLint;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@ -8,16 +9,14 @@ import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.idormy.sms.forwarder.BroadCastReceiver.RebootBroadcastReceiver;
import com.idormy.sms.forwarder.receiver.RebootBroadcastReceiver;
import com.idormy.sms.forwarder.utils.CacheUtil;
import com.idormy.sms.forwarder.utils.Define;
import com.idormy.sms.forwarder.utils.aUtil;
@ -25,13 +24,14 @@ import com.xuexiang.xupdate.easy.EasyUpdate;
import com.xuexiang.xupdate.proxy.impl.DefaultUpdateChecker;
@SuppressWarnings("SpellCheckingInspection")
public class AboutActivity extends AppCompatActivity {
private String TAG = "com.idormy.sms.forwarder.AboutActivity";
private final String TAG = "com.idormy.sms.forwarder.AboutActivity";
private Context context;
@Override
public void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "oncreate");
Log.d(TAG, "onCreate");
super.onCreate(savedInstanceState);
context = AboutActivity.this;
@ -39,138 +39,112 @@ public class AboutActivity extends AppCompatActivity {
setContentView(R.layout.activity_about);
Log.d(TAG, "onCreate: " + RebootBroadcastReceiver.class.getName());
Switch check_with_reboot = (Switch) findViewById(R.id.switch_with_reboot);
@SuppressLint("UseSwitchCompatOrMaterialCode") Switch check_with_reboot = findViewById(R.id.switch_with_reboot);
checkWithReboot(check_with_reboot);
Switch switch_help_tip = (Switch) findViewById(R.id.switch_help_tip);
@SuppressLint("UseSwitchCompatOrMaterialCode") Switch switch_help_tip = findViewById(R.id.switch_help_tip);
SwitchHelpTip(switch_help_tip);
final TextView version_now = (TextView) findViewById(R.id.version_now);
Button check_version_now = (Button) findViewById(R.id.check_version_now);
final TextView version_now = findViewById(R.id.version_now);
Button check_version_now = findViewById(R.id.check_version_now);
try {
version_now.setText(aUtil.getVersionName(AboutActivity.this));
} catch (Exception e) {
e.printStackTrace();
}
check_version_now.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//checkNewVersion();
try {
String updateUrl = "https://xupdate.bms.ink/update/checkVersion?appKey=com.idormy.sms.forwarder&versionCode=";
updateUrl += aUtil.getVersionCode(AboutActivity.this);
check_version_now.setOnClickListener(v -> {
try {
String updateUrl = "https://xupdate.bms.ink/update/checkVersion?appKey=com.idormy.sms.forwarder&versionCode=";
updateUrl += aUtil.getVersionCode(AboutActivity.this);
EasyUpdate.create(AboutActivity.this, updateUrl)
.updateChecker(new DefaultUpdateChecker() {
@Override
public void onBeforeCheck() {
super.onBeforeCheck();
Toast.makeText(AboutActivity.this, "查询中...", Toast.LENGTH_LONG).show();
}
EasyUpdate.create(AboutActivity.this, updateUrl)
.updateChecker(new DefaultUpdateChecker() {
@Override
public void onBeforeCheck() {
super.onBeforeCheck();
Toast.makeText(AboutActivity.this, "查询中...", Toast.LENGTH_LONG).show();
}
@Override
public void onAfterCheck() {
super.onAfterCheck();
}
@Override
public void noNewVersion(Throwable throwable) {
super.noNewVersion(throwable);
// 没有最新版本的处理
Toast.makeText(AboutActivity.this, "已是最新版本!", Toast.LENGTH_LONG).show();
}
})
.update();
} catch (Exception e) {
e.printStackTrace();
}
@Override
public void noNewVersion(Throwable throwable) {
super.noNewVersion(throwable);
// 没有最新版本的处理
Toast.makeText(AboutActivity.this, "已是最新版本!", Toast.LENGTH_LONG).show();
}
})
.update();
} catch (Exception e) {
e.printStackTrace();
}
});
final TextView cache_size = (TextView) findViewById(R.id.cache_size);
final TextView cache_size = findViewById(R.id.cache_size);
try {
cache_size.setText(CacheUtil.getTotalCacheSize(AboutActivity.this));
} catch (Exception e) {
e.printStackTrace();
}
Button clear_all_cache = (Button) findViewById(R.id.clear_all_cache);
clear_all_cache.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CacheUtil.clearAllCache(AboutActivity.this);
try {
cache_size.setText(CacheUtil.getTotalCacheSize(AboutActivity.this));
} catch (Exception e) {
e.printStackTrace();
}
Toast.makeText(AboutActivity.this, "缓存清理完成", Toast.LENGTH_LONG).show();
Button clear_all_cache = findViewById(R.id.clear_all_cache);
clear_all_cache.setOnClickListener(v -> {
CacheUtil.clearAllCache(AboutActivity.this);
try {
cache_size.setText(CacheUtil.getTotalCacheSize(AboutActivity.this));
} catch (Exception e) {
e.printStackTrace();
}
Toast.makeText(AboutActivity.this, "缓存清理完成", Toast.LENGTH_LONG).show();
});
Button join_qq_group = (Button) findViewById(R.id.join_qq_group);
join_qq_group.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String key = "HvroJRfvK7GGfnQgaIQ4Rh1un9O83N7M";
joinQQGroup(key);
}
Button join_qq_group = findViewById(R.id.join_qq_group);
join_qq_group.setOnClickListener(v -> {
String key = "HvroJRfvK7GGfnQgaIQ4Rh1un9O83N7M";
joinQQGroup(key);
});
}
//检查重启广播接受器状态并设置
private void checkWithReboot(Switch withrebootSwitch) {
private void checkWithReboot(@SuppressLint("UseSwitchCompatOrMaterialCode") Switch withrebootSwitch) {
//获取组件
final ComponentName cm = new ComponentName(this.getPackageName(), RebootBroadcastReceiver.class.getName());
final PackageManager pm = getPackageManager();
int state = pm.getComponentEnabledSetting(cm);
if (state != PackageManager.COMPONENT_ENABLED_STATE_DISABLED
&& state != PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) {
withrebootSwitch.setChecked(true);
} else {
withrebootSwitch.setChecked(false);
}
withrebootSwitch.setOnCheckedChangeListener(new Switch.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
int newState = (Boolean) isChecked ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
: PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
pm.setComponentEnabledSetting(cm, newState, PackageManager.DONT_KILL_APP);
Log.d(TAG, "onCheckedChanged:" + isChecked);
}
withrebootSwitch.setChecked(state != PackageManager.COMPONENT_ENABLED_STATE_DISABLED
&& state != PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER);
withrebootSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
int newState = isChecked ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
: PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
pm.setComponentEnabledSetting(cm, newState, PackageManager.DONT_KILL_APP);
Log.d(TAG, "onCheckedChanged:" + isChecked);
});
}
//页面帮助提示
private void SwitchHelpTip(Switch switchHelpTip) {
private void SwitchHelpTip(@SuppressLint("UseSwitchCompatOrMaterialCode") Switch switchHelpTip) {
switchHelpTip.setChecked(MyApplication.showHelpTip);
switchHelpTip.setOnCheckedChangeListener(new Switch.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
MyApplication.showHelpTip = isChecked;
SharedPreferences sp = context.getSharedPreferences(Define.SP_CONFIG, Context.MODE_PRIVATE);
sp.edit().putBoolean(Define.SP_CONFIG_SWITCH_HELP_TIP, isChecked).apply();
Log.d(TAG, "onCheckedChanged:" + isChecked);
}
switchHelpTip.setOnCheckedChangeListener((buttonView, isChecked) -> {
MyApplication.showHelpTip = isChecked;
SharedPreferences sp = context.getSharedPreferences(Define.SP_CONFIG, Context.MODE_PRIVATE);
sp.edit().putBoolean(Define.SP_CONFIG_SWITCH_HELP_TIP, isChecked).apply();
Log.d(TAG, "onCheckedChanged:" + isChecked);
});
}
//发起添加群流程
public boolean joinQQGroup(String key) {
public void joinQQGroup(String key) {
Intent intent = new Intent();
intent.setData(Uri.parse("mqqopensdkapi://bizAgent/qm/qr?url=http%3A%2F%2Fqm.qq.com%2Fcgi-bin%2Fqm%2Fqr%3Ffrom%3Dapp%26p%3Dandroid%26jump_from%3Dwebapi%26k%3D" + key));
// 此Flag可根据具体产品需要自定义如设置则在加群界面按返回返回手Q主界面不设置按返回会返回到呼起产品界面
//intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
try {
startActivity(intent);
return true;
} catch (Exception e) {
// 未安装手Q或安装的版本不支持
Toast.makeText(AboutActivity.this, "未安装手Q或安装的版本不支持", Toast.LENGTH_LONG).show();
return false;
}
}

View File

@ -1,27 +1,21 @@
package com.idormy.sms.forwarder;
import android.content.ComponentName;
import android.content.DialogInterface;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import com.idormy.sms.forwarder.BroadCastReceiver.SmsForwarderBroadcastReceiver;
import com.idormy.sms.forwarder.adapter.LogAdapter;
import com.idormy.sms.forwarder.model.vo.LogVo;
import com.idormy.sms.forwarder.utils.LogUtil;
@ -29,30 +23,13 @@ import com.idormy.sms.forwarder.utils.NetUtil;
import com.idormy.sms.forwarder.utils.PhoneUtils;
import com.idormy.sms.forwarder.utils.SmsUtil;
import com.idormy.sms.forwarder.utils.aUtil;
import com.umeng.analytics.MobclickAgent;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity implements ReFlashListView.IReflashListener {
public class MainActivity extends AppCompatActivity implements ReFlashListView.IRefreshListener {
ServiceConnection conn = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
// TODO Auto-generated method stub
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
// 当service绑定成功时会调用次方法可以在此申请权限
PackageManager pm = getPackageManager();
PhoneUtils.CheckPermission(pm, MainActivity.this);
}
};
private IntentFilter intentFilter;
private SmsForwarderBroadcastReceiver smsBroadcastReceiver;
private String TAG = "MainActivity";
private final String TAG = "MainActivity";
// logVoList用于存储数据
private List<LogVo> logVos = new ArrayList<>();
private LogAdapter adapter;
@ -62,7 +39,7 @@ public class MainActivity extends AppCompatActivity implements ReFlashListView.I
protected void onCreate(Bundle savedInstanceState) {
LogUtil.init(this);
Log.d(TAG, "oncreate");
Log.d(TAG, "onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
@ -94,52 +71,50 @@ public class MainActivity extends AppCompatActivity implements ReFlashListView.I
// 为ListView注册一个监听器当用户点击了ListView中的任何一个子项时就会回调onItemClick()方法
// 在这个方法中可以通过position参数判断出用户点击的是那一个子项
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (position <= 0) return;
listView.setOnItemClickListener((parent, view, position, id) -> {
if (position <= 0) return;
LogVo logVo = logVos.get(position - 1);
logDetail(logVo);
}
LogVo logVo = logVos.get(position - 1);
logDetail(logVo);
});
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
if (position <= 0) return false;
listView.setOnItemLongClickListener((parent, view, position, id) -> {
if (position <= 0) return false;
//定义AlertDialog.Builder对象当长按列表项的时候弹出确认删除对话框
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setMessage("确定删除?");
builder.setTitle("提示");
//定义AlertDialog.Builder对象当长按列表项的时候弹出确认删除对话框
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setMessage("确定删除?");
builder.setTitle("提示");
//添加AlertDialog.Builder对象的setPositiveButton()方法
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Long id = logVos.get(position - 1).getId();
Log.d(TAG, "id = " + id);
LogUtil.delLog(id, null);
initTLogs(); //初始化数据
showList(logVos);
Toast.makeText(getBaseContext(), "删除列表项", Toast.LENGTH_SHORT).show();
}
});
//添加AlertDialog.Builder对象的setPositiveButton()方法
builder.setPositiveButton("确定", (dialog, which) -> {
Long id1 = logVos.get(position - 1).getId();
Log.d(TAG, "id = " + id1);
LogUtil.delLog(id1, null);
initTLogs(); //初始化数据
showList(logVos);
Toast.makeText(getBaseContext(), "删除列表项", Toast.LENGTH_SHORT).show();
});
//添加AlertDialog.Builder对象的setNegativeButton()方法
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
//添加AlertDialog.Builder对象的setNegativeButton()方法
builder.setNegativeButton("取消", (dialog, which) -> {
});
builder.create().show();
return true;
}
builder.create().show();
return true;
});
}
@Override
protected void onResume() {
super.onResume();
//第一次打开未授权无法获取SIM信息尝试在此重新获取
if (MyApplication.SimInfoList.isEmpty()) {
MyApplication.SimInfoList = PhoneUtils.getSimMultiInfo();
}
Log.d(TAG, "SimInfoList = " + MyApplication.SimInfoList.size());
}
// 初始化数据
private void initTLogs() {
logVos = LogUtil.getLog(null, null);
@ -160,35 +135,19 @@ public class MainActivity extends AppCompatActivity implements ReFlashListView.I
}
@Override
public void onReflash() {
public void onRefresh() {
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
//获取最新数据
initTLogs();
//通知界面显示
showList(logVos);
//通知listview 刷新数据完毕
listView.reflashComplete();
}
handler.postDelayed(() -> {
// TODO Auto-generated method stub
//获取最新数据
initTLogs();
//通知界面显示
showList(logVos);
//通知listview 刷新数据完毕
listView.refreshComplete();
}, 2000);
}
@Override
protected void onDestroy() {
Log.d(TAG, "onDestroy");
super.onDestroy();
//取消注册广播
try {
if (smsBroadcastReceiver != null)
unregisterReceiver(smsBroadcastReceiver);
} catch (Exception e) {
Log.e(TAG, "unregisterReceiver fail:" + e.getMessage());
}
}
public void logDetail(LogVo logVo) {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
@ -200,29 +159,22 @@ public class MainActivity extends AppCompatActivity implements ReFlashListView.I
builder.setMessage(logVo.getFrom() + "\n\n" + logVo.getContent() + "\n\n" + logVo.getRule() + "\n\n" + aUtil.utc2Local(logVo.getTime()) + "\n\nResponse" + logVo.getForwardResponse());
}
//重发
builder.setPositiveButton("重发", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
System.out.println(logVo.toString());
Long id = logVo.getId();
Log.d(TAG, "id = " + id);
Log.d(TAG, logVo.toString());
Toast.makeText(MainActivity.this, "你确定要重发吗?", Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
builder.setPositiveButton("重发", (dialog, which) -> {
Long id = logVo.getId();
Log.d(TAG, "id = " + id);
Log.d(TAG, logVo.toString());
Toast.makeText(MainActivity.this, "你确定要重发吗?", Toast.LENGTH_SHORT).show();
dialog.dismiss();
});
//删除
builder.setNegativeButton("删除", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Long id = logVo.getId();
Log.d(TAG, "id = " + id);
LogUtil.delLog(id, null);
initTLogs(); //初始化数据
showList(logVos);
Toast.makeText(MainActivity.this, "已删除该条记录", Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
builder.setNegativeButton("删除", (dialog, which) -> {
Long id = logVo.getId();
Log.d(TAG, "id = " + id);
LogUtil.delLog(id, null);
initTLogs(); //初始化数据
showList(logVos);
Toast.makeText(MainActivity.this, "已删除该条记录", Toast.LENGTH_SHORT).show();
dialog.dismiss();
});
builder.show();
}
@ -250,16 +202,11 @@ public class MainActivity extends AppCompatActivity implements ReFlashListView.I
public void cleanLog(View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("确定要清空转发记录吗?")
.setPositiveButton("清空", new DialogInterface.OnClickListener() {// 积极
@Override
public void onClick(DialogInterface dialog,
int which) {
// TODO Auto-generated method stub
LogUtil.delLog(null, null);
initTLogs();
adapter.add(logVos);
}
.setPositiveButton("清空", (dialog, which) -> {
// TODO Auto-generated method stub
LogUtil.delLog(null, null);
initTLogs();
adapter.add(logVos);
});
builder.show();
}
@ -273,6 +220,7 @@ public class MainActivity extends AppCompatActivity implements ReFlashListView.I
startActivity(intent);
}
@SuppressLint("NonConstantResourceId")
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
@ -296,21 +244,4 @@ public class MainActivity extends AppCompatActivity implements ReFlashListView.I
}
@Override
protected void onResume() {
super.onResume();
MobclickAgent.onResume(this);
//第一次打开申请权限前无法获取SIM信息尝试在此重新获取
if (MyApplication.SimInfoList.isEmpty()) {
MyApplication.SimInfoList = PhoneUtils.getSimMultiInfo();
}
Log.d(TAG, "SimInfoList = " + MyApplication.SimInfoList.size());
}
@Override
protected void onPause() {
super.onPause();
MobclickAgent.onPause(this);
}
}

View File

@ -38,8 +38,8 @@ public class MyApplication extends Application {
* android:value="Umeng">
* </meta-data>
*
* @param ctx
* @return
* @param ctx 上下文
* @return 渠道名称
*/
// 获取渠道工具函数
public static String getChannelName(Context ctx) {
@ -52,10 +52,8 @@ public class MyApplication extends Application {
if (packageManager != null) {
//注意此处为ApplicationInfo 而不是 ActivityInfo,因为友盟设置的meta-data是在application标签中而不是activity标签中所以用ApplicationInfo
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(ctx.getPackageName(), PackageManager.GET_META_DATA);
if (applicationInfo != null) {
if (applicationInfo.metaData != null) {
channelName = applicationInfo.metaData.get("UMENG_CHANNEL") + "";
}
if (applicationInfo.metaData != null) {
channelName = applicationInfo.metaData.get("UMENG_CHANNEL") + "";
}
}
} catch (PackageManager.NameNotFoundException e) {
@ -84,7 +82,7 @@ public class MyApplication extends Application {
MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.LEGACY_MANUAL);
//pro close log
UMConfigure.setLogEnabled(true);
Log.i(TAG, "uminit");
Intent intent = new Intent(this, FrontService.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(intent);

View File

@ -1,5 +1,6 @@
package com.idormy.sms.forwarder;
import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
@ -20,11 +21,12 @@ import java.util.Locale;
/**
* 自定义listview
*/
@SuppressWarnings({"CommentedOutCode", "unused"})
public class ReFlashListView extends ListView implements AbsListView.OnScrollListener {
private static final String TAG = "ReFlashListView";
//private static final String TAG = "ReFlashListView";
final int NONE = 0;// 正常状态
final int PULL = 1;// 提示下拉状态
final int RELESE = 2;// 提示释放状态
final int RELEASE = 2;// 提示释放状态
final int REFLASHING = 3;// 刷新状态
View header;// 顶部布局文件
int headerHeight;// 顶部布局文件的高度
@ -33,7 +35,7 @@ public class ReFlashListView extends ListView implements AbsListView.OnScrollLis
boolean isRemark;// 标记当前是在listview最顶端摁下的
int startY;// 摁下时的Y值
int state;// 当前的状态
IReflashListener iReflashListener;//刷新数据的接口
IRefreshListener iRefreshListener;//刷新数据的接口
public ReFlashListView(Context context) {
super(context);
@ -55,9 +57,8 @@ public class ReFlashListView extends ListView implements AbsListView.OnScrollLis
/**
* 初始化界面添加顶部布局文件到 listview
*
* @param context
*/
@SuppressLint("InflateParams")
private void initView(Context context) {
LayoutInflater inflater = LayoutInflater.from(context);
header = inflater.inflate(R.layout.header, null);
@ -71,8 +72,6 @@ public class ReFlashListView extends ListView implements AbsListView.OnScrollLis
/**
* 通知父布局占用的宽
*
* @param view
*/
private void measureView(View view) {
ViewGroup.LayoutParams p = view.getLayoutParams();
@ -94,8 +93,6 @@ public class ReFlashListView extends ListView implements AbsListView.OnScrollLis
/**
* 设置header 布局 上边距
*
* @param topPadding
*/
private void topPadding(int topPadding) {
header.setPadding(header.getPaddingLeft(), topPadding,
@ -116,6 +113,7 @@ public class ReFlashListView extends ListView implements AbsListView.OnScrollLis
this.scrollState = scrollState;
}
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent ev) {
// TODO Auto-generated method stub
@ -131,23 +129,23 @@ public class ReFlashListView extends ListView implements AbsListView.OnScrollLis
onMove(ev);
break;
case MotionEvent.ACTION_UP:
if (state == RELESE || state == PULL) {
if (state == RELEASE || state == PULL) {
state = REFLASHING;
// 加载最新数据
reflashViewByState();
iReflashListener.onReflash();
refreshViewByState();
iRefreshListener.onRefresh();
}
// if (state == RELESE) {
// if (state == RELEASE) {
// Log.d(TAG, "onTouchEvent: up release");
// state = REFLASHING;
// // 加载最新数据
// reflashViewByState();
// iReflashListener.onReflash();
// refreshViewByState();
// iRefreshListener.onRefresh();
// } else if (state == PULL) {
// Log.d(TAG, "onTouchEvent: up pull");
// state = NONE;
// isRemark = false;
// reflashViewByState();
// refreshViewByState();
// }
break;
}
@ -156,8 +154,6 @@ public class ReFlashListView extends ListView implements AbsListView.OnScrollLis
/**
* 判断移动过程操作
*
* @param ev
*/
private void onMove(MotionEvent ev) {
if (!isRemark) {
@ -170,26 +166,26 @@ public class ReFlashListView extends ListView implements AbsListView.OnScrollLis
case NONE:
if (space > 0) {
state = PULL;
reflashViewByState();
refreshViewByState();
}
break;
case PULL:
topPadding(topPadding);
if (space > headerHeight + 30
&& scrollState == SCROLL_STATE_TOUCH_SCROLL) {
state = RELESE;
reflashViewByState();
state = RELEASE;
refreshViewByState();
}
break;
case RELESE:
case RELEASE:
topPadding(topPadding);
if (space < headerHeight + 30) {
state = PULL;
reflashViewByState();
refreshViewByState();
} else if (space <= 0) {
state = NONE;
isRemark = false;
reflashViewByState();
refreshViewByState();
}
break;
}
@ -198,10 +194,10 @@ public class ReFlashListView extends ListView implements AbsListView.OnScrollLis
/**
* 根据当前状态改变界面显示
*/
private void reflashViewByState() {
TextView tip = (TextView) header.findViewById(R.id.tip);
ImageView arrow = (ImageView) header.findViewById(R.id.arrow);
ProgressBar progress = (ProgressBar) header.findViewById(R.id.progress);
private void refreshViewByState() {
TextView tip = header.findViewById(R.id.tip);
ImageView arrow = header.findViewById(R.id.arrow);
ProgressBar progress = header.findViewById(R.id.progress);
RotateAnimation anim = new RotateAnimation(0, 180,
RotateAnimation.RELATIVE_TO_SELF, 0.5f,
RotateAnimation.RELATIVE_TO_SELF, 0.5f);
@ -225,7 +221,7 @@ public class ReFlashListView extends ListView implements AbsListView.OnScrollLis
arrow.clearAnimation();
arrow.setAnimation(anim1);
break;
case RELESE:
case RELEASE:
arrow.setVisibility(View.VISIBLE);
progress.setVisibility(View.GONE);
tip.setText("松开可以刷新!");
@ -245,19 +241,19 @@ public class ReFlashListView extends ListView implements AbsListView.OnScrollLis
/**
* 获取完数据
*/
public void reflashComplete() {
public void refreshComplete() {
state = NONE;
isRemark = false;
reflashViewByState();
TextView lastupdatetime = (TextView) header
.findViewById(R.id.lastupdate_time);
refreshViewByState();
TextView lastUpdateTime = header
.findViewById(R.id.lastUpdateTime);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
String time = sdf.format(new java.util.Date());
lastupdatetime.setText(time);
lastUpdateTime.setText(time);
}
public void setInterface(IReflashListener iReflashListener) {
this.iReflashListener = iReflashListener;
public void setInterface(IRefreshListener iRefreshListener) {
this.iRefreshListener = iRefreshListener;
}
/**
@ -265,7 +261,7 @@ public class ReFlashListView extends ListView implements AbsListView.OnScrollLis
*
* @author Administrator
*/
public interface IReflashListener {
public void onReflash();
public interface IRefreshListener {
void onRefresh();
}
}

View File

@ -1,18 +1,17 @@
package com.idormy.sms.forwarder;
import static com.idormy.sms.forwarder.SenderActivity.NOTIFY;
import android.annotation.SuppressLint;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
@ -34,32 +33,28 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import static com.idormy.sms.forwarder.SenderActivity.NOTIFY;
@SuppressWarnings("deprecation")
public class RuleActivity extends AppCompatActivity {
private String TAG = "RuleActivity";
private final String TAG = "RuleActivity";
// 用于存储数据
private List<RuleModel> ruleModels = new ArrayList<>();
private RuleAdapter adapter;
private Long selectSenderId = 0l;
private String selectSenderName = "";
//消息处理者,创建一个Handler的子类对象,目的是重写Handler的处理消息的方法(handleMessage())
private Handler handler = new Handler() {
@SuppressLint("HandlerLeak")
private final Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case NOTIFY:
Toast.makeText(RuleActivity.this, msg.getData().getString("DATA"), Toast.LENGTH_LONG).show();
break;
if (msg.what == NOTIFY) {
Toast.makeText(RuleActivity.this, msg.getData().getString("DATA"), Toast.LENGTH_LONG).show();
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "oncreate");
Log.d(TAG, "onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rule);
RuleUtil.init(RuleActivity.this);
@ -85,46 +80,33 @@ public class RuleActivity extends AppCompatActivity {
// 为ListView注册一个监听器当用户点击了ListView中的任何一个子项时就会回调onItemClick()方法
// 在这个方法中可以通过position参数判断出用户点击的是那一个子项
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
RuleModel ruleModel = ruleModels.get(position);
Log.d(TAG, "onItemClick: " + ruleModel);
setRule(ruleModel);
}
listView.setOnItemClickListener((parent, view, position, id) -> {
RuleModel ruleModel = ruleModels.get(position);
Log.d(TAG, "onItemClick: " + ruleModel);
setRule(ruleModel);
});
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
//定义AlertDialog.Builder对象当长按列表项的时候弹出确认删除对话框
AlertDialog.Builder builder = new AlertDialog.Builder(RuleActivity.this);
listView.setOnItemLongClickListener((parent, view, position, id) -> {
//定义AlertDialog.Builder对象当长按列表项的时候弹出确认删除对话框
AlertDialog.Builder builder = new AlertDialog.Builder(RuleActivity.this);
builder.setMessage("确定删除?");
builder.setTitle("提示");
builder.setMessage("确定删除?");
builder.setTitle("提示");
//添加AlertDialog.Builder对象的setPositiveButton()方法
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
RuleUtil.delRule(ruleModels.get(position).getId());
initRules();
adapter.del(ruleModels);
Toast.makeText(getBaseContext(), "删除列表项", Toast.LENGTH_SHORT).show();
}
});
//添加AlertDialog.Builder对象的setPositiveButton()方法
builder.setPositiveButton("确定", (dialog, which) -> {
RuleUtil.delRule(ruleModels.get(position).getId());
initRules();
adapter.del(ruleModels);
Toast.makeText(getBaseContext(), "删除列表项", Toast.LENGTH_SHORT).show();
});
//添加AlertDialog.Builder对象的setNegativeButton()方法
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
//添加AlertDialog.Builder对象的setNegativeButton()方法
builder.setNegativeButton("取消", (dialog, which) -> {
@Override
public void onClick(DialogInterface dialog, int which) {
});
}
});
builder.create().show();
return true;
}
builder.create().show();
return true;
});
}
@ -141,11 +123,11 @@ public class RuleActivity extends AppCompatActivity {
final AlertDialog.Builder alertDialog71 = new AlertDialog.Builder(RuleActivity.this);
final View view1 = View.inflate(RuleActivity.this, R.layout.alert_dialog_setview_rule, null);
final RadioGroup radioGroupRuleFiled = (RadioGroup) view1.findViewById(R.id.radioGroupRuleFiled);
final RadioGroup radioGroupRuleFiled = view1.findViewById(R.id.radioGroupRuleFiled);
if (ruleModel != null) radioGroupRuleFiled.check(ruleModel.getRuleFiledCheckId());
final RadioGroup radioGroupRuleCheck = (RadioGroup) view1.findViewById(R.id.radioGroupRuleCheck);
final RadioGroup radioGroupRuleCheck2 = (RadioGroup) view1.findViewById(R.id.radioGroupRuleCheck2);
final RadioGroup radioGroupRuleCheck = view1.findViewById(R.id.radioGroupRuleCheck);
final RadioGroup radioGroupRuleCheck2 = view1.findViewById(R.id.radioGroupRuleCheck2);
if (ruleModel != null) {
int ruleCheckCheckId = ruleModel.getRuleCheckCheckId();
if (ruleCheckCheckId == R.id.btnIs || ruleCheckCheckId == R.id.btnNotContain || ruleCheckCheckId == R.id.btnContain) {
@ -157,25 +139,22 @@ public class RuleActivity extends AppCompatActivity {
radioGroupRuleCheck.check(R.id.btnIs);
}
final RadioGroup radioGroupSimSlot = (RadioGroup) view1.findViewById(R.id.radioGroupSimSlot);
final RadioGroup radioGroupSimSlot = view1.findViewById(R.id.radioGroupSimSlot);
if (ruleModel != null) radioGroupSimSlot.check(ruleModel.getRuleSimSlotCheckId());
final TextView tv_mu_rule_tips = (TextView) view1.findViewById(R.id.tv_mu_rule_tips);
final TextView ruleSenderTv = (TextView) view1.findViewById(R.id.ruleSenderTv);
final TextView tv_mu_rule_tips = view1.findViewById(R.id.tv_mu_rule_tips);
final TextView ruleSenderTv = view1.findViewById(R.id.ruleSenderTv);
if (ruleModel != null && ruleModel.getSenderId() != null) {
List<SenderModel> getSeners = SenderUtil.getSender(ruleModel.getSenderId(), null);
if (!getSeners.isEmpty()) {
ruleSenderTv.setText(getSeners.get(0).getName());
ruleSenderTv.setTag(getSeners.get(0).getId());
List<SenderModel> getSenders = SenderUtil.getSender(ruleModel.getSenderId(), null);
if (!getSenders.isEmpty()) {
ruleSenderTv.setText(getSenders.get(0).getName());
ruleSenderTv.setTag(getSenders.get(0).getId());
}
}
final Button btSetRuleSender = (Button) view1.findViewById(R.id.btSetRuleSender);
btSetRuleSender.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Toast.makeText(RuleActivity.this, "selectSender", Toast.LENGTH_LONG).show();
selectSender(ruleSenderTv);
}
final Button btSetRuleSender = view1.findViewById(R.id.btSetRuleSender);
btSetRuleSender.setOnClickListener(view -> {
//Toast.makeText(RuleActivity.this, "selectSender", Toast.LENGTH_LONG).show();
selectSender(ruleSenderTv);
});
final EditText editTextRuleValue = view1.findViewById(R.id.editTextRuleValue);
@ -183,92 +162,83 @@ public class RuleActivity extends AppCompatActivity {
editTextRuleValue.setText(ruleModel.getValue());
//当更新选择的字段的时候更新之下各个选项的状态
final LinearLayout matchTypeLayout = (LinearLayout) view1.findViewById(R.id.matchTypeLayout);
final LinearLayout matchValueLayout = (LinearLayout) view1.findViewById(R.id.matchValueLayout);
final LinearLayout matchTypeLayout = view1.findViewById(R.id.matchTypeLayout);
final LinearLayout matchValueLayout = view1.findViewById(R.id.matchValueLayout);
refreshSelectRadioGroupRuleFiled(radioGroupRuleFiled, radioGroupRuleCheck, radioGroupRuleCheck2, editTextRuleValue, tv_mu_rule_tips, matchTypeLayout, matchValueLayout);
Button buttonruleok = view1.findViewById(R.id.buttonruleok);
Button buttonruledel = view1.findViewById(R.id.buttonruledel);
Button buttonruletest = view1.findViewById(R.id.buttonruletest);
Button buttonRuleOk = view1.findViewById(R.id.buttonRuleOk);
Button buttonRuleDel = view1.findViewById(R.id.buttonRuleDel);
Button buttonRuleTest = view1.findViewById(R.id.buttonRuleTest);
alertDialog71
.setTitle(R.string.setrule)
//.setIcon(R.drawable.ic_sms_forwarder)
.setView(view1)
.create();
final AlertDialog show = alertDialog71.show();
buttonruleok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Object senderId = ruleSenderTv.getTag();
buttonRuleOk.setOnClickListener(view -> {
Object senderId = ruleSenderTv.getTag();
int radioGroupRuleCheckId = Math.max(radioGroupRuleCheck.getCheckedRadioButtonId(), radioGroupRuleCheck2.getCheckedRadioButtonId());
Log.d(TAG, radioGroupRuleCheck.getCheckedRadioButtonId() + " " + radioGroupRuleCheck2.getCheckedRadioButtonId() + " " + radioGroupRuleCheckId);
if (ruleModel == null) {
RuleModel newRuleModel = new RuleModel();
newRuleModel.setFiled(RuleModel.getRuleFiledFromCheckId(radioGroupRuleFiled.getCheckedRadioButtonId()));
newRuleModel.setCheck(RuleModel.getRuleCheckFromCheckId(radioGroupRuleCheckId));
newRuleModel.setSimSlot(RuleModel.getRuleSimSlotFromCheckId(radioGroupSimSlot.getCheckedRadioButtonId()));
newRuleModel.setValue(editTextRuleValue.getText().toString());
if (senderId != null) {
newRuleModel.setSenderId(Long.valueOf(senderId.toString()));
}
RuleUtil.addRule(newRuleModel);
initRules();
adapter.add(ruleModels);
} else {
ruleModel.setFiled(RuleModel.getRuleFiledFromCheckId(radioGroupRuleFiled.getCheckedRadioButtonId()));
ruleModel.setCheck(RuleModel.getRuleCheckFromCheckId(radioGroupRuleCheckId));
ruleModel.setSimSlot(RuleModel.getRuleSimSlotFromCheckId(radioGroupSimSlot.getCheckedRadioButtonId()));
ruleModel.setValue(editTextRuleValue.getText().toString());
if (senderId != null) {
ruleModel.setSenderId(Long.valueOf(senderId.toString()));
}
RuleUtil.updateRule(ruleModel);
initRules();
adapter.update(ruleModels);
}
show.dismiss();
});
buttonRuleDel.setOnClickListener(view -> {
if (ruleModel != null) {
RuleUtil.delRule(ruleModel.getId());
initRules();
adapter.del(ruleModels);
}
show.dismiss();
});
buttonRuleTest.setOnClickListener(view -> {
Object senderId = ruleSenderTv.getTag();
if (senderId == null) {
Toast.makeText(RuleActivity.this, "请先创建选择发送方", Toast.LENGTH_LONG).show();
} else {
int radioGroupRuleCheckId = Math.max(radioGroupRuleCheck.getCheckedRadioButtonId(), radioGroupRuleCheck2.getCheckedRadioButtonId());
Log.d(TAG, "XXXX " + radioGroupRuleCheck.getCheckedRadioButtonId() + " " + radioGroupRuleCheck2.getCheckedRadioButtonId() + " " + radioGroupRuleCheckId);
if (ruleModel == null) {
RuleModel newRuleModel = new RuleModel();
newRuleModel.setFiled(RuleModel.getRuleFiledFromCheckId(radioGroupRuleFiled.getCheckedRadioButtonId()));
newRuleModel.setCheck(RuleModel.getRuleCheckFromCheckId(radioGroupRuleCheckId));
newRuleModel.setSimSlot(RuleModel.getRuleSimSlotFromCheckId(radioGroupSimSlot.getCheckedRadioButtonId()));
newRuleModel.setValue(editTextRuleValue.getText().toString());
if (senderId != null) {
newRuleModel.setSenderId(Long.valueOf(senderId.toString()));
}
RuleUtil.addRule(newRuleModel);
initRules();
adapter.add(ruleModels);
newRuleModel.setSenderId(Long.valueOf(senderId.toString()));
testRule(newRuleModel, Long.valueOf(senderId.toString()));
} else {
ruleModel.setFiled(RuleModel.getRuleFiledFromCheckId(radioGroupRuleFiled.getCheckedRadioButtonId()));
ruleModel.setCheck(RuleModel.getRuleCheckFromCheckId(radioGroupRuleCheckId));
ruleModel.setSimSlot(RuleModel.getRuleSimSlotFromCheckId(radioGroupSimSlot.getCheckedRadioButtonId()));
ruleModel.setValue(editTextRuleValue.getText().toString());
if (senderId != null) {
ruleModel.setSenderId(Long.valueOf(senderId.toString()));
}
RuleUtil.updateRule(ruleModel);
initRules();
adapter.update(ruleModels);
}
ruleModel.setSenderId(Long.valueOf(senderId.toString()));
show.dismiss();
}
});
buttonruledel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (ruleModel != null) {
RuleUtil.delRule(ruleModel.getId());
initRules();
adapter.del(ruleModels);
}
show.dismiss();
}
});
buttonruletest.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Object senderId = ruleSenderTv.getTag();
if (senderId == null) {
Toast.makeText(RuleActivity.this, "请先创建选择发送方", Toast.LENGTH_LONG).show();
} else {
int radioGroupRuleCheckId = Math.max(radioGroupRuleCheck.getCheckedRadioButtonId(), radioGroupRuleCheck2.getCheckedRadioButtonId());
if (ruleModel == null) {
RuleModel newRuleModel = new RuleModel();
newRuleModel.setFiled(RuleModel.getRuleFiledFromCheckId(radioGroupRuleFiled.getCheckedRadioButtonId()));
newRuleModel.setCheck(RuleModel.getRuleCheckFromCheckId(radioGroupRuleCheckId));
newRuleModel.setSimSlot(RuleModel.getRuleSimSlotFromCheckId(radioGroupSimSlot.getCheckedRadioButtonId()));
newRuleModel.setValue(editTextRuleValue.getText().toString());
newRuleModel.setSenderId(Long.valueOf(senderId.toString()));
testRule(newRuleModel, Long.valueOf(senderId.toString()));
} else {
ruleModel.setFiled(RuleModel.getRuleFiledFromCheckId(radioGroupRuleFiled.getCheckedRadioButtonId()));
ruleModel.setCheck(RuleModel.getRuleCheckFromCheckId(radioGroupRuleCheckId));
ruleModel.setSimSlot(RuleModel.getRuleSimSlotFromCheckId(radioGroupSimSlot.getCheckedRadioButtonId()));
ruleModel.setValue(editTextRuleValue.getText().toString());
ruleModel.setSenderId(Long.valueOf(senderId.toString()));
testRule(ruleModel, Long.valueOf(senderId.toString()));
}
testRule(ruleModel, Long.valueOf(senderId.toString()));
}
}
});
@ -281,53 +251,43 @@ public class RuleActivity extends AppCompatActivity {
private void refreshSelectRadioGroupRuleFiled(RadioGroup radioGroupRuleFiled, final RadioGroup radioGroupRuleCheck, final RadioGroup radioGroupRuleCheck2, final EditText editTextRuleValue, final TextView tv_mu_rule_tips, final LinearLayout matchTypeLayout, final LinearLayout matchValueLayout) {
refreshSelectRadioGroupRuleFiledAction(radioGroupRuleFiled.getCheckedRadioButtonId(), radioGroupRuleCheck, radioGroupRuleCheck2, editTextRuleValue, tv_mu_rule_tips, matchTypeLayout, matchValueLayout);
radioGroupRuleCheck.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@SuppressLint("ResourceType")
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
Log.d(TAG, String.valueOf(group));
Log.d(TAG, String.valueOf(checkedId));
if (group != null && checkedId > 0) {
if (group == radioGroupRuleCheck) {
radioGroupRuleCheck2.clearCheck();
} else if (group == radioGroupRuleCheck2) {
radioGroupRuleCheck.clearCheck();
}
group.check(checkedId);
}
}
});
radioGroupRuleCheck2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@SuppressLint("ResourceType")
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
Log.d(TAG, String.valueOf(group));
Log.d(TAG, String.valueOf(checkedId));
if (group != null && checkedId > 0) {
if (group == radioGroupRuleCheck) {
radioGroupRuleCheck2.clearCheck();
} else if (group == radioGroupRuleCheck2) {
radioGroupRuleCheck.clearCheck();
}
group.check(checkedId);
}
}
});
radioGroupRuleFiled.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
Log.d(TAG, String.valueOf(group));
Log.d(TAG, String.valueOf(checkedId));
radioGroupRuleCheck.setOnCheckedChangeListener((group, checkedId) -> {
Log.d(TAG, String.valueOf(group));
Log.d(TAG, String.valueOf(checkedId));
if (group != null && checkedId > 0) {
if (group == radioGroupRuleCheck) {
radioGroupRuleCheck2.clearCheck();
} else if (group == radioGroupRuleCheck2) {
radioGroupRuleCheck.clearCheck();
}
refreshSelectRadioGroupRuleFiledAction(checkedId, radioGroupRuleCheck, radioGroupRuleCheck2, editTextRuleValue, tv_mu_rule_tips, matchTypeLayout, matchValueLayout);
group.check(checkedId);
}
});
radioGroupRuleCheck2.setOnCheckedChangeListener((group, checkedId) -> {
Log.d(TAG, String.valueOf(group));
Log.d(TAG, String.valueOf(checkedId));
if (group != null && checkedId > 0) {
if (group == radioGroupRuleCheck) {
radioGroupRuleCheck2.clearCheck();
} else if (group == radioGroupRuleCheck2) {
radioGroupRuleCheck.clearCheck();
}
group.check(checkedId);
}
});
radioGroupRuleFiled.setOnCheckedChangeListener((group, checkedId) -> {
Log.d(TAG, String.valueOf(group));
Log.d(TAG, String.valueOf(checkedId));
if (group == radioGroupRuleCheck) {
radioGroupRuleCheck2.clearCheck();
} else if (group == radioGroupRuleCheck2) {
radioGroupRuleCheck.clearCheck();
}
refreshSelectRadioGroupRuleFiledAction(checkedId, radioGroupRuleCheck, radioGroupRuleCheck2, editTextRuleValue, tv_mu_rule_tips, matchTypeLayout, matchValueLayout);
});
}
@SuppressLint("NonConstantResourceId")
private void refreshSelectRadioGroupRuleFiledAction(int checkedRuleFiledId, final RadioGroup radioGroupRuleCheck, final RadioGroup radioGroupRuleCheck2, final EditText editTextRuleValue, final TextView tv_mu_rule_tips, final LinearLayout matchTypeLayout, final LinearLayout matchValueLayout) {
tv_mu_rule_tips.setVisibility(View.GONE);
matchTypeLayout.setVisibility(View.VISIBLE);
@ -336,10 +296,10 @@ public class RuleActivity extends AppCompatActivity {
switch (checkedRuleFiledId) {
case R.id.btnTranspondAll:
for (int i = 0; i < radioGroupRuleCheck.getChildCount(); i++) {
((RadioButton) radioGroupRuleCheck.getChildAt(i)).setEnabled(false);
radioGroupRuleCheck.getChildAt(i).setEnabled(false);
}
for (int i = 0; i < radioGroupRuleCheck2.getChildCount(); i++) {
((RadioButton) radioGroupRuleCheck2.getChildAt(i)).setEnabled(false);
radioGroupRuleCheck2.getChildAt(i).setEnabled(false);
}
editTextRuleValue.setEnabled(false);
matchTypeLayout.setVisibility(View.GONE);
@ -347,10 +307,10 @@ public class RuleActivity extends AppCompatActivity {
break;
case R.id.btnMultiMatch:
for (int i = 0; i < radioGroupRuleCheck.getChildCount(); i++) {
((RadioButton) radioGroupRuleCheck.getChildAt(i)).setEnabled(false);
radioGroupRuleCheck.getChildAt(i).setEnabled(false);
}
for (int i = 0; i < radioGroupRuleCheck2.getChildCount(); i++) {
((RadioButton) radioGroupRuleCheck2.getChildAt(i)).setEnabled(false);
radioGroupRuleCheck2.getChildAt(i).setEnabled(false);
}
editTextRuleValue.setEnabled(true);
matchTypeLayout.setVisibility(View.GONE);
@ -358,10 +318,10 @@ public class RuleActivity extends AppCompatActivity {
break;
default:
for (int i = 0; i < radioGroupRuleCheck.getChildCount(); i++) {
((RadioButton) radioGroupRuleCheck.getChildAt(i)).setEnabled(true);
radioGroupRuleCheck.getChildAt(i).setEnabled(true);
}
for (int i = 0; i < radioGroupRuleCheck2.getChildCount(); i++) {
((RadioButton) radioGroupRuleCheck2.getChildAt(i)).setEnabled(true);
radioGroupRuleCheck2.getChildAt(i).setEnabled(true);
}
editTextRuleValue.setEnabled(true);
break;
@ -380,47 +340,42 @@ public class RuleActivity extends AppCompatActivity {
}
AlertDialog.Builder builder = new AlertDialog.Builder(RuleActivity.this);
builder.setTitle("选择发送方");
builder.setItems(senderNames, new DialogInterface.OnClickListener() {//添加列表
@Override
public void onClick(DialogInterface dialogInterface, int which) {
Toast.makeText(RuleActivity.this, senderNames[which], Toast.LENGTH_LONG).show();
showTv.setText(senderNames[which]);
showTv.setTag(senderModels.get(which).getId());
}
//添加列表
builder.setItems(senderNames, (dialogInterface, which) -> {
Toast.makeText(RuleActivity.this, senderNames[which], Toast.LENGTH_LONG).show();
showTv.setText(senderNames[which]);
showTv.setTag(senderModels.get(which).getId());
});
builder.show();
}
public void testRule(final RuleModel ruleModel, final Long senderId) {
final View view = View.inflate(RuleActivity.this, R.layout.alert_dialog_setview_rule_test, null);
final RadioGroup radioGroupTestSimSlot = (RadioGroup) view.findViewById(R.id.radioGroupTestSimSlot);
final EditText editTextTestPhone = (EditText) view.findViewById(R.id.editTextTestPhone);
final EditText editTextTestMsgContent = (EditText) view.findViewById(R.id.editTextTestMsgContent);
Button buttonruletest = view.findViewById(R.id.buttonruletest);
final RadioGroup radioGroupTestSimSlot = view.findViewById(R.id.radioGroupTestSimSlot);
final EditText editTextTestPhone = view.findViewById(R.id.editTextTestPhone);
final EditText editTextTestMsgContent = view.findViewById(R.id.editTextTestMsgContent);
Button buttonRuleTest = view.findViewById(R.id.buttonRuleTest);
AlertDialog.Builder ad1 = new AlertDialog.Builder(RuleActivity.this);
ad1.setTitle("测试规则");
ad1.setIcon(android.R.drawable.ic_dialog_email);
ad1.setView(view);
buttonruletest.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
buttonRuleTest.setOnClickListener(v -> {
Log.i("editTextTestPhone", editTextTestPhone.getText().toString());
Log.i("editTextTestMsgContent", editTextTestMsgContent.getText().toString());
Log.i("editTextTestPhone", editTextTestPhone.getText().toString());
Log.i("editTextTestMsgContent", editTextTestMsgContent.getText().toString());
try {
String simSlot = RuleModel.getRuleSimSlotFromCheckId(radioGroupTestSimSlot.getCheckedRadioButtonId());
String simInfo = "";
if (simSlot.equals("SIM2")) {
simInfo = simSlot + "_" + SettingUtil.getAddExtraSim2();
} else {
simInfo = simSlot + "_" + SettingUtil.getAddExtraSim1();
}
SmsVo testSmsVo = new SmsVo(editTextTestPhone.getText().toString(), editTextTestMsgContent.getText().toString(), new Date(), simInfo);
SendUtil.sendMsgByRuleModelSenderId(handler, ruleModel, testSmsVo, senderId);
} catch (Exception e) {
Toast.makeText(RuleActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
try {
String simSlot = RuleModel.getRuleSimSlotFromCheckId(radioGroupTestSimSlot.getCheckedRadioButtonId());
String simInfo;
if (simSlot.equals("SIM2")) {
simInfo = simSlot + "_" + SettingUtil.getAddExtraSim2();
} else {
simInfo = simSlot + "_" + SettingUtil.getAddExtraSim1();
}
SmsVo testSmsVo = new SmsVo(editTextTestPhone.getText().toString(), editTextTestMsgContent.getText().toString(), new Date(), simInfo);
SendUtil.sendMsgByRuleModelSenderId(handler, ruleModel, testSmsVo, senderId);
} catch (Exception e) {
Toast.makeText(RuleActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
}
});
ad1.show();// 显示对话框

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,11 @@
package com.idormy.sms.forwarder;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Switch;
@ -18,61 +18,58 @@ import com.idormy.sms.forwarder.utils.SettingUtil;
public class SettingActivity extends AppCompatActivity {
private String TAG = "SettingActivity";
private final String TAG = "SettingActivity";
@Override
public void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "oncreate");
Log.d(TAG, "onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setting);
Switch switch_add_extra = (Switch) findViewById(R.id.switch_add_extra);
@SuppressLint("UseSwitchCompatOrMaterialCode") Switch switch_add_extra = findViewById(R.id.switch_add_extra);
switchAddExtra(switch_add_extra);
EditText et_add_extra_device_mark = (EditText) findViewById(R.id.et_add_extra_device_mark);
EditText et_add_extra_device_mark = findViewById(R.id.et_add_extra_device_mark);
editAddExtraDeviceMark(et_add_extra_device_mark);
EditText et_add_extra_sim1 = (EditText) findViewById(R.id.et_add_extra_sim1);
EditText et_add_extra_sim1 = findViewById(R.id.et_add_extra_sim1);
editAddExtraSim1(et_add_extra_sim1);
EditText et_add_extra_sim2 = (EditText) findViewById(R.id.et_add_extra_sim2);
EditText et_add_extra_sim2 = findViewById(R.id.et_add_extra_sim2);
editAddExtraSim2(et_add_extra_sim2);
EditText et_battery_level_alarm = (EditText) findViewById(R.id.et_battery_level_alarm);
EditText et_battery_level_alarm = findViewById(R.id.et_battery_level_alarm);
editBatteryLevelAlarm(et_battery_level_alarm);
EditText et_retry_delay_time1 = (EditText) findViewById(R.id.et_retry_delay_time1);
EditText et_retry_delay_time1 = findViewById(R.id.et_retry_delay_time1);
editRetryDelayTime(et_retry_delay_time1, 1);
EditText et_retry_delay_time2 = (EditText) findViewById(R.id.et_retry_delay_time2);
EditText et_retry_delay_time2 = findViewById(R.id.et_retry_delay_time2);
editRetryDelayTime(et_retry_delay_time2, 2);
EditText et_retry_delay_time3 = (EditText) findViewById(R.id.et_retry_delay_time3);
EditText et_retry_delay_time3 = findViewById(R.id.et_retry_delay_time3);
editRetryDelayTime(et_retry_delay_time3, 3);
EditText et_retry_delay_time4 = (EditText) findViewById(R.id.et_retry_delay_time4);
EditText et_retry_delay_time4 = findViewById(R.id.et_retry_delay_time4);
editRetryDelayTime(et_retry_delay_time4, 4);
EditText et_retry_delay_time5 = (EditText) findViewById(R.id.et_retry_delay_time5);
EditText et_retry_delay_time5 = findViewById(R.id.et_retry_delay_time5);
editRetryDelayTime(et_retry_delay_time5, 5);
Switch switch_sms_template = (Switch) findViewById(R.id.switch_sms_template);
@SuppressLint("UseSwitchCompatOrMaterialCode") Switch switch_sms_template = findViewById(R.id.switch_sms_template);
switchSmsTemplate(switch_sms_template);
EditText textSmsTemplate = (EditText) findViewById(R.id.text_sms_template);
EditText textSmsTemplate = findViewById(R.id.text_sms_template);
editSmsTemplate(textSmsTemplate);
}
//设置转发附加信息
private void switchAddExtra(Switch switch_add_extra) {
private void switchAddExtra(@SuppressLint("UseSwitchCompatOrMaterialCode") Switch switch_add_extra) {
switch_add_extra.setChecked(SettingUtil.getSwitchAddExtra());
switch_add_extra.setOnCheckedChangeListener(new Switch.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SettingUtil.switchAddExtra(isChecked);
Log.d(TAG, "onCheckedChanged:" + isChecked);
}
switch_add_extra.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingUtil.switchAddExtra(isChecked);
Log.d(TAG, "onCheckedChanged:" + isChecked);
});
}
//设置转发附加信息devicemark
//设置转发附加信息deviceMark
private void editAddExtraDeviceMark(final EditText et_add_extra_device_mark) {
et_add_extra_device_mark.setText(SettingUtil.getAddExtraDeviceMark());
@ -94,7 +91,7 @@ public class SettingActivity extends AppCompatActivity {
});
}
//设置转发附加信息devicemark
//设置转发附加信息deviceMark
private void editAddExtraSim1(final EditText et_add_extra_sim1) {
et_add_extra_sim1.setText(SettingUtil.getAddExtraSim1());
@ -116,7 +113,7 @@ public class SettingActivity extends AppCompatActivity {
});
}
//设置转发附加信息devicemark
//设置转发附加信息deviceMark
private void editAddExtraSim2(final EditText et_add_extra_sim2) {
et_add_extra_sim2.setText(SettingUtil.getAddExtraSim2());
@ -180,28 +177,25 @@ public class SettingActivity extends AppCompatActivity {
}
//设置转发时启用自定义模版
private void switchSmsTemplate(Switch switch_sms_template) {
private void switchSmsTemplate(@SuppressLint("UseSwitchCompatOrMaterialCode") Switch switch_sms_template) {
boolean isOn = SettingUtil.getSwitchSmsTemplate();
switch_sms_template.setChecked(isOn);
final LinearLayout layout_sms_template = (LinearLayout) findViewById(R.id.layout_sms_template);
final LinearLayout layout_sms_template = findViewById(R.id.layout_sms_template);
layout_sms_template.setVisibility(isOn ? View.VISIBLE : View.GONE);
final EditText textSmsTemplate = (EditText) findViewById(R.id.text_sms_template);
final EditText textSmsTemplate = findViewById(R.id.text_sms_template);
switch_sms_template.setOnCheckedChangeListener(new Switch.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Log.d(TAG, "onCheckedChanged:" + isChecked);
layout_sms_template.setVisibility(isChecked ? View.VISIBLE : View.GONE);
SettingUtil.switchSmsTemplate(isChecked);
if (!isChecked) {
textSmsTemplate.setText("{{来源号码}}\n{{短信内容}}\n{{卡槽信息}}\n{{接收时间}}\n{{设备名称}}");
}
switch_sms_template.setOnCheckedChangeListener((buttonView, isChecked) -> {
Log.d(TAG, "onCheckedChanged:" + isChecked);
layout_sms_template.setVisibility(isChecked ? View.VISIBLE : View.GONE);
SettingUtil.switchSmsTemplate(isChecked);
if (!isChecked) {
textSmsTemplate.setText("{{来源号码}}\n{{短信内容}}\n{{卡槽信息}}\n{{接收时间}}\n{{设备名称}}");
}
});
}
//设置转发附加信息devicemark
//设置转发附加信息deviceMark
private void editSmsTemplate(final EditText textSmsTemplate) {
textSmsTemplate.setText(SettingUtil.getSmsTemplate());
@ -224,17 +218,15 @@ public class SettingActivity extends AppCompatActivity {
}
//插入标签
@SuppressLint("NonConstantResourceId")
public void toInsertLabel(View v) {
EditText textSmsTemplate = (EditText) findViewById(R.id.text_sms_template);
EditText textSmsTemplate = findViewById(R.id.text_sms_template);
textSmsTemplate.setFocusable(true);
textSmsTemplate.requestFocus();
switch (v.getId()) {
case R.id.bt_insert_sender:
textSmsTemplate.append("{{来源号码}}");
return;
/*case R.id.bt_insert_receiver:
textSmsTemplate.append("{{接收号码}}");
return;*/
case R.id.bt_insert_content:
textSmsTemplate.append("{{短信内容}}");
return;
@ -248,33 +240,32 @@ public class SettingActivity extends AppCompatActivity {
textSmsTemplate.append("{{设备名称}}");
return;
default:
return;
}
}
//恢复初始化配置
public void initSetting(View v) {
Switch switch_add_extra = (Switch) findViewById(R.id.switch_add_extra);
public void initSetting(View view) {
@SuppressLint("UseSwitchCompatOrMaterialCode") Switch switch_add_extra = findViewById(R.id.switch_add_extra);
switch_add_extra.setChecked(false);
switchAddExtra(switch_add_extra);
EditText et_add_extra_device_mark = (EditText) findViewById(R.id.et_add_extra_device_mark);
EditText et_add_extra_device_mark = findViewById(R.id.et_add_extra_device_mark);
et_add_extra_device_mark.setText("");
editAddExtraDeviceMark(et_add_extra_device_mark);
EditText et_add_extra_sim1 = (EditText) findViewById(R.id.et_add_extra_sim1);
EditText et_add_extra_sim1 = findViewById(R.id.et_add_extra_sim1);
et_add_extra_sim1.setText("");
editAddExtraSim1(et_add_extra_sim1);
EditText et_add_extra_sim2 = (EditText) findViewById(R.id.et_add_extra_sim2);
EditText et_add_extra_sim2 = findViewById(R.id.et_add_extra_sim2);
et_add_extra_sim2.setText("");
editAddExtraSim2(et_add_extra_sim2);
Switch switch_sms_template = (Switch) findViewById(R.id.switch_sms_template);
@SuppressLint("UseSwitchCompatOrMaterialCode") Switch switch_sms_template = findViewById(R.id.switch_sms_template);
switch_sms_template.setChecked(false);
switchSmsTemplate(switch_sms_template);
EditText textSmsTemplate = (EditText) findViewById(R.id.text_sms_template);
EditText textSmsTemplate = findViewById(R.id.text_sms_template);
textSmsTemplate.setText("{{来源号码}}\n{{短信内容}}\n{{卡槽信息}}\n{{接收时间}}\n{{设备名称}}");
editSmsTemplate(textSmsTemplate);

View File

@ -1,7 +1,6 @@
package com.idormy.sms.forwarder.adapter;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -15,8 +14,9 @@ import com.idormy.sms.forwarder.utils.aUtil;
import java.util.List;
@SuppressWarnings("unused")
public class LogAdapter extends ArrayAdapter<LogVo> {
private int resourceId;
private final int resourceId;
private List<LogVo> list;
// 适配器的构造函数把要适配的数据传入这里
@ -112,7 +112,7 @@ public class LogAdapter extends ArrayAdapter<LogVo> {
}
// 定义一个内部类用于对控件的实例进行缓存
class ViewHolder {
static class ViewHolder {
TextView tLogFrom;
TextView tLogContent;
TextView tLogRule;

View File

@ -16,7 +16,7 @@ import com.idormy.sms.forwarder.sender.SenderUtil;
import java.util.List;
public class RuleAdapter extends ArrayAdapter<RuleModel> {
private int resourceId;
private final int resourceId;
private List<RuleModel> list;
// 适配器的构造函数把要适配的数据传入这里
@ -108,7 +108,7 @@ public class RuleAdapter extends ArrayAdapter<RuleModel> {
}
// 定义一个内部类用于对控件的实例进行缓存
class ViewHolder {
static class ViewHolder {
TextView ruleMatch;
TextView ruleSender;
ImageView ruleSenderImage;

View File

@ -13,8 +13,9 @@ import com.idormy.sms.forwarder.model.SenderModel;
import java.util.List;
@SuppressWarnings("unused")
public class SenderAdapter extends ArrayAdapter<SenderModel> {
private int resourceId;
private final int resourceId;
private List<SenderModel> list;
// 适配器的构造函数把要适配的数据传入这里
@ -120,7 +121,7 @@ public class SenderAdapter extends ArrayAdapter<SenderModel> {
}
// 定义一个内部类用于对控件的实例进行缓存
class ViewHolder {
static class ViewHolder {
ImageView senderImage;
TextView senderName;
}

View File

@ -1,5 +1,7 @@
package com.idormy.sms.forwarder.model;
import androidx.annotation.NonNull;
import lombok.Data;
@Data
@ -17,6 +19,7 @@ public class LogModel {
this.ruleId = ruleId;
}
@NonNull
@Override
public String toString() {
return "LogModel{" +

View File

@ -0,0 +1,14 @@
package com.idormy.sms.forwarder.model;
import lombok.Data;
@Data
public class PhoneBookEntity {
private String name;
private String phoneNumber;
public PhoneBookEntity(String name, String phoneNumber) {
this.name = name;
this.phoneNumber = phoneNumber;
}
}

View File

@ -1,7 +1,10 @@
package com.idormy.sms.forwarder.model;
import android.annotation.SuppressLint;
import android.util.Log;
import androidx.annotation.NonNull;
import com.idormy.sms.forwarder.R;
import com.idormy.sms.forwarder.model.vo.SmsVo;
import com.idormy.sms.forwarder.utils.RuleLineUtils;
@ -14,13 +17,14 @@ import java.util.regex.PatternSyntaxException;
import lombok.Data;
@SuppressWarnings({"unused", "LoopStatementThatDoesntLoop"})
@Data
public class RuleModel {
public static final String FILED_TRANSPOND_ALL = "transpond_all";
public static final String FILED_PHONE_NUM = "phone_num";
public static final String FILED_MSG_CONTENT = "msg_content";
public static final String FILED_MULTI_MATCH = "multi_match";
public static final Map<String, String> FILED_MAP = new HashMap<String, String>();
public static final Map<String, String> FILED_MAP = new HashMap<>();
public static final String CHECK_IS = "is";
public static final String CHECK_CONTAIN = "contain";
public static final String CHECK_NOT_CONTAIN = "notcontain";
@ -28,11 +32,11 @@ public class RuleModel {
public static final String CHECK_END_WITH = "endwith";
public static final String CHECK_NOT_IS = "notis";
public static final String CHECK_REGEX = "regex";
public static final Map<String, String> CHECK_MAP = new HashMap<String, String>();
public static final Map<String, String> CHECK_MAP = new HashMap<>();
public static final String CHECK_SIM_SLOT_ALL = "ALL";
public static final String CHECK_SIM_SLOT_1 = "SIM1";
public static final String CHECK_SIM_SLOT_2 = "SIM2";
public static final Map<String, String> SIM_SLOT_MAP = new HashMap<String, String>();
public static final Map<String, String> SIM_SLOT_MAP = new HashMap<>();
static {
FILED_MAP.put("transpond_all", "全部转发");
@ -75,6 +79,7 @@ public class RuleModel {
}
}
@SuppressLint("NonConstantResourceId")
public static String getRuleFiledFromCheckId(int id) {
switch (id) {
case R.id.btnContent:
@ -88,6 +93,7 @@ public class RuleModel {
}
}
@SuppressLint("NonConstantResourceId")
public static String getRuleCheckFromCheckId(int id) {
switch (id) {
case R.id.btnContain:
@ -105,6 +111,7 @@ public class RuleModel {
}
}
@SuppressLint("NonConstantResourceId")
public static String getRuleSimSlotFromCheckId(int id) {
switch (id) {
case R.id.btnSimSlot1:
@ -191,7 +198,6 @@ public class RuleModel {
break;
}
} catch (PatternSyntaxException e) {
checked = false;
Log.d(TAG, "PatternSyntaxException: ");
Log.d(TAG, "Description: " + e.getDescription());
Log.d(TAG, "Index: " + e.getIndex());
@ -265,6 +271,7 @@ public class RuleModel {
}
}
@NonNull
@Override
public String toString() {
return "RuleModel{" +

View File

@ -1,9 +1,12 @@
package com.idormy.sms.forwarder.model;
import androidx.annotation.NonNull;
import com.idormy.sms.forwarder.R;
import lombok.Data;
@SuppressWarnings("unused")
@Data
public class SenderModel {
public static final int STATUS_ON = 1;
@ -98,6 +101,7 @@ public class SenderModel {
}
}
@NonNull
@Override
public String toString() {
return "SenderModel{" +

View File

@ -8,9 +8,6 @@ import lombok.Data;
public class BarkSettingVo implements Serializable {
private String server;
public BarkSettingVo() {
}
public BarkSettingVo(String server) {
this.server = server;
}

View File

@ -8,16 +8,13 @@ import lombok.Data;
public class DingDingSettingVo implements Serializable {
private String token;
private String secret;
private String atMobils;
private String atMobiles;
private Boolean atAll;
public DingDingSettingVo() {
}
public DingDingSettingVo(String token, String secret, String atMobils, Boolean atAll) {
public DingDingSettingVo(String token, String secret, String atMobiles, Boolean atAll) {
this.token = token;
this.secret = secret;
this.atMobils = atMobils;
this.atMobiles = atMobiles;
this.atAll = atAll;
}
}

View File

@ -8,15 +8,12 @@ import lombok.Data;
public class EmailSettingVo implements Serializable {
private String host;
private String port;
private Boolean ssl = true;
private Boolean ssl;
private String fromEmail;
private String nickname;
private String pwd;
private String toEmail;
public EmailSettingVo() {
}
public EmailSettingVo(String host, String port, Boolean ssl, String fromEmail, String nickname, String pwd, String toEmail) {
this.host = host;
this.port = port;

View File

@ -9,9 +9,6 @@ public class FeiShuSettingVo implements Serializable {
private String webhook;
private String secret;
public FeiShuSettingVo() {
}
public FeiShuSettingVo(String webhook, String secret) {
this.webhook = webhook;
this.secret = secret;

View File

@ -16,9 +16,6 @@ public class LogVo {
private int forwardStatus;
private String forwardResponse;
public LogVo() {
}
public LogVo(Long id, String from, String content, String simInfo, String time, String rule, int senderImageId, int forwardStatus, String forwardResponse) {
this.id = id;
this.from = from;
@ -33,7 +30,7 @@ public class LogVo {
public int getSimImageId() {
if (this.simInfo != null && !this.simInfo.isEmpty()
&& this.simInfo.replace("-", "").substring(0, 4).equals("SIM2")) {
&& this.simInfo.replace("-", "").startsWith("SIM2")) {
return R.mipmap.sim2;
}

View File

@ -12,9 +12,6 @@ public class QYWXAppSettingVo implements Serializable {
private String toUser;
private Boolean atAll;
public QYWXAppSettingVo() {
}
public QYWXAppSettingVo(String corpID, String agentID, String secret, String toUser, Boolean atAll) {
this.corpID = corpID;
this.agentID = agentID;

View File

@ -8,9 +8,6 @@ import lombok.Data;
public class QYWXGroupRobotSettingVo implements Serializable {
private String webHook;
public QYWXGroupRobotSettingVo() {
}
public QYWXGroupRobotSettingVo(String webHook) {
this.webHook = webHook;
}

View File

@ -1,5 +1,8 @@
package com.idormy.sms.forwarder.model.vo;
import lombok.Data;
@Data
public class RuleVo {
private String matchStr;
private String senderStr;

View File

@ -8,9 +8,6 @@ import lombok.Data;
public class ServerChanSettingVo implements Serializable {
private String sendKey;
public ServerChanSettingVo() {
}
public ServerChanSettingVo(String sendKey) {
this.sendKey = sendKey;
}

View File

@ -12,9 +12,6 @@ public class SmsSettingVo implements Serializable {
private String mobiles;
private Boolean onlyNoNetwork;
public SmsSettingVo() {
}
public SmsSettingVo(int simSlot, String mobiles, Boolean onlyNoNetwork) {
this.simSlot = simSlot;
this.mobiles = mobiles;

View File

@ -1,5 +1,9 @@
package com.idormy.sms.forwarder.model.vo;
import android.annotation.SuppressLint;
import androidx.annotation.NonNull;
import com.idormy.sms.forwarder.utils.SettingUtil;
import java.io.Serializable;
@ -13,10 +17,7 @@ public class SmsVo implements Serializable {
String mobile;
String content;
Date date;
String simInfo = "SIM1_unknown_unknown";
public SmsVo() {
}
String simInfo;
public SmsVo(String mobile, String content, Date date, String simInfo) {
this.mobile = mobile;
@ -25,6 +26,7 @@ public class SmsVo implements Serializable {
this.simInfo = simInfo;
}
@SuppressLint("SimpleDateFormat")
public String getSmsVoForSend() {
boolean switchAddExtra = SettingUtil.getSwitchAddExtra();
boolean switchSmsTemplate = SettingUtil.getSwitchSmsTemplate();
@ -46,6 +48,7 @@ public class SmsVo implements Serializable {
.trim();
}
@NonNull
@Override
public String toString() {
return "SmsVo{" +

View File

@ -9,9 +9,6 @@ public class TelegramSettingVo implements Serializable {
private String apiToken;
private String chatId;
public TelegramSettingVo() {
}
public TelegramSettingVo(String apiToken, String chatId) {
this.apiToken = apiToken;
this.chatId = chatId;

View File

@ -13,9 +13,6 @@ public class WebNotifySettingVo implements Serializable {
private String method;
private String webParams;
public WebNotifySettingVo() {
}
public WebNotifySettingVo(String webServer, String secret, String method, String webParams) {
this.webServer = webServer;
this.secret = secret;

View File

@ -0,0 +1,66 @@
package com.idormy.sms.forwarder.receiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
import com.idormy.sms.forwarder.R;
import com.idormy.sms.forwarder.model.PhoneBookEntity;
import com.idormy.sms.forwarder.model.vo.SmsVo;
import com.idormy.sms.forwarder.sender.SendUtil;
import com.idormy.sms.forwarder.utils.ContactHelper;
import com.idormy.sms.forwarder.utils.SettingUtil;
import java.util.Date;
import java.util.List;
public class PhoneStateReceiver extends BroadcastReceiver {
private TelephonyManager mTelephonyManager;
@Override
public void onReceive(Context context, Intent intent) {
if (!SettingUtil.getSwitchEnablePhone()) {
return;
}
String action = intent.getAction();
if (TelephonyManager.ACTION_PHONE_STATE_CHANGED.equals(action)) {
String phoneNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
if (mTelephonyManager == null) {
mTelephonyManager =
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
}
int state = mTelephonyManager.getCallState();
Log.d("PhoneStateReceiver", "onReceive state=" + state + " phoneNumber = " + phoneNumber);
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
if (!TextUtils.isEmpty(phoneNumber)) {
sendReceiveCallMsg(context, phoneNumber);
}
break;
case TelephonyManager.CALL_STATE_IDLE:
case TelephonyManager.CALL_STATE_OFFHOOK:
break;
}
}
}
private void sendReceiveCallMsg(Context context, String phoneNumber) {
List<PhoneBookEntity> contacts = ContactHelper.getInstance().getContactByNumber(context, phoneNumber);
String name = "";
if (contacts != null && contacts.size() > 0) {
PhoneBookEntity phoneBookEntity = contacts.get(0);
name = phoneBookEntity.getName();
}
if (TextUtils.isEmpty(name)) {
name = context.getString(R.string.unknown_number);
}
SmsVo smsVo = new SmsVo(phoneNumber, name + context.getString(R.string.calling), new Date(), name);
Log.d("PhoneStateReceiver", "send_msg" + smsVo.toString());
SendUtil.send_msg(context, smsVo, 1);
}
}

View File

@ -1,4 +1,4 @@
package com.idormy.sms.forwarder.BroadCastReceiver;
package com.idormy.sms.forwarder.receiver;
import android.content.BroadcastReceiver;
import android.content.Context;
@ -10,15 +10,13 @@ import com.idormy.sms.forwarder.service.FrontService;
import com.idormy.sms.forwarder.utils.InitUtil;
public class RebootBroadcastReceiver extends BroadcastReceiver {
private String TAG = "RebootBroadcastReceiver";
@Override
public void onReceive(Context context, Intent intent) {
String receiveAction = intent.getAction();
String TAG = "RebootBroadcastReceiver";
Log.d(TAG, "onReceive intent " + receiveAction);
if (receiveAction.equals("android.intent.action.BOOT_COMPLETED")) {
Log.d(TAG, "BOOT_COMPLETED");
InitUtil.init(context);
Intent frontServiceIntent = new Intent(context, FrontService.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
@ -26,9 +24,6 @@ public class RebootBroadcastReceiver extends BroadcastReceiver {
} else {
context.startService(frontServiceIntent);
}
//监控当前电量
//Intent batteryServiceIntent = new Intent(context, BatteryService.class);
//context.startService(batteryServiceIntent);
}
}

View File

@ -1,4 +1,4 @@
package com.idormy.sms.forwarder.BroadCastReceiver;
package com.idormy.sms.forwarder.receiver;
import android.content.BroadcastReceiver;
import android.content.Context;
@ -20,14 +20,12 @@ import java.util.Map;
import java.util.Objects;
public class SmsForwarderBroadcastReceiver extends BroadcastReceiver {
private String TAG = "SmsForwarderBroadcastReceiver";
private int intLevel;
private int intScale;
@Override
public void onReceive(Context context, Intent intent) {
String receiveAction = intent.getAction();
String TAG = "SmsForwarderBroadcastReceiver";
Log.d(TAG, "onReceive intent " + receiveAction);
if ("android.provider.Telephony.SMS_RECEIVED".equals(receiveAction)) {
try {

View File

@ -1,5 +1,6 @@
package com.idormy.sms.forwarder.sender;
import android.annotation.SuppressLint;
import android.content.ContentValues;
import android.content.Context;
import android.content.SharedPreferences;
@ -19,10 +20,12 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
@SuppressWarnings({"SynchronizeOnNonFinalField", "unused", "MismatchedQueryAndUpdateOfCollection"})
public class SendHistory {
static String TAG = "SendHistory";
static final String TAG = "SendHistory";
static Boolean hasInit = false;
@SuppressLint("StaticFieldLeak")
static Context context;
static DbHelper dbHelper;
static SQLiteDatabase db;
@ -37,16 +40,17 @@ public class SendHistory {
}
}
@SuppressLint("MutatingSharedPrefs")
public static void addHistory(String msg) {
//不保存转发消息
if (!SettingUtil.saveMsgHistory()) return;
if (SettingUtil.saveMsgHistory()) return;
//保存
SharedPreferences sp = context.getSharedPreferences(Define.SP_MSG, Context.MODE_PRIVATE);
Set<String> msg_set_default = new HashSet<>();
Set<String> msg_set;
msg_set = sp.getStringSet(Define.SP_MSG_SET_KEY, msg_set_default);
Log.d(TAG, "msg_set" + msg_set.toString());
Log.d(TAG, "msg_set" + Integer.toString(msg_set.size()));
Log.d(TAG, "msg_set_size" + msg_set.size());
msg_set.add(msg);
sp.edit().putStringSet(Define.SP_MSG_SET_KEY, msg_set).apply();
}
@ -56,16 +60,16 @@ public class SendHistory {
Set<String> msg_set = new HashSet<>();
msg_set = sp.getStringSet(Define.SP_MSG_SET_KEY, msg_set);
Log.d(TAG, "msg_set.toString()" + msg_set.toString());
String getMsg = "";
StringBuilder getMsg = new StringBuilder();
for (String str : msg_set) {
getMsg += str + "\n";
getMsg.append(str).append("\n");
}
return getMsg;
return getMsg.toString();
}
public static long addHistoryDb(LogModel logModel) {
//不保存转发消息
if (!SettingUtil.saveMsgHistory()) return 0;
if (SettingUtil.saveMsgHistory()) return 0;
// Gets the data repository in write mode
SQLiteDatabase db = dbHelper.getWritableDatabase();
@ -101,7 +105,7 @@ public class SendHistory {
selectionArgList.add(key);
selectionArgList.add(key);
}
String[] selectionArgs = selectionArgList.toArray(new String[selectionArgList.size()]);
String[] selectionArgs = selectionArgList.toArray(new String[0]);
// Issue SQL statement.
return db.delete(LogTable.LogEntry.TABLE_NAME, selection, selectionArgs);
@ -134,7 +138,7 @@ public class SendHistory {
selectionArgList.add(key);
selectionArgList.add(key);
}
String[] selectionArgs = selectionArgList.toArray(new String[selectionArgList.size()]);
String[] selectionArgs = selectionArgList.toArray(new String[0]);
// How you want the results sorted in the resulting Cursor
String sortOrder =
@ -161,11 +165,11 @@ public class SendHistory {
Set<String> msg_set = new HashSet<>();
msg_set = sp.getStringSet(Define.SP_MSG_SET_KEY, msg_set);
Log.d(TAG, "msg_set.toString()" + msg_set.toString());
String getMsg = "";
StringBuilder getMsg = new StringBuilder();
for (String str : msg_set) {
getMsg += str + "\n";
getMsg.append(str).append("\n");
}
return getMsg;
return getMsg.toString();
}
}

View File

@ -37,7 +37,7 @@ import com.idormy.sms.forwarder.utils.RuleUtil;
import java.util.List;
public class SendUtil {
private static String TAG = "SendUtil";
private static final String TAG = "SendUtil";
public static void send_msg_list(Context context, List<SmsVo> smsVoList, int simId) {
Log.i(TAG, "send_msg_list size: " + smsVoList.size());
@ -52,10 +52,10 @@ public class SendUtil {
LogUtil.init(context);
String key = "SIM" + simId;
List<RuleModel> rulelist = RuleUtil.getRule(null, key);
if (!rulelist.isEmpty()) {
List<RuleModel> ruleList = RuleUtil.getRule(null, key);
if (!ruleList.isEmpty()) {
SenderUtil.init(context);
for (RuleModel ruleModel : rulelist) {
for (RuleModel ruleModel : ruleList) {
//规则匹配发现需要发送
try {
if (ruleModel.checkMsg(smsVo)) {
@ -114,7 +114,7 @@ public class SendUtil {
DingDingSettingVo dingDingSettingVo = JSON.parseObject(senderModel.getJsonSetting(), DingDingSettingVo.class);
if (dingDingSettingVo != null) {
try {
SenderDingdingMsg.sendMsg(logId, handError, dingDingSettingVo.getToken(), dingDingSettingVo.getSecret(), dingDingSettingVo.getAtMobils(), dingDingSettingVo.getAtAll(), smsVo.getSmsVoForSend());
SenderDingdingMsg.sendMsg(logId, handError, dingDingSettingVo.getToken(), dingDingSettingVo.getSecret(), dingDingSettingVo.getAtMobiles(), dingDingSettingVo.getAtAll(), smsVo.getSmsVoForSend());
} catch (Exception e) {
LogUtil.updateLog(logId, 0, e.getMessage());
Log.e(TAG, "senderSendMsg: dingding error " + e.getMessage());
@ -235,7 +235,7 @@ public class SendUtil {
SmsSettingVo smsSettingVo = JSON.parseObject(senderModel.getJsonSetting(), SmsSettingVo.class);
if (smsSettingVo != null) {
//仅当无网络时启用
if (true == smsSettingVo.getOnlyNoNetwork() && 0 != NetUtil.getNetWorkStatus()) {
if (smsSettingVo.getOnlyNoNetwork() && 0 != NetUtil.getNetWorkStatus()) {
String msg = "仅当无网络时启用,当前网络状态:" + NetUtil.getNetWorkStatus();
LogUtil.updateLog(logId, 0, msg);
Log.d(TAG, msg);

View File

@ -3,11 +3,14 @@ package com.idormy.sms.forwarder.sender;
import android.os.Handler;
import android.util.Log;
import androidx.annotation.NonNull;
import com.idormy.sms.forwarder.utils.LogUtil;
import com.idormy.sms.forwarder.utils.SettingUtil;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -20,9 +23,10 @@ import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
@SuppressWarnings("ResultOfMethodCallIgnored")
public class SenderBarkMsg extends SenderBaseMsg {
static String TAG = "SenderBarkMsg";
static final String TAG = "SenderBarkMsg";
public static void sendMsg(final long logId, final Handler handError, String barkServer, String from, String content, String groupName) throws Exception {
Log.i(TAG, "sendMsg barkServer:" + barkServer + " from:" + from + " content:" + content);
@ -61,15 +65,15 @@ public class SenderBarkMsg extends SenderBaseMsg {
Call call = client.newCall(request);
call.enqueue(new Callback() {
@Override
public void onFailure(Call call, final IOException e) {
public void onFailure(@NonNull Call call, @NonNull final IOException e) {
LogUtil.updateLog(logId, 0, e.getMessage());
Toast(handError, TAG, "发送失败:" + e.getMessage());
emitter.onError(new RuntimeException("请求接口异常..."));
}
@Override
public void onResponse(Call call, Response response) throws IOException {
final String responseStr = response.body().string();
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
final String responseStr = Objects.requireNonNull(response.body()).string();
Log.d(TAG, "Response" + response.code() + "" + responseStr);
Toast(handError, TAG, "发送状态:" + responseStr);

View File

@ -5,16 +5,20 @@ import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
import androidx.annotation.NonNull;
import com.alibaba.fastjson.JSON;
import com.idormy.sms.forwarder.utils.LogUtil;
import com.idormy.sms.forwarder.utils.SettingUtil;
import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import javax.crypto.Mac;
@ -30,9 +34,10 @@ import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
@SuppressWarnings({"ResultOfMethodCallIgnored", "rawtypes", "unchecked", "deprecation"})
public class SenderDingdingMsg extends SenderBaseMsg {
static String TAG = "SenderDingdingMsg";
static final String TAG = "SenderDingdingMsg";
public static void sendMsg(final long logId, final Handler handError, String token, String secret, String atMobiles, Boolean atAll, String content) throws Exception {
Log.i(TAG, "sendMsg token:" + token + " secret:" + secret + " atMobiles:" + atMobiles + " atAll:" + atAll + " content:" + content);
@ -45,8 +50,8 @@ public class SenderDingdingMsg extends SenderBaseMsg {
Long timestamp = System.currentTimeMillis();
String stringToSign = timestamp + "\n" + secret;
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(new SecretKeySpec(secret.getBytes("UTF-8"), "HmacSHA256"));
byte[] signData = mac.doFinal(stringToSign.getBytes("UTF-8"));
mac.init(new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), "HmacSHA256"));
byte[] signData = mac.doFinal(stringToSign.getBytes(StandardCharsets.UTF_8));
String sign = URLEncoder.encode(new String(Base64.encode(signData, Base64.NO_WRAP)), "UTF-8");
token += "&timestamp=" + timestamp + "&sign=" + sign;
Log.i(TAG, "token:" + token);
@ -103,15 +108,15 @@ public class SenderDingdingMsg extends SenderBaseMsg {
Call call = client.newCall(request);
call.enqueue(new Callback() {
@Override
public void onFailure(Call call, final IOException e) {
public void onFailure(@NonNull Call call, @NonNull final IOException e) {
LogUtil.updateLog(logId, 0, e.getMessage());
Toast(handError, TAG, "发送失败:" + e.getMessage());
emitter.onError(new RuntimeException("请求接口异常..."));
}
@Override
public void onResponse(Call call, Response response) throws IOException {
final String responseStr = response.body().string();
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
final String responseStr = Objects.requireNonNull(response.body()).string();
Log.d(TAG, "Response" + response.code() + "" + responseStr);
Toast(handError, TAG, "发送状态:" + responseStr);

View File

@ -4,14 +4,18 @@ import android.os.Handler;
import android.util.Base64;
import android.util.Log;
import androidx.annotation.NonNull;
import com.alibaba.fastjson.JSON;
import com.idormy.sms.forwarder.utils.LogUtil;
import com.idormy.sms.forwarder.utils.SettingUtil;
import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import javax.crypto.Mac;
@ -27,9 +31,10 @@ import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
@SuppressWarnings({"ResultOfMethodCallIgnored", "rawtypes", "unchecked", "deprecation"})
public class SenderFeishuMsg extends SenderBaseMsg {
static String TAG = "SenderFeishuMsg";
static final String TAG = "SenderFeishuMsg";
public static void sendMsg(final long logId, final Handler handError, String webhook, String secret, String content) throws Exception {
Log.i(TAG, "sendMsg webhook:" + webhook + " secret:" + secret + " content:" + content);
@ -45,8 +50,8 @@ public class SenderFeishuMsg extends SenderBaseMsg {
Long timestamp = System.currentTimeMillis();
String stringToSign = timestamp + "\n" + secret;
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(new SecretKeySpec(secret.getBytes("UTF-8"), "HmacSHA256"));
byte[] signData = mac.doFinal(stringToSign.getBytes("UTF-8"));
mac.init(new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), "HmacSHA256"));
byte[] signData = mac.doFinal(stringToSign.getBytes(StandardCharsets.UTF_8));
String sign = URLEncoder.encode(new String(Base64.encode(signData, Base64.NO_WRAP)), "UTF-8");
textMsgMap.put("timestamp", timestamp);
textMsgMap.put("sign", sign);
@ -78,15 +83,15 @@ public class SenderFeishuMsg extends SenderBaseMsg {
Call call = client.newCall(request);
call.enqueue(new Callback() {
@Override
public void onFailure(Call call, final IOException e) {
public void onFailure(@NonNull Call call, @NonNull final IOException e) {
LogUtil.updateLog(logId, 0, e.getMessage());
Toast(handError, TAG, "发送失败:" + e.getMessage());
emitter.onError(new RuntimeException("请求接口异常..."));
}
@Override
public void onResponse(Call call, Response response) throws IOException {
final String responseStr = response.body().string();
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
final String responseStr = Objects.requireNonNull(response.body()).string();
Log.d(TAG, "Response" + response.code() + "" + responseStr);
Toast(handError, TAG, "发送状态:" + responseStr);

View File

@ -14,12 +14,13 @@ import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.ObservableEmitter;
@SuppressWarnings("ResultOfMethodCallIgnored")
public class SenderMailMsg extends SenderBaseMsg {
private static String TAG = "SenderMailMsg";
private static final String TAG = "SenderMailMsg";
public static void sendEmail(final long logId, final Handler handError, final String host, final String port, final boolean ssl, final String fromemail, final String nickname, final String pwd, final String toAdd, final String title, final String content) {
public static void sendEmail(final long logId, final Handler handError, final String host, final String port, final boolean ssl, final String fromEmail, final String nickname, final String pwd, final String toAdd, final String title, final String content) {
Log.d(TAG, "sendEmail: host:" + host + " port:" + port + " ssl:" + ssl + " fromemail:" + fromemail + " nickname:" + nickname + " pwd:" + pwd + " toAdd:" + toAdd);
Log.d(TAG, "sendEmail: host:" + host + " port:" + port + " ssl:" + ssl + " fromEmail:" + fromEmail + " nickname:" + nickname + " pwd:" + pwd + " toAdd:" + toAdd);
Observable
.create((ObservableEmitter<Object> emitter) -> {
@ -31,7 +32,7 @@ public class SenderMailMsg extends SenderBaseMsg {
//配置发件人邮件服务器参数
EmailKit.Config config = new EmailKit.Config()
.setSMTP(host, Integer.parseInt(port), ssl) //设置SMTP服务器主机地址端口和是否开启ssl
.setAccount(fromemail) //发件人邮箱
.setAccount(fromEmail) //发件人邮箱
.setPassword(pwd); //密码或授权码
//设置一封草稿邮件

View File

@ -7,6 +7,8 @@ import android.os.Handler;
import android.os.Message;
import android.util.Log;
import androidx.annotation.NonNull;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.idormy.sms.forwarder.MyApplication;
@ -16,6 +18,7 @@ import com.idormy.sms.forwarder.utils.SettingUtil;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import io.reactivex.rxjava3.core.Observable;
@ -28,9 +31,10 @@ import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
@SuppressWarnings({"rawtypes", "unchecked", "deprecation", "ResultOfMethodCallIgnored"})
public class SenderQyWxAppMsg extends SenderBaseMsg {
static String TAG = "SenderQyWxAppMsg";
static final String TAG = "SenderQyWxAppMsg";
public static void sendMsg(final long logId, final Handler handError, String corpID, String agentID, String secret, String toUser, String content, boolean forceRefresh) throws Exception {
Log.i(TAG, "sendMsg corpID:" + corpID + " agentID:" + agentID + " secret:" + secret + " toUser:" + toUser + " content:" + content + " forceRefresh:" + forceRefresh);
@ -40,20 +44,20 @@ public class SenderQyWxAppMsg extends SenderBaseMsg {
}
//TODO:判断access_token是否失效
if (forceRefresh == true
if (forceRefresh
|| MyApplication.QyWxAccessToken == null || MyApplication.QyWxAccessToken.isEmpty()
|| System.currentTimeMillis() > MyApplication.QyWxAccessTokenExpiresIn) {
String gettokenUrl = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?";
gettokenUrl += "corpid=" + corpID;
gettokenUrl += "&corpsecret=" + secret;
Log.d(TAG, "gettokenUrl" + gettokenUrl);
String getTokenUrl = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?";
getTokenUrl += "corpid=" + corpID;
getTokenUrl += "&corpsecret=" + secret;
Log.d(TAG, "getTokenUrl" + getTokenUrl);
OkHttpClient client = new OkHttpClient();
final Request request = new Request.Builder().url(gettokenUrl).get().build();
final Request request = new Request.Builder().url(getTokenUrl).get().build();
Call call = client.newCall(request);
call.enqueue(new Callback() {
@Override
public void onFailure(Call call, final IOException e) {
public void onFailure(@NonNull Call call, @NonNull final IOException e) {
LogUtil.updateLog(logId, 0, e.getMessage());
Log.d(TAG, "onFailure" + e.getMessage());
if (handError != null) {
@ -67,14 +71,14 @@ public class SenderQyWxAppMsg extends SenderBaseMsg {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
final String json = response.body().string();
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
final String json = Objects.requireNonNull(response.body()).string();
Log.d(TAG, "Code" + response.code() + " Response: " + json);
JSONObject jsonObject = JSON.parseObject(json);
int errcode = jsonObject.getInteger("errcode");
if (errcode == 0) {
MyApplication.QyWxAccessToken = jsonObject.getString("access_token");
MyApplication.QyWxAccessTokenExpiresIn = System.currentTimeMillis() + (jsonObject.getInteger("expires_in") - 120) * 1000; //提前2分钟过期
MyApplication.QyWxAccessTokenExpiresIn = System.currentTimeMillis() + (jsonObject.getInteger("expires_in") - 120) * 1000L; //提前2分钟过期
Log.d(TAG, "access_token" + MyApplication.QyWxAccessToken);
Log.d(TAG, "expires_in" + MyApplication.QyWxAccessTokenExpiresIn);
@ -133,15 +137,15 @@ public class SenderQyWxAppMsg extends SenderBaseMsg {
Call call = client.newCall(request);
call.enqueue(new Callback() {
@Override
public void onFailure(Call call, final IOException e) {
public void onFailure(@NonNull Call call, @NonNull final IOException e) {
LogUtil.updateLog(logId, 0, e.getMessage());
Toast(handError, TAG, "发送失败:" + e.getMessage());
emitter.onError(new RuntimeException("请求接口异常..."));
}
@Override
public void onResponse(Call call, Response response) throws IOException {
final String responseStr = response.body().string();
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
final String responseStr = Objects.requireNonNull(response.body()).string();
Log.d(TAG, "Response" + response.code() + "" + responseStr);
Toast(handError, TAG, "发送状态:" + responseStr);

View File

@ -3,6 +3,8 @@ package com.idormy.sms.forwarder.sender;
import android.os.Handler;
import android.util.Log;
import androidx.annotation.NonNull;
import com.alibaba.fastjson.JSON;
import com.idormy.sms.forwarder.utils.LogUtil;
import com.idormy.sms.forwarder.utils.SettingUtil;
@ -10,6 +12,7 @@ import com.idormy.sms.forwarder.utils.SettingUtil;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import io.reactivex.rxjava3.core.Observable;
@ -22,9 +25,10 @@ import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
@SuppressWarnings({"rawtypes", "unchecked", "deprecation", "ResultOfMethodCallIgnored"})
public class SenderQyWxGroupRobotMsg extends SenderBaseMsg {
static String TAG = "SenderQyWxGroupRobotMsg";
static final String TAG = "SenderQyWxGroupRobotMsg";
public static void sendMsg(final long logId, final Handler handError, String webHook, String from, String content) throws Exception {
Log.i(TAG, "sendMsg webHook:" + webHook + " from:" + from + " content:" + content);
@ -59,15 +63,15 @@ public class SenderQyWxGroupRobotMsg extends SenderBaseMsg {
Call call = client.newCall(request);
call.enqueue(new Callback() {
@Override
public void onFailure(Call call, final IOException e) {
public void onFailure(@NonNull Call call, @NonNull final IOException e) {
LogUtil.updateLog(logId, 0, e.getMessage());
Toast(handError, TAG, "发送失败:" + e.getMessage());
emitter.onError(new RuntimeException("请求接口异常..."));
}
@Override
public void onResponse(Call call, Response response) throws IOException {
final String responseStr = response.body().string();
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
final String responseStr = Objects.requireNonNull(response.body()).string();
Log.d(TAG, "Response" + response.code() + "" + responseStr);
Toast(handError, TAG, "发送状态:" + responseStr);

View File

@ -3,10 +3,13 @@ package com.idormy.sms.forwarder.sender;
import android.os.Handler;
import android.util.Log;
import androidx.annotation.NonNull;
import com.idormy.sms.forwarder.utils.LogUtil;
import com.idormy.sms.forwarder.utils.SettingUtil;
import java.io.IOException;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import io.reactivex.rxjava3.core.Observable;
@ -19,9 +22,10 @@ import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
@SuppressWarnings("ResultOfMethodCallIgnored")
public class SenderServerChanMsg extends SenderBaseMsg {
static String TAG = "SenderServerChanMsg";
static final String TAG = "SenderServerChanMsg";
public static void sendMsg(final long logId, final Handler handError, final String sendKey, final String title, final String desp) throws Exception {
Log.i(TAG, "sendMsg sendKey:" + sendKey + " title:" + title + " desp:" + desp);
@ -50,15 +54,15 @@ public class SenderServerChanMsg extends SenderBaseMsg {
Call call = client.newCall(request);
call.enqueue(new Callback() {
@Override
public void onFailure(Call call, final IOException e) {
public void onFailure(@NonNull Call call, @NonNull final IOException e) {
LogUtil.updateLog(logId, 0, e.getMessage());
Toast(handError, TAG, "发送失败:" + e.getMessage());
emitter.onError(new RuntimeException("请求接口异常..."));
}
@Override
public void onResponse(Call call, Response response) throws IOException {
final String responseStr = response.body().string();
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
final String responseStr = Objects.requireNonNull(response.body()).string();
Log.d(TAG, "Response" + response.code() + "" + responseStr);
Toast(handError, TAG, "发送状态:" + responseStr);

View File

@ -13,9 +13,10 @@ import java.util.concurrent.TimeUnit;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.ObservableEmitter;
@SuppressWarnings("ResultOfMethodCallIgnored")
public class SenderSmsMsg extends SenderBaseMsg {
static String TAG = "SenderSmsMsg";
static final String TAG = "SenderSmsMsg";
public static void sendMsg(final long logId, final Handler handError, int simSlot, String mobiles, Boolean onlyNoNetwork, String from, String text) throws Exception {
Log.i(TAG, "sendMsg simSlot:" + simSlot + " mobiles:" + mobiles + " onlyNoNetwork:" + onlyNoNetwork + " from:" + from + " text:" + text);

View File

@ -3,6 +3,8 @@ package com.idormy.sms.forwarder.sender;
import android.os.Handler;
import android.util.Log;
import androidx.annotation.NonNull;
import com.alibaba.fastjson.JSON;
import com.idormy.sms.forwarder.utils.LogUtil;
import com.idormy.sms.forwarder.utils.SettingUtil;
@ -10,6 +12,7 @@ import com.idormy.sms.forwarder.utils.SettingUtil;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import io.reactivex.rxjava3.core.Observable;
@ -22,9 +25,10 @@ import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
@SuppressWarnings({"rawtypes", "unchecked", "deprecation", "ResultOfMethodCallIgnored"})
public class SenderTelegramMsg extends SenderBaseMsg {
static String TAG = "SenderTelegramMsg";
static final String TAG = "SenderTelegramMsg";
public static void sendMsg(final long logId, final Handler handError, String apiToken, String chatId, String from, String text) throws Exception {
Log.i(TAG, "sendMsg apiToken:" + apiToken + " chatId:" + chatId + " text:" + text);
@ -62,15 +66,15 @@ public class SenderTelegramMsg extends SenderBaseMsg {
Call call = client.newCall(request);
call.enqueue(new Callback() {
@Override
public void onFailure(Call call, final IOException e) {
public void onFailure(@NonNull Call call, @NonNull final IOException e) {
LogUtil.updateLog(logId, 0, e.getMessage());
Toast(handError, TAG, "发送失败:" + e.getMessage());
emitter.onError(new RuntimeException("请求接口异常..."));
}
@Override
public void onResponse(Call call, Response response) throws IOException {
final String responseStr = response.body().string();
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
final String responseStr = Objects.requireNonNull(response.body()).string();
Log.d(TAG, "Response" + response.code() + "" + responseStr);
Toast(handError, TAG, "发送状态:" + responseStr);

View File

@ -1,5 +1,6 @@
package com.idormy.sms.forwarder.sender;
import android.annotation.SuppressLint;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
@ -14,10 +15,12 @@ import com.idormy.sms.forwarder.utils.DbHelper;
import java.util.ArrayList;
import java.util.List;
@SuppressWarnings({"SynchronizeOnNonFinalField", "UnusedReturnValue", "unused"})
public class SenderUtil {
static String TAG = "SenderUtil";
static final String TAG = "SenderUtil";
static Boolean hasInit = false;
@SuppressLint("StaticFieldLeak")
static Context context;
static DbHelper dbHelper;
static SQLiteDatabase db;
@ -76,7 +79,7 @@ public class SenderUtil {
selectionArgList.add(String.valueOf(id));
}
String[] selectionArgs = selectionArgList.toArray(new String[selectionArgList.size()]);
String[] selectionArgs = selectionArgList.toArray(new String[0]);
// Issue SQL statement.
return db.delete(SenderTable.SenderEntry.TABLE_NAME, selection, selectionArgs);
@ -111,7 +114,7 @@ public class SenderUtil {
selectionArgList.add(key);
selectionArgList.add(key);
}
String[] selectionArgs = selectionArgList.toArray(new String[selectionArgList.size()]);
String[] selectionArgs = selectionArgList.toArray(new String[0]);
// How you want the results sorted in the resulting Cursor
String sortOrder =
@ -174,7 +177,7 @@ public class SenderUtil {
selectionArgList.add(key);
selectionArgList.add(key);
}
String[] selectionArgs = selectionArgList.toArray(new String[selectionArgList.size()]);
String[] selectionArgs = selectionArgList.toArray(new String[0]);
// How you want the results sorted in the resulting Cursor

View File

@ -4,12 +4,16 @@ import android.os.Handler;
import android.util.Base64;
import android.util.Log;
import androidx.annotation.NonNull;
import com.idormy.sms.forwarder.utils.CertUtils;
import com.idormy.sms.forwarder.utils.LogUtil;
import com.idormy.sms.forwarder.utils.SettingUtil;
import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import javax.crypto.Mac;
@ -26,9 +30,10 @@ import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
@SuppressWarnings({"deprecation", "ResultOfMethodCallIgnored"})
public class SenderWebNotifyMsg extends SenderBaseMsg {
static String TAG = "SenderWebNotifyMsg";
static final String TAG = "SenderWebNotifyMsg";
public static void sendMsg(final long logId, final Handler handError, String webServer, String webParams, String secret, String method, String from, String content) throws Exception {
Log.i(TAG, "sendMsg webServer:" + webServer + " webParams:" + webParams + " from:" + from + " content:" + content);
@ -42,8 +47,8 @@ public class SenderWebNotifyMsg extends SenderBaseMsg {
if (secret != null && !secret.isEmpty()) {
String stringToSign = timestamp + "\n" + secret;
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(new SecretKeySpec(secret.getBytes("UTF-8"), "HmacSHA256"));
byte[] signData = mac.doFinal(stringToSign.getBytes("UTF-8"));
mac.init(new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), "HmacSHA256"));
byte[] signData = mac.doFinal(stringToSign.getBytes(StandardCharsets.UTF_8));
sign = URLEncoder.encode(new String(Base64.encode(signData, Base64.NO_WRAP)), "UTF-8");
Log.i(TAG, "sign:" + sign);
}
@ -102,15 +107,15 @@ public class SenderWebNotifyMsg extends SenderBaseMsg {
Call call = client.newCall(request);
call.enqueue(new Callback() {
@Override
public void onFailure(Call call, final IOException e) {
public void onFailure(@NonNull Call call, @NonNull final IOException e) {
LogUtil.updateLog(logId, 0, e.getMessage());
Toast(handError, TAG, "发送失败:" + e.getMessage());
emitter.onError(new RuntimeException("请求接口异常..."));
}
@Override
public void onResponse(Call call, Response response) throws IOException {
final String responseStr = response.body().string();
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
final String responseStr = Objects.requireNonNull(response.body()).string();
Log.d(TAG, "Response" + response.code() + "" + responseStr);
Toast(handError, TAG, "发送状态:" + responseStr);

View File

@ -1,5 +1,6 @@
package com.idormy.sms.forwarder.service;
import android.annotation.SuppressLint;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
@ -11,6 +12,7 @@ import android.util.Log;
import java.text.SimpleDateFormat;
@SuppressWarnings("deprecation")
public class BatteryService extends Service {
private static final String TAG = "BatteryReceiver";
@ -24,9 +26,9 @@ public class BatteryService extends Service {
public void onCreate() {
super.onCreate();
Log.i(TAG, "onCreate--------------");
IntentFilter batteryfilter = new IntentFilter();
batteryfilter.addAction(Intent.ACTION_BATTERY_CHANGED);
registerReceiver(batteryReceiver, batteryfilter);
IntentFilter batteryFilter = new IntentFilter();
batteryFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
registerReceiver(batteryReceiver, batteryFilter);
}
@Override
@ -49,7 +51,8 @@ public class BatteryService extends Service {
}
// 接收电池信息更新的广播
private BroadcastReceiver batteryReceiver = new BroadcastReceiver() {
private final BroadcastReceiver batteryReceiver = new BroadcastReceiver() {
@SuppressWarnings("unused")
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "BatteryReceiver--------------");
@ -96,7 +99,7 @@ public class BatteryService extends Service {
break;
}
SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss:SSS ");
@SuppressLint("SimpleDateFormat") SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss:SSS ");
String date = sDateFormat.format(new java.util.Date());
Log.i(TAG, "battery: date=" + date + ",status " + statusString

View File

@ -1,5 +1,6 @@
package com.idormy.sms.forwarder.service;
import android.annotation.SuppressLint;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
@ -39,6 +40,7 @@ public class FrontService extends Service {
private static final String CHANNEL_ONE_ID = "com.idormy.sms.forwarder";
private static final String CHANNEL_ONE_NAME = "com.idormy.sms.forwarderName";
@SuppressLint("IconColors")
@Override
public void onCreate() {
super.onCreate();
@ -48,11 +50,11 @@ public class FrontService extends Service {
OSUtils.ROM_TYPE romType = OSUtils.getRomType();
//Log.d(TAG, "onCreate: " + romType);
if (romType == OSUtils.ROM_TYPE.MIUI_ROM) {
builder.setContentTitle("短信转发器");
builder.setContentTitle(getString(R.string.app_name));
}
builder.setContentText("根据规则转发到钉钉/微信/邮箱/bark/Server酱/Telegram/webhook等");
builder.setContentText(getString(R.string.notification_content));
Intent intent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity
@SuppressLint("UnspecifiedImmutableFlag") PendingIntent pendingIntent = PendingIntent.getActivity
(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(pendingIntent);

View File

@ -11,6 +11,7 @@ import java.util.Map;
import java.util.Properties;
import java.util.Set;
@SuppressWarnings("rawtypes")
public class BuildProperties {
private static BuildProperties ourInstance;
private final Properties properties;

View File

@ -10,11 +10,10 @@ public class CacheUtil {
/**
* 获取缓存大小
*
* @param context
* @return
* @throws Exception
* @param context 上下文
* @return 缓存大小
*/
public static String getTotalCacheSize(Context context) throws Exception {
public static String getTotalCacheSize(Context context) {
long cacheSize = getFolderSize(context.getCacheDir());
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
cacheSize += getFolderSize(context.getExternalCacheDir());
@ -24,7 +23,7 @@ public class CacheUtil {
/***
* 清理所有缓存
* @param context
* @param context 上下文
*/
public static void clearAllCache(Context context) {
deleteDir(context.getCacheDir());
@ -36,29 +35,32 @@ public class CacheUtil {
private static boolean deleteDir(File dir) {
if (dir != null && dir.isDirectory()) {
String[] children = dir.list();
for (int i = 0; i < children.length; i++) {
boolean success = deleteDir(new File(dir, children[i]));
assert children != null;
for (String child : children) {
boolean success = deleteDir(new File(dir, child));
if (!success) {
return false;
}
}
}
assert dir != null;
return dir.delete();
}
// 获取文件
//Context.getExternalFilesDir() --> SDCard/Android/data/你的应用的包名/files/ 目录一般放一些长时间保存的数据
//Context.getExternalCacheDir() --> SDCard/Android/data/你的应用包名/cache/目录一般存放临时缓存数据
public static long getFolderSize(File file) throws Exception {
public static long getFolderSize(File file) {
long size = 0;
try {
File[] fileList = file.listFiles();
for (int i = 0; i < fileList.length; i++) {
assert fileList != null;
for (File value : fileList) {
// 如果下面还有文件
if (fileList[i].isDirectory()) {
size = size + getFolderSize(fileList[i]);
if (value.isDirectory()) {
size = size + getFolderSize(value);
} else {
size = size + fileList[i].length();
size = size + value.length();
}
}
} catch (Exception e) {
@ -70,8 +72,8 @@ public class CacheUtil {
/**
* 格式化单位
*
* @param size
* @return
* @param size 文件大小
* @return 结果
*/
public static String getFormatSize(double size) {
double kiloByte = size / 1024;

View File

@ -1,5 +1,7 @@
package com.idormy.sms.forwarder.utils;
import android.annotation.SuppressLint;
import java.security.KeyStore;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
@ -29,10 +31,12 @@ public class CertUtils {
private static TrustManager[] getTrustManager() {
return new TrustManager[]{
new X509TrustManager() {
@SuppressLint("TrustAllX509TrustManager")
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) {
}
@SuppressLint("TrustAllX509TrustManager")
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) {
}

View File

@ -0,0 +1,191 @@
package com.idormy.sms.forwarder.utils;
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.provider.ContactsContract;
import com.idormy.sms.forwarder.model.PhoneBookEntity;
import java.util.ArrayList;
import java.util.List;
/**
* 获取联系人工具类
*/
@SuppressWarnings("unused")
public class ContactHelper {
private static final String[] PROJECTION = new String[]{
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER
};
private final List<PhoneBookEntity> contacts = new ArrayList<>();
private ContactHelper() {
}
public static ContactHelper getInstance() {
return InstanceHolder.INSTANCE;
}
private static class InstanceHolder {
private static final ContactHelper INSTANCE = new ContactHelper();
}
/**
* 获取所有联系人
*
* @param context 上下文
* @return 联系人集合
*/
public List<PhoneBookEntity> getContacts(Context context) {
contacts.clear();
ContentResolver cr = context.getContentResolver();
try (Cursor cursor = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, PROJECTION, null, null, "sort_key")) {
if (cursor != null) {
final int displayNameIndex = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
final int mobileNoIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
String mobileNo, displayName;
while (cursor.moveToNext()) {
mobileNo = cursor.getString(mobileNoIndex);
displayName = cursor.getString(displayNameIndex);
contacts.add(new PhoneBookEntity(displayName, mobileNo));
}
}
} catch (Exception e) {
e.printStackTrace();
}
return contacts;
}
/**
* 通过姓名获取联系人
*
* @param context 上下文
* @param contactName 联系人姓名
* @return 联系人集合
*/
public List<PhoneBookEntity> getContactByName(Context context, String contactName) {
contacts.clear();
ContentResolver cr = context.getContentResolver();
String selection = ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " like ? ";
String[] selectionArgs = new String[]{"%" + contactName + "%"};
try (Cursor cursor = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, PROJECTION, selection, selectionArgs, "sort_key")) {
if (cursor != null) {
final int displayNameIndex = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
final int mobileNoIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
String mobileNo, displayName;
while (cursor.moveToNext()) {
mobileNo = cursor.getString(mobileNoIndex);
displayName = cursor.getString(displayNameIndex);
contacts.add(new PhoneBookEntity(displayName, mobileNo));
}
}
} catch (Exception e) {
e.printStackTrace();
}
return contacts;
}
/**
* 通过手机号获取联系人
*
* @param context 上下文
* @param phoneNum 手机号码
* @return 联系人集合
*/
public List<PhoneBookEntity> getContactByNumber(Context context, String phoneNum) {
contacts.clear();
Cursor cursor = null;
if (phoneNum.length() < 11) {
return null;
}
try {
ContentResolver cr = context.getContentResolver();
String selection = ContactsContract.CommonDataKinds.Phone.NUMBER + " in(?,?,?) ";
String phone1 = phoneNum.subSequence(0, 3) + " " + phoneNum.substring(3, 7) +
" " + phoneNum.substring(7, 11);
String phone2 = phoneNum.subSequence(0, 3) + "-" + phoneNum.substring(3, 7) +
"-" + phoneNum.substring(7, 11);
String[] selectionArgs = new String[]{phoneNum, phone1, phone2};
cursor = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, PROJECTION, selection, selectionArgs, "sort_key");
if (cursor != null) {
final int displayNameIndex = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
final int mobileNoIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
String mobileNo, displayName;
while (cursor.moveToNext()) {
mobileNo = cursor.getString(mobileNoIndex);
displayName = cursor.getString(displayNameIndex);
contacts.add(new PhoneBookEntity(displayName, mobileNo));
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (cursor != null) {
cursor.close();
}
}
return contacts;
}
/**
* 分页查询联系人
*
* @param context 上下文
* @param page 页数
* @param pageSize 每页数据量
* @return 联系人集合
*/
public List<PhoneBookEntity> getContactsByPage(Context context, int page, int pageSize) {
contacts.clear();
Cursor cursor = null;
ContentResolver cr = context.getContentResolver();
try {
String sortOrder = "_id limit " + page + "," + pageSize;
cursor = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, PROJECTION, null, null, sortOrder);
if (cursor != null) {
final int displayNameIndex = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
final int mobileNoIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
String mobileNo, displayName;
while (cursor.moveToNext()) {
mobileNo = cursor.getString(mobileNoIndex);
displayName = cursor.getString(displayNameIndex);
contacts.add(new PhoneBookEntity(displayName, mobileNo));
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (cursor != null) {
cursor.close();
}
}
return contacts;
}
/**
* 获取联系人总数
*
* @param context 上下文
* @return 数量
*/
public int getContactCount(Context context) {
ContentResolver cr = context.getContentResolver();
try (Cursor cursor = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, PROJECTION, null, null, "sort_key")) {
if (cursor != null) {
return cursor.getCount();
}
} catch (Exception e) {
e.printStackTrace();
}
return 0;
}
}

View File

@ -12,6 +12,7 @@ import com.idormy.sms.forwarder.model.SenderTable;
import java.util.Arrays;
import java.util.List;
@SuppressWarnings("unused")
public class DbHelper extends SQLiteOpenHelper {
// If you change the database schema, you must increment the database version.
public static final String TAG = "DbHelper";

View File

@ -1,22 +1,24 @@
package com.idormy.sms.forwarder.utils;
public class Define {
public static String SP_CONFIG = "forwarder_config";
public static String SP_CONFIG_SWITCH_HELP_TIP = "forwarder_config_switch_help_tip";
public static final String SP_CONFIG = "forwarder_config";
public static final String SP_CONFIG_SWITCH_HELP_TIP = "forwarder_config_switch_help_tip";
public static String SP_MSG_KEY_SWITCH_ADD_EXTRA = "tsms_msg_key_switch_add_extra";
public static String SP_MSG_KEY_STRING_ADD_EXTRA_DEVICE_MARK = "tsms_msg_key_string_add_extra_device_mark";
public static String SP_MSG_KEY_STRING_ADD_EXTRA_SIM1 = "tsms_msg_key_string_add_extra_sim1";
public static String SP_MSG_KEY_STRING_ADD_EXTRA_SIM2 = "tsms_msg_key_string_add_extra_sim2";
public static String SP_MSG_KEY_SWITCH_SMS_TEMPLATE = "tsms_msg_key_switch_sms_template";
public static String SP_MSG_KEY_STRING_SMS_TEMPLATE = "tsms_msg_key_string_sms_template";
public static String SP_MSG_KEY_STRING_BATTERY_LEVEL_ALARM = "tsms_msg_key_string_battery_level_alarm";
public static String SP_MSG_KEY_STRING_RETRY_DELAY_TIME1 = "tsms_msg_key_string_retry_delay_time1";
public static String SP_MSG_KEY_STRING_RETRY_DELAY_TIME2 = "tsms_msg_key_string_retry_delay_time2";
public static String SP_MSG_KEY_STRING_RETRY_DELAY_TIME3 = "tsms_msg_key_string_retry_delay_time3";
public static String SP_MSG_KEY_STRING_RETRY_DELAY_TIME4 = "tsms_msg_key_string_retry_delay_time4";
public static String SP_MSG_KEY_STRING_RETRY_DELAY_TIME5 = "tsms_msg_key_string_retry_delay_time5";
public static final String SP_MSG_KEY_SWITCH_ADD_EXTRA = "tsms_msg_key_switch_add_extra";
public static final String SP_MSG_KEY_STRING_ADD_EXTRA_DEVICE_NAME = "tsms_msg_key_switch_add_extra_device_name";
public static final String SP_MSG_KEY_STRING_ENABLE_PHONE = "tsms_msg_key_switch_enable_phone";
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";
public static final String SP_MSG_KEY_SWITCH_SMS_TEMPLATE = "tsms_msg_key_switch_sms_template";
public static final String SP_MSG_KEY_STRING_SMS_TEMPLATE = "tsms_msg_key_string_sms_template";
public static final String SP_MSG_KEY_STRING_BATTERY_LEVEL_ALARM = "tsms_msg_key_string_battery_level_alarm";
public static final String SP_MSG_KEY_STRING_RETRY_DELAY_TIME1 = "tsms_msg_key_string_retry_delay_time1";
public static final String SP_MSG_KEY_STRING_RETRY_DELAY_TIME2 = "tsms_msg_key_string_retry_delay_time2";
public static final String SP_MSG_KEY_STRING_RETRY_DELAY_TIME3 = "tsms_msg_key_string_retry_delay_time3";
public static final String SP_MSG_KEY_STRING_RETRY_DELAY_TIME4 = "tsms_msg_key_string_retry_delay_time4";
public static final String SP_MSG_KEY_STRING_RETRY_DELAY_TIME5 = "tsms_msg_key_string_retry_delay_time5";
public static String SP_MSG = "forwarder_msg";
public static String SP_MSG_SET_KEY = "forwarder_msg_set_key";
public static final String SP_MSG = "forwarder_msg";
public static final String SP_MSG_SET_KEY = "forwarder_msg_set_key";
}

View File

@ -10,6 +10,7 @@ import java.util.Map;
/**
* app版本更新接口
*/
@SuppressWarnings("unused")
public interface HttpI extends Serializable {
/**
* 异步get

View File

@ -1,15 +1,19 @@
package com.idormy.sms.forwarder.utils;
import android.annotation.SuppressLint;
import android.content.Context;
import android.util.Log;
@SuppressWarnings("SynchronizeOnNonFinalField")
public class InitUtil {
static Boolean hasInit = false;
private static String TAG = "InitUtil";
private static final String TAG = "InitUtil";
@SuppressLint("StaticFieldLeak")
private static Context context = null;
public static void init(Context context1) {
Log.d(TAG, "TMSG init");
Log.d(TAG, "SmsForwarder init");
//noinspection SynchronizeOnNonFinalField
synchronized (hasInit) {
if (hasInit) return;
hasInit = true;

View File

@ -1,5 +1,6 @@
package com.idormy.sms.forwarder.utils;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
@ -15,7 +16,7 @@ public class KeepAliveUtils {
public static boolean isIgnoreBatteryOptimization(Activity activity) {
PowerManager powerManager = (PowerManager) activity.getSystemService(Context.POWER_SERVICE);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M && powerManager != null) {
if (powerManager != null) {
return powerManager.isIgnoringBatteryOptimizations(activity.getPackageName());
} else {
return true;
@ -26,7 +27,7 @@ public class KeepAliveUtils {
if (isIgnoreBatteryOptimization(activity)) {
return;
}
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
@SuppressLint("BatteryLife") Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
intent.setData(Uri.parse("package:" + activity.getPackageName()));
ResolveInfo resolveInfo = activity.getPackageManager().resolveActivity(intent, 0);
if (resolveInfo != null) {

View File

@ -1,5 +1,6 @@
package com.idormy.sms.forwarder.utils;
import android.annotation.SuppressLint;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
@ -19,15 +20,18 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@SuppressWarnings("UnusedReturnValue")
public class LogUtil {
static String TAG = "LogUtil";
static final String TAG = "LogUtil";
static Boolean hasInit = false;
@SuppressLint("StaticFieldLeak")
static Context context;
static DbHelper dbHelper;
static SQLiteDatabase db;
public static void init(Context context1) {
//noinspection SynchronizeOnNonFinalField
synchronized (hasInit) {
if (hasInit) return;
hasInit = true;
@ -56,7 +60,7 @@ public class LogUtil {
return db.insert(LogTable.LogEntry.TABLE_NAME, null, values);
}
public static int delLog(Long id, String key) {
public static void delLog(Long id, String key) {
// Define 'where' part of query.
String selection = " 1 ";
// Specify arguments in placeholder order.
@ -66,7 +70,6 @@ public class LogUtil {
selection += " and " + LogTable.LogEntry._ID + " = ? ";
// Specify arguments in placeholder order.
selectionArgList.add(String.valueOf(id));
}
if (key != null) {
@ -76,9 +79,9 @@ public class LogUtil {
selectionArgList.add(key);
selectionArgList.add(key);
}
String[] selectionArgs = selectionArgList.toArray(new String[selectionArgList.size()]);
String[] selectionArgs = selectionArgList.toArray(new String[0]);
// Issue SQL statement.
return db.delete(LogTable.LogEntry.TABLE_NAME, selection, selectionArgs);
db.delete(LogTable.LogEntry.TABLE_NAME, selection, selectionArgs);
}
@ -93,7 +96,7 @@ public class LogUtil {
values.put(LogTable.LogEntry.COLUMN_NAME_FORWARD_STATUS, forward_status);
values.put(LogTable.LogEntry.COLUMN_NAME_FORWARD_RESPONSE, forward_response);
String[] selectionArgs = selectionArgList.toArray(new String[selectionArgList.size()]);
String[] selectionArgs = selectionArgList.toArray(new String[0]);
return db.update(LogTable.LogEntry.TABLE_NAME, values, selection, selectionArgs);
}
@ -134,7 +137,7 @@ public class LogUtil {
selectionArgList.add(key);
selectionArgList.add(key);
}
String[] selectionArgs = selectionArgList.toArray(new String[selectionArgList.size()]);
String[] selectionArgs = selectionArgList.toArray(new String[0]);
// How you want the results sorted in the resulting Cursor
String sortOrder =
@ -160,9 +163,9 @@ public class LogUtil {
Log.d(TAG, "getLog: itemId cursor" + Arrays.toString(cursor.getColumnNames()));
while (cursor.moveToNext()) {
try {
Long itemid = cursor.getLong(
Long itemId = cursor.getLong(
cursor.getColumnIndexOrThrow(BaseColumns._ID));
String itemfrom = cursor.getString(
String itemFrom = cursor.getString(
cursor.getColumnIndexOrThrow(LogTable.LogEntry.COLUMN_NAME_FROM));
String content = cursor.getString(
cursor.getColumnIndexOrThrow(LogTable.LogEntry.COLUMN_NAME_CONTENT));
@ -184,14 +187,14 @@ public class LogUtil {
cursor.getColumnIndexOrThrow(RuleTable.RuleEntry.COLUMN_NAME_SIM_SLOT));
String senderName = cursor.getString(
cursor.getColumnIndexOrThrow(SenderTable.SenderEntry.COLUMN_NAME_NAME));
Integer senderType = cursor.getInt(
int senderType = cursor.getInt(
cursor.getColumnIndexOrThrow(SenderTable.SenderEntry.COLUMN_NAME_TYPE));
String rule = RuleModel.getRuleMatch(ruleFiled, ruleCheck, ruleValue, ruleSimSlot);
if (senderName != null) rule += senderName.trim();
int senderImageId = SenderModel.getImageId(senderType);
LogVo logVo = new LogVo(itemid, itemfrom, content, simInfo, time, rule, senderImageId, forwardStatus, forwardResponse);
LogVo logVo = new LogVo(itemId, itemFrom, content, simInfo, time, rule, senderImageId, forwardStatus, forwardResponse);
LogVos.add(logVo);
} catch (Exception e) {
Log.e(TAG, "getLog e:" + e.getMessage());

View File

@ -1,5 +1,6 @@
package com.idormy.sms.forwarder.utils;
import android.annotation.SuppressLint;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
@ -11,13 +12,15 @@ public class NetUtil {
//移动网络
private static final int NETWORK_MOBILE = 1;
//无线网络
private static final int NETWORW_WIFI = 2;
private static final int NETWORK_WIFI = 2;
static Boolean hasInit = false;
@SuppressLint("StaticFieldLeak")
static Context context;
public static void init(Context context1) {
//noinspection SynchronizeOnNonFinalField
synchronized (hasInit) {
if (hasInit) return;
hasInit = true;
@ -37,7 +40,7 @@ public class NetUtil {
if (activeNetworkInfo.getType() == (ConnectivityManager.TYPE_WIFI)) {
//返回无线网络
Toast.makeText(context, "当前处于无线网络", Toast.LENGTH_SHORT).show();
return NETWORW_WIFI;
return NETWORK_WIFI;
//判断是否移动网络
} else if (activeNetworkInfo.getType() == (ConnectivityManager.TYPE_MOBILE)) {
Toast.makeText(context, "当前处于移动网络", Toast.LENGTH_SHORT).show();

View File

@ -53,18 +53,16 @@ public class OSUtils {
//EMUI标识
private static final String KEY_EMUI_VERSION_CODE = "ro.build.version.emui";
//Flyme标识
private static final String KEY_FLYME_ID_FALG_KEY = "ro.build.display.id";
private static final String KEY_FLYME_ID_FALG_VALUE_KEYWORD = "Flyme";
private static final String KEY_FLYME_ICON_FALG = "persist.sys.use.flyme.icon";
private static final String KEY_FLYME_SETUP_FALG = "ro.meizu.setupwizard.flyme";
private static final String KEY_FLYME_PUBLISH_FALG = "ro.flyme.published";
private static final String KEY_FLYME_ID_FLAG_KEY = "ro.build.display.id";
private static final String KEY_FLYME_ID_FLAG_VALUE_KEYWORD = "Flyme";
private static final String KEY_FLYME_ICON_FLAG = "persist.sys.use.flyme.icon";
private static final String KEY_FLYME_SETUP_FLAG = "ro.meizu.setupwizard.flyme";
private static final String KEY_FLYME_PUBLISH_FLAG = "ro.flyme.published";
/**
* @param
* 获取ROM类型MIUI_ROM, *FLYME_ROM, * EMUI_ROM, * OTHER_ROM
*
* @return ROM_TYPE ROM类型的枚举
* @datecreate at 2016/5/11 0011 9:46
* @mehtodgetRomType
* @description获取ROM类型MIUI_ROM, *FLYME_ROM, * EMUI_ROM, * OTHER_ROM
*/
public static ROM_TYPE getRomType() {
ROM_TYPE rom_type = ROM_TYPE.OTHER_ROM;
@ -76,12 +74,12 @@ public class OSUtils {
if (buildProperties.containsKey(KEY_MIUI_VERSION_CODE) || buildProperties.containsKey(KEY_MIUI_VERSION_NAME)) {
return ROM_TYPE.MIUI_ROM;
}
if (buildProperties.containsKey(KEY_FLYME_ICON_FALG) || buildProperties.containsKey(KEY_FLYME_SETUP_FALG) || buildProperties.containsKey(KEY_FLYME_PUBLISH_FALG)) {
if (buildProperties.containsKey(KEY_FLYME_ICON_FLAG) || buildProperties.containsKey(KEY_FLYME_SETUP_FLAG) || buildProperties.containsKey(KEY_FLYME_PUBLISH_FLAG)) {
return ROM_TYPE.FLYME_ROM;
}
if (buildProperties.containsKey(KEY_FLYME_ID_FALG_KEY)) {
String romName = buildProperties.getProperty(KEY_FLYME_ID_FALG_KEY);
if (!TextUtils.isEmpty(romName) && romName.contains(KEY_FLYME_ID_FALG_VALUE_KEYWORD)) {
if (buildProperties.containsKey(KEY_FLYME_ID_FLAG_KEY)) {
String romName = buildProperties.getProperty(KEY_FLYME_ID_FLAG_KEY);
if (!TextUtils.isEmpty(romName) && romName.contains(KEY_FLYME_ID_FLAG_VALUE_KEYWORD)) {
return ROM_TYPE.FLYME_ROM;
}
}

View File

@ -24,15 +24,17 @@ import java.io.File;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
@SuppressWarnings({"deprecation", "rawtypes", "unchecked", "CommentedOutCode", "SynchronizeOnNonFinalField", "unused", "SameReturnValue"})
public class PhoneUtils {
static Boolean hasInit = false;
@SuppressLint("StaticFieldLeak")
static Context context;
private static String TAG = "PhoneUtils";
private static final String TAG = "PhoneUtils";
/**
* 构造类
@ -109,7 +111,7 @@ public class PhoneUtils {
} catch (Exception ignored) {
}
return getUniquePsuedoID();
return getUniquePseudoID();
}
/**
@ -118,7 +120,7 @@ public class PhoneUtils {
*
* @return 伪唯一ID
*/
public static String getUniquePsuedoID() {
public static String getUniquePseudoID() {
String m_szDevIDShort = "35" +
Build.BOARD.length() % 10 + Build.BRAND.length() % 10 +
Build.CPU_ABI.length() % 10 + Build.DEVICE.length() % 10 +
@ -130,7 +132,7 @@ public class PhoneUtils {
String serial;
try {
serial = android.os.Build.class.getField("SERIAL").get(null).toString();
serial = Objects.requireNonNull(Build.class.getField("SERIAL").get(null)).toString();
return new UUID(m_szDevIDShort.hashCode(), serial.hashCode()).toString();
} catch (Exception e) {
//获取失败使用AndroidId
@ -217,10 +219,10 @@ public class PhoneUtils {
public static String getSimSerialNumber() {
try {
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
String serialNumber = tm != null ? tm.getSimSerialNumber() : null;
@SuppressLint("HardwareIds") String serialNumber = tm != null ? tm.getSimSerialNumber() : null;
return serialNumber != null ? serialNumber : "";
} catch (Exception e) {
} catch (Exception ignored) {
}
return "";
@ -247,7 +249,7 @@ public class PhoneUtils {
*
* @return 电话号码
*/
@SuppressLint("MissingPermission")
@SuppressLint({"MissingPermission", "HardwareIds"})
public static String getPhoneNumber() {
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
try {
@ -280,7 +282,7 @@ public class PhoneUtils {
}
}
try {
count = Integer.parseInt(getReflexMethod(context, "getPhoneCount"));
count = Integer.parseInt(getReflexMethod(context));
} catch (MethodNotFoundException ignored) {
}
return count;
@ -334,9 +336,7 @@ public class PhoneUtils {
List<SubscriptionInfo> activeSubscriptionInfoList = null;
if (mSubscriptionManager != null) {
try {
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
//TODO
}
ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE);
activeSubscriptionInfoList = mSubscriptionManager.getActiveSubscriptionInfoList();
} catch (Exception ignored) {
}
@ -414,10 +414,10 @@ public class PhoneUtils {
String imsi = null;
try {
imsi = getReflexMethodWithId(context, "getSubscriberId", String.valueOf(i));
} catch (MethodNotFoundException ignored) {
Log.d(TAG, String.valueOf(ignored));
} catch (MethodNotFoundException e) {
Log.d(TAG, String.valueOf(e));
}
if (!TextUtils.isEmpty(imsi) && !imsi.equals(getIMSI())) {
if (!TextUtils.isEmpty(imsi) && !Objects.equals(imsi, getIMSI())) {
return imsi;
}
}
@ -456,23 +456,22 @@ public class PhoneUtils {
/**
* 通过反射调取@hide的方法
*
* @param predictedMethodName 方法名
* @return 返回方法调用的结果
* @throws MethodNotFoundException 方法没有找到
*/
private static String getReflexMethod(Context context, String predictedMethodName) throws MethodNotFoundException {
private static String getReflexMethod(Context context) throws MethodNotFoundException {
String result = null;
TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
try {
Class<?> telephonyClass = Class.forName(telephony.getClass().getName());
Method getSimID = telephonyClass.getMethod(predictedMethodName);
Method getSimID = telephonyClass.getMethod("getPhoneCount");
Object ob_phone = getSimID.invoke(telephony);
if (ob_phone != null) {
result = ob_phone.toString();
}
} catch (Exception e) {
Log.d(TAG, String.valueOf(e.fillInStackTrace()));
throw new MethodNotFoundException(predictedMethodName);
throw new MethodNotFoundException("getPhoneCount");
}
return result;
}
@ -517,8 +516,7 @@ public class PhoneUtils {
public static List removeDuplicateWithOrder(List list) {
Set set = new HashSet();
List newList = new ArrayList();
for (Iterator iter = list.iterator(); iter.hasNext(); ) {
Object element = iter.next();
for (Object element : list) {
if (set.add(element))
newList.add(element);
}
@ -601,15 +599,13 @@ public class PhoneUtils {
/**
* 通过 IMEI 判断是否相等
*
* @param obj
* @return
*/
@Override
public boolean equals(Object obj) {
return obj != null && obj instanceof SimInfo && (TextUtils.isEmpty(((SimInfo) obj).mImei) || ((SimInfo) obj).mImei.equals(mImei));
return obj instanceof SimInfo && (TextUtils.isEmpty(((SimInfo) obj).mImei) || ((SimInfo) obj).mImei.equals(mImei));
}
@NonNull
@Override
public String toString() {
return "SimInfo{" +

View File

@ -3,6 +3,8 @@ package com.idormy.sms.forwarder.utils;
import android.util.Log;
import androidx.annotation.NonNull;
import com.idormy.sms.forwarder.model.vo.SmsVo;
import java.util.ArrayList;
@ -10,6 +12,7 @@ import java.util.List;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
@SuppressWarnings("unused")
class RuleLine {
public static final String CONJUNCTION_AND = "并且";
public static final String CONJUNCTION_OR = "或者";
@ -23,11 +26,11 @@ class RuleLine {
public static final String CHECK_START_WITH = "开头";
public static final String CHECK_END_WITH = "结尾";
public static final String CHECK_REGEX = "正则";
public static List<String> CONJUNCTION_LIST = new ArrayList<String>();
public static List<String> FILED_LIST = new ArrayList<String>();
public static List<String> SURE_LIST = new ArrayList<String>();
public static List<String> CHECK_LIST = new ArrayList<String>();
static String TAG = "RuleLine";
public static final List<String> CONJUNCTION_LIST = new ArrayList<>();
public static final List<String> FILED_LIST = new ArrayList<>();
public static final List<String> SURE_LIST = new ArrayList<>();
public static final List<String> CHECK_LIST = new ArrayList<>();
static final String TAG = "RuleLine";
static Boolean STARTLOG = true;
static {
@ -71,8 +74,8 @@ class RuleLine {
String check;
String value;
public RuleLine(String line, int linenum, RuleLine beforeRuleLine) throws Exception {
logg("----------" + linenum + "-----------------");
public RuleLine(String line, int lineNum, RuleLine beforeRuleLine) throws Exception {
logg("----------" + lineNum + "-----------------");
logg(line);
//规则检验
//并且 手机号 相等 10086
@ -85,7 +88,7 @@ class RuleLine {
//标记3个阶段
boolean isCountHeading = false;
boolean isDealMiddel = false;
boolean isDealMiddle = false;
boolean isDealValue = false;
//用于保存4个中间体 并且, , 内容, 包含
@ -107,44 +110,41 @@ class RuleLine {
isCountHeading = true;
} else {
//直接进入处理中间体阶段
isCountHeading = false;
isDealMiddel = true;
logg("start to isDealMiddel:");
isDealMiddle = true;
logg("start to isDealMiddle:");
}
}
//正在数空格头但是遇到非空格阶段变更:由处理空头阶段 变为 处理 中间体阶段
if (isCountHeading && (!" ".equals(w))) {
logg("isCountHeading to isDealMiddel:");
logg("isCountHeading to isDealMiddle:");
isCountHeading = false;
isDealMiddel = true;
isDealMiddle = true;
}
//正在处理中间体中间体数量够了阶段变更由处理中间体 变为 处理 value
if (isDealMiddel && middleList.size() == 4) {
logg("isDealMiddel done middleList:" + middleList);
logg("isDealMiddel to isDealValue:");
isDealMiddel = false;
if (isDealMiddle && middleList.size() == 4) {
logg("isDealMiddle done middleList:" + middleList);
logg("isDealMiddle to isDealValue:");
isDealMiddle = false;
isDealValue = true;
}
logg("isCountHeading:" + isCountHeading);
logg("isDealMiddel:" + isDealMiddel);
logg("isDealMiddle:" + isDealMiddle);
logg("isDealValue:" + isDealValue);
if (isCountHeading) {
if (" ".equals(w)) {
logg("headSpaceNum++:" + headSpaceNum);
headSpaceNum++;
}
logg("headSpaceNum++:" + headSpaceNum);
headSpaceNum++;
}
if (isDealMiddel) {
if (isDealMiddle) {
//遇到空格
if (" ".equals(w)) {
if (buildMiddleWord.length() == 0) {
throw new Exception(linenum + "行:语法错误不允许出现连续空格!");
throw new Exception(lineNum + "行:语法错误不允许出现连续空格!");
} else {
//生成了一个中间体
middleList.add(buildMiddleWord.toString());
@ -170,7 +170,7 @@ class RuleLine {
if (middleList.size() != 4) {
throw new Exception(linenum + "行配置错误每行必须有4段组成例如 并且 手机号 是 相等 ");
throw new Exception(lineNum + "行配置错误每行必须有4段组成例如 并且 手机号 是 相等 ");
}
@ -232,19 +232,19 @@ class RuleLine {
this.value = valueBuilder.toString();
if (!CONJUNCTION_LIST.contains(this.conjunction)) {
throw new Exception(linenum + "行配置错误:连接词只支持:" + CONJUNCTION_LIST + " 但提供了" + this.conjunction);
throw new Exception(lineNum + "行配置错误:连接词只支持:" + CONJUNCTION_LIST + " 但提供了" + this.conjunction);
}
if (!FILED_LIST.contains(this.field)) {
throw new Exception(linenum + "行配置错误:字段只支持:" + FILED_LIST + " 但提供了" + this.field);
throw new Exception(lineNum + "行配置错误:字段只支持:" + FILED_LIST + " 但提供了" + this.field);
}
if (!SURE_LIST.contains(this.sure)) {
throw new Exception(linenum + "行配置错误 " + this.sure + " 确认词只支持:" + SURE_LIST + " 但提供了" + this.sure);
throw new Exception(lineNum + "行配置错误 " + this.sure + " 确认词只支持:" + SURE_LIST + " 但提供了" + this.sure);
}
if (!CHECK_LIST.contains(this.check)) {
throw new Exception(linenum + "行配置错误:比较词只支持:" + CHECK_LIST + " 但提供了" + this.check);
throw new Exception(lineNum + "行配置错误:比较词只支持:" + CHECK_LIST + " 但提供了" + this.check);
}
logg("----------" + linenum + "==" + this);
logg("----------" + lineNum + "==" + this);
}
@ -282,7 +282,6 @@ class RuleLine {
//整合肯定词
switch (this.sure) {
case SURE_YES:
mixChecked = mixChecked;
break;
case SURE_NOT:
mixChecked = !mixChecked;
@ -311,6 +310,11 @@ class RuleLine {
checked = msgValue.contains(this.value);
}
break;
case CHECK_NOT_CONTAIN:
if (msgValue != null) {
checked = !msgValue.contains(this.value);
}
break;
case CHECK_START_WITH:
if (msgValue != null) {
checked = msgValue.startsWith(this.value);
@ -326,7 +330,6 @@ class RuleLine {
try {
checked = Pattern.matches(this.value, msgValue);
} catch (PatternSyntaxException e) {
checked = false;
logg("PatternSyntaxException: ");
logg("Description: " + e.getDescription());
logg("Index: " + e.getIndex());
@ -344,6 +347,7 @@ class RuleLine {
}
@NonNull
@Override
public String toString() {
return "RuleLine{" +

View File

@ -1,5 +1,8 @@
package com.idormy.sms.forwarder.utils;
import static com.idormy.sms.forwarder.utils.RuleLine.CONJUNCTION_AND;
import static com.idormy.sms.forwarder.utils.RuleLine.CONJUNCTION_OR;
import android.util.Log;
import com.idormy.sms.forwarder.model.vo.SmsVo;
@ -7,11 +10,9 @@ import com.idormy.sms.forwarder.model.vo.SmsVo;
import java.util.Date;
import java.util.Scanner;
import static com.idormy.sms.forwarder.utils.RuleLine.CONJUNCTION_AND;
import static com.idormy.sms.forwarder.utils.RuleLine.CONJUNCTION_OR;
@SuppressWarnings("unused")
public class RuleLineUtils {
static String TAG = "RuleLineUtils";
static final String TAG = "RuleLineUtils";
static Boolean STARTLOG = false;
public static void main(String[] args) throws Exception {
@ -41,16 +42,16 @@ public class RuleLineUtils {
Scanner scanner = new Scanner(RuleLines);
int linenum = 0;
int lineNum = 0;
RuleLine headRuleLine = null;
RuleLine beforeRuleLine = null;
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
logg(linenum + " : " + line);
logg(lineNum + " : " + line);
//第一行
if (linenum == 0) {
if (lineNum == 0) {
//第一行不允许缩进
if (line.startsWith(" ")) {
throw new Exception("第一行不允许缩进");
@ -60,14 +61,15 @@ public class RuleLineUtils {
// process the line
beforeRuleLine = RuleLineUtils.generateRuleTree(line, linenum, beforeRuleLine);
if (linenum == 0) {
beforeRuleLine = RuleLineUtils.generateRuleTree(line, lineNum, beforeRuleLine);
if (lineNum == 0) {
headRuleLine = beforeRuleLine;
}
linenum++;
lineNum++;
}
assert headRuleLine != null;
return checkRuleTree(msg, headRuleLine);
}

View File

@ -1,5 +1,6 @@
package com.idormy.sms.forwarder.utils;
import android.annotation.SuppressLint;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
@ -13,9 +14,11 @@ import com.idormy.sms.forwarder.model.RuleTable;
import java.util.ArrayList;
import java.util.List;
@SuppressWarnings({"UnusedReturnValue", "SynchronizeOnNonFinalField"})
public class RuleUtil {
static String TAG = "RuleUtil";
static final String TAG = "RuleUtil";
static Boolean hasInit = false;
@SuppressLint("StaticFieldLeak")
static Context context;
static DbHelper dbHelper;
static SQLiteDatabase db;
@ -75,7 +78,7 @@ public class RuleUtil {
selectionArgList.add(String.valueOf(id));
}
String[] selectionArgs = selectionArgList.toArray(new String[selectionArgList.size()]);
String[] selectionArgs = selectionArgList.toArray(new String[0]);
// Issue SQL statement.
return db.delete(RuleTable.RuleEntry.TABLE_NAME, selection, selectionArgs);
@ -114,7 +117,7 @@ public class RuleUtil {
// Specify arguments in placeholder order.
selectionArgList.add(key);
}
String[] selectionArgs = selectionArgList.toArray(new String[selectionArgList.size()]);
String[] selectionArgs = selectionArgList.toArray(new String[0]);
// How you want the results sorted in the resulting Cursor
String sortOrder =

View File

@ -5,10 +5,12 @@ import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;
@SuppressWarnings({"SynchronizeOnNonFinalField", "unused"})
public class SettingUtil {
static Boolean hasInit = false;
private static String TAG = "SettingUtil";
private static final String TAG = "SettingUtil";
private static SharedPreferences sp_setting = null;
@SuppressWarnings("FieldCanBeLocal")
private static Context context = null;
public static void init(Context context1) {
@ -32,6 +34,27 @@ public class SettingUtil {
return sp_setting.getBoolean(Define.SP_MSG_KEY_SWITCH_ADD_EXTRA, false);
}
public static void switchAddDeviceName(Boolean switchAddDeviceName) {
Log.d(TAG, "switchAddDeviceName :" + switchAddDeviceName);
sp_setting.edit()
.putBoolean(Define.SP_MSG_KEY_STRING_ADD_EXTRA_DEVICE_NAME, switchAddDeviceName)
.apply();
}
public static boolean getSwitchAddDeviceName() {
return sp_setting.getBoolean(Define.SP_MSG_KEY_STRING_ADD_EXTRA_DEVICE_NAME, false);
}
public static void switchEnablePhone(Boolean enable) {
sp_setting.edit()
.putBoolean(Define.SP_MSG_KEY_STRING_ENABLE_PHONE, enable)
.apply();
}
public static boolean getSwitchEnablePhone() {
return sp_setting.getBoolean(Define.SP_MSG_KEY_STRING_ENABLE_PHONE, true);
}
public static void switchSmsTemplate(Boolean switchSmsTemplate) {
Log.d(TAG, "switchSmsTemplate :" + switchSmsTemplate);
sp_setting.edit()
@ -100,8 +123,7 @@ public class SettingUtil {
}
public static String getBatteryLevelAlarm() {
String res = sp_setting.getString(Define.SP_MSG_KEY_STRING_BATTERY_LEVEL_ALARM, "");
return res;
return sp_setting.getString(Define.SP_MSG_KEY_STRING_BATTERY_LEVEL_ALARM, "");
}
public static void setBatteryLevelAlarm(String battery_level) {
@ -112,7 +134,7 @@ public class SettingUtil {
}
public static boolean saveMsgHistory() {
return sp_setting.getBoolean("option_save_history_on", false);
return !sp_setting.getBoolean("option_save_history_on", false);
}
//接口请求失败重试

View File

@ -6,8 +6,9 @@ import android.util.Log;
import com.idormy.sms.forwarder.MyApplication;
@SuppressWarnings("unused")
public class SimUtil {
private static String TAG = "SimUtil";
private static final String TAG = "SimUtil";
//获取卡槽信息ID
public static int getSimId(Bundle bundle) {

View File

@ -1,5 +1,6 @@
package com.idormy.sms.forwarder.utils;
import android.annotation.SuppressLint;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
@ -7,10 +8,13 @@ import android.telephony.SmsManager;
import android.util.Log;
import java.util.ArrayList;
import java.util.Objects;
@SuppressWarnings("SynchronizeOnNonFinalField")
public class SmsUtil {
static String TAG = "SmsUtil";
static final String TAG = "SmsUtil";
static Boolean hasInit = false;
@SuppressLint("StaticFieldLeak")
static Context context;
@ -28,11 +32,11 @@ public class SmsUtil {
try {
SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
PendingIntent sendPI = PendingIntent.getBroadcast(context, 0, new Intent(Context.TELEPHONY_SUBSCRIPTION_SERVICE), PendingIntent.FLAG_ONE_SHOT);
PendingIntent deliverPI = PendingIntent.getBroadcast(context, 0, new Intent("DELIVERED_SMS_ACTION"), 0);
@SuppressLint("UnspecifiedImmutableFlag") PendingIntent sendPI = PendingIntent.getBroadcast(context, 0, new Intent(Context.TELEPHONY_SUBSCRIPTION_SERVICE), PendingIntent.FLAG_ONE_SHOT);
@SuppressLint("UnspecifiedImmutableFlag") PendingIntent deliverPI = PendingIntent.getBroadcast(context, 0, new Intent("DELIVERED_SMS_ACTION"), 0);
ArrayList<PendingIntent> sentPendingIntents = new ArrayList<PendingIntent>();
ArrayList<PendingIntent> deliveredPendingIntents = new ArrayList<PendingIntent>();
ArrayList<PendingIntent> sentPendingIntents = new ArrayList<>();
ArrayList<PendingIntent> deliveredPendingIntents = new ArrayList<>();
ArrayList<String> divideContents = smsManager.divideMessage(message);
for (int i = 0; i < divideContents.size(); i++) {
@ -43,7 +47,7 @@ public class SmsUtil {
return null;
} catch (Exception e) {
Log.e(TAG, e.getMessage());
Log.e(TAG, Objects.requireNonNull(e.getMessage()));
return e.getMessage();
}
}

View File

@ -1,5 +1,6 @@
package com.idormy.sms.forwarder.utils;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
@ -15,15 +16,13 @@ import java.util.Properties;
import java.util.TimeZone;
public class aUtil {
private static String TAG = "aUtil";
private static Context context = null;
/**
* 判断是否为MIUI系统参考http://blog.csdn.net/xx326664162/article/details/52438706
*
* @return
* @return 返回结果
*/
@SuppressWarnings("unused")
public static boolean isMIUI() {
try {
String KEY_MIUI_VERSION_CODE = "ro.miui.ui.version.code";
@ -45,8 +44,7 @@ public class aUtil {
PackageManager packageManager = context.getPackageManager();
// getPackageName()是你当前类的包名0代表是获取版本信息
PackageInfo packInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
String version = packInfo.versionName;
return version;
return packInfo.versionName;
}
public static Integer getVersionCode(Context context) throws Exception {
@ -54,15 +52,14 @@ public class aUtil {
PackageManager packageManager = context.getPackageManager();
// getPackageName()是你当前类的包名0代表是获取版本信息
PackageInfo packInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
Integer versionCode = packInfo.versionCode;
return versionCode;
return packInfo.versionCode;
}
//友好时间显示
public static String friendlyTime(String utcTime) {
SimpleDateFormat utcFormater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@SuppressLint("SimpleDateFormat") SimpleDateFormat utcFormater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
utcFormater.setTimeZone(TimeZone.getTimeZone("UTC"));//时区定义并进行时间获取
Date utcDate = null;
Date utcDate;
try {
utcDate = utcFormater.parse(utcTime);
} catch (ParseException e) {
@ -71,6 +68,7 @@ public class aUtil {
}
//获取utcDate距离当前的秒数
assert utcDate != null;
int ct = (int) ((System.currentTimeMillis() - utcDate.getTime()) / 1000);
if (ct == 0) {
@ -107,10 +105,10 @@ public class aUtil {
public static String utc2Local(String utcTime) {
String utcTimePatten = "yyyy-MM-dd HH:mm:ss";
String localTimePatten = "yyyy-MM-dd HH:mm:ss";
SimpleDateFormat utcFormater = new SimpleDateFormat(utcTimePatten);
@SuppressLint("SimpleDateFormat") SimpleDateFormat utcFormater = new SimpleDateFormat(utcTimePatten);
utcFormater.setTimeZone(TimeZone.getTimeZone("UTC"));//时区定义并进行时间获取
Date utcDate = null;
Date utcDate;
try {
utcDate = utcFormater.parse(utcTime);
} catch (ParseException e) {
@ -118,10 +116,10 @@ public class aUtil {
return utcTime;
}
SimpleDateFormat localFormater = new SimpleDateFormat(localTimePatten);
@SuppressLint("SimpleDateFormat") SimpleDateFormat localFormater = new SimpleDateFormat(localTimePatten);
localFormater.setTimeZone(TimeZone.getDefault());
String localTime = localFormater.format(utcDate.getTime());
return localTime;
assert utcDate != null;
return localFormater.format(utcDate.getTime());
}
}

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
@ -18,7 +19,7 @@
android:padding="15dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
@ -67,7 +68,8 @@
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="end"
android:textSize="18sp" />
android:textSize="18sp"
tools:ignore="UseSwitchCompatOrMaterialXml" />
</LinearLayout>
@ -93,7 +95,8 @@
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="end"
android:textSize="18sp" />
android:textSize="18sp"
tools:ignore="UseSwitchCompatOrMaterialXml" />
</LinearLayout>
@ -119,7 +122,7 @@
android:layout_height="wrap_content"
android:layout_weight="3"
android:autoLink="web"
android:gravity="right"
android:gravity="end"
android:text="https://github.com/pppscn/SmsForwarder/releases"
android:textSize="14sp" />
</LinearLayout>
@ -135,7 +138,7 @@
android:padding="15dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
@ -171,7 +174,7 @@
android:padding="15dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">

View File

@ -34,7 +34,7 @@
android:id="@+id/bt_refresh_log"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:layout_weight="1"
@ -47,7 +47,7 @@
android:id="@+id/bt_rule_set"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:layout_weight="1"

View File

@ -25,7 +25,7 @@
android:textColor="@color/colorPrimary" />
<Button
android:id="@+id/btaddrule"
android:id="@+id/bt_add_rule"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_margin="10dp"

View File

@ -28,11 +28,13 @@
android:id="@+id/et_add_extra_device_mark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:ems="16"
android:inputType=""
android:inputType="text"
android:maxLines="1"
android:text="" />
android:text=""
tools:ignore="LabelFor"
android:autofillHints="" />
</LinearLayout>
@ -61,18 +63,19 @@
android:layout_height="wrap_content"
android:gravity="end"
android:text="运营商_手机号"
android:textSize="9dp" />
android:textSize="9sp" />
</LinearLayout>
<EditText
android:id="@+id/et_add_extra_sim1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:ems="16"
android:inputType=""
android:inputType="text"
android:maxLines="1"
android:text="" />
android:text=""
android:autofillHints="" />
</LinearLayout>
@ -101,18 +104,19 @@
android:layout_height="wrap_content"
android:gravity="end"
android:text="运营商_手机号"
android:textSize="9dp" />
android:textSize="9sp" />
</LinearLayout>
<EditText
android:id="@+id/et_add_extra_sim2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:ems="16"
android:inputType=""
android:inputType="text"
android:maxLines="1"
android:text="" />
android:text=""
android:autofillHints="" />
</LinearLayout>
@ -141,18 +145,19 @@
android:layout_height="wrap_content"
android:gravity="end"
android:text="取值范围0-100留空或0禁用"
android:textSize="9dp" />
android:textSize="9sp" />
</LinearLayout>
<EditText
android:id="@+id/et_battery_level_alarm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:ems="16"
android:inputType="number"
android:maxLines="1"
android:text="" />
android:text=""
android:autofillHints="" />
</LinearLayout>
@ -181,7 +186,7 @@
android:layout_height="wrap_content"
android:gravity="end"
android:text="接口请求失败后将重试5次"
android:textSize="9dp" />
android:textSize="9sp" />
</LinearLayout>
<LinearLayout
@ -193,56 +198,61 @@
android:id="@+id/et_retry_delay_time1"
android:layout_width="42dp"
android:layout_height="48dp"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:ems="16"
android:inputType="number"
android:maxLines="1"
android:textAlignment="center"
android:text="" />
android:text=""
android:autofillHints="" />
<EditText
android:id="@+id/et_retry_delay_time2"
android:layout_width="42dp"
android:layout_height="48dp"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:ems="16"
android:inputType="number"
android:maxLines="1"
android:textAlignment="center"
android:text="" />
android:text=""
android:autofillHints="" />
<EditText
android:id="@+id/et_retry_delay_time3"
android:layout_width="42dp"
android:layout_height="48dp"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:ems="16"
android:inputType="number"
android:maxLines="1"
android:textAlignment="center"
android:text="" />
android:text=""
android:autofillHints="" />
<EditText
android:id="@+id/et_retry_delay_time4"
android:layout_width="42dp"
android:layout_height="48dp"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:ems="16"
android:inputType="number"
android:maxLines="1"
android:textAlignment="center"
android:text="" />
android:text=""
android:autofillHints="" />
<EditText
android:id="@+id/et_retry_delay_time5"
android:layout_width="42dp"
android:layout_height="48dp"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:ems="16"
android:inputType="number"
android:maxLines="1"
android:textAlignment="center"
android:text="" />
android:text=""
android:autofillHints="" />
</LinearLayout>
</LinearLayout>
@ -267,10 +277,62 @@
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="end"
android:textSize="18sp" />
android:textSize="18sp"
tools:ignore="UseSwitchCompatOrMaterialXml" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
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="转发时附加设备名称"
android:textStyle="bold" />
<Switch
android:id="@+id/switch_add_device_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="end"
android:textSize="18sp"
tools:ignore="UseSwitchCompatOrMaterialXml" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:padding="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="转发来电"
android:textStyle="bold" />
<Switch
android:id="@+id/switch_enable_phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:checked="true"
android:gravity="end"
android:textSize="18sp"
tools:ignore="UseSwitchCompatOrMaterialXml" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -293,7 +355,8 @@
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="end"
android:textSize="18sp" />
android:textSize="18sp"
tools:ignore="UseSwitchCompatOrMaterialXml" />
</LinearLayout>
@ -322,17 +385,18 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:text="Tip按需插入内容标签留空使用默认模版"
android:textSize="11dp" />
android:textSize="11sp" />
</LinearLayout>
<EditText
android:id="@+id/text_sms_template"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType=""
android:text="" />
android:inputType="text"
android:text=""
android:autofillHints="" />
<LinearLayout
android:layout_width="match_parent"
@ -368,7 +432,7 @@
android:id="@+id/bt_insert_content"
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_weight="1"
@ -380,7 +444,7 @@
android:id="@+id/bt_insert_extra"
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_weight="1"
@ -392,7 +456,7 @@
android:id="@+id/bt_insert_time"
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_weight="1"
@ -404,7 +468,7 @@
android:id="@+id/bt_insert_device_name"
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_weight="1"

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
@ -24,10 +25,12 @@
android:id="@+id/editTextBarkName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginStart="3dp"
android:ems="11"
android:inputType=""
android:text="" />
android:inputType="text"
android:text=""
tools:ignore="LabelFor"
android:autofillHints="" />
</LinearLayout>
<LinearLayout
@ -47,8 +50,10 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="14"
android:inputType=""
android:text="" />
android:inputType="text"
android:text=""
android:autofillHints=""
tools:ignore="LabelFor" />
</LinearLayout>
<LinearLayout
@ -68,7 +73,7 @@
android:id="@+id/buttonBarkDel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_weight="1"
android:text="@string/del" />
@ -76,7 +81,7 @@
android:id="@+id/buttonBarkTest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_weight="1"
android:text="@string/test" />

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
@ -24,10 +25,11 @@
android:id="@+id/editTextDingdingName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginStart="3dp"
android:ems="11"
android:inputType=""
android:text="" />
android:inputType="text"
android:text=""
android:autofillHints="" />
</LinearLayout>
<LinearLayout
@ -48,7 +50,8 @@
android:layout_height="wrap_content"
android:ems="14"
android:inputType="textPassword"
android:text="" />
android:text=""
android:autofillHints="" />
</LinearLayout>
@ -70,7 +73,8 @@
android:layout_height="wrap_content"
android:ems="14"
android:inputType="textPassword"
android:text="" />
android:text=""
android:autofillHints="" />
</LinearLayout>
<LinearLayout
@ -90,8 +94,9 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="14"
android:inputType=""
android:text="" />
android:inputType="text"
android:text=""
android:autofillHints="" />
</LinearLayout>
<LinearLayout
@ -111,7 +116,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:ems="14" />
android:ems="14"
tools:ignore="UseSwitchCompatOrMaterialXml" />
</LinearLayout>
<LinearLayout
@ -121,25 +127,25 @@
android:orientation="horizontal">
<Button
android:id="@+id/buttondingdingok"
android:id="@+id/buttonDingdingOk"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/ok" />
<Button
android:id="@+id/buttondingdingdel"
android:id="@+id/buttonDingdingDel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_weight="1"
android:text="@string/del" />
<Button
android:id="@+id/buttondingdingtest"
android:id="@+id/buttonDingdingTest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_weight="1"
android:text="@string/test" />

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
@ -24,10 +25,11 @@
android:id="@+id/editTextEmailName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginStart="3dp"
android:ems="11"
android:inputType=""
android:text="" />
android:inputType="text"
android:text=""
android:autofillHints="" />
</LinearLayout>
<LinearLayout
@ -46,10 +48,11 @@
android:id="@+id/editTextEmailHost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginStart="3dp"
android:ems="14"
android:inputType=""
android:text="" />
android:inputType="text"
android:text=""
android:autofillHints="" />
</LinearLayout>
<LinearLayout
@ -68,10 +71,11 @@
android:id="@+id/editTextEmailPort"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginStart="3dp"
android:ems="5"
android:inputType=""
android:text="" />
android:inputType="text"
android:text=""
android:autofillHints="" />
<TextView
android:layout_width="wrap_content"
@ -82,7 +86,8 @@
android:id="@+id/switchEmailSSl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true" />
android:checked="true"
tools:ignore="UseSwitchCompatOrMaterialXml" />
</LinearLayout>
<LinearLayout
@ -101,10 +106,11 @@
android:id="@+id/editTextEmailFromAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginStart="3dp"
android:ems="14"
android:inputType="textEmailAddress"
android:text="" />
android:text=""
android:autofillHints="" />
</LinearLayout>
<LinearLayout
@ -123,10 +129,11 @@
android:id="@+id/editTextEmailNickname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginStart="3dp"
android:ems="14"
android:inputType=""
android:text="" />
android:inputType="text"
android:text=""
android:autofillHints="" />
</LinearLayout>
<LinearLayout
@ -145,10 +152,11 @@
android:id="@+id/editTextEmailPsw"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginStart="3dp"
android:ems="14"
android:inputType="textPassword"
android:text="" />
android:text=""
android:autofillHints="" />
</LinearLayout>
<LinearLayout
@ -167,10 +175,11 @@
android:id="@+id/editTextEmailToAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginStart="3dp"
android:ems="14"
android:inputType="textEmailAddress"
android:text="" />
android:text=""
android:autofillHints="" />
</LinearLayout>
<LinearLayout
@ -180,25 +189,25 @@
android:orientation="horizontal">
<Button
android:id="@+id/buttonemailok"
android:id="@+id/buttonEmailOk"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/ok" />
<Button
android:id="@+id/buttonemaildel"
android:id="@+id/buttonEmailDel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_weight="1"
android:text="@string/del" />
<Button
android:id="@+id/buttonemailtest"
android:id="@+id/buttonEmailTest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_weight="1"
android:text="@string/test" />

View File

@ -24,10 +24,11 @@
android:id="@+id/editTextFeishuName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginStart="3dp"
android:ems="11"
android:inputType=""
android:text="" />
android:inputType="text"
android:text=""
android:autofillHints="" />
</LinearLayout>
<LinearLayout
@ -47,8 +48,9 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="14"
android:inputType=""
android:text="" />
android:inputType="text"
android:text=""
android:autofillHints="" />
</LinearLayout>
@ -70,7 +72,8 @@
android:layout_height="wrap_content"
android:ems="14"
android:inputType="textPassword"
android:text="" />
android:text=""
android:autofillHints="" />
</LinearLayout>
<LinearLayout
@ -80,25 +83,25 @@
android:orientation="horizontal">
<Button
android:id="@+id/buttonfeishuok"
android:id="@+id/buttonFeishuOk"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/ok" />
<Button
android:id="@+id/buttonfeishudel"
android:id="@+id/buttonFeishuDel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_weight="1"
android:text="@string/del" />
<Button
android:id="@+id/buttonfeishutest"
android:id="@+id/buttonFeishuTest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_weight="1"
android:text="@string/test" />

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
@ -18,7 +19,7 @@
<TextView
android:layout_width="60dp"
android:layout_height="wrap_content"
android:gravity="right"
android:gravity="end"
android:text="设置名称"
android:textStyle="bold" />
@ -26,9 +27,10 @@
android:id="@+id/editTextQYWXAppName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:inputType=""
android:text="" />
android:layout_marginStart="5dp"
android:inputType="text"
android:text=""
android:autofillHints="" />
</LinearLayout>
<LinearLayout
@ -41,7 +43,7 @@
<TextView
android:layout_width="60dp"
android:layout_height="wrap_content"
android:gravity="right"
android:gravity="end"
android:text="企业ID"
android:textStyle="bold" />
@ -49,9 +51,10 @@
android:id="@+id/editTextQYWXAppCorpID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:inputType=""
android:text="" />
android:layout_marginStart="5dp"
android:inputType="text"
android:text="@string/wechat_id"
android:autofillHints="" />
</LinearLayout>
<LinearLayout
@ -64,7 +67,7 @@
<TextView
android:layout_width="60dp"
android:layout_height="wrap_content"
android:gravity="right"
android:gravity="end"
android:text="AgentID"
android:textStyle="bold" />
@ -72,9 +75,10 @@
android:id="@+id/editTextQYWXAppAgentID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:inputType=""
android:text="" />
android:layout_marginStart="5dp"
android:inputType="text"
android:text="@string/Agent_ID"
android:autofillHints="" />
</LinearLayout>
@ -88,7 +92,7 @@
<TextView
android:layout_width="60dp"
android:layout_height="wrap_content"
android:gravity="right"
android:gravity="end"
android:text="Secret"
android:textStyle="bold" />
@ -96,9 +100,10 @@
android:id="@+id/editTextQYWXAppSecret"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:inputType="textPassword"
android:text="" />
android:text="@string/App_Secret"
android:autofillHints="" />
</LinearLayout>
<LinearLayout
@ -111,7 +116,7 @@
<TextView
android:layout_width="60dp"
android:layout_height="wrap_content"
android:gravity="right"
android:gravity="end"
android:text="是否@all"
android:textStyle="bold" />
@ -119,7 +124,8 @@
android:id="@+id/switchQYWXAppAtAll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="false" />
android:checked="false"
tools:ignore="UseSwitchCompatOrMaterialXml" />
</LinearLayout>
<LinearLayout
@ -138,7 +144,7 @@
<TextView
android:layout_width="60dp"
android:layout_height="wrap_content"
android:gravity="right"
android:gravity="end"
android:text="指定成员"
android:textStyle="bold" />
@ -146,9 +152,10 @@
android:id="@+id/editTextQYWXAppToUser"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:inputType=""
android:text="" />
android:layout_marginStart="5dp"
android:inputType="text"
android:text=""
android:autofillHints="" />
</LinearLayout>
<TextView
@ -176,7 +183,7 @@
android:id="@+id/buttonQYWXAppDel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_weight="1"
android:text="@string/del" />
@ -184,7 +191,7 @@
android:id="@+id/buttonQYWXAppTest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_weight="1"
android:text="@string/test" />

View File

@ -24,10 +24,11 @@
android:id="@+id/editTextQYWXGroupRobotName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginStart="3dp"
android:ems="11"
android:inputType=""
android:text="" />
android:inputType="text"
android:text=""
android:autofillHints="" />
</LinearLayout>
<LinearLayout
@ -47,8 +48,9 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="14"
android:inputType=""
android:text="" />
android:inputType="text"
android:text=""
android:autofillHints="" />
</LinearLayout>
<LinearLayout
@ -68,7 +70,7 @@
android:id="@+id/buttonQyWxGroupRobotDel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_weight="1"
android:text="@string/del" />
@ -76,7 +78,7 @@
android:id="@+id/buttonQyWxGroupRobotTest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_weight="1"
android:text="@string/test" />

View File

@ -11,14 +11,14 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:text="设置匹配的卡槽"
android:textStyle="bold" />
@ -49,14 +49,14 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:text="设置匹配的字段"
android:textStyle="bold" />
@ -93,14 +93,14 @@
android:id="@+id/matchTypeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:text="设置匹配的模式"
android:textStyle="bold" />
@ -152,7 +152,7 @@
android:id="@+id/matchValueLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:orientation="vertical">
@ -168,8 +168,9 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="14"
android:inputType=""
android:text="" />
android:inputType="text"
android:text=""
android:autofillHints="" />
<TextView
android:id="@+id/tv_mu_rule_tips"
@ -191,7 +192,7 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="5dp"
android:orientation="vertical">
@ -219,7 +220,7 @@
android:id="@+id/ruleSenderTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:text="" />
</LinearLayout>
@ -233,25 +234,25 @@
android:orientation="horizontal">
<Button
android:id="@+id/buttonruleok"
android:id="@+id/buttonRuleOk"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/ok" />
<Button
android:id="@+id/buttonruledel"
android:id="@+id/buttonRuleDel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_weight="1"
android:text="@string/del" />
<Button
android:id="@+id/buttonruletest"
android:id="@+id/buttonRuleTest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_weight="1"
android:text="@string/test" />

View File

@ -26,7 +26,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:gravity="left|center_vertical"
android:gravity="start|center_vertical"
android:orientation="horizontal">
<RadioButton
@ -56,8 +56,9 @@
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:ems="10"
android:inputType=""
android:text="" />
android:inputType="text"
android:text=""
android:autofillHints="" />
<TextView
android:layout_width="match_parent"
@ -72,14 +73,15 @@
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:ems="10"
android:inputType=""
android:text="" />
android:inputType="text"
android:text=""
android:autofillHints="" />
</LinearLayout>
<Button
android:id="@+id/buttonruletest"
android:id="@+id/buttonRuleTest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="0dp"
android:layout_margin="3dp"
android:layout_weight="1"
android:text="@string/test" />

View File

@ -24,10 +24,11 @@
android:id="@+id/editTextServerChanName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginStart="3dp"
android:ems="11"
android:inputType=""
android:text="" />
android:inputType="text"
android:text=""
android:autofillHints="" />
</LinearLayout>
<LinearLayout
@ -48,7 +49,8 @@
android:layout_height="wrap_content"
android:ems="14"
android:inputType="textPassword"
android:text="" />
android:text=""
android:autofillHints="" />
</LinearLayout>
<LinearLayout
@ -68,7 +70,7 @@
android:id="@+id/buttonServerChanDel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_weight="1"
android:text="@string/del" />
@ -76,7 +78,7 @@
android:id="@+id/buttonServerChanTest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_weight="1"
android:text="@string/test" />

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
@ -24,10 +25,11 @@
android:id="@+id/editTextSmsName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginStart="3dp"
android:ems="14"
android:inputType=""
android:text="" />
android:inputType="text"
android:text=""
android:autofillHints="" />
</LinearLayout>
<LinearLayout
@ -47,7 +49,7 @@
<RadioGroup
android:id="@+id/radioGroupSmsSimSlot"
style="@style/rg_style"
android:layout_marginLeft="3dp"
android:layout_marginStart="3dp"
android:orientation="horizontal">
<RadioButton
@ -86,9 +88,10 @@
android:id="@+id/editTextSmsMobiles"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginStart="3dp"
android:ems="14"
android:text="" />
android:text=""
android:autofillHints="" />
</LinearLayout>
<LinearLayout
@ -108,7 +111,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:ems="14" />
android:ems="14"
tools:ignore="UseSwitchCompatOrMaterialXml" />
</LinearLayout>
<LinearLayout
@ -128,7 +132,7 @@
android:id="@+id/buttonSmsDel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_weight="1"
android:text="@string/del" />
@ -136,7 +140,7 @@
android:id="@+id/buttonSmsTest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_weight="1"
android:text="@string/test" />

View File

@ -24,10 +24,11 @@
android:id="@+id/editTextTelegramName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginStart="3dp"
android:ems="11"
android:inputType=""
android:text="" />
android:inputType="text"
android:text=""
android:autofillHints="" />
</LinearLayout>
<LinearLayout
@ -48,7 +49,8 @@
android:layout_height="wrap_content"
android:ems="14"
android:inputType="textPassword"
android:text="" />
android:text=""
android:autofillHints="" />
</LinearLayout>
<LinearLayout
@ -68,8 +70,9 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="14"
android:inputType=""
android:text="" />
android:inputType="text"
android:text=""
android:autofillHints="" />
</LinearLayout>
<LinearLayout
@ -89,7 +92,7 @@
android:id="@+id/buttonTelegramDel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_weight="1"
android:text="@string/del" />
@ -97,7 +100,7 @@
android:id="@+id/buttonTelegramTest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_weight="1"
android:text="@string/test" />

View File

@ -24,10 +24,11 @@
android:id="@+id/editTextWebNotifyName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginStart="3dp"
android:ems="11"
android:inputType=""
android:text="" />
android:inputType="text"
android:text=""
android:autofillHints="" />
</LinearLayout>
<LinearLayout
@ -47,7 +48,7 @@
android:id="@+id/radioGroupWebNotifyMethod"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginStart="3dp"
android:orientation="horizontal">
<RadioButton
@ -84,8 +85,9 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="14"
android:inputType=""
android:text="" />
android:inputType="text"
android:text=""
android:autofillHints="" />
</LinearLayout>
<LinearLayout
@ -105,8 +107,9 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="14"
android:inputType=""
android:text="" />
android:inputType="text"
android:text=""
android:autofillHints="" />
</LinearLayout>
<LinearLayout
@ -127,7 +130,8 @@
android:layout_height="wrap_content"
android:ems="14"
android:inputType="textPassword"
android:text="" />
android:text=""
android:autofillHints="" />
</LinearLayout>
<LinearLayout
@ -137,25 +141,25 @@
android:orientation="horizontal">
<Button
android:id="@+id/buttonbebnotifyok"
android:id="@+id/buttonWebNotifyOk"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/ok" />
<Button
android:id="@+id/buttonbebnotifydel"
android:id="@+id/buttonWebNotifyDel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_weight="1"
android:text="@string/del" />
<Button
android:id="@+id/buttonbebnotifytest"
android:id="@+id/buttonWebNotifyTest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_weight="1"
android:text="@string/test" />

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
@ -25,7 +26,7 @@
android:text="下拉可以刷新!" />
<TextView
android:id="@+id/lastupdate_time"
android:id="@+id/lastUpdateTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
@ -34,17 +35,18 @@
android:id="@+id/arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dip"
android:layout_toLeftOf="@id/layout"
android:src="@android:drawable/ic_popup_sync" />
android:layout_marginEnd="20dip"
android:layout_toStartOf="@id/layout"
android:src="@android:drawable/ic_popup_sync"
tools:ignore="ContentDescription" />
<ProgressBar
android:id="@+id/progress"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dip"
android:layout_toLeftOf="@id/layout"
android:layout_marginEnd="20dip"
android:layout_toStartOf="@id/layout"
android:visibility="gone" />
</RelativeLayout>

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
@ -7,27 +8,29 @@
android:layout_width="34dp"
android:layout_height="34dp"
android:layout_alignParentEnd="true"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_marginTop="10dp"
android:orientation="vertical">
<ImageView
android:id="@+id/tlog_sender_image"
android:layout_width="32dp"
android:layout_height="32dp" />
android:layout_height="32dp"
tools:ignore="ContentDescription" />
<ImageView
android:id="@+id/tlog_status_image"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_marginLeft="18dp"
android:layout_marginTop="-14dp" />
android:layout_marginStart="18dp"
android:layout_marginTop="-14dp"
tools:ignore="ContentDescription" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:orientation="vertical">
<RelativeLayout
@ -54,13 +57,14 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginRight="24dp" />
android:layout_marginEnd="24dp" />
<ImageView
android:id="@+id/tlog_sim_image"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_alignParentEnd="true" />
android:layout_alignParentEnd="true"
tools:ignore="ContentDescription" />
</RelativeLayout>
<TextView

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
@ -8,19 +9,20 @@
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_alignParentEnd="true"
android:layout_margin="5dp" />
android:layout_margin="5dp"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/rule_match"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp" />
android:layout_marginStart="5dp" />
<TextView
android:id="@+id/rule_sender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp" />
android:layout_marginStart="5dp" />
</LinearLayout>

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
@ -7,12 +8,13 @@
android:id="@+id/sender_image"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_margin="5dp" />
android:layout_margin="5dp"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/sender_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp" />
android:layout_marginStart="10dp" />
</LinearLayout>

View File

@ -1,7 +1,8 @@
<resources>
<string name="app_name">短信转发器</string>
<string name="dingdingok">确认</string>
<string name="notification_content">根据规则转发到钉钉/微信/邮箱/bark/Server酱/Telegram/webhook等</string>
<string name="ok">确认</string>
<string name="cancel">取消</string>
<string name="del">删除</string>
<string name="test">测试</string>
<string name="setdingdingtitle">设置钉钉机器人</string>
@ -22,6 +23,11 @@
<string name="log_tips">提示:置顶下拉刷新,长按删除单条记录</string>
<string name="rule_tips">提示:新建规则点击“添加”,长按删除/点击编辑已有</string>
<string name="sender_tips">提示:新建发送方点击“添加”,长按删除/点击编辑已有</string>
<string name="unknown_number">未知号码</string>
<string name="calling">来电</string>
<string name="unsupport">您的手机不支持此设置</string>
<string name="isIgnored">已设置成功!</string>
<string name="wechat_id" />
<string name="Agent_ID" />
<string name="App_Secret" />
</resources>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<full-backup-content>
<!-- TODO Remove the following "exclude" elements to make them a part of the auto backup -->
<exclude
domain="database"
path="sms_forwarder.db" />
<!-- Exclude the shared preferences file that contains the GCM registrationId -->
<exclude
domain="sharedpref"
path="forwarder_config.xml" />
<exclude
domain="sharedpref"
path="forwarder_msg.xml" />
</full-backup-content>

View File

@ -1,18 +1,13 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.4.30'
repositories {
google()
jcenter()
// maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'https://repo1.maven.org/maven2/' }
maven { url "https://jitpack.io" }
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.chenenyu:img-optimizer:1.2.0' //
}
}
@ -20,8 +15,6 @@ allprojects {
repositories {
google()
jcenter()
// maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'https://repo1.maven.org/maven2/' }
maven { url "https://jitpack.io" }
}
}

3
version.properties Normal file
View File

@ -0,0 +1,3 @@
#Fri Jul 16 10:33:23 CST 2021
versionName=2.0.0
versionCode=26