From 4cf17402f97aaba90aff37bb5c19fe04f20d2083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=91=A3=E5=AE=8F=E5=AE=87?= Date: Sun, 11 Jul 2021 23:28:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=B0=8F=E5=9C=B0=E5=9B=BE?= =?UTF-8?q?=E4=BB=A5=E5=8F=8A=E8=AE=A2=E4=BD=8D=E7=BD=AE=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E5=92=8C=E8=AE=A2=E5=8D=95=E7=AB=99=E7=82=B9=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mogo/och/bus/fragment/OchBusFragment.java | 1 + .../mogo/map/impl/custom/AMapViewWrapper.java | 18 +- .../small/map/SmallMapDirectionView.java | 193 +++++++++--------- .../module/small/map/SmpServiceManager.java | 45 ++++ 4 files changed, 149 insertions(+), 108 deletions(-) create mode 100644 modules/mogo-module-smp/src/main/java/com/mogo/module/small/map/SmpServiceManager.java diff --git a/OCH/mogo-och-bus/src/main/java/com/mogo/och/bus/fragment/OchBusFragment.java b/OCH/mogo-och-bus/src/main/java/com/mogo/och/bus/fragment/OchBusFragment.java index 17e26d4f0b..7023366f2b 100644 --- a/OCH/mogo-och-bus/src/main/java/com/mogo/och/bus/fragment/OchBusFragment.java +++ b/OCH/mogo-och-bus/src/main/java/com/mogo/och/bus/fragment/OchBusFragment.java @@ -218,6 +218,7 @@ public class OchBusFragment extends BaseOchFragment< OchBusFragment, OchBusPrese * @param launch true-收车,false-出车 */ public void changeOperationStatus( boolean launch ) { + mPresenter.queryBusRoutes(); isOperationStatus = launch; if ( launch ) { tvOperationStatus.setText( "收车" ); diff --git a/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/AMapViewWrapper.java b/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/AMapViewWrapper.java index 86f62f3ac5..fcfe6a1b54 100644 --- a/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/AMapViewWrapper.java +++ b/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/AMapViewWrapper.java @@ -18,7 +18,6 @@ import android.widget.TextView; import com.mogo.commons.constants.SharedPrefsConstants; import com.mogo.commons.debug.DebugConfig; -import com.mogo.commons.voice.AIAssist; import com.mogo.map.IMogoMap; import com.mogo.map.IMogoMapView; import com.mogo.map.MogoLatLng; @@ -36,7 +35,6 @@ import com.mogo.map.uicontroller.IMogoMapUIController; import com.mogo.map.uicontroller.MapCameraPosition; import com.mogo.map.uicontroller.MapControlResult; import com.mogo.map.uicontroller.VisualAngleMode; -import com.mogo.realtime.entity.ADASRecognizedResult; import com.mogo.utils.TipToast; import com.mogo.utils.UiThreadHandler; import com.mogo.utils.logger.Logger; @@ -761,13 +759,15 @@ public class AMapViewWrapper implements IMogoMapView, sysLocation.setBearing(location.getHeading()); sysLocation.setSpeed(location.getSpeed()); - // 暂存本地,提供给下一次的Http-DNS使用,防止首次请求位置获取不到 - SharedPrefsMgr.getInstance(mMapView.getContext()) - .putString(SharedPrefsConstants.LOCATION_CITY_CODE, location.getCityCode()); - SharedPrefsMgr.getInstance(mMapView.getContext()) - .putString(SharedPrefsConstants.LOCATION_LATITUDE, String.valueOf(location.getLat())); - SharedPrefsMgr.getInstance(mMapView.getContext()) - .putString(SharedPrefsConstants.LOCATION_LONGITUDE, String.valueOf(location.getLon())); + // 将有效经纬度暂存本地,提供给下一次的Http-DNS使用,防止首次请求位置获取不到 + if (location.getLat() > 0) { + SharedPrefsMgr.getInstance(mMapView.getContext()) + .putString(SharedPrefsConstants.LOCATION_CITY_CODE, location.getCityCode()); + SharedPrefsMgr.getInstance(mMapView.getContext()) + .putString(SharedPrefsConstants.LOCATION_LATITUDE, String.valueOf(location.getLat())); + SharedPrefsMgr.getInstance(mMapView.getContext()) + .putString(SharedPrefsConstants.LOCATION_LONGITUDE, String.valueOf(location.getLon())); + } NaviClient.getInstance(getContext()).syncCarLocation(sysLocation); diff --git a/modules/mogo-module-smp/src/main/java/com/mogo/module/small/map/SmallMapDirectionView.java b/modules/mogo-module-smp/src/main/java/com/mogo/module/small/map/SmallMapDirectionView.java index c0a3c3650d..9c354cbcfb 100644 --- a/modules/mogo-module-smp/src/main/java/com/mogo/module/small/map/SmallMapDirectionView.java +++ b/modules/mogo-module-smp/src/main/java/com/mogo/module/small/map/SmallMapDirectionView.java @@ -2,12 +2,10 @@ package com.mogo.module.small.map; import android.content.Context; import android.graphics.BitmapFactory; +import android.location.Location; import android.util.AttributeSet; -import android.util.Log; import android.view.LayoutInflater; import android.view.MotionEvent; -import android.view.ViewGroup; -import android.widget.FrameLayout; import android.widget.RelativeLayout; import androidx.annotation.Nullable; @@ -16,15 +14,18 @@ import com.amap.api.maps.AMap; import com.amap.api.maps.CameraUpdate; import com.amap.api.maps.CameraUpdateFactory; import com.amap.api.maps.UiSettings; +import com.amap.api.maps.model.CustomMapStyleOptions; +import com.amap.api.navi.AMapNavi; import com.amap.api.navi.AMapNaviView; import com.amap.api.navi.AMapNaviViewOptions; import com.mogo.commons.AbsMogoApplication; import com.mogo.commons.debug.DebugConfig; +import com.mogo.map.MogoLatLng; +import com.mogo.map.navi.IMogoCarLocationChangedListener2; import com.mogo.module.common.MogoApisHandler; import com.mogo.module.common.view.RoundLayout; -import com.mogo.utils.FileUtils; - -import java.io.IOException; +import com.mogo.module.small.map.utils.MapAssetStyleUtils; +import com.mogo.utils.logger.Logger; /** * 小地图的方向View @@ -32,13 +33,19 @@ import java.io.IOException; * @author donghongyu * @date 12/14/20 4:40 PM */ -public class SmallMapDirectionView extends RelativeLayout { - private String styleFilePath = "/mnt/sdcard/amap/small_map_style.data"; +public class SmallMapDirectionView + extends RelativeLayout + implements IMogoCarLocationChangedListener2 { + + //小地图名称 + public static final String MODULE_NAME = "SmallMap"; private RoundLayout rlSmallMapBorder; + private AMapNaviView mAMapNaviView; + private AMap mAMap; + private AMapNavi mAMapNavi; private int zoomLevel = 15; - private boolean mapIsLoaded = false; public SmallMapDirectionView(Context context) { this(context, null); @@ -64,15 +71,75 @@ public class SmallMapDirectionView extends RelativeLayout { rlSmallMapBorder = findViewById(R.id.rlSmallMapBorder); rlSmallMapBorder.addView(mAMapNaviView); + + initAMapView(); + + // 注册定位监听 + SmpServiceManager.getMogoRegisterCenter() + .registerCarLocationChangedListener(MODULE_NAME, this); + + setOnClickListener(view -> { + if (DebugConfig.getCarMachineType() != DebugConfig.CAR_MACHINE_TYPE_LENOVO) { + MogoApisHandler.getInstance().getApis() + .getMapServiceApi() + .getMapUIController() + .changeMapMode( + MogoApisHandler.getInstance() + .getApis() + .getAdasControllerApi() + .getCurrentSkinMode() + ); + } + }); + } + + @Override + protected void onDetachedFromWindow() { + super.onDetachedFromWindow(); + // 注册定位监听 + SmpServiceManager.getMogoRegisterCenter() + .unregisterCarLocationChangedListener(MODULE_NAME, this); + + } + + private void initAMapView() { // 车头朝上 mAMapNaviView.setNaviMode(AMapNaviView.CAR_UP_MODE); // 设置电子眼所在路线的可见性 mAMapNaviView.setRouteOverlayVisible(false); - AMap aMap = mAMapNaviView.getMap(); + mAMap = mAMapNaviView.getMap(); // 关闭地图文字标注 - aMap.showMapText(false); + mAMap.showMapText(false); + // 设置导航地图模式,aMap是地图控制器对象。 + mAMap.setMapType(AMap.MAP_TYPE_NIGHT); + // 关闭显示实时路况图层,aMap是地图控制器对象。 + mAMap.setTrafficEnabled(false); + + mAMapNavi = AMapNavi.getInstance(getContext()); + //使用外部GPS数据 + mAMapNavi.setIsUseExtraGPSData(true); + + + new Thread(() -> { + try { + Thread.sleep(1000L); + } catch (InterruptedException e) { + e.printStackTrace(); + } + mAMap.setCustomMapStyle( + new CustomMapStyleOptions() + .setEnable(true) + .setStyleData(MapAssetStyleUtils.getAssetsStyle(getContext())) + .setStyleExtraData(MapAssetStyleUtils.getAssetsExtraStyle(getContext())) + ); + + //设置希望展示的地图缩放级别 + CameraUpdate cameraUpdate = CameraUpdateFactory.zoomTo(zoomLevel); + mAMap.moveCamera(cameraUpdate); + }).start(); + // 设置地图的样式 - UiSettings uiSettings = aMap.getUiSettings(); + UiSettings uiSettings = mAMap.getUiSettings(); uiSettings.setZoomControlsEnabled(false);// 地图缩放级别的交换按钮 uiSettings.setAllGesturesEnabled(false);// 所有手势 uiSettings.setMyLocationButtonEnabled(false); // 显示默认的定位按钮 @@ -139,95 +206,9 @@ public class SmallMapDirectionView extends RelativeLayout { // 2D模式 options.setTilt(0); // 黑夜模式 - //options.setNaviNight(true); - // 自定义地图样式 - options.setCustomMapStylePath(styleFilePath); + options.setNaviNight(true); mAMapNaviView.setViewOptions(options); } - - //设置希望展示的地图缩放级别 - CameraUpdate cameraUpdate = CameraUpdateFactory.zoomTo(zoomLevel); - aMap.moveCamera(cameraUpdate); - - try { - // 判断是否有样式文件存在 - FileUtils.copy( - context.getAssets().open("small_map_style.data"), - styleFilePath, - new FileUtils.FileCopyListener() { - - @Override - public void onStart() { - Log.w("FileCopyListener", "onStart="); - - } - - @Override - public void onFail(Exception e) { - Log.w("FileCopyListener", "onFail="); - e.printStackTrace(); - } - - @Override - public void onProcess(int process) { - Log.w("FileCopyListener", "onProcess=" + process); - - } - - @Override - public void onFinish(String toPath) { - Log.w("FileCopyListener", "onFinish toPath=" + toPath); - - // 高德地图有bug,所以需要多次调用设置皮肤才能成功 - if (options != null) { - options.setCustomMapStylePath(styleFilePath); - mAMapNaviView.setViewOptions(options); - } - - //设置希望展示的地图缩放级别 - CameraUpdate cameraUpdate = CameraUpdateFactory.zoomTo(zoomLevel); - aMap.moveCamera(cameraUpdate); - } - } - ); - } catch (IOException e) { - e.printStackTrace(); - } - - new Thread(new Runnable() { - @Override - public void run() { - try { - Thread.sleep(1000L); - } catch (InterruptedException e) { - e.printStackTrace(); - } - // 高德地图有bug,所以需要多次调用设置皮肤才能成功 - if (options != null) { - options.setCustomMapStylePath(styleFilePath); - mAMapNaviView.setViewOptions(options); - } - - //设置希望展示的地图缩放级别 - CameraUpdate cameraUpdate = CameraUpdateFactory.zoomTo(zoomLevel); - aMap.moveCamera(cameraUpdate); - } - }).start(); - - - setOnClickListener(view -> { - if (DebugConfig.getCarMachineType() != DebugConfig.CAR_MACHINE_TYPE_LENOVO ) { - MogoApisHandler.getInstance().getApis() - .getMapServiceApi() - .getMapUIController() - .changeMapMode( - MogoApisHandler.getInstance() - .getApis() - .getAdasControllerApi() - .getCurrentSkinMode() - ); - } - }); } @@ -235,4 +216,18 @@ public class SmallMapDirectionView extends RelativeLayout { public boolean onInterceptTouchEvent(MotionEvent ev) { return true; } + + @Override + public void onCarLocationChanged2(Location latLng) { + Logger.d(MODULE_NAME, "onCarLocationChanged2 latLng:" + latLng); + if (mAMapNavi != null) { + mAMapNavi.setExtraGPSData(2, latLng); + } + } + + @Override + public void onCarLocationChanged(MogoLatLng latLng) { + Logger.d(MODULE_NAME, "onCarLocationChanged latLng:" + latLng); + } + } diff --git a/modules/mogo-module-smp/src/main/java/com/mogo/module/small/map/SmpServiceManager.java b/modules/mogo-module-smp/src/main/java/com/mogo/module/small/map/SmpServiceManager.java new file mode 100644 index 0000000000..75e01881ca --- /dev/null +++ b/modules/mogo-module-smp/src/main/java/com/mogo/module/small/map/SmpServiceManager.java @@ -0,0 +1,45 @@ +package com.mogo.module.small.map; + +import android.content.Context; + +import com.alibaba.android.arouter.launcher.ARouter; +import com.mogo.service.IMogoServiceApis; +import com.mogo.service.MogoServicePaths; +import com.mogo.service.module.IMogoRegisterCenter; + +/** + * author : donghongyu + * e-mail : 1358506549@qq.com + * date : 2020-01-2114:01 + * desc : V2X 服务 + * version: 1.0 + */ +public class SmpServiceManager { + private static final String TAG = "V2XServiceManager"; + private static boolean isInit; + private static Context mContext; + private static IMogoServiceApis mMogoServiceApis; + private static IMogoRegisterCenter mMogoRegisterCenter; + + private SmpServiceManager() { + + } + + public static void init(final Context context) { + if (!isInit) { + isInit = true; + mContext = context; + mMogoServiceApis = (IMogoServiceApis) ARouter.getInstance().build(MogoServicePaths.PATH_SERVICE_APIS).navigation(context); + mMogoRegisterCenter = mMogoServiceApis.getRegisterCenterApi(); + } + } + + public static Context getContext() { + return mContext; + } + + public static IMogoRegisterCenter getMogoRegisterCenter() { + return mMogoRegisterCenter; + } + +}