Merge remote-tracking branch 'origin/dev_merge_shunyi_vr_map' into dev_merge_shunyi_vr_map

# Conflicts:
#	libraries/map-custom/build.gradle
#	modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/navi/BaseNaviInfoView.java
This commit is contained in:
wangcongtao
2020-12-13 11:06:21 +08:00
117 changed files with 2217 additions and 1155 deletions

View File

@@ -48,13 +48,16 @@ import com.mogo.module.common.map.Scene;
import com.mogo.module.common.view.OnPreventFastClickListener;
import com.mogo.module.extensions.ExtensionsModuleConst;
import com.mogo.module.extensions.R;
import com.mogo.module.extensions.navi.BaseNaviInfoView;
import com.mogo.module.extensions.navi.NaviInfoView;
import com.mogo.module.extensions.navi.VrModeNavInfoView;
import com.mogo.module.extensions.userinfo.UserInfo;
import com.mogo.module.extensions.utils.AdasNoticeHelper;
import com.mogo.module.extensions.utils.EntranceViewHolder;
import com.mogo.module.extensions.utils.NoMapTopViewShaderHelper;
import com.mogo.module.extensions.utils.TopViewAnimHelper;
import com.mogo.module.extensions.utils.TopViewNoLinkageAnimHelper;
import com.mogo.module.extensions.utils.TrafficLightPanelManager;
import com.mogo.module.share.manager.ServiceApisManager;
import com.mogo.service.IMogoServiceApis;
import com.mogo.service.analytics.IMogoAnalytics;
@@ -120,7 +123,7 @@ public class EntranceFragment extends MvpFragment<EntranceView, EntrancePresente
private ImageButton mMove2CurrentLocation;
private NaviInfoView mNaviInfo;
private BaseNaviInfoView mNaviInfo;
private TextView mExitNavi;
@@ -369,8 +372,7 @@ public class EntranceFragment extends MvpFragment<EntranceView, EntrancePresente
R.dimen.module_map_display_overview_bottom_margin)
);
mNaviInfo = new NaviInfoView();
mNaviInfo.inflate(rootView);
mNaviInfo = new NaviInfoView(rootView);
findViewById(R.id.module_map_id_navi_bg).setOnClickListener(new OnPreventFastClickListener() {
@Override
@@ -440,14 +442,16 @@ public class EntranceFragment extends MvpFragment<EntranceView, EntrancePresente
tvEnterVrMode.setOnClickListener((v)->{
// 进入vr模式
enterVrMode();
mApis.getMapFrameControllerApi().changeToVRMode();
mApis.getStatusManagerApi().setVrMode(TAG, true);
// mApis.getMapFrameControllerApi().changeToVRMode();
});
tvExitVrMode = findViewById(R.id.module_ext_exit_vr_mode);
tvExitVrMode.setOnClickListener((v)->{
// 退出vr模式
exitVrMode();
mApis.getMapFrameControllerApi().changeTo2dMode();
mApis.getStatusManagerApi().setVrMode(TAG, false);
// mApis.getMapFrameControllerApi().changeTo2dMode();
});
dealWeatherContainer();
@@ -480,6 +484,8 @@ public class EntranceFragment extends MvpFragment<EntranceView, EntrancePresente
e.printStackTrace();
}
});
TrafficLightPanelManager.getInstance().initPanel(mRootView);
}
private EditText etTimes;
@@ -491,10 +497,15 @@ public class EntranceFragment extends MvpFragment<EntranceView, EntrancePresente
mUploadRoadCondition.setVisibility(View.GONE);
mWeatherContainer.setVisibility(View.GONE);
mMsgContainer.setVisibility(View.GONE);
groupUserHead.setVisibility(View.GONE);
tvExitVrMode.setVisibility(View.VISIBLE);
TopViewAnimHelper.getInstance().enterVrMode();
TopViewNoLinkageAnimHelper.getInstance().enterVrMode();
showVrModeNaviView();
mNaviInfo = new VrModeNavInfoView(mRootView);
adasNoticeHelper.enterVrMode();
TrafficLightPanelManager.getInstance().showNavPanel();
}
private void exitVrMode(){
@@ -502,13 +513,17 @@ public class EntranceFragment extends MvpFragment<EntranceView, EntrancePresente
tvEnterVrMode.setVisibility(View.VISIBLE);
mMove2CurrentLocation.setVisibility(View.VISIBLE);
mUploadRoadCondition.setVisibility(View.VISIBLE);
groupUserHead.setVisibility(View.VISIBLE);
// mWeatherContainer.setVisibility(View.VISIBLE);
// mMsgContainer.setVisibility(View.VISIBLE);
tvExitVrMode.setVisibility(View.GONE);
TopViewAnimHelper.getInstance().exitVrMode();
TopViewNoLinkageAnimHelper.getInstance().exitVrMode();
hideVrModeNaviView();
mNaviInfo = new NaviInfoView(mRootView);
adasNoticeHelper.exitVrMode();
TrafficLightPanelManager.getInstance().hideNavPanel();
}
private void debugCrashWarn(){
@@ -1209,5 +1224,15 @@ public class EntranceFragment extends MvpFragment<EntranceView, EntrancePresente
}
mApis.getSocketManagerApi(getContext()).unregisterOnMessageListener(SEEK_HELP_NOTICE_NUM_MSG_TYPE, seekHelpNoticeListener);
}
TrafficLightPanelManager.getInstance().release();
}
private void showVrModeNaviView(){
}
private void hideVrModeNaviView(){
}
}

