Compare commits

...

58 Commits

Author SHA1 Message Date
ZhanGSKen
cedb5f521b <mymessagemanager>APK 4.1.14 release Publish. 2025-02-25 20:25:31 +08:00
ZhanGSKen
396df6713c 添加单元测试模块,增加电话号码是否是数字的检测。 2025-02-25 20:19:54 +08:00
ZhanGSKen
90e66889a9 添加MyMessageManager项目 2025-02-25 18:53:54 +08:00
ZhanGSKen
3031c9bfe0 <libappbase>Library Release 2.0.2 2025-02-25 16:51:23 +08:00
ZhanGSKen
51acbb1f54 <appbase>APK 2.0.2 release Publish. 2025-02-25 16:51:09 +08:00
ZhanGSKen
26fc0b4684 <libappbase>Library Release 2.0.1 2025-02-25 16:51:01 +08:00
ZhanGSKen
ecb67edec1 <appbase>APK 2.0.1 release Publish. 2025-02-25 16:50:23 +08:00
ZhanGSKen
3b30acfdec <appbase>APK 2.0.0 release Publish. 2025-02-25 16:48:35 +08:00
ZhanGSKen
c633e1663b 2025-02-25 16:44:26 +08:00
ZhanGSKen
40589ad879 1641 2025-02-25 16:41:51 +08:00
ZhanGSKen
0357fcf6b3 0225_1615 2025-02-25 16:15:54 +08:00
ZhanGSKen
c56fdaf14d <libappbase>Library Release 2.0.0 2025-02-25 16:11:50 +08:00
ZhanGSKen
9b1264234e 设置版本号 2025-02-25 16:02:55 +08:00
ZhanGSKen
d207a9ea9b 更正com.android.tools.build:gradle:7.2.1'对应的Gradle版本设置 2025-02-25 15:59:48 +08:00
ZhanGSKen
404239de23 更新编译配置已对应Android10开发,API级别29。Java 使用版本为 Java 8。 2025-02-25 15:51:54 +08:00
ZhanGSKen
c16b80ffae 地图标记保存完成 2025-02-25 06:43:50 +08:00
ZhanGSKen
ca16a8677a 添加地图定位功能 2025-02-24 15:20:51 +08:00
ZhanGSKen
bb089a4eb1 整合SDK成功 2025-02-24 08:06:04 +08:00
ZhanGSKen
0c00ace869 注释问题代码 2025-02-24 04:30:26 +08:00
ZhanGSKen
e06b642b70 添加demo 2025-02-24 03:51:22 +08:00
ZhanGSKen
5e107028de 绘图与缩略完成 2025-02-22 19:43:11 +08:00
ZhanGSKen
3bcfc5a5da 添加Positions项目 2025-02-22 01:50:07 +08:00
ZhanGSKen
e849e54960 <libappbase>Library Release 1.5.6 2025-02-21 11:03:53 +08:00
ZhanGSKen
8b2866419c <appbase>APK 1.5.6 release Publish. 2025-02-21 10:58:04 +08:00
ZhanGSKen
22a4a71203 更新bean基础类 2025-02-21 10:56:13 +08:00
ZhanGSKen
292f7c553f <libappbase>Library Release 1.5.5 2025-02-20 11:24:38 +08:00
ZhanGSKen
df9970c6df <appbase>APK 1.5.5 release Publish. 2025-02-20 11:24:23 +08:00
ZhanGSKen
0312ca50d2 添加绑定服务的APP的唤醒记录在部件的提示 2025-02-20 11:22:34 +08:00
ZhanGSKen
56187b588f <libappbase>Library Release 1.5.4 2025-02-19 19:57:16 +08:00
ZhanGSKen
d91372af52 <appbase>APK 1.5.4 release Publish. 2025-02-19 19:57:00 +08:00
ZhanGSKen
288725eca0 不同应用包服务绑定逻辑完成 2025-02-19 19:55:03 +08:00
ZhanGSKen
bd728b83a3 <libappbase>Library Release 1.5.3 2025-02-19 03:19:17 +08:00
ZhanGSKen
d4f9fc3561 <appbase>APK 1.5.3 release Publish. 2025-02-19 03:18:52 +08:00
ZhanGSKen
e7c614ebec 重构主应用架构 2025-02-19 03:17:49 +08:00
ZhanGSKen
c226a92ffe <libappbase>Library Release 1.5.2 2025-02-17 12:10:10 +08:00
ZhanGSKen
358e8b3522 <appbase>APK 1.5.2 release Publish. 2025-02-17 12:09:50 +08:00
ZhanGSKen
83ab4f9417 添加用磁贴启动小部件功能 2025-02-17 12:07:52 +08:00
ZhanGSKen
26cdacf1c6 BugFix 2025-02-17 11:44:15 +08:00
ZhanGSKen
6378433424 sos报告部件重构 2025-02-17 11:13:09 +08:00
ZhanGSKen
7b05d613e4 完成小部件分页功能 2025-02-16 20:54:33 +08:00
ZhanGSKen
691f9bbd1c 基本救援设施铺设完成 2025-02-15 21:37:33 +08:00
ZhanGSKen
7a8d3329d4 完成摘要事件监控小部件 2025-02-15 19:53:24 +08:00
ZhanGSKen
bbac0c7306 添加WinBoll类 2025-02-15 12:46:23 +08:00
ZhanGSKen
8d2b325172 实现磁贴启动服务功能 2025-02-15 11:30:20 +08:00
ZhanGSKen
825dfb944e AssistantService 启动成功 2025-02-14 21:18:43 +08:00
ZhanGSKen
419244b12a 放弃使用aidl 2025-02-14 07:30:47 +08:00
ZhanGSKen
39fda1b5da Use android studio add aidl file. 2025-02-14 07:04:21 +08:00
ZhanGSKen
464f2da89f test 2025-02-14 06:25:35 +08:00
ZhanGSKen
4f37b6f0e3 test 2025-02-14 06:08:50 +08:00
ZhanGSKen
f91cd0c9c3 <appbase>Start New Stage Version. 2025-02-14 06:02:07 +08:00
ZhanGSKen
d09f0783a4 <appbase>Start New Stage Version. 2025-02-14 06:01:54 +08:00
ZhanGSKen
accca716d4 Test aidl 2025-02-14 06:01:16 +08:00
ZhanGSKen
dfd09eb647 <libappbase>Library Release 1.5.1 2025-02-14 03:01:05 +08:00
ZhanGSKen
79547adcb3 <appbase>APK 1.5.1 release Publish. 2025-02-14 03:00:46 +08:00
ZhanGSKen
be39eef6e7 添加调试信息 2025-02-14 02:59:52 +08:00
ZhanGSKen
50490096b4 SOS广播消息发送与接收完成 2025-02-13 21:31:33 +08:00
ZhanGSKen
3dd4c84602 添加磁贴模块 2025-02-13 20:42:58 +08:00
ZhanGSKen
311bc8e339 <libappbase>Library Release 1.5.0 2025-02-13 06:53:58 +08:00
416 changed files with 53849 additions and 200 deletions

3
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

1
.idea/.name generated Normal file
View File

@@ -0,0 +1 @@
appbase

6
.idea/compiler.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="17" />
</component>
</project>

10
.idea/deploymentTargetDropDown.xml generated Normal file
View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<value>
<entry key="appbase">
<State />
</entry>
</value>
</component>
</project>

10
.idea/migrations.xml generated Normal file
View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectMigrations">
<option name="MigrateToGradleLocalJavaHome">
<set>
<option value="$PROJECT_DIR$" />
</set>
</option>
</component>
</project>

10
.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>

View File

@@ -18,18 +18,18 @@ def genVersionName(def versionName){
}
android {
compileSdkVersion 32
buildToolsVersion "33.0.3"
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "cc.winboll.studio.appbase"
minSdkVersion 21
targetSdkVersion 30
minSdkVersion 26
targetSdkVersion 29
versionCode 1
// versionName 更新后需要手动设置
// .winboll/winbollBuildProps.properties 文件的 stageCount=0
// Gradle编译环境下合起来的 versionName 就是 "${versionName}.0"
versionName "1.5"
versionName "2.0"
if(true) {
versionName = genVersionName("${versionName}")
}
@@ -41,11 +41,6 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
}
dependencies {

View File

@@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle
#Thu Feb 13 06:53:34 HKT 2025
stageCount=1
#Tue Feb 25 16:51:17 HKT 2025
stageCount=3
libraryProject=libappbase
baseVersion=1.5
publishVersion=1.5.0
baseVersion=2.0
publishVersion=2.0.2
buildCount=0
baseBetaVersion=1.5.1
baseBetaVersion=2.0.3

View File

@@ -21,15 +21,76 @@
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.service.quicksettings.action.QS_TILE_PREFERENCES"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name=".GlobalApplication$CrashActivity"/>
<service
android:name=".MyTileService"
android:label="@string/tileservice_name"
android:icon="@drawable/ic_launcher"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE"/>
</intent-filter>
</service>
<service
android:name=".services.MainService"
android:exported="true"/>
<service android:name=".services.AssistantService"/>
<receiver android:name="cc.winboll.studio.appbase.receivers.MainReceiver">
<intent-filter>
<action android:name="cc.winboll.studio.appbase.receivers.MainReceiver"/>
</intent-filter>
</receiver>
<receiver
android:name=".widgets.SOSWidget"
android:exported="true">
<intent-filter>
<action android:name="cc.winboll.studio.appbase.widgets.SOSWidget.ACTION_WAKEUP_SERVICE"/>
<action android:name="cc.winboll.studio.appbase.widgets.SOSWidget.ACTION_RELOAD_REPORT"/>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/widget_provider_info_sos"/>
</receiver>
<receiver android:name=".widgets.SOSWidgetClickListener">
<intent-filter>
<action android:name="cc.winboll.studio.appbase.widgets.SOSWidgetClickListener.ACTION_PRE"/>
<action android:name="cc.winboll.studio.appbase.widgets.SOSWidgetClickListener.ACTION_NEXT"/>
</intent-filter>
</receiver>
<meta-data
android:name="android.max_aspect"
android:value="4.0"/>
<activity android:name=".GlobalApplication$CrashActivity"/>
</application>

View File

@@ -19,7 +19,7 @@ public class App extends GlobalApplication {
public void onCreate() {
super.onCreate();
GlobalApplication.setIsDebuging(this, BuildConfig.DEBUG);
mSOSCSBroadcastReceiver = new SOSCSBroadcastReceiver(this);
mSOSCSBroadcastReceiver = new SOSCSBroadcastReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(SOSCSBroadcastReceiver.ACTION_SOS);
registerReceiver(mSOSCSBroadcastReceiver, intentFilter);

View File

@@ -8,13 +8,16 @@ import android.widget.CheckBox;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import cc.winboll.studio.appbase.R;
import cc.winboll.studio.appbase.services.MainService;
import cc.winboll.studio.libappbase.GlobalApplication;
import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.libappbase.LogView;
import cc.winboll.studio.libappbase.SOSCSBroadcastReceiver;
import cc.winboll.studio.libappbase.SOS;
import cc.winboll.studio.libappbase.SimpleOperateSignalCenterService;
import cc.winboll.studio.libappbase.bean.APPSOSBean;
import cc.winboll.studio.libappbase.services.TestService;
import cc.winboll.studio.libappbase.widgets.StatusWidget;
import com.hjq.toast.ToastUtils;
import cc.winboll.studio.libappbase.ISOSAPP;
public class MainActivity extends AppCompatActivity {
@@ -38,6 +41,14 @@ public class MainActivity extends AppCompatActivity {
if (GlobalApplication.isDebuging()) { mLogView.start(); }
}
@Override
protected void onDestroy() {
super.onDestroy();
Intent intentAPPWidget = new Intent(this, StatusWidget.class);
intentAPPWidget.setAction(StatusWidget.ACTION_STATUS_UPDATE);
sendBroadcast(intentAPPWidget);
}
@Override
protected void onResume() {
LogUtils.d(TAG, "onResume");
@@ -50,11 +61,11 @@ public class MainActivity extends AppCompatActivity {
}
public void onStartCenter(View view) {
SimpleOperateSignalCenterService.startISOSService(this);
MainService.startMainService(this);
}
public void onStopCenter(View view) {
SimpleOperateSignalCenterService.stopISOSService(this);
MainService.stopMainService(this);
}
public void onTestStopWithoutSettingEnable(View view) {
@@ -64,7 +75,7 @@ public class MainActivity extends AppCompatActivity {
public void onTestStartWithString(View view) {
LogUtils.d(TAG, "onTestStartWithString");
// 目标服务的包名和类名
String packageName = this.getPackageName();
String serviceClassName = SimpleOperateSignalCenterService.class.getName();
@@ -77,15 +88,29 @@ public class MainActivity extends AppCompatActivity {
}
public void onSOS(View view) {
// 创建Intent对象指定广播的action
Intent intent = new Intent(SOSCSBroadcastReceiver.ACTION_SOS);
// 目标服务的包名和类名
String packageName = this.getPackageName();
String serviceClassName = SimpleOperateSignalCenterService.class.getName();
intent.putExtra(ISOSAPP.EXTRA_PACKAGE, packageName);
intent.putExtra(ISOSAPP.EXTRA_SERVICE, serviceClassName);
// 发送广播
sendBroadcast(intent);
LogUtils.d(TAG, "onSOS");
Intent intent = new Intent(this, TestService.class);
stopService(intent);
SOS.sosWinBollService(this, new APPSOSBean(getPackageName(), TestService.class.getName()));
}
public void onStartTestService(View view) {
Intent intent = new Intent(this, TestService.class);
intent.setAction(SOS.ACTION_SERVICE_ENABLE);
startService(intent);
}
public void onStopTestService(View view) {
Intent intent = new Intent(this, TestService.class);
intent.setAction(SOS.ACTION_SERVICE_DISABLE);
startService(intent);
Intent intentStop = new Intent(this, TestService.class);
stopService(intentStop);
}
public void onStopTestServiceNoSettings(View view) {
Intent intent = new Intent(this, TestService.class);
stopService(intent);
}
}

View File

@@ -0,0 +1,79 @@
package cc.winboll.studio.appbase;
/**
* @Author ZhanGSKen@AliYun.Com
* @Date 2025/02/13 19:30:10
*/
import android.content.Context;
import android.service.quicksettings.Tile;
import android.service.quicksettings.TileService;
import cc.winboll.studio.appbase.beans.MainServiceBean;
import cc.winboll.studio.appbase.services.MainService;
public class MyTileService extends TileService {
public static final String TAG = "MyTileService";
volatile static MyTileService _MyTileService;
@Override
public void onStartListening() {
super.onStartListening();
_MyTileService = this;
Tile tile = getQsTile();
MainServiceBean bean = MainServiceBean.loadBean(this, MainServiceBean.class);
if (bean != null && bean.isEnable()) {
//MainService.startMainService(context);
tile.setState(Tile.STATE_ACTIVE);
tile.setIcon(android.graphics.drawable.Icon.createWithResource(this, R.drawable.ic_cloud));
} else {
//MainService.stopMainService(context);
tile.setState(Tile.STATE_INACTIVE);
tile.setIcon(android.graphics.drawable.Icon.createWithResource(this, R.drawable.ic_cloud_outline));
}
tile.updateTile();
// Tile tile = getQsTile();
// tile.setState(Tile.STATE_INACTIVE);
// tile.setLabel(getString(R.string.tileservice_name));
// tile.setIcon(android.graphics.drawable.Icon.createWithResource(this, R.drawable.ic_cloud_outline));
// tile.updateTile();
}
@Override
public void onClick() {
super.onClick();
Tile tile = getQsTile();
MainServiceBean bean = MainServiceBean.loadBean(this, MainServiceBean.class);
if (bean == null) {
bean = new MainServiceBean();
}
if (tile.getState() == Tile.STATE_ACTIVE) {
bean.setIsEnable(false);
MainServiceBean.saveBean(this, bean);
MainService.stopMainService(this);
} else if (tile.getState() == Tile.STATE_INACTIVE) {
bean.setIsEnable(true);
MainServiceBean.saveBean(this, bean);
MainService.startMainService(this);
}
updateServiceIconStatus(this);
}
public static void updateServiceIconStatus(Context context) {
if (_MyTileService == null) {
return;
}
Tile tile = _MyTileService.getQsTile();
MainServiceBean bean = MainServiceBean.loadBean(context, MainServiceBean.class);
if (bean != null && bean.isEnable()) {
tile.setState(Tile.STATE_ACTIVE);
tile.setIcon(android.graphics.drawable.Icon.createWithResource(context, R.drawable.ic_cloud));
} else {
tile.setState(Tile.STATE_INACTIVE);
tile.setIcon(android.graphics.drawable.Icon.createWithResource(context, R.drawable.ic_cloud_outline));
}
tile.updateTile();
}
}

View File

@@ -0,0 +1,68 @@
package cc.winboll.studio.appbase.beans;
/**
* @Author ZhanGSKen@AliYun.Com
* @Date 2025/02/13 07:06:13
*/
import android.util.JsonReader;
import android.util.JsonWriter;
import cc.winboll.studio.libappbase.BaseBean;
import java.io.IOException;
public class MainServiceBean extends BaseBean {
public static final String TAG = "MainServiceBean";
boolean isEnable;
public MainServiceBean() {
this.isEnable = false;
}
public void setIsEnable(boolean isEnable) {
this.isEnable = isEnable;
}
public boolean isEnable() {
return isEnable;
}
@Override
public String getName() {
return MainServiceBean.class.getName();
}
@Override
public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
super.writeThisToJsonWriter(jsonWriter);
MainServiceBean bean = this;
jsonWriter.name("isEnable").value(bean.isEnable());
}
@Override
public boolean initObjectsFromJsonReader(JsonReader jsonReader, String name) throws IOException {
if (super.initObjectsFromJsonReader(jsonReader, name)) { return true; } else {
if (name.equals("isEnable")) {
setIsEnable(jsonReader.nextBoolean());
} else {
return false;
}
}
return true;
}
@Override
public BaseBean readBeanFromJsonReader(JsonReader jsonReader) throws IOException {
jsonReader.beginObject();
while (jsonReader.hasNext()) {
String name = jsonReader.nextName();
if (!initObjectsFromJsonReader(jsonReader, name)) {
jsonReader.skipValue();
}
}
// 结束 JSON 对象
jsonReader.endObject();
return this;
}
}

View File

@@ -0,0 +1,72 @@
package cc.winboll.studio.appbase.beans;
/**
* @Author ZhanGSKen@AliYun.Com
* @Date 2025/02/17 10:05:09
* @Describe APPSOSReportBean
*/
import android.util.JsonReader;
import android.util.JsonWriter;
import cc.winboll.studio.libappbase.BaseBean;
import java.io.IOException;
public class SOSReportBean extends BaseBean {
public static final String TAG = "APPSOSReportBean";
protected String sosReport;
public SOSReportBean() {
this.sosReport = "";
}
public SOSReportBean(String sosReport) {
this.sosReport = sosReport;
}
public void setSosReport(String sosReport) {
this.sosReport = sosReport;
}
public String getSosReport() {
return sosReport;
}
@Override
public String getName() {
return SOSReportBean.class.getName();
}
@Override
public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
super.writeThisToJsonWriter(jsonWriter);
jsonWriter.name("sosReport").value(getSosReport());
}
@Override
public boolean initObjectsFromJsonReader(JsonReader jsonReader, String name) throws IOException {
if (super.initObjectsFromJsonReader(jsonReader, name)) { return true; } else {
if (name.equals("sosReport")) {
setSosReport(jsonReader.nextString());
} else {
return false;
}
}
return true;
}
@Override
public BaseBean readBeanFromJsonReader(JsonReader jsonReader) throws IOException {
jsonReader.beginObject();
while (jsonReader.hasNext()) {
String name = jsonReader.nextName();
if (!initObjectsFromJsonReader(jsonReader, name)) {
jsonReader.skipValue();
}
}
// 结束 JSON 对象
jsonReader.endObject();
return this;
}
}

View File

@@ -0,0 +1,38 @@
package cc.winboll.studio.appbase.handlers;
/**
* @Author ZhanGSKen@AliYun.Com
* @Date 2025/02/14 03:51:40
*/
import android.os.Handler;
import android.os.Message;
import cc.winboll.studio.appbase.services.MainService;
import java.lang.ref.WeakReference;
public class MainServiceHandler extends Handler {
public static final String TAG = "MainServiceHandler";
public static final int MSG_REMINDTHREAD = 0;
WeakReference<MainService> serviceWeakReference;
public MainServiceHandler(MainService service) {
serviceWeakReference = new WeakReference<MainService>(service);
}
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MSG_REMINDTHREAD: // 处理下载完成消息更新UI
{
// 显示提醒消息
//
//LogUtils.d(TAG, "显示提醒消息");
MainService mainService = serviceWeakReference.get();
if (mainService != null) {
mainService.appenMessage((String)msg.obj);
}
break;
}
}
}
}

View File

@@ -0,0 +1,132 @@
package cc.winboll.studio.appbase.receivers;
/**
* @Author ZhanGSKen@AliYun.Com
* @Date 2025/02/13 06:58:04
* @Describe 主要广播接收器
*/
import android.appwidget.AppWidgetManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import cc.winboll.studio.appbase.beans.SOSReportBean;
import cc.winboll.studio.appbase.services.MainService;
import cc.winboll.studio.appbase.widgets.SOSWidget;
import cc.winboll.studio.libappbase.AppUtils;
import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.libappbase.SOS;
import cc.winboll.studio.libappbase.bean.APPSOSBean;
import com.hjq.toast.ToastUtils;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.text.SimpleDateFormat;
import java.util.Date;
public class MainReceiver extends BroadcastReceiver {
public static final String TAG = "MainReceiver";
public static final String ACTION_BOOT_COMPLETED = "android.intent.action.BOOT_COMPLETED";
WeakReference<MainService> mwrService;
// 存储电量指示值,
// 用于校验电量消息时的电量变化
static volatile int _mnTheQuantityOfElectricityOld = -1;
static volatile boolean _mIsCharging = false;
public MainReceiver(MainService service) {
mwrService = new WeakReference<MainService>(service);
}
@Override
public void onReceive(Context context, Intent intent) {
String szAction = intent.getAction();
if (szAction.equals(ACTION_BOOT_COMPLETED)) {
ToastUtils.show("ACTION_BOOT_COMPLETED");
} else if (szAction.equals(SOS.ACTION_BIND)) {
LogUtils.d(TAG, "ACTION_BIND");
LogUtils.d(TAG, String.format("context.getPackageName() %s", context.getPackageName()));
LogUtils.d(TAG, String.format("intent.getAction() %s", intent.getAction()));
String SOS = intent.getStringExtra("SOS");
LogUtils.d(TAG, String.format("SOS %s", SOS));
if (SOS != null && SOS.equals("Service")) {
String szAPPSOSBean = intent.getStringExtra("APPSOSBean");
LogUtils.d(TAG, String.format("szAPPSOSBean %s", szAPPSOSBean));
if (szAPPSOSBean != null && !szAPPSOSBean.equals("")) {
try {
APPSOSBean bean = APPSOSBean.parseStringToBean(szAPPSOSBean, APPSOSBean.class);
if (bean != null) {
String sosPackage = bean.getSosPackage();
LogUtils.d(TAG, String.format("sosPackage %s", sosPackage));
String sosClassName = bean.getSosClassName();
LogUtils.d(TAG, String.format("sosClassName %s", sosClassName));
mwrService.get().bindSOSConnection(bean);
}
} catch (IOException e) {
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
}
}
}
} else if (intent.getAction().equals(SOS.ACTION_SOS)) {
LogUtils.d(TAG, "ACTION_SOS");
LogUtils.d(TAG, String.format("context.getPackageName() %s", context.getPackageName()));
LogUtils.d(TAG, String.format("intent.getAction() %s", intent.getAction()));
String SOS = intent.getStringExtra("SOS");
LogUtils.d(TAG, String.format("SOS %s", SOS));
if (SOS != null && SOS.equals("Service")) {
String szAPPSOSBean = intent.getStringExtra("APPSOSBean");
LogUtils.d(TAG, String.format("szAPPSOSBean %s", szAPPSOSBean));
if (szAPPSOSBean != null && !szAPPSOSBean.equals("")) {
try {
APPSOSBean bean = APPSOSBean.parseStringToBean(szAPPSOSBean, APPSOSBean.class);
if (bean != null) {
String sosPackage = bean.getSosPackage();
LogUtils.d(TAG, String.format("sosPackage %s", sosPackage));
String sosClassName = bean.getSosClassName();
LogUtils.d(TAG, String.format("sosClassName %s", sosClassName));
Intent intentService = new Intent();
intentService.setComponent(new ComponentName(sosPackage, sosClassName));
context.startService(intentService);
String appName = AppUtils.getAppNameByPackageName(context, sosPackage);
LogUtils.d(TAG, String.format("appName %s", appName));
SOSReportBean appSOSReportBean = new SOSReportBean(appName);
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
String currentTime = sdf.format(new Date());
StringBuilder sbLine = new StringBuilder();
sbLine.append("[");
sbLine.append(currentTime);
sbLine.append("] Power to ");
sbLine.append(appName);
appSOSReportBean.setSosReport(sbLine.toString());
SOSWidget.addAPPSOSReportBean(context, appSOSReportBean);
Intent intentWidget = new Intent(context, SOSWidget.class);
intentWidget.setAction(SOSWidget.ACTION_RELOAD_REPORT);
context.sendBroadcast(intentWidget);
}
} catch (IOException e) {
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
}
}
}
} else {
ToastUtils.show(szAction);
}
}
// 注册 Receiver
//
public void registerAction(MainService service) {
IntentFilter filter=new IntentFilter();
filter.addAction(ACTION_BOOT_COMPLETED);
filter.addAction(SOS.ACTION_SOS);
filter.addAction(SOS.ACTION_BIND);
filter.addAction(SOS.ACTION_SERVICE_ENABLE);
filter.addAction(SOS.ACTION_SERVICE_DISABLE);
//filter.addAction(Intent.ACTION_BATTERY_CHANGED);
service.registerReceiver(this, filter);
}
}

View File

@@ -0,0 +1,138 @@
package cc.winboll.studio.appbase.services;
/**
* @Author ZhanGSKen@AliYun.Com
* @Date 2025/02/14 03:38:31
* @Describe 守护进程服务
*/
import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import cc.winboll.studio.appbase.beans.MainServiceBean;
import cc.winboll.studio.appbase.services.AssistantService;
import cc.winboll.studio.appbase.services.MainService;
import cc.winboll.studio.libappbase.LogUtils;
import android.os.Binder;
public class AssistantService extends Service {
public static final String TAG = "AssistantService";
MainServiceBean mMainServiceBean;
MyServiceConnection mMyServiceConnection;
MainService mMainService;
boolean isBound = false;
volatile boolean isThreadAlive = false;
public synchronized void setIsThreadAlive(boolean isThreadAlive) {
LogUtils.d(TAG, "setIsThreadAlive(...)");
LogUtils.d(TAG, String.format("isThreadAlive %s", isThreadAlive));
this.isThreadAlive = isThreadAlive;
}
public boolean isThreadAlive() {
return isThreadAlive;
}
@Override
public IBinder onBind(Intent intent) {
return new MyBinder();
}
@Override
public void onCreate() {
LogUtils.d(TAG, "onCreate");
super.onCreate();
//mMyBinder = new MyBinder();
if (mMyServiceConnection == null) {
mMyServiceConnection = new MyServiceConnection();
}
// 设置运行参数
setIsThreadAlive(false);
assistantService();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
LogUtils.d(TAG, "call onStartCommand(...)");
assistantService();
return START_STICKY;
}
@Override
public void onDestroy() {
//LogUtils.d(TAG, "onDestroy");
setIsThreadAlive(false);
// 解除绑定
if (isBound) {
unbindService(mMyServiceConnection);
isBound = false;
}
super.onDestroy();
}
// 运行服务内容
//
void assistantService() {
LogUtils.d(TAG, "assistantService()");
mMainServiceBean = MainServiceBean.loadBean(this, MainServiceBean.class);
LogUtils.d(TAG, String.format("mMainServiceBean.isEnable() %s", mMainServiceBean.isEnable()));
if (mMainServiceBean.isEnable()) {
LogUtils.d(TAG, String.format("mIsThreadAlive %s", isThreadAlive()));
if (isThreadAlive() == false) {
// 设置运行状态
setIsThreadAlive(true);
// 唤醒和绑定主进程
wakeupAndBindMain();
}
}
}
// 唤醒和绑定主进程
//
void wakeupAndBindMain() {
LogUtils.d(TAG, "wakeupAndBindMain()");
// 绑定服务的Intent
Intent intent = new Intent(this, MainService.class);
startService(new Intent(this, MainService.class));
bindService(intent, mMyServiceConnection, Context.BIND_IMPORTANT);
// startService(new Intent(this, MainService.class));
// bindService(new Intent(AssistantService.this, MainService.class), mMyServiceConnection, Context.BIND_IMPORTANT);
}
// 主进程与守护进程连接时需要用到此类
//
class MyServiceConnection implements ServiceConnection {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
LogUtils.d(TAG, "onServiceConnected(...)");
MainService.MyBinder binder = (MainService.MyBinder) service;
mMainService = binder.getService();
isBound = true;
}
@Override
public void onServiceDisconnected(ComponentName name) {
LogUtils.d(TAG, "onServiceDisconnected(...)");
mMainServiceBean = MainServiceBean.loadBean(AssistantService.this, MainServiceBean.class);
if (mMainServiceBean.isEnable()) {
wakeupAndBindMain();
}
isBound = false;
mMainService = null;
}
}
// 用于返回服务实例的Binder
public class MyBinder extends Binder {
AssistantService getService() {
LogUtils.d(TAG, "AssistantService MyBinder getService()");
return AssistantService.this;
}
}
}

View File

@@ -0,0 +1,326 @@
package cc.winboll.studio.appbase.services;
/**
* @Author ZhanGSKen@AliYun.Com
* @Date 2025/02/13 06:56:41
* @Describe 拨号主服务
* 参考:
* 进程保活-双进程守护的正确姿势
* https://blog.csdn.net/sinat_35159441/article/details/75267380
* Android Service之onStartCommand方法研究
* https://blog.csdn.net/cyp331203/article/details/38920491
*/
import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Binder;
import android.os.IBinder;
import cc.winboll.studio.appbase.MyTileService;
import cc.winboll.studio.appbase.beans.MainServiceBean;
import cc.winboll.studio.appbase.handlers.MainServiceHandler;
import cc.winboll.studio.appbase.receivers.MainReceiver;
import cc.winboll.studio.appbase.services.AssistantService;
import cc.winboll.studio.appbase.threads.MainServiceThread;
import cc.winboll.studio.appbase.widgets.SOSWidget;
import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.libappbase.bean.APPSOSBean;
import java.util.ArrayList;
public class MainService extends Service {
public static final String TAG = "MainService";
public static final int MSG_UPDATE_STATUS = 0;
static MainService _mControlCenterService;
volatile boolean isServiceRunning;
MainServiceBean mMainServiceBean;
MainServiceThread mMainServiceThread;
MainServiceHandler mMainServiceHandler;
MyServiceConnection mMyServiceConnection;
AssistantService mAssistantService;
boolean isBound = false;
MainReceiver mMainReceiver;
ArrayList<SOSConnection> mSOSConnectionList;
@Override
public IBinder onBind(Intent intent) {
return new MyBinder();
}
public MainServiceThread getRemindThread() {
return mMainServiceThread;
}
@Override
public void onCreate() {
super.onCreate();
LogUtils.d(TAG, "onCreate()");
mSOSConnectionList = new ArrayList<SOSConnection>();
_mControlCenterService = MainService.this;
isServiceRunning = false;
mMainServiceBean = MainServiceBean.loadBean(this, MainServiceBean.class);
if (mMyServiceConnection == null) {
mMyServiceConnection = new MyServiceConnection();
}
mMainServiceHandler = new MainServiceHandler(this);
// 运行服务内容
mainService();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
LogUtils.d(TAG, "onStartCommand(...)");
// 运行服务内容
mainService();
return (mMainServiceBean.isEnable()) ? START_STICKY : super.onStartCommand(intent, flags, startId);
}
// 运行服务内容
//
void mainService() {
LogUtils.d(TAG, "mainService()");
mMainServiceBean = MainServiceBean.loadBean(this, MainServiceBean.class);
if (mMainServiceBean.isEnable() && isServiceRunning == false) {
LogUtils.d(TAG, "mainService() start running");
isServiceRunning = true;
// 唤醒守护进程
wakeupAndBindAssistant();
if (mMainReceiver == null) {
// 注册广播接收器
mMainReceiver = new MainReceiver(this);
mMainReceiver.registerAction(this);
}
// 启动小部件
Intent intentTimeWidget = new Intent(this, SOSWidget.class);
intentTimeWidget.setAction(SOSWidget.ACTION_RELOAD_REPORT);
this.sendBroadcast(intentTimeWidget);
startMainServiceThread();
MyTileService.updateServiceIconStatus(this);
LogUtils.i(TAG, "Main Service Is Start.");
}
}
// 唤醒和绑定守护进程
//
void wakeupAndBindAssistant() {
LogUtils.d(TAG, "wakeupAndBindAssistant()");
// if (ServiceUtils.isServiceAlive(getApplicationContext(), AssistantService.class.getName()) == false) {
// startService(new Intent(MainService.this, AssistantService.class));
// //LogUtils.d(TAG, "call wakeupAndBindAssistant() : Binding... AssistantService");
// bindService(new Intent(MainService.this, AssistantService.class), mMyServiceConnection, Context.BIND_IMPORTANT);
// }
Intent intent = new Intent(this, AssistantService.class);
startService(intent);
// 绑定服务的Intent
//Intent intent = new Intent(this, AssistantService.class);
bindService(intent, mMyServiceConnection, Context.BIND_IMPORTANT);
// Intent intent = new Intent(this, AssistantService.class);
// startService(intent);
// LogUtils.d(TAG, "startService(intent)");
// bindService(new Intent(this, AssistantService.class), mMyServiceConnection, Context.BIND_IMPORTANT);
}
// 开启提醒铃声线程
//
public void startMainServiceThread() {
LogUtils.d(TAG, "startMainServiceThread");
if (mMainServiceThread == null) {
mMainServiceThread = new MainServiceThread(this, mMainServiceHandler);
LogUtils.d(TAG, "new MainServiceThread");
} else {
if (mMainServiceThread.isExist() == true) {
mMainServiceThread = new MainServiceThread(this, mMainServiceHandler);
LogUtils.d(TAG, "renew MainServiceThread");
} else {
// 提醒进程正在进行中就更新状态后退出
LogUtils.d(TAG, "A mMainServiceThread running.");
return;
}
}
mMainServiceThread.start();
}
public void stopRemindThread() {
if (mMainServiceThread != null) {
mMainServiceThread.setIsExist(true);
mMainServiceThread = null;
}
}
@Override
public void onDestroy() {
//LogUtils.d(TAG, "onDestroy");
mMainServiceBean = MainServiceBean.loadBean(this, MainServiceBean.class);
if (mMainServiceBean.isEnable() == false) {
// 设置运行状态
isServiceRunning = false;// 解除绑定
if (isBound) {
unbindService(mMyServiceConnection);
isBound = false;
}
// 停止守护进程
Intent intent = new Intent(this, AssistantService.class);
stopService(intent);
// 停止Receiver
if (mMainReceiver != null) {
unregisterReceiver(mMainReceiver);
mMainReceiver = null;
}
// 停止前台通知栏
stopForeground(true);
// 停止消息提醒进程
stopRemindThread();
MyTileService.updateServiceIconStatus(this);
super.onDestroy();
//LogUtils.d(TAG, "onDestroy done");
}
}
public void bindSOSConnection(APPSOSBean bean) {
LogUtils.d(TAG, "bindSOSConnection(...)");
// 清理旧的绑定链接
for (int i = mSOSConnectionList.size() - 1; i > -1; i--) {
SOSConnection item = mSOSConnectionList.get(i);
if (item.isBindToAPPSOSBean(bean)) {
LogUtils.d(TAG, "Bind Servive exist.");
unbindService(item);
mSOSConnectionList.remove(i);
}
}
// 绑定服务
SOSConnection sosConnection = new SOSConnection();
Intent intentService = new Intent();
intentService.setComponent(new ComponentName(bean.getSosPackage(), bean.getSosClassName()));
bindService(intentService, sosConnection, Context.BIND_IMPORTANT);
mSOSConnectionList.add(sosConnection);
Intent intentWidget = new Intent(this, SOSWidget.class);
intentWidget.setAction(SOSWidget.ACTION_WAKEUP_SERVICE);
APPSOSBean appSOSBean = new APPSOSBean(bean.getSosPackage(), bean.getSosClassName());
intentWidget.putExtra("APPSOSBean", appSOSBean.toString());
sendBroadcast(intentWidget);
}
public class SOSConnection implements ServiceConnection {
ComponentName mComponentName;
boolean isBindToAPPSOSBean(APPSOSBean bean) {
return mComponentName != null
&& mComponentName.getClassName().equals(bean.getSosClassName())
&& mComponentName.getPackageName().equals(bean.getSosPackage());
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
LogUtils.d(TAG, "onServiceConnected(...)");
mComponentName = name;
LogUtils.d(TAG, String.format("onServiceConnected : \ngetClassName %s\ngetPackageName %s", name.getClassName(), name.getPackageName()));
}
@Override
public void onServiceDisconnected(ComponentName name) {
LogUtils.d(TAG, "onServiceDisconnected(...)");
LogUtils.d(TAG, String.format("onServiceDisconnected : \ngetClassName %s\ngetPackageName %s", name.getClassName(), name.getPackageName()));
// 尝试无参数启动一下服务
String sosPackage = mComponentName.getPackageName();
LogUtils.d(TAG, String.format("sosPackage %s", sosPackage));
String sosClassName = mComponentName.getClassName();
LogUtils.d(TAG, String.format("sosClassName %s", sosClassName));
Intent intentService = new Intent();
intentService.setComponent(new ComponentName(sosPackage, sosClassName));
startService(intentService);
}
}
// 主进程与守护进程连接时需要用到此类
//
private class MyServiceConnection implements ServiceConnection {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
LogUtils.d(TAG, "onServiceConnected(...)");
AssistantService.MyBinder binder = (AssistantService.MyBinder) service;
mAssistantService = binder.getService();
isBound = true;
}
@Override
public void onServiceDisconnected(ComponentName name) {
LogUtils.d(TAG, "onServiceDisconnected(...)");
if (mMainServiceBean.isEnable()) {
// 唤醒守护进程
wakeupAndBindAssistant();
}
isBound = false;
mAssistantService = null;
}
}
// 用于返回服务实例的Binder
public class MyBinder extends Binder {
MainService getService() {
LogUtils.d(TAG, "MainService MyBinder getService()");
return MainService.this;
}
}
// //
// // 启动服务
// //
// public static void startControlCenterService(Context context) {
// Intent intent = new Intent(context, MainService.class);
// context.startForegroundService(intent);
// }
//
// //
// // 停止服务
// //
// public static void stopControlCenterService(Context context) {
// Intent intent = new Intent(context, MainService.class);
// context.stopService(intent);
// }
public void appenMessage(String message) {
LogUtils.d(TAG, String.format("Message : %s", message));
}
public static void stopMainService(Context context) {
LogUtils.d(TAG, "stopMainService");
MainServiceBean bean = new MainServiceBean();
bean.setIsEnable(false);
MainServiceBean.saveBean(context, bean);
context.stopService(new Intent(context, MainService.class));
}
public static void startMainService(Context context) {
LogUtils.d(TAG, "startMainService");
MainServiceBean bean = new MainServiceBean();
bean.setIsEnable(true);
MainServiceBean.saveBean(context, bean);
context.startService(new Intent(context, MainService.class));
}
}

View File

@@ -0,0 +1,54 @@
package cc.winboll.studio.appbase.threads;
/**
* @Author ZhanGSKen@AliYun.Com
* @Date 2025/02/14 03:46:44
*/
import android.content.Context;
import cc.winboll.studio.appbase.handlers.MainServiceHandler;
import cc.winboll.studio.libappbase.LogUtils;
import java.lang.ref.WeakReference;
public class MainServiceThread extends Thread {
public static final String TAG = "MainServiceThread";
Context mContext;
// 控制线程是否退出的标志
volatile boolean isExist = false;
// 服务Handler, 用于线程发送消息使用
WeakReference<MainServiceHandler> mwrMainServiceHandler;
public void setIsExist(boolean isExist) {
this.isExist = isExist;
}
public boolean isExist() {
return isExist;
}
public MainServiceThread(Context context, MainServiceHandler handler) {
mContext = context;
mwrMainServiceHandler = new WeakReference<MainServiceHandler>(handler);
}
@Override
public void run() {
LogUtils.d(TAG, "run()");
while (!isExist()) {
//ToastUtils.show("run()");
//LogUtils.d(TAG, "run()");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
}
}
LogUtils.d(TAG, "run() exit.");
}
}

