增加adas状态同步,增加自动驾驶异常状态处理

This commit is contained in:
tongchenfei
2021-01-26 18:26:51 +08:00
parent 233ba7b89f
commit 49874015aa
17 changed files with 246 additions and 30 deletions

1
.idea/gradle.xml generated
View File

@@ -89,6 +89,7 @@
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
<option name="useQualifiedModuleNames" value="true" />
</GradleProjectSettings>
</option>
</component>

View File

@@ -39,23 +39,23 @@ public class OchBusProvider implements IMogoOCH {
public void init(Context context) {
MogoApisHandler.getInstance().getApis().getStatusManagerApi().registerStatusChangedListener("OchBus", StatusDescriptor.VR_MODE, statusChangedListener);
MogoApisHandler.getInstance().getApis().getStatusManagerApi().registerStatusChangedListener("OchBus", StatusDescriptor.TOP_VIEW, statusChangedListener);
MogoApisHandler.getInstance().getApis().getSocketManagerApi(context).registerOnMessageListener(401017,messageListener);
MogoApisHandler.getInstance().getApis().getSocketManagerApi(context).registerOnMessageListener(401017, messageListener);
}
private void showFragment() {
if (busFragment == null) {
Logger.d(TAG,"准备add fragment======");
Logger.d(TAG, "准备add fragment======");
busFragment = new OchBusFragment();
activity.getSupportFragmentManager().beginTransaction().add(containerId, busFragment).commit();
return;
}
Logger.d(TAG,"准备show fragment");
Logger.d(TAG, "准备show fragment");
activity.getSupportFragmentManager().beginTransaction().show(busFragment).commit();
}
private void hideFragment() {
if (busFragment != null) {
Logger.d(TAG,"准备hide fragment");
Logger.d(TAG, "准备hide fragment");
activity.getSupportFragmentManager().beginTransaction().hide(busFragment).commit();
}

View File

@@ -1,6 +1,7 @@
package com.mogo.och.bus.adapter;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -13,6 +14,8 @@ import androidx.recyclerview.widget.RecyclerView;
import com.mogo.och.bus.R;
import com.mogo.och.bus.bean.OchBusStation;
import com.mogo.och.bus.constant.OchBusConst;
import com.mogo.och.bus.view.VerticalDashLineView;
import com.mogo.utils.logger.Logger;
import java.util.ArrayList;
import java.util.List;
@@ -23,7 +26,6 @@ import java.util.List;
* @author tongchenfei
*/
public class OchBusStationAdapter extends RecyclerView.Adapter<OchBusStationAdapter.ViewHolder> {
private final Context context;
private final List<OchBusStation> stationList = new ArrayList<>();
private int currentStation;
@@ -53,17 +55,36 @@ public class OchBusStationAdapter extends RecyclerView.Adapter<OchBusStationAdap
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
Logger.d("OchBusStationAdapter", "position: " + position + " currPos: " + currentStation + " station: " + stationList.get(position));
holder.tvStationName.setText(stationList.get(position).getSiteName());
if (position == currentStation) {
holder.tvStationName.setTextColor(context.getResources().getColor(R.color.module_mogo_och_bus_current_station_name_text_color));
holder.ivIcon.setImageResource(R.drawable.module_mogo_och_bus_icon_arriving_station);
if(currentStation == 0){
// 在起始点
holder.tvStationName.setTextColor(context.getResources().getColor(R.color.module_mogo_och_bus_arrived_station_name_text_color));
holder.ivIcon.setImageResource(R.drawable.module_mogo_och_bus_icon_arrived_station);
holder.vDashBottom.setColor(context.getResources().getColor(R.color.module_mogo_och_bus_not_arrive_dash_color));
}else {
holder.tvStationName.setTextColor(context.getResources().getColor(R.color.module_mogo_och_bus_current_station_name_text_color));
holder.ivIcon.setImageResource(R.drawable.module_mogo_och_bus_icon_arriving_station);
holder.vDashTop.setGradient(context.getResources().getColor(R.color.module_mogo_och_bus_arriving_start_dash_color), context.getResources().getColor(R.color.module_mogo_och_bus_arriving_end_dash_color));
holder.vDashBottom.setColor(context.getResources().getColor(R.color.module_mogo_och_bus_not_arrive_dash_color));
}
} else if (position < currentStation) {
// 驶过
holder.tvStationName.setTextColor(context.getResources().getColor(R.color.module_mogo_och_bus_arrived_station_name_text_color));
holder.ivIcon.setImageResource(R.drawable.module_mogo_och_bus_icon_arrived_station);
if (position == currentStation - 1) {
holder.vDashBottom.setGradient(context.getResources().getColor(R.color.module_mogo_och_bus_leaving_start_dash_color), context.getResources().getColor(R.color.module_mogo_och_bus_leaving_end_dash_color));
holder.vDashTop.setColor(context.getResources().getColor(R.color.module_mogo_och_bus_arrived_dash_color));
}else{
holder.vDashTop.setColor(context.getResources().getColor(R.color.module_mogo_och_bus_arrived_dash_color));
holder.vDashBottom.setColor(context.getResources().getColor(R.color.module_mogo_och_bus_arrived_dash_color));
}
}else {
holder.tvStationName.setTextColor(context.getResources().getColor(R.color.module_mogo_och_bus_not_arrive_station_name_text_color));
holder.ivIcon.setImageResource(R.drawable.module_mogo_och_bus_icon_not_arrive_station);
holder.vDashTop.setColor(context.getResources().getColor(R.color.module_mogo_och_bus_not_arrive_dash_color));
holder.vDashBottom.setColor(context.getResources().getColor(R.color.module_mogo_och_bus_not_arrive_dash_color));
}
if (position == 0) {
@@ -94,7 +115,7 @@ public class OchBusStationAdapter extends RecyclerView.Adapter<OchBusStationAdap
ImageView ivIcon;
TextView tvStationName;
TextView tvStationNotice;
View vDashBottom,vDashTop;
VerticalDashLineView vDashBottom,vDashTop;
public ViewHolder(@NonNull View itemView) {
super(itemView);
ivIcon = itemView.findViewById(R.id.module_mogo_och_bus_station_icon);

View File

@@ -142,6 +142,11 @@ public class OchBusFragment extends BaseOchFragment<OchBusFragment, OchBusPresen
return R.layout.fragment_och_bus;
}
@Override
public void restartAutopilot() {
mPresenter.restartAutopilot();
}
@Override
public SlidePanelView.OnSlidePanelMoveToEndListener getSlidePanelOnEndListener() {
return this;
@@ -152,4 +157,12 @@ public class OchBusFragment extends BaseOchFragment<OchBusFragment, OchBusPresen
hideNotice();
mPresenter.autoDriveToNextStation();
}
public void onAutopilotEnableChange(boolean isEnable) {
if (isEnable) {
showAutopilotBiz();
}else{
hideAutopilotBiz();
}
}
}

View File

@@ -109,6 +109,10 @@ public class OchBusPresenter extends Presenter<OchBusFragment> implements IMogoA
// }
}
public void restartAutopilot(){
MogoApisHandler.getInstance().getApis().getAdasControllerApi().aiCloudToAdasData(currentAutopilot);
}
private RemoteControlAutoPilotParameters currentAutopilot;
public void autoDriveToNextStation() {
if (currentStationIndex >= stationList.size() - 1) {
// 当前站是最后一站,结束当前行程
@@ -119,11 +123,11 @@ public class OchBusPresenter extends Presenter<OchBusFragment> implements IMogoA
OchBusStation nextStation = stationList.get(currentStationIndex + 1);
currentStation.setIsCurrentSite(STATION_STATUS_LEAVING);
nextStation.setIsCurrentSite(STATION_STATUS_ARRIVING);
RemoteControlAutoPilotParameters parameters = new RemoteControlAutoPilotParameters();
parameters.startLatLon = new RemoteControlAutoPilotParameters.AutoPilotLonLat(currentStation.getLat(), currentStation.getLon());
parameters.endLatLon = new RemoteControlAutoPilotParameters.AutoPilotLonLat(nextStation.getLat(), nextStation.getLon());
parameters.vehicleType = VEHICAL_TYPE;
MogoApisHandler.getInstance().getApis().getAdasControllerApi().aiCloudToAdasData(parameters);
currentAutopilot = new RemoteControlAutoPilotParameters();
currentAutopilot.startLatLon = new RemoteControlAutoPilotParameters.AutoPilotLonLat(currentStation.getLat(), currentStation.getLon());
currentAutopilot.endLatLon = new RemoteControlAutoPilotParameters.AutoPilotLonLat(nextStation.getLat(), nextStation.getLon());
currentAutopilot.vehicleType = VEHICAL_TYPE;
MogoApisHandler.getInstance().getApis().getAdasControllerApi().aiCloudToAdasData(currentAutopilot);
RequestBody request = RequestBody.create(MediaType.get("application/json"), GsonUtil.jsonFromObject(new OchBusLeaveStationRequest(Utils.getSn(), currentStation.getSiteId())));
MogoApisHandler.getInstance().getApis().getNetworkApi()
@@ -185,4 +189,21 @@ public class OchBusPresenter extends Presenter<OchBusFragment> implements IMogoA
mView.refreshBusStations(stationList);
}
}
@Override
public void onStateChanged(int state, String reason) {
switch (state) {
case IMogoAdasOCHCallback.STATUS_AUTOPILOT_ENABLE:
mView.onAutopilotEnableChange(true);
mView.onAutopilotStatusChanged(false);
break;
case IMogoAdasOCHCallback.STATUS_AUTOPILOT_RUNNING:
mView.onAutopilotEnableChange(true);
mView.onAutopilotStatusChanged(true);
break;
default:
mView.onAutopilotEnableChange(false);
break;
}
}
}

View File

@@ -0,0 +1,64 @@
package com.mogo.och.bus.view;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Shader;
import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.Nullable;
/**
* 垂直虚线
*
* @author tongchenfei
*/
public class VerticalDashLineView extends View {
public VerticalDashLineView(Context context) {
this(context,null);
}
public VerticalDashLineView(Context context, @Nullable AttributeSet attrs) {
this(context, attrs,0);
}
public VerticalDashLineView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private final Paint linePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
private final Path dashPath = new Path();
private void init(){
linePaint.setColor(Color.GREEN);
linePaint.setStyle(Paint.Style.STROKE);
linePaint.setStrokeWidth(2);
linePaint.setPathEffect(new DashPathEffect(new float[]{5, 5}, 0));
}
public void setGradient(int startColor, int endColor) {
LinearGradient linearGradient = new LinearGradient(0, 0, getWidth(), getHeight(), startColor, endColor, Shader.TileMode.CLAMP);
linePaint.setShader(linearGradient);
invalidate();
}
public void setColor(int color) {
linePaint.setShader(null);
linePaint.setColor(color);
invalidate();
}
@Override
protected void onDraw(Canvas canvas) {
dashPath.reset();
dashPath.moveTo((float) getWidth()/2, 0);
dashPath.lineTo((float) getWidth()/2,getHeight());
canvas.drawPath(dashPath,linePaint);
}
}

View File

@@ -6,4 +6,7 @@
android:dashGap="5px"
android:dashWidth="5px"
android:color="@color/module_mogo_och_bus_current_station_notice_text_color" />
<gradient
android:startColor="#f00"
android:endColor="#0f0" />
</shape>

View File

@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<item
android:left="-600dp"
android:right="-600dp">
<rotate
android:drawable="@drawable/module_mogo_och_bus_station_green_dash_line"
android:visible="true"

View File

@@ -4,21 +4,19 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
<com.mogo.och.bus.view.VerticalDashLineView
android:id="@+id/module_mogo_och_bus_station_bottom_dash"
android:layout_width="1px"
android:layout_height="30px"
android:background="#fff"
app:layout_constraintLeft_toLeftOf="@id/module_mogo_och_bus_station_icon"
app:layout_constraintRight_toRightOf="@id/module_mogo_och_bus_station_icon"
app:layout_constraintTop_toTopOf="@id/module_mogo_och_bus_station_icon"
android:layout_marginTop="10px"/>
<View
<com.mogo.och.bus.view.VerticalDashLineView
android:id="@+id/module_mogo_och_bus_station_top_dash"
android:layout_width="1px"
android:layout_height="30px"
android:background="#fff"
app:layout_constraintBottom_toBottomOf="@id/module_mogo_och_bus_station_icon"
android:layout_marginBottom="10px"
app:layout_constraintLeft_toLeftOf="@id/module_mogo_och_bus_station_icon"

View File

@@ -6,4 +6,12 @@
<color name="module_mogo_och_bus_not_arrive_station_name_text_color">#FF51649D</color>
<color name="module_mogo_och_bus_station_notice_text_color">#FF8299EB</color>
<color name="module_mogo_och_bus_not_arrive_dash_color">#51649D</color>
<color name="module_mogo_och_bus_arriving_start_dash_color">#427d8e</color>
<color name="module_mogo_och_bus_arriving_end_dash_color">#1FA7FF</color>
<color name="module_mogo_och_bus_leaving_start_dash_color">#3FC281</color>
<color name="module_mogo_och_bus_leaving_end_dash_color">#427d8e</color>
<color name="module_mogo_och_bus_arrived_dash_color">#3FC281</color>
</resources>

View File

@@ -461,6 +461,11 @@ class MogoOCHTaxiModel {
mIsArriveAtEndStation = true;
OCHTaxiUiController.getInstance().onArriveAtEndStation();
}
@Override
public void onStateChanged(int state, String reason) {
}
}
/**

View File

@@ -49,6 +49,11 @@ class OCHTaxiFragment extends BaseOchFragment< OCHTaxiView, OCHTaxiPresenter > i
return R.layout.module_och_taxi_panel;
}
@Override
public void restartAutopilot() {
// todo 重新开始自动驾驶
}
@Override
protected void initViews() {
super.initViews();

View File

@@ -6,19 +6,21 @@ import android.widget.CheckedTextView;
import android.widget.FrameLayout;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import com.mogo.commons.mvp.IView;
import com.mogo.commons.mvp.MvpFragment;
import com.mogo.commons.mvp.Presenter;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.view.OnPreventFastClickListener;
import com.mogo.och.view.FrameAnimImageView;
import com.mogo.och.view.SlidePanelView;
import com.mogo.service.adas.IMogoAdasOCHCallback;
import com.mogo.service.statusmanager.IMogoStatusChangedListener;
import com.mogo.service.statusmanager.StatusDescriptor;
/**
* 网约车基础Fragment主要负责布局通用界面处理站点面板和通话面板互斥情况
* <p>
* 部分业务放在了此处处理
*
* @author tongchenfei
*/
@@ -32,10 +34,13 @@ public abstract class BaseOchFragment<V extends IView, P extends Presenter<V>> e
private final SlidePanelView.OnSlidePanelMoveToEndListener onSlideToEndListener = () -> {
// 此处做一个代理,处理一下共有情况
hideSlidePanel();
hideNotice();
if (getSlidePanelOnEndListener() != null) {
getSlidePanelOnEndListener().moveToEnd();
// 判断一下当前是否可以自动驾驶
if (MogoApisHandler.getInstance().getApis().getAdasControllerApi().getAutopilotStatus() != IMogoAdasOCHCallback.STATUS_AUTOPILOT_DISABLE) {
hideSlidePanel();
hideNotice();
if (getSlidePanelOnEndListener() != null) {
getSlidePanelOnEndListener().moveToEnd();
}
}
};
@@ -56,17 +61,30 @@ public abstract class BaseOchFragment<V extends IView, P extends Presenter<V>> e
slidePanelView.setOnSlidePanelMoveToEndListener(onSlideToEndListener);
fivNoticeHead.setAnimRes(sHappy1);
ctvAutopilotStatus.setOnClickListener(new OnPreventFastClickListener() {
@Override
public void onClickImpl(View v) {
// 如果能自动驾驶,就自动驾驶,不能就提示
if (MogoApisHandler.getInstance().getApis().getAdasControllerApi().getAutopilotStatus() != IMogoAdasOCHCallback.STATUS_AUTOPILOT_DISABLE) {
restartAutopilot();
}
}
});
checkCallView(MogoApisHandler.getInstance().getApis().getStatusManagerApi().isCallViewShow());
MogoApisHandler.getInstance().getApis().getStatusManagerApi().registerStatusChangedListener("Och", StatusDescriptor.CALL_VIEW, callViewListener);
if (MogoApisHandler.getInstance().getApis().getAdasControllerApi().getAutopilotStatus() == IMogoAdasOCHCallback.STATUS_AUTOPILOT_DISABLE) {
hideAutopilotBiz();
}
}
private void checkCallView(boolean isShown){
private void checkCallView(boolean isShown) {
if (flStationPanelContainer == null) {
return;
}
if (isShown) {
flStationPanelContainer.setTranslationY(131f);
}else{
} else {
flStationPanelContainer.setTranslationY(0f);
}
}
@@ -76,7 +94,7 @@ public abstract class BaseOchFragment<V extends IView, P extends Presenter<V>> e
slidePanelView.setVisibility(View.VISIBLE);
}
public void hideSlidePanel(){
public void hideSlidePanel() {
slidePanelView.setVisibility(View.GONE);
}
@@ -87,7 +105,7 @@ public abstract class BaseOchFragment<V extends IView, P extends Presenter<V>> e
fivNoticeHead.startAnim();
}
public void hideNotice(){
public void hideNotice() {
tvNotice.setVisibility(View.GONE);
fivNoticeHead.setVisibility(View.GONE);
fivNoticeHead.stopAnim();
@@ -95,13 +113,24 @@ public abstract class BaseOchFragment<V extends IView, P extends Presenter<V>> e
/**
* 改变自动驾驶状态
*
* @param isInAutopilot true - 在自动驾驶中 false - 不在自动驾驶中
*/
public void onAutopilotStatusChanged(boolean isInAutopilot) {
ctvAutopilotStatus.setChecked(isInAutopilot);
}
public SlidePanelView.OnSlidePanelMoveToEndListener getSlidePanelOnEndListener(){
public void hideAutopilotBiz() {
ctvAutopilotStatus.setVisibility(View.GONE);
slidePanelView.setVisibility(View.GONE);
}
public void showAutopilotBiz() {
ctvAutopilotStatus.setVisibility(View.VISIBLE);
slidePanelView.setVisibility(View.VISIBLE);
}
public SlidePanelView.OnSlidePanelMoveToEndListener getSlidePanelOnEndListener() {
return null;
}
@@ -119,10 +148,16 @@ public abstract class BaseOchFragment<V extends IView, P extends Presenter<V>> e
/**
* 获取站点面板view在{@link #initViews()}时候添加到container中
*
* @return 站点面板view
*/
public abstract int getStationPanelViewId();
/**
* 重新开启自动驾驶
*/
public abstract void restartAutopilot();
private final int[] sHappy1 = {
R.drawable.ic_happy1_00000,
R.drawable.ic_happy1_00001,

View File

@@ -157,7 +157,7 @@ ext {
gpssimulatordebug : "com.mogo.module:module-gps-simulator-debug:${MOGO_MODULE_GPS_SIMULATOR_DEBUG_VERSION}",
gpssimulatornoop : "com.mogo.module:module-gps-simulator-noop:${MOGO_MODULE_GPS_SIMULATOR_NOOP_VERSION}",
adasapi : "com.zhidao.autopilot.support:adas:1.0.6.7",
adasapi : "com.zhidao.autopilot.support:adas:1.0.6.8",
adasconfigapi : "com.zhidao.adasconfig:adasconfig:1.1.5.2",
// 个人中心的SDK

View File

@@ -141,4 +141,6 @@ public interface IMogoADASController extends IProvider {
void removeAdasOCHCallback();
void onAutopilotArriveLike( int type );
int getAutopilotStatus();
}

View File

@@ -11,5 +11,26 @@ public
*/
interface IMogoAdasOCHCallback {
/**
* 不可自动驾驶
*/
int STATUS_AUTOPILOT_DISABLE = 0;
/**
* 可自动驾驶
*/
int STATUS_AUTOPILOT_ENABLE = 1;
/**
* 自动驾驶中
*/
int STATUS_AUTOPILOT_RUNNING = 2;
void onArriveAt( AdasOCHData data );
/**
* 自动驾驶状态发生改变
* @param state {@link #STATUS_AUTOPILOT_DISABLE}
* @param reason 不能自动驾驶的原因
*/
void onStateChanged(int state, String reason);
}

View File

@@ -47,6 +47,7 @@ import com.zhidao.autopilot.support.api.AutopilotServiceManage;
import com.zhidao.autopilot.support.api.IAutopilotServiceStatusListener;
import com.zhidao.autopilot.support.api.IAutopolitDataCallBack;
import com.zhidao.autopilotservice.model.AdasAIDLAutopilotArriveModel;
import com.zhidao.autopilotservice.model.AdasAIDLAutopilotStateModel;
import com.zhidao.support.adas.high.OnAdasListener;
import com.zhidao.support.adas.high.bean.CarStateInfo;
import com.zhidao.support.adas.high.bean.RectInfo;
@@ -350,6 +351,11 @@ public class MogoADASController implements IMogoADASController {
mMogoAdasCarDataCallback.onAdasCarDataCallback( stateInfo );
}
}
@Override
public void notifyAutopilotState(AdasAIDLAutopilotStateModel autopilotStateModel) {
}
};
AutopilotServiceManage.getInstance().registerAutopilotDataListener( mAutopolitDataCallBack );
}
@@ -656,4 +662,15 @@ public class MogoADASController implements IMogoADASController {
);
}
}
@Override
public int getAutopilotStatus() {
int status = IMogoAdasOCHCallback.STATUS_AUTOPILOT_DISABLE;
try {
AutopilotServiceManage.getInstance().autopilotStateCall().getState();
} catch (Exception e) {
e.printStackTrace();
}
return status;
}
}