From 9d868f216c5bcce2f523b89b5436aea1b1883514 Mon Sep 17 00:00:00 2001 From: LaizyBoy Date: Mon, 4 May 2026 03:41:57 +0800 Subject: [PATCH] =?UTF-8?q?feat(IdleGpsService):=20=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E5=9C=86=E5=BD=A2=E8=BD=A8=E8=BF=B9GPS=E6=A8=A1=E6=8B=9F?= =?UTF-8?q?=E5=B9=B6=E4=BC=98=E5=8C=96=E6=9C=8D=E5=8A=A1=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 重构IdleGpsService,将固定坐标模拟改为圆形轨迹动态生成 - 添加角动量(bearing)递增机制,实现坐标沿圆周持续运动 - 新增calculatePosition()方法,基于锚点坐标和半径计算轨迹位置 - 在MainActivity.onResume中根据空转状态自动启动GPS服务 - 更新build.properties版本号(buildCount 21->23) --- positions/build.properties | 4 +- .../studio/positions/MainActivity.java | 3 + .../positions/services/IdleGpsService.java | 56 +++++++++++++++++-- 3 files changed, 55 insertions(+), 8 deletions(-) diff --git a/positions/build.properties b/positions/build.properties index fe1e3d1..ed9288b 100644 --- a/positions/build.properties +++ b/positions/build.properties @@ -1,8 +1,8 @@ #Created by .winboll/winboll_app_build.gradle -#Sun May 03 18:27:26 CST 2026 +#Mon May 04 03:36:37 CST 2026 stageCount=20 libraryProject= baseVersion=15.12 publishVersion=15.12.19 -buildCount=21 +buildCount=23 baseBetaVersion=15.12.20 diff --git a/positions/src/main/java/cc/winboll/studio/positions/MainActivity.java b/positions/src/main/java/cc/winboll/studio/positions/MainActivity.java index ea26b3c..ef0c9a2 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/MainActivity.java +++ b/positions/src/main/java/cc/winboll/studio/positions/MainActivity.java @@ -111,6 +111,9 @@ public class MainActivity extends WinBoLLActivity implements IWinBoLLActivity { protected void onResume() { super.onResume(); LogUtils.d(TAG, "onResume -> 页面恢复可见"); + if (App.isAppIdleRunning()) { + IdleGpsService.getInstance().start(); + } if (mADsBannerView != null) { mADsBannerView.resumeADs(MainActivity.this); } diff --git a/positions/src/main/java/cc/winboll/studio/positions/services/IdleGpsService.java b/positions/src/main/java/cc/winboll/studio/positions/services/IdleGpsService.java index 0e6929b..b504299 100644 --- a/positions/src/main/java/cc/winboll/studio/positions/services/IdleGpsService.java +++ b/positions/src/main/java/cc/winboll/studio/positions/services/IdleGpsService.java @@ -16,32 +16,72 @@ import java.util.List; public class IdleGpsService { private static final long MOCK_INTERVAL_MS = 5000; // 模拟坐标更新间隔(5秒) + private static final long BEARING_INTERVAL_MS = 1000; // 角动量递增间隔(1秒) + private static final double EARTH_RADIUS_M = 6371000; // 地球平均半径(米) + private static final double ANCHOR_LAT = 39.9042; // 固定锚点纬度(北京) + private static final double ANCHOR_LON = 116.4074; // 固定锚点经度(北京) + private static final double CIRCLE_RADIUS_M = 50; // 移动轨迹半径(米) + private static IdleGpsService instance; private final List listeners = new ArrayList<>(); private final Handler handler; private final Runnable updateRunnable; + private final Runnable bearingRunnable; private final PositionModel mockPosition; private boolean isRunning; + private int currentBearing = 1; // 当前角动量度数(1-360) private IdleGpsService() { handler = new Handler(Looper.getMainLooper()); mockPosition = new PositionModel(); mockPosition.setPositionId("mock_idle_pos"); mockPosition.setMemo("空转模拟坐标"); - // 默认模拟坐标:北京 - mockPosition.setLatitude(39.9042); - mockPosition.setLongitude(116.4074); updateRunnable = new Runnable() { @Override public void run() { if (isRunning) { + calculatePosition(); notifyListeners(mockPosition); - AppIdleRunningModeHandler.sendIdleLog("模拟GPS数据更新 -> 纬度:" + mockPosition.getLatitude() + ", 经度:" + mockPosition.getLongitude()); + AppIdleRunningModeHandler.sendIdleLog("模拟GPS数据更新 -> 纬度:" + mockPosition.getLatitude() + ", 经度:" + mockPosition.getLongitude() + ", 角度:" + currentBearing + "°"); handler.postDelayed(this, MOCK_INTERVAL_MS); } } }; + + bearingRunnable = new Runnable() { + @Override + public void run() { + if (isRunning) { + currentBearing++; + if (currentBearing > 360) { + currentBearing = 1; + } + handler.postDelayed(this, BEARING_INTERVAL_MS); + } + } + }; + } + + private void calculatePosition() { + double bearingRad = Math.toRadians(currentBearing); + double angularDistance = CIRCLE_RADIUS_M / EARTH_RADIUS_M; + + double anchorLatRad = Math.toRadians(ANCHOR_LAT); + double anchorLonRad = Math.toRadians(ANCHOR_LON); + + double newLatRad = Math.asin( + Math.sin(anchorLatRad) * Math.cos(angularDistance) + + Math.cos(anchorLatRad) * Math.sin(angularDistance) * Math.cos(bearingRad) + ); + + double newLonRad = anchorLonRad + Math.atan2( + Math.sin(bearingRad) * Math.sin(angularDistance) * Math.cos(anchorLatRad), + Math.cos(angularDistance) - Math.sin(anchorLatRad) * Math.sin(newLatRad) + ); + + mockPosition.setLatitude(Math.toDegrees(newLatRad)); + mockPosition.setLongitude(Math.toDegrees(newLonRad)); } public static IdleGpsService getInstance() { @@ -57,10 +97,11 @@ public class IdleGpsService { public void start() { if (isRunning) return; isRunning = true; + currentBearing = 1; AppIdleRunningModeHandler.sendIdleLog("空转GPS服务已启动"); - // 通知监听器 notifyStatusChange("空转GPS服务已启动"); handler.post(updateRunnable); + handler.post(bearingRunnable); } /** @@ -70,6 +111,7 @@ public class IdleGpsService { if (!isRunning) return; isRunning = false; handler.removeCallbacks(updateRunnable); + handler.removeCallbacks(bearingRunnable); notifyStatusChange("空转GPS服务已停止"); AppIdleRunningModeHandler.sendIdleLog("空转GPS服务已停止"); } @@ -103,14 +145,16 @@ public class IdleGpsService { private void startMockUpdate() { if (isRunning) return; isRunning = true; - // 通知状态变更 + currentBearing = 1; notifyStatusChange("空转GPS服务已启动"); handler.post(updateRunnable); + handler.post(bearingRunnable); } private void stopMockUpdate() { isRunning = false; handler.removeCallbacks(updateRunnable); + handler.removeCallbacks(bearingRunnable); notifyStatusChange("空转GPS服务已停止"); }