View File

@@ -0,0 +1,184 @@
package cc.winboll.studio.appbase.widgets;
/**
* @Author ZhanGSKen@AliYun.Com
* @Date 2025/02/15 14:41:25
* @Describe TimeWidget
*/
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.widget.RemoteViews;
import cc.winboll.studio.appbase.R;
import cc.winboll.studio.appbase.beans.SOSReportBean;
import cc.winboll.studio.libappbase.AppUtils;
import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.libappbase.bean.APPSOSBean;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
public class SOSWidget extends AppWidgetProvider {
public static final String TAG = "SOSWidget";
public static final String ACTION_WAKEUP_SERVICE = "cc.winboll.studio.appbase.widgets.SOSWidget.ACTION_WAKEUP_SERVICE";
public static final String ACTION_RELOAD_REPORT = "cc.winboll.studio.appbase.widgets.SOSWidget.ACTION_RELOAD_REPORT";
volatile static ArrayList<SOSReportBean> _SOSReportBeanList;
final static int _MAX_PAGES = 10;
final static int _OnePageLinesCount = 5;
volatile static int _CurrentPageIndex = 0;
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
initAPPSOSReportBeanList(context);
for (int appWidgetId : appWidgetIds) {
updateAppWidget(context, appWidgetManager, appWidgetId);
}
}
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
initAPPSOSReportBeanList(context);
if (intent.getAction().equals(ACTION_RELOAD_REPORT)) {
LogUtils.d(TAG, "ACTION_RELOAD_REPORT");
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, SOSWidget.class));
for (int appWidgetId : appWidgetIds) {
updateAppWidget(context, appWidgetManager, appWidgetId);
}
}else if (intent.getAction().equals(ACTION_WAKEUP_SERVICE)) {
LogUtils.d(TAG, "ACTION_WAKEUP_SERVICE");
String szAPPSOSBean = intent.getStringExtra("APPSOSBean");
LogUtils.d(TAG, String.format("szAPPSOSBean %s", szAPPSOSBean));
if (szAPPSOSBean != null && !szAPPSOSBean.equals("")) {
try {
APPSOSBean bean = APPSOSBean.parseStringToBean(szAPPSOSBean, APPSOSBean.class);
if (bean != null) {
String sosPackage = bean.getSosPackage();
LogUtils.d(TAG, String.format("sosPackage %s", sosPackage));
String sosClassName = bean.getSosClassName();
LogUtils.d(TAG, String.format("sosClassName %s", sosClassName));
String appName = AppUtils.getAppNameByPackageName(context, sosPackage);
LogUtils.d(TAG, String.format("appName %s", appName));
SOSReportBean appSOSReportBean = new SOSReportBean(appName);
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
String currentTime = sdf.format(new Date());
StringBuilder sbLine = new StringBuilder();
sbLine.append("[");
sbLine.append(currentTime);
sbLine.append("] Wake up ");
sbLine.append(appName);
appSOSReportBean.setSosReport(sbLine.toString());
addAPPSOSReportBean(context, appSOSReportBean);
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, SOSWidget.class));
for (int appWidgetId : appWidgetIds) {
updateAppWidget(context, appWidgetManager, appWidgetId);
}
}
} catch (IOException e) {
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
}
}
}
}
//
// 加入新报告信息
//
public synchronized static void addAPPSOSReportBean(Context context, SOSReportBean bean) {
initAPPSOSReportBeanList(context);
_SOSReportBeanList.add(0, bean);
// 控制记录总数
while (_SOSReportBeanList.size() > _MAX_PAGES * _OnePageLinesCount) {
_SOSReportBeanList.remove(_SOSReportBeanList.size() - 1);
}
SOSReportBean.saveBeanList(context, _SOSReportBeanList, SOSReportBean.class);
}
synchronized static void initAPPSOSReportBeanList(Context context) {
if (_SOSReportBeanList == null) {
_SOSReportBeanList = new ArrayList<SOSReportBean>();
SOSReportBean.loadBeanList(context, _SOSReportBeanList, SOSReportBean.class);
}
if (_SOSReportBeanList == null) {
_SOSReportBeanList = new ArrayList<SOSReportBean>();
SOSReportBean.saveBeanList(context, _SOSReportBeanList, SOSReportBean.class);
}
}
private void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
LogUtils.d(TAG, "updateAppWidget(...)");
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_sos);
//设置按钮点击事件
Intent intentPre = new Intent(context, SOSWidgetClickListener.class);
intentPre.setAction(SOSWidgetClickListener.ACTION_PRE);
PendingIntent pendingIntentPre = PendingIntent.getBroadcast(context, 0, intentPre, PendingIntent.FLAG_UPDATE_CURRENT);
views.setOnClickPendingIntent(R.id.widget_button_pre, pendingIntentPre);
Intent intentNext = new Intent(context, SOSWidgetClickListener.class);
intentNext.setAction(SOSWidgetClickListener.ACTION_NEXT);
PendingIntent pendingIntentNext = PendingIntent.getBroadcast(context, 0, intentNext, PendingIntent.FLAG_UPDATE_CURRENT);
views.setOnClickPendingIntent(R.id.widget_button_next, pendingIntentNext);
views.setTextViewText(R.id.infoTextView, getPageInfo());
views.setTextViewText(R.id.sosReportTextView, getMessage());
appWidgetManager.updateAppWidget(appWidgetId, views);
}
public static String getMessage() {
ArrayList<String> msgTemp = new ArrayList<String>();
if (_SOSReportBeanList != null) {
int start = _OnePageLinesCount * _CurrentPageIndex;
start = _SOSReportBeanList.size() > start ? start : _SOSReportBeanList.size() - 1;
for (int i = start, j = 0; i < _SOSReportBeanList.size() && j < _OnePageLinesCount && start > -1; i++, j++) {
msgTemp.add(_SOSReportBeanList.get(i).getSosReport());
}
String message = String.join("\n", msgTemp);
return message;
}
return "";
}
public static void prePage(Context context) {
if (_SOSReportBeanList != null) {
if (_CurrentPageIndex > 0) {
_CurrentPageIndex = _CurrentPageIndex - 1;
}
Intent intentWidget = new Intent(context, SOSWidget.class);
intentWidget.setAction(SOSWidget.ACTION_RELOAD_REPORT);
context.sendBroadcast(intentWidget);
}
}
public static void nextPage(Context context) {
if (_SOSReportBeanList != null) {
if ((_CurrentPageIndex + 1) * _OnePageLinesCount < _SOSReportBeanList.size()) {
_CurrentPageIndex = _CurrentPageIndex + 1;
}
Intent intentWidget = new Intent(context, SOSWidget.class);
intentWidget.setAction(SOSWidget.ACTION_RELOAD_REPORT);
context.sendBroadcast(intentWidget);
}
}
String getPageInfo() {
if (_SOSReportBeanList == null) {
return "0/0";
}
int leftCount = _SOSReportBeanList.size() % _OnePageLinesCount;
int currentPageCount = _SOSReportBeanList.size() / _OnePageLinesCount + (leftCount == 0 ?0: 1);
return String.format("%d/%d", _CurrentPageIndex + 1, currentPageCount);
}
}

View File

@@ -0,0 +1,36 @@
package cc.winboll.studio.appbase.widgets;
/**
* @Author ZhanGSKen@AliYun.Com
* @Date 2025/02/15 17:20:46
* @Describe WidgetButtonClickListener
*/
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import cc.winboll.studio.libappbase.LogUtils;
public class SOSWidgetClickListener extends BroadcastReceiver {
public static final String TAG = "SOSWidgetClickListener";
public static final String ACTION_PRE = "cc.winboll.studio.appbase.widgets.SOSWidgetClickListener.ACTION_PRE";
public static final String ACTION_NEXT = "cc.winboll.studio.appbase.widgets.SOSWidgetClickListener.ACTION_NEXT";
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action == null) {
LogUtils.d(TAG, String.format("action %s", action));
return;
}
if (action.equals(ACTION_PRE)) {
LogUtils.d(TAG, "ACTION_PRE");
SOSWidget.prePage(context);
} else if (action.equals(ACTION_NEXT)) {
LogUtils.d(TAG, "ACTION_NEXT");
SOSWidget.nextPage(context);
} else {
LogUtils.d(TAG, String.format("action %s", action));
}
}
}

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24">
<path
android:fillColor="#ff000000"
android:pathData="M6.5,20Q4.22,20 2.61,18.43 1,16.85 1,14.58 1,12.63 2.17,11.1 3.35,9.57 5.25,9.15 5.88,6.85 7.75,5.43 9.63,4 12,4 14.93,4 16.96,6.04 19,8.07 19,11 20.73,11.2 21.86,12.5 23,13.78 23,15.5 23,17.38 21.69,18.69 20.38,20 18.5,20Z"/>
</vector>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24">
<path
android:fillColor="#ff000000"
android:pathData="M6.5,20Q4.22,20 2.61,18.43 1,16.85 1,14.58 1,12.63 2.17,11.1 3.35,9.57 5.25,9.15 5.88,6.85 7.75,5.43 9.63,4 12,4 14.93,4 16.96,6.04 19,8.07 19,11 20.73,11.2 21.86,12.5 23,13.78 23,15.5 23,17.38 21.69,18.69 20.38,20 18.5,20M6.5,18H18.5Q19.55,18 20.27,17.27 21,16.55 21,15.5 21,14.45 20.27,13.73 19.55,13 18.5,13H17V11Q17,8.93 15.54,7.46 14.08,6 12,6 9.93,6 8.46,7.46 7,8.93 7,11H6.5Q5.05,11 4.03,12.03 3,13.05 3,14.5 3,15.95 4.03,17 5.05,18 6.5,18M12,12Z"/>
</vector>

View File

@@ -24,6 +24,13 @@
android:layout_height="wrap_content"
android:text="Hello, WinBoll!"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Android版本10的代号是“Q”API级别是29。 Android 10开始谷歌不再公开使用甜品作为版本代号但内部仍保留了大量与“Q”相关的元素。Android 10本身并没有严格对应某个特定的Java版本但在开发Android 10应用时通常可以使用Java 8或更高版本。
Java 8为Android开发带来了诸如Lambda表达式、方法引用等新特性能提高开发效率和代码可读性与Android 10开发适配良好。Java 9及更高版本也可用于Android 10开发能使用一些新的语言特性和API但可能需要注意兼容性和配置问题。"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
@@ -47,47 +54,88 @@
</LinearLayout>
<LinearLayout
android:orientation="vertical"
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right">
android:layout_height="400dp">
<Button
android:layout_width="wrap_content"
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="StartCenter"
android:textAllCaps="false"
android:onClick="onStartCenter"/>
android:gravity="right">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="StopCenter"
android:textAllCaps="false"
android:onClick="onStopCenter"/>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TestStopWithoutSettingEnable"
android:textAllCaps="false"
android:onClick="onTestStopWithoutSettingEnable"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TestStartWithString"
android:textAllCaps="false"
android:onClick="onTestStartWithString"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SOS"
android:onClick="onSOS"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="StartTestService"
android:textAllCaps="false"
android:onClick="onStartTestService"/>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="StopTestService"
android:textAllCaps="false"
android:onClick="onStopTestService"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="StopTestServiceNoSettings"
android:textAllCaps="false"
android:onClick="onStopTestServiceNoSettings"/>
</LinearLayout>
</HorizontalScrollView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="StartCenter"
android:textAllCaps="false"
android:onClick="onStartCenter"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="StopCenter"
android:textAllCaps="false"
android:onClick="onStopCenter"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TestStopWithoutSettingEnable"
android:textAllCaps="false"
android:onClick="onTestStopWithoutSettingEnable"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TestStartWithString"
android:textAllCaps="false"
android:onClick="onTestStartWithString"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SOS"
android:textAllCaps="false"
android:onClick="onSOS"/>
</LinearLayout>
</ScrollView>
<cc.winboll.studio.libappbase.LogView
android:layout_weight="1.0"

View File

@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#FFFFFFFF">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/infoTextView"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="⇦"
android:id="@+id/widget_button_pre"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="⇨"
android:id="@+id/widget_button_next"/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/sosReportTextView"
android:layout_weight="1.0"/>
</LinearLayout>

View File

@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">AppBase</string>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">AppBase</string>
<string name="tileservice_name">WinBoll</string>
</resources>

View File

@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="APPBaseTheme">
<item name="attrColorPrimary">@color/colorPrimary</item>
<item name="themeGlobalCrashActivity">@style/MyGlobalCrashActivityTheme</item>
</style>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="200dp"
android:minHeight="100dp"
android:updatePeriodMillis="1000"
android:initialLayout="@layout/widget_sos">
</appwidget-provider>

View File

