This commit is contained in:
wangcongtao
2020-10-22 14:17:12 +08:00
1425 changed files with 31249 additions and 12020 deletions

View File

@@ -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;
}
}

View File

@@ -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() ) {

View File

@@ -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;
}
}

View File

@@ -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 ) );
}
}
}

View File

@@ -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;
}
}

View File

@@ -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

View File

@@ -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();

View File

@@ -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();
}
}

View File

@@ -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 );
}

View File

@@ -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();

View File

@@ -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 );
}
}

View File

@@ -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

View File

@@ -6,6 +6,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.text.TextUtils;
import com.mogo.commons.storage.SpStorage;
import com.mogo.map.impl.amap.utils.IconTypeUtils;
import com.mogo.map.navi.MogoNaviInfo;
import com.mogo.map.navi.MogoNaviListenerHandler;
@@ -26,6 +27,9 @@ public class AutoNaviReceiver extends BroadcastReceiver {
private static AutoNaviReceiver autoNaviReceiver;
private static boolean sRegisterFlag = false;
private static MogoNaviInfo sNaviInfo;
private static MogoTraffic sTraffic;
public static void register( Context context ) {
IntentFilter filter = new IntentFilter();
@@ -63,6 +67,11 @@ public class AutoNaviReceiver extends BroadcastReceiver {
int state = intent.getIntExtra( "EXTRA_STATE", -1 );
handleMapStatusChanged( state );
break;
case 10056:
String json = intent.getStringExtra( "EXTRA_ROAD_INFO" );
SpStorage.setNavigationTarget(json);
Logger.d( TAG, json );
break;
}
}
@@ -85,23 +94,28 @@ public class AutoNaviReceiver extends BroadcastReceiver {
MapState.getInstance().setNaving( true );
MogoNaviListenerHandler.getInstance().onStartNavi();
}
MogoNaviInfo naviInfo = new MogoNaviInfo();
naviInfo.setCurrentLimitSpeed( cameraSpeed );
naviInfo.setCurrentRoadName( intent.getStringExtra( GuideInfoExtraKey.CUR_ROAD_NAME ) );
naviInfo.setCurrentSpeed( intent.getIntExtra( GuideInfoExtraKey.CUR_SPEED, 0 ) );
naviInfo.setCurStepRetainDistance( intent.getIntExtra( GuideInfoExtraKey.SEG_REMAIN_DIS, 0 ) );
naviInfo.setCurStepRetainTime( intent.getIntExtra( GuideInfoExtraKey.SEG_REMAIN_TIME, 0 ) );
naviInfo.setIconResId( IconTypeUtils.getResIdByIconType( context, intent.getIntExtra( GuideInfoExtraKey.NEW_ICON, 0 ) ) );
naviInfo.setNextRoadName( intent.getStringExtra( GuideInfoExtraKey.NEXT_ROAD_NAME ) );
naviInfo.setPathRetainDistance( intent.getIntExtra( GuideInfoExtraKey.ROUTE_REMAIN_DIS, 0 ) );
naviInfo.setPathRetainTime( intent.getIntExtra( GuideInfoExtraKey.ROUTE_REMAIN_TIME, 0 ) );
MogoNaviListenerHandler.getInstance().onNaviInfoUpdate( naviInfo );
if ( sNaviInfo == null ) {
sNaviInfo = new MogoNaviInfo();
}
sNaviInfo.setCurrentLimitSpeed( cameraSpeed );
sNaviInfo.setCurrentRoadName( intent.getStringExtra( GuideInfoExtraKey.CUR_ROAD_NAME ) );
sNaviInfo.setCurrentSpeed( intent.getIntExtra( GuideInfoExtraKey.CUR_SPEED, 0 ) );
sNaviInfo.setCurStepRetainDistance( intent.getIntExtra( GuideInfoExtraKey.SEG_REMAIN_DIS, 0 ) );
sNaviInfo.setCurStepRetainTime( intent.getIntExtra( GuideInfoExtraKey.SEG_REMAIN_TIME, 0 ) );
sNaviInfo.setIconResId( IconTypeUtils.getResIdByIconType( context, intent.getIntExtra( GuideInfoExtraKey.NEW_ICON, 0 ) ) );
sNaviInfo.setNextRoadName( intent.getStringExtra( GuideInfoExtraKey.NEXT_ROAD_NAME ) );
sNaviInfo.setPathRetainDistance( intent.getIntExtra( GuideInfoExtraKey.ROUTE_REMAIN_DIS, 0 ) );
sNaviInfo.setPathRetainTime( intent.getIntExtra( GuideInfoExtraKey.ROUTE_REMAIN_TIME, 0 ) );
MogoNaviListenerHandler.getInstance().onNaviInfoUpdate( sNaviInfo );
}
MogoTraffic mogoTraffic = new MogoTraffic( MapState.getInstance().isAimless() ? MogoTraffic.TYPE_AIM : MogoTraffic.TYPE_NAVI );
mogoTraffic.setDistance( cameraDisc );
mogoTraffic.setSpeedLimit( cameraSpeed );
mogoTraffic.setTrafficType( cameraType );
MogoNaviListenerHandler.getInstance().onUpdateTraffic2( mogoTraffic );
if ( sTraffic == null ) {
sTraffic = new MogoTraffic( MapState.getInstance().isAimless() ? MogoTraffic.TYPE_AIM : MogoTraffic.TYPE_NAVI );
}
sTraffic.setFromType( MapState.getInstance().isAimless() ? MogoTraffic.TYPE_AIM : MogoTraffic.TYPE_NAVI );
sTraffic.setDistance( cameraDisc );
sTraffic.setSpeedLimit( cameraSpeed );
sTraffic.setTrafficType( cameraType );
MogoNaviListenerHandler.getInstance().onUpdateTraffic2( sTraffic );
}
/**
@@ -118,6 +132,7 @@ public class AutoNaviReceiver extends BroadcastReceiver {
case MapStateValue.START_NAVI:
case MapStateValue.START_EMULATOR_NAVI:
if ( MapState.getInstance().isNaving() ) {
Logger.w( TAG, "naving..." );
return;
}
MapState.getInstance().setNaving( true );

View File

@@ -1,7 +1,6 @@
package com.mogo.map.impl.custom;
import android.content.Context;
import android.util.Log;
import com.mogo.map.IMogoMapView;
import com.mogo.map.IMogoMapViewCreator;
@@ -23,11 +22,11 @@ public class AMapBaseMapView 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( false )
.setCoordinateType( MapParams.COORDINATETYPE_GCJ02 )
.setPerspectiveMode( MapParams.MAP_PERSPECTIVE_2D )
.setZoom( 16 )
.setPointToCenter(0.5f,0.5f)
.setPointToCenter( 0.5f, 0.5f )
.setStyleMode( MapParams.MAP_STYLE_NIGHT ) );
mapAutoView = new MapAutoView( context );
return new AMapViewWrapper( mapAutoView );

View File

@@ -1,886 +0,0 @@
//package com.mogo.map.impl.custom;
//
//import android.content.Context;
//import android.graphics.BitmapFactory;
//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.mogo.commons.debug.DebugConfig;
//import com.mogo.map.IMogoMap;
//import com.mogo.map.IMogoMapView;
//import com.mogo.map.MogoLatLng;
//import com.mogo.map.impl.custom.hook.BnHooker;
//import com.mogo.map.impl.custom.marker.AMapMarkerWrapper;
//import com.mogo.map.impl.custom.message.AMapMessageListener;
//import com.mogo.map.impl.custom.message.AMapMessageManager;
//import com.mogo.map.impl.custom.navi.NaviClient;
//import com.mogo.map.impl.custom.utils.MogoMapUtils;
//import com.mogo.map.impl.custom.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.WindowUtils;
//import com.mogo.utils.logger.Logger;
//import com.zhidaoauto.map.sdk.open.MapParams;
//import com.zhidaoauto.map.sdk.open.camera.CameraUpdate;
//import com.zhidaoauto.map.sdk.open.location.LocationListener;
//import com.zhidaoauto.map.sdk.open.location.MyLocationStyle;
//import com.zhidaoauto.map.sdk.open.tools.MapTools;
//import com.zhidaoauto.map.sdk.open.view.MapAutoView;
//import com.zhidaoauto.map.sdk.open.view.MapAutoViewHelper;
//
//import org.jetbrains.annotations.NotNull;
//
//import java.util.List;
//
///**
// * @author congtaowang
// * @since 2019-12-18
// * <p>
// * 代理自研导航地图
// */
//public class AMapNaviViewWrapper implements IMogoMapView,
// IMogoMapUIController,
// OnMarkClickListener,
//// AMap.OnMapLoadedListener,
//// AMap.OnMapTouchListener,
//// AMap.OnPOIClickListener,
//// AMap.OnMapClickListener,
//// AMap.OnPolylineClickListener,
//// AMapNaviViewListener,
//// AMapMessageListener,
//// AMap.OnCameraChangeListener,
// LocationListener {
//
// private static final String TAG = "AMapNaviViewWrapper";
//
// private final MapAutoView 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 AMapNaviViewWrapper( MapAutoView mapView ) {
// this.mMapView = mapView;
// this.mIMap = new AMapWrapper( mMapView.getMapAutoViewHelper(), mMapView, this );
// try {
// new BnHooker( mMapView.getMapAutoViewHelper(), mapView.getContext() );
// } catch ( Exception e ) {
// e.printStackTrace();
// }
// }
//
// private void initMapView() {
// if ( mMapView == null ) {
// return;
// }
// MapAutoViewHelper options = mMapView.getMapAutoViewHelper();
// 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.hiddenDirection();
// // 黑夜模式
// options.setMapStyle(MapParams.MAP_STYLE_NIGHT);
// //设置路况光柱条是否显示(只适用于驾车导航,需要联网)。
//// options.setTrafficBarEnabled( false );
// // 设置[实时交通图层开关按钮]是否显示(只适用于驾车导航,需要联网)。
//// options.setTrafficLayerEnabled( false );
// // 设置导航界面是否显示路线全览按钮。
//// options.setRouteListButtonShow( false );
// // 设置导航状态下屏幕是否一直开启。
//// options.setScreenAlwaysBright( true );
// // 设置交通播报是否打开(只适用于驾车导航,需要联网)。
//// 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.5D, 0.5D );
// // 2D模式
// options.setTilt( 0 );
// mMapView.setViewOptions( options );
// }
// mMapView.setRouteOverlayVisible( false );
// mMapView.setCarOverlayVisible( false );
// setUIMode( EnumMapUI.CarUp_2D, null );
// }
//
// private void initListeners() {
//
// mMapView.setOnMarkerClickListener( this );
// mMarkerClickHandler = new AMapMarkerClickHandler();
// mMapView.setOnMapLoadedListener( this );
// mMapView.setOnMapTouchListener( this );
// mMapView.setOnPolylineClickListener( this );
// mMapView.setAMapNaviViewListener( this );
// mMapView.setOnCameraChangeListener( this );
//
// final AMap aMap = mMapView.getMap();
// if ( aMap != null ) {
// aMap.setOnPOIClickListener( this );
// aMap.setOnMapClickListener( this );
// aMap.setOnCameraChangeListener( this );
// aMap.setOnMyLocationChangeListener( this );
// }
// 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 ) {
// 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, "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();
// 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() {
// 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 );
// }
//
// /**
// * 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 onNaviSetting() {
//
// }
//
// @Override
// public void onNaviCancel() {
//
// }
//
// @Override
// public boolean onNaviBackClick() {
// return true;
// }
//
// /**
// * @param mode 0:车头朝上状态1:正北朝上模式
// */
// @Override
// public void onNaviMapMode( int mode ) {
// Logger.i( TAG, "mode=" + mode );
// }
//
// @Override
// public void onNaviTurnClick() {
//
// }
//
// @Override
// public void onNextRoadClick() {
//
// }
//
// @Override
// public void onScanViewButtonClick() {
//
// }
//
// @Override
// public void onLockMap( boolean isLock ) {
// Logger.d( TAG, "lock status = %s", isLock );
// mIsCarLocked = isLock;
// Trace.beginSection( "timer.onCameraChangeFinish" );
// MogoMapListenerHandler.getInstance().onLockMap( isLock );
// Trace.endSection();
// }
//
// @Override
// public void onNaviViewLoaded() {
//
// }
//
// @Override
// public void onMapTypeChanged( int type ) {
// if ( type == 4 ) {
// MogoMapListenerHandler.getInstance().onMapModeChanged( EnumMapUI.Type_Light );
// } else if ( type == 3 ) {
// MogoMapListenerHandler.getInstance().onMapModeChanged( EnumMapUI.Type_Night );
// }
// }
//
// @Override
// public void onNaviViewShowMode( int i ) {
//
// long delay = mMapView.getViewOptions().getLockMapDelayed();
// switch ( i ) {
// case AMapNaviViewShowMode.SHOW_MODE_DEFAULT:
// Logger.d( TAG, "普通模式" );
// break;
// case AMapNaviViewShowMode.SHOW_MODE_DISPLAY_OVERVIEW:
// Logger.d( TAG, "全览模式" );
// break;
// case AMapNaviViewShowMode.SHOW_MODE_LOCK_CAR:
// Logger.d( TAG, "锁车模式: %s", delay );
// break;
// }
// }
//
// @Override
// public void setTrafficEnabled( boolean visible ) {
// if ( checkAMapView() ) {
// mMapView.setTrafficLine( visible );
// }
// }
//
// @Override
// public MapControlResult changeZoom( boolean zoom ) {
// if ( checkAMapView() ) {
// 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 ( checkAMapView() ) {
// AMapNaviViewOptions options = mMapView.getViewOptions();
// if ( options == null ) {
// options = new AMapNaviViewOptions();
// }
// switch ( ui ) {
// case CarUp_2D:
// case CarUp_3D:
// case NorthUP_2D:
// setUIMode( ui, options );
// return;
// case Type_Light:
// options.setNaviNight( false );
// break;
// case Type_Night:
// options.setNaviNight( true );
// break;
// case Type_AUTO_LIGHT_Night:
// options.setNaviNight( false );
// options.setAutoNaviViewNightMode( true );
// break;
// }
// mMapView.setViewOptions( options );
// }
// }
//
// private void setUIMode( EnumMapUI ui, AMapNaviViewOptions options ) {
// this.mCurrentUIMode = ui;
// switch ( ui ) {
// case CarUp_2D:
// case CarUp_3D:
// mMapView.setNaviMode( AMapNaviView.CAR_UP_MODE );
// break;
// case NorthUP_2D:
// mMapView.setNaviMode( AMapNaviView.NORTH_UP_MODE );
// break;
// }
//
// Logger.d( TAG, "mCurrentUIMode--->" + mCurrentUIMode.name() );
// if ( options == null ) {
// return;
// }
// switch ( ui ) {
// case CarUp_2D:
// case NorthUP_2D:
// options.setTilt( 0 );
// break;
// case CarUp_3D:
// options.setTilt( 60 );
// break;
// }
// }
//
// private boolean checkAMapView() {
// if ( mMapView == 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 ( checkAMapView() ) {
// MyLocationStyle style = mMapView.getMap().getMyLocationStyle();
// 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 ( checkAMapView() ) {
// MyLocationStyle style = mMapView.getMap().getMyLocationStyle();
// style.showMyLocation( true );
// style.myLocationIcon( BitmapDescriptorFactory.fromView( view ) );
// 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 );
// style.interval( 1000 );
// style.anchor( 0.5F, 0.5F );
// style.strokeColor( Color.TRANSPARENT );
// style.strokeWidth( 0 );
// style.radiusFillColor( Color.TRANSPARENT );
// mMapView.getMap().setMyLocationStyle( style );
// }
// }
//
// @Override
// public void recoverLockMode() {
// if ( checkAMapView() ) {
// if ( DebugConfig.isDebug() ) {
// Logger.d( TAG, Log.getStackTraceString( new Throwable() ) );
// }
// Logger.d( TAG, "锁车" );
// mMapView.recoverLockMode();
// mIsCarLocked = true;
// }
// }
//
// @Override
// public void loseLockMode() {
// if ( DebugConfig.isDebug() ) {
// Logger.d( TAG, Log.getStackTraceString( new Throwable() ) );
// }
// Logger.d( TAG, "解锁锁车" );
// mockTouchEvent();
// 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 ( checkAMapView() ) {
// 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 ( checkAMapView() ) {
// 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 ( checkAMapView() ) {
// mMapView.setCarOverlayVisible( true );
// showMyLocation( false );
// }
// }
//
// @Override
// public void onNaviStopped() {
// if ( checkAMapView() ) {
// mMapView.setCarOverlayVisible( false );
// 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 ( checkAMapView() ) {
// if ( DebugConfig.isDebug() ) {
// Logger.d( TAG, Log.getStackTraceString( new Throwable() ) );
// }
// Logger.d( TAG, "setPointToCenter(%s, %s)", mapCenterX, mapCenterY );
//// AMapNaviViewOptions options = mMapView.getViewOptions();
//// options.setPointToCenter( mapCenterX, mapCenterY );
//// mMapView.setViewOptions( options );
// }
// }
//
// @Override
// public Point getLocationPointInScreen( MogoLatLng latLng ) {
// if ( checkAMapView() ) {
// try {
// return MapTools.INSTANCE.toScreenLocation( ObjectUtils.fromMogo( latLng ) );
// } catch ( Exception e ) {
// return null;
// }
// }
// return null;
// }
//
// @Override
// public MogoLatLng getLocationMogoLatLngInScreen( Point point ) {
// if ( checkAMapView() ) {
// try {
// return ObjectUtils.fromAMap(
// MapTools.INSTANCE.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 ( checkAMapView() ) {
// if ( mMapView.getMapAutoViewHelper() != null ) {
//// mMapView.getMapAutoViewHelper().setRenderFps( fps );
// Logger.d( TAG, "设置刷新帧率 fps = %s", fps );
// }
// }
// }
//
// @Override
// public void showBounds( String tag, MogoLatLng carPosition, List< MogoLatLng > lonLats, Rect bound, boolean lockCarPosition ) {
// if ( !checkAMapView() ) {
// return;
// }
// try {
//// if ( DebugConfig.isDebug() ) {
//// Logger.d( TAG, Log.getStackTraceString( new Throwable() ) );
//// }
//// LatLngBounds latLngBounds = MogoMapUtils.getLatLngBounds( carPosition, lonLats, lockCarPosition );
//// if ( !lockCarPosition ) {
//// loseLockMode();
//// }
//// mMapView.getMapAutoViewHelper().moveCamera( new CameraUpdate(new MapCameraMessage( 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() ) {
// mMapView.getMapAutoViewHelper().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 ( !checkAMapView() ) {
// return;
// }
//// AMapNaviViewOptions options = mMapView.getViewOptions();
//// if ( options != null && mCarCursorOption.getNaviCursorRes() != 0 ) {
//// options.setCarBitmap( BitmapFactory.decodeResource( getContext().getResources(), mCarCursorOption.getNaviCursorRes() ) );
//// } else {
//// options.setCarBitmap( BitmapFactory.decodeResource( getContext().getResources(), DEFAULT_OPTION.getNaviCursorRes() ) );
//// }
//// mMapView.setViewOptions( options );
//
// if ( mMapView.getMapAutoViewHelper() == null ) {
// return;
// }
// MyLocationStyle style = mMapView.getMapAutoViewHelper().getMyLocationStyle();
// if ( mCarCursorOption.getCarCursorBmp() != null && !mCarCursorOption.getCarCursorBmp().isRecycled() ) {
//// style.myLocationIcon( BitmapDescriptorFactory.fromBitmap( mCarCursorOption.getCarCursorBmp() ) );
// } else {
// if ( mCarCursorOption.getCarCursorRes() != 0 ) {
// style.myLocationIcon( mCarCursorOption.getCarCursorRes());
// } else {
// style.myLocationIcon( mCarCursorOption.getCarCursorRes());
// }
// }
// mMapView.getMapAutoViewHelper().setMyLocationStyle( style );
// }
//
// @Override
// public MapCameraPosition getMapCameraPosition() {
// if ( checkAMapView() ) {
//// CameraPosition cameraPosition = mMapView.getMap().getCameraPosition();
//// return ObjectUtils.fromAMap( cameraPosition );
// }
// return null;
// }
//
// @Override
// public void changeBearing( float bearing ) {
// if ( checkAMapView() ) {
//// mMapView.getMap().moveCamera( CameraUpdateFactory.changeBearing( bearing ) );
// }
// }
//
// @Override
// public void onLocationChanged(@NotNull com.zhidaoauto.map.sdk.open.location.Location 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);
// }
//}

