添加示例位置增加功能
This commit is contained in:
		| @@ -1,8 +1,8 @@ | |||||||
| #Created by .winboll/winboll_app_build.gradle | #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 | stageCount=8 | ||||||
| libraryProject= | libraryProject= | ||||||
| baseVersion=15.0 | baseVersion=15.0 | ||||||
| publishVersion=15.0.7 | publishVersion=15.0.7 | ||||||
| buildCount=9 | buildCount=14 | ||||||
| baseBetaVersion=15.0.8 | baseBetaVersion=15.0.8 | ||||||
|   | |||||||
| @@ -107,7 +107,7 @@ public class LocationActivity extends WinBoLLActivity implements IWinBoLLActivit | |||||||
|         //initServiceInstance(); |         //initServiceInstance(); | ||||||
| 		 | 		 | ||||||
|         // 方式:通过服务PUBLIC单例方法获取实例(不直接new,避免私有数据初始化重复) |         // 方式:通过服务PUBLIC单例方法获取实例(不直接new,避免私有数据初始化重复) | ||||||
|         mMainService = MainService.getInstance(); |         mMainService = MainService.getInstance(LocationActivity.this); | ||||||
|          |          | ||||||
|         // 容错:若单例未初始化(如首次启动),提示并处理 |         // 容错:若单例未初始化(如首次启动),提示并处理 | ||||||
|         if (mMainService == null) { |         if (mMainService == null) { | ||||||
| @@ -315,21 +315,21 @@ public class LocationActivity extends WinBoLLActivity implements IWinBoLLActivit | |||||||
|     /** |     /** | ||||||
|      * 同步GPS位置到服务(调用服务syncCurrentGpsPosition(),不访问私有字段) |      * 同步GPS位置到服务(调用服务syncCurrentGpsPosition(),不访问私有字段) | ||||||
|      */ |      */ | ||||||
|     public void syncGpsPositionToService(PositionModel gpsModel) { | //    public void syncGpsPositionToService(PositionModel gpsModel) { | ||||||
|         if (mMainService == null || gpsModel == null) { | //        if (mMainService == null || gpsModel == null) { | ||||||
|             LogUtils.w(TAG, "同步GPS失败:服务未就绪或GPS数据无效"); | //            LogUtils.w(TAG, "同步GPS失败:服务未就绪或GPS数据无效"); | ||||||
|             return; | //            return; | ||||||
|         } | //        } | ||||||
|  | // | ||||||
|         // 调用服务PUBLIC方法同步GPS(服务内部更新mCurrentGpsPosition) | //        // 调用服务PUBLIC方法同步GPS(服务内部更新mCurrentGpsPosition) | ||||||
|         mMainService.syncCurrentGpsPosition(gpsModel); | //        mMainService.syncCurrentGpsPosition(gpsModel); | ||||||
|         // 强制刷新距离(通过服务PUBLIC方法,触发mPositionList距离计算) | //        // 强制刷新距离(通过服务PUBLIC方法,触发mPositionList距离计算) | ||||||
|         mMainService.forceRefreshDistance(); | //        mMainService.forceRefreshDistance(); | ||||||
|         LogUtils.d(TAG, "GPS位置已同步,通过服务触发距离计算"); | //        LogUtils.d(TAG, "GPS位置已同步,通过服务触发距离计算"); | ||||||
|  | // | ||||||
|         // 刷新缓存+Adapter(显示最新距离) | //        // 刷新缓存+Adapter(显示最新距离) | ||||||
|         refreshCachedDataAndAdapter(); | //        refreshCachedDataAndAdapter(); | ||||||
|     } | //    } | ||||||
|  |  | ||||||
|     // ---------------------- 辅助方法(统一刷新缓存与Adapter,确保数据一致) ---------------------- |     // ---------------------- 辅助方法(统一刷新缓存与Adapter,确保数据一致) ---------------------- | ||||||
|     /** |     /** | ||||||
|   | |||||||
| @@ -63,14 +63,14 @@ public class MainService extends Service { | |||||||
|     // 2. 单独持有ApplicationContext(避免内存泄漏+确保非null) |     // 2. 单独持有ApplicationContext(避免内存泄漏+确保非null) | ||||||
|     private static Context sAppContext; |     private static Context sAppContext; | ||||||
|     // 单例PUBLIC方法(供外部获取实例,确保全局唯一) |     // 单例PUBLIC方法(供外部获取实例,确保全局唯一) | ||||||
|     public static synchronized MainService getInstance() { |     public static synchronized MainService getInstance(Context context) { | ||||||
| 		// 4. 修复后的单例方法:先判空,再返回(避免空指针) | 		// 4. 修复后的单例方法:先判空,再返回(避免空指针) | ||||||
|  |  | ||||||
|         // 第一步:先判断实例是否存在(未创建则返回null,不强行调用Context) |         // 第一步:先判断实例是否存在(未创建则返回null,不强行调用Context) | ||||||
|         if (sInstance == null) { |         if (sInstance == null) { | ||||||
|             // 可选:若调用时Service未启动,主动启动Service(避免后续空指针) |             // 可选:若调用时Service未启动,主动启动Service(避免后续空指针) | ||||||
| 			Intent intent = new Intent(sAppContext, MainService.class); | 			Intent intent = new Intent(context.getApplicationContext(), MainService.class); | ||||||
| 			sAppContext.startService(intent); | 			context.getApplicationContext().startService(intent); | ||||||
|             return null; // 或抛明确异常(如"Service未启动"),不触发空指针 |             return null; // 或抛明确异常(如"Service未启动"),不触发空指针 | ||||||
|         } |         } | ||||||
|         // 第二步:实例存在时,确保Context非null(双重保险) |         // 第二步:实例存在时,确保Context非null(双重保险) | ||||||
| @@ -184,7 +184,12 @@ public class MainService extends Service { | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	public void addPosition(PositionModel newPos) { | 	public void addPosition(PositionModel newPos) { | ||||||
| 		LogUtils.d(TAG, "addPosition 未实现"); | 		mPositionList.add(newPos); | ||||||
|  | 		savePositionList(); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	void savePositionList() { | ||||||
|  | 		PositionModel.saveBeanList(MainService.this, mPositionList, PositionModel.class); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
|   | |||||||
| @@ -1,71 +1,67 @@ | |||||||
| <?xml version="1.0" encoding="utf-8"?> | <?xml version="1.0" encoding="utf-8"?> | ||||||
| <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | <RelativeLayout | ||||||
|     android:layout_width="match_parent" | 	xmlns:android="http://schemas.android.com/apk/res/android" | ||||||
|     android:layout_height="match_parent" | 	android:layout_width="match_parent" | ||||||
|     android:padding="20dp"> | 	android:layout_height="match_parent" | ||||||
|  | 	android:padding="20dp"> | ||||||
|  |  | ||||||
|     <!-- 1. 经纬度显示区域(保持居中,上方) --> | 	<LinearLayout | ||||||
|     <LinearLayout | 		android:id="@+id/layout_location_info" | ||||||
|         android:id="@+id/layout_location_info" | 		android:layout_width="wrap_content" | ||||||
|         android:layout_width="wrap_content" | 		android:layout_height="wrap_content" | ||||||
|         android:layout_height="wrap_content" | 		android:layout_centerHorizontal="true" | ||||||
|         android:layout_centerHorizontal="true" | 		android:layout_marginTop="30dp" | ||||||
|         android:layout_marginTop="30dp" | 		android:orientation="vertical" | ||||||
|         android:orientation="vertical" | 		android:gravity="center_horizontal"> | ||||||
|         android:gravity="center_horizontal"> |  | ||||||
|  |  | ||||||
|         <!-- 标题 --> | 		<TextView | ||||||
|         <TextView | 			android:layout_width="wrap_content" | ||||||
|             android:layout_width="wrap_content" | 			android:layout_height="wrap_content" | ||||||
|             android:layout_height="wrap_content" | 			android:text="实时位置信息" | ||||||
|             android:text="实时位置信息" | 			android:textSize="22sp" | ||||||
|             android:textSize="22sp" | 			android:textStyle="bold"/> | ||||||
|             android:textStyle="bold"/> |  | ||||||
|  |  | ||||||
|         <!-- 经度显示 --> | 		<TextView | ||||||
|         <TextView | 			android:id="@+id/tv_longitude" | ||||||
|             android:id="@+id/tv_longitude" | 			android:layout_width="wrap_content" | ||||||
|             android:layout_width="wrap_content" | 			android:layout_height="wrap_content" | ||||||
|             android:layout_height="wrap_content" | 			android:text="当前经度:等待更新..." | ||||||
|             android:text="当前经度:等待更新..." | 			android:textSize="18sp" | ||||||
|             android:textSize="18sp" | 			android:layout_marginTop="15dp"/> | ||||||
|             android:layout_marginTop="15dp"/> |  | ||||||
|  |  | ||||||
|         <!-- 纬度显示 --> | 		<TextView | ||||||
|         <TextView | 			android:id="@+id/tv_latitude" | ||||||
|             android:id="@+id/tv_latitude" | 			android:layout_width="wrap_content" | ||||||
|             android:layout_width="wrap_content" | 			android:layout_height="wrap_content" | ||||||
|             android:layout_height="wrap_content" | 			android:text="当前纬度:等待更新..." | ||||||
|             android:text="当前纬度:等待更新..." | 			android:textSize="18sp" | ||||||
|             android:textSize="18sp" | 			android:layout_marginTop="10dp"/> | ||||||
|             android:layout_marginTop="10dp"/> |  | ||||||
|  |  | ||||||
|     </LinearLayout> | 	</LinearLayout> | ||||||
|  |  | ||||||
|     <!-- 2. 新增:位置列表(RecyclerView)- 位于经纬度下方,悬浮按钮上方 --> | 	<androidx.recyclerview.widget.RecyclerView | ||||||
|     <androidx.recyclerview.widget.RecyclerView | 		android:id="@+id/rv_position_list" | ||||||
|         android:id="@+id/rv_position_list" | 		android:layout_width="match_parent" | ||||||
|         android:layout_width="match_parent" | 		android:layout_height="match_parent" | ||||||
|         android:layout_height="match_parent" | 		android:layout_below="@id/layout_location_info" | ||||||
|         android:layout_below="@id/layout_location_info" | 		android:layout_above="@id/fab_p_button" | ||||||
|         android:layout_above="@id/fab_p_button" | 		android:layout_marginTop="20dp" | ||||||
|         android:layout_marginTop="20dp" | 		android:paddingBottom="10dp"/> | ||||||
|         android:paddingBottom="10dp"/> |  | ||||||
|  |  | ||||||
|     <!-- 3. 右下角圆形悬浮按钮(不变) --> | 	<Button | ||||||
|     <Button | 		android:id="@+id/fab_p_button" | ||||||
|         android:id="@+id/fab_p_button" | 		android:layout_width="60dp" | ||||||
|         android:layout_width="60dp" | 		android:layout_height="60dp" | ||||||
|         android:layout_height="60dp" | 		android:layout_alignParentBottom="true" | ||||||
|         android:layout_alignParentBottom="true" | 		android:layout_alignParentRight="true" | ||||||
|         android:layout_alignParentRight="true" | 		android:layout_margin="20dp" | ||||||
|         android:layout_margin="20dp" | 		android:background="@drawable/circle_button_bg" | ||||||
|         android:background="@drawable/circle_button_bg" | 		android:text="P" | ||||||
|         android:text="P" | 		android:textColor="@android:color/white" | ||||||
|         android:textColor="@android:color/white" | 		android:textSize="24sp" | ||||||
|         android:textSize="24sp" | 		android:elevation="6dp" | ||||||
|         android:elevation="6dp" | 		android:padding="0dp" | ||||||
|         android:padding="0dp"/> | 		android:onClick="addNewPosition"/> | ||||||
|  |  | ||||||
| </RelativeLayout> | </RelativeLayout> | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 ZhanGSKen
					ZhanGSKen