@@ -1,8 +1,21 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
maven { url 'https://maven.aliyun.com/repository/public/' }
maven { url 'https://maven.aliyun.com/repository/google/' }
maven { url 'https://maven.aliyun.com/repository/gradle-plugin/' }
maven { url 'https://dl.bintray.com/ppartisan/maven/' }
maven { url "https://clojars.org/repo/" }
maven { url "https://jitpack.io" }
mavenCentral()
google()
mavenLocal()
// Nexus Maven 库地址
// "WinBoll Release"
maven { url "https://nexus.winboll.cc/repository/maven-public/" }
// "WinBoll Snapshot"
maven { url "https://nexus.winboll.cc/repository/maven-snapshots/" }
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.1'
@@ -13,11 +26,12 @@ buildscript {
allprojects {
repositories {
// Nexus Maven 库地址
// "WinBoll Release"
maven { url "https://nexus.winboll.cc/repository/maven-public/" }
// "WinBoll Snapshot"
maven { url "https://nexus.winboll.cc/repository/maven-snapshots/" }
maven {
url "https://mirrors.tencent.com/repository/maven/tencent_public/"
}
maven {
url "https://mirrors.tencent.com/repository/maven/tencent_public_snapshots"
}
maven { url 'https://maven.aliyun.com/repository/public/' }
maven { url 'https://maven.aliyun.com/repository/google/' }
@@ -28,6 +42,12 @@ allprojects {
mavenCentral()
google()
mavenLocal()
// Nexus Maven 库地址
// "WinBoll Release"
maven { url "https://nexus.winboll.cc/repository/maven-public/" }
// "WinBoll Snapshot"
maven { url "https://nexus.winboll.cc/repository/maven-snapshots/" }
}
ext {
// 定义全局变量,常用于版本管理
@@ -69,6 +89,14 @@ allprojects {
}
}
}
subprojects {
tasks.withType(JavaCompile) {
options.compilerArgs << "-parameters"
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
}
task clean(type: Delete) {

View File

@@ -6,7 +6,7 @@
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx2048m
org.gradle.jvmargs=-Xmx4096m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
@@ -18,7 +18,9 @@ android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
#org.gradle.caching=true
org.gradle.caching=true
android.disableAutomaticComponentCreation=true
android.injected.testOnly=false

View File

@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl = https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionUrl = https\://services.gradle.org/distributions/gradle-7.5.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@@ -4,14 +4,12 @@ apply from: '../.winboll/winboll_lib_build.gradle'
apply from: '../.winboll/winboll_lint_build.gradle'
android {
namespace 'cc.winboll.studio.libappbase'
compileSdkVersion 32
buildToolsVersion "33.0.3"
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
minSdkVersion 21
targetSdkVersion 30
minSdkVersion 26
targetSdkVersion 29
}
buildTypes {
release {
@@ -19,10 +17,6 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
}
dependencies {

View File

@@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle
#Thu Feb 13 06:53:34 HKT 2025
stageCount=1
#Tue Feb 25 16:51:09 HKT 2025
stageCount=3
libraryProject=libappbase
baseVersion=1.5
publishVersion=1.5.0
baseVersion=2.0
publishVersion=2.0.2
buildCount=0
baseBetaVersion=1.5.1
baseBetaVersion=2.0.3

View File

@@ -6,6 +6,9 @@
<!-- 拥有完全的网络访问权限 -->
<uses-permission android:name="android.permission.INTERNET"/>
<!-- 发送持久广播 -->
<uses-permission android:name="android.permission.BROADCAST_STICKY"/>
<application>
<activity
@@ -18,10 +21,58 @@
android:label="GlobalCrashActivity"
android:launchMode="standard"/>
<service android:name=".SimpleOperateSignalCenterService"/>
<activity android:name=".LogActivity"/>
<service
android:name=".SimpleOperateSignalCenterService"
android:exported="true">
</service>
<service
android:name=".services.TestService"
android:exported="true"/>
<receiver android:name=".receiver.MyBroadcastReceiver">
<intent-filter>
<action android:name="cc.winboll.studio.libappbase.action.SOS"/>
</intent-filter>
</receiver>
<receiver
android:name=".widgets.StatusWidget"
android:exported="true">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
<action android:name="cc.winboll.studio.libappbase.widgets.StatusWidget.ACTION_STATUS_UPDATE"/>
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/widget_provider_info_status"/>
</receiver>
<receiver
android:name=".widgets.StatusWidgetClickListener"
android:exported="true">
<intent-filter>
<action android:name="cc.winboll.studio.libappbase.widgets.StatusWidgetClickListener.ACTION_IVAPP"/>
</intent-filter>
</receiver>
</application>
</manifest>

View File

@@ -0,0 +1,28 @@
package cc.winboll.studio.libappbase;
/**
* @Author ZhanGSKen@AliYun.Com
* @Date 2025/02/15 20:05:03
* @Describe AppUtils
*/
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
public class AppUtils {
public static final String TAG = "AppUtils";
public static String getAppNameByPackageName(Context context, String packageName) {
PackageManager packageManager = context.getPackageManager();
try {
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(packageName, 0);
return (String) packageManager.getApplicationLabel(applicationInfo);
} catch (NameNotFoundException e) {
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
return "";
}
}
}

View File

@@ -118,7 +118,11 @@ public abstract class BaseBean<T extends BaseBean> {
public static <T extends BaseBean> boolean parseStringToBeanList(String szBeanList, ArrayList<T> beanList, Class<T> clazz) {
try {
beanList.clear();
if(beanList == null) {
beanList = new ArrayList<T>();
} else {
beanList.clear();
}
StringReader stringReader = new StringReader(szBeanList);
JsonReader jsonReader = new JsonReader(stringReader);
jsonReader.beginArray();

View File

@@ -18,7 +18,7 @@ import android.view.Gravity;
import com.hjq.toast.ToastUtils;
import com.hjq.toast.style.WhiteToastStyle;
public class GlobalApplication extends Application implements ISOSAPP {
public class GlobalApplication extends Application {
public static final String TAG = "GlobalApplication";
@@ -93,27 +93,27 @@ public class GlobalApplication extends Application implements ISOSAPP {
}
return null;
}
@Override
public void helpISOSService(Intent intent) {
String szServiceName = intent.getStringExtra(EXTRA_SERVICE);
String szPackageName = intent.getStringExtra(EXTRA_PACKAGE);
if (szServiceName != null && !szServiceName.equals("")
&& szPackageName != null && !szPackageName.equals("")) {
LogUtils.d(TAG, "szPackageName " + szPackageName);
LogUtils.d(TAG, "szServiceName " + szServiceName);
// 目标服务的包名和类名
//String packageName = this.getPackageName();
//String serviceClassName = SimpleOperateSignalCenterService.class.getName();
// 构建Intent
Intent intentService = new Intent();
intentService.setComponent(new ComponentName(szPackageName, szServiceName));
intentService.putExtra(ISOSService.EXTRA_ENABLE, true);
startService(intentService);
LogUtils.d(TAG, "startService(intentService)");
}
LogUtils.d(TAG, "helpISOSService");
}
//
// @Override
// public void helpISOSService(Intent intent) {
// String szServiceName = intent.getStringExtra(EXTRA_SERVICE);
// String szPackageName = intent.getStringExtra(EXTRA_PACKAGE);
// if (szServiceName != null && !szServiceName.equals("")
// && szPackageName != null && !szPackageName.equals("")) {
// LogUtils.d(TAG, "szPackageName " + szPackageName);
// LogUtils.d(TAG, "szServiceName " + szServiceName);
//
// // 目标服务的包名和类名
// //String packageName = this.getPackageName();
// //String serviceClassName = SimpleOperateSignalCenterService.class.getName();
//
// // 构建Intent
// Intent intentService = new Intent();
// intentService.setComponent(new ComponentName(szPackageName, szServiceName));
// intentService.putExtra(ISOSService.EXTRA_ENABLE, true);
// startService(intentService);
// LogUtils.d(TAG, "startService(intentService)");
// }
// LogUtils.d(TAG, "helpISOSService");
// }
}

View File

@@ -1,17 +0,0 @@
package cc.winboll.studio.libappbase;
import android.content.Intent;
/**
* @Author ZhanGSKen@AliYun.Com
* @Date 2025/02/13 03:49:35
* @Describe 简单 SOS 接口
*/
public interface ISOSAPP {
public static final String TAG = "ISOS";
public static final String EXTRA_PACKAGE = "EXTRA_PACKAGE";
public static final String EXTRA_SERVICE = "EXTRA_SERVICE";
public void helpISOSService(Intent intent);
}

View File

@@ -1,17 +0,0 @@
package cc.winboll.studio.libappbase;
/**
* @Author ZhanGSKen@AliYun.Com
* @Date 2025/02/13 04:13:51
* @Describe 简单链接 SOS 体系的服务
*/
import android.content.Intent;
public interface ISOSService {
public static final String TAG = "ISOSService";
public static final String EXTRA_ENABLE = "EXTRA_ENABLE";
public Intent getISOSServiceIntentWhichAskForHelp();
public boolean isEnable();
}

View File

@@ -0,0 +1,57 @@
package cc.winboll.studio.libappbase;
/**
* @Author ZhanGSKen@AliYun.Com
* @Date 2025/02/13 21:09:36
* @Describe SOS 组件
*/
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import cc.winboll.studio.libappbase.bean.APPSOSBean;
import java.util.ArrayList;
public class SOS {
public static final String TAG = "SOS";
public static final String ACTION_SOS = SOS.class.getName() + ".ACTION_SOS";
public static final String ACTION_BIND = SOS.class.getName() + ".ACTION_BIND";
public static final String ACTION_SERVICE_ENABLE = SOS.class.getName() + ".ACTION_SERVICE_ENABLE";
public static final String ACTION_SERVICE_DISABLE = SOS.class.getName() + ".ACTION_SERVICE_DISENABLE";
public static void sosWinBollService(Context context, APPSOSBean bean) {
Intent intent = new Intent(ACTION_SOS);
intent.putExtra("SOS", "Service");
intent.putExtra("APPSOSBean", bean.toString());
String szToPackage = "";
if (GlobalApplication.isDebuging()) {
szToPackage = "cc.winboll.studio.appbase.beta";
} else {
szToPackage = "cc.winboll.studio.appbase";
}
intent.setPackage(szToPackage);
context.sendBroadcast(intent);
LogUtils.d(TAG, String.format("Send ACTION_SOS To WinBoll. (szToPackage : %s)", szToPackage));
//ToastUtils.show("SOS Send To WinBoll");
}
public static void bindToAPPService(Context context, APPSOSBean bean) {
Intent intent = new Intent(ACTION_BIND);
intent.putExtra("SOS", "Service");
intent.putExtra("APPSOSBean", bean.toString());
String szToPackage = "";
if (GlobalApplication.isDebuging()) {
szToPackage = "cc.winboll.studio.appbase.beta";
} else {
szToPackage = "cc.winboll.studio.appbase";
}
intent.setPackage(szToPackage);
context.sendBroadcast(intent);
LogUtils.d(TAG, String.format("Send ACTION_BIND To WinBoll. (szToPackage : %s)", szToPackage));
}
}

View File

@@ -14,17 +14,17 @@ public class SOSCSBroadcastReceiver extends BroadcastReceiver {
public static final String TAG = "SOSCSBroadcastReceiver";
public static final String ACTION_SOS = SOSCSBroadcastReceiver.class.getName() + ".ACTION_SOS";
ISOSAPP mISOSAPP;
//ISOSAPP mISOSAPP;
public SOSCSBroadcastReceiver(ISOSAPP iSOSAPP) {
mISOSAPP = iSOSAPP;
public SOSCSBroadcastReceiver() {
//mISOSAPP = iSOSAPP;
}
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(ACTION_SOS)) {
LogUtils.d(TAG, "ACTION_SOS");
mISOSAPP.helpISOSService(intent);
//mISOSAPP.helpISOSService(intent);
} else {
LogUtils.d(TAG, String.format("%s", action));
}

View File

@@ -10,14 +10,20 @@ import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.os.IInterface;
import android.os.Parcel;
import android.os.RemoteException;
import cc.winboll.studio.libappbase.bean.SimpleOperateSignalCenterServiceBean;
import java.io.FileDescriptor;
public class SimpleOperateSignalCenterService extends Service implements ISOSService {
public class SimpleOperateSignalCenterService extends Service {
public static final String TAG = "SimpleOperateSignalCenterService";
public static final String ACTION_ENABLE = SimpleOperateSignalCenterService.class.getName() + ".ACTION_ENABLE";
public static final String ACTION_DISABLE = SimpleOperateSignalCenterService.class.getName() + ".ACTION_DISABLE";
private final IBinder binder =(IBinder)new SOSBinder();
SimpleOperateSignalCenterServiceBean mSimpleOperateSignalCenterServiceBean;
static MainThread _MainThread;
public static synchronized MainThread getMainThreadInstance() {
@@ -29,25 +35,79 @@ public class SimpleOperateSignalCenterService extends Service implements ISOSSer
@Override
public IBinder onBind(Intent intent) {
return null;
return binder;
}
public class SOSBinder implements IBinder {
@Override
public void dump(FileDescriptor fileDescriptor, String[] string) throws RemoteException {
}
@Override
public void dumpAsync(FileDescriptor fileDescriptor, String[] string) throws RemoteException {
}
@Override
public String getInterfaceDescriptor() throws RemoteException {
return null;
}
@Override
public boolean isBinderAlive() {
return false;
}
@Override
public void linkToDeath(IBinder.DeathRecipient deathRecipient, int p) throws RemoteException {
}
@Override
public boolean pingBinder() {
return false;
}
@Override
public IInterface queryLocalInterface(String string) {
return null;
}
@Override
public boolean transact(int p, Parcel parcel, Parcel parcel1, int p1) throws RemoteException {
return false;
}
@Override
public boolean unlinkToDeath(IBinder.DeathRecipient deathRecipient, int p) {
return false;
}
public static final String TAG = "SOSBinder";
SimpleOperateSignalCenterService getService() {
return SimpleOperateSignalCenterService.this;
}
}
@Override
public void onCreate() {
super.onCreate();
LogUtils.d(TAG, "onCreate");
mSimpleOperateSignalCenterServiceBean = SimpleOperateSignalCenterServiceBean.loadBean(this, SimpleOperateSignalCenterServiceBean.class);
if(mSimpleOperateSignalCenterServiceBean == null) {
mSimpleOperateSignalCenterServiceBean = new SimpleOperateSignalCenterServiceBean();
SimpleOperateSignalCenterServiceBean.saveBean(this, mSimpleOperateSignalCenterServiceBean);
}
runMainThread();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
LogUtils.d(TAG, "onStartCommand");
if (intent.getBooleanExtra(ISOSService.EXTRA_ENABLE, false)) {
LogUtils.d(TAG, "onStartCommand enable service");
mSimpleOperateSignalCenterServiceBean.setIsEnable(true);
SimpleOperateSignalCenterServiceBean.saveBean(this, mSimpleOperateSignalCenterServiceBean);
}
// if (intent.getBooleanExtra(ISOSService.EXTRA_ENABLE, false)) {
// LogUtils.d(TAG, "onStartCommand enable service");
// mSimpleOperateSignalCenterServiceBean.setIsEnable(true);
// SimpleOperateSignalCenterServiceBean.saveBean(this, mSimpleOperateSignalCenterServiceBean);
// }
runMainThread();
@@ -63,20 +123,6 @@ public class SimpleOperateSignalCenterService extends Service implements ISOSSer
}
}
@Override
public Intent getISOSServiceIntentWhichAskForHelp() {
Intent intentService = new Intent();
intentService.putExtra(ISOSAPP.EXTRA_PACKAGE, this.getPackageName());
intentService.putExtra(ISOSAPP.EXTRA_SERVICE, this.getClass().getName());
return intentService;
}
@Override
public boolean isEnable() {
mSimpleOperateSignalCenterServiceBean = SimpleOperateSignalCenterServiceBean.loadBean(this, SimpleOperateSignalCenterServiceBean.class);
return mSimpleOperateSignalCenterServiceBean.isEnable();
}
@Override
public void onDestroy() {
super.onDestroy();
@@ -84,8 +130,8 @@ public class SimpleOperateSignalCenterService extends Service implements ISOSSer
mSimpleOperateSignalCenterServiceBean = SimpleOperateSignalCenterServiceBean.loadBean(this, SimpleOperateSignalCenterServiceBean.class);
if (mSimpleOperateSignalCenterServiceBean.isEnable()) {
LogUtils.d(TAG, "mSimpleOperateSignalCenterServiceBean.isEnable()");
ISOSAPP iSOSAPP = (ISOSAPP)getApplication();
iSOSAPP.helpISOSService(getISOSServiceIntentWhichAskForHelp());
// ISOSAPP iSOSAPP = (ISOSAPP)getApplication();
// iSOSAPP.helpISOSService(getISOSServiceIntentWhichAskForHelp());
}
if (_MainThread != null) {
_MainThread.isExist = true;
@@ -108,6 +154,10 @@ public class SimpleOperateSignalCenterService extends Service implements ISOSSer
SimpleOperateSignalCenterServiceBean.saveBean(context, bean);
context.startService(new Intent(context, SimpleOperateSignalCenterService.class));
}
public String getMessage() {
return "Hello from SimpleOperateSignalCenterService";
}
static class MainThread extends Thread {
volatile boolean isExist = false;

View File

@@ -0,0 +1,87 @@
package cc.winboll.studio.libappbase.bean;
/**
* @Author ZhanGSKen@AliYun.Com
* @Date 2025/02/17 00:29:29
* @Describe APPSOSReportBean
*/
import android.util.JsonReader;
import android.util.JsonWriter;
import cc.winboll.studio.libappbase.BaseBean;
import java.io.IOException;
import java.io.Serializable;
public class APPSOSBean extends BaseBean {
public static final String TAG = "APPSOSBean";
protected String sosPackage;
protected String sosClassName;
public APPSOSBean() {
this.sosPackage = "";
this.sosClassName = "";
}
public APPSOSBean(String sosPackage, String sosClassName) {
this.sosPackage = sosPackage;
this.sosClassName = sosClassName;
}
public void setSosPackage(String sosPackage) {
this.sosPackage = sosPackage;
}
public String getSosPackage() {
return sosPackage;
}
public void setSosClassName(String sosClassName) {
this.sosClassName = sosClassName;
}
public String getSosClassName() {
return sosClassName;
}
@Override
public String getName() {
return APPSOSBean.class.getName();
}
@Override
public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
super.writeThisToJsonWriter(jsonWriter);
jsonWriter.name("sosPackage").value(getSosPackage());
jsonWriter.name("sosClassName").value(getSosClassName());
}
@Override
public boolean initObjectsFromJsonReader(JsonReader jsonReader, String name) throws IOException {
if (super.initObjectsFromJsonReader(jsonReader, name)) { return true; } else {
if (name.equals("sosPackage")) {
setSosPackage(jsonReader.nextString());
} else if (name.equals("sosClassName")) {
setSosClassName(jsonReader.nextString());
} else {
return false;
}
}
return true;
}
@Override
public BaseBean readBeanFromJsonReader(JsonReader jsonReader) throws IOException {
jsonReader.beginObject();
while (jsonReader.hasNext()) {
String name = jsonReader.nextName();
if (!initObjectsFromJsonReader(jsonReader, name)) {
jsonReader.skipValue();
}
}
// 结束 JSON 对象
jsonReader.endObject();
return this;
}
}

View File

@@ -34,8 +34,7 @@ public class SimpleOperateSignalCenterServiceBean extends BaseBean {
@Override
public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
super.writeThisToJsonWriter(jsonWriter);
SimpleOperateSignalCenterServiceBean bean = this;
jsonWriter.name("isEnable").value(bean.isEnable());
jsonWriter.name("isEnable").value(isEnable());
}

View File

@@ -0,0 +1,67 @@
package cc.winboll.studio.libappbase.bean;
/**
* @Author ZhanGSKen@AliYun.Com
* @Date 2025/02/19 13:34:52
* @Describe TestServiceBean
*/
import android.util.JsonReader;
import android.util.JsonWriter;
import cc.winboll.studio.libappbase.BaseBean;
import java.io.IOException;
public class TestServiceBean extends BaseBean {
public static final String TAG = "TestServiceBean";
boolean isEnable;
public TestServiceBean() {
this.isEnable = false;
}
public void setIsEnable(boolean isEnable) {
this.isEnable = isEnable;
}
public boolean isEnable() {
return isEnable;
}
@Override
public String getName() {
return TestServiceBean.class.getName();
}
@Override
public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
super.writeThisToJsonWriter(jsonWriter);
jsonWriter.name("isEnable").value(isEnable());
}
@Override
public boolean initObjectsFromJsonReader(JsonReader jsonReader, String name) throws IOException {
if (super.initObjectsFromJsonReader(jsonReader, name)) { return true; } else {
if (name.equals("isEnable")) {
setIsEnable(jsonReader.nextBoolean());
} else {
return false;
}
}
return true;
}
@Override
public BaseBean readBeanFromJsonReader(JsonReader jsonReader) throws IOException {
jsonReader.beginObject();
while (jsonReader.hasNext()) {
String name = jsonReader.nextName();
if (!initObjectsFromJsonReader(jsonReader, name)) {
jsonReader.skipValue();
}
}
// 结束 JSON 对象
jsonReader.endObject();
return this;
}
}

View File

@@ -0,0 +1,29 @@
package cc.winboll.studio.libappbase.receiver;
/**
* @Author ZhanGSKen@AliYun.Com
* @Date 2025/02/13 21:19:09
* @Describe MyBroadcastReceiver
*/
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.libappbase.R;
public class MyBroadcastReceiver extends BroadcastReceiver {
public static final String TAG = "MyBroadcastReceiver";
@Override
public void onReceive(Context context, Intent intent) {
if (context.getString(R.string.action_sos).equals(intent.getAction())) {
String message = intent.getStringExtra("message");
String sosPackage = intent.getStringExtra("sosPackage");
// 处理接收到的广播消息
LogUtils.d(TAG, String.format("MyBroadcastReceiver action %s \n%s\n%s", intent.getAction(), sosPackage, message));
}
}
}

View File

@@ -0,0 +1,149 @@
package cc.winboll.studio.libappbase.services;
/**
* @Author ZhanGSKen@AliYun.Com
* @Date 2025/02/15 20:48:36
* @Describe TestService
*/
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.libappbase.SOS;
import cc.winboll.studio.libappbase.bean.APPSOSBean;
import cc.winboll.studio.libappbase.bean.TestServiceBean;
public class TestService extends Service {
public static final String TAG = "TestService";
volatile static TestThread _TestThread;
volatile static boolean _IsRunning;
public synchronized static void setIsRunning(boolean isRunning) {
_IsRunning = isRunning;
}
public static boolean isRunning() {
return _IsRunning;
}
@Override
public IBinder onBind(Intent intent) {
return new MyBinder();
}
public class MyBinder extends Binder {
public TestService getService() {
return TestService.this;
}
}
@Override
public void onCreate() {
super.onCreate();
LogUtils.d(TAG, "onCreate()");
run();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
LogUtils.d(TAG, "onStartCommand(...)");
TestServiceBean bean = TestServiceBean.loadBean(this, TestServiceBean.class);
if (bean == null) {
bean = new TestServiceBean();
}
if (intent.getAction() != null && intent.getAction().equals(SOS.ACTION_SERVICE_ENABLE)) {
bean.setIsEnable(true);
TestServiceBean.saveBean(this, bean);
run();
} else if (intent.getAction() != null && intent.getAction().equals(SOS.ACTION_SERVICE_DISABLE)) {
bean.setIsEnable(false);
TestServiceBean.saveBean(this, bean);
}
LogUtils.d(TAG, String.format("TestServiceBean.saveBean setIsEnable %s", bean.isEnable()));
return (bean.isEnable()) ? START_STICKY : super.onStartCommand(intent, flags, startId);
//return super.onStartCommand(intent, flags, startId);
}
void run() {
LogUtils.d(TAG, "run()");
TestServiceBean bean = TestServiceBean.loadBean(this, TestServiceBean.class);
if (bean == null) {
bean = new TestServiceBean();
TestServiceBean.saveBean(this, bean);
}
if (bean.isEnable()) {
LogUtils.d(TAG, "run() bean.isEnable()");
TestThread.getInstance(this).start();
LogUtils.d(TAG, "_TestThread.start()");
}
}
@Override
public void onDestroy() {
super.onDestroy();
LogUtils.d(TAG, "onDestroy()");
TestThread.getInstance(this).setIsExit(true);
_IsRunning = false;
}
static class TestThread extends Thread {
volatile static TestThread _TestThread;
Context mContext;
volatile boolean isStarted = false;
volatile boolean isExit = false;
TestThread(Context context) {
super();
mContext = context;
}
public static synchronized TestThread getInstance(Context context) {
if (_TestThread != null) {
_TestThread.setIsExit(true);
}
_TestThread = new TestThread(context);
return _TestThread;
}
public synchronized void setIsExit(boolean isExit) {
this.isExit = isExit;
}
public boolean isExit() {
return isExit;
}
@Override
public void run() {
if (isStarted == false) {
isStarted = true;
super.run();
LogUtils.d(TAG, "run() start");
SOS.bindToAPPService(mContext, new APPSOSBean(mContext.getPackageName(), TestService.class.getName()));
while (!isExit()) {
LogUtils.d(TAG, "run()");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
}
}
LogUtils.d(TAG, "run() exit");
}
}
}
}

View File

@@ -0,0 +1,48 @@
package cc.winboll.studio.libappbase.utils;
/**
* @Author ZhanGSKen@AliYun.Com
* @Date 2025/02/17 19:38:20
* @Describe 服务工具集
*/
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.util.Log;
import cc.winboll.studio.libappbase.LogUtils;
import java.util.List;
public class ServiceUtils {
public static final String TAG = "ServiceUtils";
/**
* 检查指定服务是否正在运行
* @param context 上下文
* @param serviceClass 服务类
* @return true 如果服务正在运行,否则返回 false
*/
public static boolean isServiceRunning(Context context, String serviceClassName) {
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
if (activityManager == null) {
return false;
}
List<ActivityManager.RunningServiceInfo> runningServices;
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
// Intent intent = new Intent(context, serviceClass);
// runningServices = activityManager.getRunningServices(100, intent);
// } else {
runningServices = activityManager.getRunningServices(100);
//}
for (ActivityManager.RunningServiceInfo serviceInfo : runningServices) {
if (serviceClassName.equals(serviceInfo.service.getClassName())) {
LogUtils.d(TAG, "Service is running: " + serviceInfo.service.getClassName());
return true;
}
}
LogUtils.d(TAG, "Service is not running: " + serviceClassName);
return false;
}
}

View File

@@ -0,0 +1,63 @@
package cc.winboll.studio.libappbase.widgets;
/**
* @Author ZhanGSKen@AliYun.Com
* @Date 2025/02/17 20:32:12
*/
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.widget.RemoteViews;
import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.libappbase.R;
import cc.winboll.studio.libappbase.utils.ServiceUtils;
import com.hjq.toast.ToastUtils;
import android.content.ServiceConnection;
import android.os.IBinder;
import cc.winboll.studio.libappbase.services.TestService;
public class StatusWidget extends AppWidgetProvider {
public static final String TAG = "StatusWidget";
public static final String ACTION_STATUS_UPDATE = "cc.winboll.studio.libappbase.widgets.APPWidget.ACTION_STATUS_UPDATE";
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
for (int appWidgetId : appWidgetIds) {
updateAppWidget(context, appWidgetManager, appWidgetId);
}
}
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
if (intent.getAction().equals(ACTION_STATUS_UPDATE)) {
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, StatusWidget.class));
for (int appWidgetId : appWidgetIds) {
updateAppWidget(context, appWidgetManager, appWidgetId);
}
}
}
private void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_status);
//设置按钮点击事件
Intent intentAppButton = new Intent(context, StatusWidgetClickListener.class);
intentAppButton.setAction(StatusWidgetClickListener.ACTION_IVAPP);
PendingIntent pendingIntentAppButton = PendingIntent.getBroadcast(context, 0, intentAppButton, PendingIntent.FLAG_UPDATE_CURRENT);
views.setOnClickPendingIntent(R.id.ivapp, pendingIntentAppButton);
boolean isActive = ServiceUtils.isServiceRunning(context, TestService.class.getName());
if (isActive) {
views.setImageViewResource(R.id.ivapp, cc.winboll.studio.libappbase.R.drawable.ic_launcher);
} else {
views.setImageViewResource(R.id.ivapp, cc.winboll.studio.libappbase.R.drawable.ic_launcher_disable);
}
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}

View File

@@ -0,0 +1,33 @@
package cc.winboll.studio.libappbase.widgets;
/**
* @Author ZhanGSKen@AliYun.Com
* @Date 2025/02/17 20:33:53
* @Describe APPWidgetClickListener
*/
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import cc.winboll.studio.libappbase.LogUtils;
import com.hjq.toast.ToastUtils;
public class StatusWidgetClickListener extends BroadcastReceiver {
public static final String TAG = "APPWidgetClickListener";
public static final String ACTION_IVAPP = "cc.winboll.studio.libappbase.widgets.StatusWidgetClickListener.ACTION_IVAPP";
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action == null) {
LogUtils.d(TAG, String.format("action %s", action));
return;
}
if (action.equals(ACTION_IVAPP)) {
ToastUtils.show("ACTION_LAUNCHER");
} else {
LogUtils.d(TAG, String.format("action %s", action));
}
}
}

View File

@@ -1,11 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24">
<path
android:fillColor="#ff000000"
android:pathData="M16.61,15.15C16.15,15.15 15.77,14.78 15.77,14.32S16.15,13.5 16.61,13.5H16.61C17.07,13.5 17.45,13.86 17.45,14.32C17.45,14.78 17.07,15.15 16.61,15.15M7.41,15.15C6.95,15.15 6.57,14.78 6.57,14.32C6.57,13.86 6.95,13.5 7.41,13.5H7.41C7.87,13.5 8.24,13.86 8.24,14.32C8.24,14.78 7.87,15.15 7.41,15.15M16.91,10.14L18.58,7.26C18.67,7.09 18.61,6.88 18.45,6.79C18.28,6.69 18.07,6.75 18,6.92L16.29,9.83C14.95,9.22 13.5,8.9 12,8.91C10.47,8.91 9,9.24 7.73,9.82L6.04,6.91C5.95,6.74 5.74,6.68 5.57,6.78C5.4,6.87 5.35,7.08 5.44,7.25L7.1,10.13C4.25,11.69 2.29,14.58 2,18H22C21.72,14.59 19.77,11.7 16.91,10.14H16.91Z"/>
</vector>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:clickable="true"
android:layout_width="24dp"
android:layout_height="24dp">
<item android:drawable="@drawable/ic_launcher_background"/>
<item
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp"
android:drawable="@drawable/ic_launcher_foreground"/>
</layer-list>

View File

@@ -0,0 +1,170 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillColor="#FF005C12"
android:pathData="M0,0h108v108h-108z" />
<path
android:fillColor="#00000000"
android:pathData="M9,0L9,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,0L19,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,0L29,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,0L39,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,0L49,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,0L59,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,0L69,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,0L79,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M89,0L89,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M99,0L99,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,9L108,9"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,19L108,19"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,29L108,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,39L108,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,49L108,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,59L108,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,69L108,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,79L108,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,89L108,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,99L108,99"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,29L89,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,39L89,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,49L89,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,59L89,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,69L89,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,79L89,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,19L29,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,19L39,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,19L49,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,19L59,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,19L69,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,19L79,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
</vector>

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:clickable="true"
android:layout_width="24dp"
android:layout_height="24dp">
<item android:drawable="@drawable/ic_launcher_background"/>
<item
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp"
android:drawable="@drawable/ic_launcher_foreground_disable"/>
</layer-list>

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M16.61,15.15C16.15,15.15 15.77,14.78 15.77,14.32S16.15,13.5 16.61,13.5H16.61C17.07,13.5 17.45,13.86 17.45,14.32C17.45,14.78 17.07,15.15 16.61,15.15M7.41,15.15C6.95,15.15 6.57,14.78 6.57,14.32C6.57,13.86 6.95,13.5 7.41,13.5H7.41C7.87,13.5 8.24,13.86 8.24,14.32C8.24,14.78 7.87,15.15 7.41,15.15M16.91,10.14L18.58,7.26C18.67,7.09 18.61,6.88 18.45,6.79C18.28,6.69 18.07,6.75 18,6.92L16.29,9.83C14.95,9.22 13.5,8.9 12,8.91C10.47,8.91 9,9.24 7.73,9.82L6.04,6.91C5.95,6.74 5.74,6.68 5.57,6.78C5.4,6.87 5.35,7.08 5.44,7.25L7.1,10.13C4.25,11.69 2.29,14.58 2,18H22C21.72,14.59 19.77,11.7 16.91,10.14H16.91Z"/>
</vector>

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24">
<path
android:fillColor="#FF808080"
android:pathData="M16.61,15.15C16.15,15.15 15.77,14.78 15.77,14.32S16.15,13.5 16.61,13.5H16.61C17.07,13.5 17.45,13.86 17.45,14.32C17.45,14.78 17.07,15.15 16.61,15.15M7.41,15.15C6.95,15.15 6.57,14.78 6.57,14.32C6.57,13.86 6.95,13.5 7.41,13.5H7.41C7.87,13.5 8.24,13.86 8.24,14.32C8.24,14.78 7.87,15.15 7.41,15.15M16.91,10.14L18.58,7.26C18.67,7.09 18.61,6.88 18.45,6.79C18.28,6.69 18.07,6.75 18,6.92L16.29,9.83C14.95,9.22 13.5,8.9 12,8.91C10.47,8.91 9,9.24 7.73,9.82L6.04,6.91C5.95,6.74 5.74,6.68 5.57,6.78C5.4,6.87 5.35,7.08 5.44,7.25L7.1,10.13C4.25,11.69 2.29,14.58 2,18H22C21.72,14.59 19.77,11.7 16.91,10.14H16.91Z"/>
</vector>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="40dp"
android:layout_height="40dp">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:id="@+id/ivapp"/>
</LinearLayout>

View File

@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="attrColorPrimary" format="color" />
<attr name="themeGlobalCrashActivity" format="reference"/>

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#FFFFE200</color>
<color name="colorPrimaryDark">#FFFFE200</color>
<color name="colorAccent">#FFFFE200</color>
<color name="colorText">#FFFFE200</color>
<color name="colorPrimary">#FF00B322</color>
<color name="colorPrimaryDark">#FF005C12</color>
<color name="colorAccent">#FF8DFFA2</color>
<color name="colorText">#FFFFFB8D</color>
</resources>

View File

@@ -3,5 +3,5 @@
<string name="lib_name">libappbase</string>
<string name="hello_world">Hello world!</string>
<string name="action_sos">cc.winboll.studio.libappbase.action.SOS</string>
</resources>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="40dp"
android:minHeight="40dp"
android:updatePeriodMillis="1000"
android:initialLayout="@layout/widget_status"
android:resizeMode="none">
</appwidget-provider>

1
mymessagemanager/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/build

View File

@@ -0,0 +1,45 @@
# MyMessageManager
#### 介绍
用正则表达式方法自定义短信过滤和语音播报的短信应用。
#### 软件架构
软件架构说明
#### 安装教程
1. xxxx
2. xxxx
3. xxxx
#### 使用说明
1. xxxx
2. xxxx
3. xxxx
#### 参与贡献
1. Fork 本仓库
2. 新建 Feat_xxx 分支
3. 提交代码ZhanGSKen(ZhanGSKen@QQ.COM)
4. 新建 Pull Request
#### 特技
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
#### 参考文档
使用GitHub Actions实现Android自动打包apk
https://blog.csdn.net/ZZL23333/article/details/115798615?app_version=6.0.0&code=app_1562916241&csdn_share_tail=%7B%22type%22%3A%22blog%22%2C%22rType%22%3A%22article%22%2C%22rId%22%3A%22115798615%22%2C%22source%22%3A%22weixin_38986226%22%7D&uLinkId=usr1mkqgl919blen&utm_source=app
Android中assets的使用用于读取内容
https://blog.csdn.net/qq_27664947/article/details/103924058?app_version=6.0.0&code=app_1562916241&csdn_share_tail=%7B%22type%22%3A%22blog%22%2C%22rType%22%3A%22article%22%2C%22rId%22%3A%22103924058%22%2C%22source%22%3A%22weixin_38986226%22%7D&uLinkId=usr1mkqgl919blen&utm_source=app

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,69 @@
apply plugin: 'com.android.application'
apply from: '../.winboll/winboll_app_build.gradle'
apply from: '../.winboll/winboll_lint_build.gradle'
def genVersionName(def versionName){
// 检查编译标志位配置
assert (winbollBuildProps['stageCount'] != null)
assert (winbollBuildProps['baseVersion'] != null)
// 保存基础版本号
winbollBuildProps.setProperty("baseVersion", "${versionName}");
//保存编译标志配置
FileOutputStream fos = new FileOutputStream(winbollBuildPropsFile)
winbollBuildProps.store(fos, "${winbollBuildPropsDesc}");
fos.close();
// 返回编译版本号
return "${versionName}." + winbollBuildProps['stageCount']
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "cc.winboll.studio.mymessagemanager"
minSdkVersion 26
targetSdkVersion 29
versionCode 8
// versionName 更新后需要手动设置
// .winboll/winbollBuildProps.properties 文件的 stageCount=0
// Gradle编译环境下合起来的 versionName 就是 "${versionName}.0"
versionName "4.1"
if(true) {
versionName = genVersionName("${versionName}")
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
api 'cc.winboll.studio:winboll-shared:1.6.4'
api 'io.github.medyo:android-about-page:2.0.0'
api 'com.github.getActivity:ToastUtils:10.5'
api 'com.jcraft:jsch:0.1.55'
api 'org.jsoup:jsoup:1.13.1'
api 'com.squareup.okhttp3:okhttp:4.4.1'
api 'androidx.appcompat:appcompat:1.0.0'
api 'androidx.fragment:fragment:1.0.0'
api 'com.google.android.material:material:1.0.0'
// 权限请求框架https://github.com/getActivity/XXPermissions
api 'com.github.getActivity:XXPermissions:18.63'
api 'com.baoyz.pullrefreshlayout:library:1.2.0'
api 'androidx.appcompat:appcompat:1.0.0'
api 'androidx.fragment:fragment:1.0.0'
api 'com.google.android.material:material:1.0.0'
api 'cc.winboll.studio:libaes:7.6.0'
api fileTree(dir: 'libs', include: ['*.jar'])
}

View File

@@ -0,0 +1,8 @@
#Created by .winboll/winboll_app_build.gradle
#Tue Feb 25 20:25:31 HKT 2025
stageCount=15
libraryProject=
baseVersion=4.1
publishVersion=4.1.14
buildCount=0
baseBetaVersion=4.1.15

17
mymessagemanager/proguard-rules.pro vendored Normal file
View File

@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\tools\adt-bundle-windows-x86_64-20131030\sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" >
<application>
<!-- Put flavor specific code here -->
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="cc.winboll.studio.mymessagemanager.beta.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_provider"/>
</provider>
</application>
</manifest>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">我的短信管家 ☆</string>
</resources>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">My Message Manager +</string>
</resources>

View File

@@ -0,0 +1,233 @@
<?xml version='1.0' encoding='utf-8'?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="cc.winboll.studio.mymessagemanager">
<!-- 发送短信 -->
<uses-permission android:name="android.permission.SEND_SMS"/>
<!-- 接收讯息(短信) -->
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<!-- 读取短信 -->
<uses-permission android:name="android.permission.READ_SMS"/>
<!-- WRITE_SMS -->
<uses-permission android:name="android.permission.WRITE_SMS"/>
<!-- 接收讯息(彩信) -->
<uses-permission android:name="android.permission.RECEIVE_MMS"/>
<!-- 开机启动 -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<!-- 运行前台服务 -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<!-- 读取联系人 -->
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<!-- 读取您共享存储空间中的内容 -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<!-- 修改或删除您共享存储空间中的内容 -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- 接收讯息 (WAP) -->
<uses-permission android:name="android.permission.RECEIVE_WAP_PUSH"/>
<!-- MANAGE_EXTERNAL_STORAGE -->
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
<!-- 此应用可显示在其他应用上方 -->
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<queries>
<intent>
<action android:name="android.intent.action.TTS_SERVICE"/>
</intent>
</queries>
<application
android:name=".GlobalApplication"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:roundIcon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/WinBoll.SupportThemeNoActionBar"
android:persistent="true"
android:resizeableActivity="true"
android:supportsRtl="true"
android:requestLegacyExternalStorage="true">
<activity
android:name=".activitys.SMSActivity"
android:process=":sms"/>
<activity
android:name=".activitys.SMSReceiveRuleActivity"
android:process=":smsars">
</activity>
<activity
android:name=".activitys.SharedJSONReceiveActivity"
android:process=":smssjr"
android:exported="true">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.SEND"/>
<action android:name="android.intent.action.VIEW"/>
<action android:name="android.intent.action.EDIT"/>
<data android:mimeType="application/json"/>
<data android:mimeType="text/x-json"/>
</intent-filter>
</activity>
<activity
android:name=".activitys.TTSPlayRuleActivity"
android:process=":ttsrule"/>
<activity
android:name=".activitys.AboutActivity"
android:process=":about"/>
<activity
android:name=".activitys.MainActivity"
android:exported="true"
android:process=":main">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".activitys.ComposeSMSActivity"
android:exported="true"
android:process=":csms">
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<action android:name="android.intent.action.SENDTO"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="sms"/>
<data android:scheme="smsto"/>
<data android:scheme="mms"/>
<data android:scheme="mmsto"/>
</intent-filter>
</activity>
<activity android:name=".activitys.AppSettingsActivity"/>
<service android:name=".services.TTSPlayService"/>
<service android:name=".services.MainService"/>
<service android:name=".services.AssistantService"/>
<service
android:name=".services.DefaultSMSManagerService"
android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.RESPOND_VIA_MESSAGE"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="sms"/>
<data android:scheme="smsto"/>
<data android:scheme="mms"/>
<data android:scheme="mmsto"/>
</intent-filter>
</service>
<receiver
android:name=".receivers.MainReceiver"
android:enabled="true"
android:exported="false"
android:directBootAware="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<receiver
android:name=".receivers.SMSRecevier"
android:exported="true"
android:permission="android.permission.BROADCAST_SMS">
<intent-filter android:priority="1">
<action android:name="android.provider.Telephony.SMS_DELIVER"/>
</intent-filter>
</receiver>
<receiver
android:name=".receivers.MmsReceiver"
android:exported="true"
android:permission="android.permission.BROADCAST_WAP_PUSH">
<intent-filter>
<action android:name="android.provider.Telephony.WAP_PUSH_DELIVER"/>
<data android:mimeType="application/vnd.wap.mms-message"/>
</intent-filter>
</receiver>
<meta-data
android:name="android.max_aspect"
android:value="4.0"/>
<activity android:name="cc.winboll.studio.mymessagemanager.activitys.SMSRecycleActivity"/>
<activity android:name="cc.winboll.studio.mymessagemanager.unittest.UnitTestActivity"/>
</application>
</manifest>

View File

@@ -0,0 +1,7 @@
[
{
"userId": -1,
"ruleData": ".*",
"isEnable": true
}
]

View File

@@ -0,0 +1,38 @@
[
{
"userId": 1,
"ruleName": "规则1",
"demoSMSText": "【短信应用A】验证码123456",
"patternText": "^(【.*】)验证码(\\d)(\\d)(\\d)(\\d)(\\d)(\\d)$",
"ttdRuleText": "$1验证码是($2)($3)($4)($5)($6)($7)。",
"isSimpleView": false,
"isEnable": true
},
{
"userId": 1,
"ruleName": "规则2",
"demoSMSText": "[短信应用A]验证码123456",
"patternText": "^(\\[.*\\])验证码(\\d)(\\d)(\\d)(\\d)(\\d)(\\d)$",
"ttdRuleText": "$1验证码是($2)($3)($4)($5)($6)($7)。",
"isSimpleView": false,
"isEnable": true
},
{
"userId": 1,
"ruleName": "规则3",
"demoSMSText": "【短信应用A】验证码123456",
"patternText": ".*(【.+】).*",
"ttdRuleText": "短信来自$1。",
"isSimpleView": false,
"isEnable": true
},
{
"userId": 1,
"ruleName": "规则4",
"demoSMSText": "[短信应用A]验证码123456",
"patternText": ".*(\\[.*\\]).*",
"ttdRuleText": "短信来自$1。",
"isSimpleView": false,
"isEnable": true
}
]

View File

@@ -0,0 +1,52 @@
package cc.winboll.studio.mymessagemanager;
/**
* @Author ZhanGSKen@QQ.COM
* @Date 2023/07/24 01:46:59
* @Describe 全局应用类
*/
import android.view.Gravity;
import cc.winboll.studio.mymessagemanager.R;
import cc.winboll.studio.shared.app.WinBollApplication;
import cc.winboll.studio.shared.log.LogUtils;
import com.hjq.toast.ToastUtils;
import java.io.File;
public class GlobalApplication extends WinBollApplication {
public static final String TAG = "GlobalApplication";
static String _mszAppExternalFilesDir;
static String _mszConfigUtilFileName = "ConfigUtil.json";
static String _mszConfigUtilPath;
static String _mszSMSReceiveRuleUtilFileName = "SMSReceiveRuleUtil.json";
static String _mszSMSReceiveRuleUtilPath;
public static final int USER_ID = -1;
Long mszVersionName = 1L;
Long mszDataVersionName = 1L;
@Override
public void onCreate() {
super.onCreate();
//setIsDebug(cc.winboll.studio.mymessagemanager.BuildConfig.DEBUG);
// 初始化 Toast 框架
ToastUtils.init(this);
// 设置 Toast 布局样式
ToastUtils.setView(R.layout.toast_custom_view);
//ToastUtils.setStyle(new WhiteToastStyle());
ToastUtils.setGravity(Gravity.BOTTOM, 0, 200);
//LogUtils.d(TAG, "BuildConfig.DEBUG " + Boolean.toString(BuildConfig.DEBUG));
_mszAppExternalFilesDir = getExternalFilesDir(TAG).toString();
_mszConfigUtilPath = _mszAppExternalFilesDir + File.separator + _mszConfigUtilFileName;
_mszSMSReceiveRuleUtilPath = _mszAppExternalFilesDir + File.separator + _mszSMSReceiveRuleUtilFileName;
}
public static void showApplicationMessage(String szMessage) {
LogUtils.i(TAG, szMessage);
}
}

View File

@@ -0,0 +1,74 @@
package cc.winboll.studio.mymessagemanager.activitys;
/**
* @Author ZhanGSKen@QQ.COM
* @Date 2024/07/14 13:20:33
* @Describe 应用关于对话窗口
*/
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import androidx.appcompat.widget.Toolbar;
import cc.winboll.studio.mymessagemanager.R;
import cc.winboll.studio.shared.app.WinBollActivity;
import cc.winboll.studio.shared.app.WinBollActivityManager;
import com.hjq.toast.ToastUtils;
import cc.winboll.studio.libaes.utils.AESThemeUtil;
import android.content.Context;
final public class AboutActivity extends WinBollActivity {
public static final String TAG = "AboutActivity";
Context mContext;
@Override
public String getTag() {
return TAG;
}
@Override
protected boolean isEnableDisplayHomeAsUp() {
return false;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(AESThemeUtil.getThemeTypeID(getApplicationContext()));
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
mContext = getApplicationContext();
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
setTitle(mContext.getString(R.string.text_about) + mContext.getString(R.string.app_name));
}
@Override
protected boolean isAddWinBollToolBar() {
return false;
}
@Override
protected Toolbar initToolBar() {
return findViewById(R.id.activityaboutASupportToolbar1);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.toolbar_about, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
/*if (item.getItemId() == R.id.item_help) {
ToastUtils.show("R.id.item_help");
} else */if (item.getItemId() == android.R.id.home) {
WinBollActivityManager.getInstance(getApplicationContext()).finish(this);
}
return super.onOptionsItemSelected(item);
}
}

View File

@@ -0,0 +1,99 @@
package cc.winboll.studio.mymessagemanager.activitys;
/**
* @Author ZhanGSKen@QQ.COM
* @Date 2024/05/12 20:03:42
* @Describe 应用设置窗口
*/
import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.widget.EditText;
import android.widget.Switch;
import android.widget.Toast;
import cc.winboll.studio.libaes.views.AOHPCTCSeekBar;
import cc.winboll.studio.libaes.views.AToolbar;
import cc.winboll.studio.mymessagemanager.R;
import cc.winboll.studio.mymessagemanager.utils.AppConfigUtil;
import cc.winboll.studio.mymessagemanager.utils.PermissionUtil;
public class AppSettingsActivity extends BaseActivity {
public static final String TAG = "AppSettingsActivity";
AppConfigUtil mAppConfigUtil;
AToolbar mAToolbar;
AOHPCTCSeekBar mAOHPCTCSeekBar;
EditText metTTSPlayDelayTimes;
EditText metPhoneMergePrefix;
Switch mswMergePrefixPhone;
Switch mswSMSRecycleProtectMode;
EditText metProtectModerRefuseChars;
EditText metProtectModerReplaceChars;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_appsettings);
// 初始化属性
mAppConfigUtil = AppConfigUtil.getInstance(this);
int nTtsPlayDelayTimes = mAppConfigUtil.mAppConfigBean.getTtsPlayDelayTimes();
metTTSPlayDelayTimes = findViewById(R.id.activityappsettingsEditText1);
metTTSPlayDelayTimes.setText(Integer.toString(nTtsPlayDelayTimes / 1000));
// 初始化标题栏
mAToolbar = findViewById(R.id.activityappsettingsAToolbar1);
mAToolbar.setSubtitle(getString(R.string.activity_name_appsettings));
setActionBar(mAToolbar);
metPhoneMergePrefix = findViewById(R.id.activityappsettingsEditText2);
metPhoneMergePrefix.setText(mAppConfigUtil.mAppConfigBean.getCountryCode());
mswMergePrefixPhone = findViewById(R.id.activityappsettingsSwitch1);
mswMergePrefixPhone.setChecked(mAppConfigUtil.mAppConfigBean.isMergeCountryCodePrefix());
mswSMSRecycleProtectMode = findViewById(R.id.activityappsettingsSwitch3);
mswSMSRecycleProtectMode.setChecked(mAppConfigUtil.mAppConfigBean.isSMSRecycleProtectMode());
metProtectModerRefuseChars = findViewById(R.id.activityappsettingsEditText3);
metProtectModerRefuseChars.setText(mAppConfigUtil.mAppConfigBean.getProtectModerRefuseChars());
metProtectModerReplaceChars = findViewById(R.id.activityappsettingsEditText4);
metProtectModerReplaceChars.setText(mAppConfigUtil.mAppConfigBean.getProtectModerReplaceChars());
mAOHPCTCSeekBar = findViewById(R.id.activityappsettingsAOHPCTCSeekBar1);
mAOHPCTCSeekBar.setThumb(getDrawable(R.drawable.cursor_pointer));
mAOHPCTCSeekBar.setThumbOffset(0);
mAOHPCTCSeekBar.setOnOHPCListener(new AOHPCTCSeekBar.OnOHPCListener(){
@Override
public void onOHPCommit() {
mAppConfigUtil.reLoadConfig();
mAppConfigUtil.mAppConfigBean.setIsSMSRecycleProtectMode(mswSMSRecycleProtectMode.isChecked());
mAppConfigUtil.mAppConfigBean.setProtectModerRefuseChars(metProtectModerRefuseChars.getText().toString());
mAppConfigUtil.mAppConfigBean.setProtectModerReplaceChars(metProtectModerReplaceChars.getText().toString());
mAppConfigUtil.mAppConfigBean.setCountryCode(metPhoneMergePrefix.getText().toString());
mAppConfigUtil.mAppConfigBean.setIsMergeCountryCodePrefix(mswMergePrefixPhone.isChecked());
int nTtsPlayDelayTimes = 1000 * Integer.parseInt(metTTSPlayDelayTimes.getText().toString());
mAppConfigUtil.mAppConfigBean.setTtsPlayDelayTimes(nTtsPlayDelayTimes);
mAppConfigUtil.saveConfig();
Toast.makeText(getApplication(), "App config data is saved.", Toast.LENGTH_SHORT).show();
//LogUtils.d(TAG, "TTS Play Delay Times is setting to : " + Integer.toString(mAppConfigData.getTtsPlayDelayTimes()));Toast.makeText(getApplication(), "onOHPCommit", Toast.LENGTH_SHORT).show();
}
});
};
public void onOpenSystemDefaultAppSettings(View view) {
Intent intent = new Intent(Settings.ACTION_MANAGE_DEFAULT_APPS_SETTINGS);
startActivity(intent);
}
public void onCheckAndGetAppPermission(View view) {
//LogUtils.d(TAG, "onCheckAndGetAppPermission");
if (PermissionUtil.checkAndGetAppPermission(this)) {
Toast.makeText(getApplication(), "应用已获得所需权限。", Toast.LENGTH_SHORT).show();
}
}
}

View File

@@ -0,0 +1,113 @@
package cc.winboll.studio.mymessagemanager.activitys;
import cc.winboll.studio.mymessagemanager.R;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Menu;
import android.view.MenuItem;
import androidx.appcompat.app.AppCompatActivity;
import cc.winboll.studio.libaes.utils.AESThemeUtil;
import cc.winboll.studio.shared.log.LogUtils;
import com.hjq.toast.ToastUtils;
import cc.winboll.studio.libaes.beans.AESThemeBean;
abstract public class BaseActivity extends AppCompatActivity {
public static final String TAG = "BaseActivity";
IOnActivityMessageReceived mIOnActivityMessageReceived;
@Override
protected void onCreate(Bundle savedInstanceState) {
//AppConfigUtil configUtil = AppConfigUtil.getInstance(this);
//setTheme(configUtil.mAppConfigBean.getAppThemeID());
LogUtils.d(TAG, "AESThemeUtil.getThemeTypeID(this) is : " + Integer.toString(AESThemeUtil.getThemeTypeID(this)));
setTheme(AESThemeUtil.getThemeTypeID(this));
super.onCreate(savedInstanceState);
}
public void sendActivityMessage(Message msg) {
mHandler.sendMessage(msg);
}
protected void setOnActivityMessageReceived(IOnActivityMessageReceived iOnActivityMessageReceived) {
mIOnActivityMessageReceived = iOnActivityMessageReceived;
}
Handler mHandler = new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (mIOnActivityMessageReceived != null) {
mIOnActivityMessageReceived.onActivityMessageReceived(msg);
}
}
};
protected interface IOnActivityMessageReceived {
void onActivityMessageReceived(Message msg);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
AESThemeUtil.inflateMenu(this, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
/*if (AESThemeUtil.onAppCompatThemeItemSelected(this, item)) {
ToastUtils.show("onAppCompatThemeItemSelected");
recreate();
}*/
/*int nThemeStyleID = AESThemeBean.getThemeStyleID(AESThemeBean.ThemeType.DEFAULT);
if (R.id.item_depththeme == item.getItemId()) {
nThemeStyleID = AESThemeBean.getThemeStyleID(AESThemeBean.ThemeType.DEPTH);
AESThemeUtil.saveThemeStyleID(this, nThemeStyleID);
recreate();
} else if (R.id.item_skytheme == item.getItemId()) {
nThemeStyleID = AESThemeBean.getThemeStyleID(AESThemeBean.ThemeType.SKY);
AESThemeUtil.saveThemeStyleID(this, nThemeStyleID);
recreate();
} else if (R.id.item_goldentheme == item.getItemId()) {
nThemeStyleID = AESThemeBean.getThemeStyleID(AESThemeBean.ThemeType.GOLDEN);
AESThemeUtil.saveThemeStyleID(this, nThemeStyleID);
recreate();
} else if (R.id.item_taotheme == item.getItemId()) {
nThemeStyleID = AESThemeBean.getThemeStyleID(AESThemeBean.ThemeType.TAO);
AESThemeUtil.saveThemeStyleID(this, nThemeStyleID);
recreate();
} else if (R.id.item_defaulttheme == item.getItemId()) {
nThemeStyleID = AESThemeBean.getThemeStyleID(AESThemeBean.ThemeType.DEFAULT);
AESThemeUtil.saveThemeStyleID(this, nThemeStyleID);
recreate();
}*/
//int nThemeStyleID = AESThemeBean.getThemeStyleID(AESThemeBean.ThemeType.DEFAULT);
if (R.id.item_depththeme == item.getItemId()) {
AESThemeUtil.saveThemeStyleID(this, R.style.MyDepthAESTheme);
recreate();
} else if (R.id.item_skytheme == item.getItemId()) {
AESThemeUtil.saveThemeStyleID(this, R.style.MySkyAESTheme);
recreate();
} else if (R.id.item_goldentheme == item.getItemId()) {
AESThemeUtil.saveThemeStyleID(this, R.style.MyGoldenAESTheme);
recreate();
} else if (R.id.item_memortheme == item.getItemId()) {
AESThemeUtil.saveThemeStyleID(this, R.style.MyMemorAESTheme);
recreate();
} else if (R.id.item_taotheme == item.getItemId()) {
AESThemeUtil.saveThemeStyleID(this, R.style.MyTaoAESTheme);
recreate();
} else if (R.id.item_defaulttheme == item.getItemId()) {
AESThemeUtil.saveThemeStyleID(this, R.style.MyDefaultAESTheme);
recreate();
}
//ToastUtils.show("nThemeStyleID " + Integer.toString(nThemeStyleID));
return super.onOptionsItemSelected(item);
}
}

View File

@@ -0,0 +1,192 @@
package cc.winboll.studio.mymessagemanager.activitys;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.Toolbar;
import cc.winboll.studio.libaes.views.AOHPCTCSeekBar;
import cc.winboll.studio.mymessagemanager.R;
import cc.winboll.studio.mymessagemanager.activitys.ComposeSMSActivity;
import cc.winboll.studio.mymessagemanager.beans.PhoneBean;
import cc.winboll.studio.mymessagemanager.utils.PhoneUtil;
import cc.winboll.studio.mymessagemanager.utils.SMSUtil;
import com.hjq.toast.ToastUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ComposeSMSActivity extends BaseActivity {
public static String TAG = "ComposeSMSActivity";
public static String EXTRA_SMSBODY = "sms_body";
static String MAP_NAME = "NAME";
static String MAP_PHONE = "PHONE";
String mszSMSBody;
String mszScheme;
String mszPhoneTo;
EditText metTO;
EditText metSMSBody;
SimpleAdapter mSimpleAdapter;
List<Map<String,Object>> mAdapterData = new ArrayList<>();
ListView mlvContracts;
List<PhoneBean> mListPhoneBeanContracts;
Toolbar mToolbar;
AOHPCTCSeekBar mAOHPCTCSeekBar;
RelativeLayout mrlContracts;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_composesms);
mszSMSBody = getIntent().getStringExtra(EXTRA_SMSBODY);
mszScheme = getIntent().getData().getScheme();
mszPhoneTo = getIntent().getData().getSchemeSpecificPart();
if (!mszScheme.equals("smsto")) {
// 其他方式未支持就退出
finish();
}
// 初始化视图
initView();
// 设置适配器
initAdapter();
// 设置搜索到的匹配位置
setListViewPrePosition();
}
//
// 初始化视图
//
void initView() {
//Drawable drawableFrame = AppCompatResources.getDrawable(this, R.drawable.bg_frame);
// 初始化标题栏
mToolbar = findViewById(R.id.activitycomposesmsASupportToolbar1);
mToolbar.setSubtitle(getString(R.string.activity_name_composesms));
setActionBar(mToolbar);
// 初始化联系人栏目框
mrlContracts = findViewById(R.id.activitycomposesmsRelativeLayout1);
//mrlContracts.setBackground(drawableFrame);
// 初始化联系人列表
mlvContracts = findViewById(R.id.activitycomposesmsListView1);
// 初始化联系人输入框
metTO = findViewById(R.id.activitycomposesmsEditText1);
metTO.setText(mszPhoneTo);
metTO.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
setListViewPrePosition();
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
// 初始化发送拉动控件
mAOHPCTCSeekBar = findViewById(R.id.viewsmssendpart1AOHPCTCSeekBar1);
mAOHPCTCSeekBar.setThumb(getDrawable(R.drawable.ic_message));
mAOHPCTCSeekBar.setThumbOffset(20);
mAOHPCTCSeekBar.setOnOHPCListener(new AOHPCTCSeekBar.OnOHPCListener() {
@Override
public void onOHPCommit() {
// 空号码不发送
mszPhoneTo = metTO.getText().toString();
if (mszPhoneTo.trim().equals("")) {
ToastUtils.show("没有设置接收号码。");
return;
}
// 空消息不发送
mszSMSBody = metSMSBody.getText().toString();
if (mszSMSBody.equals("")) {
ToastUtils.show("没有消息内容可发送。");
return;
}
// 发送消息
if (SMSUtil.sendMessageByInterface2(ComposeSMSActivity.this, mszPhoneTo, mszSMSBody)) {
ComposeSMSActivity.this.finish();
}
}
});
// 初始化提示框
TextView tvAOHPCTCSeekBarMSG = findViewById(R.id.viewsmssendpart1TextView1);
tvAOHPCTCSeekBarMSG.setText(R.string.msg_100sendmsg);
// 初始化发送消息框
metSMSBody = findViewById(R.id.viewsmssendpart1EditText1);
//metSMSBody.setBackground(drawableFrame);
metSMSBody.setText(mszSMSBody);
}
//
// 设置搜索到的匹配位置
//
void setListViewPrePosition() {
int nPrePosition = getContractsDataPrePosition(metTO.getText().toString());
mlvContracts.setSelected(false);
mlvContracts.setSelection(nPrePosition);
}
//
// 返回搜索到的匹配位置
//
int getContractsDataPrePosition(String szPhone) {
for (int i = 0; i < mListPhoneBeanContracts.size(); i++) {
if (mListPhoneBeanContracts.get(i).getTelPhone().compareTo(szPhone) > -1) {
return i;
}
}
return 0;
}
//
// 初始化适配器
//
void initAdapter() {
// 初始化联系人数据适配器
mAdapterData = new ArrayList<>();
// 读取联系人数据
PhoneUtil phoneUtils = new PhoneUtil(this);
mListPhoneBeanContracts = phoneUtils.getPhoneList();
// 映射联系人数据给适配器数据对象
for (int i = 0;i < mListPhoneBeanContracts.size();i++) {
Map<String,Object> map =new HashMap<>();
map.put(MAP_NAME, mListPhoneBeanContracts.get(i).getName());
map.put(MAP_PHONE, mListPhoneBeanContracts.get(i).getTelPhone());
mAdapterData.add(map);
}
// 绑定适配器与数据
mSimpleAdapter = new SimpleAdapter(ComposeSMSActivity.this, mAdapterData, R.layout.listview_contracts
, new String[]{MAP_NAME, MAP_PHONE}
, new int[]{R.id.listviewcontractsTextView1, R.id.listviewcontractsTextView2});
mSimpleAdapter.setDropDownViewResource(R.layout.listview_contracts);
mlvContracts.setAdapter(mSimpleAdapter);
mlvContracts.setOnItemClickListener(new ListView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
metTO.setText(mAdapterData.get(position).get(MAP_PHONE).toString());
}
});
}
}