View File

@@ -480,4 +480,9 @@ public class AMapMarkerWrapper implements IMogoMarker, Observer {
public void startScaleAnimationWithAlpha( float fromX, float toX, float fromY, float toY, float fromAlpha, float toAlpha, int duration, Interpolator interpolator, OnMarkerAnimationListener listener ) {
}
@Override
public boolean isInfoWindowShowing() {
return mMarker.isInfoWindowShown();
}
}

View File

@@ -0,0 +1,15 @@
package com.mogo.map;
import android.content.Context;
public
/**
* @author congtaowang
* @since 2020/9/10
*
* 描述
*/
interface IMogoMapViewInstanceHandler extends IDestroyable {
void createMapViewInstance( Context context );
}

View File

@@ -86,6 +86,7 @@ public abstract class MogoBaseMapView extends FrameLayout implements ILifeCycle
if ( mMapView != null ) {
mMapView.onDestroy();
}
MogoMap.getInstance().clear();
}
@Override

View File

@@ -46,4 +46,9 @@ public class MogoMap {
public IMogoMap getMogoMap() {
return mMap;
}
public void clear(){
mContext = null;
mMap = null;
}
}

View File

@@ -318,4 +318,10 @@ public interface IMogoMarker {
* @param duration 时长
*/
void startSmooth( List< MogoLatLng > points, int duration );
/**
* info window 是否正在显示
* @return
*/
boolean isInfoWindowShowing();
}

