增加token
This commit is contained in:
@@ -47,7 +47,9 @@ import com.amap.api.navi.AmapNaviPage;
|
||||
import com.amap.api.navi.AmapNaviParams;
|
||||
import com.amap.api.navi.AmapNaviType;
|
||||
import com.amap.api.navi.AmapPageType;
|
||||
import com.amap.api.navi.enums.PathPlanningStrategy;
|
||||
import com.amap.api.navi.model.AMapCarInfo;
|
||||
import com.amap.api.navi.model.NaviPoi;
|
||||
import com.amap.api.services.core.AMapException;
|
||||
import com.amap.api.services.core.LatLonPoint;
|
||||
import com.amap.api.services.geocoder.GeocodeResult;
|
||||
@@ -115,6 +117,125 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
||||
private boolean isFirstLocation = true;
|
||||
private final List<Marker> stationMarkers = new ArrayList<>();
|
||||
|
||||
// 存储token和车牌号
|
||||
private String token;
|
||||
private String plateNumber;
|
||||
|
||||
// 存储货车路线算法接口返回的数据
|
||||
private TruckRouteData truckRouteData;
|
||||
|
||||
// 货车路线算法数据Bean
|
||||
public static class TruckRouteData {
|
||||
public TruckDto truckDto;
|
||||
public String truckDtoStr;
|
||||
public DestinationSite destinationSite;
|
||||
public PathDto pathDto;
|
||||
public AlgorithmPath algorithmPath;
|
||||
public boolean isInvokeAlgorithm;
|
||||
}
|
||||
|
||||
public static class TruckDto {
|
||||
public boolean isRestriction;
|
||||
public String mvehicleSizeName;
|
||||
public String mvehicleAxisUnit;
|
||||
public String mcarNumber;
|
||||
public int mcarType;
|
||||
public String mvehicleHeight;
|
||||
public String mvehicleHeightUnit;
|
||||
public String mvehicleWeight;
|
||||
public String mvehicleWeightUnit;
|
||||
public String mvehicleLoad;
|
||||
public String mvehicleLoadUnit;
|
||||
public boolean mvehicleLoadSwitch;
|
||||
public String mvehicleWidth;
|
||||
public String mvehicleWidthUnit;
|
||||
public String mvehicleLength;
|
||||
public String mvehicleLengthUnit;
|
||||
public int mvehicleSize;
|
||||
public int mvehicleAxis;
|
||||
}
|
||||
|
||||
public static class PathDto {
|
||||
public int distance;
|
||||
public int duration;
|
||||
public String strategy;
|
||||
public String tolls;
|
||||
public int toll_distance;
|
||||
public int restriction;
|
||||
public int traffic_lights;
|
||||
public List<NaviPoint> naviList;
|
||||
}
|
||||
|
||||
public static class NaviPoint {
|
||||
public String name;
|
||||
public String poiId;
|
||||
public Coordinate coordinate;
|
||||
}
|
||||
|
||||
public static class Coordinate {
|
||||
public String longitude;
|
||||
public String latitude;
|
||||
}
|
||||
|
||||
public static class AlgorithmPath {
|
||||
public String tripRecommendationId;
|
||||
public String staId;
|
||||
public String tripOneWayPathId;
|
||||
public String tripReturnPathId;
|
||||
public String oneWayDis;
|
||||
public String returnDis;
|
||||
public String roundTripDis;
|
||||
public String oneWayTime;
|
||||
public String returnTime;
|
||||
public String roundTripTime;
|
||||
public String oneWayCost;
|
||||
public String returnCost;
|
||||
public String roundTripCost;
|
||||
public String oneWayLaborCost;
|
||||
public String returnLaborCost;
|
||||
public String roundTripLaborCost;
|
||||
public String oneWayChargerouteCost;
|
||||
public String returnChargerouteCost;
|
||||
public String roundTripChargerouteCost;
|
||||
public String oneWayHydrogenConsumption;
|
||||
public String returnLaborHydrogenConsumption;
|
||||
public String roundTripHydrogenConsumption;
|
||||
public String oneWayHydrogenCost;
|
||||
public String returnLaborHydrogenCost;
|
||||
public String roundTripHydrogenCost;
|
||||
public String hydrogenCost;
|
||||
public String hydrogenStaServiceTime;
|
||||
public String hydrogenStaRefuelingTime;
|
||||
public String hydrogenStaQueueTime;
|
||||
public String hydrogenStaServiceTimeCost;
|
||||
public String hydrogenStaRefuelingTimeCost;
|
||||
public String hydrogenStaQueueTimeCost;
|
||||
}
|
||||
|
||||
public static class DestinationSite {
|
||||
public String innerSiteId;
|
||||
public String name;
|
||||
public String shortName;
|
||||
public String siteNo;
|
||||
public String city;
|
||||
public String address;
|
||||
public String contact;
|
||||
public String phone;
|
||||
public String type;
|
||||
public String coOpMode;
|
||||
public String booking;
|
||||
public String siteStatus;
|
||||
public String siteStatusName;
|
||||
public String startBusiness;
|
||||
public String endBusiness;
|
||||
public String billingMethod;
|
||||
public String term;
|
||||
public String remark;
|
||||
public String longitude;
|
||||
public String latitude;
|
||||
public String distance;
|
||||
}
|
||||
|
||||
public NativeMapView(Context context, int id, Object args) {
|
||||
this.mContext = context;
|
||||
mActivity = getActivityFromContext(context);
|
||||
@@ -132,6 +253,7 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
||||
|
||||
container.addView(mapView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
|
||||
initData(context);
|
||||
initServices(context);
|
||||
initOverlays(context);
|
||||
setupMapUi();
|
||||
@@ -141,6 +263,8 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void initServices(Context context) {
|
||||
try {
|
||||
geocoderSearch = new GeocodeSearch(context);
|
||||
@@ -180,8 +304,12 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
||||
endInput.setSingleLine(true);
|
||||
endInput.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
|
||||
endInput.addTextChangedListener(new TextWatcher() {
|
||||
@Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
||||
@Override public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
if (s.length() > 1) {
|
||||
InputtipsQuery query = new InputtipsQuery(s.toString(), "");
|
||||
query.setCityLimit(true);
|
||||
@@ -190,7 +318,10 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
||||
inputtips.requestInputtipsAsyn();
|
||||
}
|
||||
}
|
||||
@Override public void afterTextChanged(Editable s) {}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
}
|
||||
});
|
||||
searchArea.addView(endInput);
|
||||
|
||||
@@ -219,7 +350,8 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
||||
locBtn.setBackground(getRoundedDrawable(Color.WHITE, 25));
|
||||
locBtn.setElevation(dp2px(4));
|
||||
locBtn.setOnClickListener(v -> {
|
||||
if (currentLatLng != null) aMap.animateCamera(CameraUpdateFactory.newLatLngZoom(currentLatLng, 15f));
|
||||
if (currentLatLng != null)
|
||||
aMap.animateCamera(CameraUpdateFactory.newLatLngZoom(currentLatLng, 15f));
|
||||
});
|
||||
FrameLayout.LayoutParams locParams = new FrameLayout.LayoutParams(dp2px(44), dp2px(44));
|
||||
locParams.setMargins(0, 0, dp2px(15), dp2px(250)); // 调高一点,避开底部的面板
|
||||
@@ -256,7 +388,7 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
||||
startNaviBtn.setTextColor(Color.WHITE);
|
||||
startNaviBtn.setBackground(getRoundedDrawable(Color.parseColor("#017143"), 10));
|
||||
startNaviBtn.setOnClickListener(v -> startRouteSearch());
|
||||
|
||||
|
||||
LinearLayout.LayoutParams btnParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dp2px(48));
|
||||
btnParams.topMargin = dp2px(15);
|
||||
panel.addView(startNaviBtn, btnParams);
|
||||
@@ -269,7 +401,7 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
||||
Toast.makeText(mContext, "正在定位...", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (endPoint == null) {
|
||||
Toast.makeText(mContext, "请先选择目的地", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
@@ -300,16 +432,16 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
||||
public void onDriveRouteSearched(DriveRouteResult result, int rCode) {
|
||||
if (rCode == AMapException.CODE_AMAP_SUCCESS && result != null && !result.getPaths().isEmpty()) {
|
||||
DrivePath path = result.getPaths().get(0);
|
||||
|
||||
|
||||
// 规划成功,显示详情面板
|
||||
detailPanel.setVisibility(View.VISIBLE);
|
||||
tvStationName.setText(endName);
|
||||
tvStationAddr.setText(endInput.getText().toString());
|
||||
|
||||
|
||||
String info = String.format("预计时间:%d分钟 | 行驶里程:%.1f公里 | 预计路费:%.0f元",
|
||||
path.getDuration() / 60, path.getDistance() / 1000f, path.getTolls());
|
||||
tvRouteInfo.setText(info);
|
||||
|
||||
|
||||
aMap.animateCamera(CameraUpdateFactory.newLatLngZoom(endPoint, 13f));
|
||||
} else {
|
||||
// 规划失败回退面板
|
||||
@@ -319,23 +451,119 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
||||
}
|
||||
|
||||
private void startRouteSearch() {
|
||||
if (mActivity == null || startPoint == null || endPoint == null) return;
|
||||
if (mActivity == null || startPoint == null || endPoint == null)
|
||||
return;
|
||||
|
||||
Poi start = new Poi(startName, startPoint, "");
|
||||
Poi end = new Poi(endName, endPoint, "");
|
||||
AmapNaviParams params = new AmapNaviParams(start, null, end, AmapNaviType.DRIVER, AmapPageType.ROUTE);
|
||||
|
||||
//todo 根据接口的返回数据填充
|
||||
try {
|
||||
AMapNavi mAMapNavi = AMapNavi.getInstance(mContext);
|
||||
AMapCarInfo carInfo = new AMapCarInfo();
|
||||
carInfo.setCarNumber("沪AGK2267");
|
||||
carInfo.setCarType("1");
|
||||
mAMapNavi.setCarInfo(carInfo);
|
||||
} catch (Exception e) { e.printStackTrace(); }
|
||||
|
||||
//添加车辆信息示例代码
|
||||
AMapCarInfo carInfo = new AMapCarInfo();
|
||||
carInfo.setCarNumber("沪AGK2267");//设置车牌号
|
||||
carInfo.setCarType("1"); //设置车辆类型,0:小车; 1:货车. 默认0(小车).
|
||||
carInfo.setVehicleAxis("6"); //设置货车的轴数,mCarType = 1时候生效,取值[0-255],默认为2
|
||||
carInfo.setVehicleHeight("3.56"); //设置货车的高度,单位:米,mCarType = 1时候生效,取值[0-25.5],默认1.6米
|
||||
carInfo.setVehicleLength("7.3"); //设置货车的最大长度,单位:米,mCarType = 1时候生效,取值[0-25],默认6米
|
||||
carInfo.setVehicleWidth("2.5"); //设置货车的最大宽度,单位:米,mCarType = 1时候生效,取值[0-25.5],默认2.5米
|
||||
carInfo.setVehicleSize("4"); //设置货车的大小,1-微型货车 2-轻型/小型货车 3-中型货车 4-重型货车,默认为2
|
||||
carInfo.setVehicleLoad("25.99"); //设置货车的总重,即车重+核定载重,单位:吨,mCarType = 1时候生效,取值[0-6553.5]
|
||||
carInfo.setVehicleWeight("20"); //设置货车的核定载重,单位:吨,mCarType = 1时候生效,取值[0-6553.5]
|
||||
carInfo.setRestriction(true); //设置是否躲避车辆限行,true代表躲避车辆限行,false代表不躲避车辆限行,默认为true
|
||||
carInfo.setVehicleLoadSwitch(true); //设置货车重量是否参与算路,true-重量会参与算路;false-重量不会参与算路。默认为false
|
||||
params.setCarInfo(carInfo);
|
||||
mAMapNavi.setCarInfo(carInfo);
|
||||
|
||||
//添加途经点算路示例代码
|
||||
// 起点信息
|
||||
NaviPoi startNaviPoi = new NaviPoi("龙城花园", null, "B000A8UF3J");
|
||||
// 终点信息
|
||||
NaviPoi endNaviPoi = new NaviPoi("北京大学", null, "B000A816R6");
|
||||
// 途经点信息
|
||||
List<NaviPoi> waysPoiIds = new ArrayList<NaviPoi>();
|
||||
waysPoiIds.add(new NaviPoi("途经点1", null, "B000A805M7"));
|
||||
waysPoiIds.add(new NaviPoi("途经点2", null, "B0FFFAADBU"));
|
||||
waysPoiIds.add(new NaviPoi("途经点3", null, "B0FFF5BER7"));
|
||||
// POI算路
|
||||
mAMapNavi.calculateDriveRoute(startNaviPoi, endNaviPoi, waysPoiIds, PathPlanningStrategy.DRIVING_MULTIPLE_ROUTES_DEFAULT);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//启动货车导航组件
|
||||
AmapNaviPage.getInstance().showRouteActivity(mActivity, params, null);
|
||||
}
|
||||
|
||||
private void initData(Context context) {
|
||||
//获取从Flutter端存储的车牌和token
|
||||
android.content.SharedPreferences prefs = context.getSharedPreferences("FlutterSharedPreferences", Context.MODE_PRIVATE);
|
||||
String plateNumber = prefs.getString("flutter.plateNumber", "");
|
||||
String token = prefs.getString("flutter.token", "");
|
||||
|
||||
Log.d(TAG, "initData - plateNumber: " + plateNumber + ", token: " + (token.isEmpty() ? "empty" : "present"));
|
||||
|
||||
// 保存token供后续使用
|
||||
this.token = token;
|
||||
this.plateNumber = plateNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* 定位成功后调用,获取货车路线算法信息
|
||||
*/
|
||||
private void fetchTruckRouteAlgorithm(AMapLocation loc) {
|
||||
if (plateNumber == null || plateNumber.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("longitude", String.valueOf(loc.getLongitude()));
|
||||
json.put("latitude", String.valueOf(loc.getLatitude()));
|
||||
json.put("plateNumber", plateNumber);
|
||||
json.put("hydrogenSiteId", "");
|
||||
|
||||
Request.Builder requestBuilder = new Request.Builder()
|
||||
.url("https://beta-esg.api.lnh2e.com/appointment/truck/truckRouteAlgorithm")
|
||||
.post(RequestBody.create(json.toString(), MediaType.parse("application/json")));
|
||||
|
||||
if (token != null && !token.isEmpty()) {
|
||||
requestBuilder.addHeader("asoco-token", token);
|
||||
}
|
||||
|
||||
httpClient.newCall(requestBuilder.build()).enqueue(new Callback() {
|
||||
@Override
|
||||
public void onFailure(@NonNull Call call, @NonNull IOException e) {
|
||||
Log.e(TAG, "fetchTruckRouteAlgorithm failed", e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
try {
|
||||
String responseString = response.body().string();
|
||||
Log.d(TAG, "fetchTruckRouteAlgorithm response: " + responseString);
|
||||
|
||||
JSONObject res = new JSONObject(responseString);
|
||||
if (res.getInt("code") == 200) {
|
||||
JSONObject data = res.getJSONObject("data");
|
||||
truckRouteData = parseTruckRouteData(data);
|
||||
Log.d(TAG, "TruckRouteAlgorithm data loaded");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "parseTruckRouteAlgorithm error", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "fetchTruckRouteAlgorithm error", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void setupMapUi() {
|
||||
aMap.setLocationSource(this);
|
||||
aMap.setMyLocationEnabled(true);
|
||||
@@ -348,7 +576,9 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
||||
Bitmap scaledBitmap = Bitmap.createScaledBitmap(carBitmap, dp2px(30), dp2px(30), true);
|
||||
myLocationStyle.myLocationIcon(BitmapDescriptorFactory.fromBitmap(scaledBitmap));
|
||||
}
|
||||
} catch (Exception e) { e.printStackTrace(); }
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
myLocationStyle.anchor(0.5f, 0.5f);
|
||||
myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER);
|
||||
@@ -369,9 +599,19 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
||||
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, mContext.getResources().getDisplayMetrics());
|
||||
}
|
||||
|
||||
@Override public void activate(OnLocationChangedListener listener) { mListener = listener; startLocation(); }
|
||||
@Override public void deactivate() { mListener = null; if (mlocationClient != null) mlocationClient.stopLocation(); }
|
||||
|
||||
@Override
|
||||
public void activate(OnLocationChangedListener listener) {
|
||||
mListener = listener;
|
||||
startLocation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deactivate() {
|
||||
mListener = null;
|
||||
if (mlocationClient != null)
|
||||
mlocationClient.stopLocation();
|
||||
}
|
||||
|
||||
public void startLocation() {
|
||||
if (mlocationClient == null) {
|
||||
try {
|
||||
@@ -381,7 +621,9 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
||||
option.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
|
||||
mlocationClient.setLocationOption(option);
|
||||
mlocationClient.startLocation();
|
||||
} catch (Exception e) { e.printStackTrace(); }
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -389,7 +631,8 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
||||
public void onLocationChanged(AMapLocation loc) {
|
||||
if (loc != null && loc.getErrorCode() == 0) {
|
||||
currentLatLng = new LatLng(loc.getLatitude(), loc.getLongitude());
|
||||
if (mListener != null) mListener.onLocationChanged(loc);
|
||||
if (mListener != null)
|
||||
mListener.onLocationChanged(loc);
|
||||
if (isFirstLocation) {
|
||||
isFirstLocation = false;
|
||||
startPoint = currentLatLng;
|
||||
@@ -397,6 +640,8 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
||||
getAddressByLatlng(currentLatLng);
|
||||
fetchRecommendStation(loc);
|
||||
fetchNearbyStations(loc);
|
||||
// 获取货车路线算法信息
|
||||
fetchTruckRouteAlgorithm(loc);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -422,8 +667,12 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
||||
json.put("latitude", loc.getLatitude());
|
||||
|
||||
httpClient.newCall(new Request.Builder().url("https://beta-esg.api.lnh2e.com/appointment/station/getStationInfoByArea").post(RequestBody.create(json.toString(), MediaType.parse("application/json"))).build()).enqueue(new Callback() {
|
||||
@Override public void onFailure(@NonNull Call call, @NonNull IOException e) {}
|
||||
@Override public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
|
||||
@Override
|
||||
public void onFailure(@NonNull Call call, @NonNull IOException e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
try {
|
||||
JSONObject res = new JSONObject(response.body().string());
|
||||
@@ -437,11 +686,15 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
||||
markStation(endPoint, endName, true);
|
||||
});
|
||||
}
|
||||
} catch (Exception e) { e.printStackTrace(); }
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (Exception e) { e.printStackTrace(); }
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void fetchNearbyStations(AMapLocation loc) {
|
||||
@@ -451,8 +704,12 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
||||
json.put("latitude", loc.getLatitude());
|
||||
|
||||
httpClient.newCall(new Request.Builder().url("https://beta-esg.api.lnh2e.com/appointment/station/getNearbyHydrogenStationsByLocation").post(RequestBody.create(json.toString(), MediaType.parse("application/json"))).build()).enqueue(new Callback() {
|
||||
@Override public void onFailure(@NonNull Call call, @NonNull IOException e) {}
|
||||
@Override public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
|
||||
@Override
|
||||
public void onFailure(@NonNull Call call, @NonNull IOException e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
try {
|
||||
JSONObject res = new JSONObject(response.body().string());
|
||||
@@ -462,14 +719,162 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
||||
try {
|
||||
JSONObject item = array.getJSONObject(i);
|
||||
markStation(new LatLng(item.getDouble("latitude"), item.getDouble("longitude")), item.getString("name"), false);
|
||||
} catch (Exception ignored) {}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (Exception e) { e.printStackTrace(); }
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (Exception e) { e.printStackTrace(); }
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析接口返回的data数据
|
||||
*/
|
||||
private TruckRouteData parseTruckRouteData(JSONObject data) throws Exception {
|
||||
TruckRouteData truckRouteData = new TruckRouteData();
|
||||
|
||||
// 解析truckDto
|
||||
if (data.has("truckDto") && !data.isNull("truckDto")) {
|
||||
JSONObject truckJson = data.getJSONObject("truckDto");
|
||||
TruckDto truckDto = new TruckDto();
|
||||
truckDto.isRestriction = truckJson.optBoolean("isRestriction", true);
|
||||
truckDto.mvehicleSizeName = truckJson.optString("mvehicleSizeName", "");
|
||||
truckDto.mvehicleAxisUnit = truckJson.optString("mvehicleAxisUnit", "轴");
|
||||
truckDto.mcarNumber = truckJson.optString("mcarNumber", "");
|
||||
truckDto.mcarType = truckJson.optInt("mcarType", 0);
|
||||
truckDto.mvehicleHeight = truckJson.optString("mvehicleHeight", "");
|
||||
truckDto.mvehicleHeightUnit = truckJson.optString("mvehicleHeightUnit", "M");
|
||||
truckDto.mvehicleWeight = truckJson.optString("mvehicleWeight", "");
|
||||
truckDto.mvehicleWeightUnit = truckJson.optString("mvehicleWeightUnit", "T");
|
||||
truckDto.mvehicleLoad = truckJson.optString("mvehicleLoad", "");
|
||||
truckDto.mvehicleLoadUnit = truckJson.optString("mvehicleLoadUnit", "T");
|
||||
truckDto.mvehicleLoadSwitch = truckJson.optBoolean("mvehicleLoadSwitch", false);
|
||||
truckDto.mvehicleWidth = truckJson.optString("mvehicleWidth", "");
|
||||
truckDto.mvehicleWidthUnit = truckJson.optString("mvehicleWidthUnit", "M");
|
||||
truckDto.mvehicleLength = truckJson.optString("mvehicleLength", "");
|
||||
truckDto.mvehicleLengthUnit = truckJson.optString("mvehicleLengthUnit", "M");
|
||||
truckDto.mvehicleSize = truckJson.optInt("mvehicleSize", 2);
|
||||
truckDto.mvehicleAxis = truckJson.optInt("mvehicleAxis", 2);
|
||||
truckRouteData.truckDto = truckDto;
|
||||
}
|
||||
|
||||
// 解析destinationSite
|
||||
if (data.has("destinationSite") && !data.isNull("destinationSite")) {
|
||||
JSONObject siteJson = data.getJSONObject("destinationSite");
|
||||
DestinationSite destinationSite = new DestinationSite();
|
||||
destinationSite.innerSiteId = siteJson.optString("innerSiteId", "");
|
||||
destinationSite.name = siteJson.optString("name", "");
|
||||
destinationSite.shortName = siteJson.optString("shortName", "");
|
||||
destinationSite.siteNo = siteJson.optString("siteNo", "");
|
||||
destinationSite.city = siteJson.optString("city", "");
|
||||
destinationSite.address = siteJson.optString("address", "");
|
||||
destinationSite.contact = siteJson.optString("contact", "");
|
||||
destinationSite.phone = siteJson.optString("phone", "");
|
||||
destinationSite.type = siteJson.optString("type", "");
|
||||
destinationSite.coOpMode = siteJson.optString("coOpMode", "");
|
||||
destinationSite.booking = siteJson.optString("booking", "");
|
||||
destinationSite.siteStatus = siteJson.optString("siteStatus", "");
|
||||
destinationSite.siteStatusName = siteJson.optString("siteStatusName", "");
|
||||
destinationSite.startBusiness = siteJson.optString("startBusiness", "");
|
||||
destinationSite.endBusiness = siteJson.optString("endBusiness", "");
|
||||
destinationSite.billingMethod = siteJson.optString("billingMethod", "");
|
||||
destinationSite.term = siteJson.optString("term", "");
|
||||
destinationSite.remark = siteJson.optString("remark", "");
|
||||
destinationSite.longitude = siteJson.optString("longitude", "");
|
||||
destinationSite.latitude = siteJson.optString("latitude", "");
|
||||
destinationSite.distance = siteJson.optString("distance", "");
|
||||
truckRouteData.destinationSite = destinationSite;
|
||||
}
|
||||
|
||||
// 解析pathDto
|
||||
if (data.has("pathDto") && !data.isNull("pathDto")) {
|
||||
JSONObject pathJson = data.getJSONObject("pathDto");
|
||||
PathDto pathDto = new PathDto();
|
||||
pathDto.distance = pathJson.optInt("distance", 0);
|
||||
pathDto.duration = pathJson.optInt("duration", 0);
|
||||
pathDto.strategy = pathJson.optString("strategy", "");
|
||||
pathDto.tolls = pathJson.optString("tolls", "");
|
||||
pathDto.toll_distance = pathJson.optInt("toll_distance", 0);
|
||||
pathDto.restriction = pathJson.optInt("restriction", -1);
|
||||
pathDto.traffic_lights = pathJson.optInt("traffic_lights", 0);
|
||||
|
||||
// 解析naviList
|
||||
if (pathJson.has("naviList") && !pathJson.isNull("naviList")) {
|
||||
JSONArray naviArray = pathJson.getJSONArray("naviList");
|
||||
List<NaviPoint> naviList = new ArrayList<>();
|
||||
for (int i = 0; i < naviArray.length(); i++) {
|
||||
JSONObject naviJson = naviArray.getJSONObject(i);
|
||||
NaviPoint naviPoint = new NaviPoint();
|
||||
naviPoint.name = naviJson.optString("name", "");
|
||||
naviPoint.poiId = naviJson.optString("poiId", "");
|
||||
|
||||
if (naviJson.has("coordinate") && !naviJson.isNull("coordinate")) {
|
||||
JSONObject coordJson = naviJson.getJSONObject("coordinate");
|
||||
Coordinate coordinate = new Coordinate();
|
||||
coordinate.longitude = coordJson.optString("longitude", "");
|
||||
coordinate.latitude = coordJson.optString("latitude", "");
|
||||
naviPoint.coordinate = coordinate;
|
||||
}
|
||||
|
||||
naviList.add(naviPoint);
|
||||
}
|
||||
pathDto.naviList = naviList;
|
||||
}
|
||||
|
||||
truckRouteData.pathDto = pathDto;
|
||||
}
|
||||
|
||||
// 解析algorithmPath
|
||||
if (data.has("algorithmPath") && !data.isNull("algorithmPath")) {
|
||||
JSONObject algorithmJson = data.getJSONObject("algorithmPath");
|
||||
AlgorithmPath algorithmPath = new AlgorithmPath();
|
||||
algorithmPath.tripRecommendationId = algorithmJson.optString("tripRecommendationId", "");
|
||||
algorithmPath.staId = algorithmJson.optString("staId", "");
|
||||
algorithmPath.tripOneWayPathId = algorithmJson.optString("tripOneWayPathId", "");
|
||||
algorithmPath.tripReturnPathId = algorithmJson.optString("tripReturnPathId", "");
|
||||
algorithmPath.oneWayDis = algorithmJson.optString("oneWayDis", "");
|
||||
algorithmPath.returnDis = algorithmJson.optString("returnDis", "");
|
||||
algorithmPath.roundTripDis = algorithmJson.optString("roundTripDis", "");
|
||||
algorithmPath.oneWayTime = algorithmJson.optString("oneWayTime", "");
|
||||
algorithmPath.returnTime = algorithmJson.optString("returnTime", "");
|
||||
algorithmPath.roundTripTime = algorithmJson.optString("roundTripTime", "");
|
||||
algorithmPath.oneWayCost = algorithmJson.optString("oneWayCost", "");
|
||||
algorithmPath.returnCost = algorithmJson.optString("returnCost", "");
|
||||
algorithmPath.roundTripCost = algorithmJson.optString("roundTripCost", "");
|
||||
algorithmPath.oneWayLaborCost = algorithmJson.optString("oneWayLaborCost", "");
|
||||
algorithmPath.returnLaborCost = algorithmJson.optString("returnLaborCost", "");
|
||||
algorithmPath.roundTripLaborCost = algorithmJson.optString("roundTripLaborCost", "");
|
||||
algorithmPath.oneWayChargerouteCost = algorithmJson.optString("oneWayChargerouteCost", "");
|
||||
algorithmPath.returnChargerouteCost = algorithmJson.optString("returnChargerouteCost", "");
|
||||
algorithmPath.roundTripChargerouteCost = algorithmJson.optString("roundTripChargerouteCost", "");
|
||||
algorithmPath.oneWayHydrogenConsumption = algorithmJson.optString("oneWayHydrogenConsumption", "");
|
||||
algorithmPath.returnLaborHydrogenConsumption = algorithmJson.optString("returnLaborHydrogenConsumption", "");
|
||||
algorithmPath.roundTripHydrogenConsumption = algorithmJson.optString("roundTripHydrogenConsumption", "");
|
||||
algorithmPath.oneWayHydrogenCost = algorithmJson.optString("oneWayHydrogenCost", "");
|
||||
algorithmPath.returnLaborHydrogenCost = algorithmJson.optString("returnLaborHydrogenCost", "");
|
||||
algorithmPath.roundTripHydrogenCost = algorithmJson.optString("roundTripHydrogenCost", "");
|
||||
algorithmPath.hydrogenCost = algorithmJson.optString("hydrogenCost", "");
|
||||
algorithmPath.hydrogenStaServiceTime = algorithmJson.optString("hydrogenStaServiceTime", "");
|
||||
algorithmPath.hydrogenStaRefuelingTime = algorithmJson.optString("hydrogenStaRefuelingTime", "");
|
||||
algorithmPath.hydrogenStaQueueTime = algorithmJson.optString("hydrogenStaQueueTime", "");
|
||||
algorithmPath.hydrogenStaServiceTimeCost = algorithmJson.optString("hydrogenStaServiceTimeCost", "");
|
||||
algorithmPath.hydrogenStaRefuelingTimeCost = algorithmJson.optString("hydrogenStaRefuelingTimeCost", "");
|
||||
algorithmPath.hydrogenStaQueueTimeCost = algorithmJson.optString("hydrogenStaQueueTimeCost", "");
|
||||
truckRouteData.algorithmPath = algorithmPath;
|
||||
}
|
||||
|
||||
// 其他字段
|
||||
truckRouteData.truckDtoStr = data.optString("truckDtoStr", null);
|
||||
truckRouteData.isInvokeAlgorithm = data.optBoolean("isInvokeAlgorithm", false);
|
||||
|
||||
return truckRouteData;
|
||||
}
|
||||
|
||||
private void markStation(LatLng latLng, String name, boolean isRecommend) {
|
||||
@@ -489,23 +894,53 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public void onGeocodeSearched(GeocodeResult r, int c) {}
|
||||
@Override public void onBusRouteSearched(BusRouteResult r, int c) {}
|
||||
@Override public void onWalkRouteSearched(WalkRouteResult r, int c) {}
|
||||
@Override public void onRideRouteSearched(RideRouteResult r, int c) {}
|
||||
@Override
|
||||
public void onGeocodeSearched(GeocodeResult r, int c) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBusRouteSearched(BusRouteResult r, int c) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWalkRouteSearched(WalkRouteResult r, int c) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRideRouteSearched(RideRouteResult r, int c) {
|
||||
}
|
||||
|
||||
private Activity getActivityFromContext(Context context) {
|
||||
if (context instanceof Activity) return (Activity) context;
|
||||
if (context instanceof android.content.ContextWrapper) return getActivityFromContext(((android.content.ContextWrapper) context).getBaseContext());
|
||||
if (context instanceof Activity)
|
||||
return (Activity) context;
|
||||
if (context instanceof android.content.ContextWrapper)
|
||||
return getActivityFromContext(((android.content.ContextWrapper) context).getBaseContext());
|
||||
return null;
|
||||
}
|
||||
|
||||
public void onResume() { mapView.onResume(); }
|
||||
public void onPause() { mapView.onPause(); }
|
||||
public void onSaveInstanceState(Bundle out) { mapView.onSaveInstanceState(out); }
|
||||
@Override public View getView() { return container; }
|
||||
@Override public void dispose() {
|
||||
if (mlocationClient != null) { mlocationClient.stopLocation(); mlocationClient.onDestroy(); }
|
||||
public void onResume() {
|
||||
mapView.onResume();
|
||||
}
|
||||
|
||||
public void onPause() {
|
||||
mapView.onPause();
|
||||
}
|
||||
|
||||
public void onSaveInstanceState(Bundle out) {
|
||||
mapView.onSaveInstanceState(out);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView() {
|
||||
return container;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
if (mlocationClient != null) {
|
||||
mlocationClient.stopLocation();
|
||||
mlocationClient.onDestroy();
|
||||
}
|
||||
mapView.onDestroy();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,13 +100,16 @@ class StorageService extends GetxService {
|
||||
await _box.write(_nameKey, name);
|
||||
await _box.write(_phoneKey, phone);
|
||||
await _box.write(_idCardKey, idCard);
|
||||
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString('token', token);
|
||||
}
|
||||
|
||||
Future<void> saveVehicleInfo(VehicleInfo data) async {
|
||||
await _box.write(_vehicleInfoKey, vehicleInfoToJson(data));
|
||||
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString('plateNumber', data.plateNumber ?? "");
|
||||
await prefs.setString('plateNumber', data.plateNumber);
|
||||
}
|
||||
|
||||
Future<void> saveStationCredentials(String account, String password) async {
|
||||
@@ -124,6 +127,7 @@ class StorageService extends GetxService {
|
||||
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
await prefs.remove('plateNumber');
|
||||
await prefs.remove('token');
|
||||
}
|
||||
|
||||
Future<void> clearStationCredentials() async {
|
||||
|
||||
Reference in New Issue
Block a user