View File

@@ -0,0 +1,338 @@
package cc.winboll.studio.mymessagemanager.activitys;
import android.Manifest;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Message;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ScrollView;
import cc.winboll.studio.libaes.views.AToolbar;
import cc.winboll.studio.mymessagemanager.BuildConfig;
import cc.winboll.studio.mymessagemanager.R;
import cc.winboll.studio.mymessagemanager.activitys.MainActivity;
import cc.winboll.studio.mymessagemanager.adapters.PhoneArrayAdapter;
import cc.winboll.studio.mymessagemanager.services.MainService;
import cc.winboll.studio.mymessagemanager.utils.AppConfigUtil;
import cc.winboll.studio.mymessagemanager.utils.AppGoToSettingsUtil;
import cc.winboll.studio.mymessagemanager.utils.NotificationUtil;
import cc.winboll.studio.mymessagemanager.utils.PermissionUtil;
import cc.winboll.studio.mymessagemanager.utils.SMSUtil;
import cc.winboll.studio.mymessagemanager.utils.ThemeUtil;
import cc.winboll.studio.mymessagemanager.utils.ViewUtil;
import cc.winboll.studio.mymessagemanager.views.ConfirmSwitchView;
import cc.winboll.studio.mymessagemanager.views.PhoneListViewForScrollView;
import cc.winboll.studio.shared.log.LogUtils;
import cc.winboll.studio.shared.log.LogView;
import com.baoyz.widget.PullRefreshLayout;
import java.util.ArrayList;
import cc.winboll.studio.libaes.utils.AESThemeUtil;
import cc.winboll.studio.libaes.views.ASupportToolbar;
import androidx.appcompat.widget.Toolbar;
import cc.winboll.studio.mymessagemanager.unittest.UnitTestActivity;
public class MainActivity extends BaseActivity {
public final static String TAG = "MainActivity";
public static final int ACTIVITY_RESULT_APP_SETTINGS = -1;
public final static int MSG_RELOADSMS = 0;
public static final int PERMISSION_SETTING_FOR_RESULT = 0;
public static final int MY_PERMISSIONS_REQUEST = 0;
static MainActivity _mMainActivity;
LogView mLogView;
AppConfigUtil mAppConfigUtil;
ConfirmSwitchView msvEnableService;
ConfirmSwitchView msvOnlyReceiveContacts;
ConfirmSwitchView msvEnableTTS;
ConfirmSwitchView msvEnableTTSRuleMode;
PhoneListViewForScrollView mListViewPhone;
Toolbar mToolbar;
PhoneArrayAdapter mPhoneArrayAdapter;
AppGoToSettingsUtil mAppGoToSettingsUtil;
String[] mPermissionList = {Manifest.permission.READ_CONTACTS,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.READ_SMS};
ArrayList<String> listPerms;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
_mMainActivity = MainActivity.this;
mAppConfigUtil = AppConfigUtil.getInstance(this);
initView();
// 调用调试检查函数
onOnceAndroidStory(null);
}
//
// 这是一个测试函数,
// 用于调试读取 string.xml string-array使用。
//
public void onOnceAndroidStory(View view) {
if (BuildConfig.DEBUG) {
// 获取strings.xml文件中的tab_names数组
String[] tab_names = getResources().getStringArray(R.array.strings_OnceAndroidStory);
// 这里R.array.tab_names是你在XML文件中定义的数组资源ID
// 例如在strings.xml中可能这样定义
/*/ <!-- strings.xml -->
<resources>
<string-array name="tab_names">
<item>Tab 1</item>
<item>Tab 2</item>
<item>Tab 3</item>
</string-array>
</resources>
*/
// 现在你可以遍历这个数组来访问每个元素
for (int i = 0; i < tab_names.length; i++) {
// 创建Random实例并传入任意非负种子这里是1
java.util.Random r = new java.util.Random(1);
// 调用nextInt(6)范围是0到5包括0和5加1后得到1到5
int randomNum = r.nextInt(6) + 1;
System.out.println("Random number between 1 and 5: " + randomNum);
LogUtils.d("OnceAndroidStory", tab_names[i]);
}
}
}
void scrollScrollView() {
ScrollView sv = findViewById(R.id.activitymainScrollView1);
ViewUtil.scrollScrollView(sv);
}
void genTestData() {
for (int i = 0; i < 2; i++) {
SMSUtil.saveReceiveSms(this, "13172887736", "调试阶段生成的短信" + Integer.toString(i), "0", -1, "inbox");
}
}
//
// 初始化视图控件
//
void initView() {
// 设置调试日志
mLogView = findViewById(R.id.logview);
mLogView.start();
// 设置消息处理函数
setOnActivityMessageReceived(mIOnActivityMessageReceived);
// 设置标题栏
mToolbar = findViewById(R.id.activitymainASupportToolbar1);
mToolbar.setSubtitle(getString(R.string.activity_name_main));
setSupportActionBar(mToolbar);
// 创建通知频道
NotificationUtil nu = new NotificationUtil();
nu.createServiceNotificationChannel(MainActivity.this);
nu.createSMSNotificationChannel(MainActivity.this);
boolean isEnableService = mAppConfigUtil.mAppConfigBean.isEnableService();
msvEnableService = findViewById(R.id.activitymainSwitchView1);
msvEnableService.setChecked(isEnableService);
msvEnableService.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean isEnable = ((ConfirmSwitchView)v).isChecked();
mAppConfigUtil.reLoadConfig();
mAppConfigUtil.mAppConfigBean.setIsEnableService(isEnable);
mAppConfigUtil.saveConfig();
initService(isEnable);
}
});
boolean isOnlyReceiveContacts = mAppConfigUtil.mAppConfigBean.isEnableOnlyReceiveContacts();
msvOnlyReceiveContacts = findViewById(R.id.activitymainSwitchView2);
msvOnlyReceiveContacts.setChecked(isOnlyReceiveContacts);
msvOnlyReceiveContacts.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean isEnable = ((ConfirmSwitchView)v).isChecked();
mAppConfigUtil.reLoadConfig();
mAppConfigUtil.mAppConfigBean.setIsEnableOnlyReceiveContacts(isEnable);
mAppConfigUtil.saveConfig();
}
});
boolean isEnableTTS = mAppConfigUtil.mAppConfigBean.isEnableTTS();
msvEnableTTS = findViewById(R.id.activitymainSwitchView3);
msvEnableTTS.setChecked(isEnableTTS);
msvEnableTTS.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean isEnable = ((ConfirmSwitchView)v).isChecked();
mAppConfigUtil.reLoadConfig();
mAppConfigUtil.mAppConfigBean.setIsEnableTTS(isEnable);
mAppConfigUtil.saveConfig();
}
});
boolean isEnableTTSRuleMode = mAppConfigUtil.mAppConfigBean.isEnableTTSRuleMode();
msvEnableTTSRuleMode = findViewById(R.id.activitymainSwitchView4);
msvEnableTTSRuleMode.setChecked(isEnableTTSRuleMode);
msvEnableTTSRuleMode.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean isEnable = ((ConfirmSwitchView)v).isChecked();
mAppConfigUtil.reLoadConfig();
mAppConfigUtil.mAppConfigBean.setIsEnableTTSRuleMode(isEnable);
mAppConfigUtil.saveConfig();
}
});
initService(isEnableService);
// 短信发送窗口按钮
Button btnSendSMS = findViewById(R.id.activitymainButton1);
btnSendSMS.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Uri uri = Uri.parse("smsto:");
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
it.putExtra("sms_body", "");
startActivity(it);
}
});
mListViewPhone = (PhoneListViewForScrollView) findViewById(R.id.activitymainListView1);
//准备数据
mPhoneArrayAdapter = new PhoneArrayAdapter(MainActivity.this);
final PullRefreshLayout layout = (PullRefreshLayout) findViewById(R.id.activitymainPullRefreshLayout1);
//将适配器加载到控件中
mListViewPhone.setAdapter(mPhoneArrayAdapter);
// listen refresh event
layout.setOnRefreshListener(new PullRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
// start refresh
reloadSMS();
layout.setRefreshing(false);
}
});
}
void initService(boolean isEnableService) {
if (isEnableService) {
Intent service = new Intent(this, MainService.class);
startService(service);
} else {
Intent service = new Intent(this, MainService.class);
stopService(service);
}
}
//
// 定义应用内消息处理函数
//
IOnActivityMessageReceived mIOnActivityMessageReceived = new IOnActivityMessageReceived(){
@Override
public void onActivityMessageReceived(Message msg) {
switch (msg.arg1) {
case MSG_RELOADSMS : {
LogUtils.d(TAG, "MSG_RELOADSMS");
if (PermissionUtil.checkAppPermission(MainActivity.this)) {
mPhoneArrayAdapter.loadData();
mPhoneArrayAdapter.notifyDataSetChanged();
} else {
LogUtils.i(TAG, "遇到应用权限问题,请打开应用设置检查一下应用权限。");
}
break;
}
}
}
};
@Override
public boolean onCreatePanelMenu(int featureId, Menu menu) {
return super.onCreatePanelMenu(featureId, menu);
}
@Override
protected void onDestroy() {
super.onDestroy();
}
@Override
protected void onResume() {
super.onResume();
reloadSMS();
mLogView.start();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
//return super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.toolbar_main, menu);
/*ThemeUtil.BaseTheme baseTheme = ThemeUtil.getTheme(mAppConfigUtil.mAppConfigBean.getAppThemeID());
if (baseTheme == ThemeUtil.BaseTheme.DEFAULT) {
menu.findItem(R.id.app_defaulttheme).setChecked(true);
} else if (baseTheme == ThemeUtil.BaseTheme.SKY) {
menu.findItem(R.id.app_skytheme).setChecked(true);
} else if (baseTheme == ThemeUtil.BaseTheme.GOLDEN) {
menu.findItem(R.id.app_goldentheme).setChecked(true);
}*/
return super.onCreateOptionsMenu(menu);
}
public static void reloadSMS() {
if (_mMainActivity != null) {
Message msg = new Message();
msg.arg1 = MSG_RELOADSMS;
_mMainActivity.sendActivityMessage(msg);
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int nItemId = item.getItemId();
if (nItemId == R.id.app_ttsrule) {
Intent i = new Intent(MainActivity.this, TTSPlayRuleActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
} else if (nItemId == R.id.app_smsrule) {
Intent i = new Intent(MainActivity.this, SMSReceiveRuleActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
} else if (nItemId == R.id.app_appsettings) {
Intent i = new Intent(MainActivity.this, AppSettingsActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
} else if (nItemId == R.id.app_unittest) {
Intent i = new Intent(MainActivity.this, UnitTestActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
} else if (nItemId == R.id.app_crashtest) {
for (int i = Integer.MIN_VALUE; i < Integer.MAX_VALUE; i++) {
getString(i);
}
} else if (nItemId == R.id.app_about) {
Intent i = new Intent(MainActivity.this, AboutActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
} else if (nItemId == R.id.app_smsrecycle) {
Intent i = new Intent(MainActivity.this, SMSRecycleActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
}
return super.onOptionsItemSelected(item);
}
}

View File

@@ -0,0 +1,228 @@
package cc.winboll.studio.mymessagemanager.activitys;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.AbsListView;
import android.widget.EditText;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.Toolbar;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import cc.winboll.studio.libaes.views.AOHPCTCSeekBar;
import cc.winboll.studio.mymessagemanager.R;
import cc.winboll.studio.mymessagemanager.activitys.SMSActivity;
import cc.winboll.studio.mymessagemanager.adapters.SMSArrayAdapter;
import cc.winboll.studio.mymessagemanager.utils.SMSUtil;
import cc.winboll.studio.mymessagemanager.utils.ViewUtil;
import cc.winboll.studio.mymessagemanager.views.SMSListViewForScrollView;
import cc.winboll.studio.mymessagemanager.views.SMSView;
import java.lang.ref.WeakReference;
public class SMSActivity extends BaseActivity {
public static String TAG = "SMSActivity";
public static final String ACTION_NOTIFY_SMS_CHANGED = "cc.winboll.studio.mymessagemanager.activitys.SMSActivity.ACTION_NOTIFY_SMS_CHANGED";
public static final String EXTRA_PHONE = "Phone";
final static int MSG_SET_FOCUS = 0;
SMSListViewForScrollView mlvSMS;
Toolbar mToolbar;
String mszPhoneTo;
SMSArrayAdapter mSMSArrayAdapter;
ScrollView mScrollView;
EditText metSMSBody;
SMSActivityBroadcastReceiver mSMSActivityBroadcastReceiver;
Handler mSetFocusHandler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sms);
initView();
mSetFocusHandler = new MyHandler(SMSActivity.this);
scrollScrollView();
// 每隔一定时间设置输入框获得焦点
//
new Thread() {
@Override
public void run() {
while (true) {
try {
Thread.sleep(1500);
} catch (InterruptedException e) {}
Message message = mSetFocusHandler.obtainMessage(MSG_SET_FOCUS);
mSetFocusHandler.sendMessage(message);
}
}}.start();
}
//
// 设置输入框获得焦点的类
//
static class MyHandler extends Handler {
WeakReference<SMSActivity> mActivity;
MyHandler(SMSActivity activity) {
mActivity = new WeakReference<SMSActivity>(activity);
}
public void handleMessage(Message msg) {
SMSActivity theActivity = mActivity.get();
switch (msg.what) {
case MSG_SET_FOCUS:
theActivity.metSMSBody.setFocusable(true);
theActivity.metSMSBody.requestFocus();
break;
default:
break;
}
super.handleMessage(msg);
}
}
@Override
protected void onDestroy() {
super.onDestroy();
LocalBroadcastManager.getInstance(this).unregisterReceiver(mSMSActivityBroadcastReceiver);
}
void initView() {
// 发送端空号码退出
mszPhoneTo = getIntent().getStringExtra(EXTRA_PHONE);
if (mszPhoneTo == null || mszPhoneTo.trim().equals("")) {
finish();
}
// 初始化标题栏
mToolbar = findViewById(R.id.activitysmsASupportToolbar1);
mToolbar.setSubtitle(getString(R.string.activity_name_smsinphone) + " < Phone : " + mszPhoneTo + " >");
setActionBar(mToolbar);
// 初始化滚动窗口
mScrollView = findViewById(R.id.activitysmsinphoneScrollView1);
// 初始化发送消息框
//Drawable drawableFrame = AppCompatResources.getDrawable(this, R.drawable.bg_frame);
metSMSBody = findViewById(R.id.viewsmssendpart1EditText1);
//metSMSBody.setBackground(drawableFrame);
// 初始化发送拉动控件
final AOHPCTCSeekBar aOHPCTCSeekBar = findViewById(R.id.viewsmssendpart1AOHPCTCSeekBar1);
aOHPCTCSeekBar.setThumb(getDrawable(R.drawable.ic_message));
aOHPCTCSeekBar.setThumbOffset(20);
aOHPCTCSeekBar.setOnOHPCListener(
new AOHPCTCSeekBar.OnOHPCListener(){
@Override
public void onOHPCommit() {
//Toast.makeText(getApplication(), "Send", Toast.LENGTH_SHORT).show();
sendSMS();
}
});
// 初始化提示框
TextView tvAOHPCTCSeekBarMSG = findViewById(R.id.viewsmssendpart1TextView1);
tvAOHPCTCSeekBarMSG.setText(R.string.msg_100sendmsg);
mlvSMS = (SMSListViewForScrollView) findViewById(R.id.activitysmsinphoneListView1);
// 准备数据
mSMSArrayAdapter = new SMSArrayAdapter(SMSActivity.this, mszPhoneTo);
mlvSMS.setAdapter(mSMSArrayAdapter);
// 设置短信列表滚动到底部就取消已发送的通知消息
//
mlvSMS.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (firstVisibleItem + visibleItemCount == totalItemCount && totalItemCount > 0) {
// 滑动到了底部
mSMSArrayAdapter.cancelMessageNotification();
}
}
});
mSMSActivityBroadcastReceiver = new SMSActivityBroadcastReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(ACTION_NOTIFY_SMS_CHANGED);
LocalBroadcastManager.getInstance(this).registerReceiver(mSMSActivityBroadcastReceiver, intentFilter);
/*SMSView mSMSView = findViewById(R.id.viewsmssendSMSView1);
mSMSView.setSMSType(SMSView.SMSType.SEND);*/
}
//
// 更新信息列表
//
public void updateSMSView() {
mSMSArrayAdapter.reLoadSMSList(SMSActivity.this, mszPhoneTo);
mSMSArrayAdapter.notifyDataSetChanged();
}
//
// 滚动消息文本框
//
void scrollScrollView() {
ViewUtil.scrollScrollView(mScrollView);
}
//
// 发送短信
//
void sendSMS() {
// 空消息不发送
String szSMSBody = metSMSBody.getText().toString();
if (szSMSBody.equals("")) {
Toast.makeText(getApplication(), "没有消息内容可发送。", Toast.LENGTH_SHORT).show();
return;
}
// 发送短信
if (SMSUtil.sendMessageByInterface2(this, mszPhoneTo, szSMSBody)) {
metSMSBody.setText("");
new Handler().postDelayed(new Runnable(){
@Override
public void run() {
updateSMSView();
ViewUtil.scrollScrollView(mScrollView);
}
}, 1000);
}
}
class SMSActivityBroadcastReceiver extends BroadcastReceiver {
public SMSActivityBroadcastReceiver() {
//LogUtils.d(TAG, "SMSActivityBroadcastReceiver()");
}
@Override
public void onReceive(Context context, Intent intent) {
switch (intent.getAction()) {
case ACTION_NOTIFY_SMS_CHANGED :
//Toast.makeText(context, "ACTION_NOTIFY_SMS_CHANGED", Toast.LENGTH_SHORT).show();
updateSMSView();
ViewUtil.scrollScrollView(mScrollView);
//LogUtils.d(TAG, "ACTION_NOTIFY_SMS_CHANGED");
break;
default:
throw new IllegalStateException("Unexpected value: " + intent.getAction());
}
}
}
}

View File

@@ -0,0 +1,232 @@
package cc.winboll.studio.mymessagemanager.activitys;
/**
* @Author ZhanGSKen@QQ.COM
* @Date 2024/07/19 12:50:52
* @Describe 短信匹配过滤规则设置窗口
*/
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import cc.winboll.studio.mymessagemanager.GlobalApplication;
import cc.winboll.studio.mymessagemanager.R;
import cc.winboll.studio.mymessagemanager.activitys.SMSReceiveRuleActivity;
import cc.winboll.studio.mymessagemanager.adapters.SMSAcceptRuleArrayAdapter;
import cc.winboll.studio.mymessagemanager.beans.SMSAcceptRuleBean;
import cc.winboll.studio.mymessagemanager.utils.FileUtil;
import cc.winboll.studio.mymessagemanager.utils.SMSReceiveRuleUtil;
import com.baoyz.widget.PullRefreshLayout;
public class SMSReceiveRuleActivity extends BaseActivity {
public static final String TAG = "SMSReceiveRuleActivity";
Context mContext;
RecyclerView mRecyclerView;
Toolbar mToolbar;
RadioButton mrbAccept;
RadioButton mrbRefuse;
CheckBox mcbEnable;
SMSAcceptRuleBean mSMSAcceptRuleBeanAdd;
SMSAcceptRuleArrayAdapter mSMSAcceptRuleArrayAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_smsacceptrulesetting);
mContext = SMSReceiveRuleActivity.this;
initSMSAcceptRuleBeanAdd();
// 初始化视图
initView();
}
//
// 初始化视图
//
public void initView() {
// 初始化标题栏
mToolbar = findViewById(R.id.activitysmsacceptrulesettingASupportToolbar1);
mToolbar.setSubtitle(getString(R.string.text_smsrule));
setSupportActionBar(mToolbar);
mrbAccept = findViewById(R.id.activitysmsacceptrulesettingRadioButton1);
mrbRefuse = findViewById(R.id.activitysmsacceptrulesettingRadioButton2);
mcbEnable = findViewById(R.id.activitysmsacceptrulesettingCheckBox1);
if (mSMSAcceptRuleBeanAdd.getRuleType() == SMSAcceptRuleBean.RuleType.ACCEPT) {
mrbAccept.setChecked(true);
mrbRefuse.setChecked(false);
}
if (mSMSAcceptRuleBeanAdd.getRuleType() == SMSAcceptRuleBean.RuleType.REFUSE) {
mrbAccept.setChecked(false);
mrbRefuse.setChecked(true);
}
mcbEnable.setChecked(mSMSAcceptRuleBeanAdd.isEnable());
Button btnAddSMSAcceptRule = findViewById(R.id.activitysmsacceptrulesettingButton1);
btnAddSMSAcceptRule.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText et = findViewById(R.id.activitysmsacceptrulesettingEditText1);
String szRule = et.getText().toString().trim();
if (szRule.equals("")) {
Toast.makeText(getApplication(), "空字符串规则不能添加", Toast.LENGTH_SHORT).show();
} else {
mSMSAcceptRuleBeanAdd.setRuleData(et.getText().toString());
mSMSAcceptRuleBeanAdd.setIsEnable(mcbEnable.isChecked());
mSMSAcceptRuleBeanAdd.setRuleType(mrbRefuse.isChecked() ?SMSAcceptRuleBean.RuleType.REFUSE: SMSAcceptRuleBean.RuleType.ACCEPT);
mSMSAcceptRuleArrayAdapter.addSMSAcceptRule(mSMSAcceptRuleBeanAdd);
initSMSAcceptRuleBeanAdd();
et.setText("");
Toast.makeText(getApplication(), "已添加规则 : " + szRule, Toast.LENGTH_SHORT).show();
}
}
});
// 绑定控件
mRecyclerView = findViewById(R.id.activitysmsacceptrulesettingRecyclerView1);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(layoutManager);
mSMSAcceptRuleArrayAdapter = new SMSAcceptRuleArrayAdapter(this);
mRecyclerView.setAdapter(mSMSAcceptRuleArrayAdapter);
final PullRefreshLayout pullRefreshLayout = findViewById(R.id.activitysmsacceptrulesettingPullRefreshLayout1);
pullRefreshLayout.setOnRefreshListener(new PullRefreshLayout.OnRefreshListener(){
@Override
public void onRefresh() {
pullRefreshLayout.setRefreshing(false);
mSMSAcceptRuleArrayAdapter.loadConfigData();
mSMSAcceptRuleArrayAdapter.notifyDataSetChanged();
}
});
}
void initSMSAcceptRuleBeanAdd() {
mSMSAcceptRuleBeanAdd = new SMSAcceptRuleBean(GlobalApplication.USER_ID, "", true, SMSAcceptRuleBean.RuleType.REFUSE, true);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
//return super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.toolbar_rule, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int nItemId = item.getItemId();
if (nItemId == R.id.item_rule_share) {
//SMSReceiveRuleUtil smsAcceptRuleConfig = SMSReceiveRuleUtil.getInstance(this, false);
SMSAcceptRuleBean beanTemp = new SMSAcceptRuleBean();
String szConfigPath = beanTemp.getBeanListJsonFilePath(mContext);
FileUtil.shareJSONFile(SMSReceiveRuleActivity.this, szConfigPath);
} else if (nItemId == R.id.item_rule_reset) {
showResetConfigDialog();
} else if (nItemId == R.id.item_rule_clean) {
showCleanConfigDialog();
}
return true;
}
//
// 短信匹配过滤规则数据重置对话框
//
void showResetConfigDialog() {
Dialog alertDialog = new AlertDialog.Builder(this).
setTitle("确定重置?").
setMessage("您确定重置短信接收规则为默认设置吗?").
setIcon(R.drawable.ic_launcher).
setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
SMSReceiveRuleUtil smsAcceptRuleConfig = SMSReceiveRuleUtil.getInstance(getApplicationContext(), false);
smsAcceptRuleConfig.resetConfig();
mSMSAcceptRuleArrayAdapter.notifyDataSetChanged();
Toast.makeText(getApplication(), "Rules Reset", Toast.LENGTH_SHORT).show();
}
}).
setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).
/*setNeutralButton("查看详情", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).*/
create();
alertDialog.show();
}
//
// 短信匹配过滤规则数据清空对话框
//
void showCleanConfigDialog() {
Dialog alertDialog = new AlertDialog.Builder(this).
setTitle("确定清理").
setMessage("您确定清理所有短信接收规则吗?").
setIcon(R.drawable.ic_launcher).
setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
SMSReceiveRuleUtil smsAcceptRuleConfig = SMSReceiveRuleUtil.getInstance(getApplicationContext(), false);
smsAcceptRuleConfig.cleanConfig();
mSMSAcceptRuleArrayAdapter.notifyDataSetChanged();
Toast.makeText(getApplication(), "Rules Cleaned.", Toast.LENGTH_SHORT).show();
}
}).
setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).
/*setNeutralButton("查看详情", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).*/
create();
alertDialog.show();
}
public void onAcceptRuleType(View view) {
mrbRefuse.setChecked(false);
}
public void onRefuseRuleType(View view) {
mrbAccept.setChecked(false);
}
@Override
protected void onResume() {
super.onResume();
mSMSAcceptRuleArrayAdapter.loadConfigData();
mSMSAcceptRuleArrayAdapter.notifyDataSetChanged();
}
}

