opt
This commit is contained in:
@@ -1,14 +1,10 @@
|
||||
package com.mogo.map.impl.amap;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.amap.api.navi.AMapNaviView;
|
||||
import com.mogo.map.IMogoMapView;
|
||||
import com.mogo.map.IMogoMapViewCreator;
|
||||
import com.mogo.map.MogoBaseMapView;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
@@ -18,8 +14,17 @@ import com.mogo.map.MogoBaseMapView;
|
||||
*/
|
||||
public class AMapBaseMapView implements IMogoMapViewCreator {
|
||||
|
||||
private static final String TAG = "AMapBaseMapView";
|
||||
|
||||
@Override
|
||||
public IMogoMapView create( Context context ) {
|
||||
return new AMapNaviViewWrapper( new AMapNaviView( context ) );
|
||||
IMogoMapView mapView = AMapViewHandler.getMapView();
|
||||
if ( mapView != null
|
||||
&& mapView.getMapView() != null
|
||||
&& mapView.getMapView().getParent() != null ) {
|
||||
ViewGroup group = ( ViewGroup ) mapView.getMapView().getParent();
|
||||
group.removeView( mapView.getMapView() );
|
||||
}
|
||||
return mapView;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ import com.mogo.map.impl.amap.marker.AMapMarkerWrapper;
|
||||
import com.mogo.map.impl.amap.message.AMapMessageListener;
|
||||
import com.mogo.map.impl.amap.message.AMapMessageManager;
|
||||
import com.mogo.map.impl.amap.navi.NaviClient;
|
||||
import com.mogo.map.impl.amap.uicontroller.AMapUIController;
|
||||
import com.mogo.map.impl.amap.utils.MogoMapUtils;
|
||||
import com.mogo.map.impl.amap.utils.ObjectUtils;
|
||||
import com.mogo.map.listener.MogoMapListenerHandler;
|
||||
@@ -91,11 +92,16 @@ public class AMapNaviViewWrapper implements IMogoMapView,
|
||||
.build();
|
||||
private CarCursorOption mCarCursorOption = DEFAULT_OPTION;
|
||||
|
||||
private BnHooker bnHooker;
|
||||
|
||||
private Location mLastDriveLocationShadow = null;
|
||||
private Marker mMyLocationMarker;
|
||||
|
||||
public AMapNaviViewWrapper( AMapNaviView mapView ) {
|
||||
this.mMapView = mapView;
|
||||
this.mIMap = new AMapWrapper( mMapView.getMap(), mMapView, this );
|
||||
this.mIMap = new AMapWrapper( mMapView.getMap(), mMapView.getContext(), this );
|
||||
try {
|
||||
new BnHooker( mMapView.getMap(), mapView.getContext() );
|
||||
bnHooker = new BnHooker( mMapView.getMap() );
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -185,6 +191,7 @@ public class AMapNaviViewWrapper implements IMogoMapView,
|
||||
aMap.setOnCameraChangeListener( this );
|
||||
aMap.setOnMyLocationChangeListener( this );
|
||||
}
|
||||
AMapMessageManager.getInstance().clear();
|
||||
AMapMessageManager.getInstance().registerAMapMessageListener( this );
|
||||
}
|
||||
|
||||
@@ -233,6 +240,8 @@ public class AMapNaviViewWrapper implements IMogoMapView,
|
||||
public void onDestroy() {
|
||||
if ( mMapView != null ) {
|
||||
mMapView.onDestroy();
|
||||
AMapUIController.getInstance().release();
|
||||
AMapWrapper.release();
|
||||
Logger.d( TAG, "map onDestroy" );
|
||||
}
|
||||
}
|
||||
@@ -272,6 +281,16 @@ public class AMapNaviViewWrapper implements IMogoMapView,
|
||||
@Override
|
||||
public void onTouch( MotionEvent motionEvent ) {
|
||||
MogoMapListenerHandler.getInstance().onTouch( motionEvent );
|
||||
if ( motionEvent.getAction() == MotionEvent.ACTION_DOWN ) {
|
||||
changeMyLocationType2UnFollow();
|
||||
}
|
||||
if ( motionEvent.getAction() != MotionEvent.ACTION_UP ) {
|
||||
try {
|
||||
bnHooker.clearAllMessages();
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -455,6 +474,7 @@ public class AMapNaviViewWrapper implements IMogoMapView,
|
||||
break;
|
||||
}
|
||||
mMapView.setViewOptions( options );
|
||||
changeMyLocationType2Follow();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -521,11 +541,17 @@ public class AMapNaviViewWrapper implements IMogoMapView,
|
||||
Logger.d( TAG, Log.getStackTraceString( new Throwable() ) );
|
||||
}
|
||||
if ( checkAMapView() ) {
|
||||
MyLocationStyle style = mMapView.getMap().getMyLocationStyle();
|
||||
MyLocationStyle style = getMyLocationStyle();
|
||||
if ( style == null ) {
|
||||
style = new MyLocationStyle();
|
||||
}
|
||||
style.showMyLocation( visible );
|
||||
if ( mCurrentUIMode == EnumMapUI.CarUp_2D
|
||||
|| mCurrentUIMode == EnumMapUI.CarUp_3D ) {
|
||||
style.myLocationType( MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER );
|
||||
} else {
|
||||
style.myLocationType( MyLocationStyle.LOCATION_TYPE_FOLLOW );
|
||||
}
|
||||
if ( visible ) {
|
||||
// 强制刷新一遍车标
|
||||
style.myLocationIcon( BitmapDescriptorFactory.fromResource( mCarCursorOption.getCarCursorRes() ) );
|
||||
@@ -543,21 +569,71 @@ public class AMapNaviViewWrapper implements IMogoMapView,
|
||||
Logger.d( TAG, Log.getStackTraceString( new Throwable() ) );
|
||||
}
|
||||
if ( checkAMapView() ) {
|
||||
MyLocationStyle style = mMapView.getMap().getMyLocationStyle();
|
||||
MyLocationStyle style = getMyLocationStyle();
|
||||
if ( style == null ) {
|
||||
style = new MyLocationStyle();
|
||||
}
|
||||
if ( mCurrentUIMode == EnumMapUI.CarUp_2D
|
||||
|| mCurrentUIMode == EnumMapUI.CarUp_3D ) {
|
||||
style.myLocationType( MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER );
|
||||
} else {
|
||||
style.myLocationType( MyLocationStyle.LOCATION_TYPE_FOLLOW );
|
||||
}
|
||||
style.showMyLocation( true );
|
||||
style.myLocationIcon( BitmapDescriptorFactory.fromView( view ) );
|
||||
mMapView.getMap().setMyLocationStyle( style );
|
||||
}
|
||||
}
|
||||
|
||||
private void changeMyLocationType2UnFollow(){
|
||||
if ( mCurrentUIMode == null ) {
|
||||
return;
|
||||
}
|
||||
if ( !checkAMapView() ) {
|
||||
return;
|
||||
}
|
||||
MyLocationStyle style = getMyLocationStyle();
|
||||
switch ( mCurrentUIMode ) {
|
||||
case NorthUP_2D:
|
||||
style.myLocationType( MyLocationStyle.LOCATION_TYPE_FOLLOW_NO_CENTER );
|
||||
break;
|
||||
case CarUp_2D:
|
||||
case CarUp_3D:
|
||||
style.myLocationType( MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER );
|
||||
break;
|
||||
}
|
||||
mMapView.getMap().setMyLocationStyle( style );
|
||||
Logger.d( TAG, "设置" );
|
||||
}
|
||||
|
||||
private void changeMyLocationType2Follow() {
|
||||
if ( mCurrentUIMode == null ) {
|
||||
return;
|
||||
}
|
||||
if ( !checkAMapView() ) {
|
||||
return;
|
||||
}
|
||||
MyLocationStyle style = getMyLocationStyle();
|
||||
if ( style == null ) {
|
||||
style = new MyLocationStyle();
|
||||
}
|
||||
switch ( mCurrentUIMode ) {
|
||||
case NorthUP_2D:
|
||||
style.myLocationType( MyLocationStyle.LOCATION_TYPE_FOLLOW );
|
||||
break;
|
||||
case CarUp_2D:
|
||||
case CarUp_3D:
|
||||
style.myLocationType( MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE );
|
||||
break;
|
||||
}
|
||||
mMapView.getMap().setMyLocationStyle( style );
|
||||
}
|
||||
|
||||
public void initMyLocation() {
|
||||
if ( checkAMapView() ) {
|
||||
mMapView.getMap().setMyLocationEnabled( true );
|
||||
MyLocationStyle style = mMapView.getMap().getMyLocationStyle();
|
||||
style.myLocationType( MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER );
|
||||
MyLocationStyle style = getMyLocationStyle();
|
||||
style.myLocationType( MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE );
|
||||
style.interval( 1000 );
|
||||
style.anchor( 0.5F, 0.5F );
|
||||
style.strokeColor( Color.TRANSPARENT );
|
||||
@@ -575,6 +651,7 @@ public class AMapNaviViewWrapper implements IMogoMapView,
|
||||
}
|
||||
Logger.d( TAG, "锁车" );
|
||||
mMapView.recoverLockMode();
|
||||
changeMyLocationType2Follow();
|
||||
mIsCarLocked = true;
|
||||
}
|
||||
}
|
||||
@@ -585,8 +662,8 @@ public class AMapNaviViewWrapper implements IMogoMapView,
|
||||
Logger.d( TAG, Log.getStackTraceString( new Throwable() ) );
|
||||
}
|
||||
Logger.d( TAG, "解锁锁车" );
|
||||
mockTouchEvent();
|
||||
mIsCarLocked = false;
|
||||
mockTouchEvent();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -609,7 +686,7 @@ public class AMapNaviViewWrapper implements IMogoMapView,
|
||||
Logger.d( TAG, Log.getStackTraceString( new Throwable() ) );
|
||||
}
|
||||
Logger.d( TAG, "Zoom锁定锁车比例尺 %s", var1 );
|
||||
mMapView.setLockZoom( var1 );
|
||||
// mMapView.setLockZoom( var1 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -818,9 +895,35 @@ public class AMapNaviViewWrapper implements IMogoMapView,
|
||||
|
||||
@Override
|
||||
public void onMyLocationChange( Location location ) {
|
||||
if ( ( int ) location.getSpeed() > 0 ) {
|
||||
mLastDriveLocationShadow = location;
|
||||
} else {
|
||||
if ( ( int ) location.getBearing() == 0
|
||||
&& mCurrentUIMode == EnumMapUI.NorthUP_2D
|
||||
&& mLastDriveLocationShadow != null ) {
|
||||
if ( mMyLocationMarker == null ) {
|
||||
initMyLocationMarker();
|
||||
}
|
||||
if ( mMyLocationMarker != null ) {
|
||||
mMyLocationMarker.setRotateAngle( 360 - mLastDriveLocationShadow.getBearing() );
|
||||
}
|
||||
}
|
||||
}
|
||||
NaviClient.getInstance( getContext() ).syncCarLocation( location );
|
||||
}
|
||||
|
||||
private void initMyLocationMarker() {
|
||||
List< Marker > markers = mMapView.getMap().getMapScreenMarkers();
|
||||
if ( markers != null ) {
|
||||
for ( Marker marker : markers ) {
|
||||
if ( marker != null && marker.getObject() == null ) {
|
||||
this.mMyLocationMarker = marker;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumMapUI getCurrentUiMode() {
|
||||
return mCurrentUIMode;
|
||||
@@ -863,7 +966,7 @@ public class AMapNaviViewWrapper implements IMogoMapView,
|
||||
if ( mMapView.getMap() == null ) {
|
||||
return;
|
||||
}
|
||||
MyLocationStyle style = mMapView.getMap().getMyLocationStyle();
|
||||
MyLocationStyle style = getMyLocationStyle();
|
||||
if ( mCarCursorOption.getCarCursorBmp() != null && !mCarCursorOption.getCarCursorBmp().isRecycled() ) {
|
||||
style.myLocationIcon( BitmapDescriptorFactory.fromBitmap( mCarCursorOption.getCarCursorBmp() ) );
|
||||
} else {
|
||||
@@ -876,6 +979,20 @@ public class AMapNaviViewWrapper implements IMogoMapView,
|
||||
mMapView.getMap().setMyLocationStyle( style );
|
||||
}
|
||||
|
||||
private MyLocationStyle getMyLocationStyle() {
|
||||
MyLocationStyle style = null;
|
||||
try {
|
||||
style = mMapView.getMap().getMyLocationStyle();
|
||||
} catch ( Exception e ) {
|
||||
style = new MyLocationStyle();
|
||||
} finally {
|
||||
if ( style == null ) {
|
||||
style = new MyLocationStyle();
|
||||
}
|
||||
return style;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapCameraPosition getMapCameraPosition() {
|
||||
if ( checkAMapView() ) {
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.mogo.map.impl.amap;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.amap.api.maps.MapView;
|
||||
import com.amap.api.navi.AMapNaviView;
|
||||
import com.mogo.commons.debug.DebugConfig;
|
||||
import com.mogo.map.IMogoMapView;
|
||||
|
||||
public
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/9/10
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
class AMapViewHandler {
|
||||
|
||||
private static IMogoMapView sMapView;
|
||||
|
||||
public static void createMapView( Context context ) {
|
||||
if ( DebugConfig.getCarMachineType() == DebugConfig.CAR_MACHINE_TYPE_SELF_INNOVATE ) {
|
||||
sMapView = new AMapNaviViewWrapper( new AMapNaviView( context ) );
|
||||
} else {
|
||||
sMapView = new AMapNaviViewWrapper( new AMapNaviView( context ) );
|
||||
}
|
||||
}
|
||||
|
||||
public static IMogoMapView getMapView() {
|
||||
return sMapView;
|
||||
}
|
||||
|
||||
public static void destroy() {
|
||||
sMapView = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,834 @@
|
||||
package com.mogo.map.impl.amap;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
import android.location.Location;
|
||||
import android.os.Bundle;
|
||||
import android.os.SystemClock;
|
||||
import android.os.Trace;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.animation.Interpolator;
|
||||
|
||||
import com.amap.api.maps.AMap;
|
||||
import com.amap.api.maps.AMapUtils;
|
||||
import com.amap.api.maps.CameraUpdateFactory;
|
||||
import com.amap.api.maps.MapView;
|
||||
import com.amap.api.maps.TextureMapView;
|
||||
import com.amap.api.maps.model.BitmapDescriptorFactory;
|
||||
import com.amap.api.maps.model.CameraPosition;
|
||||
import com.amap.api.maps.model.CameraPositionCreator;
|
||||
import com.amap.api.maps.model.LatLng;
|
||||
import com.amap.api.maps.model.LatLngBounds;
|
||||
import com.amap.api.maps.model.Marker;
|
||||
import com.amap.api.maps.model.MyLocationStyle;
|
||||
import com.amap.api.maps.model.Poi;
|
||||
import com.amap.api.maps.model.Polyline;
|
||||
import com.amap.api.maps.model.animation.Animation;
|
||||
import com.amap.api.maps.model.animation.TranslateAnimation;
|
||||
import com.amap.api.navi.model.NaviInfo;
|
||||
import com.mogo.commons.debug.DebugConfig;
|
||||
import com.mogo.map.IMogoMap;
|
||||
import com.mogo.map.IMogoMapView;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
import com.mogo.map.impl.amap.hook.BnHooker;
|
||||
import com.mogo.map.impl.amap.marker.AMapMarkerWrapper;
|
||||
import com.mogo.map.impl.amap.message.AMapMessageListener;
|
||||
import com.mogo.map.impl.amap.message.AMapMessageManager;
|
||||
import com.mogo.map.impl.amap.navi.NaviClient;
|
||||
import com.mogo.map.impl.amap.uicontroller.AMapUIController;
|
||||
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.MapCameraPosition;
|
||||
import com.mogo.map.uicontroller.MapControlResult;
|
||||
import com.mogo.utils.NetworkUtils;
|
||||
import com.mogo.utils.WindowUtils;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-18
|
||||
* <p>
|
||||
* 代理高德导航地图
|
||||
*/
|
||||
public class AMapViewWrapper implements IMogoMapView,
|
||||
IMogoMapUIController,
|
||||
AMap.OnMarkerClickListener,
|
||||
AMap.OnMapLoadedListener,
|
||||
AMap.OnMapTouchListener,
|
||||
AMap.OnPOIClickListener,
|
||||
AMap.OnMapClickListener,
|
||||
AMap.OnPolylineClickListener,
|
||||
AMapMessageListener,
|
||||
AMap.OnCameraChangeListener,
|
||||
AMap.OnMyLocationChangeListener {
|
||||
|
||||
private static final String TAG = "AMapViewWrapper";
|
||||
|
||||
private final MapView mMapView;
|
||||
private IMogoMap mIMap;
|
||||
|
||||
private AMapMarkerClickHandler mMarkerClickHandler;
|
||||
private EnumMapUI mCurrentUIMode;
|
||||
|
||||
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 AMapViewWrapper( MapView mapView ) {
|
||||
this.mMapView = mapView;
|
||||
this.mIMap = new AMapWrapper( mMapView.getMap(), mMapView.getContext(), this );
|
||||
try {
|
||||
new BnHooker( mMapView.getMap() );
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void initMapView() {
|
||||
if ( mMapView == null ) {
|
||||
return;
|
||||
}
|
||||
// AMapNaviViewOptions options = mMapView.getViewOptions();
|
||||
// if ( options != null ) {
|
||||
// // 设置是否开启自动黑夜模式切换,默认为false,不自动切换
|
||||
// options.setAutoNaviViewNightMode( false );
|
||||
// // 设置6秒后是否自动锁车
|
||||
// options.setAutoLockCar( false );
|
||||
// // 设置路线上的摄像头气泡是否显示
|
||||
// options.setCameraBubbleShow( true );
|
||||
// // 设置路线相关的配置属性,如:路线的路况颜色,路线上是否显示摄像头气泡等。
|
||||
// // options.setRouteOverlayOptions( MapStyleUtils.getRouteOverlayOptions() );
|
||||
// // 设置自车的图片对象
|
||||
// options.setCarBitmap( BitmapFactory.decodeResource( getContext().getResources(), DEFAULT_OPTION.getNaviCursorRes() ) );
|
||||
// // 设置指南针图标否在导航界面显示,默认显示。true,显示;false,隐藏。
|
||||
// options.setCompassEnabled( false );
|
||||
// // 黑夜模式
|
||||
// options.setNaviNight( true );
|
||||
// //设置路况光柱条是否显示(只适用于驾车导航,需要联网)。
|
||||
// options.setTrafficBarEnabled( false );
|
||||
// // 设置[实时交通图层开关按钮]是否显示(只适用于驾车导航,需要联网)。
|
||||
// options.setTrafficLayerEnabled( false );
|
||||
// // 设置导航界面是否显示路线全览按钮。
|
||||
// options.setRouteListButtonShow( false );
|
||||
// // 设置屏幕是否常亮,默认开启
|
||||
// options.setScreenAlwaysBright( false );
|
||||
// // 设置交通播报是否打开(只适用于驾车导航,需要联网)。
|
||||
// options.setTrafficInfoUpdateEnabled( true );
|
||||
// // 设置摄像头播报是否打开(只适用于驾车导航)。
|
||||
// options.setCameraInfoUpdateEnabled( true );
|
||||
// // 设置菜单按钮是否在导航界面显示。
|
||||
// options.setSettingMenuEnabled( false );
|
||||
// // 设置是否绘制显示交通路况的线路(彩虹线),拥堵-红色,畅通-绿色,缓慢-黄色,未知-蓝色。默认不绘制彩虹线。
|
||||
// options.setTrafficLine( true );
|
||||
// // 设置是否绘制牵引线(当前位置到目的地的指引线)。默认不绘制牵引线。
|
||||
// options.setLeaderLineEnabled( -1 );
|
||||
// // 设置导航界面UI是否显示。
|
||||
// options.setLayoutVisible( false );
|
||||
// // 设置是否自动画路
|
||||
// options.setAutoDrawRoute( false );
|
||||
// // 设置是否显示路口放大图(实景图)
|
||||
// options.setRealCrossDisplayShow( false );
|
||||
// // 设置是否显示路口放大图(路口模型图)
|
||||
// options.setModeCrossDisplayShow( false );
|
||||
// // 设置是否显示道路信息view
|
||||
// options.setLaneInfoShow( false );
|
||||
// // 设置是否自动改变缩放等级
|
||||
// options.setAutoChangeZoom( false );
|
||||
// // 设置是否自动全览模式,即在算路成功后自动进入全览模式
|
||||
// options.setAutoDisplayOverview( false );
|
||||
// // 设置路线转向箭头隐藏和显示
|
||||
// options.setNaviArrowVisible( false );
|
||||
// // 通过路线是否自动置灰,仅支持驾车导航
|
||||
// options.setAfterRouteAutoGray( true );
|
||||
// options.setZoom( ( ( int ) mDefaultZoomLevel ) );
|
||||
// options.setPointToCenter( 0.7D, 0.5D );
|
||||
// // 2D模式
|
||||
// options.setTilt( 0 );
|
||||
// mMapView.setViewOptions( options );
|
||||
// }
|
||||
// mMapView.setRouteOverlayVisible( false );
|
||||
// mMapView.setCarOverlayVisible( false );
|
||||
changeMapMode( EnumMapUI.CarUp_2D );
|
||||
if ( NetworkUtils.isConnected( mMapView.getContext() ) ) {
|
||||
setTrafficEnabled( true );
|
||||
}
|
||||
mMapView.getMap().moveCamera( CameraUpdateFactory.zoomTo( mDefaultZoomLevel ) );
|
||||
}
|
||||
|
||||
private void initListeners() {
|
||||
|
||||
mMarkerClickHandler = new AMapMarkerClickHandler();
|
||||
final AMap aMap = mMapView.getMap();
|
||||
if ( aMap != null ) {
|
||||
aMap.setOnMarkerClickListener( this );
|
||||
aMap.setOnMapLoadedListener( this );
|
||||
aMap.setOnMapTouchListener( this );
|
||||
aMap.setOnPolylineClickListener( this );
|
||||
aMap.setOnCameraChangeListener( this );
|
||||
aMap.setOnPOIClickListener( this );
|
||||
aMap.setOnMapClickListener( this );
|
||||
aMap.setOnCameraChangeListener( this );
|
||||
aMap.setOnMyLocationChangeListener( this );
|
||||
}
|
||||
AMapMessageManager.getInstance().clear();
|
||||
AMapMessageManager.getInstance().registerAMapMessageListener( this );
|
||||
}
|
||||
|
||||
private Context getContext() {
|
||||
return mMapView.getContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getMapView() {
|
||||
return mMapView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoMap getMap() {
|
||||
return mIMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate( Bundle bundle ) {
|
||||
Logger.d( TAG, Log.getStackTraceString( new Throwable( ) ) );
|
||||
if ( mMapView != null ) {
|
||||
mMapView.onCreate( bundle );
|
||||
Logger.d( TAG, "map onCreate" );
|
||||
initMapView();
|
||||
initListeners();
|
||||
initMyLocation();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
if ( mMapView != null ) {
|
||||
mMapView.onResume();
|
||||
Logger.d( TAG, Log.getStackTraceString( new Throwable() ) );
|
||||
Logger.d( TAG, "map onResume" );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
if ( mMapView != null ) {
|
||||
mMapView.onPause();
|
||||
Logger.d( TAG, "map onPause" );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
if ( mMapView != null ) {
|
||||
mMapView.onDestroy();
|
||||
AMapUIController.getInstance().release();
|
||||
AMapWrapper.release();
|
||||
Logger.d( TAG, "map onDestroy" );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState( Bundle outState ) {
|
||||
if ( mMapView != null ) {
|
||||
mMapView.onSaveInstanceState( outState );
|
||||
Logger.d( TAG, "map onSaveInstanceState" );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
if ( mMapView != null ) {
|
||||
mMapView.onLowMemory();
|
||||
}
|
||||
Logger.d( TAG, "map onLowMemory" );
|
||||
}
|
||||
|
||||
/**
|
||||
* 地图marker点击
|
||||
*/
|
||||
@Override
|
||||
public boolean onMarkerClick( Marker marker ) {
|
||||
return mMarkerClickHandler.handleMarkerClicked( marker );
|
||||
}
|
||||
|
||||
/**
|
||||
* 地图加载完毕
|
||||
*/
|
||||
@Override
|
||||
public void onMapLoaded() {
|
||||
MogoMapListenerHandler.getInstance().onMapLoaded();
|
||||
}
|
||||
|
||||
/**
|
||||
* 地图点击回调
|
||||
*/
|
||||
@Override
|
||||
public void onTouch( MotionEvent motionEvent ) {
|
||||
MogoMapListenerHandler.getInstance().onTouch( motionEvent );
|
||||
if ( mIsCarLocked ) {
|
||||
loseLockMode();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* POI 点击
|
||||
*/
|
||||
@Override
|
||||
public void onPOIClick( Poi poi ) {
|
||||
if ( InterceptorHandler.getInstance().ignorePoiClicked( getContext() ) ) {
|
||||
return;
|
||||
}
|
||||
MogoMapListenerHandler.getInstance().onPOIClick( ObjectUtils.fromAMap( poi ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapClick( LatLng latLng ) {
|
||||
if ( InterceptorHandler.getInstance().ignoreMapClicked( getContext() ) ) {
|
||||
return;
|
||||
}
|
||||
MogoMapListenerHandler.getInstance().onMapClick( ObjectUtils.fromAMap( latLng ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPolylineClick( Polyline polyline ) {
|
||||
if ( !NaviClient.getInstance( getContext() ).isNaviing() ) {
|
||||
NaviClient.getInstance( getContext() ).handleClickedPolyline( polyline );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTrafficEnabled( boolean visible ) {
|
||||
if ( checkMapView() ) {
|
||||
Logger.d( TAG, "setTrafficEnabled" );
|
||||
mMapView.getMap().setTrafficEnabled( true );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapControlResult changeZoom( boolean zoom ) {
|
||||
if ( checkMapView() ) {
|
||||
mDefaultZoomLevel = ( int ) ( getMap().getZoomLevel() + 0.5f );
|
||||
|
||||
if ( zoom ) {
|
||||
if ( mDefaultZoomLevel >= 20 ) {
|
||||
return MapControlResult.TARGET;
|
||||
}
|
||||
} else {
|
||||
if ( mDefaultZoomLevel <= 3 ) {
|
||||
return MapControlResult.TARGET;
|
||||
}
|
||||
}
|
||||
|
||||
if ( zoom ) {
|
||||
mDefaultZoomLevel += 2f;
|
||||
if ( mDefaultZoomLevel > 20 ) {
|
||||
mDefaultZoomLevel = 20;
|
||||
}
|
||||
} else {
|
||||
mDefaultZoomLevel -= 2f;
|
||||
if ( mDefaultZoomLevel < 1 ) {
|
||||
mDefaultZoomLevel = 1;
|
||||
}
|
||||
}
|
||||
changeZoom( ( int ) 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() ) );
|
||||
}
|
||||
getMap().changeZoom( zoom );
|
||||
return MapControlResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeMapMode( EnumMapUI ui ) {
|
||||
if ( ui == null ) {
|
||||
return;
|
||||
}
|
||||
if ( checkMapView() ) {
|
||||
switch ( ui ) {
|
||||
|
||||
case CarUp_3D:
|
||||
mMapView.getMap().moveCamera( CameraUpdateFactory.changeTilt( 60 ) );
|
||||
break;
|
||||
case NorthUP_2D:
|
||||
mMapView.getMap().moveCamera( CameraUpdateFactory.changeTilt( 0 ) );
|
||||
break;
|
||||
case CarUp_2D:
|
||||
mMapView.getMap().moveCamera( CameraUpdateFactory.changeTilt( 0 ) );
|
||||
break;
|
||||
case Type_Light:
|
||||
mMapView.getMap().setMapType( AMap.MAP_TYPE_NORMAL );
|
||||
break;
|
||||
case Type_Night:
|
||||
mMapView.getMap().setMapType( AMap.MAP_TYPE_NIGHT );
|
||||
break;
|
||||
case Type_AUTO_LIGHT_Night:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkMapView() {
|
||||
if ( mMapView == null || mMapView.getMap() == 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" );
|
||||
return;
|
||||
}
|
||||
if ( DebugConfig.isDebug() ) {
|
||||
Logger.d( TAG, Log.getStackTraceString( new Throwable() ) );
|
||||
}
|
||||
loseLockMode();
|
||||
if ( animate ) {
|
||||
mMapView.getMap().animateCamera( CameraUpdateFactory.newLatLng( new LatLng( latLng.lat, latLng.lng ) ) );
|
||||
} else {
|
||||
mMapView.getMap().moveCamera( CameraUpdateFactory.newLatLng( new LatLng( latLng.lat, latLng.lng ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
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 ( checkMapView() ) {
|
||||
MyLocationStyle style = getMyLocationStyle();
|
||||
if ( style == null ) {
|
||||
style = new MyLocationStyle();
|
||||
}
|
||||
style.showMyLocation( visible );
|
||||
if ( visible ) {
|
||||
// 强制刷新一遍车标
|
||||
style.myLocationIcon( BitmapDescriptorFactory.fromResource( mCarCursorOption.getCarCursorRes() ) );
|
||||
}
|
||||
mMapView.getMap().setMyLocationStyle( style );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showMyLocation( View view ) {
|
||||
if ( NaviClient.getInstance( getContext() ).isNaviing() ) {
|
||||
return;
|
||||
}
|
||||
if ( DebugConfig.isDebug() ) {
|
||||
Logger.d( TAG, Log.getStackTraceString( new Throwable() ) );
|
||||
}
|
||||
if ( checkMapView() ) {
|
||||
MyLocationStyle style = getMyLocationStyle();
|
||||
if ( style == null ) {
|
||||
style = new MyLocationStyle();
|
||||
}
|
||||
style.showMyLocation( true );
|
||||
style.myLocationIcon( BitmapDescriptorFactory.fromView( view ) );
|
||||
mMapView.getMap().setMyLocationStyle( style );
|
||||
}
|
||||
}
|
||||
|
||||
public void initMyLocation() {
|
||||
if ( checkMapView() ) {
|
||||
mMapView.getMap().setMyLocationEnabled( true );
|
||||
MyLocationStyle style = getMyLocationStyle();
|
||||
style.myLocationType( MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER );
|
||||
style.interval( 1000 );
|
||||
style.anchor( 0.5F, 0.5F );
|
||||
style.strokeColor( Color.TRANSPARENT );
|
||||
style.strokeWidth( 0 );
|
||||
style.radiusFillColor( Color.TRANSPARENT );
|
||||
mMapView.getMap().setMyLocationStyle( style );
|
||||
}
|
||||
}
|
||||
|
||||
private MyLocationStyle getMyLocationStyle() {
|
||||
MyLocationStyle style = null;
|
||||
try {
|
||||
style = mMapView.getMap().getMyLocationStyle();
|
||||
} catch ( Exception e ) {
|
||||
style = new MyLocationStyle();
|
||||
} finally {
|
||||
if ( style == null ) {
|
||||
style = new MyLocationStyle();
|
||||
}
|
||||
return style;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recoverLockMode() {
|
||||
if ( checkMapView() ) {
|
||||
if ( DebugConfig.isDebug() ) {
|
||||
Logger.d( TAG, Log.getStackTraceString( new Throwable() ) );
|
||||
}
|
||||
Logger.d( TAG, "锁车" );
|
||||
Location target = NaviClient.getInstance( getContext() ).getCarLocation2();
|
||||
if ( target != null ) {
|
||||
mMapView.getMap().animateCamera( CameraUpdateFactory.newCameraPosition(
|
||||
new CameraPosition( new LatLng( target.getLatitude(), target.getLongitude() ),
|
||||
mDefaultZoomLevel,
|
||||
0,
|
||||
0
|
||||
)
|
||||
), new AMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onFinish() {
|
||||
changeMyLocationStyle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel() {
|
||||
changeMyLocationStyle();
|
||||
}
|
||||
} );
|
||||
} else {
|
||||
changeMyLocationStyle();
|
||||
}
|
||||
mIsCarLocked = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void changeMyLocationStyle() {
|
||||
MyLocationStyle style = getMyLocationStyle();
|
||||
if ( style == null ) {
|
||||
style = new MyLocationStyle();
|
||||
}
|
||||
style.myLocationType( MyLocationStyle.LOCATION_TYPE_FOLLOW );
|
||||
mMapView.getMap().setMyLocationStyle( style );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loseLockMode() {
|
||||
if ( DebugConfig.isDebug() ) {
|
||||
Logger.d( TAG, Log.getStackTraceString( new Throwable() ) );
|
||||
}
|
||||
Logger.d( TAG, "解锁锁车" );
|
||||
MyLocationStyle style = getMyLocationStyle();
|
||||
style.myLocationType( MyLocationStyle.LOCATION_TYPE_FOLLOW_NO_CENTER );
|
||||
mMapView.getMap().setMyLocationStyle( style );
|
||||
mIsCarLocked = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 模拟点击事件,达到锁车->普通事件
|
||||
*/
|
||||
private void mockTouchEvent() {
|
||||
long downTime = SystemClock.uptimeMillis();
|
||||
long eventTime = downTime + 1;
|
||||
int metaState = 0;
|
||||
MotionEvent motionEvent = MotionEvent.obtain( downTime, eventTime, MotionEvent.ACTION_DOWN, 0, 0, metaState );
|
||||
mMapView.dispatchTouchEvent( motionEvent );
|
||||
MotionEvent upEvent = MotionEvent.obtain( downTime + 1, eventTime + 2, MotionEvent.ACTION_UP, 0, 0, metaState );
|
||||
mMapView.dispatchTouchEvent( upEvent );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLockZoom( int var1 ) {
|
||||
if ( checkMapView() ) {
|
||||
if ( DebugConfig.isDebug() ) {
|
||||
Logger.d( TAG, Log.getStackTraceString( new Throwable() ) );
|
||||
}
|
||||
Logger.d( TAG, "Zoom锁定锁车比例尺 %s", var1 );
|
||||
// mMapView.setLockZoom( var1 );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayOverview( Rect bounds ) {
|
||||
if ( checkMapView() ) {
|
||||
if ( NaviClient.getInstance( getContext() ).isNaviing() ) {
|
||||
loseLockMode();
|
||||
NaviClient.getInstance( getContext() ).displayOverview( bounds );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getScalePerPixel() {
|
||||
return getMap().getScalePerPixel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getZoomLevel() {
|
||||
return getMap().getZoomLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNaviStarted() {
|
||||
if ( checkMapView() ) {
|
||||
showMyLocation( false );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNaviStopped() {
|
||||
if ( checkMapView() ) {
|
||||
showMyLocation( true );
|
||||
NaviClient.getInstance( getContext() ).startAimlessMode();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNaviInfoUpdat( NaviInfo naviInfo ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCalculateSuccess() {
|
||||
loseLockMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCameraChange( CameraPosition cameraPosition ) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCameraChangeFinish( CameraPosition cameraPosition ) {
|
||||
if ( cameraPosition != null ) {
|
||||
Trace.beginSection( "timer.onCameraChangeFinish" );
|
||||
MogoMapListenerHandler.getInstance().onMapChanged( ObjectUtils.fromAMap( cameraPosition.target ),
|
||||
cameraPosition.zoom,
|
||||
cameraPosition.tilt,
|
||||
cameraPosition.bearing );
|
||||
Trace.endSection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MogoLatLng getCameraNorthEastPosition() {
|
||||
try {
|
||||
return ObjectUtils.fromAMap( mMapView.getMap().getProjection().getVisibleRegion().latLngBounds.northeast );
|
||||
} catch ( Exception e ) {
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MogoLatLng getCameraSouthWestPosition() {
|
||||
try {
|
||||
return ObjectUtils.fromAMap( mMapView.getMap().getProjection().getVisibleRegion().latLngBounds.southwest );
|
||||
} catch ( Exception e ) {
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MogoLatLng getWindowCenterLocation() {
|
||||
try {
|
||||
return ObjectUtils.fromAMap( mMapView.getMap().getCameraPosition().target );
|
||||
} catch ( Exception e ) {
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPointToCenter( double mapCenterX, double mapCenterY ) {
|
||||
if ( checkMapView() ) {
|
||||
if ( DebugConfig.isDebug() ) {
|
||||
Logger.d( TAG, Log.getStackTraceString( new Throwable() ) );
|
||||
}
|
||||
Logger.d( TAG, "setPointToCenter(%s, %s)", mapCenterX, mapCenterY );
|
||||
mMapView.getMap().setPointToCenter( ( ( int ) ( mapCenterX * WindowUtils.getScreenWidth( getContext() ) ) ),
|
||||
( ( int ) ( mapCenterY * WindowUtils.getScreenHeight( getContext() ) ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point getLocationPointInScreen( MogoLatLng latLng ) {
|
||||
if ( checkMapView() ) {
|
||||
try {
|
||||
return mMapView.getMap()
|
||||
.getProjection()
|
||||
.toScreenLocation( ObjectUtils.fromMogo2( latLng ) );
|
||||
} catch ( Exception e ) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MogoLatLng getLocationMogoLatLngInScreen( Point point ) {
|
||||
if ( checkMapView() ) {
|
||||
try {
|
||||
return ObjectUtils.fromAMap(
|
||||
mMapView.getMap().getProjection().fromScreenLocation( point ) );
|
||||
} catch ( Exception e ) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startJumpAnimation( IMogoMarker marker, float high, Interpolator interpolator,
|
||||
long duration ) {
|
||||
if ( marker == null || high <= 0.0f || interpolator == null || duration < 0 ) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
final LatLng latLng = ObjectUtils.fromMogo2( marker.getPosition() );
|
||||
Point point = mMapView.getMap().getProjection().toScreenLocation( latLng );
|
||||
point.y -= WindowUtils.dip2px( getContext(), high );
|
||||
LatLng target = mMapView.getMap().getProjection().fromScreenLocation( point );
|
||||
//使用TranslateAnimation,填写一个需要移动的目标点
|
||||
Animation animation = new TranslateAnimation( target );
|
||||
animation.setInterpolator( interpolator );
|
||||
//整个移动所需要的时间
|
||||
animation.setDuration( duration );
|
||||
//设置动画
|
||||
if ( marker instanceof AMapMarkerWrapper ) {
|
||||
( ( AMapMarkerWrapper ) marker ).getMarker().setAnimation( animation );
|
||||
( ( AMapMarkerWrapper ) marker ).getMarker().startAnimation();
|
||||
}
|
||||
} catch ( Exception e ) {
|
||||
Logger.e( TAG, e, "error." );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRenderFps( int fps ) {
|
||||
if ( checkMapView() ) {
|
||||
if ( mMapView.getMap() != null ) {
|
||||
mMapView.getMap().setRenderFps( fps );
|
||||
Logger.d( TAG, "设置刷新帧率 fps = %s", fps );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showBounds( String tag, MogoLatLng carPosition, List< MogoLatLng > lonLats, Rect bound, boolean lockCarPosition ) {
|
||||
if ( !checkMapView() ) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if ( DebugConfig.isDebug() ) {
|
||||
Logger.d( TAG, Log.getStackTraceString( new Throwable() ) );
|
||||
}
|
||||
LatLngBounds latLngBounds = MogoMapUtils.getLatLngBounds( carPosition, lonLats, lockCarPosition );
|
||||
if ( !lockCarPosition ) {
|
||||
loseLockMode();
|
||||
}
|
||||
mMapView.getMap().moveCamera( CameraUpdateFactory.newLatLngBoundsRect( latLngBounds, bound.left, bound.right, bound.top, bound.bottom ) );
|
||||
} catch ( Exception e ) {
|
||||
Logger.e( TAG, e, "%s error.", tag );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forceRender() {
|
||||
if ( checkMapView() ) {
|
||||
mMapView.getMap().runOnDrawFrame();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float calculateLineDistance( MogoLatLng p1, MogoLatLng p2 ) throws Exception {
|
||||
if ( p1 == null || p2 == null ) {
|
||||
throw new Exception( "计算距离的点不能为 null" );
|
||||
}
|
||||
return AMapUtils.calculateLineDistance( ObjectUtils.fromMogo2( p1 ), ObjectUtils.fromMogo2( p2 ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMyLocationChange( Location location ) {
|
||||
NaviClient.getInstance( getContext() ).syncCarLocation( location );
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumMapUI getCurrentUiMode() {
|
||||
return mCurrentUIMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeMyLocation( Location location ) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean isCarLocked() {
|
||||
return mIsCarLocked;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCarCursorOption( CarCursorOption option ) {
|
||||
if ( mCarCursorOption != null && mCarCursorOption != DEFAULT_OPTION ) {
|
||||
mCarCursorOption.destroy();
|
||||
}
|
||||
if ( option != null ) {
|
||||
try {
|
||||
mCarCursorOption = option.clone();
|
||||
} catch ( Exception e ) {
|
||||
mCarCursorOption = DEFAULT_OPTION;
|
||||
}
|
||||
} else {
|
||||
mCarCursorOption = DEFAULT_OPTION;
|
||||
}
|
||||
if ( !checkMapView() ) {
|
||||
return;
|
||||
}
|
||||
if ( mMapView.getMap() == null ) {
|
||||
return;
|
||||
}
|
||||
MyLocationStyle style = 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() ) );
|
||||
} else {
|
||||
style.myLocationIcon( BitmapDescriptorFactory.fromResource( DEFAULT_OPTION.getCarCursorRes() ) );
|
||||
}
|
||||
}
|
||||
mMapView.getMap().setMyLocationStyle( style );
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapCameraPosition getMapCameraPosition() {
|
||||
if ( checkMapView() ) {
|
||||
CameraPosition cameraPosition = mMapView.getMap().getCameraPosition();
|
||||
return ObjectUtils.fromAMap( cameraPosition );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeBearing( float bearing ) {
|
||||
if ( checkMapView() ) {
|
||||
mMapView.getMap().moveCamera( CameraUpdateFactory.changeBearing( bearing ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,15 +37,15 @@ public class AMapWrapper implements IMogoMap {
|
||||
private static final String TAG = "AMapWrapper";
|
||||
|
||||
private static AMap sAMap;
|
||||
private final Context mContext;
|
||||
private IMogoMapUIController mUIcontroller;
|
||||
private AMap mAMap;
|
||||
private AMapNaviView mMapView;
|
||||
private IMogoUiSettings mUiSettings;
|
||||
|
||||
public AMapWrapper( AMap map, AMapNaviView mapView, IMogoMapUIController controller ) {
|
||||
public AMapWrapper( AMap map, Context context, IMogoMapUIController controller ) {
|
||||
this.mAMap = map;
|
||||
sAMap = map;
|
||||
this.mMapView = mapView;
|
||||
mContext = context;
|
||||
mUIcontroller = controller;
|
||||
// 设置实现自定义 info window
|
||||
mAMap.setInfoWindowAdapter( new AMapInfoWindowAdapter() );
|
||||
@@ -56,6 +56,10 @@ public class AMapWrapper implements IMogoMap {
|
||||
return sAMap;
|
||||
}
|
||||
|
||||
public static void release(){
|
||||
sAMap = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoUiSettings getUiSettings() {
|
||||
if ( !checkAMap() ) {
|
||||
@@ -248,6 +252,6 @@ public class AMapWrapper implements IMogoMap {
|
||||
}
|
||||
|
||||
private Context getContext() {
|
||||
return mMapView.getContext();
|
||||
return mContext;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
package com.mogo.map.impl.amap.hook;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.amap.api.maps.AMap;
|
||||
import com.autonavi.amap.mapcore.interfaces.IAMap;
|
||||
import com.autonavi.base.ae.gmap.GLMapEngine;
|
||||
import com.autonavi.base.amap.api.mapcore.IAMapDelegate;
|
||||
import com.autonavi.base.amap.mapcore.interfaces.IAMapListener;
|
||||
import com.mogo.map.impl.amap.navi.NaviClient;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
@@ -23,13 +21,12 @@ import java.lang.reflect.Proxy;
|
||||
public class BnHooker implements InvocationHandler {
|
||||
|
||||
private static final String TAG = "BnHooker";
|
||||
private final Context mContext;
|
||||
|
||||
private Object host;
|
||||
private Method getGLMapEngineMethod;
|
||||
private GLMapEngine glMapEngineObject;
|
||||
|
||||
public BnHooker( AMap map, Context context ) throws Exception {
|
||||
|
||||
mContext = context;
|
||||
public BnHooker( AMap map ) throws Exception {
|
||||
|
||||
if ( map == null ) {
|
||||
return;
|
||||
@@ -48,6 +45,28 @@ public class BnHooker implements InvocationHandler {
|
||||
this
|
||||
);
|
||||
field.set( map, object );
|
||||
|
||||
}
|
||||
|
||||
public void clearAllMessages() throws Exception {
|
||||
if ( glMapEngineObject == null ) {
|
||||
if ( getGLMapEngineMethod == null ) {
|
||||
getGLMapEngineMethod = host.getClass().getDeclaredMethod( "getGLMapEngine" );
|
||||
getGLMapEngineMethod.setAccessible( true );
|
||||
}
|
||||
glMapEngineObject = ( GLMapEngine ) getGLMapEngineMethod.invoke( host );
|
||||
}
|
||||
if ( glMapEngineObject != null ) {
|
||||
clearMessageList( "mStateMessageList", glMapEngineObject );
|
||||
clearMessageList( "mAnimateStateMessageList", glMapEngineObject );
|
||||
}
|
||||
}
|
||||
|
||||
private void clearMessageList( String filedName, Object obj ) throws Exception {
|
||||
Field stateMessageListField = obj.getClass().getDeclaredField( filedName );
|
||||
stateMessageListField.setAccessible( true );
|
||||
List valList = ( List ) stateMessageListField.get( obj );
|
||||
valList.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -145,7 +145,7 @@ public class ALocationClient implements IMogoLocationClient {
|
||||
synchronized ( sListeners ) {
|
||||
Iterator< IMogoLocationListener > listenerIterator = sListeners.iterator();
|
||||
while ( listenerIterator.hasNext() ) {
|
||||
listenerIterator.next().onLocationChanged( mLastLocation.clone() );
|
||||
listenerIterator.next().onLocationChanged( mLastLocation );
|
||||
}
|
||||
}
|
||||
Trace.endSection();
|
||||
|
||||
@@ -82,8 +82,8 @@ public class AMapMarkerWrapper implements IMogoMarker, Observer {
|
||||
mMogoMarkerOptions = null;
|
||||
}
|
||||
if ( mMarker != null ) {
|
||||
mMarker.remove();
|
||||
mMarker.setObject( null );
|
||||
mMarker.remove();
|
||||
mMarker = null;
|
||||
}
|
||||
if ( mMovingPointOverlay != null ) {
|
||||
@@ -398,7 +398,7 @@ public class AMapMarkerWrapper implements IMogoMarker, Observer {
|
||||
|
||||
AnimationSet animationSet = new AnimationSet( true );
|
||||
animationSet.setDuration( duration );
|
||||
animationSet.setInterpolator( interpolator);
|
||||
animationSet.setInterpolator( interpolator );
|
||||
animationSet.setAnimationListener( new Animation.AnimationListener() {
|
||||
@Override
|
||||
public void onAnimationStart() {
|
||||
@@ -510,4 +510,11 @@ public class AMapMarkerWrapper implements IMogoMarker, Observer {
|
||||
mMovingPointOverlay.startSmoothMove();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInfoWindowShowing() {
|
||||
if ( mMarker == null ) {
|
||||
return false;
|
||||
}
|
||||
return mMarker.isInfoWindowShown();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,12 @@ public class AMapMessageManager {
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void clear(){
|
||||
if ( mListeners != null ) {
|
||||
mListeners.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void unregisterAMapMessageListener( AMapMessageListener listener ) {
|
||||
mListeners.remove( listener );
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public class NaviClient implements IMogoNavi {
|
||||
private boolean mAimlessStatus;
|
||||
|
||||
private NaviClient( Context context ) {
|
||||
mContext = context;
|
||||
mContext = context.getApplicationContext();
|
||||
if ( DebugConfig.isUseCustomNavi() ) {
|
||||
// 按需初始化导航组件
|
||||
initAMapNavi();
|
||||
|
||||
@@ -4,7 +4,6 @@ import android.text.TextUtils;
|
||||
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.commons.voice.AIAssist;
|
||||
import com.mogo.commons.voice.IMogoVoiceCmdCallBack;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
@@ -16,7 +15,7 @@ import java.util.LinkedList;
|
||||
* <p>
|
||||
* 策略:队列缓存预播报的 tts,然后上一句播完后
|
||||
*/
|
||||
public class TTSSpeaker implements IMogoVoiceCmdCallBack {
|
||||
public class TTSSpeaker {
|
||||
|
||||
private static volatile TTSSpeaker sInstance;
|
||||
|
||||
@@ -48,7 +47,6 @@ public class TTSSpeaker implements IMogoVoiceCmdCallBack {
|
||||
return;
|
||||
}
|
||||
mWaiting.add( tts );
|
||||
peekAndSpeak();
|
||||
}
|
||||
|
||||
public synchronized void shutUp() {
|
||||
@@ -60,61 +58,5 @@ public class TTSSpeaker implements IMogoVoiceCmdCallBack {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCmdSelected( String cmd ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCmdAction( String speakText ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCmdCancel( String speakText ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSpeakEnd( String speakText ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSpeakSelectTimeOut( String speakText ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTTSStart( String ttsId, String tts ) {
|
||||
if ( TextUtils.equals( mLastTts, tts ) ) {
|
||||
mLastTtsId = ttsId;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTTSEnd( String ttsId, String tts ) {
|
||||
mLastTtsId = null;
|
||||
peekAndSpeak();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTTSError( String ttsId, String tts ) {
|
||||
mLastTtsId = null;
|
||||
peekAndSpeak();
|
||||
}
|
||||
|
||||
private synchronized void peekAndSpeak() {
|
||||
if ( mWaiting.isEmpty() ) {
|
||||
mLastTts = null;
|
||||
mLastTtsId = null;
|
||||
return;
|
||||
}
|
||||
if ( mLastTtsId != null ) {
|
||||
// 上一句还没有播完
|
||||
return;
|
||||
}
|
||||
mLastTts = mWaiting.pop();
|
||||
AIAssist.getInstance( AbsMogoApplication.getApp() ).speakTTSAndDuck( mLastTts, this );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ public class AMapUIController implements IMogoMapUIController {
|
||||
}
|
||||
|
||||
public synchronized void release() {
|
||||
mClient = null;
|
||||
sInstance = null;
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 33 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 33 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 22 KiB |
Reference in New Issue
Block a user