feat(IdleGpsService): 添加手动控制空转GPS服务的启动/停止逻辑
- 新增 IdleGpsService.start() 和 stop() 方法,支持外部手动控制服务状态 - 在 MainActivity 菜单切换空转状态时,联动启动/停止空转GPS服务 - 优化模拟坐标更新间隔从1秒调整为5秒,降低资源消耗 - 添加空转日志记录,便于追踪GPS服务状态变更
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
#Created by .winboll/winboll_app_build.gradle
|
#Created by .winboll/winboll_app_build.gradle
|
||||||
#Sun May 03 15:20:10 CST 2026
|
#Sun May 03 18:27:26 CST 2026
|
||||||
stageCount=20
|
stageCount=20
|
||||||
libraryProject=
|
libraryProject=
|
||||||
baseVersion=15.12
|
baseVersion=15.12
|
||||||
publishVersion=15.12.19
|
publishVersion=15.12.19
|
||||||
buildCount=11
|
buildCount=21
|
||||||
baseBetaVersion=15.12.20
|
baseBetaVersion=15.12.20
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import cc.winboll.studio.positions.activities.WinBoLLActivity;
|
|||||||
import cc.winboll.studio.positions.handlers.AppIdleRunningModeHandler;
|
import cc.winboll.studio.positions.handlers.AppIdleRunningModeHandler;
|
||||||
import cc.winboll.studio.positions.utils.AppConfigsUtil;
|
import cc.winboll.studio.positions.utils.AppConfigsUtil;
|
||||||
import cc.winboll.studio.positions.utils.ServiceUtil;
|
import cc.winboll.studio.positions.utils.ServiceUtil;
|
||||||
|
import cc.winboll.studio.positions.services.IdleGpsService;
|
||||||
import cc.winboll.studio.positions.R;
|
import cc.winboll.studio.positions.R;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -341,6 +342,11 @@ public class MainActivity extends WinBoLLActivity implements IWinBoLLActivity {
|
|||||||
boolean idleNow = App.isAppIdleRunning();
|
boolean idleNow = App.isAppIdleRunning();
|
||||||
boolean idleNew = !idleNow;
|
boolean idleNew = !idleNow;
|
||||||
App.setAppIdleRunning(idleNew);
|
App.setAppIdleRunning(idleNew);
|
||||||
|
if (idleNew) {
|
||||||
|
IdleGpsService.getInstance().start();
|
||||||
|
} else {
|
||||||
|
IdleGpsService.getInstance().stop();
|
||||||
|
}
|
||||||
AppIdleRunningModeHandler.sendIdleSwitch(idleNew);
|
AppIdleRunningModeHandler.sendIdleSwitch(idleNew);
|
||||||
AppIdleRunningModeHandler.sendIdleLog("菜单手动切换空转状态:" + idleNew);
|
AppIdleRunningModeHandler.sendIdleLog("菜单手动切换空转状态:" + idleNew);
|
||||||
LogUtils.d(TAG, "onOptionsItemSelected -> 空转状态已切换,当前:" + idleNew);
|
LogUtils.d(TAG, "onOptionsItemSelected -> 空转状态已切换,当前:" + idleNew);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package cc.winboll.studio.positions.services;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
|
||||||
|
import cc.winboll.studio.positions.handlers.AppIdleRunningModeHandler;
|
||||||
import cc.winboll.studio.positions.models.PositionModel;
|
import cc.winboll.studio.positions.models.PositionModel;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -14,7 +15,7 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class IdleGpsService {
|
public class IdleGpsService {
|
||||||
|
|
||||||
private static final long MOCK_INTERVAL_MS = 1000; // 模拟坐标更新间隔
|
private static final long MOCK_INTERVAL_MS = 5000; // 模拟坐标更新间隔(5秒)
|
||||||
private static IdleGpsService instance;
|
private static IdleGpsService instance;
|
||||||
private final List<MainService.GpsUpdateListener> listeners = new ArrayList<>();
|
private final List<MainService.GpsUpdateListener> listeners = new ArrayList<>();
|
||||||
private final Handler handler;
|
private final Handler handler;
|
||||||
@@ -36,6 +37,7 @@ public class IdleGpsService {
|
|||||||
public void run() {
|
public void run() {
|
||||||
if (isRunning) {
|
if (isRunning) {
|
||||||
notifyListeners(mockPosition);
|
notifyListeners(mockPosition);
|
||||||
|
AppIdleRunningModeHandler.sendIdleLog("模拟GPS数据更新 -> 纬度:" + mockPosition.getLatitude() + ", 经度:" + mockPosition.getLongitude());
|
||||||
handler.postDelayed(this, MOCK_INTERVAL_MS);
|
handler.postDelayed(this, MOCK_INTERVAL_MS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -49,6 +51,29 @@ public class IdleGpsService {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启动空转模拟服务
|
||||||
|
*/
|
||||||
|
public void start() {
|
||||||
|
if (isRunning) return;
|
||||||
|
isRunning = true;
|
||||||
|
AppIdleRunningModeHandler.sendIdleLog("空转GPS服务已启动");
|
||||||
|
// 通知监听器
|
||||||
|
notifyStatusChange("空转GPS服务已启动");
|
||||||
|
handler.post(updateRunnable);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 停止空转模拟服务
|
||||||
|
*/
|
||||||
|
public void stop() {
|
||||||
|
if (!isRunning) return;
|
||||||
|
isRunning = false;
|
||||||
|
handler.removeCallbacks(updateRunnable);
|
||||||
|
notifyStatusChange("空转GPS服务已停止");
|
||||||
|
AppIdleRunningModeHandler.sendIdleLog("空转GPS服务已停止");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注册GPS监听
|
* 注册GPS监听
|
||||||
*/
|
*/
|
||||||
@@ -59,7 +84,7 @@ public class IdleGpsService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!isRunning) {
|
if (!isRunning) {
|
||||||
startMockUpdate();
|
start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user