在分享模块增加了,监听高德巡航进行事件上报的功能
TODO 上报接口对接
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
package com.mogo.map.impl.amap.navi;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.amap.api.navi.AMapNavi;
|
||||
import com.amap.api.navi.enums.AimLessMode;
|
||||
import com.mogo.map.navi.IMogoAimless;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.mogo.utils.storage.SharedPrefsMgr;
|
||||
|
||||
/**
|
||||
* @author donghongyu
|
||||
* @since 2020-11-05
|
||||
* <p>
|
||||
* 高德巡航
|
||||
*/
|
||||
public class AimlessClient implements IMogoAimless {
|
||||
|
||||
/**
|
||||
* 巡航状态控制
|
||||
*/
|
||||
public static final String KEY_AIMLESS_STATUS = "KEY_AIMLESS_STATUS";
|
||||
|
||||
private static final String TAG = "AimlessClient";
|
||||
private final Context mContext;
|
||||
|
||||
private AMapNavi mAMapNavi;
|
||||
|
||||
private AimlessModeListenerAdapter mAimlessModeListener;
|
||||
|
||||
private static volatile AimlessClient sInstance;
|
||||
|
||||
/**
|
||||
* 巡航模式配置状态
|
||||
*/
|
||||
private boolean mAimlessModeStatus;
|
||||
|
||||
/**
|
||||
* 巡航状态
|
||||
*/
|
||||
private boolean mAimlessStatus;
|
||||
|
||||
private AimlessClient(Context context) {
|
||||
mContext = context.getApplicationContext();
|
||||
// 按需初始化高德导航组件
|
||||
initAMapNavi();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化导航组件
|
||||
*/
|
||||
private void initAMapNavi() {
|
||||
Logger.d(TAG, "initAMapNavi");
|
||||
if (mAMapNavi != null) {
|
||||
return;
|
||||
}
|
||||
mAMapNavi = AMapNavi.getInstance(mContext);
|
||||
mAMapNavi.setEmulatorNaviSpeed(120);
|
||||
mAMapNavi.setUseInnerVoice(true, true);
|
||||
// mAMapNavi.stopSpeak();
|
||||
mAimlessModeListener = new AimlessModeListenerAdapter() {
|
||||
};
|
||||
mAMapNavi.addAimlessModeListener(mAimlessModeListener);
|
||||
mAimlessModeStatus = SharedPrefsMgr.getInstance(mContext).getBoolean(KEY_AIMLESS_STATUS, false);
|
||||
}
|
||||
|
||||
public static AimlessClient getInstance(Context context) {
|
||||
if (sInstance == null) {
|
||||
synchronized (AimlessClient.class) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new AimlessClient(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public synchronized void release() {
|
||||
sInstance = null;
|
||||
}
|
||||
|
||||
private boolean checkAMapNavi() {
|
||||
if (mAMapNavi == null) {
|
||||
Logger.e(TAG, "高德导航实例为空!!!");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startAimlessMode() {
|
||||
if (!checkAMapNavi()) {
|
||||
return;
|
||||
}
|
||||
if (mAimlessModeStatus) {
|
||||
mAMapNavi.startAimlessMode(AimLessMode.CAMERA_AND_SPECIALROAD_DETECTED);
|
||||
mAimlessStatus = true;
|
||||
Logger.d(TAG, "开启巡航成功");
|
||||
} else {
|
||||
mAimlessStatus = false;
|
||||
Logger.d(TAG, "开启巡航失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopAimlessMode() {
|
||||
if (!checkAMapNavi()) {
|
||||
return;
|
||||
}
|
||||
mAMapNavi.stopAimlessMode();
|
||||
mAimlessStatus = false;
|
||||
Logger.d(TAG, "关闭巡航成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAimlessModeStatus(boolean open) {
|
||||
this.mAimlessModeStatus = open;
|
||||
SharedPrefsMgr.getInstance(mContext).putBoolean(KEY_AIMLESS_STATUS, open);
|
||||
if (open) {
|
||||
if (!mAimlessStatus) {
|
||||
startAimlessMode();
|
||||
}
|
||||
} else {
|
||||
if (mAimlessStatus) {
|
||||
stopAimlessMode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -44,7 +44,6 @@ public class AimlessModeListenerAdapter implements AimlessModeListener {
|
||||
@Override
|
||||
public void updateAimlessModeCongestionInfo( AimLessModeCongestionInfo aimLessModeCongestionInfo ) {
|
||||
Logger.d( TAG, "updateAimlessModeCongestionInfo " + GsonUtil.jsonFromObject(aimLessModeCongestionInfo));
|
||||
|
||||
MogoCongestionInfo congestionInfo = ObjectUtils.fromAMap( aimLessModeCongestionInfo );
|
||||
if ( congestionInfo != null ) {
|
||||
MogoNaviListenerHandler.getInstance().onUpdateCongestion( congestionInfo );
|
||||
|
||||
@@ -13,12 +13,10 @@ import com.amap.api.navi.model.AMapNaviPath;
|
||||
import com.amap.api.navi.model.NaviLatLng;
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.commons.debug.DebugConfig;
|
||||
import com.mogo.commons.voice.AIAssist;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
import com.mogo.map.impl.amap.AMapWrapper;
|
||||
import com.mogo.map.impl.amap.message.AMapMessageManager;
|
||||
import com.mogo.map.impl.amap.utils.ObjectUtils;
|
||||
import com.mogo.map.navi.IMogoCarLocationChangedListener;
|
||||
import com.mogo.map.navi.IMogoCarLocationChangedListener2;
|
||||
import com.mogo.map.navi.IMogoNavi;
|
||||
import com.mogo.map.navi.MogoCalculatePath;
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.mogo.map.navi;
|
||||
|
||||
/**
|
||||
* @author donghongyu
|
||||
* @since 2020-11-05
|
||||
* <p>
|
||||
* 巡航操作
|
||||
*/
|
||||
public interface IMogoAimless {
|
||||
|
||||
/**
|
||||
* 打开巡航模式
|
||||
*/
|
||||
void startAimlessMode();
|
||||
|
||||
/**
|
||||
* 关闭巡航模式
|
||||
*/
|
||||
void stopAimlessMode();
|
||||
|
||||
/**
|
||||
* 设置巡航模式状态
|
||||
*
|
||||
* @param open
|
||||
*/
|
||||
void setAimlessModeStatus(boolean open);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.mogo.map;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.mogo.map.impl.amap.navi.AimlessClient;
|
||||
import com.mogo.map.navi.IMogoAimless;
|
||||
import com.mogo.map.navi.IMogoNavi;
|
||||
|
||||
/**
|
||||
* @author donghongyu
|
||||
* @since 2020-11-05
|
||||
* <p>
|
||||
* 巡航代理
|
||||
*/
|
||||
public class MogoAimless implements IMogoAimless {
|
||||
|
||||
private IMogoAimless mDelegate;
|
||||
|
||||
private static volatile MogoAimless sInstance;
|
||||
|
||||
private MogoAimless(Context context) {
|
||||
mDelegate = AimlessClient.getInstance(context);
|
||||
}
|
||||
|
||||
public static MogoAimless getInstance(Context context) {
|
||||
if (sInstance == null) {
|
||||
synchronized (MogoAimless.class) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new MogoAimless(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public synchronized void release() {
|
||||
sInstance = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startAimlessMode() {
|
||||
if (mDelegate != null) {
|
||||
mDelegate.startAimlessMode();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopAimlessMode() {
|
||||
if (mDelegate != null) {
|
||||
mDelegate.stopAimlessMode();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAimlessModeStatus(boolean open) {
|
||||
if (mDelegate != null) {
|
||||
mDelegate.setAimlessModeStatus(open);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
package com.mogo.map;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Rect;
|
||||
import android.location.Location;
|
||||
|
||||
|
||||
@@ -8,7 +8,9 @@ import com.alibaba.android.arouter.facade.template.IProvider;
|
||||
import com.mogo.map.navi.IMogoAimlessModeListener;
|
||||
import com.mogo.map.navi.MogoCongestionInfo;
|
||||
import com.mogo.map.navi.MogoTraffic;
|
||||
import com.mogo.module.common.MogoApisHandler;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.utils.network.utils.GsonUtil;
|
||||
|
||||
/**
|
||||
* TODO 高德巡航信息监听,并将拥堵信息上报到服务端
|
||||
@@ -20,9 +22,17 @@ public class GaoDeAimlessProvider implements IProvider {
|
||||
@Override
|
||||
public void init(Context context) {
|
||||
Log.d(TAG, "provider init……");
|
||||
// 开启巡航监听
|
||||
MogoApisHandler.getInstance()
|
||||
.getApis()
|
||||
.getMapServiceApi()
|
||||
.getAimless(context)
|
||||
.setAimlessModeStatus(true);
|
||||
|
||||
// 注册高德巡航回调
|
||||
TanluServiceManager.getIMogoRegisterCenter()
|
||||
MogoApisHandler.getInstance()
|
||||
.getApis()
|
||||
.getRegisterCenterApi()
|
||||
.registerMogoAimlessModeListener(TAG, new IMogoAimlessModeListener() {
|
||||
@Override
|
||||
public void onUpdateTraffic2(MogoTraffic traffic) {
|
||||
@@ -32,6 +42,7 @@ public class GaoDeAimlessProvider implements IProvider {
|
||||
@Override
|
||||
public void onUpdateCongestion(MogoCongestionInfo info) {
|
||||
// TODO 上报给服务器
|
||||
Log.d(TAG, GsonUtil.jsonFromObject(info));
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.content.Context;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.mogo.map.location.IMogoLocationClient;
|
||||
import com.mogo.map.navi.IMogoAimless;
|
||||
import com.mogo.map.search.poisearch.IMogoPoiSearch;
|
||||
import com.mogo.map.search.poisearch.query.MogoPoiSearchQuery;
|
||||
import com.mogo.service.IMogoServiceApis;
|
||||
@@ -31,6 +32,7 @@ public class TanluServiceManager {
|
||||
private static IMogoIntentManager mogoIntentManager;
|
||||
private static IMogoRegisterCenter mogoRegisterCenter;
|
||||
private static IMogoTopViewManager mIMogoTopViewManager;
|
||||
private static IMogoAimless mIMogoAimless;
|
||||
|
||||
public static void init(Context context) {
|
||||
mServiceApis = (IMogoServiceApis) ARouter.getInstance().build(MogoServicePaths.PATH_SERVICE_APIS).navigation(context);
|
||||
@@ -39,6 +41,7 @@ public class TanluServiceManager {
|
||||
mAnalytics = mServiceApis.getAnalyticsApi();
|
||||
mogoIntentManager = mServiceApis.getIntentManagerApi();
|
||||
mogoRegisterCenter = mServiceApis.getRegisterCenterApi();
|
||||
mIMogoAimless = mMapService.getAimless(context);
|
||||
|
||||
mIMogoTopViewManager = mServiceApis.getTopViewManager();
|
||||
mPoiSearch = mMapService.getPoiSearch(context, new MogoPoiSearchQuery());
|
||||
@@ -81,4 +84,7 @@ public class TanluServiceManager {
|
||||
return mServiceApis;
|
||||
}
|
||||
|
||||
public static IMogoAimless getMogoAimless() {
|
||||
return mIMogoAimless;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.mogo.map.IMogoMapViewInstanceHandler;
|
||||
import com.mogo.map.listener.IMogoHosListenerRegister;
|
||||
import com.mogo.map.location.IMogoLocationClient;
|
||||
import com.mogo.map.marker.IMogoMarkerManager;
|
||||
import com.mogo.map.navi.IMogoAimless;
|
||||
import com.mogo.map.navi.IMogoNavi;
|
||||
import com.mogo.map.overlay.IMogoOverlayManager;
|
||||
import com.mogo.map.search.drive.IMogoRoadSearch;
|
||||
@@ -77,6 +78,14 @@ public interface IMogoMapService extends IProvider {
|
||||
*/
|
||||
IMogoNavi getNavi( Context context );
|
||||
|
||||
/**
|
||||
* 获取巡航操作实例
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
IMogoAimless getAimless(Context context);
|
||||
|
||||
/**
|
||||
* marker 操作
|
||||
*
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.content.Context;
|
||||
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.mogo.map.IMogoMapViewInstanceHandler;
|
||||
import com.mogo.map.MogoAimless;
|
||||
import com.mogo.map.MogoGeoSearch;
|
||||
import com.mogo.map.MogoInputtipsSearch;
|
||||
import com.mogo.map.MogoLocationClient;
|
||||
@@ -18,6 +19,7 @@ import com.mogo.map.listener.IMogoHosListenerRegister;
|
||||
import com.mogo.map.listener.MogoHosListenerRegister;
|
||||
import com.mogo.map.location.IMogoLocationClient;
|
||||
import com.mogo.map.marker.IMogoMarkerManager;
|
||||
import com.mogo.map.navi.IMogoAimless;
|
||||
import com.mogo.map.navi.IMogoNavi;
|
||||
import com.mogo.map.overlay.IMogoOverlayManager;
|
||||
import com.mogo.map.search.drive.IMogoRoadSearch;
|
||||
@@ -69,6 +71,11 @@ public class MogoMapService implements IMogoMapService {
|
||||
return MogoNavi.getInstance( context );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoAimless getAimless(Context context) {
|
||||
return MogoAimless.getInstance( context );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoMarkerManager getMarkerManager( Context context ) {
|
||||
return MogoMarkerManager.getInstance( context );
|
||||
|
||||
Reference in New Issue
Block a user