[开启自动驾驶页面]
This commit is contained in:
yangyakun
2023-07-18 15:54:24 +08:00
parent 8ee4c90d41
commit 69cdb25532
9 changed files with 328 additions and 351 deletions

View File

@@ -1,5 +0,0 @@
package com.mogo.och.taxi.passenger.callback;
public interface ITPClickStartAutopilotCallback {
void onClickCallback();
}

View File

@@ -1,7 +1,6 @@
package com.mogo.och.taxi.passenger.network
import android.content.Context
import com.mogo.cloud.passport.MoGoAiCloudClientConfig
import com.mogo.och.taxi.passenger.bean.TaxiPassengerOrdersInServiceQueryRespBean
import com.mogo.commons.AbsMogoApplication
import com.mogo.eagle.core.function.call.telematic.CallerTelematicManager
@@ -12,6 +11,8 @@ import com.mogo.och.taxi.passenger.bean.TaxiPassengerScoreUpdateOrderReqBean
import com.mogo.och.taxi.passenger.bean.TaxiPassengerAllStarWorld
import com.mogo.och.taxi.passenger.bean.TaxiPassengerStartReqBean
import com.mogo.eagle.core.network.MoGoRetrofitFactory
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.Companion.M_TAXI_P
import com.mogo.och.common.module.biz.constant.OchCommonConst
import com.mogo.och.common.module.biz.network.OchCommonServiceCallback
import com.mogo.och.common.module.biz.network.OchCommonSubscribeImpl
@@ -27,6 +28,8 @@ object TaxiPassengerServiceManager {
private val mOCHTaxiServiceApi: TaxiPassengerServiceApi =
MoGoRetrofitFactory.getInstance(OchCommonConst.getBaseUrl()).create(TaxiPassengerServiceApi::class.java)
private const val TAG = "TaxiPassengerServiceManager"
private var draiverSnCacher = ""
/**
@@ -45,6 +48,14 @@ object TaxiPassengerServiceManager {
get() {
return AbsMogoApplication.getApp()
}
private fun beforeNet():Boolean{
if (draiverSn.isBlank()) {
CallerLogger.e(M_TAXI_P + TAG, "没有司机屏sn 请稍等在请求")
return true
}
return false
}
/**
* 查询全部服务中/待服务订单列表
* @param context
@@ -54,6 +65,9 @@ object TaxiPassengerServiceManager {
fun queryOrdersInAndWaitService(
callback: OchCommonServiceCallback<TaxiPassengerOrdersInServiceQueryRespBean>?
) {
if(beforeNet()){
return
}
mOCHTaxiServiceApi.queryOrdersInAndWaitService(driverSn = draiverSn) //获取到司机端的sn
.transformTry()
.subscribe(OchCommonSubscribeImpl(context, callback, "queryOrdersInAndWaitService"))
@@ -116,6 +130,9 @@ object TaxiPassengerServiceManager {
orderNo: String?, loc: TaxiPassengerStartReqBean.Result?,
callback: OchCommonServiceCallback<TaxiPassengerBaseRespBean>?
) {
if(beforeNet()){
return
}
mOCHTaxiServiceApi.startServicePilotDone(data = TaxiPassengerStartReqBean(draiverSn, orderNo, loc))
.transformTry()
.subscribe(OchCommonSubscribeImpl(context, callback, "startServicePilotDone"))
@@ -141,6 +158,9 @@ object TaxiPassengerServiceManager {
context: Context, orderNo: String?,
callback: OchCommonServiceCallback<TaxiPassengerOrderQueryRespBean>?
) {
if(beforeNet()){
return
}
mOCHTaxiServiceApi.queryOrderById(
data=TaxiPassengerOrderQueryReqBean(draiverSn, orderNo)
)

View File

@@ -63,11 +63,6 @@ class BaseTaxiPassengerPresenter(view: TaxiPassengerBaseFragment?) :
) {
}
override fun onDriverHasCheckedPilotCondition(isBoarded: Boolean) {
d(SceneConstant.M_TAXI_P + TAG, "isBoarded = $isBoarded")
mView?.updateStartAutopilotBtnStatus(isBoarded)
}
private fun updateOrderView(order: TaxiPassengerOrderQueryRespBean.Result?) {
order?.let {
setItineraryVisibility()
@@ -80,13 +75,13 @@ class BaseTaxiPassengerPresenter(view: TaxiPassengerBaseFragment?) :
}
TaxiPassengerOrderStatusEnum.UserArriveAtStart -> {
mView?.showOrHideStartAutopilotView(isShow = true, isClickable = false)
mView?.showOrHideStartAutopilotView(isShow = true)
mView?.showOrHideArrivedEndLayout(isShow = false)
mView?.showOrHidePressengerCheckPager(isShow = false)
}
TaxiPassengerOrderStatusEnum.OnTheWayToEnd -> {
mView?.showOrHideStartAutopilotView(isShow = false, isClickable = false)
mView?.showOrHideStartAutopilotView(isShow = false)
mView?.showOrHideArrivedEndLayout(isShow = false)
mView?.showOrHidePressengerCheckPager(isShow = false)
}
@@ -100,7 +95,7 @@ class BaseTaxiPassengerPresenter(view: TaxiPassengerBaseFragment?) :
TaxiPassengerOrderStatusEnum.Cancel -> {
// 70 取消订单
mView?.showOrHideOverMapViewFragment(false)
mView?.showOrHideStartAutopilotView(isShow = false, isClickable = false)
mView?.showOrHideStartAutopilotView(isShow = false)
mView?.showOrHidePressengerCheckPager(isShow = false)
mView?.showOrHideArrivedEndLayout(isShow = false)
}

View File

@@ -3,8 +3,6 @@ package com.mogo.och.taxi.passenger.ui
import android.os.Bundle
import android.view.View
import com.mogo.commons.mvp.MvpFragment
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener
import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager
import com.mogo.eagle.core.function.call.hmi.CallerHmiManager
import com.mogo.eagle.core.function.call.map.CallerMapUIServiceManager
import com.mogo.eagle.core.utilcode.kotlin.onClick
@@ -14,12 +12,11 @@ import com.mogo.eagle.core.utilcode.util.UiThreadHandler
import com.mogo.map.listener.IMogoMapListener
import com.mogo.map.uicontroller.VisualAngleMode
import com.mogo.och.taxi.passenger.R
import com.mogo.och.taxi.passenger.bean.TaxiPassengerScoreUpdateOrderReqBean
import com.mogo.och.taxi.passenger.callback.ITPClickStartAutopilotCallback
import com.mogo.och.taxi.passenger.callback.ITaxiPassengerCommonValueCallback
import com.mogo.och.taxi.passenger.presenter.BaseTaxiPassengerPresenter
import com.mogo.och.taxi.passenger.ui.bottom.BottomBar
import com.mogo.och.taxi.passenger.ui.comment.TaxiPassengerArrivedView
import com.mogo.och.taxi.passenger.ui.startautopilot.StartAutopilotView
import kotlinx.android.synthetic.main.taxi_p_base_fragment.bottom
import kotlinx.android.synthetic.main.taxi_p_base_fragment.ck_setting
import kotlinx.android.synthetic.main.taxi_p_base_fragment.itinerary
@@ -28,7 +25,6 @@ import kotlinx.android.synthetic.main.taxi_p_base_fragment.overMapView
import kotlinx.android.synthetic.main.taxi_p_base_fragment.pcnActionView
import kotlinx.android.synthetic.main.taxi_p_base_fragment.romaPView
import kotlinx.android.synthetic.main.taxi_p_base_fragment.rv_location_center
import kotlinx.android.synthetic.main.taxi_p_base_fragment.traffic_light_view
import java.lang.ref.WeakReference
/**
@@ -41,7 +37,7 @@ import java.lang.ref.WeakReference
*/
class TaxiPassengerBaseFragment() :
MvpFragment<TaxiPassengerBaseFragment?, BaseTaxiPassengerPresenter?>(), IMogoMapListener,
TaxiPassengerTaxiView, ITPClickStartAutopilotCallback {
TaxiPassengerTaxiView {
/**
* 到达目的地
@@ -56,7 +52,7 @@ class TaxiPassengerBaseFragment() :
/**
* 启动自驾页面
*/
private var mStartAutopilotView: WeakReference<TaxiPassengerStartAutopilotView?>? = null
private var mStartAutopilotView: WeakReference<StartAutopilotView?>? = null
override fun getLayoutId(): Int {
return R.layout.taxi_p_base_fragment
@@ -68,7 +64,6 @@ class TaxiPassengerBaseFragment() :
override fun initViews() {
initListener()
onAutopilotStatusSuccessDone()
}
override fun initViews(savedInstanceState: Bundle?) {
@@ -130,6 +125,9 @@ class TaxiPassengerBaseFragment() :
// 切换缩放到中视角
controller.changeZoom2(0.8f)
}
showOrHideStartAutopilotView(true)
}
BottomBar.SelectView.OVERMAPVIEW -> {
overMapView.displayCustomOverView()
@@ -186,14 +184,6 @@ class TaxiPassengerBaseFragment() :
mapBizView!!.onDestroy()
overMapView?.onDestroy()
super.onDestroyView()
removeListener()
}
private fun removeListener() {
if (mStartAutopilotView == null || mStartAutopilotView!!.get() == null) {
return
}
mStartAutopilotView!!.get()!!.setOnClickStartAutopilotBtnCallback(null)
}
override fun onMapVisualAngleChanged(visualAngleMode: VisualAngleMode) {
@@ -247,40 +237,21 @@ class TaxiPassengerBaseFragment() :
*
* @param isShow
*/
fun showOrHideStartAutopilotView(isShow: Boolean, isClickable: Boolean) {
fun showOrHideStartAutopilotView(isShow: Boolean) {
if (isShow) {
if (mStartAutopilotView == null || mStartAutopilotView!!.get() == null) {
mStartAutopilotView = WeakReference(TaxiPassengerStartAutopilotView(context))
mStartAutopilotView = WeakReference(StartAutopilotView(requireContext()))
}
mStartAutopilotView?.get()?.let {
OverlayViewUtils.showOverlayView(activity, it)
it.handleStartAutopilotBtnStatus(false)
}
mStartAutopilotView!!.get()!!.setOnClickStartAutopilotBtnCallback(this)
OverlayViewUtils.showOverlayView(activity, mStartAutopilotView!!.get())
updateStartAutopilotBtnStatus(isClickable)
} else {
if (mStartAutopilotView == null || mStartAutopilotView!!.get() == null) {
return
}
mStartAutopilotView!!.get()!!.setOnClickStartAutopilotBtnCallback(null)
mStartAutopilotView!!.get()!!.closeAllAnimsAndView()
mStartAutopilotView?.get()?.closeAllAnimsAndView()
mStartAutopilotView = null
}
}
fun updateStartAutopilotBtnStatus(isClickable: Boolean) {
if (mStartAutopilotView == null || mStartAutopilotView!!.get() == null) {
return
}
mStartAutopilotView!!.get()!!.handleStartAutopilotBtnStatus(isClickable)
}
fun onAutopilotStatusSuccessDone() {
if ((IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING == CallerAutoPilotStatusListenerManager.getState())) {
if (mStartAutopilotView == null || mStartAutopilotView!!.get() == null) {
return
}
mStartAutopilotView!!.get()!!.onAutopilotStatusSuccess()
}
}
/**
* 显示或者隐藏到达乘客站点的洁面
* ① 取消订单 可有可无
@@ -349,10 +320,6 @@ class TaxiPassengerBaseFragment() :
}
}
override fun onClickCallback() {
mPresenter!!.startAutopilot()
}
companion object {
@JvmField
val TAG = "TaxiPassengerBaseFragment"

View File

@@ -1,289 +0,0 @@
package com.mogo.och.taxi.passenger.ui;
import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_TAXI_P;
import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.elegant.utils.UiThreadHandler;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
import com.mogo.eagle.core.utilcode.util.OverlayViewUtils;
import com.mogo.eagle.core.utilcode.util.ToastUtils;
import com.mogo.och.common.module.utils.AnimatorDrawableUtil;
import com.mogo.och.common.module.wigets.sfv.FrameSurfaceView;
import com.mogo.och.taxi.passenger.R;
import com.mogo.och.taxi.passenger.callback.ITPClickStartAutopilotCallback;
import java.util.Arrays;
/**
* @author: wangmingjun
* @date: 2022/6/14
*/
public class TaxiPassengerStartAutopilotView extends RelativeLayout implements View.OnClickListener {
private static final String TAG = TaxiPassengerStartAutopilotView.class.getSimpleName();
private TextView mStartAutopilotBtn;
private ImageView mAutopilotBtnBg;
private ImageView mCloseIV;
private ITPClickStartAutopilotCallback mClickCallback;
public boolean isStarting = false;
private static final long TIMER_START_AUTOPILOT_INTERVAL = 20 * 1000L;
private Context mContext;
private View view;
private AnimatorDrawableUtil mAnimationDrawable ;
private AnimatorDrawableUtil mCarAnimationDrawable ;
private ImageView mCarIv;
private Integer[] startingAnimIds = new Integer[]{
R.drawable.light_00000,
R.drawable.light_00001,
R.drawable.light_00002,
R.drawable.light_00003,
R.drawable.light_00004,
R.drawable.light_00005,
R.drawable.light_00006,
R.drawable.light_00007,
R.drawable.light_00008,
R.drawable.light_00009,
R.drawable.light_00010,
R.drawable.light_00011,
R.drawable.light_00012,
R.drawable.light_00013
};
private Integer[] startBtnBgAnimIds = new Integer[]{
R.drawable.image_00000, R.drawable.image_00001, R.drawable.image_00002, R.drawable.image_00003,
R.drawable.image_00004, R.drawable.image_00005, R.drawable.image_00006, R.drawable.image_00007,
R.drawable.image_00008, R.drawable.image_00009, R.drawable.image_00010, R.drawable.image_00011,
R.drawable.image_00012, R.drawable.image_00013,R.drawable.image_00014,R.drawable.image_00015,
R.drawable.image_00016, R.drawable.image_00017,R.drawable.image_00018,R.drawable.image_00019,
R.drawable.image_00020, R.drawable.image_00021,R.drawable.image_00022,R.drawable.image_00023,
R.drawable.image_00024, R.drawable.image_00025,R.drawable.image_00026,R.drawable.image_00027,
R.drawable.image_00028, R.drawable.image_00029,R.drawable.image_00030,R.drawable.image_00031,
R.drawable.image_00032, R.drawable.image_00033,R.drawable.image_00034,R.drawable.image_00035,
R.drawable.image_00036, R.drawable.image_00037,R.drawable.image_00038,R.drawable.image_00039,
R.drawable.image_00040, R.drawable.image_00041,R.drawable.image_00042,R.drawable.image_00043,
R.drawable.image_00044, R.drawable.image_00045,R.drawable.image_00046,R.drawable.image_00047,
R.drawable.image_00048, R.drawable.image_00049,R.drawable.image_00050,R.drawable.image_00051,
R.drawable.image_00052, R.drawable.image_00053,R.drawable.image_00054,R.drawable.image_00055,
R.drawable.image_00056, R.drawable.image_00057,R.drawable.image_00058,R.drawable.image_00059,
R.drawable.image_00060, R.drawable.image_00061,R.drawable.image_00062,R.drawable.image_00063,
R.drawable.image_00064, R.drawable.image_00065,R.drawable.image_00066,R.drawable.image_00067,
R.drawable.image_00068,R.drawable.image_00069,R.drawable.image_00070, R.drawable.image_00071,
R.drawable.image_00072,R.drawable.image_00073, R.drawable.image_00074, R.drawable.image_00075,
R.drawable.image_00076,R.drawable.image_00077,R.drawable.image_00078,R.drawable.image_00079,
R.drawable.image_00080, R.drawable.image_00081, R.drawable.image_00082,R.drawable.image_00083,
R.drawable.image_00084, R.drawable.image_00085, R.drawable.image_00086,R.drawable.image_00087,
R.drawable.image_00088, R.drawable.image_00089, R.drawable.image_00090,R.drawable.image_00091,
R.drawable.image_00092, R.drawable.image_00093, R.drawable.image_00094,R.drawable.image_00095,
R.drawable.image_00096, R.drawable.image_00097, R.drawable.image_00098,R.drawable.image_00099,
};
public TaxiPassengerStartAutopilotView(Context context) {
super(context);
mContext = context;
initView(context);
}
private void initView(Context context) {
view = LayoutInflater.from(context).inflate(R.layout.taxi_p_start_autopilot_view, this,true);
mStartAutopilotBtn = view.findViewById(R.id.taxi_p_start_autopilot);
mStartAutopilotBtn.setOnClickListener(this);
mCloseIV = view.findViewById(R.id.starting_autopilot_view_close);
mCloseIV.setOnClickListener(this);
mAutopilotBtnBg = view.findViewById(R.id.taxi_p_autopilot_btn_bg);
mCarIv = view.findViewById(R.id.taxi_p_autopilot_starting);
// initBtnAnimatonDrawable();
//
// initCarStartingFrame();
}
private void initCarStartingFrame() {
mCarAnimationDrawable = new AnimatorDrawableUtil();
mCarAnimationDrawable.setAnimation(mCarIv,Arrays.asList(startingAnimIds));
}
private void initBtnAnimatonDrawable() {
mAnimationDrawable = new AnimatorDrawableUtil();
mAnimationDrawable.setAnimation(mAutopilotBtnBg,Arrays.asList(startBtnBgAnimIds));
}
public void setOnClickStartAutopilotBtnCallback(ITPClickStartAutopilotCallback clickCallback){
this.mClickCallback = clickCallback;
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.taxi_p_start_autopilot){
//开启动画和自动驾驶
if (!(boolean)mStartAutopilotBtn.getTag()){
ToastUtils.showLong(R.string.taxi_p_start_autopilot_un_click_tip);
return;
}
if (!isStarting){
if (mClickCallback == null){
CallerLogger.INSTANCE.d(M_TAXI_P+TAG,"mClickCallback = null");
return;
}
startOrStopLoadingAnim(true);
mClickCallback.onClickCallback();
}
}else if (v.getId() == R.id.starting_autopilot_view_close){
closeAllAnimsAndView();
}
}
@SuppressLint("UseCompatLoadingForDrawables")
public void handleStartAutopilotBtnStatus(boolean isClickable){
if (mCarIv != null){
mCarIv.setBackgroundResource(R.drawable.light_00000);
}
if (mStartAutopilotBtn == null) return;
updateStartAutopilotBtnStatus(isClickable);
if (isClickable){ //高亮可点击状态下动画一直进行
startAutopilotBgAnimatorDrawable(true);
}else {// 置灰色可点击状态下动画停止
startAutopilotBgAnimatorDrawable(false);
}
}
public void updateStartAutopilotBtnStatus(boolean isClickable){
if (mContext == null) return;
if (isClickable){
mStartAutopilotBtn.setTextColor(
mContext.getResources().getColor(R.color.taxi_p_start_autopilot_txt_color));
mStartAutopilotBtn.setBackground(null);
}else {
mStartAutopilotBtn.setBackground(
mContext.getResources().getDrawable(R.drawable.taxi_p_start_autopilot_txt_btn_bg));
mAutopilotBtnBg.setBackground(null);
mStartAutopilotBtn.setTextColor(
mContext.getResources().getColor(R.color.taxi_p_start_autopilot_txt_un_color));
}
mStartAutopilotBtn.setTag(isClickable);
mStartAutopilotBtn.setText(
mContext.getResources().getString(R.string.taxi_p_start_autopilot_txt));
}
public void startAutopilotBgAnimatorDrawable(boolean isStart){
if (isStart){
if (mAnimationDrawable == null){
initBtnAnimatonDrawable();
}
if (mAnimationDrawable != null){
mAnimationDrawable.start(true, 30, null);
}
}else {
clearBgAnimDrawable();
}
}
private void startingCarBgAnimatorDrawable(boolean isStart){
if (isStart){
if (mCarAnimationDrawable == null){
initCarStartingFrame();
}
mCarIv.setBackgroundResource(0);
mCarAnimationDrawable.start(true,40, null);
}else {
if (mCarAnimationDrawable != null){
mCarAnimationDrawable.stop();
}
mCarIv.setBackgroundResource(R.drawable.light_00000);
}
}
public void startOrStopLoadingAnim(boolean start) {
startingCarBgAnimatorDrawable(start);
if (start) {
isStarting = true;
mStartAutopilotBtn.setText(getResources().getString(R.string.taxi_p_start_autopilot_loading));
mStartAutopilotBtn.setTextColor(getResources().getColor(R.color.taxi_p_start_autopilot_txt_color));
startingAutopilotCountDown();
} else {
clearBgAnimDrawable();
isStarting = false;
handleStartAutopilotBtnStatus(true);
}
}
public void clearBgAnimDrawable() {
if (mAnimationDrawable != null){
mAnimationDrawable.stop();
}
}
public void closeAllAnimsAndView(){
isStarting = false;
clearStartingAnimFrame();
clearBgAnimDrawable();
OverlayViewUtils.dismissOverlayView(this);
mContext = null;
}
public void clearStartingAnimFrame(){
if (mCarAnimationDrawable != null){
mCarAnimationDrawable.stop();
}
}
public void onAutopilotStatusSuccess(){
startOrStopLoadingAnim(false);
}
private void startingAutopilotCountDown() {
UiThreadHandler.postDelayed(new Runnable() {
@Override
public void run() { //未启动成功20s后做处理
if (isStarting){ //判断动画是否在进行
ToastUtils.showLong(R.string.taxi_p_start_autopilot_fail_10s_tip);
// startOrStopLoadingAnim(false);
updateStatusCountDownOver();
}
}
},TIMER_START_AUTOPILOT_INTERVAL);
}
private void updateStatusCountDownOver() {
if (mContext == null) return;
isStarting = false;
startingCarBgAnimatorDrawable(false);
mStartAutopilotBtn.setText(
mContext.getResources().getString(R.string.taxi_p_start_autopilot_txt));
}
@Override
protected void onDetachedFromWindow() {
isStarting = false;
clearStartingAnimFrame();
clearBgAnimDrawable();
mContext = null;
super.onDetachedFromWindow();
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
try {
mContext = AbsMogoApplication.getApp();
}catch (Exception e){
e.printStackTrace();
}
}
}

View File

@@ -41,6 +41,7 @@ class OrderInfoViewModel: ViewModel(), IMoGoChassisLocationGCJ02Listener,
override fun onCleared() {
super.onCleared()
this.viewCallback = null
TaxiPassengerModel.setOrderStatusCallback(TAG,null)
}
override fun onChassisLocationGCJ02(mogoLocation: MogoLocation?) {

View File

@@ -0,0 +1,243 @@
package com.mogo.och.taxi.passenger.ui.startautopilot
import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.RelativeLayout
import androidx.core.content.res.ResourcesCompat
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelStore
import androidx.lifecycle.ViewModelStoreOwner
import com.elegant.utils.UiThreadHandler
import com.mogo.eagle.core.utilcode.kotlin.onClick
import com.mogo.eagle.core.utilcode.util.OverlayViewUtils
import com.mogo.eagle.core.utilcode.util.ToastUtils
import com.mogo.och.common.module.utils.AnimatorDrawableUtil
import com.mogo.och.taxi.passenger.R
import kotlinx.android.synthetic.main.taxi_p_start_autopilot_view.view.starting_autopilot_view_close
import kotlinx.android.synthetic.main.taxi_p_start_autopilot_view.view.taxi_p_autopilot_btn_bg
import kotlinx.android.synthetic.main.taxi_p_start_autopilot_view.view.taxi_p_autopilot_starting
import kotlinx.android.synthetic.main.taxi_p_start_autopilot_view.view.taxi_p_start_autopilot
import java.util.Arrays
/**
* @author: wangmingjun
* @date: 2022/6/14
*/
class StartAutopilotView : RelativeLayout, StartAutopilotViewModel.StartAutopilotCallback,
ViewModelStoreOwner {
constructor(context: Context) : super(context)
constructor(context: Context, attributeSet: AttributeSet) : super(context, attributeSet)
constructor(context: Context, attributeSet: AttributeSet, defStyleAttr: Int) : super(context, attributeSet, defStyleAttr)
constructor(context: Context, attributeSet: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attributeSet, defStyleAttr, defStyleRes)
companion object {
private val TAG = StartAutopilotView::class.java.simpleName
private const val TIMER_START_AUTOPILOT_INTERVAL = 20 * 1000L
}
//定义ViewModelStore变量
private lateinit var mViewModelStore: ViewModelStore
var isStarting = false
private var mAnimationDrawable: AnimatorDrawableUtil? = null
private var mCarAnimationDrawable: AnimatorDrawableUtil? = null
private val startingAnimIds = arrayOf(R.drawable.light_00000, R.drawable.light_00001,
R.drawable.light_00002, R.drawable.light_00003, R.drawable.light_00004, R.drawable.light_00005,
R.drawable.light_00006, R.drawable.light_00007, R.drawable.light_00008, R.drawable.light_00009,
R.drawable.light_00010, R.drawable.light_00011, R.drawable.light_00012, R.drawable.light_00013
)
private val startBtnBgAnimIds = arrayOf(R.drawable.image_00000, R.drawable.image_00001,
R.drawable.image_00002, R.drawable.image_00003, R.drawable.image_00004, R.drawable.image_00005,
R.drawable.image_00006, R.drawable.image_00007, R.drawable.image_00008, R.drawable.image_00009,
R.drawable.image_00010, R.drawable.image_00011, R.drawable.image_00012, R.drawable.image_00013,
R.drawable.image_00014, R.drawable.image_00015, R.drawable.image_00016, R.drawable.image_00017,
R.drawable.image_00018, R.drawable.image_00019, R.drawable.image_00020, R.drawable.image_00021,
R.drawable.image_00022, R.drawable.image_00023, R.drawable.image_00024, R.drawable.image_00025,
R.drawable.image_00026, R.drawable.image_00027, R.drawable.image_00028, R.drawable.image_00029,
R.drawable.image_00030, R.drawable.image_00031, R.drawable.image_00032, R.drawable.image_00033,
R.drawable.image_00034, R.drawable.image_00035, R.drawable.image_00036, R.drawable.image_00037,
R.drawable.image_00038, R.drawable.image_00039, R.drawable.image_00040, R.drawable.image_00041,
R.drawable.image_00042, R.drawable.image_00043, R.drawable.image_00044, R.drawable.image_00045,
R.drawable.image_00046, R.drawable.image_00047, R.drawable.image_00048, R.drawable.image_00049,
R.drawable.image_00050, R.drawable.image_00051, R.drawable.image_00052, R.drawable.image_00053,
R.drawable.image_00054, R.drawable.image_00055, R.drawable.image_00056, R.drawable.image_00057,
R.drawable.image_00058, R.drawable.image_00059, R.drawable.image_00060, R.drawable.image_00061,
R.drawable.image_00062, R.drawable.image_00063, R.drawable.image_00064, R.drawable.image_00065,
R.drawable.image_00066, R.drawable.image_00067, R.drawable.image_00068, R.drawable.image_00069,
R.drawable.image_00070, R.drawable.image_00071, R.drawable.image_00072, R.drawable.image_00073,
R.drawable.image_00074, R.drawable.image_00075, R.drawable.image_00076, R.drawable.image_00077,
R.drawable.image_00078, R.drawable.image_00079, R.drawable.image_00080, R.drawable.image_00081,
R.drawable.image_00082, R.drawable.image_00083, R.drawable.image_00084, R.drawable.image_00085,
R.drawable.image_00086, R.drawable.image_00087, R.drawable.image_00088, R.drawable.image_00089,
R.drawable.image_00090, R.drawable.image_00091, R.drawable.image_00092, R.drawable.image_00093,
R.drawable.image_00094, R.drawable.image_00095, R.drawable.image_00096, R.drawable.image_00097,
R.drawable.image_00098, R.drawable.image_00099
)
init {
initView()
}
private fun initView() {
LayoutInflater.from(context).inflate(R.layout.taxi_p_start_autopilot_view, this, true)
mViewModelStore = ViewModelStore()
}
fun startAutopilotBgAnimatorDrawable(isStart: Boolean) {
if (isStart) {
if (mAnimationDrawable == null) {
initBtnAnimatonDrawable()
}
if (mAnimationDrawable != null) {
mAnimationDrawable!!.start(true, 30, null)
}
} else {
clearBgAnimDrawable()
}
}
@SuppressLint("UseCompatLoadingForDrawables")
override fun handleStartAutopilotBtnStatus(isClickable: Boolean) {
taxi_p_autopilot_starting?.setBackgroundResource(R.drawable.light_00000)
updateStartAutopilotBtnStatus(isClickable)
if (isClickable) { //高亮可点击状态下动画一直进行
startAutopilotBgAnimatorDrawable(true)
} else { // 置灰色可点击状态下动画停止
startAutopilotBgAnimatorDrawable(false)
}
}
fun closeAllAnimsAndView() {
isStarting = false
clearStartingAnimFrame()
clearBgAnimDrawable()
OverlayViewUtils.dismissOverlayView(this)
}
fun updateStartAutopilotBtnStatus(isBoarded: Boolean) {
taxi_p_start_autopilot?.let {
if (isBoarded) {
it.setTextColor(resources.getColor(R.color.taxi_p_start_autopilot_txt_color))
it.background = null
} else {
it.background = ResourcesCompat.getDrawable(resources,R.drawable.taxi_p_start_autopilot_txt_btn_bg,null)
taxi_p_autopilot_btn_bg!!.background = null
it.setTextColor(resources.getColor(R.color.taxi_p_start_autopilot_txt_un_color))
}
it.tag = isBoarded
it.text = resources.getString(R.string.taxi_p_start_autopilot_txt)
}
}
private fun initCarStartingFrame() {
mCarAnimationDrawable = AnimatorDrawableUtil()
mCarAnimationDrawable?.setAnimation(taxi_p_autopilot_starting, Arrays.asList(*startingAnimIds))
}
private fun initBtnAnimatonDrawable() {
mAnimationDrawable = AnimatorDrawableUtil()
mAnimationDrawable?.setAnimation(taxi_p_autopilot_btn_bg, Arrays.asList(*startBtnBgAnimIds))
}
private fun startingCarBgAnimatorDrawable(isStart: Boolean) {
if (isStart) {
if (mCarAnimationDrawable == null) {
initCarStartingFrame()
}
taxi_p_autopilot_starting!!.setBackgroundResource(0)
mCarAnimationDrawable!!.start(true, 40, null)
} else {
if (mCarAnimationDrawable != null) {
mCarAnimationDrawable!!.stop()
}
taxi_p_autopilot_starting!!.setBackgroundResource(R.drawable.light_00000)
}
}
private fun startOrStopLoadingAnim(start: Boolean) {
startingCarBgAnimatorDrawable(start)
if (start) {
isStarting = true
taxi_p_start_autopilot?.text = resources.getString(R.string.taxi_p_start_autopilot_loading)
taxi_p_start_autopilot?.setTextColor(resources.getColor(R.color.taxi_p_start_autopilot_txt_color))
startingAutopilotCountDown()
} else {
clearBgAnimDrawable()
isStarting = false
handleStartAutopilotBtnStatus(true)
}
}
private fun clearBgAnimDrawable() {
if (mAnimationDrawable != null) {
mAnimationDrawable!!.stop()
mAnimationDrawable = null
}
}
fun clearStartingAnimFrame() {
if (mCarAnimationDrawable != null) {
mCarAnimationDrawable!!.stop()
mCarAnimationDrawable = null
}
}
private fun startingAutopilotCountDown() {
UiThreadHandler.postDelayed({
//未启动成功20s后做处理
if (isStarting) { //判断动画是否在进行
ToastUtils.showLong(R.string.taxi_p_start_autopilot_fail_10s_tip)
updateStatusCountDownOver()
}
}, TIMER_START_AUTOPILOT_INTERVAL)
}
private fun updateStatusCountDownOver() {
isStarting = false
startingCarBgAnimatorDrawable(false)
taxi_p_start_autopilot?.text = resources.getString(R.string.taxi_p_start_autopilot_txt)
}
override fun onAttachedToWindow() {
super.onAttachedToWindow()
val viewModel = ViewModelProvider(this).get(StartAutopilotViewModel::class.java)
viewModel.setStartAutopilotCallback(this)
taxi_p_start_autopilot.onClick {
//开启动画和自动驾驶
if (!(taxi_p_start_autopilot!!.tag as Boolean)) {
ToastUtils.showLong(R.string.taxi_p_start_autopilot_un_click_tip)
return@onClick
}
if (!isStarting) {
startOrStopLoadingAnim(true)
viewModel.startAutopilot()
}
}
starting_autopilot_view_close.onClick {
closeAllAnimsAndView()
}
}
override fun onDetachedFromWindow() {
isStarting = false
clearStartingAnimFrame()
clearBgAnimDrawable()
//View移除时清理所有的viewModel
viewModelStore.clear()
super.onDetachedFromWindow()
}
override fun getViewModelStore(): ViewModelStore {
//接口方法实现
return mViewModelStore;
}
}

View File

@@ -0,0 +1,45 @@
package com.mogo.och.taxi.passenger.ui.startautopilot
import androidx.lifecycle.ViewModel
import com.mogo.och.taxi.passenger.callback.IOCHTaxiPassengerOrderStatusCallback
import com.mogo.och.taxi.passenger.model.AutopilotManager
import com.mogo.och.taxi.passenger.model.TaxiPassengerModel
class StartAutopilotViewModel: ViewModel(), IOCHTaxiPassengerOrderStatusCallback {
private val TAG = StartAutopilotViewModel::class.java.simpleName
private var viewCallback:StartAutopilotCallback?=null
init {
TaxiPassengerModel.setOrderStatusCallback(TAG,this)
}
fun setStartAutopilotCallback(viewCallback:StartAutopilotCallback){
this.viewCallback = viewCallback
TaxiPassengerModel.startOrStopReadyToAutopilotLoop(true)
}
override fun onCleared() {
super.onCleared()
this.viewCallback = null
TaxiPassengerModel.setOrderStatusCallback(TAG,null)
}
override fun onDriverHasCheckedPilotCondition(isBoarded: Boolean) {
viewCallback?.handleStartAutopilotBtnStatus(isBoarded)
}
/**
* 开启自动驾驶
*/
fun startAutopilot() {
AutopilotManager.startAutopilot()
}
interface StartAutopilotCallback{
fun handleStartAutopilotBtnStatus(isBoarded: Boolean)
}
}

View File

@@ -9,8 +9,8 @@
<ImageView
android:id="@+id/taxi_p_autopilot_starting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />