添加示例位置增加功能

This commit is contained in:
ZhanGSKen
2025-10-02 11:10:55 +08:00
parent bd3270f8dd
commit 1ba19d8f77
4 changed files with 83 additions and 82 deletions

View File

@@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle
#Thu Oct 02 02:36:00 GMT 2025
#Thu Oct 02 03:09:35 GMT 2025
stageCount=8
libraryProject=
baseVersion=15.0
publishVersion=15.0.7
buildCount=9
buildCount=14
baseBetaVersion=15.0.8

View File

@@ -107,7 +107,7 @@ public class LocationActivity extends WinBoLLActivity implements IWinBoLLActivit
//initServiceInstance();
// 方式通过服务PUBLIC单例方法获取实例不直接new避免私有数据初始化重复
mMainService = MainService.getInstance();
mMainService = MainService.getInstance(LocationActivity.this);
// 容错:若单例未初始化(如首次启动),提示并处理
if (mMainService == null) {
@@ -315,21 +315,21 @@ public class LocationActivity extends WinBoLLActivity implements IWinBoLLActivit
/**
* 同步GPS位置到服务调用服务syncCurrentGpsPosition(),不访问私有字段)
*/
public void syncGpsPositionToService(PositionModel gpsModel) {
if (mMainService == null || gpsModel == null) {
LogUtils.w(TAG, "同步GPS失败服务未就绪或GPS数据无效");
return;
}
// 调用服务PUBLIC方法同步GPS服务内部更新mCurrentGpsPosition
mMainService.syncCurrentGpsPosition(gpsModel);
// 强制刷新距离通过服务PUBLIC方法触发mPositionList距离计算
mMainService.forceRefreshDistance();
LogUtils.d(TAG, "GPS位置已同步通过服务触发距离计算");
// 刷新缓存+Adapter显示最新距离
refreshCachedDataAndAdapter();
}
// public void syncGpsPositionToService(PositionModel gpsModel) {
// if (mMainService == null || gpsModel == null) {
// LogUtils.w(TAG, "同步GPS失败服务未就绪或GPS数据无效");
// return;
// }
//
// // 调用服务PUBLIC方法同步GPS服务内部更新mCurrentGpsPosition
// mMainService.syncCurrentGpsPosition(gpsModel);
// // 强制刷新距离通过服务PUBLIC方法触发mPositionList距离计算
// mMainService.forceRefreshDistance();
// LogUtils.d(TAG, "GPS位置已同步通过服务触发距离计算");
//
// // 刷新缓存+Adapter显示最新距离
// refreshCachedDataAndAdapter();
// }
// ---------------------- 辅助方法统一刷新缓存与Adapter确保数据一致 ----------------------
/**

View File

@@ -63,14 +63,14 @@ public class MainService extends Service {
// 2. 单独持有ApplicationContext避免内存泄漏+确保非null
private static Context sAppContext;
// 单例PUBLIC方法供外部获取实例确保全局唯一
public static synchronized MainService getInstance() {
public static synchronized MainService getInstance(Context context) {
// 4. 修复后的单例方法:先判空,再返回(避免空指针)
// 第一步先判断实例是否存在未创建则返回null不强行调用Context
if (sInstance == null) {
// 可选若调用时Service未启动主动启动Service避免后续空指针
Intent intent = new Intent(sAppContext, MainService.class);
sAppContext.startService(intent);
Intent intent = new Intent(context.getApplicationContext(), MainService.class);
context.getApplicationContext().startService(intent);
return null; // 或抛明确异常(如"Service未启动"),不触发空指针
}
// 第二步实例存在时确保Context非null双重保险
@@ -184,7 +184,12 @@ public class MainService extends Service {
}
public void addPosition(PositionModel newPos) {
LogUtils.d(TAG, "addPosition 未实现");
mPositionList.add(newPos);
savePositionList();
}
void savePositionList() {
PositionModel.saveBeanList(MainService.this, mPositionList, PositionModel.class);
}
/**

View File

@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp">
<!-- 1. 经纬度显示区域(保持居中,上方) -->
<LinearLayout
android:id="@+id/layout_location_info"
android:layout_width="wrap_content"
@@ -14,7 +14,6 @@
android:orientation="vertical"
android:gravity="center_horizontal">
<!-- 标题 -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@@ -22,7 +21,6 @@
android:textSize="22sp"
android:textStyle="bold"/>
<!-- 经度显示 -->
<TextView
android:id="@+id/tv_longitude"
android:layout_width="wrap_content"
@@ -31,7 +29,6 @@
android:textSize="18sp"
android:layout_marginTop="15dp"/>
<!-- 纬度显示 -->
<TextView
android:id="@+id/tv_latitude"
android:layout_width="wrap_content"
@@ -42,7 +39,6 @@
</LinearLayout>
<!-- 2. 新增位置列表RecyclerView- 位于经纬度下方,悬浮按钮上方 -->
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_position_list"
android:layout_width="match_parent"
@@ -52,7 +48,6 @@
android:layout_marginTop="20dp"
android:paddingBottom="10dp"/>
<!-- 3. 右下角圆形悬浮按钮(不变) -->
<Button
android:id="@+id/fab_p_button"
android:layout_width="60dp"
@@ -65,7 +60,8 @@
android:textColor="@android:color/white"
android:textSize="24sp"
android:elevation="6dp"
android:padding="0dp"/>
android:padding="0dp"
android:onClick="addNewPosition"/>
</RelativeLayout>