[taxi/bus-d 270] bus 自动驾驶按钮逻辑优化:

This commit is contained in:
wangmingjun
2022-05-11 19:10:58 +08:00
parent dec19b7c2e
commit fab322f9dd
3 changed files with 58 additions and 54 deletions

View File

@@ -1,6 +1,7 @@
package com.mogo.och.bus.fragment;
import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_BUS;
import static com.mogo.och.bus.constant.BusConst.TIMER_START_AUTOPILOT_INTERVAL;
import android.animation.ObjectAnimator;
import android.content.Intent;
@@ -83,6 +84,8 @@ public abstract class BaseBusTabFragment<V extends IView, P extends Presenter<V>
private ObjectAnimator autopilotLoadingAnimator;
public boolean isAnimateRunning = false;
/**
* 滑动按钮触发的事件
*/
@@ -156,9 +159,9 @@ public abstract class BaseBusTabFragment<V extends IView, P extends Presenter<V>
@Override
public void onClickImpl(View v) {
if (CallerAutoPilotStatusListenerManager.INSTANCE.getAutoPilotStatusInfo().getState() != IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_DISABLE){
// if (CallerAutoPilotStatusListenerManager.INSTANCE.getAutoPilotStatusInfo().getState() != IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_DISABLE){
restartAutopilot();
}
// }
}
});
@@ -169,7 +172,7 @@ public abstract class BaseBusTabFragment<V extends IView, P extends Presenter<V>
// return true;
// });
// }
onAutopilotStatusChanged(CallerAutoPilotStatusListenerManager.INSTANCE.getAutoPilotStatusInfo().getState(), false);
onAutopilotStatusChanged(CallerAutoPilotStatusListenerManager.INSTANCE.getAutoPilotStatusInfo().getState());
// 模拟 不可自动驾驶目前场景是刚开机adas还未和工控机连接
findViewById(R.id.btnAutopilotDisable).setOnClickListener(view ->
// MogoApisHandler.getInstance().getApis()
@@ -300,20 +303,15 @@ public abstract class BaseBusTabFragment<V extends IView, P extends Presenter<V>
*
* @param autopilotStatus 0:不可用 1:可用状态 2:自动驾驶中
*/
public void onAutopilotStatusChanged(int autopilotStatus, boolean isAnimateRunning) {
public void onAutopilotStatusChanged(int autopilotStatus) {
getActivity().runOnUiThread(() -> {
// ctvAutopilotStatus.setChecked(isInAutopilot);
changeAutopilotBtnView(autopilotStatus, isAnimateRunning);
});
}
private void changeAutopilotBtnView(int autopilotStatus, boolean isAnimateRunning) {
CallerLogger.INSTANCE.d(M_BUS + TAG, "onStateChangeChangeAutopilotBtnView: " + autopilotStatus + "isAnimateRunning = " + isAnimateRunning);
public void updateAutopilotStatus(int autopilotStatus){
if (IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_DISABLE
== autopilotStatus) {//0不可用
if (isAnimateRunning){
stopAutopilotAnimation();
}
ctvAutopilotStatusIv.setImageResource(R.drawable.bus_wrong_autopilot_icon);
ctvAutopilotStatusTv.setTextColor(getResources().getColor(R.color.bus_autopilot_text_color_normal));
ctvAutopilotStatusTv.setText(getResources().getString(R.string.bus_loading_autopilot_failure_tv));
@@ -334,9 +332,6 @@ public abstract class BaseBusTabFragment<V extends IView, P extends Presenter<V>
} else if (IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_ENABLE
== autopilotStatus) {//1可用
if (isAnimateRunning) {
stopAutopilotAnimation();
}
ctvAutopilotStatusTv.setTextColor(getResources().getColor(R.color.bus_autopilot_text_color_normal));
ctvAutopilotStatusTv.setText(getResources().getString(R.string.bus_loading_autopilot_runnig_tv));
ctvAutopilotStatusIv.setImageResource(R.drawable.bus_ic_autopilot);
@@ -345,9 +340,6 @@ public abstract class BaseBusTabFragment<V extends IView, P extends Presenter<V>
// ctvAutopilotStatus.setPressed(true);
} else if (IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING
== autopilotStatus) {//2 running
if (isAnimateRunning){
stopAutopilotAnimation();
}
ctvAutopilotStatusIv.setImageResource(R.drawable.bus_right_autopilot_icon);
ctvAutopilotStatusTv.setTextColor(getResources().getColor(R.color.bus_autopilot_text_color_normal));
ctvAutopilotStatusTv.setText(getResources().getString(R.string.bus_loading_autopilot_success_tv));
@@ -367,6 +359,18 @@ public abstract class BaseBusTabFragment<V extends IView, P extends Presenter<V>
}
}
private void changeAutopilotBtnView(int autopilotStatus, boolean isAnimateRunning) {
if (isAnimateRunning && IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING
!= autopilotStatus) {
// 主动开启自动驾驶中不为2为0、1则继续loading
return;
}
CallerLogger.INSTANCE.d(M_BUS + TAG, "onStateChangeChangeAutopilotBtnView: " + autopilotStatus + "isAnimateRunning = " + isAnimateRunning);
stopAutopilotAnimation();
updateAutopilotStatus(autopilotStatus);
}
/**
* 隐藏【自动驾驶】按钮
*/
@@ -429,7 +433,7 @@ public abstract class BaseBusTabFragment<V extends IView, P extends Presenter<V>
* 开启自动驾驶中间动画
*/
public void startAutopilotAnimation() {
// if (CallerAutoPilotStatusListenerManager.INSTANCE.getAutoPilotStatusInfo().getState() == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_ENABLE){
isAnimateRunning = true;
ctvAutopilotStatusTv.setText(getResources().getString(R.string.bus_loading_autopilot_tv));
ctvAutopilotStatusTv.setTextColor(getResources().getColor(R.color.bus_autopilot_text_color_normal));
ctvAutopilotStatus.setSelected(false);
@@ -442,23 +446,37 @@ public abstract class BaseBusTabFragment<V extends IView, P extends Presenter<V>
autopilotLoadingAnimator.setDuration(1000);//设置持续时间
}
autopilotLoadingAnimator.start();//动画开始
// }
startingAutoApilotCountDown();
}
private void startingAutoApilotCountDown(){
//10s 若自动驾驶没有开启,则结束动画
UiThreadHandler.postDelayed(new Runnable() {
@Override
public void run() { //未启动成功做处理
if (CallerAutoPilotStatusListenerManager.INSTANCE.getAutoPilotStatusInfo().getState()
!= IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING && isAnimateRunning){
stopAutopilotAnimation();
updateAutopilotStatus(CallerAutoPilotStatusListenerManager.INSTANCE.getAutoPilotStatusInfo().getState());
}
}
},TIMER_START_AUTOPILOT_INTERVAL);
}
/**
* 停止自动驾驶中间动画
*/
public void stopAutopilotAnimation() {
private void stopAutopilotAnimation() {
if (autopilotLoadingAnimator != null) {
autopilotLoadingAnimator.end();
ctvAutopilotStatusIv.clearAnimation();
autopilotLoadingAnimator = null;
setIsAnimateRunning(false);
isAnimateRunning = false;
}
}
public abstract void setIsAnimateRunning(boolean isAnimateRunning);
/**
* 迈速表实时更新
*

View File

@@ -94,11 +94,11 @@ public class BusFragment extends BaseBusTabFragment<BusFragment, BusPresenter>
break;
case IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_ENABLE:
showAutopilotBiz();
onAutopilotStatusChanged(IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_ENABLE, false);
onAutopilotStatusChanged(IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_ENABLE);
break;
case IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING:
showAutopilotBiz();
onAutopilotStatusChanged(IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING, false);
onAutopilotStatusChanged(IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING);
break;
default:
break;
@@ -239,7 +239,9 @@ public class BusFragment extends BaseBusTabFragment<BusFragment, BusPresenter>
@Override
public void restartAutopilot() {
mPresenter.restartAutopilot();
if (!isAnimateRunning) {
mPresenter.restartAutopilot();
}
}
@Override
@@ -347,11 +349,6 @@ public class BusFragment extends BaseBusTabFragment<BusFragment, BusPresenter>
mPresenter.debugAutoPilotStatus(status);
}
@Override
public void setIsAnimateRunning(boolean isAnimateRunning) {
mPresenter.setIsAnimateRunning(isAnimateRunning);
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.switch_line_btn) {//切换路线条件: 自动驾驶过程中点击则toast提示自动驾驶中不可切换路线

View File

@@ -44,7 +44,6 @@ public class BusPresenter extends Presenter<BusFragment>
private static final String TAG = "BusPresenter";
private int currentAutopilotStatus = -1;
private boolean isAnimateRunning = false;
private List<BusStationBean> mStationList = new ArrayList<>();
private int mCurrentStation = 0;
@@ -84,9 +83,13 @@ public class BusPresenter extends Presenter<BusFragment>
BusOrderModel.getInstance().setControllerStatusCallback(null);
}
public void setIsAnimateRunning(boolean isAnimateRunning){
this.isAnimateRunning = isAnimateRunning;
}
// public void setIsAnimateRunning(boolean isAnimateRunning){
// this.isAnimateRunning = isAnimateRunning;
// }
// public boolean getIsAnimateRunning(){
// return isAnimateRunning;
// }
public void queryBusRoutes() {
BusOrderModel.getInstance().queryBusRoutes();
@@ -102,10 +105,8 @@ public class BusPresenter extends Presenter<BusFragment>
}
public void restartAutopilot() {
if (!isAnimateRunning){
currentAutopilotStatus = -1;
BusOrderModel.getInstance().restartAutopilot();
}
currentAutopilotStatus = -1;
BusOrderModel.getInstance().restartAutopilot();
}
public void onChangeOperationStatus() {
@@ -139,7 +140,7 @@ public class BusPresenter extends Presenter<BusFragment>
|| ((mCurrentStation == 0 || mCurrentStation == mStationList.size() - 1)
&& BusOrderModel.getInstance().isGoingToNextStation()))) {
runOnUIThread(() -> mView.onAutopilotStatusChanged(
IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING, isAnimateRunning));
IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING));
}
}
@@ -190,15 +191,14 @@ public class BusPresenter extends Presenter<BusFragment>
return;
}
// 改变UI自动驾驶状态
runOnUIThread(() -> mView.onAutopilotStatusChanged(currentAutopilotStatus, isAnimateRunning));
runOnUIThread(() -> mView.onAutopilotStatusChanged(currentAutopilotStatus));
}
break;
case IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING:
runOnUIThread(() -> mView.stopAutopilotAnimation());
if (currentAutopilotStatus != IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING) {
currentAutopilotStatus = IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING;
// 改变UI自动驾驶状态
runOnUIThread(() -> mView.onAutopilotStatusChanged(currentAutopilotStatus, isAnimateRunning));
runOnUIThread(() -> mView.onAutopilotStatusChanged(currentAutopilotStatus));
BusOrderModel.getInstance().triggerStartServiceEvent(true);
}
break;
@@ -222,7 +222,7 @@ public class BusPresenter extends Presenter<BusFragment>
}
runOnUIThread(() -> {
mView.onAutopilotEnableChange(false);
mView.onAutopilotStatusChanged(currentAutopilotStatus, isAnimateRunning);
mView.onAutopilotStatusChanged(currentAutopilotStatus);
});
}
break;
@@ -246,18 +246,7 @@ public class BusPresenter extends Presenter<BusFragment>
@Override
public void startOpenAutopilot() {
isAnimateRunning = true;
runOnUIThread(() -> mView.startAutopilotAnimation());
//10s 若自动驾驶没有开启,则结束动画
UiThreadHandler.postDelayed(new Runnable() {
@Override
public void run() { //未启动成功做处理
if (CallerAutoPilotStatusListenerManager.INSTANCE.getAutoPilotStatusInfo().getState()
!= IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING && isAnimateRunning){
mView.onAutopilotStatusChanged(CallerAutoPilotStatusListenerManager.INSTANCE.getAutoPilotStatusInfo().getState(), isAnimateRunning);
}
}
},TIMER_START_AUTOPILOT_INTERVAL);
// TODO: 2021/8/20 无工控机环境, 手动调起自动驾驶开启返回结果,有工控机环境要删除
// UiThreadHandler.postDelayed(new Runnable() {
// @Override