View File

@@ -0,0 +1,92 @@
package cc.winboll.studio.mymessagemanager.activitys;
/**
* @Author ZhanGSKen@QQ.COM
* @Date 2024/07/19 16:56:18
* @Describe 短信回收站
*/
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import cc.winboll.studio.mymessagemanager.R;
import cc.winboll.studio.mymessagemanager.activitys.SMSRecycleActivity;
import cc.winboll.studio.mymessagemanager.adapters.SMSRecycleAdapter;
import cc.winboll.studio.mymessagemanager.utils.SMSRecycleUtil;
import cc.winboll.studio.shared.view.YesNoAlertDialog;
import com.baoyz.widget.PullRefreshLayout;
import java.io.File;
import androidx.appcompat.widget.Toolbar;
public class SMSRecycleActivity extends BaseActivity {
public static final String TAG = "SMSRecycleActivity";
Toolbar mToolbar;
RecyclerView mRecyclerView;
SMSRecycleAdapter mSMSRecycleAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_smsrecycle);
// 初始化标题栏
mToolbar = findViewById(R.id.activitysmsrecycleASupportToolbar1);
mToolbar.setSubtitle(getString(R.string.activity_name_about));
setSupportActionBar(mToolbar);
initView();
}
void initView() {
// 绑定控件
mRecyclerView = findViewById(R.id.activitysmsrecycleRecyclerView1);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(layoutManager);
mSMSRecycleAdapter = new SMSRecycleAdapter(this);
mRecyclerView.setAdapter(mSMSRecycleAdapter);
final PullRefreshLayout pullRefreshLayout = findViewById(R.id.activitysmsrecyclePullRefreshLayout1);
pullRefreshLayout.setOnRefreshListener(new PullRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
mSMSRecycleAdapter.loadSMSRecycleList();
mSMSRecycleAdapter.notifyDataSetChanged();
pullRefreshLayout.setRefreshing(false);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
//return super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.toolbar_smsrecycle, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int nItemId = item.getItemId();
if (nItemId == R.id.item_cleansmsrecycle) {
YesNoAlertDialog.show(this, "回收站清空确认", "是否清空回收站", mDeleteListener);
}
return true;
}
YesNoAlertDialog.OnDialogResultListener mDeleteListener = new YesNoAlertDialog.OnDialogResultListener() {
@Override
public void onNo() {
}
@Override
public void onYes() {
File file = new File(SMSRecycleUtil.getSMSRecycleListDataPath(SMSRecycleActivity.this));
file.delete();
mSMSRecycleAdapter.loadSMSRecycleList();
mSMSRecycleAdapter.notifyDataSetChanged();
}
};
}

View File

