From 798df646bfa21b2df3c1a7c7dfb9e39fce9bf32f Mon Sep 17 00:00:00 2001 From: wangcongtao Date: Mon, 13 Apr 2020 11:18:35 +0800 Subject: [PATCH] opt --- .../map/impl/amap/AMapNaviViewWrapper.java | 49 ++++++- .../amap/uicontroller/AMapUIController.java | 8 ++ .../map/uicontroller/CarCursorOption.java | 125 ++++++++++++++++++ .../uicontroller/IMogoMapUIController.java | 11 +- .../com/mogo/map/MogoMapUIController.java | 8 ++ .../extensions/entrance/EntranceFragment.java | 39 +++--- .../navi/ui/search/ChoosePathFragment.kt | 19 +-- 7 files changed, 221 insertions(+), 38 deletions(-) create mode 100644 libraries/mogo-map-api/src/main/java/com/mogo/map/uicontroller/CarCursorOption.java diff --git a/libraries/map-amap/src/main/java/com/mogo/map/impl/amap/AMapNaviViewWrapper.java b/libraries/map-amap/src/main/java/com/mogo/map/impl/amap/AMapNaviViewWrapper.java index eda8168342..cd3c9e8f0c 100644 --- a/libraries/map-amap/src/main/java/com/mogo/map/impl/amap/AMapNaviViewWrapper.java +++ b/libraries/map-amap/src/main/java/com/mogo/map/impl/amap/AMapNaviViewWrapper.java @@ -14,7 +14,6 @@ import android.view.MotionEvent; import android.view.View; import android.view.animation.Interpolator; -import com.alibaba.idst.nls.internal.utils.L; import com.amap.api.maps.AMap; import com.amap.api.maps.AMapUtils; import com.amap.api.maps.CameraUpdateFactory; @@ -47,6 +46,7 @@ import com.mogo.map.impl.amap.utils.MogoMapUtils; import com.mogo.map.impl.amap.utils.ObjectUtils; import com.mogo.map.listener.MogoMapListenerHandler; import com.mogo.map.marker.IMogoMarker; +import com.mogo.map.uicontroller.CarCursorOption; import com.mogo.map.uicontroller.EnumMapUI; import com.mogo.map.uicontroller.IMogoMapUIController; import com.mogo.map.uicontroller.MapControlResult; @@ -87,6 +87,11 @@ public class AMapNaviViewWrapper implements IMogoMapView, private boolean mIsCarLocked = false; 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 ) + .build(); + private CarCursorOption mCarCursorOption = DEFAULT_OPTION; public AMapNaviViewWrapper( AMapNaviView mapView ) { this.mMapView = mapView; @@ -113,8 +118,7 @@ public class AMapNaviViewWrapper implements IMogoMapView, // 设置路线相关的配置属性,如:路线的路况颜色,路线上是否显示摄像头气泡等。 // options.setRouteOverlayOptions( MapStyleUtils.getRouteOverlayOptions() ); // 设置自车的图片对象 - options.setCarBitmap( BitmapFactory.decodeResource( getContext().getResources(), - R.drawable.ic_amap_navi_cursor ) ); + options.setCarBitmap( BitmapFactory.decodeResource( getContext().getResources(), DEFAULT_OPTION.getNaviCursorRes() ) ); // 设置指南针图标否在导航界面显示,默认显示。true,显示;false,隐藏。 options.setCompassEnabled( false ); // 黑夜模式 @@ -463,10 +467,10 @@ public class AMapNaviViewWrapper implements IMogoMapView, break; case NorthUP_2D: mMapView.setNaviMode( AMapNaviView.NORTH_UP_MODE ); - break; + break; } - Logger.d(TAG,"mCurrentUIMode--->"+mCurrentUIMode.name()); + Logger.d( TAG, "mCurrentUIMode--->" + mCurrentUIMode.name() ); if ( options == null ) { return; } @@ -517,7 +521,7 @@ public class AMapNaviViewWrapper implements IMogoMapView, style.showMyLocation( visible ); if ( visible ) { // 强制刷新一遍车标 - style.myLocationIcon( BitmapDescriptorFactory.fromResource( R.drawable.map_api_ic_current_location2 ) ); + style.myLocationIcon( BitmapDescriptorFactory.fromResource( mCarCursorOption.getCarCursorRes() ) ); } mMapView.getMap().setMyLocationStyle( style ); } @@ -840,4 +844,37 @@ public class AMapNaviViewWrapper implements IMogoMapView, public synchronized boolean isCarLocked() { return mIsCarLocked; } + + @Override + public void setCarCursorOption( CarCursorOption option ) { + if ( mCarCursorOption != null ) { + mCarCursorOption.destroy(); + } + try { + mCarCursorOption = option.clone(); + } catch ( CloneNotSupportedException e ) { + mCarCursorOption = DEFAULT_OPTION; + } + if ( !checkAMapView() ) { + return; + } + AMapNaviViewOptions options = mMapView.getViewOptions(); + if ( options != null && mCarCursorOption.getNaviCursorRes() != 0 ) { + options.setCarBitmap( BitmapFactory.decodeResource( getContext().getResources(), mCarCursorOption.getNaviCursorRes() ) ); + mMapView.setViewOptions( options ); + } + + if ( mMapView.getMap() == null ) { + return; + } + MyLocationStyle style = mMapView.getMap().getMyLocationStyle(); + if ( mCarCursorOption.getCarCursorBmp() != null && !mCarCursorOption.getCarCursorBmp().isRecycled() ) { + style.myLocationIcon( BitmapDescriptorFactory.fromBitmap( mCarCursorOption.getCarCursorBmp() ) ); + } else { + if ( mCarCursorOption.getCarCursorRes() != 0 ) { + style.myLocationIcon( BitmapDescriptorFactory.fromResource( mCarCursorOption.getCarCursorRes() ) ); + } + } + mMapView.getMap().setMyLocationStyle( style ); + } } diff --git a/libraries/map-amap/src/main/java/com/mogo/map/impl/amap/uicontroller/AMapUIController.java b/libraries/map-amap/src/main/java/com/mogo/map/impl/amap/uicontroller/AMapUIController.java index 0c5fd01576..6e395ec1ba 100644 --- a/libraries/map-amap/src/main/java/com/mogo/map/impl/amap/uicontroller/AMapUIController.java +++ b/libraries/map-amap/src/main/java/com/mogo/map/impl/amap/uicontroller/AMapUIController.java @@ -9,6 +9,7 @@ import android.view.animation.Interpolator; import com.mogo.map.MogoLatLng; import com.mogo.map.MogoMap; import com.mogo.map.marker.IMogoMarker; +import com.mogo.map.uicontroller.CarCursorOption; import com.mogo.map.uicontroller.EnumMapUI; import com.mogo.map.uicontroller.IMogoMapUIController; import com.mogo.map.uicontroller.MapControlResult; @@ -252,4 +253,11 @@ public class AMapUIController implements IMogoMapUIController { } return false; } + + @Override + public void setCarCursorOption( CarCursorOption option ) { + if ( mClient != null ) { + mClient.setCarCursorOption( option ); + } + } } diff --git a/libraries/mogo-map-api/src/main/java/com/mogo/map/uicontroller/CarCursorOption.java b/libraries/mogo-map-api/src/main/java/com/mogo/map/uicontroller/CarCursorOption.java new file mode 100644 index 0000000000..86e8432f7e --- /dev/null +++ b/libraries/mogo-map-api/src/main/java/com/mogo/map/uicontroller/CarCursorOption.java @@ -0,0 +1,125 @@ +package com.mogo.map.uicontroller; + +import android.graphics.Bitmap; + +import androidx.annotation.DrawableRes; + +import com.mogo.map.IDestroyable; + +/** + * @author congtaowang + * @since 2020-04-13 + *

+ * 设置自车图标 + */ +public class CarCursorOption implements Cloneable, IDestroyable { + + private CarCursorOption() { + } + + /** + * 自车图标资源 + */ + @DrawableRes + private int mCarCursorRes = 0; + + /** + * 自车图标图片,优先使用 + */ + private Bitmap mCarCursorBmp; + + /** + * 导航图标资源 + */ + @DrawableRes + private int mNaviCursorRes = 0; + + public int getCarCursorRes() { + return mCarCursorRes; + } + + public void setCarCursorRes( int carCursorRes ) { + this.mCarCursorRes = carCursorRes; + } + + public Bitmap getCarCursorBmp() { + return mCarCursorBmp; + } + + public void setCarCursorBmp( Bitmap carCursorBmp ) { + this.mCarCursorBmp = carCursorBmp; + } + + public int getNaviCursorRes() { + return mNaviCursorRes; + } + + public void setNaviCursorRes( int naviCursorRes ) { + this.mNaviCursorRes = naviCursorRes; + } + + public static class Builder { + + private CarCursorOption target; + + public Builder() { + target = new CarCursorOption(); + } + + /** + * 自车图标资源 + */ + public Builder carCursorRes( @DrawableRes int redId ) { + target.mCarCursorRes = redId; + return this; + } + + /** + * 自车图标图片,优先使用 + */ + public Builder carCursorBmp( Bitmap bmp ) { + target.mCarCursorBmp = bmp; + return this; + } + + /** + * 导航图标资源 + * + * @param naviCursorRes + * @return + */ + public Builder naviCursorRes( int naviCursorRes ) { + target.mNaviCursorRes = naviCursorRes; + return this; + } + + public CarCursorOption build() { + return target; + } + } + + @Override + public CarCursorOption clone() throws CloneNotSupportedException { + CarCursorOption option = ( CarCursorOption ) super.clone(); + if ( mCarCursorBmp != null && !mCarCursorBmp.isRecycled() ) { + try { + option.mCarCursorBmp = Bitmap.createBitmap( mCarCursorBmp ); + } catch ( Exception e ) { + option.mCarCursorBmp = null; + } + } + option.mCarCursorRes = mCarCursorRes; + option.mNaviCursorRes = mNaviCursorRes; + return option; + } + + @Override + public void destroy() { + if ( mCarCursorBmp != null && !mCarCursorBmp.isRecycled() ) { + mCarCursorBmp.recycle(); + } + mCarCursorBmp = null; + mCarCursorRes = 0; + mNaviCursorRes = 0; + } +} diff --git a/libraries/mogo-map-api/src/main/java/com/mogo/map/uicontroller/IMogoMapUIController.java b/libraries/mogo-map-api/src/main/java/com/mogo/map/uicontroller/IMogoMapUIController.java index d5bdcc35f0..053ae1b848 100644 --- a/libraries/mogo-map-api/src/main/java/com/mogo/map/uicontroller/IMogoMapUIController.java +++ b/libraries/mogo-map-api/src/main/java/com/mogo/map/uicontroller/IMogoMapUIController.java @@ -6,6 +6,8 @@ import android.location.Location; import android.view.View; import android.view.animation.Interpolator; +import androidx.annotation.DrawableRes; + import com.mogo.map.MogoLatLng; import com.mogo.map.marker.IMogoMarker; @@ -56,7 +58,6 @@ public interface IMogoMapUIController { void showMyLocation( boolean visible ); /** - * * @param view */ void showMyLocation( View view ); @@ -183,7 +184,15 @@ public interface IMogoMapUIController { /** * 锁车状态 + * * @return */ boolean isCarLocked(); + + /** + * 配置自车图标样式 + * + * @param option + */ + void setCarCursorOption( CarCursorOption option ); } diff --git a/libraries/mogo-map/src/main/java/com/mogo/map/MogoMapUIController.java b/libraries/mogo-map/src/main/java/com/mogo/map/MogoMapUIController.java index 7d37b79375..e430a33b65 100644 --- a/libraries/mogo-map/src/main/java/com/mogo/map/MogoMapUIController.java +++ b/libraries/mogo-map/src/main/java/com/mogo/map/MogoMapUIController.java @@ -8,6 +8,7 @@ import android.view.animation.Interpolator; import com.mogo.map.impl.amap.uicontroller.AMapUIController; import com.mogo.map.marker.IMogoMarker; +import com.mogo.map.uicontroller.CarCursorOption; import com.mogo.map.uicontroller.EnumMapUI; import com.mogo.map.uicontroller.IMogoMapUIController; import com.mogo.map.uicontroller.MapControlResult; @@ -245,4 +246,11 @@ public class MogoMapUIController implements IMogoMapUIController { } return false; } + + @Override + public void setCarCursorOption( CarCursorOption option ) { + if ( mDelegate != null ) { + mDelegate.setCarCursorOption( option ); + } + } } diff --git a/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/entrance/EntranceFragment.java b/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/entrance/EntranceFragment.java index cb63ec5906..3cb221d814 100644 --- a/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/entrance/EntranceFragment.java +++ b/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/entrance/EntranceFragment.java @@ -9,7 +9,6 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; import com.alibaba.android.arouter.launcher.ARouter; import com.mogo.commons.mvp.MvpFragment; @@ -26,12 +25,12 @@ import com.mogo.map.navi.MogoCongestionInfo; import com.mogo.map.navi.MogoNaviInfo; import com.mogo.map.navi.MogoTraffic; import com.mogo.map.overlay.IMogoPolyline; +import com.mogo.map.uicontroller.CarCursorOption; import com.mogo.map.uicontroller.EnumMapUI; import com.mogo.map.uicontroller.IMogoMapUIController; import com.mogo.module.authorize.authprovider.invoke.AuthorizeConstant; import com.mogo.module.authorize.authprovider.module.IMogoAcquireAuthorizeListener; import com.mogo.module.authorize.authprovider.module.IMogoAuthorizeModuleManager; -import com.mogo.module.common.MogoModulePaths; import com.mogo.module.common.map.MapCenterPointStrategy; import com.mogo.module.common.map.Scene; import com.mogo.module.extensions.ExtensionsModuleConst; @@ -42,12 +41,10 @@ import com.mogo.module.share.ShareControl; import com.mogo.service.IMogoServiceApis; import com.mogo.service.MogoServicePaths; import com.mogo.service.analytics.IMogoAnalytics; -import com.mogo.service.fragmentmanager.FragmentDescriptor; import com.mogo.service.fragmentmanager.IMogoFragmentManager; import com.mogo.service.intent.IMogoIntentListener; import com.mogo.service.map.IMogoMapService; import com.mogo.service.module.IMogoAddressManager; -import com.mogo.service.module.IMogoModuleProvider; import com.mogo.service.module.IMogoRegisterCenter; import com.mogo.service.statusmanager.IMogoStatusManager; @@ -108,9 +105,8 @@ public class EntranceFragment extends MvpFragment< EntranceView, EntrancePresent * 搜索莫模块 */ private boolean mIsLock = true; - private TextView ivMode; + private TextView mCameraMode; - private IMogoPolyline iMogoPolyline; public static boolean isClickShare; @Override @@ -193,18 +189,15 @@ public class EntranceFragment extends MvpFragment< EntranceView, EntrancePresent } } ); - ivMode = findViewById( R.id.module_ext_id_north ); - ivMode.setOnClickListener( new View.OnClickListener() { - @Override - public void onClick( View v ) { - if ( ivMode.isSelected() ) { - mMApUIController.changeMapMode( EnumMapUI.CarUp_2D ); - } else { - mMApUIController.changeMapMode( EnumMapUI.NorthUP_2D ); - } - ivMode.setSelected( !ivMode.isSelected() ); - ivMode.setText( getString( ivMode.isSelected() ? R.string.mode_car_up : R.string.mode_north_up ) ); + mCameraMode = findViewById( R.id.module_ext_id_north ); + mCameraMode.setOnClickListener( view -> { + if ( mCameraMode.isSelected() ) { + mMApUIController.changeMapMode( EnumMapUI.CarUp_2D ); + } else { + mMApUIController.changeMapMode( EnumMapUI.NorthUP_2D ); } + mCameraMode.setSelected( !mCameraMode.isSelected() ); + mCameraMode.setText( getString( mCameraMode.isSelected() ? R.string.mode_car_up : R.string.mode_north_up ) ); } ); mSpeedLimit = findViewById( R.id.module_entrance_id_speed_limit_container ); @@ -221,11 +214,11 @@ public class EntranceFragment extends MvpFragment< EntranceView, EntrancePresent int opera_type = intent.getIntExtra( "EXTRA_OPERA", -1 ); if ( key_type == 10027 ) { if ( opera_type == 0 ) { - ivMode.setSelected( false ); + mCameraMode.setSelected( false ); } else if ( opera_type == 1 ) { - ivMode.setSelected( true ); + mCameraMode.setSelected( true ); } - ivMode.setText( getString( ivMode.isSelected() ? R.string.mode_car_up : R.string.mode_north_up ) ); + mCameraMode.setText( getString( mCameraMode.isSelected() ? R.string.mode_car_up : R.string.mode_north_up ) ); } } } ); @@ -312,9 +305,9 @@ public class EntranceFragment extends MvpFragment< EntranceView, EntrancePresent public void onStartNavi() { mCommonAddress.setVisibility( View.GONE ); mNaviInfo.setVisibility( View.VISIBLE ); - ivMode.setVisibility( View.VISIBLE ); + mCameraMode.setVisibility( View.VISIBLE ); mExitNavi.setVisibility( View.VISIBLE ); - mMApUIController.changeMapMode( ivMode.isSelected() ? EnumMapUI.NorthUP_2D : EnumMapUI.CarUp_2D ); + mMApUIController.changeMapMode( mCameraMode.isSelected() ? EnumMapUI.NorthUP_2D : EnumMapUI.CarUp_2D ); MapCenterPointStrategy.setMapCenterPointBySceneAndDelay( mMApUIController, Scene.NAVI, 500, () -> { return !mMogoNavi.isNaviing(); } ); @@ -324,7 +317,7 @@ public class EntranceFragment extends MvpFragment< EntranceView, EntrancePresent public void onStopNavi() { mCommonAddress.setVisibility( View.VISIBLE ); mNaviInfo.setVisibility( View.GONE ); - ivMode.setVisibility( View.GONE ); + mCameraMode.setVisibility( View.GONE ); mExitNavi.setVisibility( View.GONE ); mSpeedLimit.setVisibility( View.GONE ); mMApUIController.changeMapMode( EnumMapUI.NorthUP_2D ); diff --git a/modules/mogo-module-search/src/main/java/com/mogo/module/navi/ui/search/ChoosePathFragment.kt b/modules/mogo-module-search/src/main/java/com/mogo/module/navi/ui/search/ChoosePathFragment.kt index 1b2110e2b7..6664d5429e 100644 --- a/modules/mogo-module-search/src/main/java/com/mogo/module/navi/ui/search/ChoosePathFragment.kt +++ b/modules/mogo-module-search/src/main/java/com/mogo/module/navi/ui/search/ChoosePathFragment.kt @@ -34,8 +34,8 @@ import kotlinx.android.synthetic.main.include_search_bar.iv_navi_back * 2020-01-09. */ class ChoosePathFragment : BaseFragment(), IMogoNaviListener, IMogoVoiceCmdCallBack { - override fun onCmdSelected(cmd: String?) { + override fun onCmdSelected(cmd: String?) { when (cmd) { "firstPath" -> { selectItem(0) @@ -105,7 +105,13 @@ class ChoosePathFragment : BaseFragment(), IMogoNaviListener, IMogoVoiceCmdCallB if (calculatedStrategies != null && calculatedStrategies.size > 0) { mAdapter.setDatas(calculatedStrategies) mAdapter.selectTag = calculatedStrategies[0].tagId - UiThreadHandler.postDelayed( { + UiThreadHandler.postDelayed({ + if (isRemoving || isDetached) { + return@postDelayed + } + if (calculatedStrategies.isNullOrEmpty()) { + return@postDelayed + } SearchServiceHolder.getNavi().itemClickInteraction.onItemClicked(calculatedStrategies[0].tagId) }, 500L) } @@ -163,19 +169,16 @@ class ChoosePathFragment : BaseFragment(), IMogoNaviListener, IMogoVoiceCmdCallB et_navi_search.setText(getString(R.string.choose_path)) et_navi_search.isEnabled = false - SearchServiceHolder.getNavi() - .naviTo(mogoTip) + SearchServiceHolder.getNavi().naviTo(mogoTip) SearchServiceHolder.listenerCenter.registerMogoNaviListener(AMapConstants.PATH_FRAGMENT_CHOOSE_PATH, this) var arrayList = ArrayList() mAdapter = CalculatePathAdapter(activity, arrayList) - rv_search_result.layoutManager = - LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false) + rv_search_result.layoutManager = LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false) rv_search_result.adapter = mAdapter tv_navi_navi.setOnClickListener { - if (group_path.visibility == View.VISIBLE) { retry() } else { @@ -184,7 +187,7 @@ class ChoosePathFragment : BaseFragment(), IMogoNaviListener, IMogoVoiceCmdCallB } SearchServiceHolder.getNavi().setLineClickInteraction { - mAdapter.selectTag = it + mAdapter.selectTag = it } mAdapter.setOnClickListener {