Compare commits

...

17 Commits

Author SHA1 Message Date
ZhanGSKen
580db768cb 设置与应用级别与入口级别概念。在附加组件添加与删除时,就是应用入口的添加与删除问题。应用组件根据应用级别来组合,应用视图元素根据应用入口级别来组合。 2025-11-15 16:59:56 +08:00
8a4aea7464 <positions>APK 15.11.1 release Publish. 2025-11-13 16:25:51 +08:00
ZhanGSKen
5fa241fa64 添加Json 数据文件接收功能。 2025-11-13 16:24:20 +08:00
2e6dc5ead2 <positions>APK 15.11.0 release Publish. 2025-11-13 14:05:41 +08:00
ZhanGSKen
a1ec3cd4c1 ## @豆包
## 提问豆包:现在开发的这个安卓应用是关于位置的应用,它的功能是根据定点位置信息与当前GPS位置信息的距离计算结果多少,来判断设定的距离任务是否达到指定长度区间,从而触发通知任务。当前应用的命名为“悟空笔记”,应用有另一个应用级别的Plus组件,Plus组件在“悟空应用”基础上添加了一些附加组件的开发,附加组件添加的原则是不影响原有的应用主题风格下进行视图组件添加,以便应用模式切换时,应用的通用习惯不会有太大误差,只保持组件添加与删除的应用操作感。现在遇到一个组件命名的问题。“悟空笔记”概念是用户在使用时重点关注点在空间上,笔记就是形容用户在定制距离提醒任务。现在附加组件的开发方向是要添加一个定时器组件,定时器用于设置某一个时间点之后的周期定时提醒任务,添加一个着重于关于时间的组件。这个组件要怎样命名才会显示出当前应用与组件组合之后整体应用范围。

## 豆包说:
结合“悟空笔记”的**空间(位置)+ 笔记(任务)核心定位,以及新增时间(定时)**组件的功能,可采用“空间+时间”联动的命名逻辑,既保留原应用的“悟空”品牌识别,又突出组件的时间属性,同时贴合“笔记/任务”的产品调性:
 
推荐命名方案
 
1. 组件名称(内部类/模块名)
 
 WukongTimeNote 
 
- 解析:
-  Wukong :延续原应用品牌,保持统一性;
-  Time :直接体现“时间(定时)”组件的核心属性;
-  Note :呼应原应用“笔记(任务)”的概念,强化“时间类任务”的定位。
 
2. 组件展示名称(UI/用户可见)
 
“悟空时记”
 
- 解析:
- “悟空”:保留原应用的品牌记忆;
- “时记”:对应“时间+笔记”,既体现定时功能,又延续“笔记(任务)”的产品语境;
- 风格匹配:与“悟空笔记”的四字结构一致,用户认知成本低,同时区分“空间任务”与“时间任务”的功能边界。
 
配套组合逻辑
 
- 应用模式切换时,可将功能区分为:
- “空间笔记”:原位置距离任务(对应原“悟空笔记”核心功能);
- “时记任务”:新增定时周期任务(对应 WukongTimeNote 组件);
- 整体应用范围可描述为:“悟空笔记·时空任务”(覆盖“空间+时间”双维度任务管理)。
 
此命名既保持了原应用的风格统一性,又清晰传递了组件的“时间+任务”属性,同时让用户感知到应用从“空间单一维度”扩展到“时空双维度”的功能升级。
2025-11-13 14:01:18 +08:00
ZhanGSKen
1896b72469 应用模式切换功能完成。 2025-11-13 08:44:34 +08:00
ZhanGSKen
80a83cba4c 编译配置文件修复 2025-11-13 08:00:16 +08:00
ZhanGSKen
d73824007e 字符串资源清理和校正 2025-11-13 07:50:39 +08:00
ZhanGSKen
a4409c96d5 配置应用图标菜单字符串资源 2025-11-13 07:41:00 +08:00
ZhanGSKen
cc3ec5022a 设置编译应用目标版本 2025-11-13 07:37:03 +08:00
ZhanGSKen
53271b21cf 20251110_205526_555 2025-11-10 20:55:31 +08:00
ZhanGSKen
17d2422690 添加应用图标切换初稿 2025-11-10 11:43:26 +08:00
ZhanGSKen
55d72c3f82 在位置任务数据项里,添加普通沙漏模拟控件雏形,沙漏控件用于任务定时触发场景。 2025-11-10 08:59:33 +08:00
ZhanGSKen
74f685e07d 关闭应用启动时的应用级别提示 2025-11-10 08:05:07 +08:00
ZhanGSKen
e3826148fa 添加新的应用级别入口 2025-11-10 08:02:57 +08:00
ZhanGSKen
bf52f86b3d 优化运动状态检测模块,运动状态检测阈值标准未测定。 2025-11-05 16:50:05 +08:00
ZhanGSKen
566e84f53f 基本完成传感器陀螺仪启动,与接收器接收功能。 2025-11-04 20:56:31 +08:00
32 changed files with 2258 additions and 404 deletions

View File