@@ -0,0 +1,139 @@
package cc.winboll.studio.mymessagemanager.activitys;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.Toolbar;
import cc.winboll.studio.mymessagemanager.R;
import cc.winboll.studio.mymessagemanager.beans.SMSAcceptRuleBean;
import cc.winboll.studio.mymessagemanager.beans.TTSPlayRuleBean;
import cc.winboll.studio.mymessagemanager.dialogs.YesNoAlertDialog;
import cc.winboll.studio.mymessagemanager.utils.UriUtil;
import java.util.ArrayList;
public class SharedJSONReceiveActivity extends BaseActivity {
public static final String TAG = "SharedJSONReceive";
Toolbar mToolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sharedjsonreceive);
StringBuilder sb = new StringBuilder();
// 接收分享数据
Intent intent = getIntent();
String action = intent.getAction();//action
String type = intent.getType();//类型
//LogUtils.d(TAG, "action is " + action);
//LogUtils.d(TAG, "type is " + type);
if ((Intent.ACTION_SEND.equals(action) || Intent.ACTION_VIEW.equals(action) || Intent.ACTION_EDIT.equals(action))
&& type != null && (("application/json".equals(type)) || ("text/x-json".equals(type)))) {
//取出文件uri
Uri uri = intent.getData();
if (uri == null) {
uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
}
//获取文件真实地址
String szSrcJSON = UriUtil.getFileFromUri(getApplication(), uri);
if (TextUtils.isEmpty(szSrcJSON)) {
return;
}
String szCheck = TTSPlayRuleBean.checkIsTheSameBeanListAndFile(szSrcJSON, TTSPlayRuleBean.class);
if (szCheck.equals("")) {
importTTSPlayRuleBean(szSrcJSON);
} else {
sb.append("\n语音规则数据检测结果\n");
sb.append(szCheck);
}
//LogUtils.d(TAG, "szCheck is " + szCheck);
szCheck = SMSAcceptRuleBean.checkIsTheSameBeanListAndFile(szSrcJSON, SMSAcceptRuleBean.class);
if (szCheck.equals("")) {
importSMSAcceptRuleBean(szSrcJSON);
} else {
sb.append("\n短信接收规则数据检测结果\n");
sb.append(szCheck);
}
//LogUtils.d(TAG, "szCheck is " + szCheck);
} else {
sb.append("Not supported action.");
}
mToolbar = findViewById(R.id.activitysharedjsonreceiveASupportToolbar1);
mToolbar.setSubtitle(getString(R.string.activity_name_sharedjsonreceive));
setActionBar(mToolbar);
TextView tvMessage = findViewById(R.id.activitysharedjsonreceiveTextView1);
tvMessage.setText(sb.toString());
}
void importSMSAcceptRuleBean(final String szSrcJSON) {
ArrayList<SMSAcceptRuleBean> beanList = new ArrayList<SMSAcceptRuleBean>();
boolean bCheck = SMSAcceptRuleBean.loadBeanListFromFile(szSrcJSON, beanList, SMSAcceptRuleBean.class);
if (bCheck && beanList.size() > 0) {
YesNoAlertDialog.show(SharedJSONReceiveActivity.this,
"短信接收规则共享提示",
"已收到短信接收规则" + Integer.toString(beanList.size()) + "个,\n是否导入应用"
, (new YesNoAlertDialog.OnDialogResultListener(){
@Override
public void onYes() {
ArrayList<SMSAcceptRuleBean> beanListShare = new ArrayList<SMSAcceptRuleBean>();
SMSAcceptRuleBean.loadBeanListFromFile(szSrcJSON, beanListShare, SMSAcceptRuleBean.class);
ArrayList<SMSAcceptRuleBean> beanListApp = new ArrayList<SMSAcceptRuleBean>();
SMSAcceptRuleBean.loadBeanList(SharedJSONReceiveActivity.this, beanListApp, SMSAcceptRuleBean.class);
beanListApp.addAll(0, beanListShare);
SMSAcceptRuleBean.saveBeanList(SharedJSONReceiveActivity.this, beanListApp, SMSAcceptRuleBean.class);
Toast.makeText(getApplication(), "已导入" + Integer.toString(beanListShare.size()) + "个数据。", Toast.LENGTH_SHORT).show();
finish();
Intent intent = new Intent(SharedJSONReceiveActivity.this, SMSReceiveRuleActivity.class);
startActivity(intent);
}
@Override
public void onNo() {
finish();
}
}));
}
}
void importTTSPlayRuleBean(final String szSrcJSON) {
ArrayList<TTSPlayRuleBean> beanList = new ArrayList<TTSPlayRuleBean>();
boolean bCheck = TTSPlayRuleBean.loadBeanListFromFile(szSrcJSON, beanList, TTSPlayRuleBean.class);
if (bCheck && beanList.size() > 0) {
YesNoAlertDialog.show(SharedJSONReceiveActivity.this,
"语音规则共享提示",
"已收到语音规则" + Integer.toString(beanList.size()) + "个,\n是否导入应用"
, (new YesNoAlertDialog.OnDialogResultListener(){
@Override
public void onYes() {
ArrayList<TTSPlayRuleBean> beanListShare = new ArrayList<TTSPlayRuleBean>();
TTSPlayRuleBean.loadBeanListFromFile(szSrcJSON, beanListShare, TTSPlayRuleBean.class);
ArrayList<TTSPlayRuleBean> beanListApp = new ArrayList<TTSPlayRuleBean>();
TTSPlayRuleBean.loadBeanList(SharedJSONReceiveActivity.this, beanListApp, TTSPlayRuleBean.class);
beanListApp.addAll(0, beanListShare);
TTSPlayRuleBean.saveBeanList(SharedJSONReceiveActivity.this, beanListApp, TTSPlayRuleBean.class);
Toast.makeText(getApplication(), "已导入" + Integer.toString(beanListShare.size()) + "个数据。", Toast.LENGTH_SHORT).show();
finish();
Intent intent = new Intent(SharedJSONReceiveActivity.this, TTSPlayRuleActivity.class);
startActivity(intent);
}
@Override
public void onNo() {
finish();
}
}));
}
}
}

View File

@@ -0,0 +1,188 @@
package cc.winboll.studio.mymessagemanager.activitys;
/**
* @Author ZhanGSKen@QQ.COM
* @Date 2024/07/19 12:50:52
* @Describe TTS 语音播放规则规则设置窗口
*/
import android.os.Bundle;
import android.os.Message;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import cc.winboll.studio.mymessagemanager.R;
import cc.winboll.studio.mymessagemanager.adapters.TTSRuleBeanRecyclerViewAdapter;
import cc.winboll.studio.mymessagemanager.beans.TTSPlayRuleBean;
import cc.winboll.studio.mymessagemanager.utils.FileUtil;
import cc.winboll.studio.mymessagemanager.utils.TTSPlayRuleUtil;
public class TTSPlayRuleActivity extends BaseActivity {
public static final String TAG = "TTSPlayRuleActivity";
public static final int MSG_RELOAD = 0;
public static final String EXTRA_TTSDEMOTEXT = "EXTRA_TTSDEMOTEXT";
Toolbar mToolbar;
TTSRuleBeanRecyclerViewAdapter mTTSRuleBeanRecyclerViewAdapter;
TTSPlayRuleUtil mTTSPlayRuleUtil;
TTSPlayRuleBean mTTSRuleBeanCurrent;
RecyclerView mRecyclerView;
EditText metCurrentDemoSMSText;
EditText metPatternText;
EditText metCurrentTTSRuleText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ttsplayrule);
mTTSPlayRuleUtil = TTSPlayRuleUtil.getInstance(TTSPlayRuleActivity.this);
initView();
// 设置窗口消息处理
setOnActivityMessageReceived(new IOnActivityMessageReceived(){
@Override
public void onActivityMessageReceived(Message msg) {
switch (msg.what) {
case MSG_RELOAD : {
//Toast.makeText(getApplication(), "MSG_RELOAD", Toast.LENGTH_SHORT).show();
mTTSRuleBeanRecyclerViewAdapter.reloadConfigData();
break;
}
}
}
});
}
void initView() {
// 初始化标题栏
mToolbar = findViewById(R.id.activityttsplayruleASupportToolbar1);
mToolbar.setSubtitle(getString(R.string.text_ttsrule));
setSupportActionBar(mToolbar);
metCurrentDemoSMSText = findViewById(R.id.activityttsplayruleEditText1);
metPatternText = findViewById(R.id.activityttsplayruleEditText2);
metCurrentTTSRuleText = findViewById(R.id.activityttsplayruleEditText3);
Button btnTestTTSRule = findViewById(R.id.activityttsplayruleButton1);
btnTestTTSRule.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TTSPlayRuleBean ttsRuleBean = new TTSPlayRuleBean();
ttsRuleBean.setDemoSMSText(metCurrentDemoSMSText.getText().toString());
ttsRuleBean.setPatternText(metPatternText.getText().toString());
ttsRuleBean.setTtsRuleText(metCurrentTTSRuleText.getText().toString());
String sz = mTTSPlayRuleUtil.testTTSAnalyzeModeReply(ttsRuleBean);
Toast.makeText(getApplication(), sz, Toast.LENGTH_SHORT).show();
}
});
Button btnAcceptTTSRule = findViewById(R.id.activityttsplayruleButton2);
btnAcceptTTSRule.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mTTSRuleBeanCurrent != null) {
mTTSRuleBeanCurrent.setDemoSMSText(metCurrentDemoSMSText.getText().toString());
mTTSRuleBeanCurrent.setPatternText(metPatternText.getText().toString());
mTTSRuleBeanCurrent.setTtsRuleText(metCurrentTTSRuleText.getText().toString());
mTTSRuleBeanRecyclerViewAdapter.saveConfigData();
} else {
if (!metCurrentDemoSMSText.getText().toString().equals("")) {
mTTSRuleBeanCurrent = new TTSPlayRuleBean();
mTTSRuleBeanCurrent.setDemoSMSText(metCurrentDemoSMSText.getText().toString());
mTTSRuleBeanCurrent.setPatternText(metPatternText.getText().toString());
mTTSRuleBeanCurrent.setTtsRuleText(metCurrentTTSRuleText.getText().toString());
mTTSRuleBeanRecyclerViewAdapter.addNewTTSRuleBean(mTTSRuleBeanCurrent);
LinearLayoutManager layoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager();
layoutManager.scrollToPositionWithOffset(0, 0);
}
}
}
});
// 绑定控件
mRecyclerView = findViewById(R.id.activityttsplayruleRecyclerView1);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(layoutManager);
mTTSRuleBeanRecyclerViewAdapter = new TTSRuleBeanRecyclerViewAdapter(TTSPlayRuleActivity.this, mOnTTSRuleChangeListener);
mRecyclerView.setAdapter(mTTSRuleBeanRecyclerViewAdapter);
// 处理传入的窗口启动参数
//
String szNewDemoText = getIntent().getStringExtra(EXTRA_TTSDEMOTEXT);
metCurrentDemoSMSText.setText(szNewDemoText);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
//return super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.toolbar_rule, menu);
return true;
}
public void onScrollToDemoSMSTextMatchingRule(View view) {
int rowIndex = mTTSPlayRuleUtil.speakTTSAnalyzeModeText(metCurrentDemoSMSText.getText().toString());
LinearLayoutManager layoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager();
layoutManager.scrollToPositionWithOffset(rowIndex, 0);
Toast.makeText(getApplication(), "当前文本匹配的规则序号为 " + Integer.toString(rowIndex + 1), Toast.LENGTH_SHORT).show();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int nItemId = item.getItemId();
if (nItemId == R.id.item_rule_share) {
TTSPlayRuleBean bean = new TTSPlayRuleBean();
FileUtil.shareJSONFile(this, bean.getBeanListJsonFilePath(TTSPlayRuleActivity.this));
} else if (nItemId == R.id.item_rule_reset) {
showResetConfigDialog();
} else if (nItemId == R.id.item_rule_clean) {
showCleanConfigDialog();
}
return true;
}
//
// 规则数据重置对话框
//
void showResetConfigDialog() {
mTTSPlayRuleUtil.resetConfig();
}
//
// 规则数据重置对话框
//
void showCleanConfigDialog() {
mTTSPlayRuleUtil.cleanConfig();
}
@Override
protected void onResume() {
super.onResume();
}
//
// 规则项选择事件监听类
//
TTSRuleBeanRecyclerViewAdapter.OnTTSRuleChangeListener mOnTTSRuleChangeListener = new TTSRuleBeanRecyclerViewAdapter.OnTTSRuleChangeListener() {
@Override
public void onTTSRuleChange(TTSPlayRuleBean bean) {
metCurrentDemoSMSText.setText(bean.getDemoSMSText());
metPatternText.setText(bean.getPatternText());
metCurrentTTSRuleText.setText(bean.getTtsRuleText());
mTTSRuleBeanCurrent = bean;
}
};
}

View File

@@ -0,0 +1,114 @@
package cc.winboll.studio.mymessagemanager.adapters;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import cc.winboll.studio.mymessagemanager.R;
import cc.winboll.studio.mymessagemanager.activitys.SMSActivity;
import cc.winboll.studio.mymessagemanager.beans.PhoneBean;
import cc.winboll.studio.mymessagemanager.beans.SMSBean;
import cc.winboll.studio.mymessagemanager.utils.PhoneUtil;
import cc.winboll.studio.mymessagemanager.utils.SMSUtil;
import cc.winboll.studio.shared.log.LogUtils;
import java.util.ArrayList;
import java.util.List;
public class PhoneArrayAdapter extends BaseAdapter {
public final static String TAG = "PhoneArrayAdapter";
Context mContext;
ArrayList<SMSBean> mData;
List<PhoneBean> mlistContacts;
PhoneUtil mPhoneUtil;
public PhoneArrayAdapter(Context context) {
mContext = context;
mData = new ArrayList<SMSBean>();
}
public void loadData() {
ArrayList<SMSBean> listTemp = SMSUtil.getAllSMSList(mContext);
mData.clear();
mData.addAll(listTemp);
mPhoneUtil = new PhoneUtil(mContext);
mlistContacts = mPhoneUtil.getPhoneList();
LogUtils.i(TAG, "SMS List Reload.");
}
@Override
public int getCount() {
return mData.size();
}
@Override
public Object getItem(int p1) {
return mData.get(p1);
}
@Override
public long getItemId(int p1) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder viewHolder;
if (convertView == null) {
viewHolder = new ViewHolder();
convertView = LayoutInflater.from(mContext).inflate(R.layout.listview_phone, parent, false);
//分别获取 image view 和 textview 的实例
viewHolder.tvAddress = convertView.findViewById(R.id.listviewphoneTextView1);
viewHolder.tvName = convertView.findViewById(R.id.listviewphoneTextView2);
viewHolder.ll = convertView.findViewById(R.id.listviewphoneLinearLayout1);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
String szAddress = ((SMSBean)getItem(position)).getAddress();
viewHolder.tvAddress.setText(szAddress);
viewHolder.tvName.setText(getName(szAddress));
//Drawable drawableFrame = AppCompatResources.getDrawable(mContext, R.drawable.bg_frame);
//viewHolder.ll.setBackground(drawableFrame);
viewHolder.ll.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
//Toast.makeText(mContext, tv.getText(), Toast.LENGTH_SHORT).show();
Intent intent = new Intent(mContext, SMSActivity.class);
intent.putExtra(SMSActivity.EXTRA_PHONE, viewHolder.tvAddress.getText());
mContext.startActivity(intent);
}
});
return convertView;
}
String getName(String szAddress) {
for (int i = 0; i < mlistContacts.size(); i++) {
if (mlistContacts.get(i).getTelPhone().equals(szAddress)) {
return mlistContacts.get(i).getName();
}
}
return mContext.getString(R.string.text_notincontacts);
}
class ViewHolder {
TextView tvAddress;
TextView tvName;
LinearLayout ll;
}
}

View File

@@ -0,0 +1,229 @@
package cc.winboll.studio.mymessagemanager.adapters;
/**
* @Author ZhanGSKen@QQ.COM
* @Date 2024/07/20 12:27:34
* @Describe 短信过滤规则数据适配器
*/
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView;
import cc.winboll.studio.mymessagemanager.R;
import cc.winboll.studio.mymessagemanager.beans.SMSAcceptRuleBean;
import cc.winboll.studio.mymessagemanager.utils.SMSReceiveRuleUtil;
import com.hjq.toast.ToastUtils;
import java.util.ArrayList;
public class SMSAcceptRuleArrayAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
public static final String TAG = "SMSAcceptRuleArrayAdapter";
Context mContext;
ArrayList<SMSAcceptRuleBean> mDataList;
SMSReceiveRuleUtil mSMSReceiveRuleUtil;
public SMSAcceptRuleArrayAdapter(Context context) {
mContext = context;
mSMSReceiveRuleUtil = SMSReceiveRuleUtil.getInstance(mContext, true);
loadConfigData();
}
public void addSMSAcceptRule(SMSAcceptRuleBean bean) {
mSMSReceiveRuleUtil.addRule(bean);
notifyDataSetChanged();
}
public void loadConfigData() {
mDataList = mSMSReceiveRuleUtil.loadConfigData();
for (int i = 0; i < mDataList.size(); i++) {
mDataList.get(i).setIsSimpleView(true);
//LogUtils.d(TAG, "loadConfigData isEnable : " + Boolean.toString(mDataList.get(i).isEnable()));
}
}
void deleteItem(int position) {
mDataList.remove(position);
mSMSReceiveRuleUtil.saveConfigData();
notifyDataSetChanged();
}
@Override
public int getItemViewType(int position) {
if (mDataList.get(position).isSimpleView()) {
return 0;
} else {
return 1;
}
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType == 0) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.listview_smsacceptrule_simple, parent, false);
return new SimpleViewHolder(view);
} else {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.listview_smsacceptrule, parent, false);
return new ComplexViewHolder(view);
}
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
final SMSAcceptRuleBean item = mDataList.get(position);
if (holder.getItemViewType() == 0) {
final SimpleViewHolder viewHolder = (SimpleViewHolder) holder;
viewHolder.mtvContent.setText(item.getRuleData());
viewHolder.mcbEnable.setChecked(item.isEnable());
viewHolder.mcbEnable.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View p1) {
item.setIsEnable(viewHolder.mcbEnable.isChecked());
item.setIsSimpleView(true);
mSMSReceiveRuleUtil.saveConfigData();
notifyDataSetChanged();
}
});
viewHolder.mtvRuleType.setText(item.getRuleType().toString());
viewHolder.mbtnEdit.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
for (int i = 0; i < mDataList.size(); i++) {
mDataList.get(i).setIsSimpleView(true);
}
item.setIsSimpleView(false);
notifyDataSetChanged();
//ToastUtils.show("setIsSimpleView");
}
});
} else {
final ComplexViewHolder viewHolder = (ComplexViewHolder) holder;
if (item != null) {
//Drawable drawableFrame = AppCompatResources.getDrawable(mContext, R.drawable.bg_frame);
viewHolder.metContent.setText(item.getRuleData());
if (item.getRuleType() == SMSAcceptRuleBean.RuleType.ACCEPT) {
viewHolder.mrbAccept.setChecked(true);
viewHolder.mrbRefuse.setChecked(false);
}
if (item.getRuleType() == SMSAcceptRuleBean.RuleType.REFUSE) {
viewHolder.mrbAccept.setChecked(false);
viewHolder.mrbRefuse.setChecked(true);
}
viewHolder.mrbAccept.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
viewHolder.mrbRefuse.setChecked(false);
item.setRuleType(SMSAcceptRuleBean.RuleType.ACCEPT);
mSMSReceiveRuleUtil.saveConfigData();
notifyDataSetChanged();
}
});
viewHolder.mrbRefuse.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
viewHolder.mrbAccept.setChecked(false);
item.setRuleType(SMSAcceptRuleBean.RuleType.REFUSE);
mSMSReceiveRuleUtil.saveConfigData();
notifyDataSetChanged();
}
});
viewHolder.mbtnUp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View p1) {
if (position > 0) {
mDataList.add(position-1, mDataList.get(position));
mDataList.remove(position+1);
mSMSReceiveRuleUtil.saveConfigData();
notifyDataSetChanged();
}
}
});
viewHolder.mbtnDown.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View p1) {
if (position < mDataList.size() - 1) {
//ToastUtils.show("mbtnDown");
ToastUtils.show("position " + Integer.toString(position));
mDataList.add(position+2, mDataList.get(position));
mDataList.remove(position);
mSMSReceiveRuleUtil.saveConfigData();
notifyDataSetChanged();
}
}
});
viewHolder.mbtnOK.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View p1) {
item.setRuleData(viewHolder.metContent.getText().toString());
item.setRuleType(viewHolder.mrbAccept.isChecked() ?SMSAcceptRuleBean.RuleType.ACCEPT: SMSAcceptRuleBean.RuleType.REFUSE);
item.setIsEnable(viewHolder.mcbEnable.isChecked());
item.setIsSimpleView(true);
mSMSReceiveRuleUtil.saveConfigData();
notifyDataSetChanged();
}
});
viewHolder.mbtnDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View p1) {
deleteItem(position);
}
});
viewHolder.mcbEnable.setChecked(item.isEnable());
}
}
}
@Override
public int getItemCount() {
return mDataList.size();
}
@Override
public long getItemId(int posttion) {
return 0;
}
private static class SimpleViewHolder extends RecyclerView.ViewHolder {
TextView mtvContent;
CheckBox mcbEnable;
TextView mtvRuleType;
Button mbtnEdit;
SimpleViewHolder(View itemView) {
super(itemView);
mtvContent = itemView.findViewById(R.id.listviewsmsacceptrulesimpleTextView1);
mcbEnable = itemView.findViewById(R.id.listviewsmsacceptrulesimpleCheckBox1);
mtvRuleType = itemView.findViewById(R.id.listviewsmsacceptrulesimpleTextView2);
mbtnEdit = itemView.findViewById(R.id.listviewsmsacceptrulesimpleButton1);
}
}
private static class ComplexViewHolder extends RecyclerView.ViewHolder {
EditText metContent;
RadioButton mrbAccept;
RadioButton mrbRefuse;
CheckBox mcbEnable;
Button mbtnUp;
Button mbtnDown;
Button mbtnOK;
Button mbtnDelete;
ComplexViewHolder(View itemView) {
super(itemView);
metContent = itemView.findViewById(R.id.listviewsmsacceptruleEditText1);
mrbAccept = itemView.findViewById(R.id.listviewsmsacceptruleRadioButton1);
mrbRefuse = itemView.findViewById(R.id.listviewsmsacceptruleRadioButton2);
mcbEnable = itemView.findViewById(R.id.listviewsmsacceptruleCheckBox1);
mbtnUp = itemView.findViewById(R.id.listviewsmsacceptruleButton3);
mbtnDown = itemView.findViewById(R.id.listviewsmsacceptruleButton4);
mbtnOK = itemView.findViewById(R.id.listviewsmsacceptruleButton1);
mbtnDelete = itemView.findViewById(R.id.listviewsmsacceptruleButton2);
}
}
}

View File

@@ -0,0 +1,213 @@
package cc.winboll.studio.mymessagemanager.adapters;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.PopupMenu;
import android.widget.TextView;
import android.widget.Toast;
import cc.winboll.studio.mymessagemanager.R;
import cc.winboll.studio.mymessagemanager.activitys.TTSPlayRuleActivity;
import cc.winboll.studio.mymessagemanager.beans.SMSBean;
import cc.winboll.studio.mymessagemanager.dialogs.YesNoAlertDialog;
import cc.winboll.studio.mymessagemanager.utils.NotificationUtil;
import cc.winboll.studio.mymessagemanager.utils.SMSReceiveRuleUtil;
import cc.winboll.studio.mymessagemanager.utils.SMSRecycleUtil;
import cc.winboll.studio.mymessagemanager.utils.SMSUtil;
import cc.winboll.studio.mymessagemanager.utils.TTSPlayRuleUtil;
import cc.winboll.studio.mymessagemanager.views.DateAgoTextView;
import cc.winboll.studio.mymessagemanager.views.SMSView;
import com.hjq.toast.ToastUtils;
import java.util.ArrayList;
import cc.winboll.studio.mymessagemanager.beans.SMSAcceptRuleBean;
public class SMSArrayAdapter extends BaseAdapter {
public static String TAG = "SMSArrayAdapter";
Context mContext;
String mszPhone;
ArrayList<SMSBean> mData;
public SMSArrayAdapter(Context context, String szPhone) {
mContext = context;
mszPhone = szPhone;
mData = new ArrayList<SMSBean>();
mData = loadSMSList(context, szPhone);
}
ArrayList<SMSBean> loadSMSList(Context context, String szPhone) {
ArrayList<SMSBean> data = SMSUtil.getSMSListByPhone(context, szPhone);
SMSBean.sortSMSByDateDesc(data, false);
mData.clear();
mData.addAll(data);
return mData;
}
public void cancelMessageNotification() {
for (SMSBean bean : mData) {
NotificationUtil.cancelNotification(mContext, bean.getId());
}
}
void deleteSMSById(final int position) {
YesNoAlertDialog.show(mContext,
"短信删除提示",
"请确认删除动作!"
, (new YesNoAlertDialog.OnDialogResultListener(){
@Override
public void onYes() {
SMSRecycleUtil.addSMSRecycleItem(mContext, (SMSBean)getItem(position));
SMSUtil.deleteSMSById(mContext, ((SMSBean)getItem(position)).getId());
mData.remove(position);
notifyDataSetChanged();
Toast.makeText(mContext, "SMS delete.", Toast.LENGTH_SHORT).show();
}
@Override
public void onNo() {
}
}));
}
public void reLoadSMSList(Context context, String szPhone) {
mData = loadSMSList(context, szPhone);
}
@Override
public int getCount() {
return mData.size();
}
@Override
public Object getItem(int p1) {
return mData.get(p1);
}
@Override
public long getItemId(int p1) {
return 0;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder viewHolder;
if (convertView == null) {
viewHolder = new ViewHolder();
convertView = LayoutInflater.from(mContext).inflate(R.layout.listview_sms, parent, false);
viewHolder.mSMSView = convertView.findViewById(R.id.listviewsmsSMSView1);
viewHolder.mllMain = convertView.findViewById(R.id.listviewsmspart1LinearLayout1);
viewHolder.mllContent = convertView.findViewById(R.id.listviewsmspart1LinearLayout2);
viewHolder.mvMenu = convertView.findViewById(R.id.listviewsmspart1View1);
viewHolder.mtvBody = (TextView) convertView
.findViewById(R.id.listviewsmspart1TextView1);
viewHolder.mdatvDate = convertView.findViewById(R.id.listviewsmspart1DateAgoTextView1);
viewHolder.mvLeft = convertView.findViewById(R.id.listviewsmsView1);
viewHolder.mvRight = convertView.findViewById(R.id.listviewsmsView2);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
final SMSBean item = (SMSBean) getItem(position);
if (item != null) {
if (item.getType() == SMSBean.Type.INBOX) {
viewHolder.mvLeft.setVisibility(View.GONE);
viewHolder.mvRight.setVisibility(View.VISIBLE);
viewHolder.mSMSView.setSMSType(SMSView.SMSType.INBOX);
viewHolder.mllMain.setGravity(Gravity.LEFT);
} else {
viewHolder.mvLeft.setVisibility(View.VISIBLE);
viewHolder.mvRight.setVisibility(View.GONE);
viewHolder.mSMSView.setSMSType(SMSView.SMSType.SEND);
}
//Drawable drawableFrame = AppCompatResources.getDrawable(mContext, R.drawable.bg_frame);
//viewHolder.mllContent.setBackground(drawableFrame);
viewHolder.mtvBody.setText(item.getBody());
viewHolder.mdatvDate.setDate(item.getDate());
//viewHolder.mtvType.setText(" [" + item.getType().name() + "] ");
viewHolder.mSMSView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View p1) {
// 弹出复制菜单
PopupMenu menu = new PopupMenu(mContext, viewHolder.mvMenu);
//加载菜单资源
menu.getMenuInflater().inflate(R.menu.toolbar_item_sms, menu.getMenu());
//设置点击事件的响应
menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
int nItemId = menuItem.getItemId();
if (nItemId == R.id.copy) {
// Gets a handle to the clipboard service.
ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
// Creates a new text clip to put on the clipboard
ClipData clip = ClipData.newPlainText("simple text", item.getBody());
// Set the clipboard's primary clip.
clipboard.setPrimaryClip(clip);
Toast.makeText(mContext, "Copy to clipboard.", Toast.LENGTH_SHORT).show();
} else if (nItemId == R.id.delete) {
deleteSMSById(position);
} else if (nItemId == R.id.addttsrule) {
Intent intent = new Intent(mContext, TTSPlayRuleActivity.class);
intent.putExtra(TTSPlayRuleActivity.EXTRA_TTSDEMOTEXT, viewHolder.mtvBody.getText().toString());
mContext.startActivity(intent);
} else if (nItemId == R.id.testtts) {
//Toast.makeText(mContext, "Testing TTS.", Toast.LENGTH_SHORT).show();
TTSPlayRuleUtil ttsPlayRuleUtil = TTSPlayRuleUtil.getInstance(mContext);
ttsPlayRuleUtil.speakTTSAnalyzeModeText(viewHolder.mtvBody.getText().toString());
} else if (nItemId == R.id.testreceivetule) {
//Toast.makeText(mContext, "Testing Receive Rule.", Toast.LENGTH_SHORT).show();
SMSReceiveRuleUtil smsReceiveRuleUtil = SMSReceiveRuleUtil.getInstance(mContext, true);
SMSReceiveRuleUtil.MatchResult matchResult = smsReceiveRuleUtil.getReceiveRuleMatchResult(mContext, viewHolder.mtvBody.getText().toString());
if (matchResult.matchPositionInRules == SMSReceiveRuleUtil.VALID_MATCHRESULT_POSITION
|| matchResult.matchRuleType == SMSAcceptRuleBean.RuleType.REGEXPPIUTILS_ISPPIOK_FALSE) {
//ToastUtils.show("Test");
ToastUtils.show("Not Receive Rule is Matched.\nResult is : " + matchResult.matchRuleType);
} else {
ToastUtils.show("MatchResult : " + matchResult.matchRuleType + "\nReceiveRule Match Position : " + Integer.toString(matchResult.matchPositionInRules + 1));
}
}
return true;
}
});
//一定要调用show()来显示弹出式菜单
menu.show();
return true;
}
});
}
return convertView;
}
class ViewHolder {
SMSView mSMSView;
LinearLayout mllMain;
LinearLayout mllContent;
TextView mtvBody;
View mvMenu;
DateAgoTextView mdatvDate;
View mvLeft;
View mvRight;
}
}

