opt traffic light
This commit is contained in:
@@ -202,6 +202,7 @@ public class EntranceFragment extends MvpFragment<EntranceView, EntrancePresente
|
||||
mApis = MogoApisHandler.getInstance().getApis();
|
||||
|
||||
adasNoticeHelper.init(getContext());
|
||||
adasNoticeHelper.initView(getView());
|
||||
|
||||
mEntrancePresenter = new EntrancePresenter(getContext(), this);
|
||||
mMogoFragmentManager = mApis.getFragmentManagerApi();
|
||||
@@ -413,10 +414,14 @@ public class EntranceFragment extends MvpFragment<EntranceView, EntrancePresente
|
||||
|
||||
debugTopView();
|
||||
debugCrashWarn();
|
||||
|
||||
// 检查是否在vr模式
|
||||
if (mStatusManager.isVrMode()) {
|
||||
enterVrMode();
|
||||
}
|
||||
}
|
||||
|
||||
private void enterVrMode(){
|
||||
mApis.getStatusManagerApi().setVrMode(TYPE_ENTRANCE, true);
|
||||
tvEnterVrMode.setVisibility(View.GONE);
|
||||
mMove2CurrentLocation.setVisibility(View.GONE);
|
||||
mUploadRoadCondition.setVisibility(View.GONE);
|
||||
@@ -430,7 +435,6 @@ public class EntranceFragment extends MvpFragment<EntranceView, EntrancePresente
|
||||
|
||||
private void exitVrMode(){
|
||||
EntranceViewHolder.getInstance().forceHideNoticeView();
|
||||
mApis.getStatusManagerApi().setVrMode(TYPE_ENTRANCE, false);
|
||||
tvEnterVrMode.setVisibility(View.VISIBLE);
|
||||
mMove2CurrentLocation.setVisibility(View.VISIBLE);
|
||||
mUploadRoadCondition.setVisibility(View.VISIBLE);
|
||||
@@ -705,6 +709,7 @@ public class EntranceFragment extends MvpFragment<EntranceView, EntrancePresente
|
||||
|
||||
mStatusManager.registerStatusChangedListener(TAG, StatusDescriptor.UPLOADING, this);
|
||||
mStatusManager.registerStatusChangedListener(TAG, StatusDescriptor.DISPLAY_OVERVIEW, this);
|
||||
mStatusManager.registerStatusChangedListener(TAG, StatusDescriptor.VR_MODE, this);
|
||||
|
||||
TopViewAnimHelper.getInstance().setIMogoMapUIController(mMApUIController);
|
||||
|
||||
@@ -858,6 +863,12 @@ public class EntranceFragment extends MvpFragment<EntranceView, EntrancePresente
|
||||
mCameraMode.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
} else if (descriptor == StatusDescriptor.VR_MODE) {
|
||||
if (isTrue) {
|
||||
enterVrMode();
|
||||
}else{
|
||||
exitVrMode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1015,6 +1026,7 @@ public class EntranceFragment extends MvpFragment<EntranceView, EntrancePresente
|
||||
mStatusManager.unregisterStatusChangedListener(TAG, StatusDescriptor.UPLOADING, this);
|
||||
mStatusManager.unregisterStatusChangedListener(TAG, StatusDescriptor.DISPLAY_OVERVIEW
|
||||
, this);
|
||||
mStatusManager.unregisterStatusChangedListener(TAG, StatusDescriptor.VR_MODE, this);
|
||||
}
|
||||
if (mApis != null) {
|
||||
if (mApis.getIntentManagerApi() != null) {
|
||||
|
||||
@@ -4,48 +4,149 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
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.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.mogo.map.location.IMogoLocationListener;
|
||||
import com.mogo.map.location.MogoLocation;
|
||||
import com.mogo.module.common.MogoApisHandler;
|
||||
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.entrance.IMogoEntranceButtonController;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* vr模式下,adas左侧提示框帮助类
|
||||
*
|
||||
* @author tongchenfei
|
||||
*/
|
||||
public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback {
|
||||
public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback, IMogoLocationListener,
|
||||
Handler.Callback {
|
||||
private static final String TAG = "AdasNoticeHelper";
|
||||
|
||||
private static final int MSG_HIDE_TRAFFIC_LIGHT_BY_OBU = 1001;
|
||||
private static final int MSG_HIDE_TRAFFIC_LIGHT_BY_CLOUD = 1002;
|
||||
private static final int MSG_HIDE_LIMIT_SPEED = 1003;
|
||||
|
||||
private static final long HIDE_TRAFFIC_LIGHT_DELAY = 2_000L;
|
||||
private static final long HIDE_LIMIT_SPEED_DELAY = 10_000L;
|
||||
|
||||
private Context context;
|
||||
private AdasNoticeReceiver adasReceiver = new AdasNoticeReceiver();
|
||||
|
||||
private boolean isVrMode = false;
|
||||
|
||||
private TextView tvSelfSpeed, tvTrafficLight, tvLimitSpeed;
|
||||
|
||||
private int limitSpeed;
|
||||
|
||||
private Handler handler = new Handler(this);
|
||||
|
||||
public void init(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public void enterVrMode(){
|
||||
public void initView(View root) {
|
||||
tvSelfSpeed = root.findViewById(R.id.tvSelfSpeed);
|
||||
tvTrafficLight = root.findViewById(R.id.tvTrafficLight);
|
||||
tvLimitSpeed = root.findViewById(R.id.tvLimitSpeed);
|
||||
}
|
||||
|
||||
public void enterVrMode() {
|
||||
isVrMode = true;
|
||||
IntentFilter filter = new IntentFilter("com.mogo.launcher.adas.app.biz");
|
||||
context.registerReceiver(adasReceiver, filter);
|
||||
MogoApisHandler.getInstance().getApis().getAdasControllerApi().addAdasWarnMessageCallback(this);
|
||||
MogoApisHandler.getInstance().getApis().getRegisterCenterApi().registerMogoLocationListener(TAG, this);
|
||||
|
||||
// debug code
|
||||
tvSelfSpeed.setVisibility(View.VISIBLE);
|
||||
tvTrafficLight.setVisibility(View.VISIBLE);
|
||||
tvLimitSpeed.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
public void exitVrMode(){
|
||||
public void exitVrMode() {
|
||||
isVrMode = false;
|
||||
tvSelfSpeed.setVisibility(View.GONE);
|
||||
tvTrafficLight.setVisibility(View.GONE);
|
||||
tvLimitSpeed.setVisibility(View.GONE);
|
||||
|
||||
context.unregisterReceiver(adasReceiver);
|
||||
MogoApisHandler.getInstance().getApis().getAdasControllerApi().removeAdasWarnMessageCallback(this);
|
||||
MogoApisHandler.getInstance().getApis().getRegisterCenterApi().unregisterMogoLocationListener(TAG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceiveData(ADASWarnMessage msg) {
|
||||
Logger.d(TAG, "收到adas warn message, isVrMode: "+isVrMode+" msg: " + msg);
|
||||
if (!isVrMode) {
|
||||
return;
|
||||
}
|
||||
// 处理adas识别的时间,主要是行人碰撞预警
|
||||
if (msg.type == MogoADASWarnType.ADAS_WARNING_PERSON) {
|
||||
MogoApisHandler.getInstance().getApis().getEntranceButtonController().showLeftNoticeByType(IMogoEntranceButtonController.NOTICE_TYPE_PEOPLE_WARN, R.drawable.module_ext_people_warn, "前方注意行人");
|
||||
}
|
||||
if (msg.type == MogoADASWarnType.ADAS_WARNING_LIMIT_SPEED) {
|
||||
// 收到限速信息,更新界面
|
||||
if (tvLimitSpeed != null) {
|
||||
tvLimitSpeed.post(() -> {
|
||||
handler.removeMessages(MSG_HIDE_LIMIT_SPEED);
|
||||
|
||||
if (tvLimitSpeed.getVisibility() == View.GONE) {
|
||||
tvLimitSpeed.setVisibility(View.VISIBLE);
|
||||
}
|
||||
tvLimitSpeed.setText(msg.value);
|
||||
limitSpeed = Integer.parseInt(msg.value);
|
||||
|
||||
handler.sendEmptyMessageDelayed(MSG_HIDE_LIMIT_SPEED, HIDE_LIMIT_SPEED_DELAY);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLocationChanged(MogoLocation location) {
|
||||
if (!isVrMode) {
|
||||
return;
|
||||
}
|
||||
int speed = (int) (location.getSpeed() * 3.6F);
|
||||
if (tvSelfSpeed != null) {
|
||||
tvSelfSpeed.post(() -> {
|
||||
if (tvSelfSpeed.getVisibility() == View.GONE) {
|
||||
tvSelfSpeed.setVisibility(View.VISIBLE);
|
||||
}
|
||||
tvSelfSpeed.setText("" + speed);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleMessage(Message msg) {
|
||||
switch (msg.what) {
|
||||
case MSG_HIDE_LIMIT_SPEED:
|
||||
tvLimitSpeed.setVisibility(View.GONE);
|
||||
return true;
|
||||
case MSG_HIDE_TRAFFIC_LIGHT_BY_CLOUD:
|
||||
if (!handler.hasMessages(MSG_HIDE_TRAFFIC_LIGHT_BY_OBU)) {
|
||||
tvTrafficLight.setVisibility(View.GONE);
|
||||
}
|
||||
return true;
|
||||
case MSG_HIDE_TRAFFIC_LIGHT_BY_OBU:
|
||||
if (!handler.hasMessages(MSG_HIDE_TRAFFIC_LIGHT_BY_CLOUD)) {
|
||||
tvTrafficLight.setVisibility(View.GONE);
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,9 +154,12 @@ public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback {
|
||||
*
|
||||
* @author tongchenfei
|
||||
*/
|
||||
private class AdasNoticeReceiver extends BroadcastReceiver{
|
||||
private class AdasNoticeReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (!isVrMode) {
|
||||
return;
|
||||
}
|
||||
// todo 处理发给adas的事件, 主要处理逆向超车和obu行人碰撞
|
||||
String id = intent.getStringExtra("v2x_warning_type");
|
||||
if (id != null) {
|
||||
@@ -63,15 +167,67 @@ public class AdasNoticeHelper implements IMogoAdasWarnMessageCallback {
|
||||
MogoApisHandler.getInstance().getApis().getEntranceButtonController().showLeftNoticeByType(IMogoEntranceButtonController.NOTICE_TYPE_PEOPLE_WARN, R.drawable.module_ext_people_warn, "前方注意行人");
|
||||
}
|
||||
}
|
||||
|
||||
int type = intent.getIntExtra("type", -1);
|
||||
if (type == 2) {
|
||||
// 红绿灯处理
|
||||
String data = intent.getStringExtra("data");
|
||||
if (data != null && !data.isEmpty()) {
|
||||
try {
|
||||
JSONObject jsonObject = new JSONObject(data);
|
||||
String lightStatus = jsonObject.optString("lightStatus");
|
||||
String surplusTime = jsonObject.optString("surplusTime");
|
||||
if (!lightStatus.isEmpty() && !surplusTime.isEmpty()) {
|
||||
handleObuTrafficLightInfo(lightStatus, surplusTime);
|
||||
} else {
|
||||
Logger.d(TAG, "红绿灯必要信息都为空,不做展示");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Logger.e(TAG, e, "解析adas数据异常");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private View generateNoticeView(int iconRes, String content) {
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.item_vr_left_notice, null);
|
||||
ImageView icon = view.findViewById(R.id.module_ext_iv_left_notice_icon);
|
||||
icon.setImageResource(iconRes);
|
||||
TextView tvContent = view.findViewById(R.id.module_ext_vr_mode_left_notice_container);
|
||||
tvContent.setText(content);
|
||||
return view;
|
||||
private void handleObuTrafficLightInfo(String lightStatus, String surplusTime) {
|
||||
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(){
|
||||
if (tvTrafficLight != null && !handler.hasMessages(MSG_HIDE_TRAFFIC_LIGHT_BY_OBU)) {
|
||||
handler.removeMessages(MSG_HIDE_TRAFFIC_LIGHT_BY_CLOUD);
|
||||
// todo drawTrafficLight
|
||||
handler.sendEmptyMessageDelayed(MSG_HIDE_TRAFFIC_LIGHT_BY_CLOUD,
|
||||
HIDE_TRAFFIC_LIGHT_DELAY);
|
||||
}
|
||||
}
|
||||
|
||||
private void drawTrafficLight(String lightStatus, String surplusTime) {
|
||||
tvTrafficLight.post(() -> {
|
||||
if (tvTrafficLight.getVisibility() == View.GONE) {
|
||||
tvTrafficLight.setVisibility(View.VISIBLE);
|
||||
}
|
||||
// todo 设置字体颜色、背景颜色、leftDrawable
|
||||
switch (lightStatus) {
|
||||
case "Y":
|
||||
// 黄灯
|
||||
break;
|
||||
case "R":
|
||||
// 红灯
|
||||
break;
|
||||
default:
|
||||
// 默认绿灯
|
||||
break;
|
||||
}
|
||||
tvTrafficLight.setText(surplusTime + "S");
|
||||
Logger.d(TAG, "展示红绿灯信息: " + lightStatus + " time: " + surplusTime);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user