完成了最优路线推荐功能与服务器数据联动
This commit is contained in:
@@ -1,8 +1,18 @@
|
||||
package com.mogo.module.v2x.listener;
|
||||
|
||||
import android.content.Intent;
|
||||
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
|
||||
import com.mogo.module.common.entity.V2XMessageEntity;
|
||||
import com.mogo.module.common.entity.V2XPushMessageEntity;
|
||||
import com.mogo.module.v2x.V2XConst;
|
||||
import com.mogo.module.v2x.entity.net.V2XOptimalRouteDataRes;
|
||||
import com.mogo.module.v2x.utils.TestOnLineCarUtils;
|
||||
import com.mogo.module.v2x.utils.V2XUtils;
|
||||
import com.mogo.service.connection.IMogoOnMessageListener;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.mogo.utils.network.utils.GsonUtil;
|
||||
|
||||
import static com.mogo.module.v2x.V2XConst.MODULE_NAME;
|
||||
|
||||
@@ -20,6 +30,24 @@ public class V2XMessageListener_401019 implements IMogoOnMessageListener<V2XOpti
|
||||
@Override
|
||||
public void onMsgReceived(V2XOptimalRouteDataRes message) {
|
||||
Logger.i(MODULE_NAME, "V2XMessageListener_401019:" + message);
|
||||
// 将接收到的数据转换成最优车道推荐的场景数据
|
||||
|
||||
if (message != null
|
||||
&& message.getLocus_list() != null
|
||||
&& !message.getLocus_list().isEmpty()) {
|
||||
|
||||
V2XMessageEntity<V2XOptimalRouteDataRes> v2xMessageEntity = new V2XMessageEntity<>();
|
||||
// 控制类型
|
||||
v2xMessageEntity.setType(V2XMessageEntity.V2XTypeEnum.ALERT_PUSH_VR_SHOW);
|
||||
// 设置数据
|
||||
v2xMessageEntity.setContent(message);
|
||||
// 控制展示状态
|
||||
v2xMessageEntity.setShowState(true);
|
||||
|
||||
Intent intent = new Intent(V2XConst.BROADCAST_SCENE_HANDLER_ACTION);
|
||||
intent.putExtra(V2XConst.BROADCAST_SCENE_EXTRA_KEY, v2xMessageEntity);
|
||||
LocalBroadcastManager.getInstance(V2XUtils.getApp()).sendBroadcast(intent);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.mogo.module.v2x.observer;
|
||||
|
||||
import com.mogo.map.MogoLatLng;
|
||||
import com.mogo.map.location.MogoLocation;
|
||||
import com.mogo.module.v2x.overlay.V2XOptimalRouteOverlay;
|
||||
|
||||
@@ -17,7 +18,7 @@ public class V2XOptimalRouteObserver extends CarLocationObserver {
|
||||
//最优路线覆盖物绘制
|
||||
private V2XOptimalRouteOverlay mV2XOptimalRouteOverlay;
|
||||
// 要绘制的数据
|
||||
private List<double[]> polylinePoint;
|
||||
private List<MogoLatLng> polylinePoint;
|
||||
|
||||
public static V2XOptimalRouteObserver getInstance() {
|
||||
if (v2XOptimalRouteObserver == null) {
|
||||
@@ -39,7 +40,7 @@ public class V2XOptimalRouteObserver extends CarLocationObserver {
|
||||
*
|
||||
* @param polylinePoint 推荐的路线
|
||||
*/
|
||||
public void setPolylinePoint(List<double[]> polylinePoint) {
|
||||
public void setPolylinePoint(List<MogoLatLng> polylinePoint) {
|
||||
this.polylinePoint = polylinePoint;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ public class V2XOptimalRouteOverlay {
|
||||
*
|
||||
* @param polylinePoint 要绘制的经纬度度集合
|
||||
*/
|
||||
public IMogoPolyline draw(MogoLocation carLocal, List<double[]> polylinePoint) {
|
||||
public IMogoPolyline draw(MogoLocation carLocal, List<MogoLatLng> polylinePoint) {
|
||||
if (mMoGoPolyline != null) {
|
||||
mMoGoPolyline.remove();
|
||||
mPolylinePointList.clear();
|
||||
@@ -48,11 +48,10 @@ public class V2XOptimalRouteOverlay {
|
||||
// 将当前车辆位置放进去
|
||||
mPolylinePointList.add(new MogoLatLng(carLocal.getLatitude(), carLocal.getLongitude()));
|
||||
// 过滤后台推送的推荐路线集合
|
||||
for (double[] polyline : polylinePoint) {
|
||||
MogoLatLng pointMoGoLatLng = new MogoLatLng(polyline[1], polyline[0]);
|
||||
for (MogoLatLng polyline : polylinePoint) {
|
||||
//需要剔除已经行驶过的经纬度,这里需要比对推荐路线集合中的点是否在当前车辆行驶方向前面如果不在则抛弃
|
||||
if (LocationUtils.isPointOnCarFront(carLocal, pointMoGoLatLng)) {
|
||||
mPolylinePointList.add(pointMoGoLatLng);
|
||||
if (LocationUtils.isPointOnCarFront(carLocal, polyline)) {
|
||||
mPolylinePointList.add(polyline);
|
||||
}
|
||||
}
|
||||
// 替换路径集合
|
||||
|
||||
@@ -104,11 +104,6 @@ public class V2XScenarioManager implements IV2XScenarioManager {
|
||||
mV2XScenario = new V2XRecommendRouteScenario();
|
||||
break;
|
||||
case V2XMessageEntity.V2XTypeEnum.ALERT_PUSH_VR_SHOW:
|
||||
// if (V2XServiceManager.getMoGoStatusManager().isVrMode()) {
|
||||
//
|
||||
// } else {
|
||||
// mV2XScenario = null;
|
||||
// }
|
||||
mV2XScenario = new V2XOptimalRouteVREventScenario();
|
||||
break;
|
||||
case V2XMessageEntity.V2XTypeEnum.ALERT_THE_FRONT_CRASH_WARNING_TOP:
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.mogo.module.v2x.scenario.scene.route;
|
||||
import com.mogo.module.common.entity.V2XPushMessageEntity;
|
||||
import com.mogo.module.v2x.V2XConst;
|
||||
import com.mogo.module.v2x.V2XServiceManager;
|
||||
import com.mogo.module.v2x.entity.net.V2XOptimalRouteDataRes;
|
||||
import com.mogo.module.v2x.observer.V2XOptimalRouteObserver;
|
||||
import com.mogo.module.v2x.scenario.view.IV2XMarker;
|
||||
import com.mogo.module.v2x.utils.MarkerUtils;
|
||||
@@ -15,11 +16,11 @@ import com.mogo.utils.logger.Logger;
|
||||
* desc : 推送VR场景
|
||||
* version: 1.0
|
||||
*/
|
||||
public class V2XOptimalRouteVREventMarker implements IV2XMarker<V2XPushMessageEntity> {
|
||||
public class V2XOptimalRouteVREventMarker implements IV2XMarker<V2XOptimalRouteDataRes> {
|
||||
private final String TAG = "V2XPushVREventMarker";
|
||||
|
||||
@Override
|
||||
public void drawPOI(V2XPushMessageEntity entity) {
|
||||
public void drawPOI(V2XOptimalRouteDataRes entity) {
|
||||
Logger.w(V2XConst.MODULE_NAME + "_" + TAG, "drawPOI 绘制VR Marker");
|
||||
|
||||
try {
|
||||
@@ -27,21 +28,13 @@ public class V2XOptimalRouteVREventMarker implements IV2XMarker<V2XPushMessageEn
|
||||
V2XServiceManager
|
||||
.getMoGoV2XMarkerManager().clearALLPOI();
|
||||
// 绘制引导线
|
||||
drawableRecommendPolyline(entity);
|
||||
V2XOptimalRouteObserver.getInstance()
|
||||
.setPolylinePoint(entity.getLocus_list());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 绘制推荐引导线
|
||||
*
|
||||
* @param entity
|
||||
*/
|
||||
void drawableRecommendPolyline(V2XPushMessageEntity entity) {
|
||||
V2XOptimalRouteObserver.getInstance().setPolylinePoint(entity.getRecommendPolyline());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearPOI() {
|
||||
// 锁车就是将地图视图移植中心点,因为行驶中的车和地图要相对的跟随
|
||||
|
||||
@@ -6,10 +6,10 @@ import android.view.ViewGroup;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.mogo.module.common.entity.V2XMessageEntity;
|
||||
import com.mogo.module.common.entity.V2XPushMessageEntity;
|
||||
import com.mogo.module.v2x.R;
|
||||
import com.mogo.module.v2x.V2XConst;
|
||||
import com.mogo.module.v2x.V2XServiceManager;
|
||||
import com.mogo.module.v2x.entity.net.V2XOptimalRouteDataRes;
|
||||
import com.mogo.module.v2x.scenario.impl.AbsV2XScenario;
|
||||
import com.mogo.module.v2x.utils.V2XUtils;
|
||||
import com.mogo.service.windowview.IMogoTopViewStatusListener;
|
||||
@@ -25,7 +25,7 @@ import com.mogo.utils.network.utils.GsonUtil;
|
||||
* wiki : http://wiki.zhidaohulian.com/pages/viewpage.action?pageId=52829799
|
||||
*/
|
||||
public class V2XOptimalRouteVREventScenario
|
||||
extends AbsV2XScenario<V2XPushMessageEntity>
|
||||
extends AbsV2XScenario<V2XOptimalRouteDataRes>
|
||||
implements IMogoTopViewStatusListener {
|
||||
private String TAG = "V2XPushVREventWindow";
|
||||
|
||||
@@ -35,7 +35,7 @@ public class V2XOptimalRouteVREventScenario
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(@Nullable V2XMessageEntity<V2XPushMessageEntity> v2XMessageEntity) {
|
||||
public void init(@Nullable V2XMessageEntity<V2XOptimalRouteDataRes> v2XMessageEntity) {
|
||||
Logger.w(V2XConst.MODULE_NAME + "_" + TAG, "处理推送VR:" + GsonUtil.jsonFromObject(v2XMessageEntity));
|
||||
|
||||
if (!isSameScenario(v2XMessageEntity)
|
||||
@@ -53,7 +53,7 @@ public class V2XOptimalRouteVREventScenario
|
||||
@Override
|
||||
public void show() {
|
||||
if (getV2XMessageEntity() != null && getV2XMessageEntity().getContent() != null) {
|
||||
speakTTSVoice(getV2XMessageEntity().getContent().getTts(), null);
|
||||
speakTTSVoice("已为您选择最优路线", null);
|
||||
drawPOI();
|
||||
showWindow();
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@ import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
||||
import com.mogo.module.common.entity.V2XPushMessageEntity;
|
||||
import com.mogo.module.v2x.R;
|
||||
import com.mogo.module.v2x.V2XServiceManager;
|
||||
import com.mogo.module.v2x.entity.net.V2XOptimalRouteDataRes;
|
||||
import com.mogo.module.v2x.listener.V2XWindowStatusListener;
|
||||
import com.mogo.module.v2x.scenario.scene.V2XBasWindow;
|
||||
import com.mogo.module.v2x.scenario.view.IV2XWindow;
|
||||
@@ -24,7 +24,9 @@ import static com.mogo.module.v2x.V2XConst.MODULE_NAME;
|
||||
* TODO 只有VR演示场景使用
|
||||
* version: 1.0
|
||||
*/
|
||||
public class V2XOptimalRouteVREventWindow extends V2XBasWindow implements IV2XWindow<V2XPushMessageEntity> {
|
||||
public class V2XOptimalRouteVREventWindow
|
||||
extends V2XBasWindow
|
||||
implements IV2XWindow<V2XOptimalRouteDataRes> {
|
||||
private String TAG = "V2XPushVREventWindow";
|
||||
|
||||
// 处理道路事件,30秒倒计时
|
||||
@@ -54,8 +56,7 @@ public class V2XOptimalRouteVREventWindow extends V2XBasWindow implements IV2XWi
|
||||
* 展示道路事件详情Windows
|
||||
*/
|
||||
@Override
|
||||
public void show(V2XPushMessageEntity entity) {
|
||||
Logger.d(MODULE_NAME + "_" + TAG, "V2X==VR=推送消息:展示 Window=\n" + entity);
|
||||
public void show(V2XOptimalRouteDataRes entity) {
|
||||
|
||||
countDownV2XEvent();
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.mogo.module.v2x.R;
|
||||
import com.mogo.module.v2x.V2XConst;
|
||||
import com.mogo.module.v2x.V2XServiceManager;
|
||||
import com.mogo.module.v2x.alarm.V2XAlarmServer;
|
||||
import com.mogo.module.v2x.entity.net.V2XOptimalRouteDataRes;
|
||||
import com.mogo.module.v2x.entity.net.V2XSpecialCarRes;
|
||||
import com.mogo.module.v2x.scenario.scene.livecar.V2XVoiceCallLiveBiz;
|
||||
import com.mogo.module.v2x.utils.TestOnLineCarUtils;
|
||||
@@ -378,8 +379,8 @@ public class V2XTestConsoleWindow extends ConstraintLayout {
|
||||
*拥堵路线推荐
|
||||
* */
|
||||
btnTriggerCongestedRouteRecommendation.setOnClickListener(v -> {
|
||||
V2XMessageEntity<V2XPushMessageEntity> v2XMessageEntity =
|
||||
TestOnLineCarUtils.getV2XScenarioPushVR();
|
||||
V2XMessageEntity<V2XOptimalRouteDataRes> v2XMessageEntity =
|
||||
TestOnLineCarUtils.getV2XOptimalRoute();
|
||||
|
||||
Intent intent = new Intent(V2XConst.BROADCAST_SCENE_HANDLER_ACTION);
|
||||
intent.putExtra(V2XConst.BROADCAST_SCENE_EXTRA_KEY, v2XMessageEntity);
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.mogo.module.common.entity.V2XRoadEventEntity;
|
||||
import com.mogo.module.common.entity.V2XWarningEntity;
|
||||
import com.mogo.module.v2x.R;
|
||||
import com.mogo.module.v2x.V2XConst;
|
||||
import com.mogo.module.v2x.entity.net.V2XOptimalRouteDataRes;
|
||||
import com.mogo.module.v2x.entity.net.V2XSpecialCarRes;
|
||||
import com.mogo.utils.network.utils.GsonUtil;
|
||||
|
||||
@@ -455,4 +456,37 @@ public class TestOnLineCarUtils {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 模拟最优路线推送
|
||||
*/
|
||||
public static V2XMessageEntity<V2XOptimalRouteDataRes> getV2XOptimalRoute() {
|
||||
try {
|
||||
InputStream inputStream = V2XUtils.getApp()
|
||||
.getResources()
|
||||
.openRawResource(R.raw.scenario_push_vr_event_data_yongdu_gongsi_1);
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
int len = -1;
|
||||
byte[] buffer = new byte[1024];
|
||||
while ((len = inputStream.read(buffer)) != -1) {
|
||||
baos.write(buffer, 0, len);
|
||||
}
|
||||
inputStream.close();
|
||||
|
||||
// 加载数据源
|
||||
V2XOptimalRouteDataRes v2xRoadEventEntity = GsonUtil.objectFromJson(baos.toString(), V2XOptimalRouteDataRes.class);
|
||||
|
||||
V2XMessageEntity<V2XOptimalRouteDataRes> v2xMessageEntity = new V2XMessageEntity<>();
|
||||
// 控制类型
|
||||
v2xMessageEntity.setType(V2XMessageEntity.V2XTypeEnum.ALERT_PUSH_VR_SHOW);
|
||||
// 设置数据
|
||||
v2xMessageEntity.setContent(v2xRoadEventEntity);
|
||||
// 控制展示状态
|
||||
v2xMessageEntity.setShowState(true);
|
||||
return v2xMessageEntity;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user