View File

@@ -0,0 +1,289 @@
package cc.winboll.studio.mymessagemanager.adapters;
/**
* @Author ZhanGSKen@QQ.COM
* @Date 2024/07/19 17:07:34
* @Describe 短信回收站短信数据适配器
*/
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.PopupMenu;
import android.widget.TextView;
import android.widget.Toast;
import androidx.recyclerview.widget.RecyclerView;
import cc.winboll.studio.mymessagemanager.R;
import cc.winboll.studio.mymessagemanager.activitys.TTSPlayRuleActivity;
import cc.winboll.studio.mymessagemanager.beans.SMSBean;
import cc.winboll.studio.mymessagemanager.beans.SMSRecycleBean;
import cc.winboll.studio.mymessagemanager.dialogs.YesNoAlertDialog;
import cc.winboll.studio.mymessagemanager.utils.AppConfigUtil;
import cc.winboll.studio.mymessagemanager.utils.SMSRecycleUtil;
import cc.winboll.studio.mymessagemanager.utils.SMSUtil;
import cc.winboll.studio.mymessagemanager.utils.TTSPlayRuleUtil;
import cc.winboll.studio.mymessagemanager.utils.UserVisionSystemProtectModeUtil;
import cc.winboll.studio.mymessagemanager.views.DateAgoTextView;
import cc.winboll.studio.mymessagemanager.views.SMSView;
import com.hjq.toast.ToastUtils;
import java.util.ArrayList;
public class SMSRecycleAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
public static final String TAG = "SMSRecycleAdapter";
Context mContext;
ArrayList<SMSRecycleBean> mDataList;
String mszSMSRecycleListDataPath;
AppConfigUtil mAppConfigUtil;
public SMSRecycleAdapter(Context context) {
mContext = context;
mAppConfigUtil = AppConfigUtil.getInstance(mContext);
mszSMSRecycleListDataPath = SMSRecycleUtil.getSMSRecycleListDataPath(mContext);
mDataList = new ArrayList<SMSRecycleBean>();
mDataList = loadSMSRecycleList();
}
public ArrayList<SMSRecycleBean> loadSMSRecycleList() {
ArrayList<SMSRecycleBean> list = new ArrayList<SMSRecycleBean>();
SMSRecycleBean.loadBeanListFromFile(mszSMSRecycleListDataPath, list, SMSRecycleBean.class);
SMSRecycleBean.sortSMSByDeleteDateDesc(list, true);
mDataList.clear();
mDataList.addAll(list);
for (int i = 0; i < mDataList.size(); i++) {
mDataList.get(i).setIsSimpleView(true);
}
//ToastUtils.show("mDataList.size() : " + Integer.toString(mDataList.size()));
return mDataList;
}
public void saveSMSRecycleList() {
SMSBean.saveBeanListToFile(mszSMSRecycleListDataPath, mDataList);
}
void restoreSMSRecycleItem(final int position) {
YesNoAlertDialog.show(mContext,
"短信恢复提示",
"是否恢复该短信!"
, (new YesNoAlertDialog.OnDialogResultListener(){
@Override
public void onYes() {
SMSBean item = mDataList.get(position);
long nResultId = 0;
//LogUtils.d(TAG, "item.getType() : " + item.getType());
if (item.getType() == SMSBean.Type.INBOX) {
nResultId = SMSUtil.saveReceiveSms(mContext, item.getAddress(), item.getBody(),
(item.getReadStatus() == SMSBean.ReadStatus.READ) ?"1": "0",
item.getDate(), "inbox");
} else if (item.getType() == SMSBean.Type.SENT) {
nResultId = SMSUtil.saveOldSendedSMS(mContext, item);
}
if (nResultId == 0) {
ToastUtils.show("SMS Restored Failed!\nPlease confirm that the application has the SMS management authority.");
} else {
mDataList.remove(position);
SMSBean.saveBeanListToFile(mszSMSRecycleListDataPath, mDataList);
notifyDataSetChanged();
ToastUtils.show("SMS Restored. ID : " + Long.toString(nResultId));
}
}
@Override
public void onNo() {
}
}));
}
void deleteSMSRecycleItem(final int position) {
YesNoAlertDialog.show(mContext,
"短信删除提示",
"请确认删除动作!"
, (new YesNoAlertDialog.OnDialogResultListener(){
@Override
public void onYes() {
mDataList.remove(position);
SMSBean.saveBeanListToFile(mszSMSRecycleListDataPath, mDataList);
notifyDataSetChanged();
Toast.makeText(mContext, "SMS delete.", Toast.LENGTH_SHORT).show();
}
@Override
public void onNo() {
}
}));
}
public void reLoadSMSList(Context context, String szPhone) {
mDataList = loadSMSRecycleList();
}
@Override
public int getItemViewType(int position) {
if (mDataList.get(position).isSimpleView()) {
return 0;
} else {
return 1;
}
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType == 0) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.listview_smsrecycle_simple, parent, false);
return new SimpleViewHolder(view);
} else {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.listview_smsrecycle, parent, false);
return new ComplexViewHolder(view);
}
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
final SMSRecycleBean item = mDataList.get(position);
if (holder.getItemViewType() == 0) {
SimpleViewHolder viewHolder = (SimpleViewHolder) holder;
viewHolder.mtvAddress.setText(item.getAddress());
viewHolder.mbtnViewBody.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
for (int i = 0; i < mDataList.size(); i++) {
mDataList.get(i).setIsSimpleView(true);
}
item.setIsSimpleView(false);
notifyDataSetChanged();
//ToastUtils.show("setIsSimpleView");
}
});
} else {
final ComplexViewHolder viewHolder = (ComplexViewHolder) holder;
if (item.getType() == SMSBean.Type.INBOX) {
viewHolder.mvLeft.setVisibility(View.GONE);
viewHolder.mvRight.setVisibility(View.VISIBLE);
viewHolder.mSMSView.setSMSType(SMSView.SMSType.INBOX);
viewHolder.mllMain.setGravity(Gravity.LEFT);
} else {
viewHolder.mvLeft.setVisibility(View.VISIBLE);
viewHolder.mvRight.setVisibility(View.GONE);
viewHolder.mSMSView.setSMSType(SMSView.SMSType.SEND);
}
viewHolder.mtvAddress.setText(item.getAddress());
viewHolder.mdatvDeleteDate.setDate(item.getDeleteDate());
viewHolder.mdatvDate.setDate(item.getDate());
if(mAppConfigUtil.mAppConfigBean.isSMSRecycleProtectMode()) {
viewHolder.mtvBody.setText("ProtectMode : " + UserVisionSystemProtectModeUtil.PreviewShuffleSMS(item.getBody(), mAppConfigUtil.mAppConfigBean.getProtectModerRefuseChars(), mAppConfigUtil.mAppConfigBean.getProtectModerReplaceChars()));
} else {
viewHolder.mtvBody.setText(item.getBody());
}
/*viewHolder.mTagsAdapter = new TagsAdapter(mContext, item);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(mContext);
viewHolder.mTagsRecyclerView.setLayoutManager(layoutManager);
viewHolder.mTagsRecyclerView.setAdapter(viewHolder.mTagsAdapter);
// 这个设置可以解决嵌套listvew的内部listview拉动问题。
viewHolder.mTagsRecyclerView.setParentScrollView(viewHolder.mScrollView);*/
viewHolder.mllMain.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View p1) {
// 弹出复制菜单
PopupMenu menu = new PopupMenu(mContext, viewHolder.mvMenu);
//加载菜单资源
menu.getMenuInflater().inflate(R.menu.toolbar_item_smsrecycle, menu.getMenu());
menu.getMenuInflater().inflate(R.menu.toolbar_item_sms, menu.getMenu());
//设置点击事件的响应
menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
int nItemId = menuItem.getItemId();
if (nItemId == R.id.item_restoresms) {
restoreSMSRecycleItem(position);
} else if (nItemId == R.id.copy) {
// Gets a handle to the clipboard service.
ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
// Creates a new text clip to put on the clipboard
ClipData clip = ClipData.newPlainText("simple text", item.getBody());
// Set the clipboard's primary clip.
clipboard.setPrimaryClip(clip);
Toast.makeText(mContext, "Copy to clipboard.", Toast.LENGTH_SHORT).show();
} else if (nItemId == R.id.delete) {
deleteSMSRecycleItem(position);
/*loadSMSRecycleList();
mDataList.remove(item);
saveSMSRecycleList();*/
notifyDataSetChanged();
} else if (nItemId == R.id.addttsrule) {
Intent intent = new Intent(mContext, TTSPlayRuleActivity.class);
intent.putExtra(TTSPlayRuleActivity.EXTRA_TTSDEMOTEXT, viewHolder.mtvBody.getText().toString());
mContext.startActivity(intent);
} else if (nItemId == R.id.testtts) {
//Toast.makeText(mContext, "Testing TTS.", Toast.LENGTH_SHORT).show();
TTSPlayRuleUtil ttsPlayRuleUtil = TTSPlayRuleUtil.getInstance(mContext);
ttsPlayRuleUtil.speakTTSAnalyzeModeText(viewHolder.mtvBody.getText().toString());
}
return true;
}
});
//一定要调用show()来显示弹出式菜单
menu.show();
return true;
}
});
}
}
@Override
public int getItemCount() {
return mDataList.size();
}
private static class SimpleViewHolder extends RecyclerView.ViewHolder {
TextView mtvAddress;
Button mbtnViewBody;
SimpleViewHolder(View itemView) {
super(itemView);
mtvAddress = itemView.findViewById(R.id.listviewsmsrecyclesimpleTextView1);
mbtnViewBody = itemView.findViewById(R.id.listviewsmsrecyclesimpleButton1);
}
}
private static class ComplexViewHolder extends RecyclerView.ViewHolder {
TextView mtvAddress;
DateAgoTextView mdatvDeleteDate;
SMSView mSMSView;
LinearLayout mllMain;
LinearLayout mllContent;
TextView mtvBody;
View mvMenu;
DateAgoTextView mdatvDate;
View mvLeft;
View mvRight;
ComplexViewHolder(View itemView) {
super(itemView);
mtvAddress = itemView.findViewById(R.id.listviewsmsrecycleTextView1);
mdatvDeleteDate = itemView.findViewById(R.id.listviewsmsrecycleDateAgoTextView1);
mSMSView = itemView.findViewById(R.id.listviewsmsrecycleSMSView1);
mllMain = itemView.findViewById(R.id.listviewsmspart1LinearLayout1);
mllContent = itemView.findViewById(R.id.listviewsmspart1LinearLayout2);
mvMenu = itemView.findViewById(R.id.listviewsmsrecycleView1);
mtvBody = itemView.findViewById(R.id.listviewsmspart1TextView1);
mdatvDate = itemView.findViewById(R.id.listviewsmspart1DateAgoTextView1);
mvLeft = itemView.findViewById(R.id.listviewsmsrecycleView1);
mvRight = itemView.findViewById(R.id.listviewsmsrecycleView2);
}
}
}

View File

@@ -0,0 +1,193 @@
package cc.winboll.studio.mymessagemanager.adapters;
/**
* @Author ZhanGSKen@QQ.COM
* @Date 2024/05/18 16:08:20
* @Describe TTSRuleBean RecyclerView Adapter
*/
import android.content.Context;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.PopupMenu;
import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView;
import cc.winboll.studio.mymessagemanager.R;
import cc.winboll.studio.mymessagemanager.activitys.TTSPlayRuleActivity;
import cc.winboll.studio.mymessagemanager.beans.TTSPlayRuleBean;
import cc.winboll.studio.mymessagemanager.utils.TTSPlayRuleUtil;
import cc.winboll.studio.mymessagemanager.views.TTSRuleView;
import java.util.ArrayList;
public class TTSRuleBeanRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
public static final String TAG = "TTSRuleBeanRecyclerViewAdapter";
Context mContext;
ArrayList<TTSPlayRuleBean> mDataList;
OnTTSRuleChangeListener mOnTTSRuleChangeListener;
TTSPlayRuleUtil mTTSPlayRuleUtil;
public TTSRuleBeanRecyclerViewAdapter(TTSPlayRuleActivity ttsPlayRuleActivity, OnTTSRuleChangeListener onTTSRuleChangeListener) {
mContext = ttsPlayRuleActivity;
mOnTTSRuleChangeListener = onTTSRuleChangeListener;
mTTSPlayRuleUtil = TTSPlayRuleUtil.getInstance(ttsPlayRuleActivity);
mTTSPlayRuleUtil.initTTSPlayRuleActivity(ttsPlayRuleActivity);
mDataList = mTTSPlayRuleUtil.loadConfigData();
}
public void addNewTTSRuleBean(TTSPlayRuleBean bean) {
mTTSPlayRuleUtil.addNewTTSRuleBean(bean);
//notifyDataSetChanged();
}
public void saveConfigData() {
mTTSPlayRuleUtil.saveConfigData();
//notifyDataSetChanged();
}
public void reloadConfigData() {
mDataList = mTTSPlayRuleUtil.loadConfigData();
notifyDataSetChanged();
}
public interface OnTTSRuleChangeListener {
abstract void onTTSRuleChange(TTSPlayRuleBean bean);
}
@Override
public int getItemViewType(int position) {
if (mDataList.get(position).isSimpleView()) {
return 0;
} else {
return 1;
}
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType == 0) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.listview_ttsplayrule_simple, parent, false);
return new SimpleViewHolder(view);
} else {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.listview_ttsplayrule, parent, false);
return new ComplexViewHolder(view);
}
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
final TTSPlayRuleBean item = mDataList.get(position);
if (holder.getItemViewType() == 0) {
SimpleViewHolder viewHolder = (SimpleViewHolder) holder;
viewHolder.mSortNumber.setText(Integer.toString(position + 1));
viewHolder.mtvDemoSMSText.setText(item.getDemoSMSText());
} else {
final ComplexViewHolder viewHolder = (ComplexViewHolder) holder;
viewHolder.mSortNumber.setText(Integer.toString(position + 1));
viewHolder.mtvDemoSMSText.setText(item.getDemoSMSText());
viewHolder.mTTSRuleView.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
mOnTTSRuleChangeListener.onTTSRuleChange(item);
}
});
viewHolder.mbtnUp.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
//Toast.makeText(mContext, Integer.toString(position), Toast.LENGTH_SHORT).show();
mTTSPlayRuleUtil.changeBeanPosition(position, true);
//notifyDataSetChanged();
}
});
viewHolder.mbtnDown.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
//Toast.makeText(mContext, Integer.toString(position), Toast.LENGTH_SHORT).show();
mTTSPlayRuleUtil.changeBeanPosition(position, false);
//notifyDataSetChanged();
}
});
viewHolder.mchbEnable.setChecked(item.isEnable());
viewHolder.mchbEnable.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
mTTSPlayRuleUtil.setBeanEnable(position, ((CheckBox)v).isChecked());
//notifyDataSetChanged();
}
});
viewHolder.mTTSRuleView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View p1) {
// 弹出复制菜单
PopupMenu menu = new PopupMenu(mContext, viewHolder.mSortNumber);
//加载菜单资源
menu.getMenuInflater().inflate(R.menu.toolbar_ttsrule, menu.getMenu());
//设置点击事件的响应
menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
int nItemId = menuItem.getItemId();
if (nItemId == R.id.deletettsrule) {
mTTSPlayRuleUtil.deleteTTSRuleBean(position);
//notifyDataSetChanged();
}
return true;
}
});
//一定要调用show()来显示弹出式菜单
menu.show();
return true;
}
});
}
}
@Override
public int getItemCount() {
return mDataList.size();
}
private static class SimpleViewHolder extends RecyclerView.ViewHolder {
TextView mSortNumber;
TextView mtvDemoSMSText;
SimpleViewHolder(View itemView) {
super(itemView);
mSortNumber = itemView.findViewById(R.id.itemttsplayrulesimpleTextView2);
mtvDemoSMSText = itemView.findViewById(R.id.itemttsplayrulesimpleTextView1);
}
}
private static class ComplexViewHolder extends RecyclerView.ViewHolder {
TextView mSortNumber;
TTSRuleView mTTSRuleView;
LinearLayout mllMain;
TextView mtvDemoSMSText;
Button mbtnUp;
Button mbtnDown;
CheckBox mchbEnable;
ComplexViewHolder(View itemView) {
super(itemView);
mSortNumber = itemView.findViewById(R.id.itemttsplayruleTextView2);
mTTSRuleView = itemView.findViewById(R.id.listviewttsplayruleTTSRuleView1);
mllMain = itemView.findViewById(R.id.itemttsplayruleLinearLayout1);
mtvDemoSMSText = itemView.findViewById(R.id.itemttsplayruleTextView1);
mbtnUp = itemView.findViewById(R.id.itemttsplayruleButton1);
mbtnDown = itemView.findViewById(R.id.itemttsplayruleButton2);
mchbEnable = itemView.findViewById(R.id.itemttsplayruleCheckBox1);
}
}
}

View File

@@ -0,0 +1,185 @@
package cc.winboll.studio.mymessagemanager.beans;
/**
* @Author ZhanGSKen@QQ.COM
* @Date 2024/06/02 20:07:44
* @Describe 应用配置数据类
*/
import android.util.JsonReader;
import android.util.JsonWriter;
import cc.winboll.studio.mymessagemanager.utils.ThemeUtil;
import cc.winboll.studio.shared.app.BaseBean;
import java.io.IOException;
public class AppConfigBean extends BaseBean {
public static final String TAG = "AppConfigBean";
// 当前国家代码(如+8612345678901代码就是86.)
String countryCode = "86";
// 是否合并的手机号码前缀
boolean isMergeCountryCodePrefix = true;
// TT语音延时播放毫秒数
int ttsPlayDelayTimes = 3000;
boolean isEnableService = false;
boolean isEnableOnlyReceiveContacts = false;
boolean isEnableTTS = false;
boolean isEnableTTSRuleMode = false;
boolean isSMSRecycleProtectMode = false;
// 保护式预览拒绝显示的字符集
String protectModerRefuseChars = "设定被和谐的字符";
// 保护式预览拒绝显示的字符集的替代字符
String protectModerReplaceChars = "当前替代显示字符";
//int appThemeID = ThemeUtil.getThemeID(ThemeUtil.BaseTheme.DEFAULT);
public void setProtectModerRefuseChars(String protectModerRefuseChars) {
this.protectModerRefuseChars = protectModerRefuseChars;
}
public String getProtectModerRefuseChars() {
return protectModerRefuseChars;
}
public void setProtectModerReplaceChars(String protectModerReplaceChars) {
this.protectModerReplaceChars = protectModerReplaceChars;
}
public String getProtectModerReplaceChars() {
return protectModerReplaceChars;
}
public void setIsSMSRecycleProtectMode(boolean isSMSRecycleProtectMode) {
this.isSMSRecycleProtectMode = isSMSRecycleProtectMode;
}
public boolean isSMSRecycleProtectMode() {
return isSMSRecycleProtectMode;
}
public void setCountryCode(String countryCode) {
this.countryCode = countryCode;
}
public String getCountryCode() {
return countryCode;
}
public void setIsMergeCountryCodePrefix(boolean isMergeCountryCodePrefix) {
this.isMergeCountryCodePrefix = isMergeCountryCodePrefix;
}
public boolean isMergeCountryCodePrefix() {
return isMergeCountryCodePrefix;
}
public void setTtsPlayDelayTimes(int ttsPlayDelayTimes) {
this.ttsPlayDelayTimes = ttsPlayDelayTimes;
}
public int getTtsPlayDelayTimes() {
return ttsPlayDelayTimes;
}
public void setIsEnableService(boolean isEnableService) {
this.isEnableService = isEnableService;
}
public boolean isEnableService() {
return isEnableService;
}
public void setIsEnableOnlyReceiveContacts(boolean isEnableOnlyReceiveContacts) {
this.isEnableOnlyReceiveContacts = isEnableOnlyReceiveContacts;
}
public boolean isEnableOnlyReceiveContacts() {
return isEnableOnlyReceiveContacts;
}
public void setIsEnableTTS(boolean isEnableTTS) {
this.isEnableTTS = isEnableTTS;
}
public boolean isEnableTTS() {
return isEnableTTS;
}
public void setIsEnableTTSRuleMode(boolean isEnableTTSRuleMode) {
this.isEnableTTSRuleMode = isEnableTTSRuleMode;
}
public boolean isEnableTTSRuleMode() {
return isEnableTTSRuleMode;
}
/*public void setAppThemeID(int appThemeID) {
this.appThemeID = appThemeID;
}
public int getAppThemeID() {
return appThemeID;
}
public void setAppTheme(ThemeUtil.BaseTheme baseTheme) {
setAppThemeID(ThemeUtil.getThemeID(baseTheme));
}*/
@Override
public String getName() {
return AppConfigBean.class.getName();
}
@Override
public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
super.writeThisToJsonWriter(jsonWriter);
AppConfigBean bean = this;
jsonWriter.name("countryCode").value(bean.getCountryCode());
jsonWriter.name("isMergeCountryCodePrefix").value(bean.isMergeCountryCodePrefix());
jsonWriter.name("ttsPlayDelayTimes").value(bean.getTtsPlayDelayTimes());
jsonWriter.name("isEnableService").value(bean.isEnableService());
jsonWriter.name("isEnableOnlyReceiveContacts").value(bean.isEnableOnlyReceiveContacts());
jsonWriter.name("isEnableTTS").value(bean.isEnableTTS());
jsonWriter.name("isEnableTTSRuleMode").value(bean.isEnableTTSRuleMode());
jsonWriter.name("isSMSRecycleProtectMode").value(bean.isSMSRecycleProtectMode());
jsonWriter.name("protectModerRefuseChars").value(bean.getProtectModerRefuseChars());
jsonWriter.name("protectModerReplaceChars").value(bean.getProtectModerReplaceChars());
//jsonWriter.name("appThemeID").value(bean.getAppThemeID());
}
@Override
public BaseBean readBeanFromJsonReader(JsonReader jsonReader) throws IOException {
AppConfigBean bean = new AppConfigBean();
jsonReader.beginObject();
while (jsonReader.hasNext()) {
String name = jsonReader.nextName();
if (name.equals("countryCode")) {
bean.setCountryCode(jsonReader.nextString());
} else if (name.equals("isMergeCountryCodePrefix")) {
bean.setIsMergeCountryCodePrefix(jsonReader.nextBoolean());
} else if (name.equals("ttsPlayDelayTimes")) {
bean.setTtsPlayDelayTimes(jsonReader.nextInt());
} else if (name.equals("isEnableService")) {
bean.setIsEnableService(jsonReader.nextBoolean());
} else if (name.equals("isEnableOnlyReceiveContacts")) {
bean.setIsEnableOnlyReceiveContacts(jsonReader.nextBoolean());
} else if (name.equals("isEnableTTS")) {
bean.setIsEnableTTS(jsonReader.nextBoolean());
} else if (name.equals("isEnableTTSRuleMode")) {
bean.setIsEnableTTSRuleMode(jsonReader.nextBoolean());
} else if (name.equals("isSMSRecycleProtectMode")) {
bean.setIsSMSRecycleProtectMode(jsonReader.nextBoolean());
} else if (name.equals("protectModerRefuseChars")) {
bean.setProtectModerRefuseChars(jsonReader.nextString());
} else if (name.equals("protectModerReplaceChars")) {
bean.setProtectModerReplaceChars(jsonReader.nextString());
} /*else if (name.equals("appThemeID")) {
bean.setAppThemeID(jsonReader.nextInt());
}*/ else {
jsonReader.skipValue();
}
}
// 结束 JSON 对象
jsonReader.endObject();
return bean;
}
}

View File

@@ -0,0 +1,88 @@
package cc.winboll.studio.mymessagemanager.beans;
/**
* @Author ZhanGSKen@QQ.COM
* @Date 2023/06/30 23:21:27
* @Describe 应用配置数据类V1 旧版。
*/
import cc.winboll.studio.mymessagemanager.utils.ThemeUtil;
public class AppConfigBean_V1 {
// 当前国家代码(如+8612345678901代码就是86.)
String countryCode = "86";
// 是否合并的手机号码前缀
boolean isMergeCountryCodePrefix = true;
// TT语音延时播放毫秒数
int ttsPlayDelayTimes = 3000;
boolean enableService = false;
boolean enableOnlyReceiveContacts = false;
boolean enableTTS = false;
boolean enableTTSRuleMode = false;
//int appThemeID = ThemeUtil.getThemeID(ThemeUtil.BaseTheme.DEFAULT);
public void setCountryCode(String countryCode) {
this.countryCode = countryCode;
}
public String getCountryCode() {
return countryCode;
}
public void setIsMergeCountryCodePrefix(boolean isMergeCountryCodePrefix) {
this.isMergeCountryCodePrefix = isMergeCountryCodePrefix;
}
public boolean isMergeCountryCodePrefix() {
return isMergeCountryCodePrefix;
}
public void setTtsPlayDelayTimes(int ttsPlayDelayTimes) {
this.ttsPlayDelayTimes = ttsPlayDelayTimes;
}
public int getTtsPlayDelayTimes() {
return ttsPlayDelayTimes;
}
public void setEnableService(boolean enableService) {
this.enableService = enableService;
}
public boolean isEnableService() {
return enableService;
}
public void setEnableOnlyReceiveContacts(boolean enableOnlyReceiveContacts) {
this.enableOnlyReceiveContacts = enableOnlyReceiveContacts;
}
public boolean isEnableOnlyReceiveContacts() {
return enableOnlyReceiveContacts;
}
public void setEnableTTS(boolean enableTTS) {
this.enableTTS = enableTTS;
}
public boolean isEnableTTS() {
return enableTTS;
}
public void setEnableTTSRuleMode(boolean enableTTSRuleMode) {
this.enableTTSRuleMode = enableTTSRuleMode;
}
public boolean isEnableTTSRuleMode() {
return enableTTSRuleMode;
}
/*public void setAppThemeID(int appThemeID) {
this.appThemeID = appThemeID;
}
public int getAppThemeID() {
return appThemeID;
}*/
}

View File

@@ -0,0 +1,29 @@
package cc.winboll.studio.mymessagemanager.beans;
public class ContractsBean {
private String mszName;
private String mszTelPhone;
public ContractsBean(String szName, String szTelPhone) {
this.mszName = szName;
this.mszTelPhone = szTelPhone;
}
public void setName(String szName) {
this.mszName = szName;
}
public String getName() {
return mszName;
}
public void setTelPhone(String szTelPhone) {
this.mszTelPhone = szTelPhone;
}
public String getTelPhone() {
return mszTelPhone;
}
}

View File

@@ -0,0 +1,53 @@
package cc.winboll.studio.mymessagemanager.beans;
/**
* @Author ZhanGSKen@QQ.COM
* @Date 2024/07/19 13:10:44
* @Describe 短信通知栏消息结构
*/
public class MessageNotificationBean {
private int messageId;
private String mszPhone;
private String mszTitle;
private String mszContent;
public MessageNotificationBean(int messageId, String mszPhone, String mszTitle, String mszContent) {
this.messageId = messageId;
this.mszPhone = mszPhone;
this.mszTitle = mszTitle;
this.mszContent = mszContent;
}
public void setMessageId(int messageId) {
this.messageId = messageId;
}
public int getMessageId() {
return messageId;
}
public void setPhone(String szPhone) {
this.mszPhone = szPhone;
}
public String getPhone() {
return mszPhone;
}
public void setTitle(String szTitle) {
this.mszTitle = szTitle;
}
public String getTitle() {
return mszTitle;
}
public void setContent(String szContent) {
this.mszContent = szContent;
}
public String getContent() {
return mszContent;
}
}

View File

