增加测试按钮

This commit is contained in:
tongchenfei
2021-01-26 20:32:48 +08:00
parent 41a1c60718
commit d2933a09b4
6 changed files with 147 additions and 49 deletions

View File

@@ -14,9 +14,9 @@ import com.mogo.och.bus.bean.OchBusStation;
import com.mogo.och.bus.constant.OchBusConst;
import com.mogo.och.bus.presenter.OchBusPresenter;
import com.mogo.och.view.SlidePanelView;
import com.mogo.service.adas.IMogoAdasOCHCallback;
import com.mogo.utils.logger.Logger;
import java.util.ArrayList;
import java.util.List;
@@ -44,6 +44,22 @@ public class OchBusFragment extends BaseOchFragment<OchBusFragment, OchBusPresen
adapter = new OchBusStationAdapter(getContext());
rvStationList.setAdapter(adapter);
rvStationList.setLayoutManager(new LinearLayoutManager(getContext()));
switch (MogoApisHandler.getInstance().getApis().getAdasControllerApi().getAutopilotStatus()) {
case IMogoAdasOCHCallback.STATUS_AUTOPILOT_DISABLE:
hideAutopilotBiz();
break;
case IMogoAdasOCHCallback.STATUS_AUTOPILOT_ENABLE:
showAutopilotBiz();
onAutopilotStatusChanged(false);
break;
case IMogoAdasOCHCallback.STATUS_AUTOPILOT_RUNNING:
showAutopilotBiz();
onAutopilotStatusChanged(true);
break;
default:
break;
}
}
@NonNull
@@ -112,15 +128,15 @@ public class OchBusFragment extends BaseOchFragment<OchBusFragment, OchBusPresen
}
// todo smoothMove
int moveTo = currPos +1;
int moveTo = currPos + 1;
if (currPos < 3) {
moveTo = 0;
}
if (currPos >= stationList.size() - 3) {
moveTo = stationList.size()-1;
moveTo = stationList.size() - 1;
}
if (moveTo >= stationList.size()) {
moveTo = stationList.size()-1;
moveTo = stationList.size() - 1;
}
rvStationList.smoothScrollToPosition(moveTo);
}
@@ -154,15 +170,15 @@ public class OchBusFragment extends BaseOchFragment<OchBusFragment, OchBusPresen
@Override
public void moveToEnd() {
hideNotice();
mPresenter.autoDriveToNextStation();
}
public void onAutopilotEnableChange(boolean isEnable) {
if (isEnable) {
showAutopilotBiz();
}else{
} else {
hideAutopilotBiz();
}
}
}

View File

@@ -128,30 +128,6 @@ public class OchBusPresenter extends Presenter<OchBusFragment> implements IMogoA
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()
.create(IOchBusApiService.class, HostConst.OCH_DOMAIN)
.leaveStation(request).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new SubscribeImpl<BaseData>(RequestOptions.create(getContext())) {
@Override
public void onError(String message, int code) {
super.onError(message, code);
Logger.d(TAG, "leave station error: " + message);
}
@Override
public void onError(Throwable e) {
super.onError(e);
Logger.e(TAG,e,"leave station exception");
}
});
if (mView != null) {
mView.refreshBusStations(stationList);
}
}
private void refreshCurrentStation() {
@@ -200,6 +176,31 @@ public class OchBusPresenter extends Presenter<OchBusFragment> implements IMogoA
case IMogoAdasOCHCallback.STATUS_AUTOPILOT_RUNNING:
mView.onAutopilotEnableChange(true);
mView.onAutopilotStatusChanged(true);
mView.hideSlidePanel();
mView.hideNotice();
RequestBody request = RequestBody.create(MediaType.get("application/json"), GsonUtil.jsonFromObject(new OchBusLeaveStationRequest(Utils.getSn(), stationList.get(currentStationIndex).getSiteId())));
MogoApisHandler.getInstance().getApis().getNetworkApi()
.create(IOchBusApiService.class, HostConst.OCH_DOMAIN)
.leaveStation(request).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new SubscribeImpl<BaseData>(RequestOptions.create(getContext())) {
@Override
public void onError(String message, int code) {
super.onError(message, code);
Logger.d(TAG, "leave station error: " + message);
}
@Override
public void onError(Throwable e) {
super.onError(e);
Logger.e(TAG,e,"leave station exception");
}
});
if (mView != null) {
mView.refreshBusStations(stationList);
}
break;
default:
mView.onAutopilotEnableChange(false);

View File

