|
|
@@ -15,37 +15,30 @@ import com.huawei.hms.accountsdk.support.account.service.AccountAuthService;
|
|
|
import com.huawei.hms.accountsdk.support.account.tasks.OnFailureListener;
|
|
|
import com.huawei.hms.accountsdk.support.account.tasks.OnSuccessListener;
|
|
|
import com.huawei.hms.accountsdk.support.account.tasks.Task;
|
|
|
-import com.huawei.hms.maps.harmony.*;
|
|
|
-import com.huawei.hms.maps.harmony.model.CameraPosition;
|
|
|
-import com.huawei.hms.maps.harmony.model.LatLng;
|
|
|
-import com.huawei.hms.maps.harmony.model.Marker;
|
|
|
-import com.huawei.hms.maps.harmony.model.MarkerOptions;
|
|
|
import ohos.aafwk.ability.AbilitySlice;
|
|
|
import ohos.aafwk.ability.DataAbilityHelper;
|
|
|
import ohos.aafwk.ability.IDataAbilityObserver;
|
|
|
import ohos.aafwk.content.Intent;
|
|
|
-import ohos.account.AccountAbility;
|
|
|
-import ohos.agp.colors.RgbColor;
|
|
|
-import ohos.agp.colors.StateColor;
|
|
|
import ohos.agp.components.*;
|
|
|
import ohos.agp.components.element.ShapeElement;
|
|
|
+import ohos.agp.colors.RgbColor;
|
|
|
import ohos.agp.utils.Color;
|
|
|
import ohos.agp.window.dialog.ToastDialog;
|
|
|
import ohos.agp.window.service.Window;
|
|
|
import ohos.agp.window.service.WindowManager;
|
|
|
-import ohos.global.resource.NotExistException;
|
|
|
-import ohos.global.resource.Resource;
|
|
|
import ohos.location.Location;
|
|
|
import ohos.location.Locator;
|
|
|
import ohos.location.LocatorCallback;
|
|
|
import ohos.location.RequestParam;
|
|
|
-import ohos.sysappcomponents.settings.AppSettings;
|
|
|
+import ohos.rpc.RemoteException;
|
|
|
import ohos.sysappcomponents.settings.SystemSettings;
|
|
|
-
|
|
|
-import java.io.IOException;
|
|
|
-import java.lang.reflect.Method;
|
|
|
+import ohos.utils.zson.ZSONObject;
|
|
|
+import com.fujica.abk.model.response.ParkNearRes;
|
|
|
+import com.fujica.abk.model.response.Page;
|
|
|
+import com.fujica.abk.utils.R;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
|
|
|
public class MainAbilitySlice extends AbilitySlice {
|
|
|
// PageSlider相关
|
|
|
@@ -77,27 +70,34 @@ public class MainAbilitySlice extends AbilitySlice {
|
|
|
private LocatorCallback locatorCallback;
|
|
|
private Location currentLocation; // 当前定位坐标
|
|
|
|
|
|
- // 地图相关 - 完全按照 MarkerDemo 的方式
|
|
|
- private HuaweiMap mHuaweiMap;
|
|
|
- /**
|
|
|
- * Declare a MapView object.
|
|
|
- */
|
|
|
- private MapView mMapView;
|
|
|
- /**
|
|
|
- * Declare a Marker object.
|
|
|
- */
|
|
|
- private Marker mMarker;
|
|
|
- /**
|
|
|
- * 当前位置标记
|
|
|
- */
|
|
|
- private Marker currentLocationMarker;
|
|
|
+ // 找车位页面相关
|
|
|
+ private Component findParkingPage; // 找车位页面组件
|
|
|
+ private Text tabAll; // 全部车场标签
|
|
|
+ private Text tabRecommended; // 推荐车场标签
|
|
|
+ private Component tabAllUnderline; // 全部车场下划线
|
|
|
+ private Component tabRecommendedUnderline; // 推荐车场下划线
|
|
|
+ private Button btnDistanceSort; // 距离最近按钮
|
|
|
+ private ScrollView parkingListScroll; // 停车场列表滚动视图
|
|
|
+ private DirectionalLayout parkingListContainer; // 停车场列表容器
|
|
|
+ private int currentPage = 1; // 当前页码
|
|
|
+ private int pageSize = 10; // 每页数量
|
|
|
+ private boolean isLoading = false; // 是否正在加载
|
|
|
+ private boolean hasMore = true; // 是否还有更多数据
|
|
|
+ private int filterType = 2; // 筛选类型:2=全部,1=推荐
|
|
|
+ private List<ParkNearRes> parkingList = new ArrayList<>(); // 停车场列表数据
|
|
|
+
|
|
|
DataAbilityHelper dataAbilityHelper;
|
|
|
IDataAbilityObserver dataAbilityObserver;
|
|
|
|
|
|
@Override
|
|
|
public void onStart(Intent intent) {
|
|
|
super.onStart(intent);
|
|
|
-
|
|
|
+ try {
|
|
|
+ //com.fujica.abk_BD8VI9k5bO0HeGAPnhTGeYX++mgKw87G8y+3RZ6nrb9evCePddojupXJN03auUKxTKn1qbFrYQAjFyGumpjsHzw=
|
|
|
+ String appId = getApplicationContext().getBundleManager().getBundleInfo(getBundleName(), 0).getAppId();
|
|
|
+ Log.info(appId);
|
|
|
+ } catch (RemoteException e) {
|
|
|
+ }
|
|
|
cache.setToken(getContext(), "sdfdsfdsf11111111111");
|
|
|
String token = cache.getToken(getContext());
|
|
|
|
|
|
@@ -105,22 +105,15 @@ public class MainAbilitySlice extends AbilitySlice {
|
|
|
|
|
|
api.http(getContext(), "/park/near/page?longitude=0&latitude=0", "GET", null, null, null);
|
|
|
|
|
|
-
|
|
|
// 设置全屏显示
|
|
|
setFullScreen();
|
|
|
|
|
|
- // 设置 CommonContext,华为地图需要 - 完全按照示例代码
|
|
|
- CommonContext.setContext(this);
|
|
|
-
|
|
|
// 设置布局
|
|
|
super.setUIContent(ResourceTable.Layout_ability_main);
|
|
|
|
|
|
// 初始化组件
|
|
|
initComponents();
|
|
|
|
|
|
- // 初始化地图 - 完全按照 MarkerDemo 的方式
|
|
|
- initMap();
|
|
|
-
|
|
|
// 设置事件监听
|
|
|
setupListeners();
|
|
|
|
|
|
@@ -279,6 +272,18 @@ public class MainAbilitySlice extends AbilitySlice {
|
|
|
case 1: // 找车位
|
|
|
page = LayoutScatter.getInstance(MainAbilitySlice.this)
|
|
|
.parse(ResourceTable.Layout_layout_find_parking, null, false);
|
|
|
+ findParkingPage = page;
|
|
|
+ // 初始化找车位页面组件(延迟执行,确保页面已添加到容器)
|
|
|
+ getUITaskDispatcher().asyncDispatch(() -> {
|
|
|
+ try {
|
|
|
+ Thread.sleep(100); // 等待页面渲染
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ initFindParkingPage();
|
|
|
+ // 默认加载数据
|
|
|
+ loadParkingData(true);
|
|
|
+ });
|
|
|
break;
|
|
|
case 2: // 预约停车
|
|
|
page = LayoutScatter.getInstance(MainAbilitySlice.this)
|
|
|
@@ -322,6 +327,10 @@ public class MainAbilitySlice extends AbilitySlice {
|
|
|
currentTab = index;
|
|
|
updateBottomNavState(index);
|
|
|
Log.info("切换到页面: " + index);
|
|
|
+ // 如果切换到找车位页面,加载数据
|
|
|
+ if (index == 1 && findParkingPage != null) {
|
|
|
+ loadParkingData(true);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -407,15 +416,10 @@ public class MainAbilitySlice extends AbilitySlice {
|
|
|
textFee.setTextColor(grayColor);
|
|
|
}
|
|
|
|
|
|
- iconPark.setImageAndDecodeBounds(ResourceTable.Media_park);
|
|
|
- iconMy.setImageAndDecodeBounds(ResourceTable.Media_my);
|
|
|
-// iconReserveParking.setImageAndDecodeBounds(ResourceTable.Media_fee);
|
|
|
-
|
|
|
// 设置选中状态
|
|
|
switch (index) {
|
|
|
case 0: // 我的
|
|
|
textMy.setTextColor(blueColor);
|
|
|
- iconMy.setImageAndDecodeBounds(ResourceTable.Media_my_1);
|
|
|
|
|
|
iconMy.setVisibility(Component.HIDE);
|
|
|
iconMy1.setVisibility(Component.VISIBLE);
|
|
|
@@ -426,7 +430,6 @@ public class MainAbilitySlice extends AbilitySlice {
|
|
|
break;
|
|
|
case 1: // 找车位
|
|
|
textPark.setTextColor(blueColor);
|
|
|
- iconPark.setImageAndDecodeBounds(ResourceTable.Media_park_1);
|
|
|
|
|
|
iconMy.setVisibility(Component.VISIBLE);
|
|
|
iconMy1.setVisibility(Component.HIDE);
|
|
|
@@ -448,156 +451,6 @@ public class MainAbilitySlice extends AbilitySlice {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 初始化地图 - 完全按照 MarkerDemo 的方式
|
|
|
- */
|
|
|
- private void initMap() {
|
|
|
- try {
|
|
|
- // Declaring and Initializing the HuaweiMapOptions Object - 完全按照 MarkerDemo
|
|
|
- HuaweiMapOptions huaweiMapOptions = new HuaweiMapOptions();
|
|
|
-
|
|
|
- // Initialize Camera Properties
|
|
|
- CameraPosition cameraPosition =
|
|
|
- new CameraPosition(new LatLng(48.893478, 2.334595), 6, 0, 0);
|
|
|
-
|
|
|
- huaweiMapOptions
|
|
|
- // Set Camera Properties
|
|
|
- .camera(cameraPosition)
|
|
|
- // Enables or disables the zoom function. By default, the zoom function is enabled.
|
|
|
- .zoomControlsEnabled(false)
|
|
|
- // Sets whether the compass is available. The compass is available by default.
|
|
|
- .compassEnabled(true)
|
|
|
- // Specifies whether the zoom gesture is available. By default, the zoom gesture is available.
|
|
|
- .zoomGesturesEnabled(true)
|
|
|
- // Specifies whether to enable the scrolling gesture. By default, the scrolling gesture is enabled.
|
|
|
- .scrollGesturesEnabled(true)
|
|
|
- // Specifies whether the rotation gesture is available. By default, the rotation gesture is available.
|
|
|
- .rotateGesturesEnabled(false)
|
|
|
- // Specifies whether the tilt gesture is available. By default, the tilt gesture is available.
|
|
|
- .tiltGesturesEnabled(true)
|
|
|
- // Sets whether the map is in lite mode. The default value is No.
|
|
|
- .liteMode(false)
|
|
|
- // Set Preference Minimum Zoom Level
|
|
|
- .minZoomPreference(3)
|
|
|
- // Set Preference Maximum Zoom Level
|
|
|
- .maxZoomPreference(13);
|
|
|
-
|
|
|
- if (true) return;
|
|
|
-
|
|
|
- // Initialize MapView Object. - 完全按照 MarkerDemo
|
|
|
- mMapView = new MapView(this, huaweiMapOptions);
|
|
|
- mMapView.onCreate();
|
|
|
-
|
|
|
-
|
|
|
- // Obtains the HuaweiMap object. - 完全按照 MarkerDemo
|
|
|
- mMapView.getMapAsync(huaweiMap -> {
|
|
|
- mHuaweiMap = huaweiMap;
|
|
|
-
|
|
|
- // If mHuaweiMap is null, the program stops running. - 完全按照 MarkerDemo
|
|
|
- if (null == mHuaweiMap) {
|
|
|
- Log.error("mHuaweiMap 为 null");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- Log.info("地图已就绪,开始获取定位");
|
|
|
-
|
|
|
- mHuaweiMap.setOnMapClickListener(new OnMapClickListener() {
|
|
|
- @Override
|
|
|
- public void onMapClick(LatLng latLng) {
|
|
|
- new ToastDialog(CommonContext.getContext()).setText("onMapClick ").show();
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- // If mMarker is not null, remove it from the map and then set it to null. - 完全按照 MarkerDemo
|
|
|
- if (null != mMarker) {
|
|
|
- mMarker.remove();
|
|
|
- mMarker = null;
|
|
|
- }
|
|
|
-
|
|
|
- // Add a marker to the map. - 完全按照 MarkerDemo
|
|
|
- MarkerOptions options = new MarkerOptions()
|
|
|
- .position(new LatLng(48.893478, 2.334595))
|
|
|
- .title("Hello Huawei Map")
|
|
|
- .snippet("This is a snippet!");
|
|
|
- mMarker = mHuaweiMap.addMarker(options);
|
|
|
-
|
|
|
- // Set the marker title. - 完全按照 MarkerDemo
|
|
|
- if (mMarker != null) {
|
|
|
- mMarker.setTitle("Marker title");
|
|
|
- }
|
|
|
-
|
|
|
- // Set whether the marker can be dragged. - 完全按照 MarkerDemo
|
|
|
- if (mMarker != null) {
|
|
|
- mMarker.setDraggable(true);
|
|
|
- }
|
|
|
-
|
|
|
- // Set the marker anchor point. - 完全按照 MarkerDemo
|
|
|
- if (mMarker != null) {
|
|
|
- mMarker.setMarkerAnchor(0.9F, 0.9F);
|
|
|
- }
|
|
|
-
|
|
|
- // Customizing the Marker Icon - 完全按照 MarkerDemo
|
|
|
- addCustomMarker();
|
|
|
-
|
|
|
- mHuaweiMap.setOnMarkerClickListener(new OnMarkerClickListener() {
|
|
|
- @Override
|
|
|
- public boolean onMarkerClick(Marker marker) {
|
|
|
- new ToastDialog(CommonContext.getContext()).setText("onMarkerClick: " + marker.getTitle()).show();
|
|
|
- return false;
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- mHuaweiMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
|
|
|
- @Override
|
|
|
- public void onInfoWindowClick(Marker marker) {
|
|
|
- new ToastDialog(CommonContext.getContext()).setText("onInfoWindowClick:").show();
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- // 地图就绪后,自动获取当前位置
|
|
|
- if (locator != null && locatorCallback != null) {
|
|
|
- locateCurrentPosition();
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
-// ComponentContainer.LayoutConfig config = new ComponentContainer.LayoutConfig(ComponentContainer.LayoutConfig.MATCH_PARENT, ComponentContainer.LayoutConfig.MATCH_PARENT);
|
|
|
-// PositionLayout myLayout = new PositionLayout(this);
|
|
|
-// myLayout.setLayoutConfig(config);
|
|
|
-
|
|
|
- PositionLayout myLayout = findComponentById(ResourceTable.Id_main_body);
|
|
|
-
|
|
|
- ShapeElement element = new ShapeElement();
|
|
|
- element.setShape(ShapeElement.RECTANGLE);
|
|
|
- element.setRgbColor(new RgbColor(255, 255, 255));
|
|
|
-
|
|
|
- // 加载MapView
|
|
|
- myLayout.addComponent(mMapView);
|
|
|
- } catch (Exception e) {
|
|
|
- Log.error("初始化地图失败: " + e.getMessage());
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * addCustomMarker - 完全按照 MarkerDemo
|
|
|
- */
|
|
|
- private void addCustomMarker() {
|
|
|
- Resource resource = null;
|
|
|
- try {
|
|
|
- resource = getResourceManager().getResource(ResourceTable.Media_icon);
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } catch (NotExistException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- if (resource != null && mHuaweiMap != null) {
|
|
|
- mHuaweiMap.addMarker(new MarkerOptions()
|
|
|
- .position(new LatLng(47.8333, 2.8333))
|
|
|
- .icon(resource));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 设置事件监听
|
|
|
*/
|
|
|
@@ -620,9 +473,10 @@ public class MainAbilitySlice extends AbilitySlice {
|
|
|
double longitude = location.getLongitude();
|
|
|
|
|
|
Log.info("定位成功: " + latitude + ", " + longitude);
|
|
|
-
|
|
|
- // 将坐标传递给地图
|
|
|
- updateMapWithLocation(location);
|
|
|
+ // 定位成功后,如果当前在找车位页面,重新加载数据
|
|
|
+ if (currentTab == 1 && findParkingPage != null) {
|
|
|
+ loadParkingData(true);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -633,7 +487,7 @@ public class MainAbilitySlice extends AbilitySlice {
|
|
|
@Override
|
|
|
public void onErrorReport(int errorCode) {
|
|
|
Log.error("定位错误: " + errorCode);
|
|
|
- new ToastDialog(CommonContext.getContext())
|
|
|
+ new ToastDialog(getContext())
|
|
|
.setText("定位失败,错误码: " + errorCode)
|
|
|
.show();
|
|
|
}
|
|
|
@@ -662,116 +516,440 @@ public class MainAbilitySlice extends AbilitySlice {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onStop() {
|
|
|
+ super.onStop();
|
|
|
+ // 停止定位
|
|
|
+ if (locator != null && locatorCallback != null) {
|
|
|
+ try {
|
|
|
+ locator.stopLocating(locatorCallback);
|
|
|
+ } catch (Exception e) {
|
|
|
+ Log.error("停止定位失败: " + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (dataAbilityHelper != null) {
|
|
|
+
|
|
|
+ }
|
|
|
+ dataAbilityHelper.unregisterObserver(SystemSettings.getUri(SystemSettings.Date.TIME_FORMAT), dataAbilityObserver);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
- * 将定位坐标传递给地图并更新地图显示
|
|
|
+ * 初始化找车位页面组件
|
|
|
*/
|
|
|
- private void updateMapWithLocation(Location location) {
|
|
|
- if (mHuaweiMap == null) {
|
|
|
- Log.warn("地图未初始化完成,等待地图就绪");
|
|
|
+ private void initFindParkingPage() {
|
|
|
+ if (findParkingPage == null) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- try {
|
|
|
- double latitude = location.getLatitude();
|
|
|
- double longitude = location.getLongitude();
|
|
|
+ // 获取组件
|
|
|
+ tabAll = (Text) findParkingPage.findComponentById(ResourceTable.Id_tab_all);
|
|
|
+ tabRecommended = (Text) findParkingPage.findComponentById(ResourceTable.Id_tab_recommended);
|
|
|
+ tabAllUnderline = findParkingPage.findComponentById(ResourceTable.Id_tab_all_underline);
|
|
|
+ tabRecommendedUnderline = findParkingPage.findComponentById(ResourceTable.Id_tab_recommended_underline);
|
|
|
+ btnDistanceSort = (Button) findParkingPage.findComponentById(ResourceTable.Id_btn_distance_sort);
|
|
|
+ parkingListScroll = (ScrollView) findParkingPage.findComponentById(ResourceTable.Id_parking_list_scroll);
|
|
|
+ parkingListContainer = (DirectionalLayout) findParkingPage.findComponentById(ResourceTable.Id_parking_list_container);
|
|
|
+
|
|
|
+ // 设置标签页点击事件
|
|
|
+ if (tabAll != null) {
|
|
|
+ tabAll.setClickedListener(component -> switchTab(2)); // 2=全部
|
|
|
+ }
|
|
|
+ if (tabRecommended != null) {
|
|
|
+ tabRecommended.setClickedListener(component -> switchTab(1)); // 1=推荐
|
|
|
+ }
|
|
|
|
|
|
- Log.info("更新地图位置: " + latitude + ", " + longitude);
|
|
|
+ // 设置下拉框点击事件(这里用按钮模拟下拉框)
|
|
|
+ if (btnDistanceSort != null) {
|
|
|
+ btnDistanceSort.setClickedListener(component -> {
|
|
|
+ // 可以在这里显示下拉选择框,暂时保持"距离最近"
|
|
|
+ Log.info("点击了距离最近下拉框");
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- // 创建坐标点
|
|
|
- LatLng latLng = new LatLng(latitude, longitude);
|
|
|
+ // 设置滚动监听,实现分页加载
|
|
|
+ if (parkingListScroll != null) {
|
|
|
+ parkingListScroll.setReboundEffect(false);
|
|
|
+ // 监听滚动到底部
|
|
|
+ parkingListScroll.addScrolledListener(new Component.ScrolledListener() {
|
|
|
+ @Override
|
|
|
+ public void onContentScrolled(Component component, int x, int y, int oldX, int oldY) {
|
|
|
+ // 计算是否滚动到底部
|
|
|
+ int scrollHeight = parkingListScroll.getScrollValue(1);
|
|
|
+ int contentHeight = parkingListScroll.getEstimatedHeight();
|
|
|
+// int contentHeight = parkingListScroll.getContentHeight();
|
|
|
+ int viewHeight = parkingListScroll.getHeight();
|
|
|
+
|
|
|
+ if (scrollHeight + viewHeight >= contentHeight - 100 && !isLoading && hasMore) {
|
|
|
+ // 加载下一页
|
|
|
+ loadParkingData(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- // 移除旧的当前位置标记
|
|
|
- if (currentLocationMarker != null) {
|
|
|
- currentLocationMarker.remove();
|
|
|
- currentLocationMarker = null;
|
|
|
+ // 默认选中全部车场
|
|
|
+ switchTab(2);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 切换标签页
|
|
|
+ */
|
|
|
+ private void switchTab(int filter) {
|
|
|
+ filterType = filter;
|
|
|
+ currentPage = 1;
|
|
|
+ hasMore = true;
|
|
|
+ parkingList.clear();
|
|
|
+ if (parkingListContainer != null) {
|
|
|
+ parkingListContainer.removeAllComponents();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新标签样式
|
|
|
+ Color selectedColor = new Color(Color.getIntColor("#FA6332"));
|
|
|
+ Color normalColor = new Color(Color.getIntColor("#FF666666"));
|
|
|
+
|
|
|
+ if (tabAll != null) {
|
|
|
+ tabAll.setTextColor(filter == 2 ? selectedColor : normalColor);
|
|
|
+ }
|
|
|
+ if (tabRecommended != null) {
|
|
|
+ tabRecommended.setTextColor(filter == 1 ? selectedColor : normalColor);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新下划线显示
|
|
|
+ if (tabAllUnderline != null) {
|
|
|
+ tabAllUnderline.setVisibility(filter == 2 ? Component.VISIBLE : Component.HIDE);
|
|
|
+ }
|
|
|
+ if (tabRecommendedUnderline != null) {
|
|
|
+ tabRecommendedUnderline.setVisibility(filter == 1 ? Component.VISIBLE : Component.HIDE);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 加载数据
|
|
|
+ loadParkingData(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 加载停车场数据
|
|
|
+ */
|
|
|
+ private void loadParkingData(boolean isRefresh) {
|
|
|
+ if (isLoading) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isRefresh) {
|
|
|
+ currentPage = 1;
|
|
|
+ hasMore = true;
|
|
|
+ parkingList.clear();
|
|
|
+ if (parkingListContainer != null) {
|
|
|
+ parkingListContainer.removeAllComponents();
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- // 在地图上添加当前位置标记
|
|
|
- MarkerOptions currentLocationOptions = new MarkerOptions()
|
|
|
- .position(latLng)
|
|
|
- .title("当前位置")
|
|
|
- .snippet("纬度: " + latitude + ", 经度: " + longitude);
|
|
|
- currentLocationMarker = mHuaweiMap.addMarker(currentLocationOptions);
|
|
|
+ if (!hasMore) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- // Method 8: Set the center point and zoom level of the camera. - 完全按照示例代码
|
|
|
- float zoom = 15.0f;
|
|
|
- CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, zoom);
|
|
|
+ isLoading = true;
|
|
|
|
|
|
- // move camera - 完全按照示例代码
|
|
|
- mHuaweiMap.moveCamera(cameraUpdate);
|
|
|
+ // 获取定位坐标
|
|
|
+ double latitude = 0;
|
|
|
+ double longitude = 0;
|
|
|
+ if (currentLocation != null) {
|
|
|
+ latitude = currentLocation.getLatitude();
|
|
|
+ longitude = currentLocation.getLongitude();
|
|
|
+ }
|
|
|
|
|
|
- Log.info("地图已更新到当前位置");
|
|
|
+ // 构建请求URL
|
|
|
+ String url = String.format("/park/near/page?filter=%d&latitude=%f&longitude=%f¤t=%d&size=%d",
|
|
|
+ filterType, latitude, longitude, currentPage, pageSize);
|
|
|
+
|
|
|
+ // 发送请求
|
|
|
+ CompletableFuture<R<Object>> future = api.http(getContext(), url, "GET", null, null, null);
|
|
|
+ future.thenAccept(response -> {
|
|
|
+ getUITaskDispatcher().asyncDispatch(() -> {
|
|
|
+ isLoading = false;
|
|
|
+
|
|
|
+ if (response == null || !response.isSuccess()) {
|
|
|
+ String errorMsg = response != null ? response.getMsg() : "请求失败";
|
|
|
+ Log.error("加载停车场数据失败: " + errorMsg);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 解析响应数据
|
|
|
+ Object dataObj = response.getData();
|
|
|
+ if (dataObj == null) {
|
|
|
+ Log.error("响应数据为空");
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- // 显示提示
|
|
|
- new ToastDialog(CommonContext.getContext())
|
|
|
- .setText("已定位到当前位置")
|
|
|
- .show();
|
|
|
+ // 将data转换为ZSONObject
|
|
|
+ ZSONObject pageObj;
|
|
|
+ if (dataObj instanceof ZSONObject) {
|
|
|
+ pageObj = (ZSONObject) dataObj;
|
|
|
+ } else {
|
|
|
+ pageObj = ZSONObject.stringToZSON(dataObj.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 解析Page对象
|
|
|
+ Page<ParkNearRes> page = parsePageData(pageObj);
|
|
|
+ if (page == null || page.getRecords() == null) {
|
|
|
+ Log.error("解析分页数据失败");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ParkNearRes> records = page.getRecords();
|
|
|
+ if (records.isEmpty()) {
|
|
|
+ hasMore = false;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加到列表
|
|
|
+ parkingList.addAll(records);
|
|
|
+
|
|
|
+ // 渲染列表项
|
|
|
+ for (ParkNearRes park : records) {
|
|
|
+ addParkingItem(park);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新分页信息
|
|
|
+ if (page.getCurrent() != null && page.getPages() != null) {
|
|
|
+ if (page.getCurrent() >= page.getPages()) {
|
|
|
+ hasMore = false;
|
|
|
+ } else {
|
|
|
+ currentPage++;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 如果没有分页信息,根据返回数量判断
|
|
|
+ if (records.size() < pageSize) {
|
|
|
+ hasMore = false;
|
|
|
+ } else {
|
|
|
+ currentPage++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ Log.error("解析停车场数据失败: " + e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 解析分页数据
|
|
|
+ */
|
|
|
+ private Page<ParkNearRes> parsePageData(ZSONObject pageObj) {
|
|
|
+ try {
|
|
|
+ Page<ParkNearRes> page = new Page<>();
|
|
|
+
|
|
|
+ if (pageObj.containsKey("total")) {
|
|
|
+ page.setTotal(pageObj.getIntValue("total"));
|
|
|
+ }
|
|
|
+ if (pageObj.containsKey("pages")) {
|
|
|
+ page.setPages(pageObj.getIntValue("pages"));
|
|
|
+ }
|
|
|
+ if (pageObj.containsKey("current")) {
|
|
|
+ page.setCurrent(pageObj.getIntValue("current"));
|
|
|
+ }
|
|
|
+ if (pageObj.containsKey("size")) {
|
|
|
+ page.setSize(pageObj.getIntValue("size"));
|
|
|
+ }
|
|
|
+ if (pageObj.containsKey("records")) {
|
|
|
+ Object recordsObj = pageObj.get("records");
|
|
|
+ if (recordsObj instanceof List) {
|
|
|
+ List<?> recordsList = (List<?>) recordsObj;
|
|
|
+ List<ParkNearRes> parkList = new ArrayList<>();
|
|
|
+ for (Object item : recordsList) {
|
|
|
+ ParkNearRes park = parseParkData(item);
|
|
|
+ if (park != null) {
|
|
|
+ parkList.add(park);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ page.setRecords(parkList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return page;
|
|
|
} catch (Exception e) {
|
|
|
- Log.error("更新地图位置失败: " + e.getMessage());
|
|
|
- e.printStackTrace();
|
|
|
+ Log.error("解析Page数据失败: " + e.getMessage());
|
|
|
+ return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 移动地图到当前位置 - 完全按照 MapViewCameraDemo 的方式
|
|
|
+ * 解析停车场数据
|
|
|
*/
|
|
|
- private void moveToCurrentLocation(Location location) {
|
|
|
- updateMapWithLocation(location);
|
|
|
- }
|
|
|
+ private ParkNearRes parseParkData(Object itemObj) {
|
|
|
+ try {
|
|
|
+ ZSONObject parkObj;
|
|
|
+ if (itemObj instanceof ZSONObject) {
|
|
|
+ parkObj = (ZSONObject) itemObj;
|
|
|
+ } else {
|
|
|
+ parkObj = ZSONObject.stringToZSON(itemObj.toString());
|
|
|
+ }
|
|
|
|
|
|
- // 生命周期管理 - 完全按照示例代码 MapViewDemo.java 的方式
|
|
|
- @Override
|
|
|
- protected void onActive() {
|
|
|
- super.onActive();
|
|
|
- if (mMapView != null) {
|
|
|
- mMapView.onResume();
|
|
|
- }
|
|
|
- }
|
|
|
+ ParkNearRes park = new ParkNearRes();
|
|
|
+ if (parkObj.containsKey("parkId")) {
|
|
|
+ park.setParkId(parkObj.getString("parkId"));
|
|
|
+ }
|
|
|
+ if (parkObj.containsKey("parkName")) {
|
|
|
+ park.setParkName(parkObj.getString("parkName"));
|
|
|
+ }
|
|
|
+ if (parkObj.containsKey("isreserver")) {
|
|
|
+ park.setIsreserver(parkObj.getIntValue("isreserver"));
|
|
|
+ }
|
|
|
+ if (parkObj.containsKey("isfindcar")) {
|
|
|
+ park.setIsfindcar(parkObj.getIntValue("isfindcar"));
|
|
|
+ }
|
|
|
+ if (parkObj.containsKey("powerEnable")) {
|
|
|
+ park.setPowerEnable(parkObj.getIntValue("powerEnable"));
|
|
|
+ }
|
|
|
+ if (parkObj.containsKey("distance")) {
|
|
|
+ park.setDistance(parkObj.getDoubleValue("distance"));
|
|
|
+ }
|
|
|
+ if (parkObj.containsKey("address")) {
|
|
|
+ park.setAddress(parkObj.getString("address"));
|
|
|
+ }
|
|
|
+ if (parkObj.containsKey("totalPlace")) {
|
|
|
+ park.setTotalPlace(parkObj.getIntValue("totalPlace"));
|
|
|
+ }
|
|
|
+ if (parkObj.containsKey("residuePlace")) {
|
|
|
+ park.setResiduePlace(parkObj.getIntValue("residuePlace"));
|
|
|
+ }
|
|
|
+ if (parkObj.containsKey("latitude")) {
|
|
|
+ park.setLatitude(parkObj.getDoubleValue("latitude"));
|
|
|
+ }
|
|
|
+ if (parkObj.containsKey("longitude")) {
|
|
|
+ park.setLongitude(parkObj.getDoubleValue("longitude"));
|
|
|
+ }
|
|
|
+ if (parkObj.containsKey("onlinePayEnable")) {
|
|
|
+ park.setOnlinePayEnable(parkObj.getIntValue("onlinePayEnable"));
|
|
|
+ }
|
|
|
+ if (parkObj.containsKey("invoiceEnable")) {
|
|
|
+ park.setInvoiceEnable(parkObj.getIntValue("invoiceEnable"));
|
|
|
+ }
|
|
|
+ if (parkObj.containsKey("reductionEnable")) {
|
|
|
+ park.setReductionEnable(parkObj.getIntValue("reductionEnable"));
|
|
|
+ }
|
|
|
+ if (parkObj.containsKey("chargeInfo")) {
|
|
|
+ park.setChargeInfo(parkObj.getString("chargeInfo"));
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
- protected void onInactive() {
|
|
|
- super.onInactive();
|
|
|
- if (mMapView != null) {
|
|
|
- mMapView.onPause();
|
|
|
+ return park;
|
|
|
+ } catch (Exception e) {
|
|
|
+ Log.error("解析ParkNearRes数据失败: " + e.getMessage());
|
|
|
+ return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- protected void onBackground() {
|
|
|
- super.onBackground();
|
|
|
- if (mMapView != null) {
|
|
|
- mMapView.onStop();
|
|
|
+ /**
|
|
|
+ * 添加停车场列表项
|
|
|
+ */
|
|
|
+ private void addParkingItem(ParkNearRes park) {
|
|
|
+ if (parkingListContainer == null) {
|
|
|
+ return;
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- @Override
|
|
|
- protected void onForeground(Intent intent) {
|
|
|
- super.onForeground(intent);
|
|
|
- if (mMapView != null) {
|
|
|
- mMapView.onStart();
|
|
|
- }
|
|
|
- }
|
|
|
+ try {
|
|
|
+ // 加载列表项布局
|
|
|
+ Component item = LayoutScatter.getInstance(this)
|
|
|
+ .parse(ResourceTable.Layout_item_parking, null, false);
|
|
|
+
|
|
|
+ // 设置停车场名称
|
|
|
+ Text nameText = (Text) item.findComponentById(ResourceTable.Id_parking_name);
|
|
|
+ if (nameText != null && park.getParkName() != null) {
|
|
|
+ nameText.setText(park.getParkName());
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
- protected void onStop() {
|
|
|
- super.onStop();
|
|
|
- // 停止定位
|
|
|
- if (locator != null && locatorCallback != null) {
|
|
|
- try {
|
|
|
- locator.stopLocating(locatorCallback);
|
|
|
- } catch (Exception e) {
|
|
|
- Log.error("停止定位失败: " + e.getMessage());
|
|
|
+ // 设置距离和地址
|
|
|
+ Text addressText = (Text) item.findComponentById(ResourceTable.Id_parking_address);
|
|
|
+ if (addressText != null) {
|
|
|
+ String distanceStr = park.getDistance() != null ?
|
|
|
+ String.format("%.1fkm", park.getDistance() / 1000.0) : "0km";
|
|
|
+ String address = park.getAddress() != null ? park.getAddress() : "";
|
|
|
+ addressText.setText(distanceStr + " | " + address);
|
|
|
}
|
|
|
- }
|
|
|
- // 销毁地图 - 完全按照示例代码
|
|
|
- if (mMapView != null) {
|
|
|
- mMapView.onDestroy();
|
|
|
- }
|
|
|
|
|
|
- if (dataAbilityHelper != null) {
|
|
|
+ // 设置总车位
|
|
|
+ Text totalPlaceText = (Text) item.findComponentById(ResourceTable.Id_text_total_place);
|
|
|
+ if (totalPlaceText != null && park.getTotalPlace() != null) {
|
|
|
+ totalPlaceText.setText(String.valueOf(park.getTotalPlace()));
|
|
|
+ }
|
|
|
|
|
|
+ // 设置剩余车位
|
|
|
+ Text residuePlaceText = (Text) item.findComponentById(ResourceTable.Id_text_residue_place);
|
|
|
+ if (residuePlaceText != null && park.getResiduePlace() != null) {
|
|
|
+ residuePlaceText.setText(String.valueOf(park.getResiduePlace()));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置免费时长(从chargeInfo中解析,这里简化处理)
|
|
|
+ Text freeDurationText = (Text) item.findComponentById(ResourceTable.Id_text_free_duration);
|
|
|
+ if (freeDurationText != null) {
|
|
|
+ // 这里可以根据chargeInfo解析免费时长,暂时显示"15分"
|
|
|
+ freeDurationText.setText("15分");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置标签
|
|
|
+ DirectionalLayout tagsContainer = (DirectionalLayout) item.findComponentById(ResourceTable.Id_tags_container);
|
|
|
+ if (tagsContainer != null) {
|
|
|
+ tagsContainer.removeAllComponents();
|
|
|
+
|
|
|
+ // 根据数据添加标签
|
|
|
+ // 商场、学校等标签需要根据业务逻辑判断,这里简化处理
|
|
|
+ // 可预约 - 浅蓝色(#4CAF50 或 #2196F3)
|
|
|
+ if (park.getIsreserver() != null && park.getIsreserver() == 1) {
|
|
|
+ addTag(tagsContainer, "可预约", "#4CAF50");
|
|
|
+ }
|
|
|
+ // 可充电 - 浅蓝色
|
|
|
+ if (park.getPowerEnable() != null && park.getPowerEnable() == 1) {
|
|
|
+ addTag(tagsContainer, "可充电", "#4CAF50");
|
|
|
+ }
|
|
|
+ // 优惠 - 红色
|
|
|
+ if (park.getReductionEnable() != null && park.getReductionEnable() == 1) {
|
|
|
+ addTag(tagsContainer, "惠", "#FF0000");
|
|
|
+ }
|
|
|
+ // 商场、学校等标签 - 橙色(#FA6332,需要根据业务逻辑判断,这里暂时不添加)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置导航按钮点击事件
|
|
|
+ Button navButton = (Button) item.findComponentById(ResourceTable.Id_btn_navigate);
|
|
|
+ if (navButton != null) {
|
|
|
+ navButton.setClickedListener(component -> {
|
|
|
+ // 导航功能
|
|
|
+ Log.info("导航到: " + park.getParkName());
|
|
|
+ // TODO: 实现导航功能
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加到容器
|
|
|
+ parkingListContainer.addComponent(item);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ Log.error("添加停车场列表项失败: " + e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
- dataAbilityHelper.unregisterObserver(SystemSettings.getUri(SystemSettings.Date.TIME_FORMAT), dataAbilityObserver);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加标签
|
|
|
+ */
|
|
|
+ private void addTag(DirectionalLayout container, String text, String bgColor) {
|
|
|
+ Text tag = new Text(getContext());
|
|
|
+ tag.setText(text);
|
|
|
+ tag.setTextSize(11);
|
|
|
+ tag.setTextColor(Color.WHITE);
|
|
|
+ tag.setPadding(8, 4, 8, 4);
|
|
|
+
|
|
|
+ // 创建圆角背景(椭圆形)
|
|
|
+ ShapeElement background = new ShapeElement();
|
|
|
+ background.setShape(ShapeElement.RECTANGLE);
|
|
|
+ RgbColor rgbColor = new RgbColor(Color.getIntColor(bgColor));
|
|
|
+ background.setRgbColor(rgbColor);
|
|
|
+ background.setCornerRadius(12);
|
|
|
+ tag.setBackground(background);
|
|
|
+
|
|
|
+ tag.setMarginLeft(4);
|
|
|
+ container.addComponent(tag);
|
|
|
}
|
|
|
}
|