@@ -0,0 +1,39 @@
package cc.winboll.studio.mymessagemanager.beans;
/**
* @Author ZhanGSKen@QQ.COM
* @Date 2024/07/19 13:10:44
* @Describe 联系人信息类
*/
public class PhoneBean {
//联系人姓名
private String mszName;
//电话号码
private String mszTelPhone;
public String getName() {
return mszName;
}
public void setName(String szName) {
this.mszName = szName;
}
public String getTelPhone() {
return mszTelPhone;
}
public void setTelPhone(String szTelPhone) {
this.mszTelPhone = szTelPhone;
}
public PhoneBean() {
}
public PhoneBean(String szName, String szTelPhone) {
this.mszName = szName;
this.mszTelPhone = szTelPhone;
}
}

View File

@@ -0,0 +1,121 @@
package cc.winboll.studio.mymessagemanager.beans;
/**
* @Author ZhanGSKen@QQ.COM
* @Date 2024/05/30 10:57:14
* @Describe 短信接收规则类
*/
import android.util.JsonReader;
import android.util.JsonWriter;
import cc.winboll.studio.shared.app.BaseBean;
import java.io.IOException;
public class SMSAcceptRuleBean extends BaseBean {
public static final String TAG = "SMSAcceptRuleBean";
// 规则类型枚举
public enum RuleType { ACCEPT, REFUSE, REGEXPPIUTILS_ISPPIOK_FALSE }
// 用户ID
int userId = -1;
// 规则数据
String ruleData = "";
// 是否启用
boolean isEnable = false;
// 规则类型
RuleType ruleType = RuleType.REFUSE;
// 是否简单视图
boolean isSimpleView = false;
public SMSAcceptRuleBean() {}
public SMSAcceptRuleBean(int userId, String ruleData, boolean isEnable, RuleType ruleType, boolean isSimpleView) {
this.userId = userId;
this.ruleData = ruleData;
this.isEnable = isEnable;
this.ruleType = ruleType;
this.isSimpleView = isSimpleView;
}
public void setRuleType(RuleType ruleType) {
this.ruleType = ruleType;
}
public RuleType getRuleType() {
return ruleType;
}
public void setIsSimpleView(boolean isSimpleView) {
this.isSimpleView = isSimpleView;
}
public boolean isSimpleView() {
return isSimpleView;
}
public void setUserId(int userID) {
this.userId = userID;
}
public int getUserId() {
return userId;
}
public void setRuleData(String ruleData) {
this.ruleData = ruleData;
}
public String getRuleData() {
return ruleData;
}
public void setIsEnable(boolean isEnable) {
this.isEnable = isEnable;
}
public boolean isEnable() {
return isEnable;
}
@Override
public String getName() {
return SMSAcceptRuleBean.class.getName();
}
@Override
public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
super.writeThisToJsonWriter(jsonWriter);
SMSAcceptRuleBean bean = this;
jsonWriter.name("userId").value(bean.getUserId());
jsonWriter.name("ruleData").value(bean.getRuleData());
jsonWriter.name("isEnable").value(bean.isEnable());
jsonWriter.name("ruleType").value(bean.getRuleType().ordinal());
jsonWriter.name("isSimpleView").value(bean.isSimpleView());
}
@Override
public BaseBean readBeanFromJsonReader(JsonReader jsonReader) throws IOException {
SMSAcceptRuleBean bean = new SMSAcceptRuleBean();
jsonReader.beginObject();
while (jsonReader.hasNext()) {
String name = jsonReader.nextName();
if (name.equals("userId")) {
bean.setUserId(jsonReader.nextInt());
} else if (name.equals("ruleData")) {
bean.setRuleData(jsonReader.nextString());
} else if (name.equals("isEnable")) {
bean.setIsEnable(jsonReader.nextBoolean());
} else if (name.equals("ruleType")) {
bean.setRuleType(RuleType.values()[jsonReader.nextInt()]);
} else if (name.equals("isSimpleView")) {
bean.setIsSimpleView(jsonReader.nextBoolean());
} else {
jsonReader.skipValue();
}
}
// 结束 JSON 对象
jsonReader.endObject();
return bean;
}
}

View File

@@ -0,0 +1,50 @@
package cc.winboll.studio.mymessagemanager.beans;
/**
* @Author ZhanGSKen@QQ.COM
* @Date 2024/05/30 10:57:14
* @Describe 短信接收规则类V1 旧版。
*/
public class SMSAcceptRuleBean_V1 {
public static final String TAG = "SMSAcceptRuleBean_V1";
// 用户ID
String userID = "";
// 规则数据
String ruleData = "";
// 是否启用
boolean enable = false;
public SMSAcceptRuleBean_V1() {}
public SMSAcceptRuleBean_V1(String userID, String ruleData, boolean enable) {
this.userID = userID;
this.ruleData = ruleData;
this.enable = enable;
}
public void setUserID(String userID) {
this.userID = userID;
}
public String getUserID() {
return userID;
}
public void setRuleData(String ruleData) {
this.ruleData = ruleData;
}
public String getRuleData() {
return ruleData;
}
public void setEnable(boolean enable) {
this.enable = enable;
}
public boolean isEnable() {
return enable;
}
}

View File

@@ -0,0 +1,272 @@
package cc.winboll.studio.mymessagemanager.beans;
/**
* @Author ZhanGSKen@QQ.COM
* @Date 2024/05/30 10:57:14
* @Describe 短信信息类
参考资料:
https://blog.csdn.net/freeking101/article/details/121575985
获取短信只需要得到 ContentResolver 就行了,它的 URI 主要有:
content://sms/ 所有短信
content://sms/inbox 收件箱
content://sms/sent 已发送
content://sms/draft 草稿
content://sms/outbox 发件箱
content://sms/failed 发送失败
content://sms/queued 待发送列表
SMS 数据库中的字段如下:
_id 一个自增字段从1开始
thread_id 序号同一发信人的id相同
address 发件人手机号码
person 联系人列表里的序号陌生人为null
date 发件日期
protocol 协议,分为: 0 SMS_RPOTO, 1 MMS_PROTO
read 是否阅读 0未读 1已读
status 状态 -1接收0 complete, 64 pending, 128 failed
type ALL = 0;INBOX = 1;SENT = 2;DRAFT = 3;OUTBOX = 4;FAILED = 5; QUEUED = 6;
body 短信内容
service_center 短信服务中心号码编号。如+8613800755500
subject 短信的主题
reply_path_present TP-Reply-Path
locked
*/
import android.content.ContentValues;
import android.util.JsonReader;
import android.util.JsonWriter;
import cc.winboll.studio.shared.app.BaseBean;
import java.io.IOException;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
public class SMSBean extends BaseBean {
//public enum Type { ALL(8), INBOX(0), SENT, DRAFT, OUTBOX, FAILED, QUEUED, TRASH }
public enum Type { ALL(0), INBOX(1), SENT(2), DRAFT(3), OUTBOX(4), FAILED(5), QUEUED(6), TRASH(7);
static String[] _mlistName = { "所有短信", "接收", "发送", "草稿", "发件箱", "发送失败", "待发送列表", "回收站" };
private int value = 0;
private Type(int value) { //必须是private的否则编译错误
this.value = value;
}
}
public enum ReadStatus { UNREAD, READ }
transient private static String _ContentValuesName_address = "address";
transient private static String _ContentValuesName_body = "body";
transient private static String _ContentValuesName_read = "read";
transient private static String _ContentValuesName_date = "date";
// 短信标识
protected int id;
// 发件人手机号码
protected String mszAddress;
// 短信内容
protected String mszBody;
// 发件日期
protected long mnDate;
// 短息归类
protected Type mType;
// 是否阅读
protected ReadStatus mReadStatus;
// 联系人列表里的序号陌生人为null
protected int mnPerson;
public SMSBean() {
this.id = -1;
this.mszAddress = "";
this.mszBody = "";
this.mnDate = 0;
this.mType = Type.INBOX;
this.mReadStatus = ReadStatus.UNREAD;
this.mnPerson = 0;
}
public SMSBean(int id, String mszAddress, String mszBody, long mnDate, Type mType, ReadStatus mReadStatus, int mnPerson) {
this.id = id;
this.mszAddress = mszAddress;
this.mszBody = mszBody;
this.mnDate = mnDate;
this.mType = mType;
this.mReadStatus = mReadStatus;
this.mnPerson = mnPerson;
}
public void setId(int id) {
this.id = id;
}
public int getId() {
return id;
}
public void setAddress(String szAddress) {
this.mszAddress = szAddress;
}
public String getAddress() {
return mszAddress;
}
public void setBody(String szBody) {
this.mszBody = szBody;
}
public String getBody() {
return mszBody;
}
public void setDate(long date) {
this.mnDate = date;
}
public long getDate() {
return mnDate;
}
public void setType(Type type) {
this.mType = type;
}
public Type getType() {
return mType;
}
public void setReadStatus(ReadStatus readStatus) {
this.mReadStatus = readStatus;
}
public ReadStatus getReadStatus() {
return mReadStatus;
}
public void setPerson(int person) {
this.mnPerson = person;
}
public int getPerson() {
return mnPerson;
}
@Override
public String getName() {
return SMSBean.class.getName();
}
@Override
public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
super.writeThisToJsonWriter(jsonWriter);
SMSBean bean = this;
jsonWriter.name("id").value(bean.getId());
jsonWriter.name("mszAddress").value(bean.getAddress());
jsonWriter.name("mszBody").value(bean.getBody());
jsonWriter.name("mnDate").value(bean.getDate());
jsonWriter.name("mType").value(bean.getType().ordinal());
jsonWriter.name("mReadStatus").value(bean.getReadStatus().ordinal());
jsonWriter.name("mnPerson").value(bean.getPerson());
}
@Override
public boolean initObjectsFromJsonReader(JsonReader jsonReader, String name) throws IOException {
if(super.initObjectsFromJsonReader(jsonReader, name)) { return true; }
else{
if (name.equals("id")) {
setId(jsonReader.nextInt());
} else if (name.equals("mszAddress")) {
setAddress(jsonReader.nextString());
} else if (name.equals("mszBody")) {
setBody(jsonReader.nextString());
} else if (name.equals("mnDate")) {
setDate(jsonReader.nextLong());
} else if (name.equals("mType")) {
setType(Type.values()[jsonReader.nextInt()]);
} else if (name.equals("mReadStatus")) {
setReadStatus(ReadStatus.values()[jsonReader.nextInt()]);
} else if (name.equals("mnPerson")) {
setPerson(jsonReader.nextInt());
} else {
return false;
}
}
return true;
}
@Override
public BaseBean readBeanFromJsonReader(JsonReader jsonReader) throws IOException {
jsonReader.beginObject();
while (jsonReader.hasNext()) {
String name = jsonReader.nextName();
if(!initObjectsFromJsonReader(jsonReader, name)) {
jsonReader.skipValue();
}
}
// 结束 JSON 对象
jsonReader.endObject();
return this;
}
public static ContentValues createOldSendedSMSContentValues(SMSBean smsBean) {
ContentValues result = new ContentValues();
result.put(_ContentValuesName_address, smsBean.mszAddress);
result.put(_ContentValuesName_body, smsBean.mszBody);
result.put(_ContentValuesName_read, smsBean.mReadStatus.toString()); //"0" for have not read sms and "1" for have read sms
result.put(_ContentValuesName_date, Long.toString(smsBean.getDate()));
return result;
}
public static ContentValues createSendedSMSContentValues(SMSBean smsBean) {
ContentValues result = new ContentValues();
result.put(_ContentValuesName_address, smsBean.mszAddress);
result.put(_ContentValuesName_body, smsBean.mszBody);
result.put(_ContentValuesName_read, smsBean.mReadStatus.toString()); //"0" for have not read sms and "1" for have read sms
result.put(_ContentValuesName_date, Long.toString(System.currentTimeMillis()));
return result;
}
public static String getTypeName(Type type) {
return Type._mlistName[type.ordinal()];
}
@Override
public String toString() {
String szResult = "\n";
szResult += "mszAddress is (" + mszAddress + ")\n";
szResult += "mszBody is (" + mszBody + ")\n";
szResult += "mnDate is (" + Long.toString(mnDate) + ")\n";
szResult += "mType is (" + mType.name() + ")\n";
if (mReadStatus != null) {
szResult += "mReadStatus is (" + mReadStatus.name() + ")\n";
}
szResult += "mnPerson is (" + Integer.toString(mnPerson) + ")\n";
return szResult;
}
public static void sortSMSByDateDesc(ArrayList<SMSBean> list, boolean isDesc) {
Collections.sort(list, new SortSMSByDateDesc(isDesc));
}
private static class SortSMSByDateDesc implements Comparator<SMSBean> {
private boolean mIsDesc = true;
// isDesc 是否降序排列
public SortSMSByDateDesc(boolean isDesc) {
mIsDesc = isDesc;
}
Collator cmp = Collator.getInstance(java.util.Locale.CHINA);
@Override
public int compare(SMSBean o1, SMSBean o2) {
boolean b0_1 = (o1.getDate() < o2.getDate());
if (mIsDesc) {
return b0_1 ?1: -1;
} else {
return b0_1 ?-1: 1;
}
}
}
}

View File

@@ -0,0 +1,127 @@
package cc.winboll.studio.mymessagemanager.beans;
/**
* @Author ZhanGSKen@QQ.COM
* @Date 2024/07/20 01:51:44
* @Describe 回收站短信存储类
*/
import android.util.JsonReader;
import android.util.JsonWriter;
import cc.winboll.studio.shared.app.BaseBean;
import java.io.IOException;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
public class SMSRecycleBean extends SMSBean {
public static final String TAG = "SMSRecycleBean";
// 短信删除日期
long deleteDate;
// 当前是否是简单视图
boolean isSimpleView;
public void setDeleteDate(long deleteDate) {
this.deleteDate = deleteDate;
}
public long getDeleteDate() {
return deleteDate;
}
public void setIsSimpleView(boolean isSimpleView) {
this.isSimpleView = isSimpleView;
}
public boolean isSimpleView() {
return isSimpleView;
}
public SMSRecycleBean() {
}
public SMSRecycleBean(SMSBean smsBean, long deleteDate) {
super.id = smsBean.getId();
super.mszAddress = smsBean.getAddress();
super.mszBody = smsBean.getBody();
super.mnDate = smsBean.getDate();
super.mType = smsBean.getType();
super.mReadStatus = smsBean.getReadStatus();
super.mnPerson = smsBean.getPerson();
this.deleteDate = deleteDate;
this.isSimpleView = true;
}
@Override
public String getName() {
return SMSRecycleBean.class.getName();
}
@Override
public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
super.writeThisToJsonWriter(jsonWriter);
SMSRecycleBean bean = this;
jsonWriter.name("deleteDate").value(bean.getDeleteDate());
jsonWriter.name("isSimpleView").value(bean.isSimpleView());
}
@Override
public BaseBean readBeanFromJsonReader(JsonReader jsonReader) throws IOException {
/*SMSRecycleBean bean = new SMSRecycleBean((SMSBean)super.readBeanFromJsonReader(jsonReader), 0);
// 只有在读取完成后才能获取整个JSON字符串
String completeJson = jsonReader.toString();
JsonReader newJsonReader = new JsonReader(new StringReader(completeJson));
newJsonReader.setLenient(true);
LogUtils.d(TAG, completeJson);*/
jsonReader.beginObject();
while (jsonReader.hasNext()) {
String name = jsonReader.nextName();
if (!initObjectsFromJsonReader(jsonReader, name)) {
jsonReader.skipValue();
}
}
// 结束 JSON 对象
jsonReader.endObject();
return this;
}
@Override
public boolean initObjectsFromJsonReader(JsonReader jsonReader, String name) throws IOException {
if(super.initObjectsFromJsonReader(jsonReader, name)) { return true; }
else{
if (name.equals("deleteDate")) {
setDeleteDate(jsonReader.nextLong());
} else if (name.equals("isSimpleView")) {
setIsSimpleView(jsonReader.nextBoolean());
} else {
return false;
}
}
return true;
}
public static void sortSMSByDeleteDateDesc(ArrayList<SMSRecycleBean> list, boolean isDesc) {
Collections.sort(list, new SortSMSByDeleteDateDesc(isDesc));
}
private static class SortSMSByDeleteDateDesc implements Comparator<SMSRecycleBean> {
private boolean mIsDesc = true;
// isDesc 是否降序排列
public SortSMSByDeleteDateDesc(boolean isDesc) {
mIsDesc = isDesc;
}
Collator cmp = Collator.getInstance(java.util.Locale.CHINA);
@Override
public int compare(SMSRecycleBean o1, SMSRecycleBean o2) {
boolean b0_1 = (o1.getDeleteDate() < o2.getDeleteDate());
if (mIsDesc) {
return b0_1 ?1: -1;
} else {
return b0_1 ?-1: 1;
}
}
}
}

View File

@@ -0,0 +1,147 @@
package cc.winboll.studio.mymessagemanager.beans;
/**
* @Author ZhanGSKen@QQ.COM
* @Date 2024/05/28 20:22:12
* @Describe TTS 语音播放规则类
*/
import android.util.JsonReader;
import android.util.JsonWriter;
import cc.winboll.studio.shared.app.BaseBean;
import java.io.IOException;
public class TTSPlayRuleBean extends BaseBean {
public static final String TAG = "TTSPlayRuleBean";
// 用户ID
int userId = -1;
// TTS语音规则名称
String ruleName = "";
// 短信测试文本
String demoSMSText = "";
// 短信内容查询正则文本
String patternText = "";
// TTS语音播报正则文本
String ttsRuleText = "";
// 是否启用简单视图
boolean isSimpleView = false;
// 是否启用规则
boolean isEnable = false;
public TTSPlayRuleBean() {}
public TTSPlayRuleBean(int userId, String ruleName, String demoSMSText, String patternText, String ttsRuleText, boolean isSimpleView, boolean isEnable) {
this.userId = userId;
this.ruleName = ruleName;
this.demoSMSText = demoSMSText;
this.patternText = patternText;
this.ttsRuleText = ttsRuleText;
this.isSimpleView = isSimpleView;
this.isEnable = isEnable;
}
public void setUserId(int userId) {
this.userId = userId;
}
public int getUserId() {
return userId;
}
public void setRuleName(String ruleName) {
this.ruleName = ruleName;
}
public String getRuleName() {
return ruleName;
}
public void setDemoSMSText(String demoSMSText) {
this.demoSMSText = demoSMSText;
}
public String getDemoSMSText() {
return demoSMSText;
}
public void setPatternText(String patternText) {
this.patternText = patternText;
}
public String getPatternText() {
return patternText;
}
public void setTtsRuleText(String ttsRuleText) {
this.ttsRuleText = ttsRuleText;
}
public String getTtsRuleText() {
return ttsRuleText;
}
public void setIsSimpleView(boolean isSimpleView) {
this.isSimpleView = isSimpleView;
}
public boolean isSimpleView() {
return isSimpleView;
}
public void setIsEnable(boolean isEnable) {
this.isEnable = isEnable;
}
public boolean isEnable() {
return isEnable;
}
@Override
public String getName() {
return TTSPlayRuleBean.class.getName();
}
@Override
public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
super.writeThisToJsonWriter(jsonWriter);
TTSPlayRuleBean bean = this;
jsonWriter.name("userId").value(bean.userId);
jsonWriter.name("ruleName").value(bean.ruleName);
jsonWriter.name("demoSMSText").value(bean.demoSMSText);
jsonWriter.name("patternText").value(bean.patternText);
jsonWriter.name("ttdRuleText").value(bean.ttsRuleText);
jsonWriter.name("isSimpleView").value(bean.isSimpleView);
jsonWriter.name("isEnable").value(bean.isEnable);
}
@Override
public BaseBean readBeanFromJsonReader(JsonReader jsonReader) throws IOException {
TTSPlayRuleBean bean = new TTSPlayRuleBean();
jsonReader.beginObject();
while (jsonReader.hasNext()) {
String name = jsonReader.nextName();
if (name.equals("userId")) {
bean.setUserId(jsonReader.nextInt());
} else if (name.equals("ruleName")) {
bean.setRuleName(jsonReader.nextString());
} else if (name.equals("demoSMSText")) {
bean.setDemoSMSText(jsonReader.nextString());
} else if (name.equals("patternText")) {
bean.setPatternText(jsonReader.nextString());
} else if (name.equals("ttdRuleText")) {
bean.setTtsRuleText(jsonReader.nextString());
} else if (name.equals("isSimpleView")) {
bean.setIsSimpleView(jsonReader.nextBoolean());
} else if (name.equals("isEnable")) {
bean.setIsEnable(jsonReader.nextBoolean());
} else {
jsonReader.skipValue();
}
}
// 结束 JSON 对象
jsonReader.endObject();
return bean;
}
}

View File

@@ -0,0 +1,281 @@
package cc.winboll.studio.mymessagemanager.beans;
/**
* @Author ZhanGSKen@QQ.COM
* @Date 2024/05/28 20:22:12
* @Describe TTS 语音播放规则类V1 旧版。
*/
import android.content.Context;
import android.util.JsonReader;
import android.util.JsonWriter;
import cc.winboll.studio.mymessagemanager.utils.FileUtil;
import cc.winboll.studio.shared.log.LogUtils;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.ArrayList;
public class TTSPlayRuleBean_V1 {
public static final String TAG = "TTSPlayRuleBean2";
// 用户ID
int userId = -1;
// TTS语音规则名称
String ruleName = "";
// 短信测试文本
String demoSMSText = "";
// 短信内容查询正则文本
String patternText = "";
// TTS语音播报正则文本
String ttsRuleText = "";
// 是否启用简单视图
boolean isSimpleView = false;
// 是否启用规则
boolean isEnable = false;
public TTSPlayRuleBean_V1(int userId, String ruleName, String demoSMSText, String patternText, String ttsRuleText, boolean isSimpleView, boolean isEnable) {
this.userId = userId;
this.ruleName = ruleName;
this.demoSMSText = demoSMSText;
this.patternText = patternText;
this.ttsRuleText = ttsRuleText;
this.isSimpleView = isSimpleView;
this.isEnable = isEnable;
}
public TTSPlayRuleBean_V1() {}
public void setRuleName(String ruleName) {
this.ruleName = ruleName;
}
public String getRuleName() {
return ruleName;
}
public void setUserId(int userId) {
this.userId = userId;
}
public int getUserId() {
return userId;
}
public void setDemoSMSText(String demoSMSText) {
this.demoSMSText = demoSMSText;
}
public String getDemoSMSText() {
return demoSMSText;
}
public void setPatternText(String patternText) {
this.patternText = patternText;
}
public String getPatternText() {
return patternText;
}
public void setTtsRuleText(String ttsRuleText) {
this.ttsRuleText = ttsRuleText;
}
public String getTtsRuleText() {
return ttsRuleText;
}
public void setIsSimpleView(boolean isSimpleView) {
this.isSimpleView = isSimpleView;
}
public boolean isSimpleView() {
return isSimpleView;
}
public void setIsEnable(boolean isEnable) {
this.isEnable = isEnable;
}
public boolean isEnable() {
return isEnable;
}
static String getBeanJsonFilePath(Context context) {
return context.getExternalFilesDir(TAG) + "/" + TAG + ".json";
}
static String getBeanListJsonFilePath(Context context) {
return context.getExternalFilesDir(TAG) + "/" + TAG + "_List.json";
}
static void writeBean(JsonWriter writer, TTSPlayRuleBean_V1 bean) throws IOException {
// 开始 JSON 对象
writer.beginObject();
// 写入键值对
writer.name("userId").value(bean.userId);
writer.name("ruleName").value(bean.ruleName);
writer.name("demoSMSText").value(bean.demoSMSText);
writer.name("patternText").value(bean.patternText);
writer.name("ttdRuleText").value(bean.ttsRuleText);
writer.name("isSimpleView").value(bean.isSimpleView);
writer.name("isEnable").value(bean.isEnable);
// 结束 JSON 对象
writer.endObject();
}
static TTSPlayRuleBean_V1 parseBean(JsonReader jsonReader) {
try {
TTSPlayRuleBean_V1 bean = new TTSPlayRuleBean_V1();
// 开始 JSON 对象
jsonReader.beginObject();
// 写入键值对
while (jsonReader.hasNext()) {
String name = jsonReader.nextName();
if (name.equals("ruleName")) {
bean.setRuleName(jsonReader.nextString());
} else if (name.equals("userId")) {
bean.setUserId(jsonReader.nextInt());
} else if (name.equals("demoSMSText")) {
bean.setDemoSMSText(jsonReader.nextString());
} else if (name.equals("patternText")) {
bean.setPatternText(jsonReader.nextString());
} else if (name.equals("ttdRuleText")) {
bean.setTtsRuleText(jsonReader.nextString());
} else if (name.equals("isSimpleView")) {
bean.setIsSimpleView(jsonReader.nextBoolean());
} else if (name.equals("isEnable")) {
bean.setIsEnable(jsonReader.nextBoolean());
} else {
jsonReader.skipValue();
}
}
// 结束 JSON 对象
jsonReader.endObject();
return bean;
} catch (IOException e) {
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
}
return null;
}
static ArrayList<TTSPlayRuleBean_V1> parseBeanList(String beanList) {
try {
StringReader stringReader = new StringReader(beanList);
JsonReader jsonReader = new JsonReader(stringReader);
ArrayList<TTSPlayRuleBean_V1> list = new ArrayList<TTSPlayRuleBean_V1>();
jsonReader.beginArray();
while (jsonReader.hasNext()) {
TTSPlayRuleBean_V1 bean = parseBean(jsonReader);
if (bean != null) {
list.add(bean);
}
}
jsonReader.endArray();
return list;
} catch (IOException e) {
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
}
return null;
}
@Override
public String toString() {
// 创建 JsonWriter 对象
StringWriter stringWriter = new StringWriter();
JsonWriter jsonWriter = new JsonWriter(stringWriter);
jsonWriter.setIndent(" ");
try {
writeBean(jsonWriter, this);
return stringWriter.toString();
} catch (IOException e) {
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
}
// 获取 JSON 字符串
return "";
}
public static String toStringByBeanList(ArrayList<TTSPlayRuleBean_V1> beanList) {
try {
StringWriter stringWriter = new StringWriter();
JsonWriter writer = new JsonWriter(stringWriter);
writer.setIndent(" ");
writer.beginArray();
for (TTSPlayRuleBean_V1 bean : beanList) {
writeBean(writer, bean);
}
writer.endArray();
writer.close();
return stringWriter.toString();
} catch (IOException e) {
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
}
return "";
}
public static TTSPlayRuleBean_V1 parseBean(String szBean) {
// 创建 JsonWriter 对象
StringReader stringReader = new StringReader(szBean);
JsonReader jsonReader = new JsonReader(stringReader);
return parseBean(jsonReader);
}
/*public static TTSPlayRuleBean_V1 loadBean(Context context) {
return loadBeanFromFile(getBeanJsonFilePath(context));
}
public static TTSPlayRuleBean_V1 loadBeanFromFile(String szFilePath) {
TTSPlayRuleBean_V1 bean = null;
try {
String szJson = FileUtil.readFile(szFilePath);
bean = TTSPlayRuleBean_V1.parseBean(szJson);
} catch (IOException e) {
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
}
return bean;
}
public static void saveBean(Context context, TTSPlayRuleBean_V1 bean) {
saveBeanToFile(getBeanJsonFilePath(context), bean);
}
public static void saveBeanToFile(String szFilePath, TTSPlayRuleBean_V1 bean) {
try {
String szJson = bean.toString();
FileUtil.writeFile(szFilePath, szJson);
} catch (IOException e) {
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
}
}
public static ArrayList<TTSPlayRuleBean_V1> loadBeanList(Context context) {
return loadBeanListFromFile(getBeanListJsonFilePath(context));
}*/
public static ArrayList<TTSPlayRuleBean_V1> loadBeanListFromFile(String szFilePath) {
ArrayList<TTSPlayRuleBean_V1> beanList = null;
try {
String szListJson = FileUtil.readFile(szFilePath);
beanList = TTSPlayRuleBean_V1.parseBeanList(szListJson);
} catch (IOException e) {
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
}
return beanList;
}
/*public static boolean saveBeanList(Context context, ArrayList<TTSPlayRuleBean_V1> beanList) {
return saveBeanListToFile(getBeanListJsonFilePath(context), beanList);
}
public static boolean saveBeanListToFile(String szFilePath, ArrayList<TTSPlayRuleBean_V1> beanList) {
try {
String szJson = TTSPlayRuleBean_V1.toStringByBeanList(beanList);
FileUtil.writeFile(szFilePath, szJson);
return true;
} catch (IOException e) {
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
}
return false;
}*/
}

View File

@@ -0,0 +1,24 @@
package cc.winboll.studio.mymessagemanager.beans;
/**
* @Author ZhanGSKen@QQ.COM
* @Date 2024/05/28 20:22:12
* @Describe TTS 语音播放文本内容类
*/
import java.io.Serializable;
public class TTSSpeakTextBean implements Serializable {
transient public static final String TAG = "TTSSpeakTextBean";
// 延迟播放
public int mnDelay = 0;
// 语音播放内容
public String mszSpeakContent = "";
public TTSSpeakTextBean(int nDelay, String szSpeakContent) {
this.mnDelay = nDelay;
this.mszSpeakContent = szSpeakContent;
}
}

Some files were not shown because too many files have changed in this diff Show More