From 735f5a6812af2cb60e3af545542e235caba4e31d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=91=A3=E5=AE=8F=E5=AE=87?= Date: Wed, 28 Oct 2020 16:16:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E6=8E=A8=E9=80=81VR?= =?UTF-8?q?=E7=9A=84=E5=9C=BA=E6=99=AF=E5=A4=84=E7=90=86=EF=BC=8C=E7=9B=AE?= =?UTF-8?q?=E5=89=8D=E6=98=AF=E7=A9=BA=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/entity/V2XMessageEntity.java | 3 + .../v2x/scenario/impl/V2XScenarioManager.java | 4 + .../scene/pushVR/V2XPushVREventMarker.java | 78 ++++++++++ .../scene/pushVR/V2XPushVREventScenario.java | 141 ++++++++++++++++++ .../scene/test/V2XTestConsoleWindow.java | 10 ++ .../module/v2x/utils/TestOnLineCarUtils.java | 33 ++++ 6 files changed, 269 insertions(+) create mode 100644 modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/pushVR/V2XPushVREventMarker.java create mode 100644 modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/pushVR/V2XPushVREventScenario.java diff --git a/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/V2XMessageEntity.java b/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/V2XMessageEntity.java index 3da153adb3..598a4b7658 100644 --- a/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/V2XMessageEntity.java +++ b/modules/mogo-module-common/src/main/java/com/mogo/module/common/entity/V2XMessageEntity.java @@ -139,6 +139,8 @@ public class V2XMessageEntity implements Serializable { int ALERT_ILLEGAL_PARK_WARNING = 1_008; // 呼叫、请求直播事件 int ALERT_VOICE_CALL_FOR_LIVECAR_SHOW = 1_009; + // 推送VR消息展示 + int ALERT_PUSH_VR_SHOW = 2_000; // 自车求助 int ALERT_CAR_FOR_HELP = 8_000; // obu事件 @@ -157,6 +159,7 @@ public class V2XMessageEntity implements Serializable { V2XTypeEnum.ALERT_ILLEGAL_PARK_WARNING, V2XTypeEnum.ALERT_CAR_FOR_HELP, V2XTypeEnum.ALERT_VOICE_CALL_FOR_LIVECAR_SHOW, + V2XTypeEnum.ALERT_PUSH_VR_SHOW, V2XTypeEnum.ALERT_OBU_EVENT, }) @Target({ diff --git a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/impl/V2XScenarioManager.java b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/impl/V2XScenarioManager.java index 5378e38d52..7674b5c9c3 100644 --- a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/impl/V2XScenarioManager.java +++ b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/impl/V2XScenarioManager.java @@ -15,6 +15,7 @@ import com.mogo.module.v2x.scenario.scene.livecar.V2XPushLiveCarScenario; import com.mogo.module.v2x.scenario.scene.livecar.V2XVoiceCallLiveScenario; import com.mogo.module.v2x.scenario.scene.park.V2XIllegalParkScenario; import com.mogo.module.v2x.scenario.scene.push.V2XPushEventScenario; +import com.mogo.module.v2x.scenario.scene.pushVR.V2XPushVREventScenario; import com.mogo.module.v2x.scenario.scene.road.V2XRoadEventScenario; import com.mogo.module.v2x.scenario.scene.seek.V2XSeekHelpScenario; import com.mogo.module.v2x.utils.V2XUtils; @@ -99,6 +100,9 @@ public class V2XScenarioManager implements IV2XScenarioManager { case V2XMessageEntity.V2XTypeEnum.ALERT_VOICE_CALL_FOR_LIVECAR_SHOW: mV2XScenario = V2XVoiceCallLiveScenario.getInstance(); break; + case V2XMessageEntity.V2XTypeEnum.ALERT_PUSH_VR_SHOW: + mV2XScenario = V2XPushVREventScenario.getInstance(); + break; default: Logger.e(MODULE_NAME, "当前V2X消息类型未定义。"); TipToast.tip("当前V2X消息类型未定义"); diff --git a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/pushVR/V2XPushVREventMarker.java b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/pushVR/V2XPushVREventMarker.java new file mode 100644 index 0000000000..f0c145d8d4 --- /dev/null +++ b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/pushVR/V2XPushVREventMarker.java @@ -0,0 +1,78 @@ +package com.mogo.module.v2x.scenario.scene.pushVR; + +import com.mogo.module.common.entity.MarkerExploreWay; +import com.mogo.module.common.entity.MarkerExploreWayItem; +import com.mogo.module.common.entity.MarkerLocation; +import com.mogo.module.common.entity.V2XPoiTypeEnum; +import com.mogo.module.common.entity.V2XPushMessageEntity; +import com.mogo.module.common.entity.V2XRoadEventEntity; +import com.mogo.module.v2x.V2XServiceManager; +import com.mogo.module.v2x.listener.V2XMarkerClickListener; +import com.mogo.module.v2x.scenario.view.IV2XMarker; +import com.mogo.module.v2x.utils.MarkerUtils; + +import java.util.ArrayList; +import java.util.List; + +/** + * author : donghongyu + * e-mail : 1358506549@qq.com + * date : 2020/5/15 5:37 PM + * desc : 推送VR场景 + * version: 1.0 + */ +public class V2XPushVREventMarker implements IV2XMarker { + @Override + public void drawPOI(V2XPushMessageEntity entity) { + try { + // 清除道路事件 + V2XServiceManager + .getMoGoV2XMarkerManager().clearALLPOI(); + + // 位置信息 + MarkerLocation markerLocation = new MarkerLocation(); + markerLocation.setLon(entity.getLon()); + markerLocation.setLat(entity.getLat()); + + // 进行数据转换,用于Marker展示 + V2XRoadEventEntity v2XRoadEventEntity = new V2XRoadEventEntity(); + v2XRoadEventEntity.setLocation(markerLocation); + // 探路目前只有上报拥堵 + v2XRoadEventEntity.setPoiType(V2XPoiTypeEnum.ALERT_TRAFFIC_EXPRESS); + + MarkerExploreWay markerNoveltyInfo = new MarkerExploreWay(); + + List items = new ArrayList<>(); + MarkerExploreWayItem exploreWayItem = new MarkerExploreWayItem(); + exploreWayItem.setThumbnail(entity.getMsgImgUrl()); + items.add(exploreWayItem); + markerNoveltyInfo.setPoiType(V2XPoiTypeEnum.ALERT_TRAFFIC_EXPRESS); + markerNoveltyInfo.setItems(items); + markerNoveltyInfo.setUploadType("1"); + + v2XRoadEventEntity.setNoveltyInfo(markerNoveltyInfo); + v2XRoadEventEntity.setExpireTime(20000); + + V2XServiceManager + .getMoGoV2XMarkerManager() + .drawableAlarmPOI(V2XServiceManager.getContext(), + v2XRoadEventEntity, + V2XMarkerClickListener.getInstance()); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Override + public void clearPOI() { + // 锁车就是将地图视图移植中心点,因为行驶中的车和地图要相对的跟随 + MarkerUtils.resetMapZoom(16); + // 移除线 + V2XServiceManager.getMoGoV2XPolylineManager().clearLine(); + // 移除事件POI + V2XServiceManager.getMoGoV2XMarkerManager().clearAlarmPOI(); + // 绘制上次的数据 + V2XServiceManager.getMoGoV2XMarkerManager().drawableLastAllPOI(); + } +} diff --git a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/pushVR/V2XPushVREventScenario.java b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/pushVR/V2XPushVREventScenario.java new file mode 100644 index 0000000000..3defbed3f0 --- /dev/null +++ b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/pushVR/V2XPushVREventScenario.java @@ -0,0 +1,141 @@ +package com.mogo.module.v2x.scenario.scene.pushVR; + +import android.view.View; + +import androidx.annotation.Nullable; + +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.V2XServiceManager; +import com.mogo.module.v2x.scenario.impl.AbsV2XScenario; +import com.mogo.service.windowview.IMogoTopViewStatusListener; +import com.mogo.utils.logger.Logger; +import com.mogo.utils.network.utils.GsonUtil; + +import static com.mogo.module.v2x.V2XConst.MODULE_NAME; + +/** + * author : donghongyu + * e-mail : 1358506549@qq.com + * date : 2020/5/15 5:37 PM + * desc : 推送VR场景控制 + * version: 1.0 + */ +public class V2XPushVREventScenario + extends AbsV2XScenario + implements IMogoTopViewStatusListener { + + private static V2XPushVREventScenario mV2XPushEventScenario; + + private V2XPushVREventScenario() { + } + + public static V2XPushVREventScenario getInstance() { + if (mV2XPushEventScenario == null) { + synchronized (V2XPushVREventScenario.class) { + if (mV2XPushEventScenario == null) { + mV2XPushEventScenario = new V2XPushVREventScenario(); + mV2XPushEventScenario.setV2XMarker(new V2XPushVREventMarker()); + } + } + } + return mV2XPushEventScenario; + } + + + @Override + public void init(@Nullable V2XMessageEntity v2XMessageEntity) { + Logger.w(MODULE_NAME, "处理推送VR场景:" + GsonUtil.jsonFromObject(v2XMessageEntity)); + + if (!isSameScenario(v2XMessageEntity) + && V2XServiceManager.getMoGoStatusManager().isMainPageLaunched()) { + setV2XMessageEntity(v2XMessageEntity); + show(); + } else { + setV2XMessageEntity(v2XMessageEntity); + Logger.w(V2XConst.MODULE_NAME, "要处理的场景已经存在,丢弃这次初始化"); + } + } + + @Override + public void show() { + if (getV2XMessageEntity() != null && getV2XMessageEntity().getContent() != null) { + speakTTSVoice(getV2XMessageEntity().getContent().getTts(), null); + drawPOI(); + showWindow(); + } + } + + @Override + public void showWindow() { + if (getV2XWindow() != null) { + //TODO 这里调用 showLeftNoticeByType 进行展示左下角的弹窗 + } + } + + @Override + public void closeWindow() { + V2XServiceManager.getMoGoV2XStatusManager().setPushWindowShow(TAG, false); + if (getV2XWindow() != null) { + getV2XWindow().close(); + } + } + + @Override + public void showButton() { + if (getV2XButton() != null) { + getV2XButton().show(); + } + } + + @Override + public void closeButton() { + if (getV2XButton() != null) { + getV2XButton().close(); + } + } + + @Override + public void drawPOI() { + if (getV2XMarker() != null) { + getV2XMarker().drawPOI(getV2XMessageEntity().getContent()); + V2XServiceManager.getMoGoV2XStatusManager().setPushPOIShow(TAG, true); + } + } + + @Override + public void clearPOI() { + if (getV2XMarker() != null) { + getV2XMarker().clearPOI(); + } + V2XServiceManager.getMoGoV2XStatusManager().setPushPOIShow(TAG, false); + } + + //////////////////////////////////////////////////////////////////////////////////////////////////// + @Override + public void onViewAdded(View view) { + Logger.d(MODULE_NAME, "展示 Window 动画结束"); + } + + @Override + public void onViewRemoved(View view) { + Logger.d(MODULE_NAME, "关闭 Window 动画结束"); + } + + @Override + public void beforeViewAddAnim(View view) { + Logger.d(MODULE_NAME, "展示 Window 开始"); + } + + @Override + public void beforeViewRemoveAnim(View view) { + Logger.d(MODULE_NAME, "关闭 Window 开始"); + V2XServiceManager.getMoGoV2XStatusManager().setPushWindowShow(TAG, false); + // 重置场景提示的消息 + setV2XMessageEntity(null); + clearPOI(); + } + //////////////////////////////////////////////////////////////////////////////////////////////////// + +} diff --git a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/test/V2XTestConsoleWindow.java b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/test/V2XTestConsoleWindow.java index 3c886f4d0a..f9b6b10033 100644 --- a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/test/V2XTestConsoleWindow.java +++ b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/test/V2XTestConsoleWindow.java @@ -206,6 +206,16 @@ public class V2XTestConsoleWindow extends ConstraintLayout { LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent); }); + + btnTriggerCongestedRouteRecommendation.setOnClickListener(v -> { + V2XMessageEntity v2XMessageEntity = + TestOnLineCarUtils.getV2XScenarioPushVR(); + + Intent intent = new Intent(V2XConst.BROADCAST_SCENE_HANDLER_ACTION); + intent.putExtra(V2XConst.BROADCAST_SCENE_EXTRA_KEY, v2XMessageEntity); + LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent); + }); + } } diff --git a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/utils/TestOnLineCarUtils.java b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/utils/TestOnLineCarUtils.java index 350b76c6d6..d1dbaf1236 100644 --- a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/utils/TestOnLineCarUtils.java +++ b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/utils/TestOnLineCarUtils.java @@ -357,4 +357,37 @@ public class TestOnLineCarUtils { } return null; } + + /** + * 模拟H5推送场景---推送VR场景信息 + */ + public static V2XMessageEntity getV2XScenarioPushVR() { + try { + InputStream inputStream = V2XUtils.getApp() + .getResources() + .openRawResource(R.raw.scenario_push_vr_event_data_yongdu); + 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(); + + // 加载数据源 + V2XPushMessageEntity v2xRoadEventEntity = GsonUtil.objectFromJson(baos.toString(), V2XPushMessageEntity.class); + + V2XMessageEntity 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; + } }