View File

@@ -10,6 +10,7 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* @author congtaowang
@@ -33,7 +34,7 @@ public class MogoMarkersHandler implements IMogoMarkerClickListener, IMogoMarker
return sInstance;
}
private Map< String, List< IMogoMarker > > mServicesMarkers = new HashMap<>();
private Map< String, List< IMogoMarker > > mServicesMarkers = new ConcurrentHashMap<>();
private MogoMarkersHandler() {
}

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

View File

@@ -66,12 +66,23 @@ class MogoMapDelegateFactory {
return AMapUIController.getInstance();
}
public static IMogoMapViewCreator getMapViewCreatorDelegate() {
private static IMogoMapView sMapView;
public static void createMapView( Context context ) {
if ( DebugConfig.isUseCustomMap() ) {
Logger.d( TAG, "use custom IMogoMapViewCreator" );
return new com.mogo.map.impl.custom.AMapBaseMapView();
sMapView = new com.mogo.map.impl.custom.AMapBaseMapView().create( context );
} else {
sMapView = new AMapBaseMapView().create( context );
}
return new AMapBaseMapView();
}
public static void destroy() {
sMapView = null;
}
public static IMogoMapView getMapView() {
return sMapView;
}
public static IMogoNavi getNaviDelegate( Context context ) {

View File

@@ -6,7 +6,6 @@ import android.util.AttributeSet;
import androidx.annotation.Nullable;
import com.mogo.map.impl.amap.AMapBaseMapView;
import com.mogo.utils.logger.Logger;
/**
@@ -18,6 +17,7 @@ import com.mogo.utils.logger.Logger;
public class MogoMapView extends MogoBaseMapView implements ILifeCycle {
private static final String TAG = "MogoMapView";
public MogoMapView( Context context ) {
super( context );
}
@@ -30,40 +30,40 @@ public class MogoMapView extends MogoBaseMapView implements ILifeCycle {
super( context, attrs, defStyleAttr );
}
@Override
protected IMogoMapView createMapView( Context context ) {
return MogoMapDelegateFactory.getMapViewCreatorDelegate().create( context );
}
@Override
public IMogoMap getMap() {
return super.getMap();
}
@Override
protected IMogoMapView createMapView( Context context ) {
MogoMapDelegateFactory.createMapView( context );
return MogoMapDelegateFactory.getMapView();
}
@Override
public void onCreate( Bundle bundle ) {
super.onCreate( bundle );
Logger.d(TAG,"onCreate");
Logger.d( TAG, "onCreate" );
}
@Override
public void onResume() {
super.onResume();
Logger.d(TAG,"onResume");
Logger.d( TAG, "onResume" );
}
@Override
public void onPause() {
super.onPause();
Logger.d(TAG,"onPause");
Logger.d( TAG, "onPause" );
}
@Override
public void onDestroy() {
super.onDestroy();
Logger.d(TAG,"onDestroy");
Logger.d( TAG, "onDestroy" );
}

View File

@@ -0,0 +1,49 @@
package com.mogo.map;
import android.content.Context;
import com.mogo.map.impl.amap.AMapViewHandler;
public
/**
* @author congtaowang
* @since 2020/9/10
*
* 描述
*/
class MogoMapViewInstanceHandler implements IMogoMapViewInstanceHandler {
private static volatile MogoMapViewInstanceHandler sInstance;
private MogoMapViewInstanceHandler(){}
public static MogoMapViewInstanceHandler getInstance(){
if( sInstance == null ){
synchronized( MogoMapViewInstanceHandler.class ) {
if( sInstance == null ){
sInstance = new MogoMapViewInstanceHandler();
}
}
}
return sInstance;
}
public synchronized void release(){
sInstance = null;
}
private Object readResolve() {
// 阻止反序列化,必须实现 Serializable 接口
return sInstance;
}
@Override
public void createMapViewInstance( Context context ) {
AMapViewHandler.createMapView( context );
}
@Override
public void destroy() {
AMapViewHandler.destroy();
}
}

View File

@@ -3,15 +3,10 @@ package com.zhidao.mogo.tanlu.api;
import android.content.Context;
import android.util.ArrayMap;
import androidx.annotation.NonNull;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.mogo.commons.analytics.AnalyticsUtils;
import com.mogo.service.IMogoServiceApis;
import com.mogo.service.MogoServicePaths;
import com.mogo.service.tanlu.IMogoTanluProvider;
import com.mogo.service.tanlu.TanluUploadParams;
import com.mogo.service.share.IMogoTanluProvider;
import com.mogo.service.share.TanluUploadParams;
import com.mogo.utils.logger.Logger;
import com.zhidao.roadcondition.service.MainService;
import com.zhidao.roadcondition.service.UploadParams;

View File

@@ -46,12 +46,11 @@ dependencies {
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.6.0'
implementation 'com.zhidaoauto.controller:api:1.0.8'
implementation 'com.zhidao.cosupload:cosuploadsdk:1.1.6'
implementation 'com.zhidao.cosupload:cosuploadsdk:1.1.6', {
exclude group: 'com.zhidao.utils', module: 'utils'
}
implementation 'com.zhidao.video:video-processor:1.0.2.1'
implementation 'com.foundation.utils:common-utils:1.0.7'
implementation rootProject.ext.dependencies.eventbus
compileOnly rootProject.ext.dependencies.mogocommons
implementation rootProject.ext.dependencies.eventbus
implementation rootProject.ext.dependencies.coroutinescore
implementation rootProject.ext.dependencies.coroutinesandroid
@@ -60,9 +59,16 @@ dependencies {
implementation rootProject.ext.dependencies.gson
implementation rootProject.ext.dependencies.rxjava
implementation rootProject.ext.dependencies.rxandroid
compileOnly rootProject.ext.dependencies.mogomap
implementation rootProject.ext.dependencies.aspectj
implementation rootProject.ext.dependencies.analytics
if (Boolean.valueOf(RELEASE)) {
compileOnly rootProject.ext.dependencies.mogocommons
compileOnly rootProject.ext.dependencies.mogomap
} else {
implementation project(':modules:mogo-module-common')
implementation project(':libraries:mogo-map')
}
}
apply from: new File(rootProject.rootDir, "gradle/upload.gradle").toString()

View File

@@ -68,6 +68,11 @@ const val UPLOAD_FROM_STRATEGY_CLOUD_CHECK = "4"
*/
const val UPLOAD_FROM_STRATEGY_ACCIDENT_AUTO = "5"
/**
* 策略上报集合
*/
val STRATEGY_UPLOAD_TYPE_ARRAY = arrayOf(UPLOAD_FROM_STRATEGY_BLOCK_AUTO,
UPLOAD_FROM_STRATEGY_CLOUD_CHECK, UPLOAD_FROM_STRATEGY_ACCIDENT_AUTO)
/**
* 默认视频抓取时长,单位是秒
*/

View File

@@ -108,7 +108,7 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
this.mLatitude = latitude
if (DebugConfig.getCarMachineType() == 0) { //自研车机
outputVideoPath = getCompressVideoPath()
CustomStatusHandler.offerVideoStatus(TakeEntity(isCustom, id))
CustomStatusHandler.offerVideoStatus(TakeEntity(isCustom, id,fromType))
zdCarCoderController.takeVideo(cameraId, duration)
trackGetVideo(1)
} else { //比亚迪
@@ -117,7 +117,7 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
// TipToast.shortTip("分享失败,请检查网络")
// } else {
//失败了,传空地址,发起请求
val entity = TakeEntity(isCustom, id)
val entity = TakeEntity(isCustom, id,fromType)
videoAndThumbMap["video"] = ""
videoAndThumbMap["thumb"] = ""
@@ -159,16 +159,16 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
val entity = TakeEntity(isCustom, 0L)
Log.e(TAG, "onTakePhotoFail -----mType = $mType --- isCustom = $isCustom")
//语音播报 1上报路况2交通检查3封路 默认 mType 应该为null
if (mType.equals(TANLU_ROAD_CONGESTION) || mType.equals(TANLU_TRAFFIC_CHECK) || mType.equals(
TANLU_ROAD_CLOSURE
)
|| mType.equals(TANLU_ROAD_CURRENT) || mType.equals(TANLU_ROAD_PONDING) || mType.equals(
TANLU_ROAD_ICING
)
|| mType.equals(TANLU_ROAD_HEAVY_FOG) || mType.equals(TANLU_ROAD_ACCIDENT) || mType.equals(
TANLU_ROAD_WORK
)
) {
// if (mType.equals(TANLU_ROAD_CONGESTION) || mType.equals(TANLU_TRAFFIC_CHECK) || mType.equals(
// TANLU_ROAD_CLOSURE
// )
// || mType.equals(TANLU_ROAD_CURRENT) || mType.equals(TANLU_ROAD_PONDING) || mType.equals(
// TANLU_ROAD_ICING
// )
// || mType.equals(TANLU_ROAD_HEAVY_FOG) || mType.equals(TANLU_ROAD_ACCIDENT) || mType.equals(
// TANLU_ROAD_WORK
// )
// ) {
taskAsync(1_500) {
try {
// VoiceController.speakVoice("上报失败")
@@ -190,9 +190,9 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
mainInfoId,
mLongitude,
mLatitude
);
)
}
}
// }
}
//拍照成功回调返回图片本地路径
@@ -271,6 +271,7 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
}
}
//获取视频成功
override fun onTakeVideoSuccess(camera: Int, videoPath: String?) {
var thumbnailPath =
@@ -282,8 +283,11 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
)
val entity = CustomStatusHandler.pollVideoStatus()
if (!entity?.isCustom) {
trackNormalEvent(CarNet_auto_upload_video, null)
entity?.let {
if (!entity.isCustom) {
trackNormalEvent(CarNet_auto_upload_video, null)
}
}
if (isSuccess) {
@@ -297,25 +301,30 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
)
var speed = LocationUtil.getInstance().getSpeed()
if (entity?.isCustom) {
compressVideo(videoPath, thumbnailPath, entity)
} else {
Log.d(
TAG,
"onTakeVideoSuccess maxSpeedVideo = $maxSpeedVideo --->speed= $speed + minSpeedVideo = $minSpeedVideo"
)
if (maxSpeedVideo == -1) {
Log.d(TAG, "onTakeVideoSuccess 111 abs =" + (Math.abs(minSpeedVideo) / 3.6f))
if (speed >= (Math.abs(minSpeedVideo) / 3.6f)) {
//获取视频以及缩略图成功,开始上报
compressVideo(videoPath, thumbnailPath, entity)
entity?.let {
if (entity.isCustom) {
compressVideo(videoPath, thumbnailPath, entity)
}else if (entity.fromType in STRATEGY_UPLOAD_TYPE_ARRAY) {
// 属于策略上报
compressVideo(videoPath, thumbnailPath, entity)
} else {
Log.d(
TAG,
"onTakeVideoSuccess maxSpeedVideo = $maxSpeedVideo --->speed= $speed + minSpeedVideo = $minSpeedVideo"
)
if (maxSpeedVideo == -1) {
Log.d(TAG, "onTakeVideoSuccess 111 abs =" + (Math.abs(minSpeedVideo) / 3.6f))
if (speed >= (Math.abs(minSpeedVideo) / 3.6f)) {
//获取视频以及缩略图成功,开始上报
compressVideo(videoPath, thumbnailPath, entity)
}
}
}
if (minSpeedVideo > 0 && maxSpeedVideo > 0) {
Log.d(TAG, "onTakeVideoSuccess minSpeedVideo > 0 -- speed = $speed")
if ((speed >= (minSpeedVideo / 3.6f)) && speed <= (maxSpeedVideo / 3.6f)) {
compressVideo(videoPath, thumbnailPath, entity)
if (minSpeedVideo > 0 && maxSpeedVideo > 0) {
Log.d(TAG, "onTakeVideoSuccess minSpeedVideo > 0 -- speed = $speed")
if ((speed >= (minSpeedVideo / 3.6f)) && speed <= (maxSpeedVideo / 3.6f)) {
compressVideo(videoPath, thumbnailPath, entity)
}
}
}
}
@@ -332,10 +341,13 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
Log.e(TAG, "getVideo onTakeVideoFail")
getVideoFailed?.invoke()
val entity = CustomStatusHandler.pollVideoStatus()
InformationUploadController.release(entity?.id)
Log.e(TAG, "getVideo onTakeVideoFail entity?.isCustom =" + entity?.isCustom)
if (entity?.isCustom) {
entity?.let {
InformationUploadController.release(entity.id)
Log.e(TAG, "getVideo onTakeVideoFail entity?.isCustom =" + entity?.isCustom)
if (entity?.isCustom) {
// sendGetInfoFailedReceiver(mType)
}
}
//失败了,传空地址,发起请求

View File

@@ -4,6 +4,7 @@ import android.content.Intent
import android.util.Log
import com.google.gson.Gson
import com.mogo.commons.AbsMogoApplication
import com.mogo.utils.TipToast
import com.zhidao.cosupload.DbPriorityConfig
import com.zhidao.cosupload.callback.CosStatusCallback
import com.zhidao.cosupload.manager.CosUploadManagerImpl
@@ -91,9 +92,9 @@ class CosStatusController : CosStatusCallback {
) {
// VoiceController.speakVoice("cos上报失败")
Log.d(TAG, "uploadCosFailed mType = $mType")
if (entity?.isCustom && mFromType != UPLOAD_FROM_STRATEGY_ACCIDENT_AUTO) {
sendGetInfoFailedReceiver("100")
}
// if (entity?.isCustom && mFromType != UPLOAD_FROM_STRATEGY_ACCIDENT_AUTO) {
// sendGetInfoFailedReceiver("100")
// }
}
if (!isRetry) {
@@ -121,7 +122,6 @@ class CosStatusController : CosStatusCallback {
downloadUrl: String?,
localPath: String?
) {
Log.d(TAG, "uploadFile mType= $mType")
Log.d(TAG, "uploadCosCompleted localPath = $localPath")
Log.d(TAG, "uploadCosCompleted downloadUrl = $downloadUrl")
Log.d(TAG, "uploadCosCompleted cosPath = $cosPath")
@@ -137,30 +137,30 @@ class CosStatusController : CosStatusCallback {
}
Log.d(TAG, "videoAndThumbMap ${videoAndThumbMap}")
if (videoAndThumbMap.size == 2) {
trackUploadCos(4)
Log.d(TAG, "videoAndThumbMap.size == 2 ")
var locationInfo = LocationUtil.getInstance().getLocationInfo()
val locationStr: String = Gson().toJson(locationInfo)
Log.d(TAG, "locationStr = " + locationStr)
//如果失败,需要提示失败弹框
if (locationInfo.address.isNullOrEmpty() || locationInfo.cityName.isNullOrEmpty() || locationInfo.cityCode.isNullOrEmpty()
|| locationInfo.latitude == 0.0 || locationInfo.areaName.isNullOrEmpty() || locationInfo.street.isNullOrEmpty()
|| locationInfo.areaCode.isNullOrEmpty() || locationInfo.provinceName.isNullOrEmpty()
) {
if (entity?.isCustom && mFromType != UPLOAD_FROM_STRATEGY_ACCIDENT_AUTO) {
sendGetInfoFailedReceiver("100")
}
} else {
//分享成功并打点如果是上报拥堵需要takeVideo
LatLngStickyEventBus.getInstance()
.postSticky(GetImageSuccessEvent(downloadUrl, mType))
//上传录像以及缩略图成功
sendInformation(INFO_TYPE_VIDEO, videoAndThumbMap)
}
// if (locationInfo.address.isNullOrEmpty() || locationInfo.cityName.isNullOrEmpty() || locationInfo.cityCode.isNullOrEmpty()
// || locationInfo.latitude == 0.0 || locationInfo.areaName.isNullOrEmpty() || locationInfo.street.isNullOrEmpty()
// || locationInfo.areaCode.isNullOrEmpty() || locationInfo.provinceName.isNullOrEmpty()
// ) {
// if (entity?.isCustom && mFromType != UPLOAD_FROM_STRATEGY_ACCIDENT_AUTO) {
// sendGetInfoFailedReceiver("100")
// }
// } else {
//上传录像以及缩略图成功
sendInformation(INFO_TYPE_VIDEO, videoAndThumbMap)
// }
} else {
trackUploadCos(5)
}
} else {
//上传图片成功, 如果是上报路况直接上传TODO
Log.d(TAG, "uploadCosCompleted 分享成功 ----mType = $mType")
// if (mType.equals("1") || mType.equals("-1")) {
Log.d(TAG, "uploadCosCompleted 分享成功 ---- mType = $mType")
sendInformationDirectly(
INFO_TYPE_IMG,
mutableMapOf("pic" to downloadUrl as String),
@@ -170,7 +170,6 @@ class CosStatusController : CosStatusCallback {
mLongitude,
mLatitude
)
// }
}
Log.d(TAG, "delete file: ${localPath!!}")
CosCallbackMapController.unregisterCallback(localPath)
@@ -195,25 +194,44 @@ class CosStatusController : CosStatusCallback {
type: Int,
map: Map<String, String>,
poiType: String,
entity: TakeEntity,
entity: TakeEntity?,
mainInfoId: Long,
longitude: Double,
latitude: Double
) {
Log.d(TAG, "sendInformationDirectly isCustomSend = ${entity?.isCustom}")
Log.d(TAG, "sendInformationDirectly poiType= $poiType ---- mainInfoId= $mainInfoId")
mainServiceHttpModel.sendInformationMessage(
type = type,
url = map,
isCustom = entity?.isCustom,
poiType = poiType,
mainInfoId = mainInfoId,
longitude = longitude,
latitude = latitude
) { success ->
CosCallbackMapController.unregisterCallbacks(map)
CosCallbackMapController.mainService?.let {
CosCallbackMapController.mainService?.sendCustomResult(success)
//开始上传
entity?.isCustom?.let {
mainServiceHttpModel.sendInformationMessage(
type = type,
url = map,
isCustom = it,
poiType = poiType,
mainInfoId = mainInfoId,
longitude = longitude,
latitude = latitude
) { success ->
CosCallbackMapController.unregisterCallbacks(map)
// CosCallbackMapController.mainService?.let {
// CosCallbackMapController.mainService?.sendCustomResult(success)
// }
Log.d(TAG, "type = $type ----success = $success")
if (success) {
//分享成功并打点如果是上报拥堵需要takeVideo
if (type == INFO_TYPE_VIDEO) {
try {
LatLngStickyEventBus.getInstance()
.postSticky(GetImageSuccessEvent("", poiType))
} catch (e: java.lang.Exception) {
e.printStackTrace()
}
}
} else {
// if (type == INFO_TYPE_VIDEO) {
// TipToast.shortTip("分享失败,请检查网络")
// }
}
}
}
}

View File

@@ -23,9 +23,9 @@ object CustomStatusHandler {
takeVideoStatusQueue.offer(entity)
}
fun pollVideoStatus(): TakeEntity = takeVideoStatusQueue.poll()
fun pollVideoStatus(): TakeEntity? = takeVideoStatusQueue.poll()
}
class TakeEntity(
var isCustom: Boolean, var id: Long
var isCustom: Boolean, var id: Long, var fromType: String = "0"
)

View File

@@ -11,10 +11,14 @@ import android.os.IBinder
import android.util.Log
import com.elegant.analytics.Analytics
import com.mogo.commons.AbsMogoApplication
import com.mogo.commons.debug.DebugConfig
import com.mogo.utils.logger.Logger
import com.mogo.utils.storage.SharedPrefsMgr
import com.zhidao.cosupload.manager.CosUploadManagerImpl
import com.zhidao.roadcondition.BuildConfig
import com.zhidao.roadcondition.constant.*
import com.zhidao.roadcondition.constant.DEFAULT_VIDEO_DURATION
import com.zhidao.roadcondition.constant.TANLU_ROAD_CURRENT
import com.zhidao.roadcondition.constant.UPLOAD_FROM_STRATEGY_ACCIDENT_AUTO
import com.zhidao.roadcondition.constant.UPLOAD_FROM_STRATEGY_BLOCK_AUTO
import com.zhidao.roadcondition.event.GetImageSuccessEvent
import com.zhidao.roadcondition.event.LatLngStickyEventBus
import com.zhidao.roadcondition.util.*
@@ -66,11 +70,11 @@ class MainService : Service() {
private var mLatitude: Double = 0.0
//发送主动上报结果广播给外部
fun sendCustomResult(result: Boolean) {
var intent = Intent(customResultAction)
intent.putExtra("isSuccess", result)
sendBroadcast(intent)
}
// fun sendCustomResult(result: Boolean) {
// var intent = Intent(customResultAction)
// intent.putExtra("isSuccess", result)
// sendBroadcast(intent)
// }
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
Log.d(TAG, "onStartCommand -----------> ")
@@ -80,7 +84,7 @@ class MainService : Service() {
Analytics.getInstance().start(this)
//参数说明appKey: app唯一标识比如包名
CosUploadManagerImpl.getInstance(AbsMogoApplication.getApp().applicationContext)
.init(BuildConfig.APPLICATION_ID, 2)
.init(BuildConfig.APPLICATION_ID, 0)
//初始化语音
VoiceController.initVoice()
@@ -93,10 +97,10 @@ class MainService : Service() {
mLongitude = it.lon
mLatitude = it.lat
Log.d(TAG, "onStartCommand shareType = $shareType --fromType = $fromType --mainInfoId = $mainInfoId -- mLongitude = $mLongitude --mLatitude = $mLatitude --it.duration = ${it.duration} ")
if (shareType == TANLU_ROAD_CONGESTION || shareType == TANLU_TRAFFIC_CHECK || shareType == TANLU_ROAD_CLOSURE || shareType == TANLU_ROAD_CURRENT
|| shareType == TANLU_ROAD_PONDING || shareType == TANLU_ROAD_ICING || shareType == TANLU_ROAD_HEAVY_FOG
|| shareType == TANLU_ROAD_ACCIDENT || shareType == TANLU_ROAD_WORK
) {
// if (shareType == TANLU_ROAD_CONGESTION || shareType == TANLU_TRAFFIC_CHECK || shareType == TANLU_ROAD_CLOSURE || shareType == TANLU_ROAD_CURRENT
// || shareType == TANLU_ROAD_PONDING || shareType == TANLU_ROAD_ICING || shareType == TANLU_ROAD_HEAVY_FOG
// || shareType == TANLU_ROAD_ACCIDENT || shareType == TANLU_ROAD_WORK
// ) {
// takePhoto(1, false, true)
if (fromType == UPLOAD_FROM_STRATEGY_ACCIDENT_AUTO || fromType == UPLOAD_FROM_STRATEGY_BLOCK_AUTO) {
// 如果是策略上报isCustom = false
@@ -104,7 +108,7 @@ class MainService : Service() {
} else {
takeVideo(it.duration, isCustom = true, id = id)
}
}
// }
}
} else {
Log.e(TAG, "intent == null ")
@@ -200,18 +204,18 @@ class MainService : Service() {
}
private fun sendMarkerInfoReceiver(lat: Double, lon: Double, imageUrl: String?, type: String?) {
Log.e("MainService", "sendMarkerInfoReceiver ------> type = $type ")
Log.e("MainService", "sendMarkerInfoReceiver ------> fromType = $fromType ")
Log.e("MainService", "sendMarkerInfoReceiver ------> isCustom = $isCustom ")
var intent = Intent()
intent.action = "com.zhidao.roadcondition.marker.info"
intent.putExtra("type", type)
intent.putExtra("imageUrl", imageUrl)
intent.putExtra("lat", lat)
intent.putExtra("lon", lon)
intent.putExtra("custom", isCustom)
intent.putExtra("fromType", fromType)
sendBroadcast(intent)
// Log.e("MainService", "sendMarkerInfoReceiver ------> type = $type ")
// Log.e("MainService", "sendMarkerInfoReceiver ------> fromType = $fromType ")
// Log.e("MainService", "sendMarkerInfoReceiver ------> isCustom = $isCustom ")
// var intent = Intent()
// intent.action = "com.zhidao.roadcondition.marker.info"
// intent.putExtra("type", type)
// intent.putExtra("imageUrl", imageUrl)
// intent.putExtra("lat", lat)
// intent.putExtra("lon", lon)
// intent.putExtra("custom", isCustom)
// intent.putExtra("fromType", fromType)
// sendBroadcast(intent)
}
/**
@@ -221,12 +225,16 @@ class MainService : Service() {
//开始开始监听速度,只要超过一次5公里每小时则即开始获取策略进行本地上报 只有release才加此判断qa环境方便测试
LocationUtil.getInstance().setonSpeedlistenner(object : LocationUtil.SpeedListener {
override fun onSpeedGet(speed: Float) {
if (speed > (5 / 3.6f) && !isGetStrategies) {
mainServiceHttpModel.initStrategies {
handleReportStrategy()
var isOpen = SharedPrefsMgr.getInstance(AbsMogoApplication.getApp().applicationContext).getBoolean("KEY_SERVER_REPORTSTRATEGY_SWITCH", false)
Logger.d("EntrancePresenter", " -------- isOpen = $isOpen")
if (isOpen) {
if (speed > (5 / 3.6f) && !isGetStrategies) {
mainServiceHttpModel.initStrategies {
handleReportStrategy()
}
Log.d("MainService", "initLocationListener more than 5 start upload speed = $speed")
isGetStrategies = true
}
Log.d("MainService", "initLocationListener more than 5 start upload speed = $speed")
isGetStrategies = true
}
}
})
@@ -248,6 +256,7 @@ class MainService : Service() {
getStrategyType("video")
)
Log.d("MainService", "handleReportStrategy picType = $picType ---videoType = $videoType")
shareType = TANLU_ROAD_CURRENT
if (picType == 1) {
takePhoto(1)
} else if (picType == 2) {
@@ -302,7 +311,7 @@ class MainService : Service() {
Log.d("MainService", "takeVideo --------1---->")
// if (isAuthorization(BaseApplication.getAppContext())) {
// log(TAG, "takeVideo --------2---->")
CarCorderController.takeVideo(1, duration, isCustom, id, if (isCustom) shareType else TANLU_ROAD_CURRENT, mainInfoId, fromType, mLongitude, mLatitude)
CarCorderController.takeVideo(1, duration, isCustom, id, shareType, mainInfoId, fromType, mLongitude, mLatitude)
// }
postVideoAlarmTask(isInterval)

View File

@@ -2,7 +2,10 @@ package com.zhidao.roadcondition.service
import android.util.Log
import com.mogo.commons.AbsMogoApplication
import com.zhidao.roadcondition.event.GetImageSuccessEvent
import com.zhidao.roadcondition.event.LatLngStickyEventBus
import com.zhidao.roadcondition.model.*
import com.zhidao.roadcondition.model.proxy.INFO_TYPE_VIDEO
import com.zhidao.roadcondition.net.request
import com.zhidao.roadcondition.util.*
import com.zhidao.roadcondition.util.StrategyPreferenceUtil.Companion.setStrategyFrequency
@@ -231,10 +234,12 @@ class MainServiceController {
latitude: Double,
customSend: ((Boolean) -> Unit)? = null
) {
Log.d(TAG, " sendInformationMessage poiType = $poiType");
Log.d(TAG, " sendInformationMessage poiType = $poiType")
//删除测试数据
var locationInfo = LocationUtil.getInstance().getLocationInfo();
var locationInfo = LocationUtil.getInstance().getLocationInfo()
if (locationInfo.address.isNullOrEmpty()) {
Log.d(TAG, " sendInformationMessage locationInfo.address = $locationInfo.address")
trackUploadGeo(1)
geoLocation(type, url, locationInfo, isCustom,trafficInfoType, isShare, customSend,poiType,mainInfoId,longitude,latitude)
} else {
postInformationMessage(
@@ -259,19 +264,28 @@ class MainServiceController {
longitude: Double,
latitude: Double
) {
Log.d(TAG, " geoLocation -- poiType = $poiType");
Log.d(TAG, " geoLocation -- poiType = $poiType")
LocationUtil.getInstance()
.geoCodeLocation(locationInfo.toLatLngPoint(), { locInfo: LocationInfo ->
Log.d(TAG, "geoLocation -------start -->")
postInformationMessage(
getInformationBody(type, url, locationInfo, isCustom, trafficInfoType, isShare, poiType,mainInfoId,longitude,latitude),
customSend
)
}, {
//转换失败的情况下再重试一次
Log.d(TAG, "geoLocation -------true-->")
geoRetryed = if (!geoRetryed) {
geoLocation(type, url, locationInfo, isCustom, trafficInfoType, isShare, customSend, poiType,mainInfoId,longitude,latitude)
true
} else {
//如果两次都失败,直接上报服务端
Log.d(TAG, "geoLocation ---- postInformationMessage ---false-->")
postInformationMessage(
getInformationBody(type, url, locationInfo, isCustom, trafficInfoType, isShare, poiType,mainInfoId,longitude,latitude),
customSend
)
false
}
})
@@ -292,7 +306,6 @@ class MainServiceController {
trackUploadServer(1)
// CosStatusController().videoAndThumbMap.clear()
customSend?.invoke(true)
}
onError {
Log.i(TAG, "$it upload message ${it.message}")
@@ -310,4 +323,11 @@ class MainServiceController {
)
}
//上传
private fun trackUploadGeo(type: Int) {
trackNormalEvent(
CarNet_Geo, mutableMapOf("type" to type)
)
}
}

View File

@@ -28,11 +28,13 @@ const val CarNet_Get_Strategy:String = "CarNet_Get_Strategy" //策略拉取成
const val CarNet_Create_Task:String = "CarNet_Create_Task" //创建定时任务
const val CarNet_Get_Picture:String = "CarNet_Get_Picture" //获取图片,type=1 调用, type=2 成功, type=3 失败
const val CarNet_Get_Video:String = "CarNet_Get_Video" //获取视频,type=1 调用,type=2 成功,type=3 失败
const val CarNet_Cos_Upload:String = "CarNet_Cos_Upload" //上传COS, type=1 成功, type=2 失败, type=3 开始
const val CarNet_Cos_Upload:String = "CarNet_Cos_Upload" //上传COS, type=1 成功, type=2 失败, type=3 开始 type=4 成功返回视频和缩略图type=5 成功但没有返回全视频和缩略图
const val CarNet_Servers_Upload:String = "CarNet_Servers_Upload" //上传服务端, type=1 成功,type=2 失败, type=3 开始
const val CarNet_Voice_Search:String = "CarNet_Voice_Search" //语音搜索路况,type=1 成功,type=2 失败
const val CarNet_USER_SHOW:String = "CarNet_user_show" //情报展示时长,showtime 加载列表时长
const val CarNet_USER_LOAD:String = "CarNet_user_load" //情报加载时长,type=1 视频2图片
const val CarNet_Geo:String = "CarNet_Geo_Location" //上传服务端, type=1开始 ,type=2 成功, type=3 失败
const val CarNet_live_broadcast = "CarNet_live_broadcast" // 地图页面点击直播(在线可直播车机)
//自定义埋点

View File

@@ -183,12 +183,14 @@ class LocationUtil private constructor() {
geocoderSearch.setOnGeocodeSearchListener(object : GeocodeSearch.OnGeocodeSearchListener {
override fun onRegeocodeSearched(p0: RegeocodeResult?, p1: Int) {
if (p1 == 1000) {
trackUploadGeo(2);
var regeocodeAddress = p0?.regeocodeAddress
regeocodeAddress?.let {
var locInfo = regeocodeAddress.toLocInfo(regeocodeAddress, latlngPoint)
locGeoCode.invoke(locInfo)
}
} else {
trackUploadGeo(3);
onError.invoke("geoCode -> $p1")
}
}
@@ -198,6 +200,13 @@ class LocationUtil private constructor() {
})
}
//上传
private fun trackUploadGeo(type: Int) {
trackNormalEvent(
CarNet_Geo, mutableMapOf("type" to type)
)
}
fun getSpeed():Float{
return speed
}