Merge branch 'feature/v1.0.0' into feature/v1.0.0-anim

This commit is contained in:
unknown
2020-02-24 11:45:21 +08:00
13 changed files with 367 additions and 296 deletions

View File

@@ -5,6 +5,7 @@ import android.content.Context;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import com.mogo.map.listener.IMogoMapListener;
import com.mogo.service.connection.IMessageResponse;
import com.mogo.service.connection.IMogoMsgAckListener;
import com.mogo.service.connection.IMogoOnMessageListener;
import com.mogo.service.connection.IMogoSocketManager;
@@ -73,6 +74,9 @@ public class SocketManager implements IMogoSocketManager, OnSocketReceiveCallbac
private SocketConnManager mSocketConnManager;
public static final int MAX_CAP = 64; //保证充足的容量应对非常延时的推送
private ArrayList< Long > mReceivedMsgId = new ArrayList<>( MAX_CAP );
private int mCurrentIndex = 0;
@Override
public void init( Context context, String appId ) {
@@ -90,15 +94,17 @@ public class SocketManager implements IMogoSocketManager, OnSocketReceiveCallbac
List< IMogoOnMessageListener > listeners = mListeners.get( msgType );
if ( listeners != null && !listeners.isEmpty() ) {
Iterator< IMogoOnMessageListener > iterator = listeners.iterator();
if ( msgId != 0 ) { //兼容老版本
if ( mReceivedMsgId.contains( msgId ) ) { // 避免消息重发
return;
}
cacheLastReceivedMsgId( msgId );
}
while ( iterator.hasNext() ) {
IMogoOnMessageListener listener = iterator.next();
if ( listener != null ) {
Object obj = GsonUtil.objectFromJson( payload.getPayload().toStringUtf8(), listener.target() );
if ( obj instanceof IMessageResponse ) {
( ( IMessageResponse ) obj ).setMsgId( msgId );
}
Logger.d(TAG, "received msg == %s, msgId = %s", payload.getPayload().toStringUtf8(), msgId);
listener.onMsgReceived( obj );
Logger.d( TAG, "received msg == %s, msgId = %s", payload.getPayload().toStringUtf8(), msgId );
listener.onMsgReceived( GsonUtil.objectFromJson( payload.getPayload().toStringUtf8(), listener.target() ) );
}
}
}
@@ -107,6 +113,16 @@ public class SocketManager implements IMogoSocketManager, OnSocketReceiveCallbac
}
}
private void cacheLastReceivedMsgId( long msgId ) {
if ( msgId == 0 ) {
return;
}
synchronized ( this ){
mReceivedMsgId.add( mCurrentIndex % MAX_CAP, msgId );
mCurrentIndex++;
}
}
@Override
public void onAck( byte[] headerBytes, byte[] payloadBytes ) {
try {

View File

@@ -5,6 +5,7 @@ import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Point;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Interpolator;
@@ -23,6 +24,7 @@ import com.amap.api.maps.model.animation.TranslateAnimation;
import com.amap.api.navi.AMapNaviView;
import com.amap.api.navi.AMapNaviViewListener;
import com.amap.api.navi.AMapNaviViewOptions;
import com.amap.api.navi.enums.AMapNaviViewShowMode;
import com.amap.api.navi.enums.AimLessMode;
import com.amap.api.navi.model.NaviInfo;
import com.mogo.map.IMogoMap;
@@ -49,16 +51,16 @@ import retrofit2.http.HEAD;
* 代理高德导航地图
*/
public class AMapNaviViewWrapper implements IMogoMapView,
IMogoMapUIController,
AMap.OnMarkerClickListener,
AMap.OnMapLoadedListener,
AMap.OnMapTouchListener,
AMap.OnPOIClickListener,
AMap.OnMapClickListener,
AMap.OnPolylineClickListener,
AMapNaviViewListener,
AMapMessageListener,
AMap.OnCameraChangeListener {
IMogoMapUIController,
AMap.OnMarkerClickListener,
AMap.OnMapLoadedListener,
AMap.OnMapTouchListener,
AMap.OnPOIClickListener,
AMap.OnMapClickListener,
AMap.OnPolylineClickListener,
AMapNaviViewListener,
AMapMessageListener,
AMap.OnCameraChangeListener {
private static final String TAG = "AMapNaviViewWrapper";
@@ -67,95 +69,95 @@ public class AMapNaviViewWrapper implements IMogoMapView,
private AMapMarkerClickHandler mMarkerClickHandler;
public AMapNaviViewWrapper(AMapNaviView mapView) {
public AMapNaviViewWrapper( AMapNaviView mapView ) {
this.mMapView = mapView;
this.mIMap = new AMapWrapper(mMapView.getMap(), mMapView, this);
this.mIMap = new AMapWrapper( mMapView.getMap(), mMapView, this );
}
private void initMapView() {
if (mMapView != null) {
if ( mMapView != null ) {
AMapNaviViewOptions options = mMapView.getViewOptions();
if (options != null) {
if ( options != null ) {
// 设置是否开启自动黑夜模式切换默认为false不自动切换
options.setAutoNaviViewNightMode(false);
options.setAutoNaviViewNightMode( false );
// 设置6秒后是否自动锁车
options.setAutoLockCar(false);
options.setAutoLockCar( false );
// 设置路线上的摄像头气泡是否显示
options.setCameraBubbleShow(true);
options.setCameraBubbleShow( true );
// 设置路线相关的配置属性,如:路线的路况颜色,路线上是否显示摄像头气泡等。
// options.setRouteOverlayOptions( MapStyleUtils.getRouteOverlayOptions() );
// 设置自车的图片对象
options.setCarBitmap(BitmapFactory.decodeResource(getContext().getResources(),
R.drawable.ic_amap_navi_cursor));
options.setCarBitmap( BitmapFactory.decodeResource( getContext().getResources(),
R.drawable.ic_amap_navi_cursor ) );
// 设置指南针图标否在导航界面显示默认显示。true显示false隐藏。
options.setCompassEnabled(false);
options.setCompassEnabled( false );
// 黑夜模式
options.setNaviNight(true);
options.setNaviNight( true );
//设置路况光柱条是否显示(只适用于驾车导航,需要联网)。
options.setTrafficBarEnabled(false);
options.setTrafficBarEnabled( false );
// 设置[实时交通图层开关按钮]是否显示(只适用于驾车导航,需要联网)。
options.setTrafficLayerEnabled(false);
options.setTrafficLayerEnabled( false );
// 设置导航界面是否显示路线全览按钮。
options.setRouteListButtonShow(false);
options.setRouteListButtonShow( false );
// 设置导航状态下屏幕是否一直开启。
options.setScreenAlwaysBright(true);
options.setScreenAlwaysBright( true );
// 设置交通播报是否打开(只适用于驾车导航,需要联网)。
options.setTrafficInfoUpdateEnabled(true);
options.setTrafficInfoUpdateEnabled( true );
// 设置摄像头播报是否打开(只适用于驾车导航)。
options.setCameraInfoUpdateEnabled(true);
options.setCameraInfoUpdateEnabled( true );
// 设置菜单按钮是否在导航界面显示。
options.setSettingMenuEnabled(false);
options.setSettingMenuEnabled( false );
// 设置是否绘制显示交通路况的线路(彩虹线),拥堵-红色,畅通-绿色,缓慢-黄色,未知-蓝色。默认不绘制彩虹线。
options.setTrafficLine(true);
options.setTrafficLine( true );
// 设置是否绘制牵引线(当前位置到目的地的指引线)。默认不绘制牵引线。
options.setLeaderLineEnabled(-1);
options.setLeaderLineEnabled( -1 );
// 设置导航界面UI是否显示。
options.setLayoutVisible(false);
options.setLayoutVisible( false );
// 设置是否自动画路
options.setAutoDrawRoute(false);
options.setAutoDrawRoute( false );
// 设置是否显示路口放大图(实景图)
options.setRealCrossDisplayShow(false);
options.setRealCrossDisplayShow( false );
// 设置是否显示路口放大图(路口模型图)
options.setModeCrossDisplayShow(false);
options.setModeCrossDisplayShow( false );
// 设置是否显示道路信息view
options.setLaneInfoShow(false);
options.setLaneInfoShow( false );
// 设置是否自动改变缩放等级
options.setAutoChangeZoom(true);
options.setAutoChangeZoom( true );
// 设置是否自动全览模式,即在算路成功后自动进入全览模式
options.setAutoDisplayOverview(false);
options.setAutoDisplayOverview( false );
// 设置路线转向箭头隐藏和显示
options.setNaviArrowVisible(false);
options.setNaviArrowVisible( false );
// 通过路线是否自动置灰,仅支持驾车导航
options.setAfterRouteAutoGray(true);
options.setZoom(16);
options.setPointToCenter(0.5D, 0.5D);
options.setAfterRouteAutoGray( true );
options.setZoom( 16 );
options.setPointToCenter( 0.5D, 0.5D );
// 2D模式
options.setTilt(0);
mMapView.setViewOptions(options);
options.setTilt( 0 );
mMapView.setViewOptions( options );
}
mMapView.setRouteOverlayVisible(false);
mMapView.setCarOverlayVisible(false);
mMapView.setNaviMode(AMapNaviView.CAR_UP_MODE);
mMapView.setRouteOverlayVisible( false );
mMapView.setCarOverlayVisible( false );
mMapView.setNaviMode( AMapNaviView.CAR_UP_MODE );
}
}
private void initListeners() {
mMapView.setOnMarkerClickListener(this);
mMapView.setOnMarkerClickListener( this );
mMarkerClickHandler = new AMapMarkerClickHandler();
mMapView.setOnMapLoadedListener(this);
mMapView.setOnMapTouchListener(this);
mMapView.setOnPolylineClickListener(this);
mMapView.setAMapNaviViewListener(this);
mMapView.setOnCameraChangeListener(this);
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);
if ( aMap != null ) {
aMap.setOnPOIClickListener( this );
aMap.setOnMapClickListener( this );
aMap.setOnCameraChangeListener( this );
}
AMapMessageManager.getInstance().registerAMapMessageListener(this);
AMapMessageManager.getInstance().registerAMapMessageListener( this );
}
private Context getContext() {
@@ -173,10 +175,10 @@ public class AMapNaviViewWrapper implements IMogoMapView,
}
@Override
public void onCreate(Bundle bundle) {
if (mMapView != null) {
mMapView.onCreate(bundle);
Logger.d(TAG, "map onCreate");
public void onCreate( Bundle bundle ) {
if ( mMapView != null ) {
mMapView.onCreate( bundle );
Logger.d( TAG, "map onCreate" );
initMapView();
initListeners();
initMyLocation();
@@ -185,47 +187,47 @@ public class AMapNaviViewWrapper implements IMogoMapView,
@Override
public void onResume() {
if (mMapView != null) {
if ( mMapView != null ) {
mMapView.onResume();
Logger.d(TAG, "map onResume");
Logger.d( TAG, "map onResume" );
}
}
@Override
public void onPause() {
if (mMapView != null) {
if ( mMapView != null ) {
mMapView.onPause();
Logger.d(TAG, "map onPause");
Logger.d( TAG, "map onPause" );
}
}
@Override
public void onDestroy() {
if (mMapView != null) {
if ( mMapView != null ) {
mMapView.onDestroy();
Logger.d(TAG, "map onDestroy");
Logger.d( TAG, "map onDestroy" );
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
if (mMapView != null) {
mMapView.onSaveInstanceState(outState);
Logger.d(TAG, "map onSaveInstanceState");
public void onSaveInstanceState( Bundle outState ) {
if ( mMapView != null ) {
mMapView.onSaveInstanceState( outState );
Logger.d( TAG, "map onSaveInstanceState" );
}
}
@Override
public void onLowMemory() {
Logger.d(TAG, "map onLowMemory");
Logger.d( TAG, "map onLowMemory" );
}
/**
* 地图marker点击
*/
@Override
public boolean onMarkerClick(Marker marker) {
return mMarkerClickHandler.handleMarkerClicked(marker);
public boolean onMarkerClick( Marker marker ) {
return mMarkerClickHandler.handleMarkerClicked( marker );
}
/**
@@ -240,32 +242,32 @@ public class AMapNaviViewWrapper implements IMogoMapView,
* 地图点击回调
*/
@Override
public void onTouch(MotionEvent motionEvent) {
MogoMapListenerHandler.getInstance().onTouch(motionEvent);
public void onTouch( MotionEvent motionEvent ) {
MogoMapListenerHandler.getInstance().onTouch( motionEvent );
}
/**
* POI 点击
*/
@Override
public void onPOIClick(Poi poi) {
if (InterceptorHandler.getInstance().ignorePoiClicked(getContext())) {
public void onPOIClick( Poi poi ) {
if ( InterceptorHandler.getInstance().ignorePoiClicked( getContext() ) ) {
return;
}
MogoMapListenerHandler.getInstance().onPOIClick(ObjectUtils.fromAMap(poi));
MogoMapListenerHandler.getInstance().onPOIClick( ObjectUtils.fromAMap( poi ) );
}
@Override
public void onMapClick(LatLng latLng) {
if (InterceptorHandler.getInstance().ignoreMapClicked(getContext())) {
public void onMapClick( LatLng latLng ) {
if ( InterceptorHandler.getInstance().ignoreMapClicked( getContext() ) ) {
return;
}
MogoMapListenerHandler.getInstance().onMapClick(ObjectUtils.fromAMap(latLng));
MogoMapListenerHandler.getInstance().onMapClick( ObjectUtils.fromAMap( latLng ) );
}
@Override
public void onPolylineClick(Polyline polyline) {
NaviClient.getInstance(getContext()).handleClickedPolyline(polyline);
public void onPolylineClick( Polyline polyline ) {
NaviClient.getInstance( getContext() ).handleClickedPolyline( polyline );
}
@Override
@@ -287,8 +289,8 @@ public class AMapNaviViewWrapper implements IMogoMapView,
* @param mode 0:车头朝上状态1:正北朝上模式
*/
@Override
public void onNaviMapMode(int mode) {
Logger.i(TAG, "mode=" + mode);
public void onNaviMapMode( int mode ) {
Logger.i( TAG, "mode=" + mode );
}
@Override
@@ -307,8 +309,9 @@ public class AMapNaviViewWrapper implements IMogoMapView,
}
@Override
public void onLockMap(boolean isLock) {
MogoMapListenerHandler.getInstance().onLockMap(isLock);
public void onLockMap( boolean isLock ) {
Logger.d( TAG, "lock status = %s", isLock );
MogoMapListenerHandler.getInstance().onLockMap( isLock );
}
@Override
@@ -317,136 +320,152 @@ public class AMapNaviViewWrapper implements IMogoMapView,
}
@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);
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) {
public void onNaviViewShowMode( int i ) {
}
@Override
public void setTrafficEnabled(boolean visible) {
if (checkAMapView()) {
mMapView.setTrafficLine(visible);
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 changeZoom(boolean zoom) {
if (checkAMapView()) {
if (zoom) {
public void setTrafficEnabled( boolean visible ) {
if ( checkAMapView() ) {
mMapView.setTrafficLine( visible );
}
}
@Override
public void changeZoom( boolean zoom ) {
if ( checkAMapView() ) {
if ( zoom ) {
mMapView.zoomIn();
} else {
mMapView.zoomOut();
}
Logger.i(TAG, "mapview zoom = " + mMapView.getMap().getCameraPosition().zoom);
Logger.i(TAG, "scalePerPixel = " + getMap().getScalePerPixel());
Logger.i( TAG, "mapview zoom = " + mMapView.getMap().getCameraPosition().zoom );
Logger.i( TAG, "scalePerPixel = " + getMap().getScalePerPixel() );
}
}
@Override
public void changeZoom(float zoom) {
getMap().changeZoom(zoom);
public void changeZoom( float zoom ) {
Logger.d( TAG, "changeZoom %s", zoom );
mockTouchEvent();
getMap().changeZoom( zoom );
}
@Override
public void changeMapMode(EnumMapUI ui) {
if (ui == null) {
public void changeMapMode( EnumMapUI ui ) {
if ( ui == null ) {
return;
}
if (checkAMapView()) {
if ( checkAMapView() ) {
AMapNaviViewOptions options = mMapView.getViewOptions();
if (options == null) {
if ( options == null ) {
options = new AMapNaviViewOptions();
}
switch (ui) {
switch ( ui ) {
case CarUp_2D:
options.setTilt(0);
mMapView.setNaviMode(AMapNaviView.CAR_UP_MODE);
options.setTilt( 0 );
mMapView.setNaviMode( AMapNaviView.CAR_UP_MODE );
break;
case CarUp_3D:
options.setTilt(60);
mMapView.setNaviMode(AMapNaviView.CAR_UP_MODE);
options.setTilt( 60 );
mMapView.setNaviMode( AMapNaviView.CAR_UP_MODE );
break;
case NorthUP_2D:
options.setTilt(0);
mMapView.setNaviMode(AMapNaviView.NORTH_UP_MODE);
options.setTilt( 0 );
mMapView.setNaviMode( AMapNaviView.NORTH_UP_MODE );
break;
case Type_Light:
options.setNaviNight(false);
options.setNaviNight( false );
break;
case Type_Night:
options.setNaviNight(true);
options.setNaviNight( true );
break;
case Type_AUTO_LIGHT_Night:
options.setNaviNight(false);
options.setAutoNaviViewNightMode(true);
options.setNaviNight( false );
options.setAutoNaviViewNightMode( true );
break;
}
mMapView.setViewOptions(options);
mMapView.setViewOptions( options );
}
}
private boolean checkAMapView() {
if (mMapView == null) {
Logger.e(TAG, "高德mapView实例为空请检查");
if ( mMapView == null ) {
Logger.e( TAG, "高德mapView实例为空请检查" );
return false;
}
return true;
}
@Override
public void moveToCenter(MogoLatLng latLng) {
if (latLng == null || latLng.lat == 0.0d || latLng.lng == 0.0d) {
Logger.e(TAG, "latlng = null or is illegal");
public void moveToCenter( MogoLatLng latLng ) {
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;
}
mockTouchEvent();
mMapView.getMap()
.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(latLng.lat, latLng.lng)));
.moveCamera( CameraUpdateFactory.newLatLng( new LatLng( latLng.lat, latLng.lng ) ) );
}
@Override
public void showMyLocation(boolean visible) {
if (checkAMapView()) {
public void showMyLocation( boolean visible ) {
if ( checkAMapView() ) {
MyLocationStyle style = mMapView.getMap().getMyLocationStyle();
style.showMyLocation(visible);
mMapView.getMap().setMyLocationStyle(style);
style.showMyLocation( visible );
mMapView.getMap().setMyLocationStyle( style );
}
}
public void initMyLocation() {
if (checkAMapView()) {
mMapView.getMap().setMyLocationEnabled(true);
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.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 );
style.myLocationIcon(
BitmapDescriptorFactory.fromResource(R.drawable.map_api_ic_current_location2));
mMapView.getMap().setMyLocationStyle(style);
BitmapDescriptorFactory.fromResource( R.drawable.map_api_ic_current_location2 ) );
mMapView.getMap().setMyLocationStyle( style );
}
}
@Override
public void recoverLockMode() {
if (checkAMapView()) {
if ( checkAMapView() ) {
mMapView.recoverLockMode();
}
}
@Override
public void displayOverview() {
if (checkAMapView()) {
if (NaviClient.getInstance(getContext()).isNaviing()) {
if ( checkAMapView() ) {
if ( NaviClient.getInstance( getContext() ).isNaviing() ) {
mMapView.displayOverview();
}
}
@@ -464,37 +483,37 @@ public class AMapNaviViewWrapper implements IMogoMapView,
@Override
public void onNaviStarted() {
if (checkAMapView()) {
mMapView.setCarOverlayVisible(true);
if ( checkAMapView() ) {
mMapView.setCarOverlayVisible( true );
showMyLocation( false );
}
}
@Override
public void onNaviStopped() {
if (checkAMapView()) {
mMapView.setCarOverlayVisible(false);
showMyLocation(true);
NaviClient.getInstance(getContext()).startAimlessMode(AimLessMode.CAMERA_AND_SPECIALROAD_DETECTED);
if ( checkAMapView() ) {
mMapView.setCarOverlayVisible( false );
showMyLocation( true );
NaviClient.getInstance( getContext() ).startAimlessMode( AimLessMode.CAMERA_AND_SPECIALROAD_DETECTED );
}
}
@Override
public void onNaviInfoUpdat(NaviInfo naviInfo) {
public void onNaviInfoUpdat( NaviInfo naviInfo ) {
}
@Override
public void onCameraChange(CameraPosition cameraPosition) {
public void onCameraChange( CameraPosition cameraPosition ) {
}
@Override
public void onCameraChangeFinish(CameraPosition cameraPosition) {
if (cameraPosition != null) {
public void onCameraChangeFinish( CameraPosition cameraPosition ) {
if ( cameraPosition != null ) {
MogoMapListenerHandler.getInstance()
.onMapChanged(ObjectUtils.fromAMap(cameraPosition.target), cameraPosition.zoom,
cameraPosition.tilt, cameraPosition.bearing);
.onMapChanged( ObjectUtils.fromAMap( cameraPosition.target ), cameraPosition.zoom,
cameraPosition.tilt, cameraPosition.bearing );
}
}
@@ -502,8 +521,8 @@ public class AMapNaviViewWrapper implements IMogoMapView,
public MogoLatLng getCameraNorthEastPosition() {
try {
return ObjectUtils.fromAMap(
mMapView.getMap().getProjection().getVisibleRegion().latLngBounds.northeast);
} catch (Exception e) {
mMapView.getMap().getProjection().getVisibleRegion().latLngBounds.northeast );
} catch ( Exception e ) {
}
return null;
@@ -513,8 +532,8 @@ public class AMapNaviViewWrapper implements IMogoMapView,
public MogoLatLng getCameraSouthWestPosition() {
try {
return ObjectUtils.fromAMap(
mMapView.getMap().getProjection().getVisibleRegion().latLngBounds.southwest);
} catch (Exception e) {
mMapView.getMap().getProjection().getVisibleRegion().latLngBounds.southwest );
} catch ( Exception e ) {
}
return null;
@@ -523,30 +542,30 @@ public class AMapNaviViewWrapper implements IMogoMapView,
@Override
public MogoLatLng getWindowCenterLocation() {
try {
return ObjectUtils.fromAMap(mMapView.getMap().getCameraPosition().target);
} catch (Exception e) {
return ObjectUtils.fromAMap( mMapView.getMap().getCameraPosition().target );
} catch ( Exception e ) {
}
return null;
}
@Override
public void setPointToCenter(double mapCenterX, double mapCenterY) {
if (checkAMapView()) {
public void setPointToCenter( double mapCenterX, double mapCenterY ) {
if ( checkAMapView() ) {
AMapNaviViewOptions options = mMapView.getViewOptions();
options.setPointToCenter(mapCenterX, mapCenterY);
mMapView.setViewOptions(options);
options.setPointToCenter( mapCenterX, mapCenterY );
mMapView.setViewOptions( options );
}
}
@Override
public Point getLocationPointInScreen(MogoLatLng latLng) {
if (checkAMapView()) {
public Point getLocationPointInScreen( MogoLatLng latLng ) {
if ( checkAMapView() ) {
try {
return mMapView.getMap()
.getProjection()
.toScreenLocation(ObjectUtils.fromMogo2(latLng));
} catch (Exception e) {
.getProjection()
.toScreenLocation( ObjectUtils.fromMogo2( latLng ) );
} catch ( Exception e ) {
return null;
}
}
@@ -554,12 +573,12 @@ public class AMapNaviViewWrapper implements IMogoMapView,
}
@Override
public MogoLatLng getLocationMogoLatLngInScreen(Point point) {
if (checkAMapView()) {
public MogoLatLng getLocationMogoLatLngInScreen( Point point ) {
if ( checkAMapView() ) {
try {
return ObjectUtils.fromAMap(
mMapView.getMap().getProjection().fromScreenLocation(point));
} catch (Exception e) {
mMapView.getMap().getProjection().fromScreenLocation( point ) );
} catch ( Exception e ) {
return null;
}
}
@@ -567,28 +586,41 @@ public class AMapNaviViewWrapper implements IMogoMapView,
}
@Override
public void startJumpAnimation(IMogoMarker marker, float high, Interpolator interpolator,
long duration) {
if (marker == null || high <= 0.0f || interpolator == null || duration < 0) {
public void startJumpAnimation( IMogoMarker marker, float high, Interpolator interpolator,
long duration ) {
if ( marker == null || high <= 0.0f || interpolator == null || duration < 0 ) {
return;
}
try {
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);
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 animation = new TranslateAnimation( target );
animation.setInterpolator( interpolator );
//整个移动所需要的时间
animation.setDuration(duration);
animation.setDuration( duration );
//设置动画
if (marker instanceof AMapMarkerWrapper) {
((AMapMarkerWrapper) marker).getMarker().setAnimation(animation);
((AMapMarkerWrapper) marker).getMarker().startAnimation();
if ( marker instanceof AMapMarkerWrapper ) {
( ( AMapMarkerWrapper ) marker ).getMarker().setAnimation( animation );
( ( AMapMarkerWrapper ) marker ).getMarker().startAnimation();
}
} catch (Exception e) {
Logger.e(TAG, e, "error.");
} catch ( Exception e ) {
Logger.e( TAG, e, "error." );
}
}
/**
* 模拟点击事件,达到锁车->普通事件
*/
private void mockTouchEvent(){
long downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis() + 100;
int metaState = 0;
MotionEvent motionEvent = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, 0, 0, metaState);
mMapView.dispatchTouchEvent(motionEvent);
MotionEvent upEvent = MotionEvent.obtain(downTime + 100, eventTime + 100, MotionEvent.ACTION_UP, 0,0, metaState);
mMapView.dispatchTouchEvent(upEvent);
}
}

View File

@@ -212,12 +212,12 @@ public class NaviListenerAdapter extends AMapNaviListenerAdapter {
}
public void stopNavi() {
mNaviOverlayHelper.clearCalculatedOverlay();
setStopped( true );
setNaviing( false );
mAMapNavi.stopNavi();
MogoNaviListenerHandler.getInstance().onStopNavi();
AMapMessageManager.getInstance().postNaviStopped();
mNaviOverlayHelper.clearCalculatedOverlay();
}
public void handleClickedPolyline( Polyline polyline ) {

View File

@@ -136,6 +136,7 @@ public class EntranceFragment extends MvpFragment< EntranceView, EntrancePresent
if ( location != null ) {
mMogoStatusManager.setUserInteractionStatus( TAG, true, false );
mMApUIController.changeZoom( 16.0f );
mMogoStatusManager.setUserInteractionStatus( TAG, true, false );
mMApUIController.recoverLockMode();
// mMApUIController.moveToCenter( new MogoLatLng( location.getLatitude(), location.getLongitude() ) );
}

View File

@@ -595,10 +595,6 @@ public class MogoModulesManager implements MogoModulesHandler,
}
}
}
if ( iterator.hasNext() ) {
iterator.next().accOn();
}
}
@Override

View File

@@ -56,7 +56,7 @@ public class MarkerServiceHandler {
mMarkerManager = mMapService.getMarkerManager(context);
mNavi = mMapService.getNavi(context);
mMapUIController = mMapService.getMapUIController();
mLocationClient = mMapService.getLocationClient(context);
mLocationClient = mMapService.getSingletonLocationClient(context);
mMapMarkerManager = MapMarkerManager.getInstance(context);
mMapMarkerManager.init(context);

View File

@@ -193,12 +193,14 @@ public class MogoServiceProvider implements IMogoModuleProvider,
@Override
public void onSuccess() {
mLoopRequest = false;
Logger.d( TAG, "request Success." );
invokeAutoRefreshStrategy();
}
@Override
public void onFail() {
if ( mLoopRequest ) {
Logger.d( TAG, "onFail and loop" );
mHandler.sendEmptyMessageDelayed( ServiceConst.MSG_LOOP_REQUEST, ServiceConst.LOOP_INTERVAL );
} else {
invokeAutoRefreshStrategy();
@@ -427,7 +429,7 @@ public class MogoServiceProvider implements IMogoModuleProvider,
@Override
public void onMapChanged( MogoLatLng latLng, float zoom, float tilt, float bearing ) {
Logger.d(TAG, "onMapChanged==latLng:" + latLng+" mStatusManager.isUserInteracted()==="+mStatusManager.isUserInteracted());
if ( mIsCameraInited ) {
mLastZoomLevel = zoom;
mLastCustomRefreshCenterLocation = latLng;
@@ -444,6 +446,7 @@ public class MogoServiceProvider implements IMogoModuleProvider,
if ( mStatusManager.isUserInteracted() ) {
mLastCustomRefreshCenterLocation = latLng;
mLastZoomLevel = zoom;
refreshCameraPosition();
return;
}
@@ -487,6 +490,7 @@ public class MogoServiceProvider implements IMogoModuleProvider,
if ( factor == 0.0f ) {
return false;
}
Logger.d( TAG, "invokeRefreshWhenTranslationByUsermLastCustomRefreshCenterLocation = %s, latLng = %s", mLastCustomRefreshCenterLocation, latLng );
float distance = Utils.calculateLineDistance( latLng, mLastCustomRefreshCenterLocation );
return distance > factor;
} catch ( Exception e ) {
@@ -500,6 +504,7 @@ public class MogoServiceProvider implements IMogoModuleProvider,
if ( location == null ) {
return;
}
// 自动刷新触发
final MogoLatLng point = new MogoLatLng( location.getLatitude(), location.getLongitude() );
if ( mLastAutoRefreshLocation == null ) {
@@ -580,7 +585,7 @@ public class MogoServiceProvider implements IMogoModuleProvider,
try {
if ( isTrue ) {
// V2X_UI时不在自动刷新打点策略
// stopAutoRefreshStrategy();
stopAutoRefreshStrategy();
// 清除所有的打点信息记录
MarkerServiceHandler.getMapMarkerManager().alreadySmallMarker.clear();
} else {

View File

@@ -1,25 +1,21 @@
package com.mogo.module.service.marker;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.BounceInterpolator;
import android.view.animation.OvershootInterpolator;
import android.widget.TextView;
import com.amap.api.maps.model.animation.Animation;
import com.amap.api.maps.model.animation.ScaleAnimation;
import com.mogo.map.MogoLatLng;
import com.mogo.map.impl.amap.marker.AMapMarkerWrapper;
import com.mogo.map.location.MogoLocation;
import com.mogo.map.marker.IMogoMarker;
import com.mogo.map.marker.IMogoMarkerClickListener;
import com.mogo.map.marker.MogoMarkerOptions;
import com.mogo.map.marker.MogoMarkersHandler;
import com.mogo.module.common.entity.MarkerCarChat;
import com.mogo.module.common.entity.MarkerCardResult;
import com.mogo.module.common.entity.MarkerExploreWay;
import com.mogo.module.common.entity.MarkerLocation;
@@ -33,6 +29,7 @@ import com.mogo.module.service.MarkerServiceHandler;
import com.mogo.module.service.ServiceConst;
import com.mogo.module.service.Utils;
import com.mogo.module.service.datamanager.MogoDataHandler;
import com.mogo.module.service.utils.ViewUtils;
import com.mogo.service.cardmanager.IMogoCardChangedListener;
import com.mogo.service.connection.IMogoOnMessageListener;
import com.mogo.utils.logger.Logger;
@@ -56,8 +53,7 @@ import java.util.Map;
public class MapMarkerManager implements IMogoMarkerClickListener, IMogoOnMessageListener<MarkerResponse> {
private static final String TAG = "MapMarkerManager";
// 第一次请求到地图的Marker数据
private boolean isFirstMarker = true;
private boolean isOnLineCard = false;
private boolean isFirstMarker = false;
private static Context mContext;
private static IMogoMarker lastMarker;
private static MapMarkerManager mMarkerManager;
@@ -99,17 +95,15 @@ public class MapMarkerManager implements IMogoMarkerClickListener, IMogoOnMessag
public void onSwitched(int position, String moduleName) {
Logger.e(TAG, "======moduleName" + moduleName);
highlightedMarker(moduleName, false);
if (moduleName.equals(ServiceConst.CARD_TYPE_USER_DATA)) {
isOnLineCard = true;
} else {
isOnLineCard = false;
}
mLastHighLightModule = moduleName;
}
});
}
// ACC ON 的时候重置为true
public void setFirstMarker(boolean firstMarker) {
isFirstMarker = firstMarker;
}
/**
* 地图上的Marker点击回调
@@ -119,7 +113,7 @@ public class MapMarkerManager implements IMogoMarkerClickListener, IMogoOnMessag
Logger.i(TAG, "onMarkerClicked 点击了大而全中的Marker" + marker);
try {
// 移动地图到指定位置
MarkerServiceHandler.getMogoStatusManager().setUserInteractionStatus(ServiceConst.TYPE, true, true);
MarkerServiceHandler.getMogoStatusManager().setUserInteractionStatus(ServiceConst.TYPE, true, false);
MarkerServiceHandler.getMapUIController().moveToCenter(marker.getPosition());
if (lastMarker != null) {
@@ -129,26 +123,11 @@ public class MapMarkerManager implements IMogoMarkerClickListener, IMogoOnMessag
return false;
}
// 将上次选中 Marker 设置为未选中状态
MarkerShowEntity lastMarkerShowEntity = (MarkerShowEntity) lastMarker.getObject();
Logger.i(TAG, "onMarkerClicked 点击了大而全中的Marker lastMarkerShowEntity" + lastMarkerShowEntity);
if (lastMarkerShowEntity != null) {
lastMarkerShowEntity.setChecked(false);
lastMarkerShowEntity.setHighlighted(false);
IMarkerView markerView = MapMarkerAdapter.getMarkerView(mContext, lastMarkerShowEntity, lastMarker.getMogoMarkerOptions());
lastMarker.setIcon(fromView(markerView.getView()));
}
closeMarker(lastMarker);
}
// 将当前的Marker设置为选中
MarkerShowEntity markerShowEntity = (MarkerShowEntity) marker.getObject();
Logger.i(TAG, "onMarkerClicked 点击了大而全中的Marker markerShowEntity" + markerShowEntity);
if (markerShowEntity != null) {
markerShowEntity.setChecked(true);
markerShowEntity.setHighlighted(true);
IMarkerView markerView = MapMarkerAdapter.getMarkerView(mContext, markerShowEntity, marker.getMogoMarkerOptions());
marker.setIcon(fromView(markerView.getView()));
}
openMarker(marker);
lastMarker = marker;
// 数据统计代码
@@ -200,31 +179,6 @@ public class MapMarkerManager implements IMogoMarkerClickListener, IMogoOnMessag
}
private Bitmap fromView(View view) {
view.setDrawingCacheEnabled(true);
processChildView(view);
view.destroyDrawingCache();
view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
Bitmap bitmap = null;
return (bitmap = view.getDrawingCache()) != null ? bitmap.copy(Bitmap.Config.ARGB_8888, false) : null;
}
private void processChildView(View view) {
if (!(view instanceof ViewGroup)) {
if (view instanceof TextView) {
((TextView) view).setHorizontallyScrolling(false);
}
} else {
for (int var1 = 0; var1 < ((ViewGroup) view).getChildCount(); ++var1) {
processChildView(((ViewGroup) view).getChildAt(var1));
}
}
}
// 对指定类型高亮处理
public synchronized static void highlightedMarker(final String typeTag) {
highlightedMarker(typeTag, false);
@@ -334,22 +288,38 @@ public class MapMarkerManager implements IMogoMarkerClickListener, IMogoOnMessag
// 将上次选中 Marker 设置为未选中状态
if (marker != null) {
Logger.i(TAG, "closeMarkerSelect 将出Marker详情关闭" + marker);
// 将上次选中 Marker 设置为未选中状态
MarkerShowEntity lastMarkerShowEntity = (MarkerShowEntity) marker.getObject();
lastMarkerShowEntity.setChecked(false);
lastMarkerShowEntity.setHighlighted(false);
IMarkerView markerView = MapMarkerAdapter.getMarkerView(mContext, lastMarkerShowEntity, marker.getMogoMarkerOptions());
marker.setIcon(fromView(markerView.getView()));
closeMarker(marker);
lastMarker = null;
}
}
/**
* 绘制Marker
*/
// 展开气泡
private void openMarker(IMogoMarker mogoMarker) {
if (mogoMarker != null) {
Object object = mogoMarker.getObject();
if (object != null) {
MarkerShowEntity markerShowEntity = (MarkerShowEntity) object;
markerShowEntity.setChecked(true);
IMarkerView markerView = MapMarkerAdapter.getMarkerView(mContext, markerShowEntity, mogoMarker.getMogoMarkerOptions());
mogoMarker.setIcon(ViewUtils.fromView(markerView.getView()));
}
}
}
// 折叠气泡
private void closeMarker(IMogoMarker mogoMarker) {
if (mogoMarker != null) {
Object object = mogoMarker.getObject();
if (object != null) {
MarkerShowEntity markerShowEntity = (MarkerShowEntity) object;
markerShowEntity.setChecked(false);
IMarkerView markerView = MapMarkerAdapter.getMarkerView(mContext, markerShowEntity, mogoMarker.getMogoMarkerOptions());
mogoMarker.setIcon(ViewUtils.fromView(markerView.getView()));
}
}
}
// 绘制Marker
public synchronized void drawMapMarker(MarkerResponse response) {
lastMarker = null;
@@ -369,25 +339,16 @@ public class MapMarkerManager implements IMogoMarkerClickListener, IMogoOnMessag
isFirstMarker = true;
} else {
// 清空所有地图上绘制的Marker
if (!MarkerServiceHandler.getMogoStatusManager().isV2XShow()) {
MarkerServiceHandler.getMarkerManager().removeMarkers();
}
MarkerServiceHandler.getMarkerManager().removeMarkers();
}
List<MarkerCarChat> carChatList = markerCardResult.getCarChat();
List<MarkerOnlineCar> onlineCarList = markerCardResult.getOnlineCar();
List<MarkerExploreWay> exploreWayList = null;
List<MarkerShareMusic> shareMusicList = null;
List<MarkerNoveltyInfo> noveltyInfoList = null;
List<MarkerExploreWay> exploreWayList = markerCardResult.getExploreWay();
List<MarkerShareMusic> shareMusicList = markerCardResult.getShareMusic();
List<MarkerNoveltyInfo> noveltyInfoList = markerCardResult.getNoveltyInfo();
// V2X 场景下只保留在线车辆数据
if (!MarkerServiceHandler.getMogoStatusManager().isV2XShow()) {
exploreWayList = markerCardResult.getExploreWay();
shareMusicList = markerCardResult.getShareMusic();
noveltyInfoList = markerCardResult.getNoveltyInfo();
}
if (onlineCarList != null) {
double nearlyDistance = Double.MAX_VALUE;
double nearlyDistance = Float.MAX_VALUE;
for (MarkerOnlineCar markerOnlineCar : onlineCarList) {
MarkerLocation markerLocation = markerOnlineCar.getLocation();
@@ -401,16 +362,25 @@ public class MapMarkerManager implements IMogoMarkerClickListener, IMogoOnMessag
IMogoMarker iMogoMarker = drawMapMarker(markerShowEntity);
// 计算在线车辆距离当前车辆的距离,每次都与最后一次距离最近的进行比较,保留距离最近的车辆,进行卡片展示
try {
double calculateDistance = Utils.calculateLineDistance(
new MogoLatLng(markerLocation.getLat(), markerLocation.getLat()),
new MogoLatLng(
MarkerServiceHandler.getMogoLocationClient().getLastKnowLocation().getLatitude(),
MarkerServiceHandler.getMogoLocationClient().getLastKnowLocation().getLongitude()
)
// 当前车辆的位置
MogoLocation currentLocation = MarkerServiceHandler.getMogoLocationClient().getLastKnowLocation();
// 计算车辆距离指定气泡的距离
float calculateDistance = Utils.calculateLineDistance(
new MogoLatLng(markerLocation.getLat(), markerLocation.getLon()),
new MogoLatLng(currentLocation.getLatitude(), currentLocation.getLongitude())
);
// Logger.d("点之间距离",
// "当前车辆经纬度:" +
// "\n\tlatitude=" + currentLocation.getLatitude() +
// "\n\tlongitude=" + currentLocation.getLongitude() +
// "\n气泡经纬度" + markerLocation +
// "\n相距" + calculateDistance + "米");
// 进行比较,保留最近的一个数据
if (calculateDistance < nearlyDistance) {
nearlyDistance = calculateDistance;
nearlyMogoMarker = iMogoMarker;
}
@@ -418,6 +388,7 @@ public class MapMarkerManager implements IMogoMarkerClickListener, IMogoOnMessag
e.printStackTrace();
}
}
Logger.d("点之间距离", "距离当前车辆位置最近的距离为:" + nearlyDistance);
fillNumberTrackEventBody(array, 3, onlineCarList.size());
}
@@ -505,9 +476,8 @@ public class MapMarkerManager implements IMogoMarkerClickListener, IMogoOnMessag
highlightedMarker(mLastHighLightModule, true);
try {
Thread.sleep(500);
// 在ACC on 之后第一次获取到了在线车辆数据选中最近的一个Marker
if (isFirstMarker && isOnLineCard) {
if (isFirstMarker) {
if (nearlyMogoMarker != null) {
Logger.w(TAG, "ACC ON,或者语音搜索触发默认选中最近的在线车辆nearlyMogoMarker" + nearlyMogoMarker);
onMarkerClicked(nearlyMogoMarker);

View File

@@ -77,6 +77,14 @@ public class RefreshModel {
}
}
@Override
public void onError( Throwable e ) {
super.onError( e );
if (callback != null) {
callback.onFail();
}
}
@Override
public void onError(String message, int code) {
super.onError(message, code);

View File

@@ -0,0 +1,37 @@
package com.mogo.module.service.utils;
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
/**
* author : donghongyu
* e-mail : 1358506549@qq.com
* date : 2020-02-2123:51
* desc :
* version: 1.0
*/
public class ViewUtils {
public static Bitmap fromView(View view) {
view.setDrawingCacheEnabled(true);
processChildView(view);
view.destroyDrawingCache();
view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
Bitmap bitmap = null;
return (bitmap = view.getDrawingCache()) != null ? bitmap.copy(Bitmap.Config.ARGB_8888, false) : null;
}
public static void processChildView(View view) {
if (!(view instanceof ViewGroup)) {
if (view instanceof TextView) {
((TextView) view).setHorizontallyScrolling(false);
}
} else {
for (int var1 = 0; var1 < ((ViewGroup) view).getChildCount(); ++var1) {
processChildView(((ViewGroup) view).getChildAt(var1));
}
}
}
}

View File

@@ -616,6 +616,7 @@ import static com.mogo.module.tanlu.video.VideoInitKt.initVideo;
private void moveToMarcker(double lat, double lon) {
MogoLatLng latLng = new MogoLatLng(lat, lon);
mMogoStatusManager.setUserInteractionStatus( TAG, true, false );
mMApUIController.moveToCenter(latLng);
}
@@ -1303,6 +1304,7 @@ import static com.mogo.module.tanlu.video.VideoInitKt.initVideo;
optionList.add(options);
}
Logger.d(TAG, "getVoiceControlRoadData optionList.size() = " + optionList.size());
mMogoStatusManager.setUserInteractionStatus(TanluConstants.MODEL_NAME, true, false);
mMarkerManager.addMarkers(TanluConstants.MODEL_NAME, optionList, true);
//直接使用当前数据list作为切换的数据源切换左侧列表到最新的数据

View File

@@ -1,4 +1,4 @@
package com.mogo.connection.socket;
package com.mogo.service.connection;
/**
* @author congtaowang

View File

@@ -8,6 +8,7 @@ import com.mogo.service.MogoServicePaths;
import com.mogo.service.statusmanager.IMogoStatusChangedListener;
import com.mogo.service.statusmanager.IMogoStatusManager;
import com.mogo.service.statusmanager.StatusDescriptor;
import com.mogo.utils.logger.Logger;
import java.util.ArrayList;
import java.util.Iterator;
@@ -24,6 +25,8 @@ import java.util.concurrent.ConcurrentHashMap;
@Route( path = MogoServicePaths.PATH_STATUS_MANAGER )
public class MogoStatusManager implements IMogoStatusManager {
private static final String TAG = "MogoStatusManager";
/**
* 状态记录
*/
@@ -123,6 +126,7 @@ public class MogoStatusManager implements IMogoStatusManager {
@Override
public void setUserInteractionStatus( String tag, boolean interrupt, boolean callback ) {
Logger.d( TAG, "setUserInteractionStatus handler = %s, status = %s, callback = %s", tag, interrupt, callback );
mStatus.put( StatusDescriptor.USER_INTERACTED, interrupt );
if ( callback ) {
invokeStatusChangedListener( StatusDescriptor.USER_INTERACTED, interrupt );