diff --git a/foudations/mogo-base-websocket-sdk/src/main/java/com/mogo/base/websocket/WebSocketHandlerThread.java b/foudations/mogo-base-websocket-sdk/src/main/java/com/mogo/base/websocket/WebSocketHandlerThread.java index bf17ae09c5..4343842f8c 100644 --- a/foudations/mogo-base-websocket-sdk/src/main/java/com/mogo/base/websocket/WebSocketHandlerThread.java +++ b/foudations/mogo-base-websocket-sdk/src/main/java/com/mogo/base/websocket/WebSocketHandlerThread.java @@ -19,9 +19,8 @@ public class WebSocketHandlerThread extends HandlerThread { tag = name; } - @Override - public void run() { - super.run(); + + public void initHandler(){ mHandler = new Handler(this.getLooper()) { @Override public void handleMessage(Message msg) { @@ -34,6 +33,7 @@ public class WebSocketHandlerThread extends HandlerThread { }; } + public void sendMsg(String msg) { if(mHandler!=null) { Message message = new Message(); diff --git a/foudations/mogo-base-websocket-sdk/src/main/java/com/mogo/base/websocket/WebSocketManager.java b/foudations/mogo-base-websocket-sdk/src/main/java/com/mogo/base/websocket/WebSocketManager.java index 5cd489872b..e83e05a4a3 100644 --- a/foudations/mogo-base-websocket-sdk/src/main/java/com/mogo/base/websocket/WebSocketManager.java +++ b/foudations/mogo-base-websocket-sdk/src/main/java/com/mogo/base/websocket/WebSocketManager.java @@ -35,6 +35,7 @@ public class WebSocketManager implements IMogoWebSocketManager, ISocketMsgSettin public WebSocketManager(Context context) { handlerThread = new WebSocketHandlerThread(TAG); handlerThread.start(); + handlerThread.initHandler(); } @Keep @@ -155,6 +156,7 @@ public class WebSocketManager implements IMogoWebSocketManager, ISocketMsgSettin @Override public void onConnectClose() { Logger.d(TAG, "websocket ready to reconnect"); + SocketClient.getInstance().getClientProxy().stop(); SocketClient.getInstance().getClientProxy().reConnect(); } diff --git a/libraries/map-custom/build.gradle b/libraries/map-custom/build.gradle index be76b52f42..31c8e8ebee 100644 --- a/libraries/map-custom/build.gradle +++ b/libraries/map-custom/build.gradle @@ -55,7 +55,7 @@ dependencies { implementation project(':foudations:mogo-commons') } - implementation 'com.zhidaoauto.machine:map:1.0.0-online-16' + implementation 'com.zhidaoauto.machine:map:1.0.0-online-18' } apply from: new File(rootProject.rootDir, "gradle/upload.gradle").toString() 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 c59d308e86..ad1ed7b446 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 @@ -68,27 +68,27 @@ public class AMapViewWrapper implements IMogoMapView, IMogoMapUIController, Loca private float mDefaultZoomLevel = 16.0f; private final CarCursorOption DEFAULT_OPTION = new CarCursorOption.Builder() - .carCursorRes(R.drawable.map_api_ic_current_location2) - .naviCursorRes(R.drawable.ic_amap_navi_cursor) + .carCursorRes( R.drawable.map_api_ic_current_location2 ) + .naviCursorRes( R.drawable.ic_amap_navi_cursor ) .build(); private CarCursorOption mCarCursorOption = DEFAULT_OPTION; - public AMapViewWrapper(MapAutoView mMapView) { + public AMapViewWrapper( MapAutoView mMapView ) { startTime = System.currentTimeMillis(); - Logger.i(TAG, "autoop--AMapViewWrapper: init"); + Logger.i( TAG, "autoop--AMapViewWrapper: init" ); this.mMapView = mMapView; initListeners(); - this.mIMap = new AMapWrapper(this.mMapView.getMapAutoViewHelper(), this.mMapView, this); + this.mIMap = new AMapWrapper( this.mMapView.getMapAutoViewHelper(), this.mMapView, this ); } private void initMapView() { - if (mMapView == null) { + if ( mMapView == null ) { return; } MapAutoViewHelper options = mMapView.getMapAutoViewHelper(); - if (options != null) { + if ( options != null ) { // 设置是否开启自动黑夜模式切换,默认为false,不自动切换 - options.setAutoSwitchStyle(false); +// options.setAutoSwitchStyle(false); // 设置6秒后是否自动锁车 // options.setAutoLockCar( false ); // 设置路线上的摄像头气泡是否显示 @@ -96,11 +96,11 @@ public class AMapViewWrapper implements IMogoMapView, IMogoMapUIController, Loca // 设置路线相关的配置属性,如:路线的路况颜色,路线上是否显示摄像头气泡等。 // options.setRouteOverlayOptions( MapStyleUtils.getRouteOverlayOptions() ); // 设置自车的图片对象 - options.setMyLocationStyle( options.getMyLocationStyle().myLocationIcon(DEFAULT_OPTION.getCarCursorRes())); + options.setMyLocationStyle( options.getMyLocationStyle().myLocationIcon( DEFAULT_OPTION.getCarCursorRes() ) ); // 设置指南针图标否在导航界面显示,默认显示。true,显示;false,隐藏。 - options.hiddenDirection(); +// options.hiddenDirection(); // 黑夜模式 - options.setMapStyle(MapAutoApi.MAP_STYLE_NIGHT); +// options.setMapStyle(MapAutoApi.MAP_STYLE_NIGHT); //设置路况光柱条是否显示(只适用于驾车导航,需要联网)。 // options.setTrafficBarEnabled( false ); // 设置[实时交通图层开关按钮]是否显示(只适用于驾车导航,需要联网)。 @@ -137,29 +137,29 @@ public class AMapViewWrapper implements IMogoMapView, IMogoMapUIController, Loca // options.setNaviArrowVisible( false ); // 通过路线是否自动置灰,仅支持驾车导航 // options.setAfterRouteAutoGray( true ); - options.setZoom(((int) mDefaultZoomLevel)); +// options.setZoom(((int) mDefaultZoomLevel)); // options.setPointToCenter( 0.5D, 0.5D ); // 2D模式 - options.setMapViewPerspective(MapAutoApi.MAP_PERSPECTIVE_2D); +// options.setMapViewPerspective(MapAutoApi.MAP_PERSPECTIVE_2D); // mMapView.setViewOptions( options ); } // mMapView.setRouteOverlayVisible( false ); // mMapView.setCarOverlayVisible( false ); - setUIMode(EnumMapUI.CarUp_2D); +// setUIMode(EnumMapUI.CarUp_2D); } private void initListeners() { - mMapView.setOnMarkClickListener(this); + mMapView.setOnMarkClickListener( this ); mMarkerClickHandler = new AMapMarkerClickHandler(); - mMapView.setOnMapLoadedListener(this); - mMapView.setOnMapTouchListener(this); - mMapView.setOnMapClickListener(this); - mMapView.getLocationClient().registerListener(this); - mMapView.registerListener(this, MapAutoApi.LISTENER_TYPE_ZOOM); - mMapView.registerListener(this, MapAutoApi.LISTENER_TYPE_ROTATE); - mMapView.registerListener(this, MapAutoApi.LISTENER_TYPE_3D); - mMapView.setMOnCameraChangeListener(this); + mMapView.setOnMapLoadedListener( this ); + mMapView.setOnMapTouchListener( this ); + mMapView.setOnMapClickListener( this ); + mMapView.getLocationClient().registerListener( this ); + mMapView.registerListener( this, MapAutoApi.LISTENER_TYPE_ZOOM ); + mMapView.registerListener( this, MapAutoApi.LISTENER_TYPE_ROTATE ); + mMapView.registerListener( this, MapAutoApi.LISTENER_TYPE_3D ); + mMapView.setMOnCameraChangeListener( this ); // mMapView.setOnPolylineClickListener( this ); // mMapView.setAMapNaviViewListener( this ); @@ -190,10 +190,10 @@ public class AMapViewWrapper implements IMogoMapView, IMogoMapUIController, Loca } @Override - public void onCreate(Bundle bundle) { - if (mMapView != null) { - mMapView.onCreate(bundle); - Logger.d(TAG, "map onCreate"); + public void onCreate( Bundle bundle ) { + if ( mMapView != null ) { + mMapView.onCreate( bundle ); + Logger.d( TAG, "map onCreate" ); initMapView(); // initMyLocation(); @@ -202,33 +202,33 @@ public class AMapViewWrapper implements IMogoMapView, IMogoMapUIController, Loca @Override public void onResume() { - if (mMapView != null) { + if ( mMapView != null ) { mMapView.onResume(); - Logger.d(TAG, "map onResume"); + Logger.d( TAG, "map onResume" ); } } @Override public void onPause() { - if (mMapView != null) { + if ( mMapView != null ) { mMapView.onPause(); - Logger.d(TAG, "map onPause"); + Logger.d( TAG, "map onPause" ); } } @Override public void onDestroy() { - if (mMapView != null) { + if ( mMapView != null ) { mMapView.onDestroy(); - Logger.d(TAG, "map onDestroy"); + Logger.d( TAG, "map onDestroy" ); } } @Override - public void onSaveInstanceState(Bundle outState) { - if (mMapView != null) { - mMapView.onSaveInstanceState(outState); - Logger.d(TAG, "map onSaveInstanceState"); + public void onSaveInstanceState( Bundle outState ) { + if ( mMapView != null ) { + mMapView.onSaveInstanceState( outState ); + Logger.d( TAG, "map onSaveInstanceState" ); } } @@ -238,205 +238,207 @@ public class AMapViewWrapper implements IMogoMapView, IMogoMapUIController, Loca } @Override - public void setTrafficEnabled(boolean visible) { - if (checkAMapView()) { + public void setTrafficEnabled( boolean visible ) { + if ( checkAMapView() ) { // mMapView.getMapAutoViewHelper().setTraffic(visible); } } @Override - public MapControlResult changeZoom(boolean zoom) { - if (checkAMapView()) { - mDefaultZoomLevel = (getMap().getZoomLevel() + 0.5f); + public MapControlResult changeZoom( boolean zoom ) { + if ( checkAMapView() ) { + mDefaultZoomLevel = ( getMap().getZoomLevel() + 0.5f ); - if (zoom) { - if (mDefaultZoomLevel >= 20f) { + if ( zoom ) { + if ( mDefaultZoomLevel >= 20f ) { return MapControlResult.TARGET; } } else { - if (mDefaultZoomLevel <= 7f) { + if ( mDefaultZoomLevel <= 7f ) { return MapControlResult.TARGET; } } - if (zoom) { + if ( zoom ) { mDefaultZoomLevel += 1f; - if (mDefaultZoomLevel > 19f) { + if ( mDefaultZoomLevel > 19f ) { mDefaultZoomLevel = 19f; } } else { mDefaultZoomLevel -= 1f; - if (mDefaultZoomLevel < 8f) { + if ( mDefaultZoomLevel < 8f ) { mDefaultZoomLevel = 8f; } } - changeZoom(mDefaultZoomLevel); + changeZoom( mDefaultZoomLevel ); } return MapControlResult.SUCCESS; } @Override - public MapControlResult changeZoom(float zoom) { - Logger.d(TAG, "changeZoom %s", zoom); - if (DebugConfig.isDebug()) { - Logger.d(TAG, Log.getStackTraceString(new Throwable())); + public MapControlResult changeZoom( float zoom ) { + Logger.d( TAG, "changeZoom %s", zoom ); + if ( DebugConfig.isDebug() ) { + Logger.d( TAG, Log.getStackTraceString( new Throwable() ) ); } - getMap().changeZoom(zoom); + getMap().changeZoom( zoom ); return MapControlResult.SUCCESS; } @Override - public void changeMapMode(EnumMapUI ui) { - if (ui == null) { + public void changeMapMode( EnumMapUI ui ) { + if ( ui == null ) { return; } - if (checkAMapView()) { - switch (ui) { - case CarUp_2D: - case CarUp_3D: - case NorthUP_2D: - //setUIMode( ui, options ); - return; - case Type_Light: - mMapView.getMapAutoViewHelper().setAutoSwitchStyle(false); - mMapView.getMapAutoViewHelper().setMapStyle(MapAutoApi.MAP_STYLE_DAY); - break; - case Type_Night: - mMapView.getMapAutoViewHelper().setAutoSwitchStyle(false); - mMapView.getMapAutoViewHelper().setMapStyle(MapAutoApi.MAP_STYLE_NIGHT); - break; - case Type_AUTO_LIGHT_Night: - mMapView.getMapAutoViewHelper().setAutoSwitchStyle(true); - break; - } - + if ( checkAMapView() ) { +// switch (ui) { +// case CarUp_2D: +// case CarUp_3D: +// case NorthUP_2D: +// break; +// case Type_VR: +// mMapView.getMapAutoViewHelper().setMapStyle(MapAutoApi.MAP_STYLE_VR); +// //setUIMode( ui, options ); +// return; +// case Type_Light: +// mMapView.getMapAutoViewHelper().setAutoSwitchStyle(false); +// mMapView.getMapAutoViewHelper().setMapStyle(MapAutoApi.MAP_STYLE_DAY); +// break; +// case Type_Night: +// mMapView.getMapAutoViewHelper().setAutoSwitchStyle(false); +// mMapView.getMapAutoViewHelper().setMapStyle(MapAutoApi.MAP_STYLE_NIGHT); +// break; +// case Type_AUTO_LIGHT_Night: +// mMapView.getMapAutoViewHelper().setAutoSwitchStyle(true); +// break; } + } @Override - public void moveToCenter(MogoLatLng latLng) { + public void moveToCenter( MogoLatLng latLng ) { } - private void setUIMode(EnumMapUI ui) { + private void setUIMode( EnumMapUI ui ) { this.mCurrentUIMode = ui; - if (mMapView.getMapAutoViewHelper() != null) { - switch (ui) { + if ( mMapView.getMapAutoViewHelper() != null ) { + switch ( ui ) { case CarUp_2D: - mMapView.getMapAutoViewHelper().setMapViewPerspective(MapAutoApi.MAP_PERSPECTIVE_2D); + mMapView.getMapAutoViewHelper().setMapViewPerspective( MapAutoApi.MAP_PERSPECTIVE_2D ); break; case CarUp_3D: - mMapView.getMapAutoViewHelper().setMapViewPerspective(MapAutoApi.MAP_PERSPECTIVE_3D); + mMapView.getMapAutoViewHelper().setMapViewPerspective( MapAutoApi.MAP_PERSPECTIVE_3D ); break; case NorthUP_2D: - mMapView.getMapAutoViewHelper().setRotateGesturesEnabled(false); + mMapView.getMapAutoViewHelper().setRotateGesturesEnabled( false ); break; } } } private boolean checkAMapView() { - if (mMapView == null || mMapView.getMapAutoViewHelper() == null) { - Logger.e(TAG, "自研mapView实例为空,请检查"); + if ( mMapView == null || mMapView.getMapAutoViewHelper() == null ) { + Logger.e( TAG, "自研mapView实例为空,请检查" ); return false; } return true; } @Override - public void moveToCenter(MogoLatLng latLng, boolean animate) { - Logger.d(TAG, "move to center %s", latLng); - if (latLng == null || latLng.lat == 0.0d || latLng.lng == 0.0d) { - Logger.e(TAG, "latlng = null or is illegal"); + public void moveToCenter( MogoLatLng latLng, boolean animate ) { + Logger.d( TAG, "move to center %s", latLng ); + if ( latLng == null || latLng.lat == 0.0d || latLng.lng == 0.0d ) { + Logger.e( TAG, "latlng = null or is illegal" ); return; } - if (DebugConfig.isDebug()) { - Logger.d(TAG, Log.getStackTraceString(new Throwable())); + if ( DebugConfig.isDebug() ) { + Logger.d( TAG, Log.getStackTraceString( new Throwable() ) ); } loseLockMode(); - mMapView.getMapAutoViewHelper().animateCamera(new LonLatPoint(latLng.lon, latLng.lat)); + mMapView.getMapAutoViewHelper().animateCamera( new LonLatPoint( latLng.lon, latLng.lat ) ); } @Override - public void showMyLocation(boolean visible) { - Logger.d(TAG, "showMyLocation1 %s", visible); - if (visible && NaviClient.getInstance(getContext()).isNaviing()) { + public void showMyLocation( boolean visible ) { + Logger.d( TAG, "showMyLocation1 %s", visible ); + if ( visible && NaviClient.getInstance( getContext() ).isNaviing() ) { return; } // if (DebugConfig.isDebug()) { // Logger.d(TAG, Log.getStackTraceString(new Throwable())); // } - if (checkAMapView()) { + if ( checkAMapView() ) { MyLocationStyle style = mMapView.getMapAutoViewHelper().getMyLocationStyle(); - if (visible) { + if ( visible ) { // 强制刷新一遍车标 - style.myLocationIcon(mCarCursorOption.getCarCursorRes()); + style.myLocationIcon( mCarCursorOption.getCarCursorRes() ); } - mMapView.getMapAutoViewHelper().setMyLocationStyle(style); + mMapView.getMapAutoViewHelper().setMyLocationStyle( style ); } } @Override - public void showMyLocation(View view) { - Logger.d(TAG, "showMyLocation %s", "view"); - if (NaviClient.getInstance(getContext()).isNaviing()) { + public void showMyLocation( View view ) { + Logger.d( TAG, "showMyLocation %s", "view" ); + if ( NaviClient.getInstance( getContext() ).isNaviing() ) { return; } - if (DebugConfig.isDebug()) { - Logger.d(TAG, Log.getStackTraceString(new Throwable())); + if ( DebugConfig.isDebug() ) { + Logger.d( TAG, Log.getStackTraceString( new Throwable() ) ); } - if (checkAMapView()) { + if ( checkAMapView() ) { MyLocationStyle style = mMapView.getMapAutoViewHelper().getMyLocationStyle(); style.myLocationIcon( BitmapDescriptorFactory.INSTANCE.convertViewToBitmap( view ) ); - mMapView.getMapAutoViewHelper().setMyLocationStyle(style); + mMapView.getMapAutoViewHelper().setMyLocationStyle( style ); } } public void initMyLocation() { - if (checkAMapView()) { - mMapView.getMapAutoViewHelper().setMyLocationEnabled(true); + if ( checkAMapView() ) { + mMapView.getMapAutoViewHelper().setMyLocationEnabled( true ); MyLocationStyle style = mMapView.getMapAutoViewHelper().getMyLocationStyle(); - style.setLocationType(MyLocationStyle.LOCATION_TYPE_FOLLOW_NO_CENTER); - style.interval(1000); + style.setLocationType( MyLocationStyle.LOCATION_TYPE_FOLLOW_NO_CENTER ); + style.interval( 1000 ); // style.anchor( 0.5F, 0.5F ); // style.strokeColor( Color.TRANSPARENT ); // style.strokeWidth( 0 ); // style.radiusFillColor( Color.TRANSPARENT ); - mMapView.getMapAutoViewHelper().setMyLocationStyle(style); + mMapView.getMapAutoViewHelper().setMyLocationStyle( style ); } } @Override public void recoverLockMode() { - if (checkAMapView()) { + if ( checkAMapView() ) { // if ( DebugConfig.isDebug() ) { // Logger.d( TAG, Log.getStackTraceString( new Throwable() ) ); // } - Logger.d(TAG, "锁车"); + Logger.d( TAG, "锁车" ); // mMapView.getMapAutoViewHelper().setZoom(mLockZoom); - mMapView.getMapAutoViewHelper().setLockMode(true); + mMapView.getMapAutoViewHelper().setLockMode( true ); mIsCarLocked = true; } } @Override public void loseLockMode() { - if (DebugConfig.isDebug()) { - Logger.d(TAG, Log.getStackTraceString(new Throwable())); + if ( DebugConfig.isDebug() ) { + Logger.d( TAG, Log.getStackTraceString( new Throwable() ) ); } - Logger.d(TAG, "解锁锁车"); - mMapView.getMapAutoViewHelper().setLockMode(false); + Logger.d( TAG, "解锁锁车" ); + mMapView.getMapAutoViewHelper().setLockMode( false ); mIsCarLocked = false; } @Override - public void setLockZoom(int var1) { + public void setLockZoom( int var1 ) { mLockZoom = var1; } @Override - public void displayOverview(Rect bounds) { + public void displayOverview( Rect bounds ) { } @@ -453,15 +455,15 @@ public class AMapViewWrapper implements IMogoMapView, IMogoMapUIController, Loca @Override public MogoLatLng getCameraNorthEastPosition() { - return ObjectUtils.fromAMap(MapTools.INSTANCE.getVisibleRegion().getRightTopPoint()); + return ObjectUtils.fromAMap( MapTools.INSTANCE.getVisibleRegion().getRightTopPoint() ); } @Override public MogoLatLng getCameraSouthWestPosition() { try { - return ObjectUtils.fromAMap(MapTools.INSTANCE.getVisibleRegion().getLeftBottomPoint()); - } catch (Exception e) { + return ObjectUtils.fromAMap( MapTools.INSTANCE.getVisibleRegion().getLeftBottomPoint() ); + } catch ( Exception e ) { } return null; @@ -470,30 +472,30 @@ public class AMapViewWrapper implements IMogoMapView, IMogoMapUIController, Loca @Override public MogoLatLng getWindowCenterLocation() { try { - return ObjectUtils.fromAMap(mMapView.getMapAutoViewHelper().getCenter()); - } catch (Exception e) { + return ObjectUtils.fromAMap( mMapView.getMapAutoViewHelper().getCenter() ); + } catch ( Exception e ) { } return null; } @Override - public void setPointToCenter(double mapCenterX, double mapCenterY) { - if (checkAMapView()) { + public void setPointToCenter( double mapCenterX, double mapCenterY ) { + if ( checkAMapView() ) { // if (DebugConfig.isDebug()) { // Logger.d(TAG, Log.getStackTraceString(new Throwable())); // } - Logger.d(TAG, "setPointToCenter(%s, %s)", mapCenterX, mapCenterY); - mMapView.getMapAutoViewHelper().setPointToCenter((float) mapCenterX, (float) mapCenterY); + Logger.d( TAG, "setPointToCenter(%s, %s)", mapCenterX, mapCenterY ); + mMapView.getMapAutoViewHelper().setPointToCenter( ( float ) mapCenterX, ( float ) mapCenterY ); } } @Override - public Point getLocationPointInScreen(MogoLatLng latLng) { - if (checkAMapView()) { + public Point getLocationPointInScreen( MogoLatLng latLng ) { + if ( checkAMapView() ) { try { - return MapTools.INSTANCE.toScreenLocation(ObjectUtils.fromMogo(latLng)); - } catch (Exception e) { + return MapTools.INSTANCE.toScreenLocation( ObjectUtils.fromMogo( latLng ) ); + } catch ( Exception e ) { return null; } } @@ -501,12 +503,12 @@ public class AMapViewWrapper implements IMogoMapView, IMogoMapUIController, Loca } @Override - public MogoLatLng getLocationMogoLatLngInScreen(Point point) { - if (checkAMapView()) { + public MogoLatLng getLocationMogoLatLngInScreen( Point point ) { + if ( checkAMapView() ) { try { return ObjectUtils.fromAMap( - MapTools.INSTANCE.fromScreenLocation(point)); - } catch (Exception e) { + MapTools.INSTANCE.fromScreenLocation( point ) ); + } catch ( Exception e ) { return null; } } @@ -514,9 +516,9 @@ public class AMapViewWrapper implements IMogoMapView, IMogoMapUIController, Loca } @Override - public void startJumpAnimation(IMogoMarker marker, float high, Interpolator interpolator, - long duration) { - if (marker == null || high <= 0.0f || interpolator == null || duration < 0) { + public void startJumpAnimation( IMogoMarker marker, float high, Interpolator interpolator, + long duration ) { + if ( marker == null || high <= 0.0f || interpolator == null || duration < 0 ) { return; } try { @@ -534,55 +536,55 @@ public class AMapViewWrapper implements IMogoMapView, IMogoMapUIController, Loca // ( ( AMapMarkerWrapper ) marker ).getMarker().setAnimation( animation ); // ( ( AMapMarkerWrapper ) marker ).getMarker().startAnimation(); // } - } catch (Exception e) { - Logger.e(TAG, e, "error."); + } catch ( Exception e ) { + Logger.e( TAG, e, "error." ); } } @Override - public void setRenderFps(int fps) { - if (checkAMapView()) { - if (mMapView.getMapAutoViewHelper() != null) { - mMapView.getMapAutoViewHelper().setRenderFps(fps); - Logger.d(TAG, "设置刷新帧率 fps = %s", fps); + public void setRenderFps( int fps ) { + if ( checkAMapView() ) { + if ( mMapView.getMapAutoViewHelper() != null ) { + mMapView.getMapAutoViewHelper().setRenderFps( fps ); + Logger.d( TAG, "设置刷新帧率 fps = %s", fps ); } } } @Override - public void showBounds(String tag, MogoLatLng carPosition, List lonLats, Rect bound, boolean lockCarPosition) { - if (!checkAMapView()) { + public void showBounds( String tag, MogoLatLng carPosition, List< MogoLatLng > lonLats, Rect bound, boolean lockCarPosition ) { + if ( !checkAMapView() ) { return; } - Logger.i(TAG, "showBounds:%s -%s-%s- %b ", tag, carPosition.toString(), bound.toShortString(), lockCarPosition); + Logger.i( TAG, "showBounds:%s -%s-%s- %b ", tag, carPosition.toString(), bound.toShortString(), lockCarPosition ); try { - if (DebugConfig.isDebug()) { - Logger.d(TAG, Log.getStackTraceString(new Throwable())); + if ( DebugConfig.isDebug() ) { + Logger.d( TAG, Log.getStackTraceString( new Throwable() ) ); } - LatLngBounds latLngBounds = MogoMapUtils.getLatLngBounds(carPosition, lonLats, lockCarPosition); - if (!lockCarPosition) { + LatLngBounds latLngBounds = MogoMapUtils.getLatLngBounds( carPosition, lonLats, lockCarPosition ); + if ( !lockCarPosition ) { loseLockMode(); } - mMapView.getMapAutoViewHelper().setCenter(ObjectUtils.fromMogo(carPosition)); - mMapView.getMapAutoViewHelper().moveCamera(CameraUpdateFactory.INSTANCE.newLatLngBounds(latLngBounds, bound.left, bound.right, bound.top, bound.bottom)); - } catch (Exception e) { - Logger.e(TAG, e, "%s error.", tag); + mMapView.getMapAutoViewHelper().setCenter( ObjectUtils.fromMogo( carPosition ) ); + mMapView.getMapAutoViewHelper().moveCamera( CameraUpdateFactory.INSTANCE.newLatLngBounds( latLngBounds, bound.left, bound.right, bound.top, bound.bottom ) ); + } catch ( Exception e ) { + Logger.e( TAG, e, "%s error.", tag ); } } @Override public void forceRender() { - if (checkAMapView()) { + if ( checkAMapView() ) { mMapView.getMapAutoViewHelper().runOnDrawFrame(); } } @Override - public float calculateLineDistance(MogoLatLng p1, MogoLatLng p2) throws Exception { - if (p1 == null || p2 == null) { - throw new Exception("计算距离的点不能为 null"); + public float calculateLineDistance( MogoLatLng p1, MogoLatLng p2 ) throws Exception { + if ( p1 == null || p2 == null ) { + throw new Exception( "计算距离的点不能为 null" ); } - return MogoMapUtils.calculateLineDistance(ObjectUtils.fromMogo(p1), ObjectUtils.fromMogo(p2)); + return MogoMapUtils.calculateLineDistance( ObjectUtils.fromMogo( p1 ), ObjectUtils.fromMogo( p2 ) ); } @@ -592,7 +594,7 @@ public class AMapViewWrapper implements IMogoMapView, IMogoMapUIController, Loca } @Override - public void changeMyLocation(Location location) { + public void changeMyLocation( Location location ) { } @Override @@ -601,125 +603,125 @@ public class AMapViewWrapper implements IMogoMapView, IMogoMapUIController, Loca } @Override - public void setCarCursorOption(CarCursorOption option) { - if (mCarCursorOption != null && mCarCursorOption != DEFAULT_OPTION) { + public void setCarCursorOption( CarCursorOption option ) { + if ( mCarCursorOption != null && mCarCursorOption != DEFAULT_OPTION ) { mCarCursorOption.destroy(); } - if (option != null) { + if ( option != null ) { try { mCarCursorOption = option.clone(); - } catch (Exception e) { + } catch ( Exception e ) { mCarCursorOption = DEFAULT_OPTION; } } else { mCarCursorOption = DEFAULT_OPTION; } - if (!checkAMapView()) { + if ( !checkAMapView() ) { return; } - if (mMapView.getMapAutoViewHelper() == null) { + if ( mMapView.getMapAutoViewHelper() == null ) { return; } MyLocationStyle style = mMapView.getMapAutoViewHelper().getMyLocationStyle(); - if (mCarCursorOption.getCarCursorBmp() != null && !mCarCursorOption.getCarCursorBmp().isRecycled()) { - style.myLocationIcon(mCarCursorOption.getCarCursorBmp()); + if ( mCarCursorOption.getCarCursorBmp() != null && !mCarCursorOption.getCarCursorBmp().isRecycled() ) { + style.myLocationIcon( mCarCursorOption.getCarCursorBmp() ); } else { - if (mCarCursorOption.getCarCursorRes() != 0) { - style.myLocationIcon(mCarCursorOption.getCarCursorRes()); + if ( mCarCursorOption.getCarCursorRes() != 0 ) { + style.myLocationIcon( mCarCursorOption.getCarCursorRes() ); } else { - style.myLocationIcon(mCarCursorOption.getCarCursorRes()); + style.myLocationIcon( mCarCursorOption.getCarCursorRes() ); } } - mMapView.getMapAutoViewHelper().setMyLocationStyle(style); + mMapView.getMapAutoViewHelper().setMyLocationStyle( style ); } @Override public MapCameraPosition getMapCameraPosition() { - if (checkAMapView()) { + if ( checkAMapView() ) { CameraPosition cameraPosition = mMapView.getMapAutoViewHelper().getCameraPosition(); - return ObjectUtils.fromAMap(cameraPosition); + return ObjectUtils.fromAMap( cameraPosition ); } return null; } @Override - public void changeBearing(float bearing) { - if (checkAMapView()) { - mMapView.getMapAutoViewHelper().setMapViewRotation(bearing); + public void changeBearing( float bearing ) { + if ( checkAMapView() ) { + mMapView.getMapAutoViewHelper().setMapViewRotation( bearing ); } } @Override - public void onLocationChanged(@NotNull com.zhidaoauto.map.sdk.open.location.MogoLocation location) { - Location sysLocation = new Location(location.getProvider()); - sysLocation.setAltitude(location.getAltitude()); - sysLocation.setLatitude(location.getLat()); - sysLocation.setLongitude(location.getLon()); - sysLocation.setSpeed(location.getSpeed()); - NaviClient.getInstance(getContext()).syncCarLocation(sysLocation); + public void onLocationChanged( @NotNull com.zhidaoauto.map.sdk.open.location.MogoLocation location ) { + Location sysLocation = new Location( location.getProvider() ); + sysLocation.setAltitude( location.getAltitude() ); + sysLocation.setLatitude( location.getLat() ); + sysLocation.setLongitude( location.getLon() ); + sysLocation.setSpeed( location.getSpeed() ); + NaviClient.getInstance( getContext() ).syncCarLocation( sysLocation ); } @Override - public void onMapClick(@Nullable LonLatPoint lonLatPoint) { - if (InterceptorHandler.getInstance().ignoreMapClicked(getContext())) { + public void onMapClick( @Nullable LonLatPoint lonLatPoint ) { + if ( InterceptorHandler.getInstance().ignoreMapClicked( getContext() ) ) { return; } - MogoMapListenerHandler.getInstance().onMapClick(ObjectUtils.fromAMap(lonLatPoint)); + MogoMapListenerHandler.getInstance().onMapClick( ObjectUtils.fromAMap( lonLatPoint ) ); } @Override public void onMapLoaded() { - Logger.i(TAG, "autoop--onMapLoaded: " ); + Logger.i( TAG, "autoop--onMapLoaded: " ); MogoMapListenerHandler.getInstance().onMapLoaded(); CameraPosition cameraPosition = mMapView.getMapAutoViewHelper().getCameraPosition(); - if (cameraPosition != null) { - Trace.beginSection("timer.onCameraChangeFinish"); - MogoMapListenerHandler.getInstance().onMapChanged(ObjectUtils.fromAMap(cameraPosition.getTarget()), + if ( cameraPosition != null ) { + Trace.beginSection( "timer.onCameraChangeFinish" ); + MogoMapListenerHandler.getInstance().onMapChanged( ObjectUtils.fromAMap( cameraPosition.getTarget() ), cameraPosition.getZoom(), cameraPosition.getTilt(), - cameraPosition.getBearing()); + cameraPosition.getBearing() ); Trace.endSection(); } } @Override - public boolean onTouch(@Nullable MotionEvent motionEvent) { - MogoMapListenerHandler.getInstance().onTouch(motionEvent); + public boolean onTouch( @Nullable MotionEvent motionEvent ) { + MogoMapListenerHandler.getInstance().onTouch( motionEvent ); return false; } @Override - public void onMarkClick(@NotNull Marker markerInfo) { - mMarkerClickHandler.handleMarkerClicked(markerInfo); + public void onMarkClick( @NotNull Marker markerInfo ) { + mMarkerClickHandler.handleMarkerClicked( markerInfo ); } @Override - public void onRoadLoaded(@Nullable String s) { + public void onRoadLoaded( @Nullable String s ) { } @Override - public void onMapStatusChanged(int type, int value) { - Logger.i(TAG, "mapop--onMapStatusChanged-: " + type + "," + value); + public void onMapStatusChanged( int type, int value ) { + Logger.i( TAG, "mapop--onMapStatusChanged-: " + type + "," + value ); } @Override - public void onCameraChange(int type, int value) { - Logger.i(TAG, "mapop--onCameraChange-: " + type + "," + value); + public void onCameraChange( int type, int value ) { + Logger.i( TAG, "mapop--onCameraChange-: " + type + "," + value ); } @Override - public void onCameraChangeFinish(@Nullable CameraPosition cameraPosition) { - Logger.i(TAG, "mapop--onCameraChangeFinish-: " + cameraPosition + "cost:" + (System.currentTimeMillis() - startTime)); - if (cameraPosition != null) { - Trace.beginSection("timer.onCameraChangeFinish"); - MogoMapListenerHandler.getInstance().onMapChanged(ObjectUtils.fromAMap(cameraPosition.getTarget()), + public void onCameraChangeFinish( @Nullable CameraPosition cameraPosition ) { + Logger.i( TAG, "mapop--onCameraChangeFinish-: " + cameraPosition + "cost:" + ( System.currentTimeMillis() - startTime ) ); + if ( cameraPosition != null ) { + Trace.beginSection( "timer.onCameraChangeFinish" ); + MogoMapListenerHandler.getInstance().onMapChanged( ObjectUtils.fromAMap( cameraPosition.getTarget() ), cameraPosition.getZoom(), cameraPosition.getTilt(), - cameraPosition.getBearing()); + cameraPosition.getBearing() ); Trace.endSection(); } } diff --git a/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/CustomMapView.java b/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/CustomMapView.java index 2a3d8d24ff..9e8c503db9 100644 --- a/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/CustomMapView.java +++ b/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/CustomMapView.java @@ -23,12 +23,12 @@ public class CustomMapView implements IMogoMapViewCreator { @Override public IMogoMapView create( Context context ) { - MapAutoApi.INSTANCE.init( context, MapParams.Companion.init().setDebugMode( false ) + MapAutoApi.INSTANCE.init( context, MapParams.Companion.init().setDebugMode( true ) .setCoordinateType( MapParams.COORDINATETYPE_GCJ02 ) .setPerspectiveMode( MapParams.MAP_PERSPECTIVE_2D ) .setZoom( 16 ) .setPointToCenter( 0.5f, 0.5f ) - .setStyleMode( MapParams.MAP_STYLE_NIGHT ) ); + .setStyleMode( MapParams.MAP_STYLE_VR ) ); MapAutoView mapAutoView = new MapAutoView( context ); mapView = new AMapViewWrapper( mapAutoView ); return mapView; diff --git a/libraries/mogo-map-api/src/main/java/com/mogo/map/uicontroller/EnumMapUI.java b/libraries/mogo-map-api/src/main/java/com/mogo/map/uicontroller/EnumMapUI.java index bae12fe5a7..14bbb7bc52 100644 --- a/libraries/mogo-map-api/src/main/java/com/mogo/map/uicontroller/EnumMapUI.java +++ b/libraries/mogo-map-api/src/main/java/com/mogo/map/uicontroller/EnumMapUI.java @@ -35,7 +35,12 @@ public enum EnumMapUI { /** * 夜晚模式 */ - Type_AUTO_LIGHT_Night( 5, 3 ); + Type_AUTO_LIGHT_Night( 5, 3 ), + + /** + * 自研地图的VR模式 + */ + Type_VR( 0, 0 ); private int next; private int code; diff --git a/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/CloudRoadData.java b/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/CloudRoadData.java index 9c9ecbad4e..0481f19c4a 100644 --- a/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/CloudRoadData.java +++ b/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/CloudRoadData.java @@ -21,9 +21,9 @@ public class CloudRoadData implements Parcelable { private long systemTime; /**红绿灯状态 1红 2绿 3黄*/ - private Integer lightStatus;// + private int lightStatus;// /**红绿灯剩余时间 读秒*/ - private Integer lightLeftTime; + private int lightLeftTime; /**视频流直播地址*/ private String rtmpUrl;// @@ -31,22 +31,15 @@ public class CloudRoadData implements Parcelable { public List coordinates; + protected CloudRoadData(Parcel in) { type = in.readInt(); lat = in.readDouble(); lon = in.readDouble(); speed = in.readDouble(); systemTime = in.readLong(); - if (in.readByte() == 0) { - lightStatus = null; - } else { - lightStatus = in.readInt(); - } - if (in.readByte() == 0) { - lightLeftTime = null; - } else { - lightLeftTime = in.readInt(); - } + lightStatus = in.readInt(); + lightLeftTime = in.readInt(); rtmpUrl = in.readString(); distance = in.readDouble(); coordinates = in.createTypedArrayList(CloudLocationInfo.CREATOR); @@ -59,18 +52,8 @@ public class CloudRoadData implements Parcelable { dest.writeDouble(lon); dest.writeDouble(speed); dest.writeLong(systemTime); - if (lightStatus == null) { - dest.writeByte((byte) 0); - } else { - dest.writeByte((byte) 1); - dest.writeInt(lightStatus); - } - if (lightLeftTime == null) { - dest.writeByte((byte) 0); - } else { - dest.writeByte((byte) 1); - dest.writeInt(lightLeftTime); - } + dest.writeInt(lightStatus); + dest.writeInt(lightLeftTime); dest.writeString(rtmpUrl); dest.writeDouble(distance); dest.writeTypedList(coordinates); @@ -92,4 +75,84 @@ public class CloudRoadData implements Parcelable { return new CloudRoadData[size]; } }; + + public int getType() { + return type; + } + + public void setType(int type) { + this.type = type; + } + + public double getLat() { + return lat; + } + + public void setLat(double lat) { + this.lat = lat; + } + + public double getLon() { + return lon; + } + + public void setLon(double lon) { + this.lon = lon; + } + + public double getSpeed() { + return speed; + } + + public void setSpeed(double speed) { + this.speed = speed; + } + + public long getSystemTime() { + return systemTime; + } + + public void setSystemTime(long systemTime) { + this.systemTime = systemTime; + } + + public int getLightStatus() { + return lightStatus; + } + + public void setLightStatus(int lightStatus) { + this.lightStatus = lightStatus; + } + + public int getLightLeftTime() { + return lightLeftTime; + } + + public void setLightLeftTime(int lightLeftTime) { + this.lightLeftTime = lightLeftTime; + } + + public String getRtmpUrl() { + return rtmpUrl; + } + + public void setRtmpUrl(String rtmpUrl) { + this.rtmpUrl = rtmpUrl; + } + + public double getDistance() { + return distance; + } + + public void setDistance(double distance) { + this.distance = distance; + } + + public List getCoordinates() { + return coordinates; + } + + public void setCoordinates(List coordinates) { + this.coordinates = coordinates; + } } diff --git a/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/MogoSnapshotSetData.java b/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/MogoSnapshotSetData.java index 11acfdbe96..2fef42f58c 100644 --- a/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/MogoSnapshotSetData.java +++ b/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/MogoSnapshotSetData.java @@ -16,10 +16,10 @@ class MogoSnapshotSetData implements Parcelable { private String msgId; - private Long time; + private long time; //过期时间 - private Long expire; + private long expire; //总数据集合 private List allList; @@ -30,16 +30,8 @@ class MogoSnapshotSetData implements Parcelable { protected MogoSnapshotSetData(Parcel in) { msgId = in.readString(); - if (in.readByte() == 0) { - time = null; - } else { - time = in.readLong(); - } - if (in.readByte() == 0) { - expire = null; - } else { - expire = in.readLong(); - } + time = in.readLong(); + expire = in.readLong(); allList = in.createTypedArrayList(CloudRoadData.CREATOR); trafficLight = in.readParcelable(CloudRoadData.class.getClassLoader()); } @@ -47,18 +39,8 @@ class MogoSnapshotSetData implements Parcelable { @Override public void writeToParcel(Parcel dest, int flags) { dest.writeString(msgId); - if (time == null) { - dest.writeByte((byte) 0); - } else { - dest.writeByte((byte) 1); - dest.writeLong(time); - } - if (expire == null) { - dest.writeByte((byte) 0); - } else { - dest.writeByte((byte) 1); - dest.writeLong(expire); - } + dest.writeLong(time); + dest.writeLong(expire); dest.writeTypedList(allList); dest.writeParcelable(trafficLight, flags); } @@ -90,4 +72,44 @@ class MogoSnapshotSetData implements Parcelable { ", trafficLight=" + trafficLight + '}'; } + + public String getMsgId() { + return msgId; + } + + public void setMsgId(String msgId) { + this.msgId = msgId; + } + + public long getTime() { + return time; + } + + public void setTime(long time) { + this.time = time; + } + + public long getExpire() { + return expire; + } + + public void setExpire(long expire) { + this.expire = expire; + } + + public List getAllList() { + return allList; + } + + public void setAllList(List allList) { + this.allList = allList; + } + + public CloudRoadData getTrafficLight() { + return trafficLight; + } + + public void setTrafficLight(CloudRoadData trafficLight) { + this.trafficLight = trafficLight; + } } diff --git a/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/utils/AdasNoticeHelper.java b/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/utils/AdasNoticeHelper.java index c3b9b78e28..6cf28e9879 100644 --- a/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/utils/AdasNoticeHelper.java +++ b/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/utils/AdasNoticeHelper.java @@ -12,6 +12,7 @@ import android.widget.TextView; import com.mogo.map.location.IMogoLocationListener; import com.mogo.map.location.MogoLocation; import com.mogo.module.common.MogoApisHandler; +import com.mogo.module.common.entity.CloudRoadData; import com.mogo.module.common.entity.MogoSnapshotSetData; import com.mogo.module.extensions.R; import com.mogo.service.adas.IMogoAdasWarnMessageCallback; @@ -94,10 +95,7 @@ public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback, IMogoLoca if (!isVrMode) { return; } - // 处理adas识别的时间,主要是行人碰撞预警 - if (msg.type == MogoADASWarnType.ADAS_WARNING_PERSON) { - MogoApisHandler.getInstance().getApis().getEntranceButtonController().showLeftNoticeByType(IMogoEntranceButtonController.NOTICE_TYPE_PEOPLE_WARN, R.drawable.module_ext_people_warn, "前方注意行人"); - } + if (msg.type == MogoADASWarnType.ADAS_WARNING_LIMIT_SPEED) { // 收到限速信息,更新界面 if (tvLimitSpeed != null) { @@ -164,13 +162,6 @@ public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback, IMogoLoca if (!isVrMode) { return; } - // todo 处理发给adas的事件, 主要处理逆向超车和obu行人碰撞 - String id = intent.getStringExtra("v2x_warning_type"); - if (id != null) { - if ("100003".equals(id)) {// 行人碰撞 - MogoApisHandler.getInstance().getApis().getEntranceButtonController().showLeftNoticeByType(IMogoEntranceButtonController.NOTICE_TYPE_PEOPLE_WARN, R.drawable.module_ext_people_warn, "前方注意行人"); - } - } int type = intent.getIntExtra("type", -1); if (type == 2) { @@ -204,10 +195,11 @@ public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback, IMogoLoca } } - private void handleCloudTrafficLight(){ + private void handleCloudTrafficLight(CloudRoadData roadData){ if (tvTrafficLight != null && !handler.hasMessages(MSG_HIDE_TRAFFIC_LIGHT_BY_OBU)) { handler.removeMessages(MSG_HIDE_TRAFFIC_LIGHT_BY_CLOUD); // todo drawTrafficLight + handler.sendEmptyMessageDelayed(MSG_HIDE_TRAFFIC_LIGHT_BY_CLOUD, HIDE_TRAFFIC_LIGHT_DELAY); } @@ -243,5 +235,10 @@ public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback, IMogoLoca @Override public void onMsgReceived(MogoSnapshotSetData obj) { Logger.d(TAG, "收到大而全数据: " + obj); + CloudRoadData roadData = obj.getTrafficLight(); + if (roadData != null) { + Logger.d(TAG, "收到红绿灯数据"); + handleCloudTrafficLight(roadData); + } } } diff --git a/modules/mogo-module-map/src/main/java/com/mogo/module/map/MapFragment.java b/modules/mogo-module-map/src/main/java/com/mogo/module/map/MapFragment.java index 90d660b0a3..32b651a8a5 100644 --- a/modules/mogo-module-map/src/main/java/com/mogo/module/map/MapFragment.java +++ b/modules/mogo-module-map/src/main/java/com/mogo/module/map/MapFragment.java @@ -72,13 +72,13 @@ public class MapFragment extends MvpFragment< MapView, MapPresenter > implements } mMogoMapView.displayVRMap( mIsFirstLoadCustomMap, true ); if ( mIsFirstLoadCustomMap ) { - initMapView(); - mMogoMap = mMogoMapView.getMap(); - if ( mMogoMap.getUIController() != null ) { - mMogoMap.getUIController().showMyLocation( true ); - mMogoMap.getUIController().recoverLockMode();// 启动锁车 - } - mIsFirstLoadCustomMap = false; +// initMapView(); +// mMogoMap = mMogoMapView.getMap(); +// if ( mMogoMap.getUIController() != null ) { +// mMogoMap.getUIController().showMyLocation( true ); +// mMogoMap.getUIController().recoverLockMode();// 启动锁车 +// } +// mIsFirstLoadCustomMap = false; } afterMapModeChanged(); MogoApisHandler.getInstance().getApis().getAdasControllerApi().closeADAS(); diff --git a/modules/mogo-module-service/src/main/java/com/mogo/module/service/marker/MapMarkerManager.java b/modules/mogo-module-service/src/main/java/com/mogo/module/service/marker/MapMarkerManager.java index dc4f7a0a21..d52be7d4d9 100644 --- a/modules/mogo-module-service/src/main/java/com/mogo/module/service/marker/MapMarkerManager.java +++ b/modules/mogo-module-service/src/main/java/com/mogo/module/service/marker/MapMarkerManager.java @@ -159,6 +159,13 @@ public class MapMarkerManager implements IMogoMarkerClickListener, } } ); + MarkerServiceHandler.getApis().getAdasControllerApi().addAdasRecognizedDataCallback( resultList -> { + if ( resultList == null || resultList.isEmpty() ) { + return; + } + // 绘制近景识别到的车辆,每秒绘制一次 + } ); + } /** diff --git a/modules/mogo-modules-mvision/src/main/java/com/mogo/module/machine/vision/MachineVisionMapViewHandler.java b/modules/mogo-modules-mvision/src/main/java/com/mogo/module/machine/vision/MachineVisionMapViewHandler.java index a551e7f172..79b92faa31 100644 --- a/modules/mogo-modules-mvision/src/main/java/com/mogo/module/machine/vision/MachineVisionMapViewHandler.java +++ b/modules/mogo-modules-mvision/src/main/java/com/mogo/module/machine/vision/MachineVisionMapViewHandler.java @@ -44,6 +44,11 @@ class MachineVisionMapViewHandler { } public void renderSnapshotSetData( MogoSnapshotSetData data ) { - + if ( data == null ) { + return; + } + if ( mMachineVisionMapView == null ) { + return; + } } } diff --git a/services/mogo-service-api/src/main/java/com/mogo/service/adas/IMogoADASController.java b/services/mogo-service-api/src/main/java/com/mogo/service/adas/IMogoADASController.java index 16dbcb59ca..4d4bfc61dd 100644 --- a/services/mogo-service-api/src/main/java/com/mogo/service/adas/IMogoADASController.java +++ b/services/mogo-service-api/src/main/java/com/mogo/service/adas/IMogoADASController.java @@ -114,4 +114,18 @@ public interface IMogoADASController extends IProvider { * @return */ List< ADASRecognizedResult > getLastADASRecognizedResult(); + + /** + * 添加adas识别物体回调 + * + * @param callback + */ + void addAdasRecognizedDataCallback( IMogoAdasRecognizedDataCallback callback ); + + /** + * 移除adas识别物体回调 + * + * @param callback + */ + void removeAdasRecognizedDataCallback( IMogoAdasRecognizedDataCallback callback ); } diff --git a/services/mogo-service-api/src/main/java/com/mogo/service/adas/IMogoAdasRecognizedDataCallback.java b/services/mogo-service-api/src/main/java/com/mogo/service/adas/IMogoAdasRecognizedDataCallback.java index 49c32d34f9..301b94d0fc 100644 --- a/services/mogo-service-api/src/main/java/com/mogo/service/adas/IMogoAdasRecognizedDataCallback.java +++ b/services/mogo-service-api/src/main/java/com/mogo/service/adas/IMogoAdasRecognizedDataCallback.java @@ -1,5 +1,10 @@ package com.mogo.service.adas; +import com.mogo.service.adas.entity.ADASRecognizedListResult; +import com.mogo.service.adas.entity.ADASRecognizedResult; + +import java.util.List; + /** * adas 物体识别数据回调接口 * @@ -8,7 +13,8 @@ package com.mogo.service.adas; public interface IMogoAdasRecognizedDataCallback { /** * adas 数据回调 - * @param msg 具体数据 + * + * @param resultList 具体识别的物体数据 */ - void onAdasDataCallback( String msg ); + void onAdasDataCallback( List< ADASRecognizedListResult > resultList ); } \ No newline at end of file diff --git a/services/mogo-service-api/src/main/java/com/mogo/service/adas/entity/ADASRecognizedListResult.java b/services/mogo-service-api/src/main/java/com/mogo/service/adas/entity/ADASRecognizedListResult.java new file mode 100644 index 0000000000..df8da8f28e --- /dev/null +++ b/services/mogo-service-api/src/main/java/com/mogo/service/adas/entity/ADASRecognizedListResult.java @@ -0,0 +1,29 @@ +package com.mogo.service.adas.entity; + +import java.util.List; + +public +/** + * @author congtaowang + * @since 2020/10/25 + * + * adas 识别物体参数 + */ +class ADASRecognizedListResult { + + public int type; + public String uuid; + public double heading; + public double speed; + public List< LatLon > latLonList; + + public static class LatLon { + public LatLon( double lat, double lon ) { + this.lat = lat; + this.lon = lon; + } + + public double lat; + public double lon; + } +} diff --git a/services/mogo-service/src/main/java/com/mogo/service/impl/adas/AdasObjectUtils.java b/services/mogo-service/src/main/java/com/mogo/service/impl/adas/AdasObjectUtils.java index 066d36a29d..834da1a61b 100644 --- a/services/mogo-service/src/main/java/com/mogo/service/impl/adas/AdasObjectUtils.java +++ b/services/mogo-service/src/main/java/com/mogo/service/impl/adas/AdasObjectUtils.java @@ -1,13 +1,17 @@ package com.mogo.service.impl.adas; import com.mogo.commons.utils.MortonCode; +import com.mogo.service.adas.entity.ADASRecognizedListResult; import com.mogo.service.adas.entity.ADASRecognizedResult; import com.mogo.service.adas.entity.ADASWarnMessage; import com.zhidao.support.adas.high.bean.RectInfo; import com.zhidao.support.adas.high.bean.WarnMessageInfo; import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; import java.util.List; +import java.util.Map; public /** @@ -74,4 +78,36 @@ class AdasObjectUtils { result.mortonCode = MortonCode.wrapEncodeMorton( result.lon, result.lat ); return result; } + + public static List< ADASRecognizedListResult > regroupData( List< RectInfo > datums ) { + if ( datums == null || datums.isEmpty() ) { + return null; + } + Map< String, ADASRecognizedListResult > result = new HashMap<>(); + for ( RectInfo rectInfo : datums ) { + if ( rectInfo == null || rectInfo.getModels() == null || rectInfo.getModels().isEmpty() ) { + continue; + } + List< RectInfo.RectBean > models = rectInfo.getModels(); + for ( RectInfo.RectBean model : models ) { + ADASRecognizedListResult recognizedListResult = null; + if ( !result.containsKey( model.getUuid() ) ) { + recognizedListResult = new ADASRecognizedListResult(); + recognizedListResult.latLonList = new ArrayList<>(); + recognizedListResult.heading = model.getHeading(); + recognizedListResult.speed = model.getSpeed(); + recognizedListResult.type = Integer.valueOf( model.getType() ); + recognizedListResult.uuid = model.getUuid(); + result.put( model.getUuid(), recognizedListResult ); + } else { + recognizedListResult = result.get( model.getUuid() ); + } + recognizedListResult.latLonList.add( new ADASRecognizedListResult.LatLon( model.getLat(), model.getLon() ) ); + } + } + if ( result.isEmpty() ) { + return null; + } + return new ArrayList<>( result.values() ); + } } diff --git a/services/mogo-service/src/main/java/com/mogo/service/impl/adas/MogoADASController.java b/services/mogo-service/src/main/java/com/mogo/service/impl/adas/MogoADASController.java index abd9f7838a..50630feca6 100644 --- a/services/mogo-service/src/main/java/com/mogo/service/impl/adas/MogoADASController.java +++ b/services/mogo-service/src/main/java/com/mogo/service/impl/adas/MogoADASController.java @@ -14,8 +14,10 @@ import com.mogo.module.common.utils.CarSeries; import com.mogo.service.MogoServicePaths; import com.mogo.service.adas.IMogoADASController; import com.mogo.service.adas.IMogoAdasDataCallback; +import com.mogo.service.adas.IMogoAdasRecognizedDataCallback; import com.mogo.service.adas.IMogoAdasWarnMessageCallback; import com.mogo.service.adas.RemoteControlAutoPilotParameters; +import com.mogo.service.adas.entity.ADASRecognizedListResult; import com.mogo.service.adas.entity.ADASRecognizedResult; import com.mogo.service.adas.entity.ADASWarnMessage; import com.mogo.service.impl.singleton.SingletonsHolder; @@ -81,6 +83,10 @@ public class MogoADASController implements IMogoADASController { */ private List< IMogoAdasWarnMessageCallback > mMogoAdasWarnMessageCallbackList = new CopyOnWriteArrayList<>(); + /** + * adas 识别物体回调 + */ + private List< IMogoAdasRecognizedDataCallback > mMogoAdasRecognizedDataCallbacks = new CopyOnWriteArrayList<>(); private RectInfo mLastFrameData; @@ -91,6 +97,7 @@ public class MogoADASController implements IMogoADASController { // 物体识别返回 Logger.d( TAG, "onRectData = %s", rectInfo.toString() ); mLastFrameData = rectInfo; + handleAdasRecognizedData( rectInfo ); } @Override @@ -119,6 +126,53 @@ public class MogoADASController implements IMogoADASController { } }; + private long mLastRecordSeconds = 0L; + + + /** + * 缓存容器 + */ + List< RectInfo > mCacheRecognizedDataSet = new ArrayList<>(); + + /** + * 处理数据,将识别到的物体分组,然后每1s进行一次回调 + * 时间:系统时间 + * + * @param rectInfo + */ + private void handleAdasRecognizedData( RectInfo rectInfo ) { + if ( rectInfo == null + || rectInfo.getModels() == null + || rectInfo.getModels().isEmpty() ) { + return; + } + long curTime = System.currentTimeMillis() / 1000; + if ( mLastRecordSeconds == 0L ) { + mLastRecordSeconds = curTime; + } + if ( mLastRecordSeconds != curTime ) { + invokeCallbackPerSecond( mCacheRecognizedDataSet ); + mCacheRecognizedDataSet = new ArrayList<>(); + } + mCacheRecognizedDataSet.add( rectInfo ); + } + + private void invokeCallbackPerSecond( List< RectInfo > data ) { + List< RectInfo > newRef = data; + List< ADASRecognizedListResult > recognizedListResults = AdasObjectUtils.regroupData( newRef ); + if ( recognizedListResults == null || recognizedListResults.isEmpty() ) { + return; + } + if ( !mMogoAdasRecognizedDataCallbacks.isEmpty() ) { + for ( IMogoAdasRecognizedDataCallback callback : mMogoAdasRecognizedDataCallbacks ) { + if ( callback == null ) { + continue; + } + callback.onAdasDataCallback( recognizedListResults ); + } + } + } + private MyMessageFactory mAdasMessageFactory; private IAutopolitDataCallBack mAutoPilotDataCallBack = new IAutopolitDataCallBack() { @Override @@ -376,4 +430,22 @@ public class MogoADASController implements IMogoADASController { List< ADASRecognizedResult > recognizedResultList = AdasObjectUtils.fromAdasObject( rectInfo ); return recognizedResultList; } + + @Override + public void addAdasRecognizedDataCallback( IMogoAdasRecognizedDataCallback callback ) { + if ( callback == null ) { + return; + } + if ( !mMogoAdasRecognizedDataCallbacks.contains( callback ) ) { + mMogoAdasRecognizedDataCallbacks.add( callback ); + } + } + + @Override + public void removeAdasRecognizedDataCallback( IMogoAdasRecognizedDataCallback callback ) { + if ( callback == null ) { + return; + } + mMogoAdasRecognizedDataCallbacks.remove( callback ); + } }