View File

@@ -1,5 +1,6 @@
package com.mogo.module.extensions.navi;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
@@ -16,10 +17,12 @@ import java.util.Calendar;
*/
public abstract class BaseNaviInfoView {
public void notifyChanged( MogoNaviInfo naviInfo ) {
public BaseNaviInfoView(View view) {
}
public abstract void notifyChanged( MogoNaviInfo naviInfo );
protected void fillNextCrossIconType( ImageView target, int iconId ) {
if ( iconId > 0 ) {
target.setImageResource( iconId );
@@ -143,4 +146,6 @@ public abstract class BaseNaviInfoView {
}
builder.append( "到达" );
}
public abstract boolean isVisible();
}

View File

@@ -26,7 +26,8 @@ public class NaviInfoView extends BaseNaviInfoView {
private TextView remainingTimeUnit;
private TextView arriveTime;
public void inflate( View view ) {
public NaviInfoView(View view) {
super(view);
turnIcon = view.findViewById( R.id.module_map_id_navi_next_info_road_turn_icon );
distance = view.findViewById( R.id.module_map_id_navi_next_info_distance );
distanceUnit = view.findViewById( R.id.module_map_id_navi_next_info_distance_unit );
@@ -39,6 +40,7 @@ public class NaviInfoView extends BaseNaviInfoView {
arriveTime = view.findViewById( R.id.module_map_id_arrive_time );
}
@Override
public boolean isVisible() {
return turnIcon != null && turnIcon.getVisibility() == View.VISIBLE;
}
@@ -46,7 +48,6 @@ public class NaviInfoView extends BaseNaviInfoView {
@Override
public void notifyChanged( MogoNaviInfo naviInfo ) {
super.notifyChanged( naviInfo );
if ( naviInfo == null ) {
return;
}

View File

@@ -0,0 +1,25 @@
package com.mogo.module.extensions.navi;
import android.view.View;
import com.mogo.map.navi.MogoNaviInfo;
/**
* vr模式下导航信息封装
*
* @author tongchenfei
*/
public class VrModeNavInfoView extends BaseNaviInfoView {
public VrModeNavInfoView(View view) {
super(view);
}
@Override
public boolean isVisible() {
return true;
}
@Override
public void notifyChanged(MogoNaviInfo naviInfo) {
}
}

View File

@@ -6,23 +6,18 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import com.mogo.map.location.IMogoLocationListener;
import com.mogo.map.location.MogoLocation;
import com.mogo.map.navi.MogoTraffic;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.entity.CloudRoadData;
import com.mogo.module.common.entity.MogoSnapshotSetData;
import com.mogo.module.extensions.R;
import com.mogo.service.adas.IMogoAdasWarnMessageCallback;
import com.mogo.service.adas.MogoADASWarnType;
import com.mogo.service.adas.entity.ADASWarnMessage;
import com.mogo.service.connection.IMogoOnWebSocketMessageListener;
import com.mogo.service.connection.WebSocketMsgType;
import com.mogo.service.entrance.IMogoEntranceButtonController;
import com.mogo.utils.logger.Logger;
import org.json.JSONObject;
@@ -50,8 +45,6 @@ public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback, IMogoLoca
private volatile boolean isVrMode = false;
private TextView tvSelfSpeed, tvTrafficLight, tvLimitSpeed;
private int limitSpeed = -1;
private int currentSpeed = 0;
private String lightStatus = "G";
@@ -61,26 +54,18 @@ public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback, IMogoLoca
private boolean isObuLightData = false;
private View selfCar;
private boolean lightCenter = true;
public void init(Context context) {
this.context = context;
if(!lightCenter) {
selfCar = LayoutInflater.from(context).inflate(R.layout.module_ext_item_self_car, null);
tvSelfSpeed = selfCar.findViewById(R.id.tvSelfSpeed);
tvTrafficLight = selfCar.findViewById(R.id.tvTrafficLight);
tvLimitSpeed = selfCar.findViewById(R.id.tvLimitSpeed);
if (!lightCenter) {
}
Logger.d(TAG, "init====");
}
public void initView(View root) {
if(lightCenter) {
tvSelfSpeed = root.findViewById(R.id.tvSelfSpeed);
tvTrafficLight = root.findViewById(R.id.tvTrafficLight);
tvLimitSpeed = root.findViewById(R.id.tvLimitSpeed);
if (lightCenter) {
}
}
@@ -88,13 +73,15 @@ public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback, IMogoLoca
Logger.d(TAG, "enterVrMode===" + isVrMode);
if (!isVrMode) {
isVrMode = true;
MogoApisHandler.getInstance().getApis().getAdasControllerApi().closeADAS();
IntentFilter filter = new IntentFilter("com.mogo.launcher.adas.app.biz");
filter.addAction("com.mogo.launcher.adas");
context.registerReceiver(adasReceiver, filter);
MogoApisHandler.getInstance().getApis().getAdasControllerApi().addAdasWarnMessageCallback(this);
MogoApisHandler.getInstance().getApis().getRegisterCenterApi().registerMogoLocationListener(TAG, this);
MogoApisHandler.getInstance().getApis().getWebSocketManagerApi(context).registerOnWebSocketMessageListener(this);
if(!lightCenter) {
if (!lightCenter) {
handler.sendEmptyMessageDelayed(MSG_REFRESH_CAR_STRATEGY, STRATEGY_DELAY);
}
}
@@ -104,10 +91,8 @@ public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback, IMogoLoca
Logger.d(TAG, "退出vr模式===" + isVrMode);
if (isVrMode) {
isVrMode = false;
MogoApisHandler.getInstance().getApis().getAdasControllerApi().showADAS();
handler.removeMessages(MSG_REFRESH_CAR_STRATEGY);
tvSelfSpeed.setVisibility(View.GONE);
tvTrafficLight.setVisibility(View.GONE);
tvLimitSpeed.setVisibility(View.GONE);
MogoApisHandler.getInstance().getApis().getAdasControllerApi().removeAdasWarnMessageCallback(this);
MogoApisHandler.getInstance().getApis().getRegisterCenterApi().unregisterMogoLocationListener(TAG);
MogoApisHandler.getInstance().getApis().getWebSocketManagerApi(context).unregisterOnWebSocketMessageListener(this);
@@ -130,18 +115,7 @@ public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback, IMogoLoca
}
}
private void drawLimitSpeed(){
if (tvLimitSpeed != null) {
tvLimitSpeed.post(() -> {
handler.removeMessages(MSG_HIDE_LIMIT_SPEED);
if (tvLimitSpeed.getVisibility() == View.GONE) {
tvLimitSpeed.setVisibility(View.VISIBLE);
}
tvLimitSpeed.setText(limitSpeed+"");
handler.sendEmptyMessageDelayed(MSG_HIDE_LIMIT_SPEED, HIDE_LIMIT_SPEED_DELAY);
});
}
private void drawLimitSpeed() {
}
@Override
@@ -150,25 +124,7 @@ public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback, IMogoLoca
return;
}
currentSpeed = (int) (location.getSpeed() * 3.6F);
if(lightCenter) {
if (tvSelfSpeed != null) {
tvSelfSpeed.post(() -> {
if (tvSelfSpeed.getVisibility() == View.GONE) {
tvSelfSpeed.setVisibility(View.VISIBLE);
}
if (limitSpeed != -1 && currentSpeed > limitSpeed) {
// 显示红色
tvSelfSpeed.setTextColor(context.getResources().getColor(R.color.module_ext_vr_mode_left_traffic_light_red));
tvSelfSpeed.setBackgroundResource(R.drawable.module_ext_vr_mode_speed_red_bg);
}else{
// 显示白
tvSelfSpeed.setTextColor(context.getResources().getColor(R.color.module_ext_vr_mode_left_traffic_light_white));
tvSelfSpeed.setBackgroundResource(R.drawable.module_ext_vr_mode_speed_white_bg);
}
tvSelfSpeed.setText("" + currentSpeed);
Logger.d(TAG, "onLocationChange: " + currentSpeed);
});
}
if (lightCenter) {
}
}
@@ -178,11 +134,6 @@ public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback, IMogoLoca
case MSG_REFRESH_CAR_STRATEGY:
// todo 暂时不采用此种渲染方式
// 自车速度
tvSelfSpeed.setText("" + currentSpeed);
// 红绿灯
if (tvTrafficLight.getVisibility() == View.GONE) {
tvTrafficLight.setVisibility(View.VISIBLE);
}
// todo 设置字体颜色、背景颜色、leftDrawable
switch (lightStatus) {
case "Y":
@@ -195,26 +146,21 @@ public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback, IMogoLoca
// 默认绿灯
break;
}
tvTrafficLight.setText(surplusTime + "S");
MogoApisHandler.getInstance().getApis().getMapServiceApi().getMapUIController().showMyLocation(inflateRoadInfo());
if (isVrMode) {
handler.sendEmptyMessageDelayed(MSG_REFRESH_CAR_STRATEGY, STRATEGY_DELAY);
}
return true;
case MSG_HIDE_LIMIT_SPEED:
limitSpeed = -1;
tvLimitSpeed.setVisibility(View.GONE);
return true;
case MSG_HIDE_TRAFFIC_LIGHT_BY_CLOUD:
if (!isObuLightData && !handler.hasMessages(MSG_HIDE_TRAFFIC_LIGHT_BY_OBU)) {
tvTrafficLight.setVisibility(View.GONE);
}
return true;
case MSG_HIDE_TRAFFIC_LIGHT_BY_OBU:
isObuLightData = false;
if (!handler.hasMessages(MSG_HIDE_TRAFFIC_LIGHT_BY_CLOUD)) {
tvTrafficLight.setVisibility(View.GONE);
}
return true;
default:
@@ -234,22 +180,22 @@ public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback, IMogoLoca
return;
}
String action = intent.getAction();
if("com.mogo.launcher.adas".equals(action)){
if ("com.mogo.launcher.adas".equals(action)) {
// 收到限速信息
int limit = intent.getIntExtra("adas_speed_limit", -1);
if(limit>0) {
if (limit > 0) {
limitSpeed = limit;
drawLimitSpeed();
}
}else {
} else {
int type = intent.getIntExtra("type", -1);
if (type == 2) {
String obuLightAction = intent.getStringExtra("action");
if("1".equals(obuLightAction)){
if ("1".equals(obuLightAction)) {
// 隐藏红绿灯
handler.removeMessages(MSG_HIDE_TRAFFIC_LIGHT_BY_OBU);
handler.sendEmptyMessage(MSG_HIDE_TRAFFIC_LIGHT_BY_OBU);
}else {
} else {
// 红绿灯处理
String data = intent.getStringExtra("data");
if (data != null && !data.isEmpty()) {
@@ -275,13 +221,6 @@ public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback, IMogoLoca
private void handleObuTrafficLightInfo(String lightStatus, String surplusTime) {
isObuLightData = true;
if (tvTrafficLight != null) {
handler.removeMessages(MSG_HIDE_TRAFFIC_LIGHT_BY_OBU);
handler.removeMessages(MSG_HIDE_TRAFFIC_LIGHT_BY_CLOUD);
drawTrafficLight(lightStatus, surplusTime);
handler.sendEmptyMessageDelayed(MSG_HIDE_TRAFFIC_LIGHT_BY_OBU,
HIDE_TRAFFIC_LIGHT_DELAY);
}
}
private void handleCloudTrafficLight(CloudRoadData roadData) {
@@ -289,75 +228,12 @@ public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback, IMogoLoca
handler.removeMessages(MSG_HIDE_TRAFFIC_LIGHT_BY_CLOUD);
return;
}
if (tvTrafficLight != null && !handler.hasMessages(MSG_HIDE_TRAFFIC_LIGHT_BY_OBU)) {
handler.removeMessages(MSG_HIDE_TRAFFIC_LIGHT_BY_CLOUD);
// todo drawTrafficLight
String lightStatus = null;
switch (roadData.getLightStatus()) {
case 1:
// 红灯
lightStatus = "R";
break;
case 2:
// 绿灯
lightStatus = "G";
break;
case 3:
// 黄灯
lightStatus = "Y";
break;
default:
break;
}
if(lightStatus == null){
handler.sendEmptyMessage(MSG_HIDE_TRAFFIC_LIGHT_BY_CLOUD);
}else {
int diff = (int) ((System.currentTimeMillis() - roadData.getSystemTime()) / 1000);
int leftTime = roadData.getLightLeftTime() - diff;
if (leftTime < 0) {
leftTime = 0;
}
Logger.d("CloudTrafficLight",
"lightStatus: " + lightStatus + " current: " + System.currentTimeMillis() + " cloudType: " + roadData.getSystemTime() + " diff: " + diff + " cloudLeftTime: " + roadData.getLightLeftTime() + " leftTime: " + leftTime);
drawTrafficLight(lightStatus, "" + leftTime);
handler.sendEmptyMessageDelayed(MSG_HIDE_TRAFFIC_LIGHT_BY_CLOUD,
HIDE_TRAFFIC_LIGHT_DELAY);
}
}
}
private void drawTrafficLight(String lightStatus, String surplusTime) {
this.lightStatus = lightStatus;
this.surplusTime = surplusTime;
if(lightCenter) {
tvTrafficLight.post(() -> {
if (tvTrafficLight.getVisibility() == View.GONE) {
tvTrafficLight.setVisibility(View.VISIBLE);
}
// todo 设置字体颜色、背景颜色、leftDrawable
switch (lightStatus) {
case "Y":
// 黄灯
tvTrafficLight.setTextColor(context.getResources().getColor(R.color.module_ext_vr_mode_left_traffic_light_yellow));
tvTrafficLight.setBackgroundResource(R.drawable.module_ext_vr_mode_traffic_light_yellow_bg);
tvTrafficLight.setCompoundDrawablesWithIntrinsicBounds(R.drawable.module_ext_traffic_light_yellow, 0, 0, 0);
break;
case "R":
// 红灯
tvTrafficLight.setTextColor(context.getResources().getColor(R.color.module_ext_vr_mode_left_traffic_light_red));
tvTrafficLight.setBackgroundResource(R.drawable.module_ext_vr_mode_traffic_light_red_bg);
tvTrafficLight.setCompoundDrawablesWithIntrinsicBounds(R.drawable.module_ext_traffic_light_red, 0, 0, 0);
break;
default:
// 默认绿灯
tvTrafficLight.setTextColor(context.getResources().getColor(R.color.module_ext_vr_mode_left_traffic_light_green));
tvTrafficLight.setBackgroundResource(R.drawable.module_ext_vr_mode_traffic_light_green_bg);
tvTrafficLight.setCompoundDrawablesWithIntrinsicBounds(R.drawable.module_ext_traffic_light_green, 0, 0, 0);
break;
}
tvTrafficLight.setText(surplusTime + "S");
Logger.d(TAG, "展示红绿灯信息: " + lightStatus + " time: " + surplusTime);
});
if (lightCenter) {
}
}
@@ -383,12 +259,4 @@ public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback, IMogoLoca
}
}
private View inflateRoadInfo(){
View view = View.inflate(context, R.layout.module_ext_item_self_car, null);
TextView _speed = view.findViewById(R.id.tvSelfSpeed);
_speed.setText("" + currentSpeed);
Logger.d(TAG, "showCurrentSpeed: " + currentSpeed);
return view;
}
}

View File

@@ -782,4 +782,18 @@ public class TopViewAnimHelper {
cameraMode = null;
transition = null;
}
public void enterVrMode(){
removeAllView();
topContainer.getLayoutParams().width = (int) getDimen(R.dimen.module_ext_top_view_width_in_vr_mode);
// topContainer.requestLayout();
// topMotionLayout.requestLayout();
}
public void exitVrMode(){
removeAllView();
topContainer.getLayoutParams().width = (int) getDimen(R.dimen.module_ext_top_view_width);
// topContainer.requestLayout();
// topMotionLayout.requestLayout();
}
}

View File

@@ -384,6 +384,11 @@ public class TopViewNoLinkageAnimHelper {
}
MogoApisHandler.getInstance().getApis().getStatusManagerApi().setTopViewShow(ExtensionsModuleConst.TYPE_ENTRANCE, true);
// vr模式下与TopView互斥
if (MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode()) {
TopViewAnimHelper.getInstance().removeAllView();
}
}
/**
@@ -536,4 +541,14 @@ public class TopViewNoLinkageAnimHelper {
cameraMode = null;
transition = null;
}
public void enterVrMode(){
removeAllView();
topContainerNoLinkage.getLayoutParams().width = (int) getDimen(R.dimen.module_ext_top_view_no_link_width_in_vr_mode);
}
public void exitVrMode(){
removeAllView();
topContainerNoLinkage.getLayoutParams().width = LayoutParams.MATCH_PARENT;
}
}

View File

@@ -0,0 +1,175 @@
package com.mogo.module.extensions.utils;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.TextView;
import androidx.constraintlayout.widget.Group;
import com.mogo.module.extensions.R;
import com.mogo.module.extensions.view.VerticalTrafficLightView;
import com.mogo.utils.logger.Logger;
import java.util.Random;
/**
* 红绿灯面板管理类,控制各部分显示隐藏,同时控制限速、车速、红绿灯信息展示
* <p>
* 导航信息内容通过{@link com.mogo.module.extensions.navi.VrModeNavInfoView} 在{@link com.mogo.module.extensions.entrance.EntranceFragment}进行控制
* 此处仅控制导航信息的显示与隐藏
*
* @author tongchenfei
*/
public class TrafficLightPanelManager implements Handler.Callback, View.OnClickListener {
private static final String TAG = "TrafficLightPanelManager";
private TrafficLightPanelManager() {
}
private final static TrafficLightPanelManager INSTANCE = new TrafficLightPanelManager();
public static TrafficLightPanelManager getInstance() {
return INSTANCE;
}
private Group speedGroup, navGroup, extraGroup;
private TextView tvLimitSpeed;
private VerticalTrafficLightView turnAroundLight, turnLeftLight, straightLight, turnRightLight;
private Handler handler = new Handler(this);
private boolean isInit = false;
public void initPanel(View root) {
speedGroup = root.findViewById(R.id.module_ext_id_group_navi_in_vr_speed);
navGroup = root.findViewById(R.id.module_ext_id_group_navi_in_vr_nav_info);
extraGroup = root.findViewById(R.id.module_ext_id_group_traffic_light_panel_extra);
tvLimitSpeed = root.findViewById(R.id.module_ext_id_tv_limit_speed);
turnAroundLight = root.findViewById(R.id.module_ext_id_traffic_light_turn_around);
turnLeftLight = root.findViewById(R.id.module_ext_id_traffic_light_turn_left);
straightLight = root.findViewById(R.id.module_ext_id_traffic_light_straight);
turnRightLight = root.findViewById(R.id.module_ext_id_traffic_light_turn_right);
isInit = true;
// debug
root.findViewById(R.id.module_ext_id_navi_in_vr_speed_bg).setOnClickListener(this);
root.findViewById(R.id.module_ext_id_navi_in_vr_traffic_bg).setOnClickListener(this);
}
public void showNavPanel() {
if (!isInit) {
Logger.e(TAG, "nav panel 未初始化");
return;
}
extraGroup.setVisibility(View.VISIBLE);
if (isNav) {
navGroup.setVisibility(View.VISIBLE);
speedGroup.setVisibility(View.GONE);
} else {
speedGroup.setVisibility(View.VISIBLE);
navGroup.setVisibility(View.GONE);
}
tvLimitSpeed.setVisibility(View.VISIBLE);
}
public void hideNavPanel() {
if (!isInit) {
Logger.e(TAG, "nav panel 未初始化");
return;
}
extraGroup.setVisibility(View.GONE);
speedGroup.setVisibility(View.GONE);
tvLimitSpeed.setVisibility(View.GONE);
}
private boolean isNav = false;
public void startNav() {
isNav = true;
navGroup.setVisibility(View.VISIBLE);
speedGroup.setVisibility(View.GONE);
}
public void stopNav() {
isNav = false;
speedGroup.setVisibility(View.VISIBLE);
navGroup.setVisibility(View.GONE);
}
public void refreshLimitSpeed(int limitSpeed) {
handler.removeMessages(MSG_HIDE_LIMIT_SPEED);
tvLimitSpeed.setVisibility(View.VISIBLE);
tvLimitSpeed.setText(String.valueOf(limitSpeed));
handler.sendEmptyMessageDelayed(MSG_HIDE_LIMIT_SPEED, HIDE_LIMIT_SPEED_DELAY);
}
/**
* 刷新红绿灯显示状态
*
* @param laneLight 固定数组长度为4的车道类型灯从0-3依次代表 掉头,左转,执行,右转
* @param surplusTime 固定数组长度为4的剩余时长数组从0-3依次代表 掉头,左转,执行,右转
*/
public void refreshTrafficLightStatus(int[] laneLight, String[] surplusTime) {
turnAroundLight.setTrafficLightStatus(laneLight[0], surplusTime[0]);
turnLeftLight.setTrafficLightStatus(laneLight[1], surplusTime[1]);
straightLight.setTrafficLightStatus(laneLight[2], surplusTime[2]);
turnRightLight.setTrafficLightStatus(laneLight[3], surplusTime[3]);
}
public void release() {
isInit = false;
speedGroup = null;
navGroup = null;
extraGroup = null;
tvLimitSpeed = null;
turnAroundLight = null;
turnLeftLight = null;
straightLight = null;
turnRightLight = null;
}
private static final int MSG_HIDE_LIMIT_SPEED = 1001;
private static final long HIDE_LIMIT_SPEED_DELAY = 5000;
@Override
public boolean handleMessage(Message msg) {
if (!isInit) {
return false;
}
if (msg.what == MSG_HIDE_LIMIT_SPEED) {
tvLimitSpeed.setVisibility(View.GONE);
return true;
}
return false;
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.module_ext_id_navi_in_vr_speed_bg) {
boolean s = new Random().nextBoolean();
boolean b = new Random().nextBoolean();
if (s) {
if (b) {
startNav();
} else {
stopNav();
}
} else {
refreshLimitSpeed(90);
}
} else {
int[] color = new int[4];
String[] time = new String[4];
for (int i = 0; i < 4; i++) {
int s = new Random().nextInt(4);
boolean b = new Random().nextBoolean();
color[i] = s;
time[i] = b ? "12" : "";
}
refreshTrafficLightStatus(color, time);
}
}
}

View File

@@ -41,7 +41,7 @@ public class VerticalTrafficLightView extends ConstraintLayout {
private static final int[] TURN_RIGHT_ICON_RES = new int[]{R.drawable.module_ext_dw_traffic_turn_right_gray, R.drawable.module_ext_dw_traffic_turn_right_red, R.drawable.module_ext_dw_traffic_turn_right_yellow, R.drawable.module_ext_dw_traffic_turn_right_green};
private final int[] iconRes;
private final int[] colorRes = new int[]{-1, Color.parseColor("#F63A35"), Color.parseColor("#F63A35"), Color.parseColor("#11FF89")};
private final int[] colorRes = new int[]{-1, Color.parseColor("#F63A35"), Color.parseColor("#FFA71F"), Color.parseColor("#11FF89")};
public VerticalTrafficLightView(Context context) {
this(context, null);
@@ -54,7 +54,6 @@ public class VerticalTrafficLightView extends ConstraintLayout {
public VerticalTrafficLightView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
LayoutInflater.from(context).inflate(R.layout.merge_vertical_traffic_light_in_vr, this);
initView();
TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.VerticalTrafficLightView, 0, 0);
int lightType = typedArray.getInt(R.styleable.VerticalTrafficLightView_iconRes, 0);
typedArray.recycle();
@@ -76,6 +75,7 @@ public class VerticalTrafficLightView extends ConstraintLayout {
iconRes = TURN_AROUND_ICON_RES;
break;
}
initView();
}
private void initView() {
@@ -84,6 +84,7 @@ public class VerticalTrafficLightView extends ConstraintLayout {
tvLeftTime = findViewById(R.id.module_ext_id_traffic_light_left_time);
tvLeftTimeUnit = findViewById(R.id.module_ext_id_traffic_light_left_time_unit);
groupLeftTime = findViewById(R.id.module_ext_id_group_left_time);
ivTrafficLight.setImageResource(iconRes[0]);
}
/**