From fab322f9dd7c79ff149fbd4c6a6f8e519e74e4f5 Mon Sep 17 00:00:00 2001 From: wangmingjun Date: Wed, 11 May 2022 19:10:58 +0800 Subject: [PATCH] =?UTF-8?q?[taxi/bus-d=20270]=20bus=20=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E9=A9=BE=E9=A9=B6=E6=8C=89=E9=92=AE=E9=80=BB=E8=BE=91=E4=BC=98?= =?UTF-8?q?=E5=8C=96:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../och/bus/fragment/BaseBusTabFragment.java | 62 ++++++++++++------- .../mogo/och/bus/fragment/BusFragment.java | 13 ++-- .../mogo/och/bus/presenter/BusPresenter.java | 37 ++++------- 3 files changed, 58 insertions(+), 54 deletions(-) diff --git a/OCH/mogo-och-bus/src/main/java/com/mogo/och/bus/fragment/BaseBusTabFragment.java b/OCH/mogo-och-bus/src/main/java/com/mogo/och/bus/fragment/BaseBusTabFragment.java index 305a3077fd..3746c54a4b 100644 --- a/OCH/mogo-och-bus/src/main/java/com/mogo/och/bus/fragment/BaseBusTabFragment.java +++ b/OCH/mogo-och-bus/src/main/java/com/mogo/och/bus/fragment/BaseBusTabFragment.java @@ -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 private ObjectAnimator autopilotLoadingAnimator; + public boolean isAnimateRunning = false; + /** * 滑动按钮触发的事件 */ @@ -156,9 +159,9 @@ public abstract class BaseBusTabFragment @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 // 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 * * @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 } 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 // 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 } } + 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 * 开启自动驾驶中间动画 */ 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 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); - /** * 迈速表实时更新 * diff --git a/OCH/mogo-och-bus/src/main/java/com/mogo/och/bus/fragment/BusFragment.java b/OCH/mogo-och-bus/src/main/java/com/mogo/och/bus/fragment/BusFragment.java index 8650adc83b..38633cccd5 100644 --- a/OCH/mogo-och-bus/src/main/java/com/mogo/och/bus/fragment/BusFragment.java +++ b/OCH/mogo-och-bus/src/main/java/com/mogo/och/bus/fragment/BusFragment.java @@ -94,11 +94,11 @@ public class BusFragment extends BaseBusTabFragment 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 @Override public void restartAutopilot() { - mPresenter.restartAutopilot(); + if (!isAnimateRunning) { + mPresenter.restartAutopilot(); + } } @Override @@ -347,11 +349,6 @@ public class BusFragment extends BaseBusTabFragment 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提示:自动驾驶中,不可切换路线 diff --git a/OCH/mogo-och-bus/src/main/java/com/mogo/och/bus/presenter/BusPresenter.java b/OCH/mogo-och-bus/src/main/java/com/mogo/och/bus/presenter/BusPresenter.java index 558bc36b4d..646d08d794 100644 --- a/OCH/mogo-och-bus/src/main/java/com/mogo/och/bus/presenter/BusPresenter.java +++ b/OCH/mogo-och-bus/src/main/java/com/mogo/och/bus/presenter/BusPresenter.java @@ -44,7 +44,6 @@ public class BusPresenter extends Presenter private static final String TAG = "BusPresenter"; private int currentAutopilotStatus = -1; - private boolean isAnimateRunning = false; private List mStationList = new ArrayList<>(); private int mCurrentStation = 0; @@ -84,9 +83,13 @@ public class BusPresenter extends Presenter 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 } 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 || ((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 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 } runOnUIThread(() -> { mView.onAutopilotEnableChange(false); - mView.onAutopilotStatusChanged(currentAutopilotStatus, isAnimateRunning); + mView.onAutopilotStatusChanged(currentAutopilotStatus); }); } break; @@ -246,18 +246,7 @@ public class BusPresenter extends Presenter @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