From 0442cc436a20cf2322b1c724557c80c532fae62b Mon Sep 17 00:00:00 2001 From: wangcongtao Date: Wed, 16 Dec 2020 14:44:01 +0800 Subject: [PATCH] =?UTF-8?q?marker=E5=9C=A8vr=E6=A8=A1=E5=BC=8F=E4=B8=8B?= =?UTF-8?q?=E7=9A=84=E7=AB=8B=E4=BD=93=E6=95=88=E6=9E=9C=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/custom/AMapMarkerClickHandler.java | 24 ++++++++++ .../mogo/map/impl/custom/AMapViewWrapper.java | 2 +- .../custom/marker/AMapInfoWindowAdapter.java | 11 ++++- .../common/drawer/marker/EmptyMarkerView.java | 46 +++++++++++++++++++ .../drawer/marker/MapMarkerAdapter.java | 28 +++++++++-- .../drawer/marker/MapMarkerInfoView.java | 7 ++- .../RoadConditionInfoWindow3DAdapter.java | 2 +- .../service/marker/MapMarkerManager.java | 24 +++++++--- 8 files changed, 129 insertions(+), 15 deletions(-) create mode 100644 modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/marker/EmptyMarkerView.java diff --git a/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/AMapMarkerClickHandler.java b/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/AMapMarkerClickHandler.java index 0b89685535..f2775c4894 100644 --- a/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/AMapMarkerClickHandler.java +++ b/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/AMapMarkerClickHandler.java @@ -19,6 +19,30 @@ import java.util.Map; */ public class AMapMarkerClickHandler { + private static volatile AMapMarkerClickHandler sInstance; + + private AMapMarkerClickHandler(){} + + public static AMapMarkerClickHandler getInstance(){ + if( sInstance == null ){ + synchronized( AMapMarkerClickHandler.class ) { + if( sInstance == null ){ + sInstance = new AMapMarkerClickHandler(); + } + } + } + return sInstance; + } + + public synchronized void release(){ + sInstance = null; + } + + private Object readResolve() { + // 阻止反序列化,必须实现 Serializable 接口 + return sInstance; + } + public boolean handleMarkerClicked( Marker marker ) { if ( marker == null ) { return false; 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 f1a887e85c..5a903d4115 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 @@ -162,7 +162,7 @@ public class AMapViewWrapper implements IMogoMapView, private void initListeners() { mMapView.setOnMarkClickListener( this ); - mMarkerClickHandler = new AMapMarkerClickHandler(); + mMarkerClickHandler = AMapMarkerClickHandler.getInstance(); mMapView.setOnMapLoadedListener( this ); mMapView.setOnMapTouchListener( this ); mMapView.setOnMapClickListener( this ); diff --git a/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/marker/AMapInfoWindowAdapter.java b/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/marker/AMapInfoWindowAdapter.java index 1e06b9ddbb..e7a55c39bd 100644 --- a/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/marker/AMapInfoWindowAdapter.java +++ b/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/marker/AMapInfoWindowAdapter.java @@ -2,6 +2,7 @@ package com.mogo.map.impl.custom.marker; import android.view.View; +import com.mogo.map.impl.custom.AMapMarkerClickHandler; import com.mogo.map.marker.IMogoInfoWindowAdapter; import com.mogo.map.marker.IMogoMarker; import com.zhidaoauto.map.sdk.open.abs.marker.InfoWindowAdapter; @@ -9,6 +10,8 @@ import com.zhidaoauto.map.sdk.open.marker.Marker; import org.jetbrains.annotations.Nullable; +import java.io.FileInputStream; + /** * @author congtaowang * @since 2019-12-24 @@ -22,7 +25,13 @@ public final class AMapInfoWindowAdapter implements InfoWindowAdapter { IMogoMarker mogoMarker = ( ( IMogoMarker ) marker.getMObject() ); IMogoInfoWindowAdapter delegate = mogoMarker.getInfoWindowAdapter(); if ( delegate != null ) { - return delegate.getInfoWindow( mogoMarker ); + final View infoView = delegate.getInfoWindow( mogoMarker ); + if ( infoView != null ) { + infoView.setOnClickListener( view -> { + AMapMarkerClickHandler.getInstance().handleMarkerClicked( marker ); + } ); + } + return infoView; } } return null; diff --git a/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/marker/EmptyMarkerView.java b/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/marker/EmptyMarkerView.java new file mode 100644 index 0000000000..be4771ae5a --- /dev/null +++ b/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/marker/EmptyMarkerView.java @@ -0,0 +1,46 @@ +package com.mogo.module.common.drawer.marker; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.View; + +import androidx.annotation.Nullable; + +import com.mogo.map.marker.IMogoMarker; + +public +/** + * @author congtaowang + * @since 2020/12/16 + * + * 描述 + */ +class EmptyMarkerView extends View implements IMarkerView { + + public EmptyMarkerView( Context context ) { + this( context, null ); + } + + public EmptyMarkerView( Context context, @Nullable AttributeSet attrs ) { + this( context, attrs, 0 ); + } + + public EmptyMarkerView( Context context, @Nullable AttributeSet attrs, int defStyleAttr ) { + super( context, attrs, defStyleAttr ); + } + + @Override + public View getView() { + return this; + } + + @Override + public void setMarker( IMogoMarker marker ) { + + } + + @Override + protected void onMeasure( int widthMeasureSpec, int heightMeasureSpec ) { + setMeasuredDimension( 1, 1 ); + } +} diff --git a/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/marker/MapMarkerAdapter.java b/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/marker/MapMarkerAdapter.java index 94d682ca4a..8a130a1f59 100644 --- a/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/marker/MapMarkerAdapter.java +++ b/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/marker/MapMarkerAdapter.java @@ -5,6 +5,7 @@ import android.text.TextUtils; import com.mogo.map.marker.MogoMarkerOptions; import com.mogo.module.common.ModuleNames; +import com.mogo.module.common.MogoApisHandler; import com.mogo.module.common.entity.MarkerShowEntity; /** @@ -23,17 +24,36 @@ public class MapMarkerAdapter { * @param markerShowEntity 要填充的数据 * @return MarkerView */ - public static IMarkerView getMarkerView(Context context, MarkerShowEntity markerShowEntity, MogoMarkerOptions options) { + public static IMarkerView getMarkerView( Context context, MarkerShowEntity markerShowEntity, MogoMarkerOptions options ) { if ( TextUtils.equals( markerShowEntity.getMarkerType(), ModuleNames.CARD_TYPE_USER_DATA ) ) { return OnlineCarMarkerView.getInstance(); } else { - if (markerShowEntity.isChecked()) { - return new MapMarkerInfoView(context, markerShowEntity, options); + if ( MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode() ) { + return new EmptyMarkerView( context ); } else { - return new MapMarkerView(context, markerShowEntity, options); + if ( markerShowEntity.isChecked() ) { + return new MapMarkerInfoView( context, markerShowEntity, options ); + } else { + return new MapMarkerView( context, markerShowEntity, options ); + } } } } + + /** + * 获取 MarkerShowEntity 填充好的 MarkerView + * + * @param context 上下文 + * @param markerShowEntity 要填充的数据 + * @return MarkerView + */ + public static IMarkerView getMarkerInfoWindowView( Context context, MarkerShowEntity markerShowEntity, MogoMarkerOptions options ) { + if ( markerShowEntity.isChecked() ) { + return new MapMarkerInfoView( context, markerShowEntity, options ); + } else { + return new MapMarkerView( context, markerShowEntity, options ); + } + } } diff --git a/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/marker/MapMarkerInfoView.java b/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/marker/MapMarkerInfoView.java index 404ded1d88..9ded911563 100644 --- a/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/marker/MapMarkerInfoView.java +++ b/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/marker/MapMarkerInfoView.java @@ -13,6 +13,7 @@ import androidx.constraintlayout.widget.ConstraintLayout; import com.mogo.map.marker.MogoMarkerOptions; import com.mogo.module.common.ModuleNames; +import com.mogo.module.common.MogoApisHandler; import com.mogo.module.common.entity.MarkerExploreWay; import com.mogo.module.common.entity.MarkerShareMusic; import com.mogo.module.common.entity.MarkerShowEntity; @@ -71,7 +72,11 @@ public class MapMarkerInfoView extends MapMarkerBaseView { Object bindObj = markerShowEntity.getBindObj(); - ivCar.setImageResource( R.drawable.icon_map_marker_location_yellow ); + if ( MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode() ) { + ivCar.setImageResource( R.drawable.icon_map_marker_location_yellow_vr ); + } else { + ivCar.setImageResource( R.drawable.icon_map_marker_location_yellow ); + } clMarkerContent.setBackgroundResource( R.drawable.bg_map_marker_yellow_info ); ivReverseTriangle.setImageResource( R.drawable.bg_shape_reverse_yellow ); switch ( markerShowEntity.getMarkerType() ) { diff --git a/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/marker/RoadConditionInfoWindow3DAdapter.java b/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/marker/RoadConditionInfoWindow3DAdapter.java index 374d3597a0..063be888e7 100644 --- a/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/marker/RoadConditionInfoWindow3DAdapter.java +++ b/modules/mogo-module-common/src/main/java/com/mogo/module/common/drawer/marker/RoadConditionInfoWindow3DAdapter.java @@ -31,7 +31,7 @@ class RoadConditionInfoWindow3DAdapter implements IMogoInfoWindowAdapter { @Override public View getInfoWindow( IMogoMarker marker ) { - IMarkerView creator = MapMarkerAdapter.getMarkerView( mContext, mEntity, mOptions ); + IMarkerView creator = MapMarkerAdapter.getMarkerInfoWindowView( mContext, mEntity, mOptions ); return creator.getView(); } } 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 7561060acc..2abcaf7a2f 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 @@ -262,7 +262,7 @@ public class MapMarkerManager implements IMogoMarkerClickListener, MarkerShowEntity markerShowEntity = ( MarkerShowEntity ) object; markerShowEntity.setChecked( true ); IMarkerView markerView = MapMarkerAdapter.getMarkerView( mContext, markerShowEntity, mogoMarker.getMogoMarkerOptions() ); - markerView.setMarker(mogoMarker); + markerView.setMarker( mogoMarker ); if ( markerView instanceof OnlineCarMarkerView ) { try { mogoMarker.setIcon( markerView.getBitmap( ( ( MarkerOnlineCar ) markerShowEntity.getBindObj() ).getCarInfo().getVehicleType() ) ); @@ -270,7 +270,12 @@ public class MapMarkerManager implements IMogoMarkerClickListener, mogoMarker.setIcon( markerView.getBitmap( 0 ) ); } } else { - mogoMarker.setIcon( ViewUtils.fromView( markerView.getView() ) ); + if ( MarkerServiceHandler.getApis().getStatusManagerApi().isVrMode() ) { + mogoMarker.hideInfoWindow(); + mogoMarker.showInfoWindow(); + } else { + mogoMarker.setIcon( ViewUtils.fromView( markerView.getView() ) ); + } } mogoMarker.setToTop(); } @@ -309,7 +314,7 @@ public class MapMarkerManager implements IMogoMarkerClickListener, MarkerShowEntity markerShowEntity = ( MarkerShowEntity ) object; markerShowEntity.setChecked( false ); IMarkerView markerView = MapMarkerAdapter.getMarkerView( mContext, markerShowEntity, mogoMarker.getMogoMarkerOptions() ); - markerView.setMarker(mogoMarker); + markerView.setMarker( mogoMarker ); if ( markerView instanceof OnlineCarMarkerView ) { try { mogoMarker.setIcon( markerView.getBitmap( ( ( MarkerOnlineCar ) markerShowEntity.getBindObj() ).getCarInfo().getVehicleType() ) ); @@ -317,7 +322,12 @@ public class MapMarkerManager implements IMogoMarkerClickListener, mogoMarker.setIcon( markerView.getBitmap( 0 ) ); } } else { - mogoMarker.setIcon( ViewUtils.fromView( markerView.getView() ) ); + if ( MarkerServiceHandler.getApis().getStatusManagerApi().isVrMode() ) { + mogoMarker.hideInfoWindow(); + mogoMarker.showInfoWindow(); + } else { + mogoMarker.setIcon( ViewUtils.fromView( markerView.getView() ) ); + } } } } @@ -698,7 +708,7 @@ public class MapMarkerManager implements IMogoMarkerClickListener, } } - public void redrawMarkerByStyleChanged(){ + public void redrawMarkerByStyleChanged() { if ( mLastDataResult != null ) { runOnTargetThread( () -> { MarkerServiceHandler.getMarkerManager().removeMarkers( ModuleNames.CARD_TYPE_ROAD_CONDITION ); @@ -708,8 +718,8 @@ public class MapMarkerManager implements IMogoMarkerClickListener, } } - public void onCloseCurrentSelectedMarker(){ - if ( mLastCheckMarker != null && !mLastCheckMarker.isDestroyed()) { + public void onCloseCurrentSelectedMarker() { + if ( mLastCheckMarker != null && !mLastCheckMarker.isDestroyed() ) { closeMarker( mLastCheckMarker ); mLastCheckMarker = null; }