@@ -18,18 +18,21 @@ def genVersionName(def versionName){
} }
android { android {
compileSdkVersion 32 // 1. compileSdkVersion:必须 ≥ targetSdkVersion建议直接等于 targetSdkVersion30
buildToolsVersion "32.0.0" compileSdkVersion 30
// 2. buildToolsVersion需匹配 compileSdkVersion建议使用 30.x.x 最新稳定版(无需高于 compileSdkVersion
buildToolsVersion "30.0.3" // 这是 30 对应的最新稳定版,避免使用 beta 版
defaultConfig { defaultConfig {
applicationId "cc.winboll.studio.positions" applicationId "cc.winboll.studio.positions"
minSdkVersion 24 minSdkVersion 23
targetSdkVersion 30 targetSdkVersion 30
versionCode 1 versionCode 1
// versionName 更新后需要手动设置 // versionName 更新后需要手动设置
// .winboll/winbollBuildProps.properties 文件的 stageCount=0 // .winboll/winbollBuildProps.properties 文件的 stageCount=0
// Gradle编译环境下合起来的 versionName 就是 "${versionName}.0" // Gradle编译环境下合起来的 versionName 就是 "${versionName}.0"
versionName "15.0" versionName "15.11"
if(true) { if(true) {
versionName = genVersionName("${versionName}") versionName = genVersionName("${versionName}")
} }
@@ -44,8 +47,6 @@ android {
} }
dependencies { dependencies {
api fileTree(dir: 'libs', include: ['*.jar'])
// https://mvnrepository.com/artifact/com.jzxiang.pickerview/TimePickerDialog // https://mvnrepository.com/artifact/com.jzxiang.pickerview/TimePickerDialog
api 'com.jzxiang.pickerview:TimePickerDialog:1.0.1' api 'com.jzxiang.pickerview:TimePickerDialog:1.0.1'
@@ -61,8 +62,6 @@ dependencies {
api 'com.journeyapps:zxing-android-embedded:3.6.0' api 'com.journeyapps:zxing-android-embedded:3.6.0'
// 应用介绍页类库 // 应用介绍页类库
api 'io.github.medyo:android-about-page:2.0.0' api 'io.github.medyo:android-about-page:2.0.0'
// 吐司类库
//api 'com.github.getActivity:ToastUtils:10.5'
// 网络连接类库 // 网络连接类库
api 'com.squareup.okhttp3:okhttp:4.4.1' api 'com.squareup.okhttp3:okhttp:4.4.1'
// AndroidX 类库 // AndroidX 类库
@@ -73,7 +72,7 @@ dependencies {
//api 'androidx.vectordrawable:vectordrawable-animated:1.1.0' //api 'androidx.vectordrawable:vectordrawable-animated:1.1.0'
//api 'androidx.fragment:fragment:1.1.0' //api 'androidx.fragment:fragment:1.1.0'
api 'cc.winboll.studio:libaes:15.10.2' api 'cc.winboll.studio:libaes:15.11.0'
api 'cc.winboll.studio:libapputils:15.10.2' api 'cc.winboll.studio:libappbase:15.11.0'
api 'cc.winboll.studio:libappbase:15.10.9' api fileTree(dir: 'libs', include: ['*.jar'])
} }

View File

@@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle #Created by .winboll/winboll_app_build.gradle
#Tue Oct 28 20:03:59 HKT 2025 #Sat Nov 15 08:45:48 GMT 2025
stageCount=18 stageCount=2
libraryProject= libraryProject=
baseVersion=15.0 baseVersion=15.11
publishVersion=15.0.17 publishVersion=15.11.1
buildCount=0 buildCount=21
baseBetaVersion=15.0.18 baseBetaVersion=15.11.2

View File

@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string name="app_name">悟空笔记#</string> <string name="app_name">悟空笔记#</string>
<string name="appplus_name">时空任务#</string>
</resources> </resources>

View File

@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string name="app_name">Positions +</string> <string name="app_name">Positions</string>
<string name="appplus_name">PositionsPlus+</string>
</resources> </resources>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 切换启动入口的快捷菜单 -->
<shortcut
android:shortcutId="open_appplus"
android:enabled="true"
android:icon="@mipmap/ic_launcher"
android:shortcutShortLabel="@string/open_appplus"
android:shortcutLongLabel="@string/open_appplus"
android:shortcutDisabledMessage="@string/appplus_open_disabled">
<intent
android:action="cc.winboll.studio.positions.App.ACTION_OPEN_APPPLUS"
android:targetPackage="cc.winboll.studio.positions.beta"
android:targetClass="cc.winboll.studio.positions.activities.ShortcutActionActivity"
android:data="open_appplus" />
<categories android:name="android.shortcut.conversation" />
</shortcut>
</shortcuts>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 切换启动入口的快捷菜单 -->
<shortcut
android:shortcutId="close_appplus"
android:enabled="true"
android:icon="@mipmap/ic_launcher"
android:shortcutShortLabel="@string/close_appplus"
android:shortcutLongLabel="@string/close_appplus"
android:shortcutDisabledMessage="@string/appplus_close_disabled">
<intent
android:action="cc.winboll.studio.positions.App.ACTION_CLOSE_APPPLUS"
android:targetPackage="cc.winboll.studio.positions.beta"
android:targetClass="cc.winboll.studio.positions.activities.ShortcutActionActivity"
android:data="close_appplus" />
<categories android:name="android.shortcut.conversation" />
</shortcut>
</shortcuts>

View File

@@ -3,23 +3,32 @@
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
package="cc.winboll.studio.positions"> package="cc.winboll.studio.positions">
<!-- 1. 声明GPS权限 -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- 前台服务权限(可选,提升后台定位稳定性,避免服务被回收) -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<!-- 只能在前台获取精确的位置信息 --> <!-- 只能在前台获取精确的位置信息 -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<!-- 只有在前台运行时才能获取大致位置信息 --> <!-- 只有在前台运行时才能获取大致位置信息 -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<!-- 在后台使用位置信息 -->
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
<!-- 运行前台服务 -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<!-- 运行“location”类型的前台服务 -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION"/>
<!-- 拥有完全的网络访问权限 --> <!-- 拥有完全的网络访问权限 -->
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
<!-- 在后台使用位置信息 --> <!-- 安装快捷方式 -->
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/> <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
<!-- 读取您共享存储空间中的内容 -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<!-- 修改或删除您共享存储空间中的内容 -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-feature <uses-feature
android:name="android.hardware.location.gps" android:name="android.hardware.location.gps"
@@ -35,7 +44,36 @@
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:label="@string/app_name"> android:label="@string/app_name"
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=".activities.CrashActivity"/>
<activity-alias
android:name=".MainActivityWukong"
android:targetActivity=".MainActivity"
android:exported="true"
android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
android:enabled="true">
<intent-filter> <intent-filter>
@@ -45,36 +83,80 @@
</intent-filter> </intent-filter>
</activity> <meta-data
android:name="android.app.shortcuts"
android:resource="@xml/shortcutsmain"/>
</activity-alias>
<activity-alias
android:name=".MainActivityLaojun"
android:targetActivity=".MainActivity"
android:exported="true"
android:label="@string/appplus_name"
android:icon="@drawable/ic_positions_plus"
android:enabled="false">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/shortcutsplus"/>
</activity-alias>
<meta-data <meta-data
android:name="android.max_aspect" android:name="android.max_aspect"
android:value="4.0"/> android:value="4.0"/>
<activity android:name=".GlobalApplication$CrashActivity"/>
<activity android:name="cc.winboll.studio.positions.activities.LocationActivity"/> <activity android:name="cc.winboll.studio.positions.activities.LocationActivity"/>
<meta-data <meta-data
android:name="com.google.android.gms.version" android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/> android:value="@integer/google_play_services_version"/>
<service android:name=".services.MainService"/> <service
android:name=".services.MainService"
android:exported="false"/>
<service android:name=".services.AssistantService"/> <service
android:name=".services.AssistantService"
android:exported="false"/>
<service android:name=".services.DistanceRefreshService"/> <service
android:name=".services.DistanceRefreshService"
android:exported="false"/>
<receiver android:name="cc.winboll.studio.positions.receivers.MotionStatusReceiver">
<intent-filter>
<action android:name="cc.winboll.studio.positions.receivers.MotionStatusReceiver"/>
</intent-filter>
</receiver>
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"/>
</provider>
<activity android:name="cc.winboll.studio.positions.activities.ShortcutActionActivity"/>
<!-- 2. 注册运动状态Receiver -->
<receiver
android:name="cc.winboll.studio.positions.receivers.MotionStatusReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="cc.winboll.studio.positions.ACTION_MOTION_STATUS" />
</intent-filter>
</receiver>
</application> </application>
</manifest> </manifest>

View File

@@ -14,7 +14,6 @@ import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.Gravity;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.ViewGroup; import android.view.ViewGroup;
@@ -25,6 +24,7 @@ import android.widget.Toast;
import cc.winboll.studio.libaes.utils.WinBoLLActivityManager; import cc.winboll.studio.libaes.utils.WinBoLLActivityManager;
import cc.winboll.studio.libappbase.GlobalApplication; import cc.winboll.studio.libappbase.GlobalApplication;
import cc.winboll.studio.libappbase.ToastUtils; import cc.winboll.studio.libappbase.ToastUtils;
import cc.winboll.studio.positions.utils.MyActivityLifecycleCallbacks;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.Closeable; import java.io.Closeable;
@@ -44,24 +44,36 @@ import java.util.concurrent.atomic.AtomicBoolean;
public class App extends GlobalApplication { public class App extends GlobalApplication {
public static volatile AppLevel _mAppLevel = AppLevel.WUKONG;
public static final String COMPONENT_WUKONG = "cc.winboll.studio.positions.MainActivityWukong";
public static final String COMPONENT_LAOJUN = "cc.winboll.studio.positions.MainActivityLaojun";
public static final String ACTION_OPEN_APPPLUS = "cc.winboll.studio.positions.App.ACTION_OPEN_APPPLUS";
public static final String ACTION_CLOSE_APPPLUS = "cc.winboll.studio.positions.App.ACTION_CLOSE_APPPLUS";
private static Handler MAIN_HANDLER = new Handler(Looper.getMainLooper()); private static Handler MAIN_HANDLER = new Handler(Looper.getMainLooper());
MyActivityLifecycleCallbacks mMyActivityLifecycleCallbacks;
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
setIsDebuging(BuildConfig.DEBUG);
setIsDebugging(BuildConfig.DEBUG);
WinBoLLActivityManager.init(this); WinBoLLActivityManager.init(this);
// 初始化 Toast 框架 // 初始化 Toast 框架
ToastUtils.init(this); ToastUtils.init(this);
// 设置 Toast 布局样式 // 设置 Toast 布局样式
//ToastUtils.setView(R.layout.view_toast); //ToastUtils.setView(R.layout.view_toast);
//ToastUtils.setStyle(new WhiteToastStyle()); //ToastUtils.setStyle(new WhiteToastStyle());
//ToastUtils.setGravity(Gravity.BOTTOM, 0, 200); //ToastUtils.setGravity(Gravity.BOTTOM, 0, 200);
//CrashHandler.getInstance().registerGlobal(this); //CrashHandler.getInstance().registerGlobal(this);
//CrashHandler.getInstance().registerPart(this); //CrashHandler.getInstance().registerPart(this);
mMyActivityLifecycleCallbacks = new MyActivityLifecycleCallbacks();
registerActivityLifecycleCallbacks(mMyActivityLifecycleCallbacks);
} }
public static void write(InputStream input, OutputStream output) throws IOException { public static void write(InputStream input, OutputStream output) throws IOException {

View File

@@ -0,0 +1,43 @@
package cc.winboll.studio.positions;
/**
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
* @Date 2025/11/10 07:23
* @Describe 应用级别类型枚举
*/
public enum AppLevel {
WUKONG("wukong", "悟空级别"),
LAOJUN("laojun", "老君级别");
public static final String TAG = "AppLevel";
// 枚举属性
private final String code; // 编码(如 "wukong"
private final String desc; // 描述
// 构造方法Java 7 需显式定义)
AppLevel(String code, String desc) {
this.code = code;
this.desc = desc;
}
// Getter 方法(获取枚举属性)
public String getCode() {
return code;
}
public String getDesc() {
return desc;
}
// 可选:根据 code 获取枚举项(便于业务使用)
public static AppLevel getByCode(String code) {
for (AppLevel level : values()) {
if (level.code.equals(code)) {
return level;
}
}
return null; // 或抛出异常,根据业务需求调整
}
}

View File

@@ -6,6 +6,7 @@ import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.CompoundButton; import android.widget.CompoundButton;
@@ -17,10 +18,12 @@ import androidx.core.content.ContextCompat;
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity; import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
import cc.winboll.studio.libaes.utils.WinBoLLActivityManager; import cc.winboll.studio.libaes.utils.WinBoLLActivityManager;
import cc.winboll.studio.libappbase.LogUtils; import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.libappbase.ToastUtils;
import cc.winboll.studio.positions.activities.LocationActivity; import cc.winboll.studio.positions.activities.LocationActivity;
import cc.winboll.studio.positions.activities.WinBoLLActivity; import cc.winboll.studio.positions.activities.WinBoLLActivity;
import cc.winboll.studio.positions.services.MainService; import cc.winboll.studio.positions.utils.APPPlusUtils;
import cc.winboll.studio.positions.utils.AppConfigsUtil; import cc.winboll.studio.positions.utils.AppConfigsUtil;
import cc.winboll.studio.positions.utils.JsonShareHandler;
import cc.winboll.studio.positions.utils.ServiceUtil; import cc.winboll.studio.positions.utils.ServiceUtil;
/** /**
@@ -31,17 +34,18 @@ import cc.winboll.studio.positions.utils.ServiceUtil;
*/ */
public class MainActivity extends WinBoLLActivity implements IWinBoLLActivity { public class MainActivity extends WinBoLLActivity implements IWinBoLLActivity {
public static final String TAG = "MainActivity"; public static final String TAG = "MainActivity";
// 权限请求码(建议定义为类常量,避免魔法值)
// 权限请求码(建议定义为类常量,避免魔法值)
private static final int REQUEST_LOCATION_PERMISSIONS = 1001; private static final int REQUEST_LOCATION_PERMISSIONS = 1001;
private static final int REQUEST_BACKGROUND_LOCATION_PERMISSION = 1002; private static final int REQUEST_BACKGROUND_LOCATION_PERMISSION = 1002;
// UI 控件:服务控制开关、顶部工具栏 // UI 控件:服务控制开关、顶部工具栏
private Switch mServiceSwitch; private Switch mServiceSwitch;
private Button mManagePositionsButton; private Button mManagePositionsButton;
private Toolbar mToolbar; private Toolbar mToolbar;
// 服务相关:服务实例、绑定状态标记 // 服务相关:服务实例、绑定状态标记
//private DistanceRefreshService mDistanceService; //private DistanceRefreshService mDistanceService;
private boolean isServiceBound = false; //private boolean isServiceBound = false;
@Override @Override
@@ -83,6 +87,10 @@ public class MainActivity extends WinBoLLActivity implements IWinBoLLActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); // 关联主页面布局 setContentView(R.layout.activity_main); // 关联主页面布局
// 处理启动时的分享 Intent
handleShareIntent(getIntent());
// 1. 初始化顶部 Toolbar保留原逻辑设置页面标题 // 1. 初始化顶部 Toolbar保留原逻辑设置页面标题
initToolbar(); initToolbar();
// 2. 初始化其他控件 // 2. 初始化其他控件
@@ -95,6 +103,31 @@ public class MainActivity extends WinBoLLActivity implements IWinBoLLActivity {
//bindDistanceService(); //bindDistanceService();
} }
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
// 处理后续接收的分享 Intent如应用已在后台
handleShareIntent(intent);
}
private void handleShareIntent(Intent intent) {
if (intent != null && Intent.ACTION_SEND.equals(intent.getAction())) {
// 调用工具类,弹出确认对话框
JsonShareHandler.handleSharedJsonWithConfirm(this, intent, new JsonShareHandler.ConfirmCallback() {
@Override
public void onConfirm(boolean isConfirm) {
// 回调处理isConfirm 为 true 表示接收并保存false 表示取消
if (!isConfirm) {
Log.d("MainActivity", "用户取消接收文件");
// 可添加取消后的逻辑(如关闭页面)
// finish();
}
}
});
}
}
@Override @Override
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
@@ -114,9 +147,9 @@ public class MainActivity extends WinBoLLActivity implements IWinBoLLActivity {
mToolbar = (Toolbar) findViewById(R.id.toolbar); // Java 7 显式 findViewById + 强转 mToolbar = (Toolbar) findViewById(R.id.toolbar); // Java 7 显式 findViewById + 强转
setSupportActionBar(mToolbar); setSupportActionBar(mToolbar);
// 给ActionBar设置标题先判断非空避免空指针异常 // 给ActionBar设置标题先判断非空避免空指针异常
if (getSupportActionBar() != null) { AppLevel appLevel = AppConfigsUtil.getInstance(getApplicationContext()).getAppLevel(true);
getSupportActionBar().setTitle(getString(R.string.app_name)); getSupportActionBar().setTitle(getString(R.string.app_name));
}
} }
/** /**

View File

@@ -0,0 +1,22 @@
package cc.winboll.studio.positions;
import android.os.Bundle;
import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.libappbase.ToastUtils;
/**
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
* @Date 2025/11/13 15:21
* @Describe MainActivityLaojun
*/
public class MainActivityLaojun extends MainActivity {
public static final String TAG = "MainActivityLaojun";
@Override
protected void onCreate(Bundle savedInstanceState) {
ToastUtils.show("道法自然");
LogUtils.d(TAG, "玩法归臻");
super.onCreate(savedInstanceState);
}
}

View File

@@ -0,0 +1,43 @@
package cc.winboll.studio.positions;
/**
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
* @Date 2025/11/15 15:14
* @Describe 应用入口级别类型枚举
*/
public enum PointLevel {
DORAEMON("doraemon", "叮铛级别"),
WUKONG("wukong", "悟空级别"),
LAOJUN("laojun", "老君级别");
public static final String TAG = "PointLevel";
// 枚举属性
private final String code; // 编码(如 "wukong"
private final String desc; // 描述
// 构造方法Java 7 需显式定义)
PointLevel(String code, String desc) {
this.code = code;
this.desc = desc;
}
// Getter 方法(获取枚举属性)
public String getCode() {
return code;
}
public String getDesc() {
return desc;
}
// 可选:根据 code 获取枚举项(便于业务使用)
public static PointLevel getByCode(String code) {
for (PointLevel level : values()) {
if (level.code.equals(code)) {
return level;
}
}
return null; // 或抛出异常,根据业务需求调整
}
}

View File

@@ -0,0 +1,61 @@
package cc.winboll.studio.positions.activities;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;
import cc.winboll.studio.libappbase.ToastUtils;
import cc.winboll.studio.positions.R;
import cc.winboll.studio.positions.utils.APPPlusUtils;
import cc.winboll.studio.positions.utils.AppConfigsUtil;
import cc.winboll.studio.positions.AppLevel;
/**
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
* @Date 2025/11/15 13:45
* @Describe 应用快捷方式活动类
*/
public class ShortcutActionActivity extends Activity {
public static final String TAG = "ShortcutActionActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 处理应用级别的切换请求
handleSwitchRequest();
finish();
}
// @Override
// public void onPostCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
// super.onPostCreate(savedInstanceState, persistentState);
// finish();
// }
// @Override
// protected void onStart() {
// super.onStart();
// }
/**
* 处理应用图标快捷菜单的请求
*/
private void handleSwitchRequest() {
Intent intent = getIntent();
if (intent != null && "open_appplus".equals(intent.getDataString())) {
ToastUtils.show("已添加" + getString(R.string.app_name) + "附加组件");
AppConfigsUtil.getInstance(getApplicationContext()).setAppLevel(AppLevel.LAOJUN);
APPPlusUtils.openAPPPlus(this);
//moveTaskToBack(true);
}
if (intent != null && "close_appplus".equals(intent.getDataString())) {
ToastUtils.show("已移除" + getString(R.string.app_name) + "附加组件");
AppConfigsUtil.getInstance(getApplicationContext()).setAppLevel(AppLevel.WUKONG);
APPPlusUtils.closeAPPPlus(this);
//moveTaskToBack(true);
}
}
}

View File

@@ -12,11 +12,19 @@ import androidx.appcompat.app.AppCompatActivity;
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity; import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
import cc.winboll.studio.libaes.utils.WinBoLLActivityManager; import cc.winboll.studio.libaes.utils.WinBoLLActivityManager;
import cc.winboll.studio.libappbase.LogUtils; import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.libappbase.ToastUtils;
import cc.winboll.studio.positions.App;
import cc.winboll.studio.positions.PointLevel;
import cc.winboll.studio.positions.R;
import cc.winboll.studio.positions.utils.ActivityAliasUtils;
import cc.winboll.studio.positions.utils.AppConfigsUtil;
public class WinBoLLActivity extends AppCompatActivity implements IWinBoLLActivity { public class WinBoLLActivity extends AppCompatActivity implements IWinBoLLActivity {
public static final String TAG = "WinBoLLActivity"; public static final String TAG = "WinBoLLActivity";
public static volatile PointLevel _mPointLevel = PointLevel.WUKONG;
@Override @Override
public Activity getActivity() { public Activity getActivity() {
return this; return this;
@@ -30,18 +38,67 @@ public class WinBoLLActivity extends AppCompatActivity implements IWinBoLLActivi
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
//ToastUtils.show("onResume");
// ActivityAliasUtils 工具使用示例
//
// // 获取真实的目标组件名(即使通过 alias 启动,也能拿到 OriginalActivity
// String realTargetName = ActivityAliasUtils.getRealTargetNameFromIntent(this);
// LogUtils.d("AliasActivity", "真实组件名:" + realTargetName);
// 获取真实的目标组件名(即使通过 alias 启动,也能拿到 OriginalActivity
// String realTargetName = ActivityAliasUtils.getRealTargetNameFromIntent(this);
// LogUtils.d(TAG, "真实组件名:" + realTargetName);
// ToastUtils.show(realTargetName);
// // 判断某个组件是否为 alias
// String componentName = "com.winboll.app.AliasActivity";
// boolean isAlias = ActivityAliasUtils.isActivityAlias(getApplicationContext(), componentName);
// LogUtils.d("判断结果", componentName + " 是否为 alias" + isAlias); // true
// // 获取启动当前 Activity 的组件名(兼容 alias 场景)
// String launchComponent = ActivityAliasUtils.getLaunchComponentName(this);
// LogUtils.d("MainActivity", "启动组件名:" + launchComponent);
/*
* 应用入口逻辑模块
*/
//
// 检查当前活动的启动组件名,设置应用入口级别。
String launchComponent = ActivityAliasUtils.getLaunchComponentName(this);
LogUtils.d("MainActivity", "启动组件名:" + launchComponent);
ToastUtils.show(launchComponent);
// 当前应用处于活动暂停的状态时,就检查应用的入口组件名称,设置应用入口级别。
if (WinBoLLActivity._mPointLevel == PointLevel.DORAEMON) {
if (launchComponent.equals(App.COMPONENT_WUKONG)) {
getSupportActionBar().setTitle(getString(R.string.appplus_name));
ToastUtils.show("WUKONG");
_mPointLevel = PointLevel.WUKONG;
} else if (launchComponent.equals(App.COMPONENT_LAOJUN)) {
getSupportActionBar().setTitle(getString(R.string.app_name));
ToastUtils.show("LAOJUN");
_mPointLevel = PointLevel.LAOJUN;
} else {
// 如果是其他应用组件入口,就关闭活动
finish();
}
}
/*
* 应用级别设置模块
*/
// 读取并配置应用级别
App._mAppLevel = AppConfigsUtil.getInstance(getApplicationContext()).getAppLevel(true);
LogUtils.d(TAG, String.format("onResume %s", getTag())); LogUtils.d(TAG, String.format("onResume %s", getTag()));
} }
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
/*if (item.getItemId() == R.id.item_log) { /*if (item.getItemId() == R.id.item_log) {
WinBoLLActivityManager.getInstance().startLogActivity(this); WinBoLLActivityManager.getInstance().startLogActivity(this);
return true; return true;
} else if (item.getItemId() == R.id.item_home) { } else if (item.getItemId() == R.id.item_home) {
startActivity(new Intent(this, MainActivity.class)); startActivity(new Intent(this, MainActivity.class));
return true; return true;
}*/ }*/
// 在switch语句中处理每个ID并在处理完后返回true未处理的情况返回false。 // 在switch语句中处理每个ID并在处理完后返回true未处理的情况返回false。
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }

View File

@@ -9,12 +9,14 @@ package cc.winboll.studio.positions.models;
import android.util.JsonWriter; import android.util.JsonWriter;
import android.util.JsonReader; import android.util.JsonReader;
import java.io.IOException; import java.io.IOException;
import cc.winboll.studio.positions.AppLevel;
public class AppConfigsModel extends BaseBean { public class AppConfigsModel extends BaseBean {
public static final String TAG = "AppConfigsModel"; public static final String TAG = "AppConfigsModel";
boolean isEnableMainService; boolean isEnableMainService;
AppLevel appLevel;
public AppConfigsModel(boolean isEnableMainService) { public AppConfigsModel(boolean isEnableMainService) {
this.isEnableMainService = isEnableMainService; this.isEnableMainService = isEnableMainService;
@@ -24,6 +26,14 @@ public class AppConfigsModel extends BaseBean {
this.isEnableMainService = false; this.isEnableMainService = false;
} }
public void setAppLevel(AppLevel appLevel) {
this.appLevel = appLevel;
}
public AppLevel getAppLevel() {
return appLevel;
}
public void setIsEnableMainService(boolean isEnableMainService) { public void setIsEnableMainService(boolean isEnableMainService) {
this.isEnableMainService = isEnableMainService; this.isEnableMainService = isEnableMainService;
} }
@@ -42,6 +52,7 @@ public class AppConfigsModel extends BaseBean {
public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException { public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
super.writeThisToJsonWriter(jsonWriter); super.writeThisToJsonWriter(jsonWriter);
jsonWriter.name("isEnableDistanceRefreshService").value(isEnableMainService()); jsonWriter.name("isEnableDistanceRefreshService").value(isEnableMainService());
jsonWriter.name("appLevel").value(getAppLevel().ordinal());
} }
// JSON反序列化加载位置数据校验字段 // JSON反序列化加载位置数据校验字段
@@ -52,6 +63,8 @@ public class AppConfigsModel extends BaseBean {
} else { } else {
if (name.equals("isEnableDistanceRefreshService")) { if (name.equals("isEnableDistanceRefreshService")) {
setIsEnableMainService(jsonReader.nextBoolean()); setIsEnableMainService(jsonReader.nextBoolean());
} else if (name.equals("appLevel")) {
setAppLevel((AppLevel.values()[jsonReader.nextInt()]));
} else { } else {
return false; return false;
} }

View File

@@ -9,116 +9,353 @@ import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Build; import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils; import android.text.TextUtils;
import cc.winboll.studio.libappbase.LogUtils; import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.libappbase.ToastUtils;
import cc.winboll.studio.positions.services.MainService; import cc.winboll.studio.positions.services.MainService;
import cc.winboll.studio.positions.utils.ServiceUtil; import cc.winboll.studio.positions.utils.ServiceUtil;
/** /**
* 运动状态监听Receiver * 运动状态监听Receiver
* 功能:接收运动状态广播控制GPS权限申请与GPS监听开关 * 功能:1.持续监听传感器(不关闭) 2.每5秒计算运动状态 3.按状态切换GPS模式实时/30秒定时
*/ */
public class MotionStatusReceiver extends BroadcastReceiver { public class MotionStatusReceiver extends BroadcastReceiver implements SensorEventListener {
public static final String TAG = "MotionStatusReceiver"; public static final String TAG = "MotionStatusReceiver";
// 运动状态广播Action(需与运动状态发送方保持一致,如传感器服务) // 广播Action
public static final String ACTION_MOTION_STATUS = "cc.winboll.studio.positions.ACTION_MOTION_STATUS"; public static final String ACTION_MOTION_STATUS_RECEIVER = "cc.winboll.studio.positions.receivers.MotionStatusReceiver";
// 运动状态Extra键0=静止/低运动1=行走/高运动 public static final String EXTRA_SENSORS_ENABLE = "EXTRA_SENSORS_ENABLE";
public static final String EXTRA_MOTION_STATUS = "EXTRA_MOTION_STATUS"; // 传感器启动状态标志位
// 静止时GPS定时获取间隔单位分钟可配置 boolean mIsSensorsEnable = false;
public static final long GPS_STATIC_INTERVAL = 1; // 运动状态常量
private static final int MOTION_STATUS_STATIC = 0; // 静止/低运动
private static final int MOTION_STATUS_WALKING = 1; // 行走/高速运动
// 配置参数(按需求调整)
private static final float ACCELEROMETER_THRESHOLD = 0.8f; // 加速度阈值
private static final float GYROSCOPE_THRESHOLD = 0.5f; // 陀螺仪阈值
private static final long STATUS_CALC_INTERVAL = 5000; // 运动状态计算间隔5秒
private static final long GPS_STATIC_INTERVAL = 30; // 静止时GPS间隔30秒
// 核心对象
private volatile SensorManager mSensorManager;
private Sensor mAccelerometer;
private Sensor mGyroscope;
private volatile boolean mIsSensorListening = false; // 传感器是否持续监听
private int mCurrentMotionStatus = MOTION_STATUS_STATIC; // 当前运动状态
private Handler mMainHandler; // 主线程Handler用于定时计算
private Context mBroadcastContext; // 广播上下文
// 传感器数据缓存用于5秒内数据汇总避免单次波动误判
private float mAccelMax = 0f; // 5秒内加速度最大值
private float mGyroMax = 0f; // 5秒内陀螺仪最大值
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
if (context == null || intent == null || !TextUtils.equals(intent.getAction(), ACTION_MOTION_STATUS)) {
LogUtils.w(TAG, "无效广播Action不匹配或上下文为空");
return;
}
// 1. 获取运动状态0=静止/低运动1=行走/高运动) LogUtils.d(TAG, "===== 接收器启动onReceive() 开始执行 =====");
int motionStatus = intent.getIntExtra(EXTRA_MOTION_STATUS, 0); this.mBroadcastContext = context;
LogUtils.d(TAG, "接收运动状态:" + (motionStatus == 1 ? "行走中" : "静止/低运动")); mMainHandler = new Handler(Looper.getMainLooper());
// 2. 绑定并获取MainService实例确保服务已启动 if (TextUtils.equals(intent.getAction(), ACTION_MOTION_STATUS_RECEIVER)) {
MainService mainService = getMainService(context); boolean isSettingEnable = intent.getBooleanExtra(EXTRA_SENSORS_ENABLE, false);
if (mainService == null) { if (mIsSensorsEnable == false && isSettingEnable == true) {
LogUtils.e(TAG, "MainService未启动无法控制GPS状态"); mIsSensorsEnable = true;
return; // 1. 初始化传感器(必执行)
} initSensors();
// 3. 根据运动状态处理GPS逻辑 if (mAccelerometer == null || mGyroscope == null) {
if (motionStatus == 1) { LogUtils.e(TAG, "设备缺少加速度/陀螺仪,无法持续监听");
// 3.1 行走中申请GPS权限若未授予+ 开启持续GPS监听 cleanResources(false); // 传感器不可用才清理
handleWalkingStatus(mainService, context); return;
} else { }
// 3.2 静止/低运动关闭持续GPS监听 + 启动定时GPS获取
handleStaticStatus(mainService);
}
}
/** // 2. 校验参数
* 处理行走状态申请GPS权限+开启持续GPS监听 if (context == null || intent == null) {
*/ LogUtils.d(TAG, "onReceive():无效参数,终止处理");
private void handleWalkingStatus(MainService mainService, Context context) { cleanResources(false);
// 检查GPS权限Android 6.0+动态权限) return;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && }
context.checkSelfPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) LogUtils.d(TAG, "onReceive()接收到广播Action=" + intent.getAction());
!= PackageManager.PERMISSION_GRANTED) {
// 发送权限申请广播由Activity接收并发起申请Receiver无法直接申请权限
Intent permissionIntent = new Intent("cc.winboll.studio.positions.ACTION_REQUEST_GPS_PERMISSION");
permissionIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(permissionIntent);
LogUtils.d(TAG, "行走中GPS权限未授予已发送权限申请广播");
return;
}
// 权限已授予开启持续GPS监听调用MainService原有方法 // 3. 启动持续传感器监听(核心:不关闭,重复调用无影响
if (!mainService.isGpsListening()) { // 需在MainService中新增isGpsListening()方法 startSensorListening();
mainService.startGpsLocation();
LogUtils.d(TAG, "行走中已开启持续GPS监听");
}
// 停止静止时的GPS定时任务避免重复获取 // 4. 启动5秒定时计算运动状态核心持续触发状态判断
mainService.stopGpsStaticTimer(); startStatusCalcTimer();
}
/**
* 处理静止状态关闭持续GPS监听+启动定时GPS获取
*/
private void handleStaticStatus(MainService mainService) {
// 关闭持续GPS监听避免耗电
if (mainService.isGpsListening()) {
mainService.stopGpsLocation();
LogUtils.d(TAG, "静止中已关闭持续GPS监听");
}
// 启动定时GPS获取获取一次后关闭间隔GPS_STATIC_INTERVAL分钟
mainService.startGpsStaticTimer(GPS_STATIC_INTERVAL);
}
/**
* 获取MainService实例通过绑定服务或单例确保线程安全
*/
private MainService getMainService(Context context) {
// 方式1若MainService单例有效直接获取推荐
MainService singleton = MainService.getInstance(context);
if (singleton != null && singleton.isServiceRunning()) {
return singleton;
}
// 方式2若单例无效尝试绑定服务备用需处理绑定回调
if (!ServiceUtil.isServiceAlive(context, MainService.class.getName())) {
// 启动服务(若未运行)
context.startService(new Intent(context, MainService.class));
// 等待服务启动短延时实际项目建议用ServiceConnection异步绑定
try {
Thread.sleep(500);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} }
} }
return MainService.getInstance(context);
}
// 5. 处理外部广播触发(可选,保留外部控制能力)
// if (TextUtils.equals(intent.getAction(), ACTION_MOTION_STATUS_RECEIVER)) {
// int motionStatus = intent.getIntExtra(EXTRA_MOTION_STATUS, MOTION_STATUS_STATIC);
// String statusDesc = motionStatus == MOTION_STATUS_WALKING ? "高速运动" : "静止/低运动";
// LogUtils.d(TAG, "外部广播触发,强制设置运动状态:" + statusDesc);
// mCurrentMotionStatus = motionStatus;
// handleMotionStatus(mCurrentMotionStatus); // 立即执行GPS切换
// }
}
/**
* 初始化传感器(持续监听,复用实例)
*/
private void initSensors() {
LogUtils.d(TAG, "initSensors():初始化传感器");
if (mSensorManager != null || mBroadcastContext == null) return;
mSensorManager = (SensorManager) mBroadcastContext.getSystemService(Context.SENSOR_SERVICE);
if (mSensorManager == null) {
LogUtils.e(TAG, "设备不支持传感器服务");
return;
}
// 获取传感器实例(持续复用,不销毁)
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
mGyroscope = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
LogUtils.d(TAG, "传感器初始化结果:加速度=" + (mAccelerometer != null) + ",陀螺仪=" + (mGyroscope != null));
}
/**
* 启动传感器持续监听(核心:不关闭,注册一次一直生效)
*/
private void startSensorListening() {
if (mSensorManager == null || mAccelerometer == null || mGyroscope == null) return;
if (!mIsSensorListening) {
// 注册传感器监听(持续生效,直到服务销毁才注销)
mSensorManager.registerListener(
this,
mAccelerometer,
SensorManager.SENSOR_DELAY_NORMAL, // 正常延迟,平衡性能与精度
mMainHandler
);
mSensorManager.registerListener(
this,
mGyroscope,
SensorManager.SENSOR_DELAY_NORMAL,
mMainHandler
);
mIsSensorListening = true;
LogUtils.d(TAG, "startSensorListening():传感器持续监听已启动(不关闭)");
}
}
/**
* 启动5秒定时计算运动状态核心周期性汇总传感器数据
*/
private void startStatusCalcTimer() {
if (mMainHandler == null) return;
// 移除旧任务(避免重复注册)
mMainHandler.removeCallbacks(mStatusCalcRunnable);
// 启动定时任务每5秒执行一次
mMainHandler.postDelayed(mStatusCalcRunnable, STATUS_CALC_INTERVAL);
LogUtils.d(TAG, "startStatusCalcTimer()5秒运动状态计算定时器已启动");
}
/**
* 运动状态计算任务5秒执行一次
*/
private final Runnable mStatusCalcRunnable = new Runnable() {
@Override
public void run() {
// 1. 基于5秒内缓存的最大传感器数据判断状态
boolean isHighMotion = (mAccelMax > ACCELEROMETER_THRESHOLD) && (mGyroMax > GYROSCOPE_THRESHOLD);
int newMotionStatus = isHighMotion ? MOTION_STATUS_WALKING : MOTION_STATUS_STATIC;
// 2. 状态变化时才处理避免频繁切换GPS
if (newMotionStatus != mCurrentMotionStatus) {
mCurrentMotionStatus = newMotionStatus;
String statusDesc = isHighMotion ? "高速运动" : "静止/低运动";
LogUtils.d(TAG, "运动状态更新5秒计算" + statusDesc
+ "(加速度最大值=" + mAccelMax + ",陀螺仪最大值=" + mGyroMax + "");
handleMotionStatus(newMotionStatus); // 切换GPS模式
} else {
LogUtils.d(TAG, "运动状态无变化5秒计算" + (isHighMotion ? "高速运动" : "静止/低运动"));
}
// 3. 重置传感器数据缓存准备下一个5秒周期
mAccelMax = 0f;
mGyroMax = 0f;
// 4. 循环执行定时任务(核心:持续计算)
mMainHandler.postDelayed(this, STATUS_CALC_INTERVAL);
}
};
/**
* 传感器数据变化回调(核心:实时缓存最大数据)
*/
@Override
public void onSensorChanged(SensorEvent event) {
if (event == null) return;
// 实时缓存5秒内的最大传感器数据避免单次波动误判
switch (event.sensor.getType()) {
case Sensor.TYPE_ACCELEROMETER:
float accelTotal = Math.abs(event.values[0]) + Math.abs(event.values[1]) + Math.abs(event.values[2]);
if (accelTotal > mAccelMax) mAccelMax = accelTotal; // 缓存最大值
LogUtils.d(TAG, "加速度传感器实时数据:合值=" + accelTotal + "当前5秒最大值=" + mAccelMax + "");
break;
case Sensor.TYPE_GYROSCOPE:
float gyroTotal = Math.abs(event.values[0]) + Math.abs(event.values[1]) + Math.abs(event.values[2]);
if (gyroTotal > mGyroMax) mGyroMax = gyroTotal; // 缓存最大值
LogUtils.d(TAG, "陀螺仪实时数据:合值=" + gyroTotal + "当前5秒最大值=" + mGyroMax + "");
break;
}
}
/**
* 处理运动状态核心按状态切换GPS模式
*/
private void handleMotionStatus(int motionStatus) {
LogUtils.d(TAG, "handleMotionStatus()开始处理运动状态切换GPS模式");
if (mBroadcastContext == null) {
LogUtils.w(TAG, "上下文为空无法处理GPS");
return;
}
MainService mainService = getMainService();
if (mainService == null) {
LogUtils.e(TAG, "MainService未启动GPS控制失败");
return;
}
if (motionStatus == MOTION_STATUS_WALKING) {
// 高速运动启动GPS实时更新2秒/1米
handleHighMotionGPS(mainService);
} else {
// 静止/低运动启动GPS30秒定时更新
handleStaticGPS(mainService);
}
}
/**
* 高速运动GPS处理实时更新
*/
private void handleHighMotionGPS(MainService mainService) {
// 动态权限判断Android 6.0+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
mBroadcastContext.checkSelfPermission(android.Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
sendPermissionRequestBroadcast();
return;
}
// 启动实时GPS已启动则不重复操作
if (!mainService.isGpsListening()) {
mainService.startGpsLocation(); // 实时更新2秒/1米
mainService.stopGpsStaticTimer(); // 停止定时GPS
LogUtils.d(TAG, "高速运动已启动GPS实时更新");
}
}
/**
* 静止/低运动GPS处理30秒定时更新
*/
private void handleStaticGPS(MainService mainService) {
// 停止实时GPS已停止则不重复操作
if (mainService.isGpsListening()) {
mainService.stopGpsLocation(); // 停止实时更新
LogUtils.d(TAG, "静止/低运动已停止GPS实时更新");
}
// 启动30秒定时GPS已启动则不重复操作
mainService.startGpsStaticTimer(GPS_STATIC_INTERVAL); // 30秒一次
LogUtils.d(TAG, "静止/低运动已启动GPS30秒定时更新");
}
/**
* 获取MainService实例复用逻辑
*/
private MainService getMainService() {
if (mBroadcastContext == null) return null;
// 优先获取单例
MainService singleton = MainService.getInstance(mBroadcastContext);
if (singleton != null && singleton.isServiceRunning()) {
return singleton;
}
// 启动服务并重试
if (!ServiceUtil.isServiceAlive(mBroadcastContext, MainService.class.getName())) {
mBroadcastContext.startService(new Intent(mBroadcastContext, MainService.class));
try {
Thread.sleep(500); // 等待服务启动
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
return MainService.getInstance(mBroadcastContext);
}
/**
* 发送GPS权限申请广播Receiver无法直接申请
*/
private void sendPermissionRequestBroadcast() {
Intent permissionIntent = new Intent("cc.winboll.studio.positions.ACTION_REQUEST_GPS_PERMISSION");
permissionIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
mBroadcastContext.sendBroadcast(permissionIntent);
LogUtils.d(TAG, "GPS权限缺失已发送申请广播");
}
/**
* 资源清理核心传感器不关闭仅清理Handler和上下文
* @param isForceStopSensor 是否强制停止传感器仅服务销毁时传true
*/
private void cleanResources(boolean isForceStopSensor) {
// 1. 停止定时计算任务
if (mMainHandler != null) {
mMainHandler.removeCallbacksAndMessages(null);
mMainHandler = null;
LogUtils.d(TAG, "cleanResources():已停止运动状态计算定时器");
}
// 2. 强制停止传感器(仅当外部触发销毁时执行,正常情况不关闭)
if (isForceStopSensor && mSensorManager != null && mIsSensorListening) {
mSensorManager.unregisterListener(this);
mIsSensorListening = false;
LogUtils.d(TAG, "cleanResources():已强制停止传感器监听");
}
// 3. 置空上下文(避免内存泄漏)
mBroadcastContext = null;
}
/**
* 传感器精度变化回调(日志监控)
*/
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
String sensorType = sensor.getType() == Sensor.TYPE_ACCELEROMETER ? "加速度" : "陀螺仪";
String accuracyDesc = getAccuracyDesc(accuracy);
LogUtils.d(TAG, sensorType + "传感器精度变化:" + accuracyDesc);
}
/**
* 传感器精度描述转换
*/
private String getAccuracyDesc(int accuracy) {
switch (accuracy) {
case SensorManager.SENSOR_STATUS_ACCURACY_HIGH: return "";
case SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM: return "";
case SensorManager.SENSOR_STATUS_ACCURACY_LOW: return "";
case SensorManager.SENSOR_STATUS_UNRELIABLE: return "不可靠";
default: return "未知";
}
}
/**
* 补充Receiver销毁时强制清理需在MainService注销时调用
*/
public void forceCleanResources() {
cleanResources(true); // 强制停止传感器
}
} }

View File

@@ -3,7 +3,7 @@ package cc.winboll.studio.positions.services;
/** /**
* @Author ZhanGSKen<zhangsken@qq.com> * @Author ZhanGSKen<zhangsken@qq.com>
* @Date 2024/07/19 14:30:57 * @Date 2024/07/19 14:30:57
* @Describe 应用主要服务组件类适配运动状态GPS控制 * @Describe 应用主要服务组件类适配运动状态GPS控制+静止10秒切换
*/ */
import android.app.Service; import android.app.Service;
import android.content.ComponentName; import android.content.ComponentName;
@@ -36,121 +36,128 @@ import java.util.Set;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import cc.winboll.studio.positions.utils.LocalMotionDetector;
public class MainService extends Service { public class MainService extends Service implements LocalMotionDetector.MotionStatusCallback {
public static final String TAG = "MainService"; public static final String TAG = "MainService";
public static final String EXTRA_IS_SETTING_TO_ENABLE = "EXTRA_IS_SETTING_TO_ENABLE"; public static final String EXTRA_IS_SETTING_TO_ENABLE = "EXTRA_IS_SETTING_TO_ENABLE";
// ---------------------- 定时器相关变量 ---------------------- // ---------------------- 核心LocalMotionDetector 实例(唯一运动状态检测工具) ----------------------
private ScheduledExecutorService taskCheckTimer; // 任务校验定时 private LocalMotionDetector mMotionDetector; // 本地运动状态检测
private static final long TASK_CHECK_INTERVAL = 1; // 定时间隔1分钟 private static final long GPS_STATIC_INTERVAL = 30; // 静止时GPS间隔30秒
private static final long TASK_CHECK_INIT_DELAY = 1; // 初始延迟1分钟
// 新增静止时GPS定时任务变量Java 7 显式声明)
private ScheduledExecutorService gpsStaticTimer; // 静止时GPS定时获取线程池
private volatile boolean isGpsListening = false; // GPS是否处于持续监听状态
private static final long GPS_STATIC_DURATION = 3; // 静止时GPS单次获取超时时间
// GPS监听接口Java 7 标准接口定义) // ---------------------- 定时器相关变量 ----------------------
private ScheduledExecutorService gpsStaticTimer; // 静止时GPS定时任务
private volatile boolean isGpsListening = false; // GPS是否持续监听
private static final long GPS_STATIC_DURATION = 3; // 单次GPS获取超时
// ---------------------- 静止延迟切换配置(核心功能) ----------------------
private static final long STATIC_DELAY_MS = 10 * 1000; // 静止10秒后切换
private Handler staticDelayHandler; // 延迟执行切换逻辑的Handler
private volatile boolean isDelaySwitching = false; // 标记是否正在等待延迟切换
// GPS监听接口
public interface GpsUpdateListener { public interface GpsUpdateListener {
void onGpsPositionUpdated(PositionModel currentGpsPos); void onGpsPositionUpdated(PositionModel currentGpsPos);
void onGpsStatusChanged(String status); void onGpsStatusChanged(String status);
} }
// 任务更新监听接口Java 7 风格) // 任务更新监听接口
public interface TaskUpdateListener { public interface TaskUpdateListener {
void onTaskUpdated(); void onTaskUpdated();
} }
// 监听管理(弱引用+线程安全集合适配Java 7 // 监听管理
private final Set<WeakReference<GpsUpdateListener>> mGpsListeners = new HashSet<WeakReference<GpsUpdateListener>>(); private final Set<WeakReference<GpsUpdateListener>> mGpsListeners = new HashSet<WeakReference<GpsUpdateListener>>();
private final Set<WeakReference<TaskUpdateListener>> mTaskListeners = new HashSet<WeakReference<TaskUpdateListener>>(); private final Set<WeakReference<TaskUpdateListener>> mTaskListeners = new HashSet<WeakReference<TaskUpdateListener>>();
private final Object mListenerLock = new Object(); // 监听操作锁 private final Object mListenerLock = new Object();
// 原有核心变量Java 7 显式初始化) // 原有核心变量
private LocalBinder mLocalBinder; // 持有 LocalBinder 实例 private LocalBinder mLocalBinder;
private LocationManager mLocationManager; private LocationManager mLocationManager;
private LocationListener mGpsLocationListener; private LocationListener mGpsLocationListener;
private static final long GPS_UPDATE_INTERVAL = 2000; // GPS更新间隔2秒 private static final long GPS_UPDATE_INTERVAL = 2000; // 实时GPS更新间隔2秒
private static final float GPS_UPDATE_DISTANCE = 1; // GPS更新距离阈值1米 private static final float GPS_UPDATE_DISTANCE = 1; // 实时GPS更新距离1米
private boolean isGpsEnabled = false; // GPS是否启用标记 private boolean isGpsEnabled = false;
private boolean isGpsPermissionGranted = false; // 定位权限是否授予标记 private boolean isGpsPermissionGranted = false;
// 数据存储集合Java 7 基础集合) // 数据存储集合
private final ArrayList<PositionModel> mPositionList = new ArrayList<PositionModel>(); // 位置数据列表 private final ArrayList<PositionModel> mPositionList = new ArrayList<PositionModel>();
private final ArrayList<PositionTaskModel> mAllTasks = new ArrayList<PositionTaskModel>();// 任务数据列表 private final ArrayList<PositionTaskModel> mAllTasks = new ArrayList<PositionTaskModel>();
private static PositionModel _mCurrentGpsPosition; // 当前GPS定位数据 private static PositionModel _mCurrentGpsPosition;
// 服务相关变量Java 7 显式声明) // 服务相关变量
MyServiceConnection mMyServiceConnection; MyServiceConnection mMyServiceConnection;
volatile static boolean _mIsServiceRunning; // 服务运行状态volatile保证可见性 volatile static boolean _mIsServiceRunning;
AppConfigsUtil mAppConfigsUtil; AppConfigsUtil mAppConfigsUtil;
private ScheduledExecutorService distanceExecutor = Executors.newSingleThreadScheduledExecutor(); // 距离计算线程池 private ScheduledExecutorService distanceExecutor = Executors.newSingleThreadScheduledExecutor();
private final Set<String> mVisiblePositionIds = new HashSet<String>(); // 可见位置ID集合 private final Set<String> mVisiblePositionIds = new HashSet<String>();
// 单例+应用上下文Java 7 静态变量) // 单例+应用上下文
private static volatile MainService sInstance; private static volatile MainService sInstance;
private static Context sAppContext; private static Context sAppContext;
// ========================================================================= // =========================================================================
// 定时器初始化方法(任务校验+静止GPS定时 // 核心运动状态回调仅通过LocalMotionDetector触发低运动归类为静止
// ========================================================================= // =========================================================================
/*private void initTaskCheckTimer() { @Override
// 先销毁旧定时器(避免重复创建) public void onMotionStatusChanged(boolean isWalking, String statusDesc) {
if (taskCheckTimer != null && !taskCheckTimer.isShutdown()) { LogUtils.d(TAG, "运动状态回调:" + statusDesc + "isWalking=" + isWalking + "");
taskCheckTimer.shutdown(); updateNotificationGpsStatus("当前状态:" + statusDesc);
}
// 创建单线程定时器(任务串行执行) // 仅行走状态切实时GPS非行走静止+低运动)统一按静止处理
taskCheckTimer = Executors.newSingleThreadScheduledExecutor(); if (isWalking) {
taskCheckTimer.scheduleAtFixedRate(new Runnable() { // 行走状态立即切回实时GPS取消未执行的延迟任务
@Override if (staticDelayHandler != null) {
public void run() { staticDelayHandler.removeCallbacksAndMessages(null); // 清空延迟任务
LogUtils.d(TAG, "定时任务触发开始校验任务间隔1分钟"); isDelaySwitching = false; // 重置标记
DistanceCalculatorUtil.getInstance(MainService.this).checkAllTaskTriggerCondition(MainService._mCurrentGpsPosition);
}
}, TASK_CHECK_INIT_DELAY, TASK_CHECK_INTERVAL, TimeUnit.MINUTES);
LogUtils.d(TAG, "任务校验定时器已启动(间隔:" + TASK_CHECK_INTERVAL + "分钟)");
}*/
/*private void destroyTaskCheckTimer() {
if (taskCheckTimer != null && !taskCheckTimer.isShutdown()) {
taskCheckTimer.shutdown(); // 优雅关闭
try {
if (!taskCheckTimer.awaitTermination(1, TimeUnit.SECONDS)) {
taskCheckTimer.shutdownNow(); // 强制关闭
}
} catch (InterruptedException e) {
taskCheckTimer.shutdownNow();
Thread.currentThread().interrupt(); // 恢复中断状态
} finally {
taskCheckTimer = null;
LogUtils.d(TAG, "任务校验定时器已销毁");
} }
} stopGpsStaticTimer(); // 停止定时GPS
}*/ startGpsLocation(); // 启动实时GPS
LogUtils.d(TAG, "行走状态已切换为实时GPS2秒/1米");
// 新增启动静止时GPS定时获取Java 7 语法无Lambda } else {
public void startGpsStaticTimer(long interval) { // 非行走状态延迟10秒切换为定时GPS
// 先销毁旧定时器(避免重复创建) if (isGpsListening && !isDelaySwitching) { // 仅实时GPS运行且无延迟任务时触发
isDelaySwitching = true;
staticDelayHandler.postDelayed(new Runnable() {
@Override
public void run() {
stopGpsLocation(); // 停止实时GPS
startGpsStaticTimer(GPS_STATIC_INTERVAL); // 启动30秒定时GPS
LogUtils.d(TAG, "静止/低运动10秒已切换为30秒定时GPS");
isDelaySwitching = false; // 重置标记
}
}, STATIC_DELAY_MS);
LogUtils.d(TAG, "检测到静止/低运动将在10秒后切换为定时GPS若持续非行走");
}
LogUtils.d(TAG, "静止/低运动状态等待延迟切换GPS");
}
}
// =========================================================================
// 静止GPS定时任务方法适配Java7
// =========================================================================
// 启动静止时GPS定时获取间隔
public void startGpsStaticTimer(long intervalSeconds) {
stopGpsStaticTimer(); stopGpsStaticTimer();
// 创建单线程定时器
gpsStaticTimer = Executors.newSingleThreadScheduledExecutor(); gpsStaticTimer = Executors.newSingleThreadScheduledExecutor();
gpsStaticTimer.scheduleAtFixedRate(new Runnable() { gpsStaticTimer.scheduleAtFixedRate(new Runnable() {
@Override @Override
public void run() { public void run() {
LogUtils.d(TAG, "静止时GPS定时任务触发开始单次GPS获取"); LogUtils.d(TAG, "静止时GPS定时任务触发开始单次GPS获取");
startSingleGpsRetrieve(); // 单次GPS获取 startSingleGpsRetrieve();
} }
}, 0, interval, TimeUnit.MINUTES); // 立即执行第一次,之后按间隔执行 }, 0, intervalSeconds, TimeUnit.SECONDS);
LogUtils.d(TAG, "静止时GPS定时任务已启动间隔" + interval + "分钟"); LogUtils.d(TAG, "静止时GPS定时任务已启动间隔" + intervalSeconds + "");
} }
// 新增:停止静止时GPS定时任务 // 停止静止时GPS定时任务
public void stopGpsStaticTimer() { public void stopGpsStaticTimer() {
if (gpsStaticTimer != null && !gpsStaticTimer.isShutdown()) { if (gpsStaticTimer != null && !gpsStaticTimer.isShutdown()) {
gpsStaticTimer.shutdown(); gpsStaticTimer.shutdown();
@@ -168,7 +175,7 @@ public class MainService extends Service {
} }
} }
// 新增:单次GPS获取获取后关闭监听Java 7 匿名内部类 // 单次GPS获取获取后关闭监听
private void startSingleGpsRetrieve() { private void startSingleGpsRetrieve() {
if (!checkGpsReady()) { if (!checkGpsReady()) {
LogUtils.w(TAG, "单次GPS获取GPS未就绪跳过"); LogUtils.w(TAG, "单次GPS获取GPS未就绪跳过");
@@ -176,13 +183,11 @@ public class MainService extends Service {
} }
try { try {
// 注册临时GPS监听仅获取一次位置
mLocationManager.requestSingleUpdate( mLocationManager.requestSingleUpdate(
LocationManager.GPS_PROVIDER, LocationManager.GPS_PROVIDER,
new LocationListener() { new LocationListener() {
@Override @Override
public void onLocationChanged(Location location) { public void onLocationChanged(Location location) {
// 获取到位置:同步数据+关闭监听
if (location != null) { if (location != null) {
PositionModel gpsPos = new PositionModel(); PositionModel gpsPos = new PositionModel();
gpsPos.setLatitude(location.getLatitude()); gpsPos.setLatitude(location.getLatitude());
@@ -192,7 +197,6 @@ public class MainService extends Service {
syncCurrentGpsPosition(gpsPos); syncCurrentGpsPosition(gpsPos);
LogUtils.d(TAG, "单次GPS获取成功纬度=" + location.getLatitude()); LogUtils.d(TAG, "单次GPS获取成功纬度=" + location.getLatitude());
} }
// 移除监听(避免内存泄漏)
mLocationManager.removeUpdates(this); mLocationManager.removeUpdates(this);
} }
@@ -204,24 +208,23 @@ public class MainService extends Service {
@Override @Override
public void onProviderDisabled(String provider) { public void onProviderDisabled(String provider) {
mLocationManager.removeUpdates(this); // 禁用时移除监听 mLocationManager.removeUpdates(this);
} }
}, },
Looper.getMainLooper() Looper.getMainLooper()
); );
// 超时处理:指定时间内未获取则强制关闭 // 超时处理
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override @Override
public void run() { public void run() {
// 移除所有临时监听
mLocationManager.removeUpdates(new LocationListener() { mLocationManager.removeUpdates(new LocationListener() {
@Override public void onLocationChanged(Location location) {} @Override public void onLocationChanged(Location location) {}
@Override public void onStatusChanged(String provider, int status, Bundle extras) {} @Override public void onStatusChanged(String provider, int status, Bundle extras) {}
@Override public void onProviderEnabled(String provider) {} @Override public void onProviderEnabled(String provider) {}
@Override public void onProviderDisabled(String provider) {} @Override public void onProviderDisabled(String provider) {}
}); });
LogUtils.d(TAG, "单次GPS获取超时" + GPS_STATIC_DURATION + "秒),已强制关闭监听"); LogUtils.d(TAG, "单次GPS获取超时" + GPS_STATIC_DURATION + "秒)");
} }
}, GPS_STATIC_DURATION * 1000); }, GPS_STATIC_DURATION * 1000);
@@ -234,7 +237,7 @@ public class MainService extends Service {
// ========================================================================= // =========================================================================
// 任务操作核心接口Java 7 实现) // 任务操作核心接口
// ========================================================================= // =========================================================================
public void addTask(PositionTaskModel newTask) { public void addTask(PositionTaskModel newTask) {
if (newTask == null || TextUtils.isEmpty(newTask.getPositionId())) { if (newTask == null || TextUtils.isEmpty(newTask.getPositionId())) {
@@ -242,7 +245,6 @@ public class MainService extends Service {
return; return;
} }
// 任务去重Java 7 迭代器遍历)
boolean isDuplicate = false; boolean isDuplicate = false;
Iterator<PositionTaskModel> taskIter = mAllTasks.iterator(); Iterator<PositionTaskModel> taskIter = mAllTasks.iterator();
while (taskIter.hasNext()) { while (taskIter.hasNext()) {
@@ -269,7 +271,6 @@ public class MainService extends Service {
return posTasks; return posTasks;
} }
// 筛选任务Java 7 迭代器遍历)
Iterator<PositionTaskModel> taskIter = mAllTasks.iterator(); Iterator<PositionTaskModel> taskIter = mAllTasks.iterator();
while (taskIter.hasNext()) { while (taskIter.hasNext()) {
PositionTaskModel task = taskIter.next(); PositionTaskModel task = taskIter.next();
@@ -313,7 +314,6 @@ public class MainService extends Service {
return; return;
} }
// 迭代器删除Java 7 安全方式)
Iterator<PositionTaskModel> taskIter = mAllTasks.iterator(); Iterator<PositionTaskModel> taskIter = mAllTasks.iterator();
while (taskIter.hasNext()) { while (taskIter.hasNext()) {
PositionTaskModel task = taskIter.next(); PositionTaskModel task = taskIter.next();
@@ -359,7 +359,6 @@ public class MainService extends Service {
while (iter.hasNext()) { while (iter.hasNext()) {
final WeakReference<TaskUpdateListener> ref = iter.next(); final WeakReference<TaskUpdateListener> ref = iter.next();
if (ref.get() != null) { if (ref.get() != null) {
// 主线程判断+切换Java 7 匿名Runnable
if (Looper.myLooper() == Looper.getMainLooper()) { if (Looper.myLooper() == Looper.getMainLooper()) {
ref.get().onTaskUpdated(); ref.get().onTaskUpdated();
} else { } else {
@@ -371,7 +370,7 @@ public class MainService extends Service {
}); });
} }
} else { } else {
iter.remove(); // 清理已回收弱引用 iter.remove();
} }
} }
} }
@@ -379,7 +378,7 @@ public class MainService extends Service {
// ========================================================================= // =========================================================================
// 原有基础方法(Java 7 语法适配 // 服务基础方法(初始化LocalMotionDetector删除Receiver相关逻辑
// ========================================================================= // =========================================================================
public static synchronized MainService getInstance(Context context) { public static synchronized MainService getInstance(Context context) {
if (sInstance == null) { if (sInstance == null) {
@@ -397,7 +396,7 @@ public class MainService extends Service {
@Override @Override
public IBinder onBind(Intent intent) { public IBinder onBind(Intent intent) {
return mLocalBinder; // 返回LocalBinder暴露服务 return mLocalBinder;
} }
@Override @Override
@@ -407,49 +406,49 @@ public class MainService extends Service {
sInstance = this; sInstance = this;
sAppContext = getApplicationContext(); sAppContext = getApplicationContext();
// 初始化LocalBinder
mLocalBinder = new LocalBinder(this); mLocalBinder = new LocalBinder(this);
_mIsServiceRunning = false; _mIsServiceRunning = false;
mAppConfigsUtil = AppConfigsUtil.getInstance(this); mAppConfigsUtil = AppConfigsUtil.getInstance(this);
// 初始化服务连接
if (mMyServiceConnection == null) { if (mMyServiceConnection == null) {
mMyServiceConnection = new MyServiceConnection(); mMyServiceConnection = new MyServiceConnection();
} }
// 初始化LocalMotionDetector+延迟切换HandlerJava7兼容
mMotionDetector = LocalMotionDetector.getInstance();
staticDelayHandler = new Handler(Looper.getMainLooper());
if (mAppConfigsUtil.isEnableMainService(true)) { if (mAppConfigsUtil.isEnableMainService(true)) {
run(); // 启动服务核心逻辑 run();
} }
} }
// 服务核心运行方法删除Receiver注册逻辑
public void run() { public void run() {
if (mAppConfigsUtil.isEnableMainService(true)) { if (mAppConfigsUtil.isEnableMainService(true)) {
if (!_mIsServiceRunning) { if (!_mIsServiceRunning) {
_mIsServiceRunning = true; _mIsServiceRunning = true;
wakeupAndBindAssistant(); // 唤醒并绑定辅助服务 wakeupAndBindAssistant();
// 启动前台服务 // 启动前台服务
String initialStatus = "[ Positions ] is in Service."; String initialStatus = "[ Positions ] is in Service.";
NotificationUtil.createForegroundServiceNotification(this, initialStatus); NotificationUtil.createForegroundServiceNotification(this, initialStatus);
startForeground(NotificationUtil.FOREGROUND_SERVICE_NOTIFICATION_ID, startForeground(NotificationUtil.FOREGROUND_SERVICE_NOTIFICATION_ID,
NotificationUtil.createForegroundServiceNotification(this, initialStatus)); NotificationUtil.createForegroundServiceNotification(this, initialStatus));
// 初始化GPS相关 // 初始化LocationManager
mLocationManager = (LocationManager) sInstance.getApplicationContext().getSystemService(Context.LOCATION_SERVICE); mLocationManager = (LocationManager) sInstance.getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
initGpsLocationListener();
startGpsLocation();
// 加载本地数据 // 加载本地数据
PositionModel.loadBeanList(MainService.this, mPositionList, PositionModel.class); PositionModel.loadBeanList(MainService.this, mPositionList, PositionModel.class);
PositionTaskModel.loadBeanList(MainService.this, mAllTasks, PositionTaskModel.class); PositionTaskModel.loadBeanList(MainService.this, mAllTasks, PositionTaskModel.class);
// 核心启动LocalMotionDetector监测唯一运动状态来源
mMotionDetector.startDetection(this, this);
// 提示与日志 // 提示与日志
ToastUtils.show(initialStatus); ToastUtils.show(initialStatus);
LogUtils.i(TAG, initialStatus); LogUtils.i(TAG, initialStatus);
// 启动任务校验定时器
//initTaskCheckTimer();
} }
} }
} }
@@ -463,34 +462,44 @@ public class MainService extends Service {
super.onDestroy(); super.onDestroy();
sInstance = null; sInstance = null;
// 清理资源 // 核心停止LocalMotionDetector避免传感器内存泄漏
if (mMotionDetector != null) {
mMotionDetector.stopDetection();
LogUtils.d(TAG, "LocalMotionDetector 已停止检测");
}
// 清理延迟Handler任务避免内存泄漏
if (staticDelayHandler != null) {
staticDelayHandler.removeCallbacksAndMessages(null);
staticDelayHandler = null;
}
// 原有清理逻辑已删除Receiver注销代码
stopGpsLocation(); stopGpsLocation();
stopGpsStaticTimer();
clearAllData(); clearAllData();
stopForeground(true); stopForeground(true);
// 清理所有监听者
synchronized (mListenerLock) { synchronized (mListenerLock) {
mGpsListeners.clear(); mGpsListeners.clear();
mTaskListeners.clear(); mTaskListeners.clear();
} }
// 销毁所有定时器与线程池
//destroyTaskCheckTimer();
stopGpsStaticTimer(); // 新增销毁静止时GPS定时任务
if (distanceExecutor != null && !distanceExecutor.isShutdown()) { if (distanceExecutor != null && !distanceExecutor.isShutdown()) {
distanceExecutor.shutdown(); distanceExecutor.shutdown();
} }
// 重置状态变量
_mIsServiceRunning = false; _mIsServiceRunning = false;
isGpsEnabled = false; isGpsEnabled = false;
isGpsListening = false; // 新增重置GPS监听状态 isGpsListening = false;
isDelaySwitching = false;
mLocationManager = null; mLocationManager = null;
LogUtils.d(TAG, "MainService 销毁完成,所有资源已清理");
} }
// ========================================================================= // =========================================================================
// 位置操作方法Java 7 语法) // 位置操作方法
// ========================================================================= // =========================================================================
public ArrayList<PositionModel> getPositionList() { public ArrayList<PositionModel> getPositionList() {
return mPositionList; return mPositionList;
@@ -500,7 +509,6 @@ public class MainService extends Service {
return _mCurrentGpsPosition; return _mCurrentGpsPosition;
} }
// 新增判断GPS是否处于持续监听状态给Receiver调用
public boolean isGpsListening() { public boolean isGpsListening() {
return isGpsListening; return isGpsListening;
} }
@@ -510,7 +518,6 @@ public class MainService extends Service {
LogUtils.w(TAG, "removePosition参数无效"); LogUtils.w(TAG, "removePosition参数无效");
return; return;
} }
// 迭代器遍历删除
Iterator<PositionModel> iter = mPositionList.iterator(); Iterator<PositionModel> iter = mPositionList.iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
PositionModel pos = iter.next(); PositionModel pos = iter.next();
@@ -527,7 +534,6 @@ public class MainService extends Service {
LogUtils.w(TAG, "updatePosition参数无效"); LogUtils.w(TAG, "updatePosition参数无效");
return; return;
} }
// 基础for循环查找并更新
for (int i = 0; i < mPositionList.size(); i++) { for (int i = 0; i < mPositionList.size(); i++) {
PositionModel oldPos = mPositionList.get(i); PositionModel oldPos = mPositionList.get(i);
if (updatedPos.getPositionId().equals(oldPos.getPositionId())) { if (updatedPos.getPositionId().equals(oldPos.getPositionId())) {
@@ -554,7 +560,6 @@ public class MainService extends Service {
LogUtils.w(TAG, "addPosition位置为空"); LogUtils.w(TAG, "addPosition位置为空");
return; return;
} }
// 位置去重增强for循环
boolean isDuplicate = false; boolean isDuplicate = false;
for (PositionModel pos : mPositionList) { for (PositionModel pos : mPositionList) {
if (newPos.getPositionId().equals(pos.getPositionId())) { if (newPos.getPositionId().equals(pos.getPositionId())) {
@@ -594,7 +599,6 @@ public class MainService extends Service {
LogUtils.d(TAG, "syncCurrentGpsPosition成功纬度=" + position.getLatitude() + ",经度=" + position.getLongitude() + ""); LogUtils.d(TAG, "syncCurrentGpsPosition成功纬度=" + position.getLatitude() + ",经度=" + position.getLongitude() + "");
notifyAllGpsListeners(position); notifyAllGpsListeners(position);
// 服务运行中同步通知栏状态
if (_mIsServiceRunning) { if (_mIsServiceRunning) {
syncGpsStatusToNotification(); syncGpsStatusToNotification();
} }
@@ -604,14 +608,12 @@ public class MainService extends Service {
if (!_mIsServiceRunning || _mCurrentGpsPosition == null) { if (!_mIsServiceRunning || _mCurrentGpsPosition == null) {
return; return;
} }
// 格式化通知内容
final String gpsStatus = String.format( final String gpsStatus = String.format(
"GPS位置北纬%.4f° 东经%.4f° | 可见位置:%d个", "GPS位置北纬%.4f° 东经%.4f° | 可见位置:%d个",
_mCurrentGpsPosition.getLatitude(), _mCurrentGpsPosition.getLatitude(),
_mCurrentGpsPosition.getLongitude(), _mCurrentGpsPosition.getLongitude(),
mVisiblePositionIds.size() mVisiblePositionIds.size()
); );
// 主线程切换
if (Looper.myLooper() == Looper.getMainLooper()) { if (Looper.myLooper() == Looper.getMainLooper()) {
NotificationUtil.updateForegroundServiceStatus(this, gpsStatus); NotificationUtil.updateForegroundServiceStatus(this, gpsStatus);
} else { } else {
@@ -626,7 +628,7 @@ public class MainService extends Service {
// ========================================================================= // =========================================================================
// 服务生命周期+辅助服务相关Java 7 语法) // 服务生命周期+辅助服务相关
// ========================================================================= // =========================================================================
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
@@ -634,24 +636,18 @@ public class MainService extends Service {
if (intent != null) { if (intent != null) {
isSettingToEnable = intent.getBooleanExtra(EXTRA_IS_SETTING_TO_ENABLE, false); isSettingToEnable = intent.getBooleanExtra(EXTRA_IS_SETTING_TO_ENABLE, false);
if (isSettingToEnable) { if (isSettingToEnable) {
run(); // 重启服务核心逻辑 run();
} }
} }
// 根据是否自启动返回对应启动模式
return isSettingToEnable ? Service.START_STICKY : super.onStartCommand(intent, flags, startId); return isSettingToEnable ? Service.START_STICKY : super.onStartCommand(intent, flags, startId);
} }
// 服务连接内部类
private class MyServiceConnection implements ServiceConnection { private class MyServiceConnection implements ServiceConnection {
@Override @Override
public void onServiceConnected(ComponentName name, IBinder service) { public void onServiceConnected(ComponentName name, IBinder service) {}
// 空实现(如需绑定辅助服务可补充逻辑)
}
@Override @Override
public void onServiceDisconnected(ComponentName name) { public void onServiceDisconnected(ComponentName name) {
// 辅助服务断开时重新绑定
if (mAppConfigsUtil.isEnableMainService(true)) { if (mAppConfigsUtil.isEnableMainService(true)) {
wakeupAndBindAssistant(); wakeupAndBindAssistant();
} }
@@ -659,9 +655,7 @@ public class MainService extends Service {
} }
void wakeupAndBindAssistant() { void wakeupAndBindAssistant() {
// 检查辅助服务是否存活
if (!ServiceUtil.isServiceAlive(getApplicationContext(), AssistantService.class.getName())) { if (!ServiceUtil.isServiceAlive(getApplicationContext(), AssistantService.class.getName())) {
// 启动+绑定辅助服务
startService(new Intent(MainService.this, AssistantService.class)); startService(new Intent(MainService.this, AssistantService.class));
bindService(new Intent(MainService.this, AssistantService.class), mMyServiceConnection, Context.BIND_IMPORTANT); bindService(new Intent(MainService.this, AssistantService.class), mMyServiceConnection, Context.BIND_IMPORTANT);
} }
@@ -669,7 +663,7 @@ public class MainService extends Service {
// ========================================================================= // =========================================================================
// GPS相关核心方法Java 7 语法,匿名内部类实现) // GPS相关核心方法
// ========================================================================= // =========================================================================
public MainService() { public MainService() {
distanceExecutor = Executors.newSingleThreadScheduledExecutor(); distanceExecutor = Executors.newSingleThreadScheduledExecutor();
@@ -682,14 +676,12 @@ public class MainService extends Service {
@Override @Override
public void onLocationChanged(Location location) { public void onLocationChanged(Location location) {
if (location != null) { if (location != null) {
// 封装GPS位置
PositionModel gpsPos = new PositionModel(); PositionModel gpsPos = new PositionModel();
gpsPos.setLatitude(location.getLatitude()); gpsPos.setLatitude(location.getLatitude());
gpsPos.setLongitude(location.getLongitude()); gpsPos.setLongitude(location.getLongitude());
gpsPos.setPositionId("CURRENT_GPS_POS"); gpsPos.setPositionId("CURRENT_GPS_POS");
gpsPos.setMemo("实时GPS位置"); gpsPos.setMemo("实时GPS位置");
// 同步位置+校验任务
syncCurrentGpsPosition(gpsPos); syncCurrentGpsPosition(gpsPos);
DistanceCalculatorUtil.getInstance(MainService.this).checkAllTaskTriggerCondition(gpsPos); DistanceCalculatorUtil.getInstance(MainService.this).checkAllTaskTriggerCondition(gpsPos);
LogUtils.d(TAG, "GPS位置更新纬度=" + location.getLatitude() + ",经度=" + location.getLongitude()); LogUtils.d(TAG, "GPS位置更新纬度=" + location.getLatitude() + ",经度=" + location.getLongitude());
@@ -700,7 +692,6 @@ public class MainService extends Service {
public void onStatusChanged(String provider, int status, Bundle extras) { public void onStatusChanged(String provider, int status, Bundle extras) {
if (provider.equals(LocationManager.GPS_PROVIDER)) { if (provider.equals(LocationManager.GPS_PROVIDER)) {
String statusDesc = ""; String statusDesc = "";
// Java 7 基础switch
switch (status) { switch (status) {
case LocationProvider.AVAILABLE: case LocationProvider.AVAILABLE:
statusDesc = "GPS状态已就绪可用"; statusDesc = "GPS状态已就绪可用";
@@ -725,8 +716,7 @@ public class MainService extends Service {
String statusDesc = "GPS已开启用户手动打开"; String statusDesc = "GPS已开启用户手动打开";
LogUtils.d(TAG, statusDesc); LogUtils.d(TAG, statusDesc);
notifyAllGpsStatusListeners(statusDesc); notifyAllGpsStatusListeners(statusDesc);
updateNotificationGpsStatus("GPS已开启正在获取位置..."); updateNotificationGpsStatus("GPS已开启等待运动状态触发...");
startGpsLocation();
} }
} }
@@ -734,7 +724,7 @@ public class MainService extends Service {
public void onProviderDisabled(String provider) { public void onProviderDisabled(String provider) {
if (provider.equals(LocationManager.GPS_PROVIDER)) { if (provider.equals(LocationManager.GPS_PROVIDER)) {
isGpsEnabled = false; isGpsEnabled = false;
isGpsListening = false; // 新增GPS禁用时重置监听状态 isGpsListening = false;
_mCurrentGpsPosition = null; _mCurrentGpsPosition = null;
String statusDesc = "GPS已关闭用户手动关闭"; String statusDesc = "GPS已关闭用户手动关闭";
LogUtils.w(TAG, statusDesc); LogUtils.w(TAG, statusDesc);
@@ -747,18 +737,14 @@ public class MainService extends Service {
} }
private boolean checkGpsReady() { private boolean checkGpsReady() {
// 检查定位权限
isGpsPermissionGranted = checkSelfPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) isGpsPermissionGranted = checkSelfPermission(android.Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED; == PackageManager.PERMISSION_GRANTED;
// 初始化LocationManager
if (mLocationManager == null) { if (mLocationManager == null) {
mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
} }
// 检查GPS是否启用
isGpsEnabled = mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); isGpsEnabled = mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
// 权限未授予处理
if (!isGpsPermissionGranted) { if (!isGpsPermissionGranted) {
String tip = "GPS准备失败缺少精确定位权限"; String tip = "GPS准备失败缺少精确定位权限";
LogUtils.e(TAG, tip); LogUtils.e(TAG, tip);
@@ -767,7 +753,6 @@ public class MainService extends Service {
ToastUtils.show("请授予定位权限否则无法获取GPS位置"); ToastUtils.show("请授予定位权限否则无法获取GPS位置");
return false; return false;
} }
// GPS未启用处理
if (!isGpsEnabled) { if (!isGpsEnabled) {
String tip = "GPS准备失败系统GPS未开启"; String tip = "GPS准备失败系统GPS未开启";
LogUtils.e(TAG, tip); LogUtils.e(TAG, tip);
@@ -781,25 +766,24 @@ public class MainService extends Service {
return true; return true;
} }
// 启动GPS持续监听运动状态回调调用
public void startGpsLocation() { public void startGpsLocation() {
if (!checkGpsReady()) { if (!checkGpsReady() || isGpsListening) {
return; return;
} }
try { try {
// 注册GPS位置更新
mLocationManager.requestLocationUpdates( mLocationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, LocationManager.GPS_PROVIDER,
GPS_UPDATE_INTERVAL, GPS_UPDATE_INTERVAL,
GPS_UPDATE_DISTANCE, GPS_UPDATE_DISTANCE,
mGpsLocationListener, mGpsLocationListener,
Looper.getMainLooper() Looper.getMainLooper()
); );
// 新增标记GPS进入持续监听状态
isGpsListening = true; isGpsListening = true;
// 获取最后已知GPS位置 // 获取最后已知位置
Location lastKnownLocation = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); Location lastKnownLocation = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (lastKnownLocation != null) { if (lastKnownLocation != null) {
PositionModel lastGpsPos = new PositionModel(); PositionModel lastGpsPos = new PositionModel();
@@ -820,31 +804,31 @@ public class MainService extends Service {
LogUtils.e(TAG, error); LogUtils.e(TAG, error);
notifyAllGpsStatusListeners(error); notifyAllGpsStatusListeners(error);
isGpsPermissionGranted = false; isGpsPermissionGranted = false;
isGpsListening = false; // 新增:异常时重置监听状态 isGpsListening = false;
updateNotificationGpsStatus("定位权限异常无法获取GPS"); updateNotificationGpsStatus("定位权限异常无法获取GPS");
} catch (Exception e) { } catch (Exception e) {
String error = "启动GPS失败" + e.getMessage(); String error = "启动GPS失败" + e.getMessage();
LogUtils.e(TAG, error); LogUtils.e(TAG, error);
notifyAllGpsStatusListeners(error); notifyAllGpsStatusListeners(error);
isGpsListening = false; // 新增:异常时重置监听状态 isGpsListening = false;
updateNotificationGpsStatus("GPS启动失败尝试重试..."); updateNotificationGpsStatus("GPS启动失败尝试重试...");
} }
} }
// 停止GPS持续监听运动状态回调调用
public void stopGpsLocation() { public void stopGpsLocation() {
// 校验参数:避免空指针+权限未授予时调用
if (mLocationManager != null && mGpsLocationListener != null && isGpsPermissionGranted) { if (mLocationManager != null && mGpsLocationListener != null && isGpsPermissionGranted) {
try { try {
mLocationManager.removeUpdates(mGpsLocationListener); mLocationManager.removeUpdates(mGpsLocationListener);
String tip = "GPS定位已停止移除监听器"; String tip = "GPS定位已停止移除监听器";
LogUtils.d(TAG, tip); LogUtils.d(TAG, tip);
notifyAllGpsStatusListeners(tip); notifyAllGpsStatusListeners(tip);
isGpsListening = false; // 新增:停止监听时重置状态 isGpsListening = false;
} catch (Exception e) { } catch (Exception e) {
String error = "停止GPS失败" + e.getMessage(); String error = "停止GPS失败" + e.getMessage();
LogUtils.e(TAG, error); LogUtils.e(TAG, error);
notifyAllGpsStatusListeners(error); notifyAllGpsStatusListeners(error);
isGpsListening = false; // 新增:异常时重置状态 isGpsListening = false;
} }
} }
} }
@@ -855,20 +839,17 @@ public class MainService extends Service {
return; return;
} }
// 格式化通知内容
final String triggerContent = String.format( final String triggerContent = String.format(
"任务触发:%s\n位置%s\n当前距离%.1f米(条件:%s%d米", "任务触发:%s\n位置%s\n当前距离%.1f米(条件:%s%d米",
task.getTaskDescription(), task.getTaskDescription(),
bindPos.getMemo(), bindPos.getMemo(),
currentDistance, currentDistance,
task.isGreaterThan() ? ">" : "<", task.isGreaterThan() ? ">" : "<",
task.getDiscussDistance() task.getDiscussDistance()
); );
// 更新前台通知
updateNotificationGpsStatus(triggerContent); updateNotificationGpsStatus(triggerContent);
// 显示Toast主线程安全
if (Looper.myLooper() == Looper.getMainLooper()) { if (Looper.myLooper() == Looper.getMainLooper()) {
ToastUtils.show(triggerContent); ToastUtils.show(triggerContent);
NotificationUtil.show(MainService.this, task.getTaskId(), task.getPositionId(), task.getTaskDescription()); NotificationUtil.show(MainService.this, task.getTaskId(), task.getPositionId(), task.getTaskDescription());
@@ -887,7 +868,6 @@ public class MainService extends Service {
// 更新前台通知的GPS状态 // 更新前台通知的GPS状态
void updateNotificationGpsStatus(final String statusText) { void updateNotificationGpsStatus(final String statusText) {
if (_mIsServiceRunning) { if (_mIsServiceRunning) {
// 主线程判断+切换
if (Looper.myLooper() == Looper.getMainLooper()) { if (Looper.myLooper() == Looper.getMainLooper()) {
NotificationUtil.updateForegroundServiceStatus(this, statusText); NotificationUtil.updateForegroundServiceStatus(this, statusText);
} else { } else {
@@ -903,7 +883,7 @@ public class MainService extends Service {
// ========================================================================= // =========================================================================
// GPS监听通知相关方法Java 7 语法) // GPS监听通知相关方法
// ========================================================================= // =========================================================================
public void notifyAllGpsListeners(PositionModel currentGpsPos) { public void notifyAllGpsListeners(PositionModel currentGpsPos) {
if (currentGpsPos == null || mGpsListeners.isEmpty()) { if (currentGpsPos == null || mGpsListeners.isEmpty()) {
@@ -916,102 +896,101 @@ public class MainService extends Service {
GpsUpdateListener listener = ref.get(); GpsUpdateListener listener = ref.get();
if (listener != null) { if (listener != null) {
notifySingleListener(listener, currentGpsPos); notifySingleListener(listener, currentGpsPos);
} else { } else {
iter.remove(); // 清理已回收监听者 iter.remove();
} }
} }
} }
} }
private void notifySingleListener(final GpsUpdateListener listener, final PositionModel currentGpsPos) { private void notifySingleListener(final GpsUpdateListener listener, final PositionModel currentGpsPos) {
if (Looper.myLooper() == Looper.getMainLooper()) { if (Looper.myLooper() == Looper.getMainLooper()) {
listener.onGpsPositionUpdated(currentGpsPos); listener.onGpsPositionUpdated(currentGpsPos);
} else { } else {
new Handler(Looper.getMainLooper()).post(new Runnable() { new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override @Override
public void run() { public void run() {
listener.onGpsPositionUpdated(currentGpsPos); listener.onGpsPositionUpdated(currentGpsPos);
} }
}); });
} }
} }
private void notifyAllGpsStatusListeners(final String status) { private void notifyAllGpsStatusListeners(final String status) {
if (status == null || mGpsListeners.isEmpty()) { if (status == null || mGpsListeners.isEmpty()) {
return; return;
} }
synchronized (mListenerLock) { synchronized (mListenerLock) {
Iterator<WeakReference<GpsUpdateListener>> iter = mGpsListeners.iterator(); Iterator<WeakReference<GpsUpdateListener>> iter = mGpsListeners.iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
WeakReference<GpsUpdateListener> ref = iter.next(); WeakReference<GpsUpdateListener> ref = iter.next();
final GpsUpdateListener listener = ref.get(); final GpsUpdateListener listener = ref.get();
if (listener != null) { if (listener != null) {
// 主线程切换避免UI异常 if (Looper.myLooper() == Looper.getMainLooper()) {
if (Looper.myLooper() == Looper.getMainLooper()) { listener.onGpsStatusChanged(status);
listener.onGpsStatusChanged(status); } else {
} else { new Handler(Looper.getMainLooper()).post(new Runnable() {
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override @Override
public void run() { public void run() {
listener.onGpsStatusChanged(status); listener.onGpsStatusChanged(status);
} }
}); });
} }
} else { } else {
iter.remove(); // 清理无效弱引用 iter.remove();
} }
} }
} }
} }
public void registerGpsUpdateListener(GpsUpdateListener listener) { public void registerGpsUpdateListener(GpsUpdateListener listener) {
if (listener == null) { if (listener == null) {
LogUtils.w(TAG, "registerGpsUpdateListener监听者为空"); LogUtils.w(TAG, "registerGpsUpdateListener监听者为空");
return; return;
} }
synchronized (mListenerLock) { synchronized (mListenerLock) {
mGpsListeners.add(new WeakReference<GpsUpdateListener>(listener)); mGpsListeners.add(new WeakReference<GpsUpdateListener>(listener));
LogUtils.d(TAG, "GPS监听注册成功当前数量" + mGpsListeners.size()); LogUtils.d(TAG, "GPS监听注册成功当前数量" + mGpsListeners.size());
// 注册后推送当前GPS位置避免监听者遗漏初始数据 if (_mCurrentGpsPosition != null) {
if (_mCurrentGpsPosition != null) { notifySingleListener(listener, _mCurrentGpsPosition);
notifySingleListener(listener, _mCurrentGpsPosition); }
} }
} }
}
public void unregisterGpsUpdateListener(GpsUpdateListener listener) { public void unregisterGpsUpdateListener(GpsUpdateListener listener) {
if (listener == null) { if (listener == null) {
LogUtils.w(TAG, "unregisterGpsUpdateListener监听者为空"); LogUtils.w(TAG, "unregisterGpsUpdateListener监听者为空");
return; return;
} }
synchronized (mListenerLock) { synchronized (mListenerLock) {
Iterator<WeakReference<GpsUpdateListener>> iter = mGpsListeners.iterator(); Iterator<WeakReference<GpsUpdateListener>> iter = mGpsListeners.iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
WeakReference<GpsUpdateListener> ref = iter.next(); WeakReference<GpsUpdateListener> ref = iter.next();
if (ref.get() == listener || ref.get() == null) { if (ref.get() == listener || ref.get() == null) {
iter.remove(); iter.remove();
LogUtils.d(TAG, "GPS监听反注册成功当前数量" + mGpsListeners.size()); LogUtils.d(TAG, "GPS监听反注册成功当前数量" + mGpsListeners.size());
break; break;
} }
} }
} }
} }
// ========================================================================= // =========================================================================
// LocalBinder 定义(与Activity绑定用Java 7 内部类 // LocalBinder 定义(无修改
// ========================================================================= // =========================================================================
public class LocalBinder extends android.os.Binder { public class LocalBinder extends android.os.Binder {
private MainService mService; private MainService mService;
public LocalBinder(MainService service) { public LocalBinder(MainService service) {
this.mService = service; this.mService = service;
} }
public MainService getService() { public MainService getService() {
return mService; // 暴露MainService实例给绑定的Activity return mService;
} }
} }
} }

View File

@@ -0,0 +1,194 @@
package cc.winboll.studio.positions.utils;
/**
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
* @Date 2025/11/10 09:51
* @Describe 应用图标切换工具类(启用组件时创建对应快捷方式)
*/
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.widget.Toast;
import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.positions.App;
import cc.winboll.studio.positions.MainActivity;
public class APPPlusUtils {
public static final String TAG = "APPPlusUtils";
// 快捷方式配置(名称+图标,需与实际资源匹配)
// private static final String PLUS_SHORTCUT_NAME = "位置服务-Laojun";
// private static final int PLUS_SHORTCUT_ICON = R.mipmap.ic_launcher; // Laojun 图标资源
/**
* 添加Plus组件与图标
*/
public static boolean openAPPPlus(Context context) {
if (context == null) {
LogUtils.d(TAG, "切换失败:上下文为空");
Toast.makeText(context, "图标切换失败", Toast.LENGTH_SHORT).show();
return false;
}
PackageManager pm = context.getPackageManager();
ComponentName plusComponentLaojun = new ComponentName(context, App.COMPONENT_LAOJUN);
//ComponentName plusComponentWuKong = new ComponentName(context, MainActivity.COMPONENT_WUKONG);
try {
//disableComponent(pm, plusComponentWuKong);
enableComponent(pm, plusComponentLaojun);
// 2. 创建 Laojun 组件对应的快捷方式(自动去重)
// boolean shortcutCreated = createComponentShortcut(context, plusComponent, PLUS_SHORTCUT_NAME, PLUS_SHORTCUT_ICON);
//
// // 3. 通知桌面刷新图标
// context.sendBroadcast(new Intent(Intent.ACTION_PACKAGE_CHANGED)
// .setData(android.net.Uri.parse("package:" + context.getPackageName())));
//
// // 4. 反馈结果
// String logMsg = shortcutCreated ? "启用 Laojun + 快捷方式创建成功" : "启用 Laojun 成功,快捷方式创建失败";
// String toastMsg = shortcutCreated ? "图标切换为 Laojun已创建快捷方式" : "图标切换为 Laojun快捷方式创建失败";
// LogUtils.d(TAG, logMsg);
// Toast.makeText(context, toastMsg, Toast.LENGTH_SHORT).show();
//
return true;
} catch (Exception e) {
LogUtils.e(TAG, "Laojun 图标切换失败:" + e.getMessage());
// 失败兜底:启用 Wukong 组件
//enableComponent(pm, wukongComponent);
Toast.makeText(context, "图标切换失败" + e.getMessage(), Toast.LENGTH_SHORT).show();
return false;
}
}
/**
* 移除Plus组件
*/
public static boolean closeAPPPlus(Context context) {
if (context == null) {
LogUtils.d(TAG, "切换失败:上下文为空");
Toast.makeText(context, "图标切换失败", Toast.LENGTH_SHORT).show();
return false;
}
PackageManager pm = context.getPackageManager();
ComponentName plusComponentLaojun = new ComponentName(context, App.COMPONENT_LAOJUN);
//ComponentName plusComponentWuKong = new ComponentName(context, MainActivity.COMPONENT_WUKONG);
disableComponent(pm, plusComponentLaojun);
//enableComponent(pm, plusComponentWuKong);
return true;
}
/**
* 创建指定组件的桌面快捷方式(自动去重,兼容 Android 8.0+
* @param component 目标组件(如 LAOJUN_ACTIVITY
* @param name 快捷方式名称
* @param iconRes 快捷方式图标资源ID
* @return 是否创建成功
*/
private static boolean createComponentShortcut(Context context, ComponentName component, String name, int iconRes) {
if (context == null || component == null || name == null || iconRes == 0) {
LogUtils.d(TAG, "快捷方式创建失败:参数为空");
return false;
}
// Android 8.0+API 26+):使用 ShortcutManager系统推荐
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
try {
PackageManager pm = context.getPackageManager();
android.content.pm.ShortcutManager shortcutManager = context.getSystemService(android.content.pm.ShortcutManager.class);
if (shortcutManager == null || !shortcutManager.isRequestPinShortcutSupported()) {
LogUtils.d(TAG, "系统不支持创建快捷方式");
return false;
}
// 检查是否已存在该组件的快捷方式(去重)
for (android.content.pm.ShortcutInfo info : shortcutManager.getPinnedShortcuts()) {
if (component.getClassName().equals(info.getIntent().getComponent().getClassName())) {
LogUtils.d(TAG, "快捷方式已存在:" + component.getClassName());
return true;
}
}
// 构建启动目标组件的意图
Intent launchIntent = new Intent(Intent.ACTION_MAIN)
.setComponent(component)
.addCategory(Intent.CATEGORY_LAUNCHER)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
// 构建快捷方式信息
android.content.pm.ShortcutInfo shortcutInfo = new android.content.pm.ShortcutInfo.Builder(context, component.getClassName())
.setShortLabel(name)
.setLongLabel(name)
.setIcon(android.graphics.drawable.Icon.createWithResource(context, iconRes))
.setIntent(launchIntent)
.build();
// 请求创建快捷方式(需用户确认)
shortcutManager.requestPinShortcut(shortcutInfo, null);
return true;
} catch (Exception e) {
LogUtils.d(TAG, "Android O+ 快捷方式创建失败:" + e.getMessage());
return false;
}
} else {
// Android 8.0 以下:使用广播(兼容旧机型)
try {
// 构建启动目标组件的意图
Intent launchIntent = new Intent(Intent.ACTION_MAIN)
.setComponent(component)
.addCategory(Intent.CATEGORY_LAUNCHER)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
// 构建创建快捷方式的广播意图
Intent installIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
installIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launchIntent);
installIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
installIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(context, iconRes));
installIntent.putExtra("duplicate", false); // 禁止重复创建
context.sendBroadcast(installIntent);
return true;
} catch (Exception e) {
LogUtils.d(TAG, "Android O- 快捷方式创建失败:" + e.getMessage());
return false;
}
}
}
/**
* 启用组件(带状态检查,避免重复操作)
*/
private static void enableComponent(PackageManager pm, ComponentName component) {
if (pm.getComponentEnabledSetting(component) != PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
pm.setComponentEnabledSetting(
component,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP | PackageManager.SYNCHRONOUS
);
}
}
/**
* 禁用组件(带状态检查,避免重复操作)
*/
private static void disableComponent(PackageManager pm, ComponentName component) {
if (pm.getComponentEnabledSetting(component) != PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
pm.setComponentEnabledSetting(
component,
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP | PackageManager.SYNCHRONOUS
);
}
}
}

View File

@@ -0,0 +1,148 @@
package cc.winboll.studio.positions.utils;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.text.TextUtils;
import cc.winboll.studio.libappbase.LogUtils;
/**
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
* @Date 2025/11/15 15:23
* @Describe Activity Alias 工具类(兼容 Android 所有版本Java 7 语法)
* 用于获取 activity-alias 对应的原始 Activity 组件名、判断 alias 类型、获取启动组件名等
*/
public class ActivityAliasUtils {
private static final String TAG = "ActivityAliasUtils";
/**
* 获取 activity-alias 指向的原始 Activity 组件名
*
* @param context 上下文(建议用 ApplicationContext
* @param aliasName activity-alias 的组件名(完整路径,如 ".AliasActivity" 或 "com.winboll.app.AliasActivity"
* @return 原始 Activity 的完整组件名(如 "com.winboll.app.OriginalActivity"),失败返回 null
*/
public static String getTargetActivityName(Context context, String aliasName) {
// 校验参数
if (context == null || TextUtils.isEmpty(aliasName)) {
LogUtils.e(TAG, "getTargetActivityName: context is null or aliasName is empty");
return null;
}
// 补全组件名(若传入的是短名,自动拼接包名)
String fullAliasName = aliasName.startsWith(".")
? context.getPackageName() + aliasName
: aliasName;
try {
// 1. 获取 PackageManager
PackageManager packageManager = context.getPackageManager();
// 2. 解析 activity-alias 的 ActivityInfoflag 必须设为 PackageManager.GET_META_DATA否则可能获取不到 targetActivity
ActivityInfo aliasActivityInfo = packageManager.getActivityInfo(
new android.content.ComponentName(context.getPackageName(), fullAliasName),
PackageManager.GET_META_DATA
);
// 3. 获取 targetActivity原始 Activity 组件名)
String targetActivity = aliasActivityInfo.targetActivity;
if (TextUtils.isEmpty(targetActivity)) {
LogUtils.e(TAG, "getTargetActivityName: targetActivity is empty for alias " + fullAliasName);
return null;
}
// 4. 补全原始 Activity 的完整包名(若 targetActivity 是短名)
String fullTargetName = targetActivity.startsWith(".")
? context.getPackageName() + targetActivity
: targetActivity;
LogUtils.d(TAG, "getTargetActivityName: alias=" + fullAliasName + ", target=" + fullTargetName);
return fullTargetName;
} catch (PackageManager.NameNotFoundException e) {
LogUtils.e(TAG, "getTargetActivityName: alias not found - " + fullAliasName, e);
} catch (Exception e) {
LogUtils.e(TAG, "getTargetActivityName: unknown error", e);
}
return null;
}
/**
* 判断某个组件名是否为 activity-alias而非原始 Activity
*
* @param context 上下文
* @param componentName 待判断的组件名(完整路径)
* @return true是 activity-aliasfalse不是或判断失败
*/
public static boolean isActivityAlias(Context context, String componentName) {
// 调用 getTargetActivityName若返回非空则说明是 alias
return !TextUtils.isEmpty(getTargetActivityName(context, componentName));
}
/**
* 从启动的 Intent 中获取实际的目标组件名(处理 alias 场景)
* 适用于 Activity 中获取自身真实组件名(原始 Activity 名)
*
* @param context 当前 Activity 上下文
* @return 真实的目标组件名(原始 Activity 名,若为 alias 启动则返回原始 Activity否则返回自身
*/
public static String getRealTargetNameFromIntent(Context context) {
if (context == null) {
LogUtils.e(TAG, "getRealTargetNameFromIntent: context is null");
return null;
}
// 获取当前 Activity 的组件名(可能是 alias
String currentComponentName = context.getClass().getName();
// 检查是否为 alias若是则返回 target否则返回自身
String targetName = getTargetActivityName(context, currentComponentName);
return TextUtils.isEmpty(targetName) ? currentComponentName : targetName;
}
/**
* 获取当前活动上下文Activity的启动组件名即启动时使用的组件名可能是 alias 或原始 Activity
* 场景:若通过 alias 启动 Activity返回 alias 名;若直接启动原始 Activity返回原始 Activity 名
*
* @param context 当前 Activity 上下文(必须是 Activity 实例,不能是 ApplicationContext
* @return 启动组件的完整名,失败返回 null
*/
public static String getLaunchComponentName(Context context) {
// 1. 校验上下文类型(必须是 Activity否则无法获取启动 Intent
if (context == null) {
LogUtils.e(TAG, "getLaunchComponentName: context is null");
return null;
}
if (!(context instanceof android.app.Activity)) {
LogUtils.e(TAG, "getLaunchComponentName: context must be Activity instance, current is " + context.getClass().getName());
return null;
}
try {
// 2. 获取启动当前 Activity 的 Intent
android.app.Activity activity = (android.app.Activity) context;
Intent launchIntent = activity.getIntent();
if (launchIntent == null) {
LogUtils.e(TAG, "getLaunchComponentName: launch Intent is null");
return null;
}
// 3. 从 Intent 中获取启动组件名ComponentName
android.content.ComponentName componentName = launchIntent.getComponent();
if (componentName == null) {
LogUtils.e(TAG, "getLaunchComponentName: ComponentName is null in launch Intent");
return null;
}
// 4. 获取组件的完整类名(即启动时使用的组件名)
String launchComponentName = componentName.getClassName();
LogUtils.d(TAG, "getLaunchComponentName: current launch component is " + launchComponentName);
return launchComponentName;
} catch (Exception e) {
LogUtils.e(TAG, "getLaunchComponentName: failed to get launch component name", e);
return null;
}
}
}

View File

@@ -1,6 +1,8 @@
package cc.winboll.studio.positions.utils; package cc.winboll.studio.positions.utils;
import android.content.Context; import android.content.Context;
import cc.winboll.studio.positions.AppLevel;
import cc.winboll.studio.positions.models.AppConfigsModel; import cc.winboll.studio.positions.models.AppConfigsModel;
import cc.winboll.studio.positions.App;
/** /**
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com> * @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
@@ -58,11 +60,27 @@ public class AppConfigsUtil {
} }
public void setIsEnableMainService(boolean isEnableMainService) { public void setIsEnableMainService(boolean isEnableMainService) {
if(mAppConfigsModel == null) { if (mAppConfigsModel == null) {
mAppConfigsModel = new AppConfigsModel(); mAppConfigsModel = new AppConfigsModel();
} }
mAppConfigsModel.setIsEnableMainService(isEnableMainService); mAppConfigsModel.setIsEnableMainService(isEnableMainService);
saveConfigs(); saveConfigs();
} }
public AppLevel getAppLevel(boolean isReloadConfigs) {
if (isReloadConfigs) {
loadConfigs();
}
return (mAppConfigsModel == null) ?AppLevel.WUKONG: mAppConfigsModel.getAppLevel();
}
public void setAppLevel(AppLevel appLevel) {
if (mAppConfigsModel == null) {
mAppConfigsModel = new AppConfigsModel();
}
App._mAppLevel = appLevel;
mAppConfigsModel.setAppLevel(appLevel);
saveConfigs();
}
} }

View File

@@ -0,0 +1,241 @@
package cc.winboll.studio.positions.utils;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;
import android.widget.Toast;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
/**
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
* @Date 2025/11/13 15:42
* @Describe JsonShareHandler
* 外部 JSON 文件分享处理工具类
* 功能:接收外部分享的 .json 文件,弹出确认对话框,保存到外部存储 files/BaseBean 目录
*/
public class JsonShareHandler {
private static final String TAG = "JsonShareHandler";
private static final String TARGET_DIR = "BaseBean";
private static final String MIME_TYPE_JSON = "application/json";
private static final String FILE_SUFFIX_JSON = ".json";
// 对话框回调接口Java7 无 Lambda用接口实现
public interface ConfirmCallback {
void onConfirm(boolean isConfirm);
}
/**
* 处理外部分享的 Intent先弹出确认对话框再决定是否接收文件
* @param context 上下文(需为 Activity否则无法弹出对话框
* @param intent 分享 Intent
* @param callback 确认结果回调(用于 Activity 处理后续逻辑)
*/
public static void handleSharedJsonWithConfirm(final Context context, final Intent intent, final ConfirmCallback callback) {
if (context == null || intent == null || callback == null) {
Log.e(TAG, "参数为空,处理失败");
if (callback != null) callback.onConfirm(false);
return;
}
// 1. 先验证 Intent 合法性(提前过滤无效分享)
String action = intent.getAction();
String type = intent.getType();
if (!Intent.ACTION_SEND.equals(action) || type == null) {
Log.e(TAG, "非文件分享 Intent");
Toast.makeText(context, "不支持的分享类型", Toast.LENGTH_SHORT).show();
callback.onConfirm(false);
return;
}
// 2. 弹出确认对话框
new AlertDialog.Builder(context)
.setTitle("接收 JSON 文件")
.setMessage("是否接收并保存该 JSON 文件?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
// 3. 点击 Yes处理文件保存
String savedPath = handleSharedJsonFile(context, intent);
if (savedPath != null) {
Toast.makeText(context, "文件保存成功:" + savedPath, Toast.LENGTH_LONG).show();
callback.onConfirm(true);
} else {
Toast.makeText(context, "文件保存失败", Toast.LENGTH_SHORT).show();
callback.onConfirm(false);
}
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
// 4. 点击 No直接退出处理
callback.onConfirm(false);
}
})
.setCancelable(false) // 不可点击外部取消
.show();
}
/**
* 核心文件处理逻辑(原有功能,无修改)
*/
private static String handleSharedJsonFile(Context context, Intent intent) {
String action = intent.getAction();
String type = intent.getType();
// 验证 JSON 格式
if (!MIME_TYPE_JSON.equals(type) && !type.contains("json")) {
Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (uri == null || !getFileNameFromUri(context, uri).endsWith(FILE_SUFFIX_JSON)) {
Log.e(TAG, "接收的文件不是 JSON 格式");
return null;
}
}
Uri sharedUri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (sharedUri == null) {
Log.e(TAG, "未获取到分享的文件 Uri");
return null;
}
try {
// 创建保存目录
File saveDir = getTargetSaveDir(context);
if (!saveDir.exists() && !saveDir.mkdirs()) {
Log.e(TAG, "创建保存目录失败:" + saveDir.getAbsolutePath());
return null;
}
// 解析文件名(兼容低版本)
String fileName = getFileNameFromUri(context, sharedUri);
if (fileName == null || !fileName.endsWith(FILE_SUFFIX_JSON)) {
fileName = "default_" + System.currentTimeMillis() + FILE_SUFFIX_JSON;
Log.w(TAG, "文件名解析失败,使用默认名称:" + fileName);
}
// 复制文件
File targetFile = new File(saveDir, fileName);
boolean copySuccess = copyFileFromUri(context, sharedUri, targetFile);
return copySuccess ? targetFile.getAbsolutePath() : null;
} catch (Exception e) {
Log.e(TAG, "处理分享文件异常:" + e.getMessage());
return null;
}
}
/**
* 获取目标保存目录(兼容 Android 10+ 分区存储)
*/
private static File getTargetSaveDir(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
return new File(context.getExternalFilesDir(null), TARGET_DIR);
} else {
return new File(
Environment.getExternalStorageDirectory() + File.separator +
"Android" + File.separator +
"data" + File.separator +
context.getPackageName() + File.separator +
"files" + File.separator +
TARGET_DIR
);
}
}
/**
* 从 Uri 解析文件名(兼容所有 Android 版本)
*/
private static String getFileNameFromUri(Context context, Uri uri) {
if (uri == null) return null;
// 1. 文件 Urifile:// 开头)
if ("file".equals(uri.getScheme())) {
return new File(uri.getPath()).getName();
}
// 2. 内容 Uricontent:// 开头)
if ("content".equals(uri.getScheme())) {
Cursor cursor = null;
try {
cursor = context.getContentResolver().query(
uri,
new String[]{MediaStore.MediaColumns.DISPLAY_NAME},
null,
null,
null
);
if (cursor != null && cursor.moveToFirst()) {
int nameIndex = cursor.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME);
if (nameIndex != -1) {
return cursor.getString(nameIndex);
}
}
} catch (Exception e) {
Log.e(TAG, "解析内容 Uri 文件名失败:" + e.getMessage());
} finally {
if (cursor != null) cursor.close();
}
}
// 3. 解析失败,返回默认名称
String lastPathSegment = uri.getLastPathSegment();
return lastPathSegment != null ? lastPathSegment : "unknown.json";
}
/**
* 复制 Uri 指向的文件到目标路径
*/
private static boolean copyFileFromUri(Context context, Uri sourceUri, File targetFile) {
InputStream inputStream = null;
OutputStream outputStream = null;
try {
inputStream = context.getContentResolver().openInputStream(sourceUri);
if (inputStream == null) {
Log.e(TAG, "无法打开源文件输入流");
return false;
}
outputStream = new FileOutputStream(targetFile);
byte[] buffer = new byte[1024 * 4];
int length;
while ((length = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, length);
}
outputStream.flush();
Log.d(TAG, "文件保存成功:" + targetFile.getAbsolutePath());
return true;
} catch (IOException e) {
Log.e(TAG, "文件复制异常:" + e.getMessage());
return false;
} finally {
try {
if (inputStream != null) inputStream.close();
if (outputStream != null) outputStream.close();
} catch (IOException e) {
Log.e(TAG, "关闭流异常:" + e.getMessage());
}
}
}
/**
* 检查外部存储是否可用
*/
public static boolean isExternalStorageAvailable() {
String state = Environment.getExternalStorageState();
return Environment.MEDIA_MOUNTED.equals(state);
}
}

View File

@@ -0,0 +1,168 @@
package cc.winboll.studio.positions.utils;
/**
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
* @Date 2025/11/05 15:49
* @Describe LocalMotionDetector
*/
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import cc.winboll.studio.libappbase.LogUtils;
/**
* 本机运动状态监测工具(无联网,纯传感器)
*/
public class LocalMotionDetector implements SensorEventListener {
public static final String TAG = "LocalMotionDetector";
// 配置参数(重点修改:调高运动阈值,适配坐立持机场景)
private static final float MOTION_THRESHOLD = 1.8f; // 从0.5f调高到1.8f(过滤坐立轻微晃动)
private static final long STATUS_CHECK_INTERVAL = 3000; // 3秒判断一次状态
private static final int STEP_CHANGE_THRESHOLD = 2; // 3秒≥2步判定行走
private SensorManager mSensorManager;
private Sensor mAccelerometer;
private Sensor mStepCounter;
private Handler mMainHandler;
private MotionStatusCallback mCallback;
private boolean mIsDetecting = false;
private float mLastAccelMagnitude = 0f;
private int mLastStepCount = 0;
private int mCurrentStepCount = 0;
private boolean mIsWalking = false;
// 单例模式
private static LocalMotionDetector sInstance;
public static LocalMotionDetector getInstance() {
if (sInstance == null) {
synchronized (LocalMotionDetector.class) {
if (sInstance == null) {
sInstance = new LocalMotionDetector();
}
}
}
return sInstance;
}
private LocalMotionDetector() {
mMainHandler = new Handler(Looper.getMainLooper());
}
/**
* 开始监测运动状态
*/
public void startDetection(Context context, MotionStatusCallback callback) {
if (mIsDetecting) return;
mCallback = callback;
mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
// 初始化传感器
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
mStepCounter = mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
// 注册传感器监听
if (mAccelerometer != null) {
mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL, mMainHandler);
}
if (mStepCounter != null) {
mSensorManager.registerListener(this, mStepCounter, SensorManager.SENSOR_DELAY_NORMAL, mMainHandler);
LogUtils.d(TAG, "计步传感器已启动");
} else {
LogUtils.d(TAG, "设备不支持计步传感器,仅用加速度判断");
}
// 启动定时状态检测
mMainHandler.postDelayed(mStatusCheckRunnable, STATUS_CHECK_INTERVAL);
mIsDetecting = true;
LogUtils.d(TAG, "运动状态监测已启动");
}
/**
* 停止监测
*/
public void stopDetection() {
if (!mIsDetecting) return;
if (mSensorManager != null) {
mSensorManager.unregisterListener(this);
}
mMainHandler.removeCallbacksAndMessages(null);
mIsDetecting = false;
mIsWalking = false;
mCallback = null;
LogUtils.d(TAG, "运动状态监测已停止");
}
@Override
public void onSensorChanged(SensorEvent event) {
if (!mIsDetecting) return;
switch (event.sensor.getType()) {
case Sensor.TYPE_ACCELEROMETER:
// 计算加速度幅度(保留原逻辑,阈值已调高)
float accelX = Math.abs(event.values[0]);
float accelY = Math.abs(event.values[1]);
float accelZ = Math.abs(event.values[2]);
mLastAccelMagnitude = accelX + accelY + accelZ;
break;
case Sensor.TYPE_STEP_COUNTER:
// 累计步数
mCurrentStepCount = (int) event.values[0];
break;
}
}
/**
* 定时判断运动状态优化逻辑计步为0时即使有轻微加速度也判定为静止
*/
private final Runnable mStatusCheckRunnable = new Runnable() {
@Override
public void run() {
if (!mIsDetecting || mCallback == null) return;
//LogUtils.d(TAG, "mStatusCheckRunnable run");
boolean newIsWalking = false;
// 结合计步器+加速度判断(优化:优先计步,无步数时严格按高阈值判断)
if (mStepCounter != null) {
int stepChange = mCurrentStepCount - mLastStepCount;
// 只有“步数达标” 或 “无步数但加速度远超坐立幅度”,才判定为行走
newIsWalking = (stepChange >= STEP_CHANGE_THRESHOLD)
&& (mLastAccelMagnitude >= MOTION_THRESHOLD); // 增加步数+加速度双重校验
mLastStepCount = mCurrentStepCount;
} else {
// 无计步器时,仅用高阈值判断
newIsWalking = mLastAccelMagnitude >= MOTION_THRESHOLD;
}
// 状态变化时回调
if (newIsWalking != mIsWalking) {
mIsWalking = newIsWalking;
String statusDesc = mIsWalking ? "行走状态" : "静止/低运动状态";
LogUtils.d(TAG, "运动状态变化:" + statusDesc + " | 加速度幅度:" + mLastAccelMagnitude); // 增加日志便于调试
mCallback.onMotionStatusChanged(mIsWalking, statusDesc);
}
LogUtils.d(TAG, String.format("运动状态 newIsWalking %s", newIsWalking));
// 循环检测
mMainHandler.postDelayed(this, STATUS_CHECK_INTERVAL);
}
};
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {}
/**
* 运动状态回调接口
*/
public interface MotionStatusCallback {
void onMotionStatusChanged(boolean isWalking, String statusDesc);
}
}

View File

@@ -0,0 +1,105 @@
package cc.winboll.studio.positions.utils;
import android.app.Activity;
import android.app.Application;
import android.content.Intent;
import android.os.Bundle;
import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.libappbase.ToastUtils;
import cc.winboll.studio.positions.PointLevel;
import cc.winboll.studio.positions.activities.WinBoLLActivity;
/**
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
* @Date 2025/11/15 15:59
* @Describe 应用活动窗口状态响应类
* 主要用于设置应用级别与组件状态
*/
public class MyActivityLifecycleCallbacks implements Application.ActivityLifecycleCallbacks {
public static final String TAG = "MyActivityLifecycleCallbacks";
public String mInfo = "";
public MyActivityLifecycleCallbacks() {
}
void createActivityeInfo(Activity activity) {
StringBuilder sb = new StringBuilder();
Intent receivedIntent = activity.getIntent();
sb.append("\nCallingActivity : \n");
if (activity.getCallingActivity() != null) {
sb.append(activity.getCallingActivity().getPackageName());
}
sb.append("\nReceived Intent Package : \n");
sb.append(receivedIntent.getPackage());
Bundle extras = receivedIntent.getExtras();
if (extras != null) {
for (String key : extras.keySet()) {
sb.append("\nIntentInfo");
sb.append("\n键: ");
sb.append(key);
sb.append(", 值: ");
sb.append(extras.get(key));
//Log.d("IntentInfo", "键: " + key + ", 值: " + extras.get(key));
}
}
mInfo = sb.toString();
//Log.d("IntentInfo", "发送Intent的应用包名: " + senderPackage);
}
public void showActivityeInfo() {
//ToastUtils.show("ActivityeInfo : " + mInfo);
LogUtils.d(TAG, "ActivityeInfo : " + mInfo);
}
@Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
// 在这里可以做一些初始化相关的操作例如记录Activity的创建时间等
//System.out.println(activity.getLocalClassName() + " was created");
LogUtils.d(TAG, activity.getLocalClassName() + " was created");
createActivityeInfo(activity);
}
@Override
public void onActivityStarted(Activity activity) {
//System.out.println(activity.getLocalClassName() + " was started");
LogUtils.d(TAG, activity.getLocalClassName() + " was started");
//createActivityeInfo(activity);
}
@Override
public void onActivityResumed(Activity activity) {
//System.out.println(activity.getLocalClassName() + " was resumed");
LogUtils.d(TAG, activity.getLocalClassName() + " was resumed");
//createActivityeInfo(activity);
}
@Override
public void onActivityPaused(Activity activity) {
ToastUtils.show("Activity Paused");
// 应用从正在活动状态抽离出来时设置应用入口级别状态设置为时空虚幻而不确定的哆啦A梦级别。
WinBoLLActivity._mPointLevel = PointLevel.DORAEMON;
//System.out.println(activity.getLocalClassName() + " was paused");
LogUtils.d(TAG, activity.getLocalClassName() + " was paused");
}
@Override
public void onActivityStopped(Activity activity) {
//System.out.println(activity.getLocalClassName() + " was stopped");
LogUtils.d(TAG, activity.getLocalClassName() + " was stopped");
}
@Override
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
// 可以在这里添加保存状态的自定义逻辑
}
@Override
public void onActivityDestroyed(Activity activity) {
//System.out.println(activity.getLocalClassName() + " was destroyed");
LogUtils.d(TAG, activity.getLocalClassName() + " was destroyed");
}
}

View File

@@ -0,0 +1,282 @@
package cc.winboll.studio.positions.views;
/**
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
* @Date 2025/11/10 08:29
* @Describe 沙漏计时器控件
*/
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ClipDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.text.InputFilter;
import android.text.InputType;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.Switch;
import android.widget.TextView;
/**
* 沙漏视图类Java 7语法修复ProgressDrawable和setHeight问题
*/
public class HourglassView extends LinearLayout {
public static final String TAG = "HourglassView";
// 数据模型
private String hourglassId;
private int hour; // 小时
private int minute; // 分钟
private boolean isEnabled; // 开关状态
// 控件引用
private EditText etHour;
private EditText etMinute;
private ProgressBar progressBar;
private Switch switchControl;
// 样式参数
private int textSize = 16;
private int padding = 8;
private int progressColor = 0xFF2196F3; // 进度条颜色
private int progressBgColor = 0xFFE0E0E0; // 进度条背景色
private int textColor = 0xFF333333;
private int editTextWidth = 40; // 输入框宽度dp
private int progressHeight = 8; // 进度条高度dp新增参数
public HourglassView(Context context) {
super(context);
initView();
}
public HourglassView(Context context, AttributeSet attrs) {
super(context, attrs);
initView();
}
/**
* 初始化视图布局
*/
private void initView() {
setOrientation(HORIZONTAL);
setGravity(Gravity.CENTER_VERTICAL);
setPadding(dp2px(padding), dp2px(padding), dp2px(padding), dp2px(padding));
// 1. 左侧时间输入区域(水平布局)
LinearLayout inputLayout = new LinearLayout(getContext());
inputLayout.setOrientation(HORIZONTAL);
inputLayout.setGravity(Gravity.CENTER_VERTICAL);
LayoutParams inputParams = new LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT
);
inputParams.setMargins(0, 0, dp2px(padding * 2), 0);
addView(inputLayout, inputParams);
// 小时输入框
etHour = createNumberEditText();
etHour.setHint("");
etHour.setFilters(new InputFilter[]{new InputFilter.LengthFilter(2)});
inputLayout.addView(etHour, getEditTextParams());
// 分隔符
TextView divider = new TextView(getContext());
divider.setText(":");
divider.setTextSize(textSize);
divider.setTextColor(textColor);
LayoutParams dividerParams = new LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT
);
dividerParams.setMargins(dp2px(padding / 2), 0, dp2px(padding / 2), 0);
inputLayout.addView(divider, dividerParams);
// 分钟输入框
etMinute = createNumberEditText();
etMinute.setHint("");
etMinute.setFilters(new InputFilter[]{new InputFilter.LengthFilter(2)});
inputLayout.addView(etMinute, getEditTextParams());
// 2. 中间进度条修复通过LayoutParams设置高度替代setHeight
progressBar = new ProgressBar(getContext(), null, android.R.attr.progressBarStyleHorizontal);
progressBar.setProgressDrawable(createProgressDrawable()); // 传入Drawable类型
// 修复核心用LayoutParams设置进度条高度兼容低版本
LayoutParams progressParams = new LayoutParams(
0,
dp2px(progressHeight), // 直接在布局参数中设置高度dp转px
1.0f
);
progressParams.setMargins(0, 0, dp2px(padding * 2), 0);
addView(progressBar, progressParams);
// 3. 右侧开关
switchControl = new Switch(getContext());
switchControl.setOnCheckedChangeListener(new Switch.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(android.widget.CompoundButton buttonView, boolean isChecked) {
isEnabled = isChecked;
// 开关状态控制输入框是否可编辑
etHour.setEnabled(!isChecked);
etMinute.setEnabled(!isChecked);
// 更新进度条(仅在开关开启时生效)
if (isChecked) {
updateProgressBar();
}
}
});
addView(switchControl);
// 初始状态
isEnabled = false;
etHour.setEnabled(true);
etMinute.setEnabled(true);
}
/**
* 创建数字输入框
*/
private EditText createNumberEditText() {
EditText editText = new EditText(getContext());
editText.setInputType(InputType.TYPE_CLASS_NUMBER);
editText.setTextSize(textSize);
editText.setTextColor(textColor);
editText.setGravity(Gravity.CENTER);
editText.setSingleLine(true);
editText.setBackgroundResource(android.R.drawable.edit_text); // 默认输入框背景
return editText;
}
/**
* 获取输入框布局参数
*/
private LayoutParams getEditTextParams() {
LayoutParams params = new LayoutParams(
dp2px(editTextWidth),
ViewGroup.LayoutParams.WRAP_CONTENT
);
params.setMargins(0, 0, dp2px(padding), 0);
return params;
}
/**
* 修复核心创建ProgressDrawable返回Drawable类型而非Paint
* 用LayerDrawable实现「背景+进度」的双层进度条
*/
private Drawable createProgressDrawable() {
// 1. 进度条背景(灰色)
ColorDrawable bgDrawable = new ColorDrawable(progressBgColor);
// 2. 进度条前景(主题色)
ColorDrawable progressDrawable = new ColorDrawable(progressColor);
// 3. 用ClipDrawable包裹前景实现进度裁剪
ClipDrawable clipDrawable = new ClipDrawable(progressDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL);
// 4. 组合成LayerDrawable顺序背景在下进度在上
Drawable[] layers = new Drawable[]{bgDrawable, clipDrawable};
LayerDrawable layerDrawable = new LayerDrawable(layers);
// 5. 设置进度条的层级ID必须与系统ProgressBar的ID匹配
layerDrawable.setId(0, android.R.id.background);
layerDrawable.setId(1, android.R.id.progress);
return layerDrawable;
}
/**
* 更新进度条(总时间 = 小时*60 + 分钟,单位:分钟)
*/
private void updateProgressBar() {
try {
// 获取输入的时间为空时默认0
int inputHour = TextUtils.isEmpty(etHour.getText().toString().trim())
? 0 : Integer.parseInt(etHour.getText().toString().trim());
int inputMinute = TextUtils.isEmpty(etMinute.getText().toString().trim())
? 0 : Integer.parseInt(etMinute.getText().toString().trim());
// 校验时间合法性小时0-99分钟0-59
inputHour = Math.max(0, Math.min(99, inputHour));
inputMinute = Math.max(0, Math.min(59, inputMinute));
// 计算总分钟数(进度条最大值)
int totalMinutes = inputHour * 60 + inputMinute;
totalMinutes = Math.max(1, totalMinutes); // 最小1分钟避免进度条无长度
// 更新进度条
progressBar.setMax(totalMinutes);
progressBar.setProgress(totalMinutes); // 初始显示满进度,可根据实际需求修改
// 更新数据模型
this.hour = inputHour;
this.minute = inputMinute;
} catch (NumberFormatException e) {
// 输入非法时重置进度条
progressBar.setMax(0);
progressBar.setProgress(0);
}
}
/**
* dp转px适配不同设备
*/
private int dp2px(int dp) {
return (int) (dp * getContext().getResources().getDisplayMetrics().density + 0.5f);
}
// ------------------- 数据模型 getter/setter -------------------
public String getHourglassId() {
return hourglassId;
}
public void setHourglassId(String hourglassId) {
this.hourglassId = hourglassId;
}
public int getHour() {
return hour;
}
public void setHour(int hour) {
this.hour = Math.max(0, Math.min(99, hour)); // 限制范围
etHour.setText(String.valueOf(this.hour));
}
public int getMinute() {
return minute;
}
public void setMinute(int minute) {
this.minute = Math.max(0, Math.min(59, minute)); // 限制范围
etMinute.setText(String.valueOf(this.minute));
}
public boolean isEnabled() {
return isEnabled;
}
public void setEnabled(boolean enabled) {
isEnabled = enabled;
switchControl.setChecked(enabled);
}
/**
* 手动更新进度条(外部调用)
*/
public void refreshProgress() {
if (isEnabled) {
updateProgressBar();
}
}
// 工具类判断字符串是否为空Java7无TextUtils.isEmpty手动实现
private static class TextUtils {
public static boolean isEmpty(CharSequence str) {
return str == null || str.length() == 0;
}
}
}

View File

@@ -33,6 +33,10 @@ import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import cc.winboll.studio.positions.App;
import cc.winboll.studio.positions.AppLevel;
import cc.winboll.studio.positions.activities.WinBoLLActivity;
import cc.winboll.studio.positions.PointLevel;
public class PositionTaskListView extends LinearLayout { public class PositionTaskListView extends LinearLayout {
// 视图模式常量 // 视图模式常量
@@ -380,7 +384,7 @@ public class PositionTaskListView extends LinearLayout {
// 步骤3刷新Adapter局部刷新+范围通知,避免列表错乱) // 步骤3刷新Adapter局部刷新+范围通知,避免列表错乱)
notifyItemRemoved(position); notifyItemRemoved(position);
notifyItemRangeChanged(position, mAdapterData.size()); notifyItemRangeChanged(position, mAdapterData.size());
LogUtils.d(TAG, "Adapter已移除任务刷新列表位置索引=" + position + ""); LogUtils.d(TAG, "Adapter已移除任务刷新列表位置索引=" + position + "");
// 步骤4通知外部如Activity任务已更新 // 步骤4通知外部如Activity任务已更新
@@ -457,7 +461,7 @@ public class PositionTaskListView extends LinearLayout {
} }
}); });
} }
private String genSelectedTimeText(long timeMillis) { private String genSelectedTimeText(long timeMillis) {
// 2. 格式化时间字符串Java 7 用 SimpleDateFormat需处理 ParseException // 2. 格式化时间字符串Java 7 用 SimpleDateFormat需处理 ParseException
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault()); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault());
@@ -483,6 +487,16 @@ public class PositionTaskListView extends LinearLayout {
final EditText etEditDistance = dialogView.findViewById(R.id.et_edit_distance); final EditText etEditDistance = dialogView.findViewById(R.id.et_edit_distance);
Button btnCancel = dialogView.findViewById(R.id.btn_dialog_cancel); Button btnCancel = dialogView.findViewById(R.id.btn_dialog_cancel);
Button btnSave = dialogView.findViewById(R.id.btn_dialog_save); Button btnSave = dialogView.findViewById(R.id.btn_dialog_save);
HourglassView hourglassView = dialogView.findViewById(R.id.hourglassView);
if (WinBoLLActivity._mPointLevel == PointLevel.WUKONG) {
hourglassView.setVisibility(View.GONE);
} else if (WinBoLLActivity._mPointLevel == PointLevel.LAOJUN) {
hourglassView.setHourglassId("hourglass_001");
hourglassView.setHour(1);
hourglassView.setMinute(30);
hourglassView.setEnabled(false); // 开启开关
}
// 绑定外层对话框内的控件 // 绑定外层对话框内的控件

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

View File

@@ -65,6 +65,16 @@
</LinearLayout> </LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<cc.winboll.studio.positions.views.HourglassView
android:id="@+id/hourglassView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout <LinearLayout
android:orientation="horizontal" android:orientation="horizontal"
android:layout_width="match_parent" android:layout_width="match_parent"
@@ -77,7 +87,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="开始时间" android:text="开始时间"
android:id="@+id/btn_select_time"/> android:id="@+id/btn_select_time"/>
<TextView <TextView
android:id="@+id/tv_selected_time" android:id="@+id/tv_selected_time"
android:layout_width="0dp" android:layout_width="0dp"
@@ -85,7 +95,6 @@
android:text="Text" android:text="Text"
android:layout_weight="1.0"/> android:layout_weight="1.0"/>
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout

View File

@@ -1,4 +1,9 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string name="app_name">悟空笔记</string> <string name="app_name">悟空笔记</string>
<string name="appplus_name">时空任务</string>
<string name="open_appplus">开疆扩土</string>
<string name="close_appplus">返璞归真</string>
<string name="appplus_open_disabled">余力不足</string>
<string name="appplus_close_disabled">辎重难返</string>
</resources> </resources>

View File

@@ -1,3 +1,8 @@
<resources> <resources>
<string name="app_name">Positions</string> <string name="app_name">Positions</string>
<string name="appplus_name">PositionsPlus</string>
<string name="open_appplus">Open APP Plus</string>
<string name="close_appplus">Close APP Plus</string>
<string name="appplus_open_disabled">APP Plus Open Disable</string>
<string name="appplus_close_disabled">APP Plus Close Disable</string>
</resources> </resources>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-files-path
name="BaseBean"
path="BaseBean/" />
</paths>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 切换启动入口的快捷菜单 -->
<shortcut
android:shortcutId="open_appplus"
android:enabled="true"
android:icon="@mipmap/ic_launcher"
android:shortcutShortLabel="@string/open_appplus"
android:shortcutLongLabel="@string/open_appplus"
android:shortcutDisabledMessage="@string/appplus_open_disabled">
<intent
android:action="cc.winboll.studio.positions.App.ACTION_OPEN_APPPLUS"
android:targetPackage="cc.winboll.studio.positions"
android:targetClass="cc.winboll.studio.positions.activities.ShortcutActionActivity"
android:data="open_appplus" />
<categories android:name="android.shortcut.conversation" />
</shortcut>
</shortcuts>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 切换启动入口的快捷菜单 -->
<shortcut
android:shortcutId="close_appplus"
android:enabled="true"
android:icon="@mipmap/ic_launcher"
android:shortcutShortLabel="@string/close_appplus"
android:shortcutLongLabel="@string/close_appplus"
android:shortcutDisabledMessage="@string/appplus_close_disabled">
<intent
android:action="cc.winboll.studio.positions.App.ACTION_CLOSE_APPPLUS"
android:targetPackage="cc.winboll.studio.positions"
android:targetClass="cc.winboll.studio.positions.activities.ShortcutActionActivity"
android:data="close_appplus" />
<categories android:name="android.shortcut.conversation" />
</shortcut>
</shortcuts>