@@ -60,14 +60,23 @@ public abstract class BaseOchFragment<V extends IView, P extends Presenter<V>> e
@Override
public void onClickImpl(View v) {
// 如果能自动驾驶,就自动驾驶,不能就提示
if (MogoApisHandler.getInstance().getApis().getAdasControllerApi().getAutopilotStatus() != IMogoAdasOCHCallback.STATUS_AUTOPILOT_DISABLE) {
restartAutopilot();
}
// 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);
findViewById(R.id.btnAutopilotDisable).setOnClickListener(view-> MogoApisHandler.getInstance().getApis().getAdasControllerApi().mockOchStatus(IMogoAdasOCHCallback.STATUS_AUTOPILOT_DISABLE, "不能使用"));
findViewById(R.id.btnAutopilotEnable).setOnClickListener(view-> MogoApisHandler.getInstance().getApis().getAdasControllerApi().mockOchStatus(IMogoAdasOCHCallback.STATUS_AUTOPILOT_ENABLE, "能使用"));
findViewById(R.id.btnAutopilotRunning).setOnClickListener(view -> MogoApisHandler.getInstance().getApis().getAdasControllerApi().mockOchStatus(IMogoAdasOCHCallback.STATUS_AUTOPILOT_RUNNING, "Running"));
findViewById(R.id.btnAutopilotArrive).setOnClickListener(view -> MogoApisHandler.getInstance().getApis().getAdasControllerApi().mockOchStatus(-1, "Running"));
}
private void checkCallView(boolean isShown) {
@@ -82,25 +91,33 @@ public abstract class BaseOchFragment<V extends IView, P extends Presenter<V>> e
}
public void showSlidePanle(String text) {
slidePanelView.setText(text);
slidePanelView.setVisibility(View.VISIBLE);
getActivity().runOnUiThread(()->{
slidePanelView.setText(text);
slidePanelView.setVisibility(View.VISIBLE);
});
}
public void hideSlidePanel() {
slidePanelView.setVisibility(View.GONE);
getActivity().runOnUiThread(()->{
slidePanelView.setVisibility(View.GONE);
});
}
public void showNotice(String notice) {
tvNotice.setText(notice);
tvNotice.setVisibility(View.VISIBLE);
fivNoticeHead.setVisibility(View.VISIBLE);
fivNoticeHead.startAnim();
getActivity().runOnUiThread(()->{
tvNotice.setText(notice);
tvNotice.setVisibility(View.VISIBLE);
fivNoticeHead.setVisibility(View.VISIBLE);
fivNoticeHead.startAnim();
});
}
public void hideNotice() {
tvNotice.setVisibility(View.GONE);
fivNoticeHead.setVisibility(View.GONE);
fivNoticeHead.stopAnim();
getActivity().runOnUiThread(()->{
tvNotice.setVisibility(View.GONE);
fivNoticeHead.setVisibility(View.GONE);
fivNoticeHead.stopAnim();
});
}
/**
@@ -109,17 +126,23 @@ public abstract class BaseOchFragment<V extends IView, P extends Presenter<V>> e
* @param isInAutopilot true - 在自动驾驶中 false - 不在自动驾驶中
*/
public void onAutopilotStatusChanged(boolean isInAutopilot) {
ctvAutopilotStatus.setChecked(isInAutopilot);
getActivity().runOnUiThread(()->{
ctvAutopilotStatus.setChecked(isInAutopilot);
});
}
public void hideAutopilotBiz() {
ctvAutopilotStatus.setVisibility(View.GONE);
slidePanelView.setVisibility(View.GONE);
getActivity().runOnUiThread(()->{
ctvAutopilotStatus.setVisibility(View.GONE);
slidePanelView.setVisibility(View.GONE);
});
}
public void showAutopilotBiz() {
ctvAutopilotStatus.setVisibility(View.VISIBLE);
slidePanelView.setVisibility(View.VISIBLE);
getActivity().runOnUiThread(()->{
ctvAutopilotStatus.setVisibility(View.VISIBLE);
slidePanelView.setVisibility(View.VISIBLE);
});
}
public SlidePanelView.OnSlidePanelMoveToEndListener getSlidePanelOnEndListener() {

View File

@@ -65,4 +65,47 @@
app:layout_constraintRight_toRightOf="@id/module_mogo_och_notice"
app:layout_constraintTop_toTopOf="@id/module_mogo_och_notice"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnAutopilotDisable"
android:text="Disable"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:textSize="30sp"
android:background="#f00" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnAutopilotEnable"
android:text="Enable"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnAutopilotDisable"
app:layout_constraintRight_toRightOf="parent"
android:textSize="30sp"
android:background="#0f0" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnAutopilotRunning"
android:text="Running"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnAutopilotEnable"
app:layout_constraintRight_toRightOf="parent"
android:textSize="30sp"
android:background="#00f" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnAutopilotArrive"
android:text="Arrived"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnAutopilotRunning"
app:layout_constraintRight_toRightOf="parent"
android:textSize="30sp"
android:background="#f00" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -143,4 +143,6 @@ public interface IMogoADASController extends IProvider {
void onAutopilotArriveLike( int type );
int getAutopilotStatus();
void mockOchStatus(int state, String reason);
}

View File

@@ -669,10 +669,23 @@ public class MogoADASController implements IMogoADASController {
public int getAutopilotStatus() {
int status = IMogoAdasOCHCallback.STATUS_AUTOPILOT_DISABLE;
try {
AutopilotServiceManage.getInstance().autopilotStateCall().getState();
status = AutopilotServiceManage.getInstance().autopilotStateCall().getState();
} catch (Exception e) {
e.printStackTrace();
}
return status;
}
@Override
public void mockOchStatus(int state, String reason) {
if(state == -1){
if (mAdasOCHCallback != null) {
mAdasOCHCallback.onArriveAt(new AdasOCHData(1, 1d, 1d));
}
}else {
if (mAdasOCHCallback != null) {
mAdasOCHCallback.onStateChanged(state, reason);
}
}
}
}