[shuttle-jl]
[切换位置]
This commit is contained in:
yangyakun
2023-12-06 10:30:00 +08:00
parent 4e107b54e7
commit 1b676d34a3
93 changed files with 88 additions and 75 deletions

View File

@@ -10,7 +10,7 @@ import com.mogo.eagle.core.function.api.base.IMoGoFunctionProvider;
*
* Created on 2022/3/29
*/
interface IMogoOCH extends IMoGoFunctionProvider {
public interface IMogoOCH extends IMoGoFunctionProvider {
/**
* 初始化网约车容器

View File

@@ -1,7 +1,5 @@
package com.mogo.och.bus.passenger.constant
import com.mogo.commons.debug.DebugConfig
/**
* Created on 2021/12/6
*/

View File

@@ -0,0 +1,108 @@
package com.mogo.och.shuttle.passenger;
import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_TAXI_P;
import android.content.Context;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.mogo.eagle.core.data.config.FunctionBuildConfig;
import com.mogo.eagle.core.function.call.setting.CallerMoGoUiSettingManager;
import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils;
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
import com.mogo.eagle.core.utilcode.util.MultiDisplayUtils;
import com.mogo.och.bus.passenger.IMogoOCH;
import com.mogo.och.bus.passenger.constant.BusPassengerConst;
import com.mogo.och.shuttle.passenger.ui.BusPassengerRouteFragment;
import com.mogo.och.common.module.wigets.video.VideoPlayerActivity;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* 网约车-Bus-乘客端
*
* Created on 2022/3/29
*/
@Route(path = BusPassengerConst.PATH)
public class MogoOCHBusPassenger implements IMogoOCH {
private static final String TAG = MogoOCHBusPassenger.class.getSimpleName();
private FragmentActivity mActivity;
private int mContainerId;
private BusPassengerRouteFragment mPassengerFragment;
@Override
public void createCoverage(FragmentActivity activity, int containerId) {
}
@Nullable
@Override
public Fragment createCoverage(@Nullable FragmentActivity activity, @Nullable Integer containerId) {
this.mActivity = activity;
this.mContainerId = containerId;
showFragment();
if (AppIdentityModeUtils.isJL(FunctionBuildConfig.appIdentityMode)) {
MultiDisplayUtils.INSTANCE.startActWithSecond(activity, VideoPlayerActivity.class);
}
return null;
}
@NotNull
@Override
public String getFunctionName() {
return null;
}
@Override
public void onDestroy() {
// 若不调用finish, 设置中打开关闭UITouch,会造成och fragment 重叠
if (mActivity == null) return;
mActivity.finish();
}
@Override
public void init(Context context) {
}
/**
* 进入鹰眼模式,设置手势缩放地图失效
*/
private void stepIntoVrMode() {
CallerLogger.d( M_TAXI_P + TAG, "进入vr模式" );
CallerMoGoUiSettingManager.INSTANCE.stepInDayMode();//白天模式 状态栏字体颜色变黑
}
private void showFragment() {
FragmentManager supportFragmentManager = mActivity.getSupportFragmentManager();
if(mPassengerFragment == null){
CallerLogger.d(M_TAXI_P + TAG, "准备add fragment======");
Fragment fragmentByTag = supportFragmentManager.findFragmentByTag(BusPassengerRouteFragment.TAG);
if (fragmentByTag instanceof BusPassengerRouteFragment){
mPassengerFragment = (BusPassengerRouteFragment)fragmentByTag;
}else {
mPassengerFragment = new BusPassengerRouteFragment();
}
if (!mPassengerFragment.isAdded()){
supportFragmentManager.beginTransaction().add(mContainerId, mPassengerFragment
,BusPassengerRouteFragment.TAG).commitAllowingStateLoss();
}
return;
}
CallerLogger.d(M_TAXI_P + TAG, "准备show fragment");
supportFragmentManager.beginTransaction().show(mPassengerFragment).commitAllowingStateLoss();
}
private void hideFragment(){
if (mPassengerFragment != null){
mActivity.getSupportFragmentManager().beginTransaction().hide(mPassengerFragment).commitAllowingStateLoss();
}
}
}

View File

@@ -0,0 +1,140 @@
package com.mogo.och.shuttle.passenger.adapter;
import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.mogo.och.bus.passenger.R;
import com.mogo.och.common.module.utils.BlinkAnimationUtil;
import com.mogo.och.common.module.wigets.MarqueeTextView;
import com.mogo.och.data.bean.BusStationBean;
import java.util.List;
import static com.mogo.och.bus.passenger.constant.BusPassengerConst.STATION_STATUS_ARRIVING;
import static com.mogo.och.bus.passenger.constant.BusPassengerConst.STATION_STATUS_LEAVING;
import static com.mogo.och.bus.passenger.constant.BusPassengerConst.STATION_STATUS_STOPPED;
/**
* @author: wangmingjun
* @date: 2022/4/6
*/
public class BusPassengerLineStationsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private Context mContext;
private List<BusStationBean> mStations;
public BusPassengerLineStationsAdapter(Context context, List<BusStationBean> stations){
this.mContext = context;
this.mStations = stations;
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(mContext).inflate(R.layout.shuttle_p_jl_stations_common_item,parent,false);
StationViewHolder viewHolder = new StationViewHolder(view);
return viewHolder;
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
BusStationBean station = mStations.get(position);
StationViewHolder viewHolder = (StationViewHolder)holder;
viewHolder.stationName.setText(station.getName());
BlinkAnimationUtil.clearAnimation(viewHolder.stationCircle);
if (position == 0){ //第一个 起点
viewHolder.curArrowBg.setVisibility(View.GONE);
viewHolder.curArrowBottomBg.setVisibility(View.VISIBLE);
Log.d("onBindViewHolder" , "position0 = "+position);
viewHolder.stationCircle.setImageResource(R.drawable.shuttle_p_jl_bg_start_tag_bg);
if (station.getDrivingStatus() == STATION_STATUS_STOPPED && !station.isLeaving()){//到达未离开
viewHolder.stationName.setTextColor(mContext.getResources().getColor(R.color.bus_p_clock_17417B));
BlinkAnimationUtil.setAnimation(viewHolder.stationCircle);
viewHolder.stationName.setEllipsize(TextUtils.TruncateAt.MARQUEE);
viewHolder.curArrowBottomBg.setBackgroundColor(mContext.getColor(R.color.bus_p_clock_1F82FB));
}else {
viewHolder.stationName.setTextColor(mContext.getResources().getColor(R.color.bus_p_clock_992D3E5F));
viewHolder.stationName.setEllipsize(TextUtils.TruncateAt.END);
viewHolder.curArrowBottomBg.setBackgroundColor(mContext.getColor(R.color.bus_p_clock_A9B6CA));
}
}else{
viewHolder.curArrowBg.setVisibility(View.VISIBLE);
viewHolder.curArrowBottomBg.setVisibility(View.VISIBLE);
BusStationBean preStation = mStations.get(position -1);
if (station.getDrivingStatus() == STATION_STATUS_LEAVING ||
(station.getDrivingStatus() == STATION_STATUS_STOPPED && station.isLeaving())){ //过站
viewHolder.stationName.setTextColor(mContext.getResources().getColor(R.color.bus_p_clock_992D3E5F));
viewHolder.curArrowBg.setBackgroundColor(mContext.getColor(R.color.bus_p_clock_A9B6CA));
viewHolder.curArrowBottomBg.setBackgroundColor(mContext.getColor(R.color.bus_p_clock_A9B6CA));
viewHolder.stationCircle.setImageResource(R.drawable.shuttle_p_jl_point_gray);
viewHolder.stationName.setEllipsize(TextUtils.TruncateAt.END);
Log.d("onBindViewHolder" , "position 1 = "+position);
} else if (station.getDrivingStatus() == STATION_STATUS_STOPPED && !station.isLeaving()){//刚到站未离开的
viewHolder.stationName.setTextColor(mContext.getResources().getColor(R.color.bus_p_clock_17417B));
viewHolder.curArrowBg.setBackgroundColor(mContext.getColor(R.color.bus_p_clock_A9B6CA));
viewHolder.curArrowBottomBg.setBackgroundColor(mContext.getColor(R.color.bus_p_clock_1F82FB));
viewHolder.stationCircle.setImageResource(R.drawable.shuttle_p_jl_arrive_line_green);
if (position == mStations.size() - 1){
viewHolder.stationCircle.setImageResource(R.drawable.shuttle_p_jl_bg_end_tag_bg);
viewHolder.curArrowBottomBg.setVisibility(View.GONE);
}
Log.d("onBindViewHolder" , "position2 = "+position);
BlinkAnimationUtil.setAnimation(viewHolder.stationCircle);
viewHolder.stationName.setEllipsize(TextUtils.TruncateAt.MARQUEE);
}else if (station.getDrivingStatus() == STATION_STATUS_ARRIVING && preStation.isLeaving()){//即将到站
viewHolder.stationName.setTextColor(mContext.getResources().getColor(R.color.bus_p_panel_cur_station_tips_color));
viewHolder.curArrowBg.setBackgroundColor(mContext.getColor(R.color.bus_p_clock_A9B6CA));
viewHolder.curArrowBottomBg.setBackgroundColor(mContext.getColor(R.color.bus_p_clock_1F82FB));
viewHolder.stationCircle.setImageResource(R.drawable.shuttle_p_jl_arrive_line_blue);
Log.d("onBindViewHolder" , "position3 = "+position);
if (position == mStations.size() - 1){
viewHolder.curArrowBottomBg.setVisibility(View.GONE);
}
}else if (station.getDrivingStatus() == STATION_STATUS_ARRIVING &&
(preStation.getDrivingStatus() == STATION_STATUS_ARRIVING
|| preStation.getDrivingStatus() == STATION_STATUS_STOPPED)){ //未到站的并且前面也是未到站或者刚到站的
viewHolder.stationName.setTextColor(mContext.getResources().getColor(R.color.bus_p_panel_cur_station_tips_color));
viewHolder.curArrowBg.setBackgroundColor(mContext.getColor(R.color.bus_p_clock_1F82FB));
viewHolder.curArrowBottomBg.setBackgroundColor(mContext.getColor(R.color.bus_p_clock_1F82FB));
viewHolder.stationCircle.setImageResource(R.drawable.shuttle_p_jl_point_blue);
viewHolder.stationName.setEllipsize(TextUtils.TruncateAt.END);
if (position == mStations.size() - 1){
viewHolder.stationCircle.setImageResource(R.drawable.shuttle_p_jl_bg_end_tag_bg);
viewHolder.curArrowBottomBg.setVisibility(View.GONE);
}
Log.d("onBindViewHolder" , "position4 = "+position);
}
}
}
@Override
public int getItemCount() {
return mStations.size();
}
}
class StationViewHolder extends RecyclerView.ViewHolder{
public MarqueeTextView stationName;
public ImageView stationCircle;
public ImageView curArrowBg;
public ImageView curArrowBottomBg;
public StationViewHolder(@NonNull View itemView) {
super(itemView);
stationName = itemView.findViewById(R.id.bus_p_station);
stationCircle = itemView.findViewById(R.id.bus_p_circle);
curArrowBg = itemView.findViewById(R.id.bus_p_cur_arrow_bg);
curArrowBottomBg = itemView.findViewById(R.id.bus_p_cur_arrow_bottom_bg);
}
}

View File

@@ -0,0 +1,21 @@
package com.mogo.och.shuttle.passenger.bean;
import com.mogo.eagle.core.data.BaseData;
/**
* @author congtaowang
* @since 2021/3/22
*
* 小巴车运营状态返回参数
*/
public class BusPassengerOperationStatusResponse extends BaseData {
public Result data;
public static class Result {
private String sn; //司机屏sn
private String phone; //司机手机号
public String plateNumber; //车牌号
public int driverStatus;//0:已收车1:已出车
}
}

View File

@@ -0,0 +1,16 @@
package com.mogo.och.shuttle.passenger.bean;
public
/**
* @author congtaowang
* @since 2021/3/22
*
* 根据车机行驶线路站点信息
*/
class BusPassengerQueryLineRequest {
private String sn;
public BusPassengerQueryLineRequest(String sn) {
this.sn = sn;
}
}

View File

@@ -0,0 +1,29 @@
package com.mogo.och.shuttle.passenger.bean;
import com.mogo.eagle.core.data.BaseData;
import com.mogo.och.data.bean.BusRoutesResult;
/**
* 网约车小巴路线接口请求响应结果 返回的是对应司机屏的线路信息
*
* @author tongchenfei
*/
public class BusPassengerRoutesResponse extends BaseData {
private BusRoutesResult data;
public BusRoutesResult getResult() {
return data;
}
public void setResult(BusRoutesResult data) {
this.data = data;
}
@Override
public String toString() {
return "OchBusRoutesResponse{" +
"data=" + data +
'}';
}
}

View File

@@ -0,0 +1,85 @@
package com.mogo.och.shuttle.passenger.bean;
import java.util.List;
import java.util.Objects;
/**
* 网约车小巴路线接口返回接口数据封装
*
* @author tongchenfei
*/
public class BusPassengerRoutesResult {
private List<BusPassengerStation> sites;
private int lineId;
private String name; //线路名称
private int lineType; //线路类型0:环形
private String description;
private int status;
private String runningDur; //运营时间
private long taskTime; //线路时间班次
private long writeVersion;//更新时间戳
public List<BusPassengerStation> getSites() {
return sites;
}
public int getLineId() {
return lineId;
}
public String getName() {
return name;
}
public int getLineType() {
return lineType;
}
public String getDescription() {
return description;
}
public int getStatus() {
return status;
}
public String getRunningDur() {
return runningDur;
}
public long getWriteVersion() {
return writeVersion;
}
@Override
public String toString() {
return "BusPassengerRoutesResult{" +
"sites=" + sites +
", lineId=" + lineId +
", name='" + name + '\'' +
", lineType=" + lineType +
", description='" + description + '\'' +
", status=" + status +
", writeVersion="+ writeVersion+
", runningDur='" + runningDur + '\'' +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
BusPassengerRoutesResult that = (BusPassengerRoutesResult) o;
return lineId == that.lineId
&& lineType == that.lineType
&& status == that.status
&& sites.equals(that.sites)
&& name.equals(that.name)
&& runningDur.equals(that.runningDur);
}
@Override
public int hashCode() {
return Objects.hash(sites, lineId, name, lineType, description, status, runningDur);
}
}

View File

@@ -0,0 +1,173 @@
package com.mogo.och.shuttle.passenger.bean;
import java.util.Objects;
/**
* 单个网约车小巴车站信息
*
* @author wangmingjun
*/
public class BusPassengerStation {
private String name;
private String description;
private String cityCode;
private double lon; //高精坐标
private double lat; //高精坐标
private double gcjLon; //高德坐标
private double gcjLat; //高德坐标
private int businessType; //站点类型9:taxi10:bus
private int status;
private int siteId;
private int seq;
private int drivingStatus;//行驶信息0初始值1已经过2当前站3未到站
private int ifStop = 1; // 是否需要停靠、1需要、0不需要 // TODO: 2021/10/19 原来站点里有设计是否需要停靠字段,现设计暂无,默认都需要停靠
private boolean leaving;
public void setName(String name) {
this.name = name;
}
public void setDescription(String description) {
this.description = description;
}
public void setCityCode(String cityCode) {
this.cityCode = cityCode;
}
public void setLon(double lon) {
this.lon = lon;
}
public void setLat(double lat) {
this.lat = lat;
}
public void setBusinessType(int businessType) {
this.businessType = businessType;
}
public void setStatus(int status) {
this.status = status;
}
public void setSiteId(int siteId) {
this.siteId = siteId;
}
public void setSeq(int seq) {
this.seq = seq;
}
public void setDrivingStatus(int drivingStatus) {
this.drivingStatus = drivingStatus;
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
public String getCityCode() {
return cityCode;
}
public double getGcjLon() {
return gcjLon;
}
public double getGcjLat() {
return gcjLat;
}
public int getBusinessType() {
return businessType;
}
public int getStatus() {
return status;
}
public int getSiteId() {
return siteId;
}
public int getSeq() {
return seq;
}
public int getDrivingStatus() {
return drivingStatus;
}
public double getLon() {
return lon;
}
public double getLat() {
return lat;
}
public void setIfStop(int ifStop) {
this.ifStop = ifStop;
}
public int getIfStop() {
return ifStop;
}
public void setLeaving(boolean leaving) {
this.leaving = leaving;
}
public boolean isLeaving() {
return leaving;
}
@Override
public String toString() {
return "OchBusStation{" +
"name='" + name + '\'' +
", description='" + description + '\'' +
", cityCode='" + cityCode + '\'' +
", lon=" + lon +
", lat=" + lat +
", businessType=" + businessType +
", status=" + status +
", siteId=" + siteId +
", seq=" + seq +
", drivingStatus=" + drivingStatus +
", ifStop=" + ifStop +
", leaving=" + leaving +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
BusPassengerStation that = (BusPassengerStation) o;
return Double.compare(that.lon, lon) == 0
&& Double.compare(that.lat, lat) == 0
&& Double.compare(that.gcjLon, gcjLon) == 0
&& Double.compare(that.gcjLat, gcjLat) == 0
&& businessType == that.businessType
&& status == that.status
&& siteId == that.siteId
&& seq == that.seq
&& drivingStatus == that.drivingStatus
&& ifStop == that.ifStop
&& leaving == that.leaving
&& Objects.equals(name, that.name)
&& Objects.equals(cityCode, that.cityCode);
}
@Override
public int hashCode() {
return Objects.hash(name, description, cityCode, lon, lat, gcjLon, gcjLat, businessType, status, siteId, seq, drivingStatus, ifStop, leaving);
}
}

View File

@@ -0,0 +1,10 @@
package com.mogo.och.shuttle.passenger.callback;
/**
* @author: wangmingjun
* @date: 2021/10/22
*/
public interface IBusPassegerDriverStatusCallback {
void changeOperationStatus(boolean changeStatus);
void updatePlateNumber(String plateNumber);
}

View File

@@ -0,0 +1,20 @@
package com.mogo.och.shuttle.passenger.callback;
/**
* Created on 2022/3/31
*
* Model->Presenter回调ADAS相关自动驾驶状态回调到达终点等等
*/
public interface IBusPassengerADASStatusCallback {
// 自动驾驶触发的已到达目的地:暂未用到
void onAutopilotArriveEnd();
// 自动驾驶可用状态
void onAutopilotEnable();
// 自动驾驶不可用状态
void onAutopilotDisable();
// 自动驾驶运行中
void onAutopilotRunning();
}

View File

@@ -0,0 +1,15 @@
package com.mogo.och.shuttle.passenger.callback;
import com.amap.api.maps.model.LatLng;
import java.util.List;
import mogo.telematics.pad.MessagePad;
/**
* Created on 2022/3/31
*/
public interface IBusPassengerAutopilotPlanningCallback {
void routePlanningToNextStationChanged(long meters, long timeInSecond);
void updateTotalDistance();
}

View File

@@ -0,0 +1,15 @@
package com.mogo.och.shuttle.passenger.callback;
import com.mogo.eagle.core.data.map.MogoLocation;
/**
* Created on 2022/3/31
*
* Model->Presenter回调状态控制器监听accOn、adas ui show、voice ui show、push ui show、v2x ui show等等
*/
public interface IBusPassengerControllerStatusCallback {
// 是否vr map模式
void onVRModeChanged(boolean isVRMode);
// 自车定位
void onCarLocationChanged(MogoLocation location);
}

View File

@@ -0,0 +1,9 @@
package com.mogo.och.shuttle.passenger.callback;
/**
* @author: wangmingjun
* @date: 2022/3/10
*/
public interface IBusPassengerMapViewCallback {
void onCameraChange(float bearing);
}

View File

@@ -0,0 +1,16 @@
package com.mogo.och.shuttle.passenger.callback;
import com.mogo.och.data.bean.BusStationBean;
import java.util.List;
/**
* @author: wangmingjun
* @date: 2022/4/6
*/
public interface IBusPassengerRouteLineInfoCallback {
void updateLineInfo(String lineName);
void updateStationsInfo(List<BusStationBean> stations, int currentStationIndex, boolean isArrived);
void showNoTaskView();
void hideNoTaskView();
}

View File

@@ -0,0 +1,672 @@
package com.mogo.och.shuttle.passenger.model;
import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_BUS_P;
import static com.mogo.och.bus.passenger.constant.BusPassengerConst.QUERY_BUS_P_STATION_DELAY;
import static com.mogo.och.bus.passenger.constant.BusPassengerConst.STATION_STATUS_STOPPED;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.os.Handler;
import android.os.Message;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.mogo.aicloud.services.socket.MogoAiCloudSocketManager;
import com.mogo.commons.debug.DebugConfig;
import com.mogo.commons.module.intent.IMogoIntentListener;
import com.mogo.commons.module.intent.IntentManager;
import com.mogo.commons.module.status.IMogoStatusChangedListener;
import com.mogo.commons.module.status.MogoStatusManager;
import com.mogo.eagle.core.function.api.telematic.IReceivedMsgListener;
import com.mogo.eagle.core.function.call.telematic.CallerTelematicListenerManager;
import com.mogo.eagle.core.function.call.telematic.CallerTelematicManager;
import com.mogo.eagle.core.utilcode.mogo.logger.Logger;
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant;
import com.mogo.eagle.core.utilcode.util.GsonUtils;
import com.mogo.eagle.core.utilcode.util.ToastUtils;
import com.mogo.och.bus.passenger.R;
import com.mogo.och.shuttle.passenger.bean.BusPassengerOperationStatusResponse;
import com.mogo.och.shuttle.passenger.bean.BusPassengerRoutesResponse;
import com.mogo.och.common.module.bean.dpmsg.AppConnectMsg;
import com.mogo.och.common.module.bean.dpmsg.BaseDPMsg;
import com.mogo.och.common.module.bean.dpmsg.DPMsgType;
import com.mogo.och.common.module.bean.dpmsg.TaskDetailsMsg;
import com.mogo.och.common.module.biz.common.socketmessage.OCHSocketMessageManager;
import com.mogo.och.common.module.biz.constant.OchCommonConst;
import com.mogo.och.common.module.manager.distancemamager.IDistanceListener;
import com.mogo.och.common.module.manager.distancemamager.TrajectoryAndDistanceManager;
import com.mogo.och.common.module.utils.DateTimeUtil;
import com.mogo.commons.module.status.StatusDescriptor;
import com.mogo.eagle.core.data.autopilot.AutopilotStatusInfo;
import com.mogo.eagle.core.data.config.FunctionBuildConfig;
import com.mogo.eagle.core.data.map.MogoLocation;
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener;
import com.mogo.eagle.core.function.api.autopilot.IMoGoChassisLocationGCJ02Listener;
import com.mogo.eagle.core.function.api.autopilot.IMoGoPlanningRottingListener;
import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager;
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationGCJ02ListenerManager;
import com.mogo.eagle.core.function.call.autopilot.CallerPlanningRottingListenerManager;
import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils;
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
import com.mogo.eagle.core.utilcode.mogo.storage.SharedPrefsMgr;
import com.mogo.eagle.core.utilcode.util.NetworkUtils;
import com.mogo.och.shuttle.passenger.callback.IBusPassegerDriverStatusCallback;
import com.mogo.och.shuttle.passenger.callback.IBusPassengerADASStatusCallback;
import com.mogo.och.shuttle.passenger.callback.IBusPassengerAutopilotPlanningCallback;
import com.mogo.och.shuttle.passenger.callback.IBusPassengerControllerStatusCallback;
import com.mogo.och.shuttle.passenger.callback.IBusPassengerRouteLineInfoCallback;
import com.mogo.och.bus.passenger.constant.BusPassengerConst;
import com.mogo.och.shuttle.passenger.network.BusPassengerModelLoopManager;
import com.mogo.och.shuttle.passenger.network.BusPassengerServiceManager;
import com.mogo.och.common.module.biz.network.OchCommonServiceCallback;
import com.mogo.och.common.module.manager.AbnormalFactorsLoopManager;
import com.mogo.och.common.module.utils.CoordinateCalculateRouteUtil;
import com.mogo.och.common.module.utils.RxUtils;
import com.mogo.och.data.bean.BusRoutesResult;
import com.mogo.och.data.bean.BusStationBean;
import com.mogo.och.data.bean.BusTransferData;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import io.reactivex.disposables.Disposable;
import mogo.telematics.pad.MessagePad;
import mogo_msg.MogoReportMsg;
import system_master.SsmInfo;
import system_master.SystemStatusInfo;
/**
* Created on 2022/3/31
*/
public class BusPassengerModel {
private static final String TAG = BusPassengerModel.class.getSimpleName();
private volatile List<MogoLocation> mRoutePoints = new ArrayList<>();
// 1s内只接受一次轨迹
private volatile Disposable globalPathTruncation;
private static final class SingletonHolder {
private static final BusPassengerModel INSTANCE = new BusPassengerModel();
}
public static BusPassengerModel getInstance() {
return SingletonHolder.INSTANCE;
}
private Context mContext;
private IBusPassengerADASStatusCallback mADASStatusCallback; //Model->Presenter自动驾驶状态相关
private IBusPassengerAutopilotPlanningCallback mAutopilotPlanningCallback; //Model->Presenter自动驾驶线路规划
private Map<String, IBusPassengerControllerStatusCallback> mControllerStatusCallbackMap = new ConcurrentHashMap<>();
private IBusPassegerDriverStatusCallback mDriverStatusCallback; //出车收车状态
private IBusPassengerRouteLineInfoCallback mRouteLineInfoCallback; // bus路线信息更新
private MogoLocation mLocation = null;
private BusRoutesResult routesResult = null;
List<BusStationBean> mStations = new ArrayList<>();
private int mNextStationIndex = 0;// 要到达站的index
private List<MogoLocation> mTwoStationsRouts = new ArrayList<>();
private int mPreRouteIndex = 0;
private int mWipePreIndex = 0;
private volatile boolean isGoingToNextStation = false;
private static final int MSG_QUERY_BUS_P_STATION = 1001;
private final Handler handler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(Message msg) {
if ( msg.what == MSG_QUERY_BUS_P_STATION ) {
queryDriverOperationStatus();
return true;
}
return false;
}
});
private BusPassengerModel() {
}
public void init( Context context ) {
mContext = context.getApplicationContext();
initListeners();
queryDriverOperationStatus();
queryDriverByLocalDriver();
startOrStopOrderLoop(true);
}
private void queryDriverByLocalDriver() {
//本地去请求司机端
TaskDetailsMsg msg = new TaskDetailsMsg("task");
sendMsgToServer(GsonUtils.toJson(msg));
}
public void setDriverStatusCallback(IBusPassegerDriverStatusCallback callback){
this.mDriverStatusCallback = callback;
}
public void setRouteLineInfoCallback(IBusPassengerRouteLineInfoCallback callback){
this.mRouteLineInfoCallback = callback;
}
private void queryDriverOperationDelay() {
handler.sendEmptyMessageDelayed( MSG_QUERY_BUS_P_STATION, QUERY_BUS_P_STATION_DELAY );
}
private void sendMsgToServer(String msg){
CallerTelematicManager.INSTANCE.sendMsgToServer(
OchCommonConst.BUSINESS_STRING,
msg.getBytes()
);
}
private void queryDriverOperationStatus() {
BusPassengerServiceManager.queryDriverOperationStatus(mContext
, new OchCommonServiceCallback<BusPassengerOperationStatusResponse>() {
@Override
public void onSuccess(BusPassengerOperationStatusResponse data) {
if (data == null || data.data == null) return;
if (mDriverStatusCallback != null) {
CallerLogger.d( M_BUS_P + TAG, "queryDriverOperationStatus = %s", data.data.plateNumber );
mDriverStatusCallback.changeOperationStatus(data.data.driverStatus == 1);
mDriverStatusCallback.updatePlateNumber(data.data.plateNumber);
}
}
@Override
public void onError() {
if (!NetworkUtils.isConnected(mContext)) {
ToastUtils.showShort(mContext.getString(R.string.network_error_tip));
} else {
ToastUtils.showShort(mContext.getString(R.string.request_error_tip));
}
}
@Override
public void onFail(int code, String msg) {
//延迟3s再次查询
queryDriverOperationDelay();
}
});
}
public void queryDriverSiteByCoordinate(){
BusPassengerServiceManager.queryDriverSiteByCoordinate(mContext
, new OchCommonServiceCallback<BusPassengerRoutesResponse>() {
@Override
public void onSuccess(BusPassengerRoutesResponse data) {
if ( data == null || data.getResult() == null) {
CallerLogger.d( M_BUS_P + TAG, "queryDriverSiteByCoordinate = null");
clearLocalRouteResult();
return;
}
if (routesResult != null && data.getResult().equals(routesResult)){
CallerLogger.d( M_BUS_P + TAG, "queryDriverSiteByCoordinate = not update");
return;
}
if (routesResult != null &&
routesResult.getWriteVersion() < data.getResult().getWriteVersion()){
routesResult = data.getResult();
}
if (routesResult == null){
routesResult = data.getResult();
}
updatePassengerRouteInfo(routesResult);
}
@Override
public void onError() {
CallerLogger.d( M_BUS_P + TAG, "queryDriverSiteByCoordinate = onError ="
+ ", sn = " +BusPassengerServiceManager.INSTANCE.getDriverAppSn());
queryDriverByLocalDriver();
}
@Override
public void onFail(int code, String msg) {
CallerLogger.d( M_BUS_P + TAG, "queryDriverSiteByCoordinate = %s", msg
+ ", sn = " +BusPassengerServiceManager.INSTANCE.getDriverAppSn());
if (code == 1003){
queryDriverOperationDelay();
}
if (BusPassengerServiceManager.INSTANCE.getDriverAppSn().isEmpty()){
//此处拦截是为了防止过程中乘客屏和司机端断连拿不到司机端sn, 造成请求失败去刷新了界面
return;
}
if (code == 1003){
routesResult = null;
cleanStation("queryDriverSiteByCoordinate 1003");
return;
}
queryDriverByLocalDriver();
}
});
}
private void clearLocalRouteResult() {
if (routesResult != null) {
routesResult = null;
}
mNextStationIndex = 0;
cleanStation("queryDriverSiteByCoordinate");
mRoutePoints.clear();
if (mRouteLineInfoCallback != null){
mRouteLineInfoCallback.showNoTaskView();
}
}
private void updatePassengerRouteInfo(BusRoutesResult result) {
if (result == null){
clearLocalRouteResult();
return;
}
CallerLogger.d( M_BUS_P + TAG, "queryDriverSiteByCoordinate = update");
routesResult = result;
if (mRouteLineInfoCallback != null){
mRouteLineInfoCallback.updateLineInfo(result.getName());
mRouteLineInfoCallback.hideNoTaskView();
if (result.getSites() != null){
List<BusStationBean> stations = result.getSites();
mStations.clear();
mStations.addAll(stations);
for (int i = 0; i< stations.size(); i++){
BusStationBean station = stations.get(i);
if (station.getDrivingStatus() == STATION_STATUS_STOPPED && station.isLeaving() && i+1 < stations.size()){
Logger.d(M_BUS_P + TAG, "order = station= leave");
isGoingToNextStation = true;
mRouteLineInfoCallback.updateStationsInfo(stations,i+1,false);
if(mNextStationIndex != i+1){
mTwoStationsRouts.clear();
}
mNextStationIndex = i+1;
BusStationBean startStation = mStations.get(i);
BusStationBean endStation = mStations.get(i+1);
setTrajectoryStation(startStation, endStation, result.getLineId());
return;
}else if (station.getDrivingStatus() == STATION_STATUS_STOPPED && !station.isLeaving()){
if (i == stations.size() - 1) {
cleanStation("updatePassengerRouteInfo最后一个站点");
}
isGoingToNextStation = false;
Logger.d(M_BUS_P + TAG, "order = station= arrive");
mPreRouteIndex = 0;
mRouteLineInfoCallback.updateStationsInfo(stations,i,true);
return;
}
}
}
}
}
public void release() {
releaseListeners();
cleanStation("release");
startOrStopOrderLoop(false);
}
public void setMoGoAutopilotPlanningListener(IBusPassengerAutopilotPlanningCallback
moGoAutopilotPlanningCallback) {
this.mAutopilotPlanningCallback = moGoAutopilotPlanningCallback;
}
public void setADASStatusCallback(IBusPassengerADASStatusCallback callback) {
this.mADASStatusCallback = callback;
}
public void setControllerStatusCallback(String tag, IBusPassengerControllerStatusCallback callback) {
if (tag == null || "".equals(tag)) return;
if (callback == null) {
mControllerStatusCallbackMap.remove(tag);
return;
}
mControllerStatusCallbackMap.put(tag,callback);
}
private void initListeners() {
// 2021.11.1重构自动驾驶 实现接口 IMoGoAutopilotStatusListener 注册监听 替换IMogoAdasOCHCallback接口
CallerAutoPilotStatusListenerManager.INSTANCE.addListener(TAG, mGoAutopilotStatusListener);
IntentManager.getInstance().registerIntentListener(ConnectivityManager.CONNECTIVITY_ACTION, mNetWorkIntentListener );
MogoStatusManager.getInstance().registerStatusChangedListener(TAG, StatusDescriptor.VR_MODE, mMogoStatusChangedListener );
// 定位监听
CallerChassisLocationGCJ02ListenerManager.INSTANCE.addListener(TAG, 10,mMapLocationListener);
//2021.11.1 自动驾驶路线规划接口
CallerPlanningRottingListenerManager.INSTANCE.addListener(TAG,moGoAutopilotPlanningListener);
//监听司机端消息
CallerTelematicListenerManager.INSTANCE.addListener(TAG,mReceivedMsgListener);
AbnormalFactorsLoopManager.INSTANCE.startLoopAbnormalFactors(mContext);
TrajectoryAndDistanceManager.INSTANCE.addDistanceListener(TAG, trajectoryListener);
}
private void releaseListeners() {
MogoStatusManager.getInstance().unregisterStatusChangedListener(TAG, StatusDescriptor.VR_MODE, mMogoStatusChangedListener);
// 注销定位监听
CallerChassisLocationGCJ02ListenerManager.INSTANCE.removeListener(TAG);
MogoAiCloudSocketManager.getInstance(mContext)
.unregisterLifecycleListener(10010);
CallerAutoPilotStatusListenerManager.INSTANCE.removeListener(mGoAutopilotStatusListener);
CallerPlanningRottingListenerManager.INSTANCE.removeListener(moGoAutopilotPlanningListener);
AbnormalFactorsLoopManager.INSTANCE.stopLoopAbnormalFactors();
CallerTelematicListenerManager.INSTANCE.removeListener(TAG);
CallerTelematicListenerManager.INSTANCE.removeListener(TAG);
}
private final IDistanceListener trajectoryListener = new IDistanceListener() {
@Override
public void stationDistanceCallback(float distance) {
}
@Override
public void distanceCallback(float distance) {
double lastTime = distance / BusPassengerConst.BUS_AVERAGE_SPEED * 3.6; //秒
CallerLogger.d(M_BUS_P + TAG, "轨迹排查==lastSumLength = "+distance);
if(routesResult!=null){
for (BusStationBean site : routesResult.getSites()) {
if (site.getDrivingStatus() == BusPassengerConst.STATION_STATUS_STOPPED && !site.isLeaving()) {
return;
}
}
}
mAutopilotPlanningCallback.routePlanningToNextStationChanged(
(long)distance, (long)lastTime
);
}
};
private final IReceivedMsgListener mReceivedMsgListener = new IReceivedMsgListener() {
@Override
public void onDemoMode(boolean isDemoMode) {
}
@Override
public void onReceivedServerSn(@Nullable String sn) {
}
@Override
public void onReceivedMsg(int type, @NonNull byte[] byteArray) {
if (OchCommonConst.BUSINESS_STRING == type) {
BaseDPMsg baseMsg = GsonUtils.fromJson(new String(byteArray), BaseDPMsg.class);
Logger.d(SceneConstant.M_BUS_P + TAG, "onReceivedMsg = " + GsonUtils.toJson(baseMsg));
if (baseMsg != null && baseMsg.getType() == DPMsgType.TYPE_COMMON.getType()) {
AppConnectMsg msg = GsonUtils.fromJson(new String(byteArray), AppConnectMsg.class);
if (msg != null && msg.isViewShow()) { //消息盒子显示内容
OCHSocketMessageManager.INSTANCE.pushAppOperationalMsgBox(
DateTimeUtil.getCurrentTimeStamp(), msg.getMsg(),
OCHSocketMessageManager.OPERATION_SYSTEM);
}
} else if (baseMsg != null && baseMsg.getType() == DPMsgType.TYPE_TASK_DETAILS.getType()) {
TaskDetailsMsg msg = GsonUtils.fromJson(new String(byteArray), TaskDetailsMsg.class);
Logger.d(SceneConstant.M_BUS_P + TAG, "onReceivedMsg = " + GsonUtils.toJson(msg));
if (msg == null || msg.getMsg().isEmpty()) {
clearLocalRouteResult();
return;
}
BusTransferData result = GsonUtils.fromJson(msg.getMsg(), BusTransferData.class);
if (msg != null && mDriverStatusCallback != null) {
mDriverStatusCallback.changeOperationStatus(result.getLoginStatus() == 1);
}
if (result != null) { //已司机端传来的为准
routesResult = result.getRoutesResult();
updatePassengerRouteInfo(routesResult);
}
}
}
}
};
//监听网络变化,避免启动机器时无网导致无法更新订单信息
private final IMogoIntentListener mNetWorkIntentListener = new IMogoIntentListener() {
@Override
public void onIntentReceived( String intentStr, Intent intent ) {
CallerLogger.d( M_BUS_P + TAG, "onIntentReceived = %s", intentStr );
if ( ConnectivityManager.CONNECTIVITY_ACTION.equals( intentStr ) ) {
if ( NetworkUtils.isConnected( mContext ) ) {
queryDriverOperationStatus();
}
}
}
};
// VR mode变更回调
private final IMogoStatusChangedListener mMogoStatusChangedListener = (descriptor, isTrue) -> {
if (StatusDescriptor.VR_MODE == descriptor) {
if (mControllerStatusCallbackMap.size() > 0) {
for (IBusPassengerControllerStatusCallback callback :mControllerStatusCallbackMap.values()){
callback.onVRModeChanged(isTrue);
}
}
}
};
private final IMoGoChassisLocationGCJ02Listener mMapLocationListener = new IMoGoChassisLocationGCJ02Listener() {
@Override
public void onChassisLocationGCJ02(@Nullable MogoLocation gnssInfo) {
if (null == gnssInfo) return;
mLocation = gnssInfo;
for (IBusPassengerControllerStatusCallback callback :mControllerStatusCallbackMap.values()){
callback.onCarLocationChanged(gnssInfo);
}
}
};
private final IMoGoAutopilotStatusListener mGoAutopilotStatusListener = new IMoGoAutopilotStatusListener(){
@Override
public void onSystemStatus(@NonNull SsmInfo.SsmStatusInf statusInf) {
//IMoGoAutopilotStatusListener.super.onSystemStatus(statusInf);
}
@Override
public void onAutopilotDockerInfo(@NonNull String dockerVersion) {
// TODO: 2023/6/19 mingjun
}
@Override
public void onAutopilotStatusResponse(int state) {
if (state == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING) {
//2022.7.20 自动驾驶更换成带档位的
if (mADASStatusCallback != null) mADASStatusCallback.onAutopilotRunning();
} else{
if (FunctionBuildConfig.isDemoMode &&
mNextStationIndex>= 0 && mNextStationIndex <= mStations.size() - 1
&& isGoingToNextStation){
Logger.d(M_BUS_P + TAG, "FunctionBuildConfig.isDemoMode is true");
return;
}
if (state == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_ENABLE) {
mTwoStationsRouts.clear();
if (mADASStatusCallback != null) mADASStatusCallback.onAutopilotEnable();
} else if (state == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_DISABLE) {
mTwoStationsRouts.clear();
if (mADASStatusCallback != null) mADASStatusCallback.onAutopilotDisable();
}else if (state == IMoGoAutopilotStatusListener.STATUS_PARALLEL_DRIVING){
mTwoStationsRouts.clear();
if (mADASStatusCallback != null) mADASStatusCallback.onAutopilotRunning();
}
}
}
@Override
public void onAutopilotRouteLineId(long lineId) {
}
@Override
public void onAutopilotIpcConnectStatusChanged(int status, @Nullable String reason) {
}
@Override
public void onAutopilotGuardian(@Nullable MogoReportMsg.MogoReportMessage guardianInfo) {
}
private boolean arriveAtEnd = false; //乘客app专用字段
@Override
public void onAutopilotStatusResponse(@NotNull AutopilotStatusInfo autopilotStatusInfo) {
}
@Override
public void onAutopilotSNRequest() {
}
@Override
public void onAutopilotArriveAtStation(@Nullable MessagePad.ArrivalNotification arrivalNotification) {
if (FunctionBuildConfig.isDemoMode
&& AppIdentityModeUtils.isPassenger(FunctionBuildConfig.appIdentityMode)) {
arriveAtEnd = true;
}
// TODO: 2022/3/31
if (DebugConfig.isDebug()) {
// ToastUtils.showShort("到达目的地");
}
if (mADASStatusCallback != null){
mADASStatusCallback.onAutopilotArriveEnd();
}
}
@Override
public void onAutopilotStatusRespByQuery(@NonNull SystemStatusInfo.StatusInfo status) {
}
};
private final IMoGoPlanningRottingListener moGoAutopilotPlanningListener = new IMoGoPlanningRottingListener(){
@Override
public synchronized void onAutopilotRotting(@Nullable MessagePad.GlobalPathResp routeList) {
// CallerLogger.d(M_BUS_P + TAG, "onAutopilotRotting = "
// + GsonUtil.jsonFromObject(routeList));
List<MessagePad.Location> routePoints = routeList.getWayPointsList();
if(globalPathTruncation!=null&&!globalPathTruncation.isDisposed()){
CallerLogger.d(M_BUS_P + TAG, "1s内不可以接受轨迹");
return;
}
globalPathTruncation = RxUtils.INSTANCE.createSubscribe(1_000, () -> {
CallerLogger.d(M_BUS_P + TAG, "可以接受轨迹");
return null;
});
CallerLogger.d(M_BUS_P + TAG, "接受轨迹中");
if (null != routePoints && routePoints.size() > 0){
updateRoutePoints(routePoints);
}
}
};
public synchronized void updateRoutePoints(List<MessagePad.Location> routePoints){
mRoutePoints.clear();
List<MogoLocation> latLngModels = CoordinateCalculateRouteUtil
.coordinateConverterWgsToGcjLocations(mContext,routePoints);
mRoutePoints.addAll(latLngModels);
calculateTwoStationsRoute();
}
private void calculateTwoStationsRoute(){
//找出前往站对应的轨迹点,拿出两站点的集合
CallerLogger.d(M_BUS_P + TAG, "mRoutePoints.size() = " + mRoutePoints.size());
if (mRoutePoints.size() > 0) {
if (mStations.size() > 1){ //两个站点及以上要计算两个站点间的轨迹路线
if (mNextStationIndex <= mStations.size()-1 && mNextStationIndex - 1 >=0){
mTwoStationsRouts.clear();
BusStationBean stationNext = mStations.get(mNextStationIndex);
BusStationBean stationCur = mStations.get(mNextStationIndex - 1);
//当前站在轨迹中对应的点
int currentRouteIndex = CoordinateCalculateRouteUtil.getArrivedPointIndexNew(0
,mRoutePoints
,stationCur.getGcjLon(),stationCur.getGcjLat());
//要前往的站在轨迹中对应的点
int nextRouteIndex = CoordinateCalculateRouteUtil.getArrivedPointIndexNew(currentRouteIndex
,mRoutePoints
,stationNext.getGcjLon(),stationNext.getGcjLat());
CallerLogger.d(M_BUS_P + TAG, "轨迹排查==currentRouteIndex = " + currentRouteIndex
+ " nextRouteIndex = " + nextRouteIndex);
if (currentRouteIndex < nextRouteIndex){ //如果找到的next在起点的轨迹前面直接舍弃这个轨迹不显示
mTwoStationsRouts.addAll(mRoutePoints.subList(currentRouteIndex,nextRouteIndex + 1));
}
}
}
// else { //只有两个站点的时候整个路线就是两个站点之间的轨迹
// mTwoStationsRouts.clear();
// mTwoStationsRouts.addAll(mRoutePoints);
// }
if (mTwoStationsRouts.size() > 0){
float sumLength = CoordinateCalculateRouteUtil.calculateRouteSumLength(mTwoStationsRouts);
SharedPrefsMgr.getInstance(mContext).putInt(BusPassengerConst.BUS_SP_KEY_ORDER_SUM_DIS,(int) sumLength);
if (mAutopilotPlanningCallback != null){
mAutopilotPlanningCallback.updateTotalDistance();
}
}
}
}
public int getAverageSpeed(){
return BusPassengerConst.SHUTTLE_AVERAGE_SPEED;
}
public void loopRouteAndWipe() {
}
private void startOrStopOrderLoop(boolean start) {
CallerLogger.d(M_BUS_P + TAG, "startOrStopOrderLoop() " + start);
if (start) {
BusPassengerModelLoopManager.getInstance().startQueryDriverLineLoop();
} else {
BusPassengerModelLoopManager.getInstance().stopQueryDriverLineLoop();
}
}
private void setTrajectoryStation(
BusStationBean startStationInfo ,
BusStationBean endStationInfo,
int lineId
) {
MogoLocation startStation = new MogoLocation();
startStation.setLongitude(startStationInfo.getGcjLon());
startStation.setLatitude(startStationInfo.getGcjLat());
MogoLocation endStation = new MogoLocation();
endStation.setLongitude(endStationInfo.getGcjLon());
endStation.setLatitude(endStationInfo.getGcjLat());
TrajectoryAndDistanceManager.INSTANCE.setStationPoint(startStation, endStation, (long)lineId);
}
private void cleanStation(String type) {
CallerLogger.d(M_BUS_P + TAG, "清理站点:"+type);
TrajectoryAndDistanceManager.INSTANCE.setStationPoint(null, null, -1L);
}
}

View File

@@ -0,0 +1,60 @@
package com.mogo.och.shuttle.passenger.network;
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
import com.mogo.och.shuttle.passenger.model.BusPassengerModel;
import java.util.concurrent.TimeUnit;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_BUS_P;
import static com.mogo.och.bus.passenger.constant.BusPassengerConst.LOOP_DELAY;
import static com.mogo.och.bus.passenger.constant.BusPassengerConst.LOOP_LINE_2S;
/**
* Created on 2021/11/22
*
* 管理轮询逻辑(订单轮询、新单轮询、新单抢单结果轮询等等)
*/
public class BusPassengerModelLoopManager {
private static final String TAG = BusPassengerModelLoopManager.class.getSimpleName();
private static final class SingletonHolder {
private static final BusPassengerModelLoopManager INSTANCE = new BusPassengerModelLoopManager();
}
public static BusPassengerModelLoopManager getInstance() {
return SingletonHolder.INSTANCE;
}
private Disposable mQueryLineDisposable; //心跳轮询
private CompositeDisposable mRouteWipeDisposable;
private CompositeDisposable mCalculateRouteDisposable; //每隔2s计算一次剩余里程和时间
public void startQueryDriverLineLoop() {
if (mQueryLineDisposable != null && !mQueryLineDisposable.isDisposed()) {
return;
}
CallerLogger.i(M_BUS_P + TAG, "startQueryDriverLineLoop()");
mQueryLineDisposable = Observable.interval(LOOP_DELAY,
LOOP_LINE_2S, TimeUnit.MILLISECONDS)
.map((aLong -> aLong + 1))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(aLong -> BusPassengerModel.getInstance().queryDriverSiteByCoordinate());
}
public void stopQueryDriverLineLoop() {
if (mQueryLineDisposable != null) {
CallerLogger.i(M_BUS_P + TAG, "stopQueryDriverLineLoop()");
mQueryLineDisposable.dispose();
mQueryLineDisposable = null;
}
}
}

View File

@@ -0,0 +1,77 @@
package com.mogo.och.shuttle.passenger.network
import android.content.Context
import com.mogo.eagle.core.function.call.telematic.CallerTelematicManager.getServerToken
import com.mogo.och.shuttle.passenger.bean.BusPassengerRoutesResponse
import com.mogo.cloud.passport.MoGoAiCloudClientConfig
import com.mogo.och.shuttle.passenger.bean.BusPassengerQueryLineRequest
import com.mogo.och.shuttle.passenger.bean.BusPassengerOperationStatusResponse
import com.mogo.eagle.core.network.MoGoRetrofitFactory
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
import com.mogo.och.common.module.biz.network.interceptor.transformTry
/**
* Created on 2022/3/31
*/
object BusPassengerServiceManager {
private var driverSnCache = ""
private var mShuttleBusPassengerServiceApi =
MoGoRetrofitFactory.getInstance(OchCommonConst.getShuttleUrl()).create(
ShettlePassengerServiceApi::class.java)
/**
* 获取Bus司机端的sn
* @return
*/
val driverAppSn: String
get() {
val serverToken = getServerToken()
if (serverToken != driverSnCache && serverToken.isNotEmpty()) {
driverSnCache = serverToken
}
return driverSnCache
}
/**
* 查询绑定行驶的小巴车路线
* @param context
* @param callback
*/
@JvmStatic
fun queryDriverSiteByCoordinate(
context: Context, callback: OchCommonServiceCallback<BusPassengerRoutesResponse>?
) {
mShuttleBusPassengerServiceApi.queryDriverSiteByCoordinate(
MoGoAiCloudClientConfig.getInstance().serviceAppId,
MoGoAiCloudClientConfig.getInstance().token,
BusPassengerQueryLineRequest(
driverAppSn
)
).transformTry()
.subscribe(OchCommonSubscribeImpl(context, callback, "queryDriverSiteByCoordinate"))
}
/**
* 查询司机端出车收车状态,以及车牌号
* @param context
* @param callback
*/
@JvmStatic
fun queryDriverOperationStatus(
context: Context,
callback: OchCommonServiceCallback<BusPassengerOperationStatusResponse>?
) {
mShuttleBusPassengerServiceApi.queryDriverOperationStatus(
MoGoAiCloudClientConfig.getInstance().serviceAppId,
MoGoAiCloudClientConfig.getInstance().token,
driverAppSn
)
.transformTry()
.subscribe(OchCommonSubscribeImpl(context, callback, "queryDriverOperationStatus"))
}
}

View File

@@ -0,0 +1,40 @@
package com.mogo.och.shuttle.passenger.network;
import com.mogo.och.shuttle.passenger.bean.BusPassengerOperationStatusResponse;
import com.mogo.och.shuttle.passenger.bean.BusPassengerQueryLineRequest;
import com.mogo.och.shuttle.passenger.bean.BusPassengerRoutesResponse;
import io.reactivex.Observable;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.Header;
import retrofit2.http.Headers;
import retrofit2.http.POST;
import retrofit2.http.Query;
/**
* Created on 2022/3/31
*
* Bus乘客端接口定义
*/
interface ShettlePassengerServiceApi {
/**
* 查询bus司机端绑定路线
* @return 接口返回数据
*/
@Headers( {"Content-Type:application/json;charset=UTF-8"} )
@POST( "/och-shuttle-cabin/api/business/v1/passenger/lineDataWithDriver/query" )
Observable<BusPassengerRoutesResponse> queryDriverSiteByCoordinate(@Header("appId") String appId, @Header("ticket") String ticket, @Body BusPassengerQueryLineRequest request);
/**
* 查询司机端的登陆状态
* @param sn
* @return
*/
@Headers({"Content-type:application/json;charset=UTF-8"})
// @GET("/autopilot-car-hailing/car/v2/driver/bus/passenger/takeOrderStatus/query")
@GET("/och-shuttle-cabin/api/business/v1/passenger/loginStatus")
Observable<BusPassengerOperationStatusResponse> queryDriverOperationStatus(@Header ("appId") String appId, @Header("ticket") String ticket, @Query("sn") String sn);
}

View File

@@ -0,0 +1,156 @@
package com.mogo.och.shuttle.passenger.presenter;
import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_BUS_P;
import android.os.Looper;
import androidx.annotation.NonNull;
import androidx.lifecycle.LifecycleOwner;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.commons.mvp.Presenter;
import com.mogo.eagle.core.data.map.MogoLocation;
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener;
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
import com.mogo.eagle.core.utilcode.util.UiThreadHandler;
import com.mogo.och.shuttle.passenger.callback.IBusPassegerDriverStatusCallback;
import com.mogo.och.shuttle.passenger.callback.IBusPassengerADASStatusCallback;
import com.mogo.och.shuttle.passenger.callback.IBusPassengerAutopilotPlanningCallback;
import com.mogo.och.shuttle.passenger.callback.IBusPassengerControllerStatusCallback;
import com.mogo.och.shuttle.passenger.callback.IBusPassengerRouteLineInfoCallback;
import com.mogo.och.shuttle.passenger.model.BusPassengerModel;
import com.mogo.och.shuttle.passenger.ui.BusPassengerRouteFragment;
import com.mogo.och.data.bean.BusStationBean;
import java.util.List;
/**
* Created on 2022/3/31
*/
public class BaseBusPassengerPresenter extends Presenter<BusPassengerRouteFragment> implements
IBusPassengerADASStatusCallback, IBusPassengerControllerStatusCallback, IBusPassegerDriverStatusCallback, IBusPassengerRouteLineInfoCallback, IBusPassengerAutopilotPlanningCallback {
private static final String TAG = BaseBusPassengerPresenter.class.getSimpleName();
public BaseBusPassengerPresenter(BusPassengerRouteFragment view) {
super(view);
BusPassengerModel.getInstance().init(AbsMogoApplication.getApp());
initListeners();
}
@Override
public void onCreate( @NonNull LifecycleOwner owner ) {
super.onCreate( owner );
CallerLogger.d( M_BUS_P + TAG, "Bus乘客端Presenter onCreate()" );
}
@Override
public void onDestroy( @NonNull LifecycleOwner owner ) {
super.onDestroy( owner );
releaseListeners();
BusPassengerModel.getInstance().release();
}
private void initListeners() {
BusPassengerModel.getInstance().setADASStatusCallback(this);
BusPassengerModel.getInstance().setControllerStatusCallback(TAG, this);
BusPassengerModel.getInstance().setDriverStatusCallback(this);
BusPassengerModel.getInstance().setRouteLineInfoCallback(this);
BusPassengerModel.getInstance().setMoGoAutopilotPlanningListener(this);
}
private void releaseListeners() {
BusPassengerModel.getInstance().setADASStatusCallback(null);
BusPassengerModel.getInstance().setControllerStatusCallback(TAG, null);
BusPassengerModel.getInstance().setDriverStatusCallback(null);
BusPassengerModel.getInstance().setRouteLineInfoCallback(null);
BusPassengerModel.getInstance().setMoGoAutopilotPlanningListener(null);
}
private void runOnUIThread( Runnable executor ) {
if ( executor == null ) {
return;
}
if ( Looper.myLooper() != Looper.getMainLooper() ) {
UiThreadHandler.post( executor );
} else {
executor.run();
}
}
@Override
public void onAutopilotArriveEnd() {
// mView.showOverviewFragment();
}
@Override
public void onAutopilotEnable() {
runOnUIThread(() -> mView.onAutopilotStatusChanged(
IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_ENABLE));
}
@Override
public void onAutopilotDisable() {
runOnUIThread(() -> mView.onAutopilotStatusChanged(
IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_DISABLE));
}
@Override
public void onAutopilotRunning() {
runOnUIThread(() -> mView.onAutopilotStatusChanged(
IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING));
}
@Override
public void onVRModeChanged(boolean isVRMode) {
}
@Override
public void onCarLocationChanged(MogoLocation location) {
if (location != null){
runOnUIThread(() -> mView.onCarLocationChanged(location));
}
}
@Override
public void changeOperationStatus(boolean changeStatus) {
runOnUIThread(() -> mView.changeOperationStatus(changeStatus));
}
@Override
public void updatePlateNumber(String plateNumber) {
// runOnUIThread(() -> mView.updatePlateNum(plateNumber));
}
@Override
public void updateLineInfo(String lineName) {
runOnUIThread(() -> mView.updateLineInfo(lineName));
}
@Override
public void updateStationsInfo(List<BusStationBean> stations, int currentStationIndex, boolean isArrived) {
runOnUIThread(() -> mView.updateStationsInfo(stations,currentStationIndex, isArrived));
}
@Override
public void showNoTaskView() {
runOnUIThread(() -> mView.showNoTaskView());
}
@Override
public void hideNoTaskView() {
runOnUIThread(() -> mView.hideNoTaskView());
}
@Override
public void routePlanningToNextStationChanged(long meters, long timeInSecond) {
runOnUIThread(() -> mView.updateRoutePlanningToNextStation(meters, timeInSecond));
}
@Override
public void updateTotalDistance() {
// runOnUIThread(() -> mView.setProgressBarMax());
}
}

View File

@@ -0,0 +1,33 @@
package com.mogo.och.shuttle.passenger.provider;
import android.content.Context;
import android.view.View;
import com.mogo.och.shuttle.passenger.ui.BusPStatusBarView;
import androidx.annotation.NonNull;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.mogo.eagle.core.data.constants.MogoServicePaths;
import com.mogo.eagle.core.function.api.hmi.view.IStatusViewLayout;
/**
* @author congtaowang
* @since 2020-01-06
* <p>
* 根据优先级控制显示 window view.
*/
@Route( path = MogoServicePaths.PATH_STATUS_VIEW_MANAGER )
public class B1StatusViewManager implements IStatusViewLayout {
@NonNull
@Override
public View getStatusView(Context context) {
return new BusPStatusBarView(context);
}
@Override
public void init(Context context) {
}
}

View File

@@ -0,0 +1,36 @@
package com.mogo.och.shuttle.passenger.ui
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import com.mogo.eagle.core.function.api.devatools.IMoGoDevaToolsListener
import com.mogo.eagle.core.function.hmi.ui.widget.BlueToothView
import com.mogo.eagle.core.utilcode.util.ThreadUtils
import com.mogo.och.bus.passenger.R
import kotlinx.android.synthetic.main.shuttle_p_jl_view_blue_tooth.view.blueView
/**
* 魔戒蓝牙控件
* 放置于StatusBar右侧位置
*/
class BusPBlueToothView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : BlueToothView(context, attrs, defStyleAttr),IMoGoDevaToolsListener {
init {
LayoutInflater.from(context).inflate(R.layout.shuttle_p_jl_view_blue_tooth, this, true)
}
override fun mofangStatus(status: Boolean) {
ThreadUtils.runOnUiThread {
if (status) {
blueView.setImageResource(R.drawable.shuttle_p_jl_blue_tooth_close)
} else {
blueView.setImageResource(R.drawable.shuttle_p_jl_blue_tooth_open)
}
}
}
}

View File

@@ -0,0 +1,66 @@
package com.mogo.och.shuttle.passenger.ui
import android.annotation.*
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.constraintlayout.widget.ConstraintLayout
import com.mogo.eagle.core.function.api.hmi.view.IViewControlListener
import com.mogo.eagle.core.function.api.setting.IMoGoSkinModeChangeListener
import com.mogo.eagle.core.function.call.devatools.CallerDevaToolsManager
import com.mogo.eagle.core.function.call.hmi.CallerHmiViewControlListenerManager
import com.mogo.eagle.core.function.call.setting.CallerSkinModeListenerManager
import com.mogo.eagle.core.utilcode.kotlin.*
import com.mogo.och.bus.passenger.R
import kotlinx.coroutines.*
import me.jessyan.autosize.utils.AutoSizeUtils
/**
* @author: wangmingjun
* @date: 2023/2/14
*/
class BusPStatusBarView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null
) : ConstraintLayout(context, attrs), IViewControlListener, IMoGoSkinModeChangeListener{
companion object {
const val TAG = "BusPStatusBarView"
}
init {
LayoutInflater.from(context).inflate(R.layout.shuttle_p_jl_view_status_bar, this, true)
setBackgroundResource(R.drawable.shuttle_p_jl_bg_status_bar)
isClickable = true
isFocusable = true
}
@SuppressLint("ClickableViewAccessibility")
override fun onAttachedToWindow() {
super.onAttachedToWindow()
post {
val params: ViewGroup.LayoutParams = getLayoutParams()
params.height = AutoSizeUtils.dp2px(context,40f)
layoutParams = params
}
//添加view控制
CallerHmiViewControlListenerManager.addListener(TAG,this)
// 添加换肤监听
CallerSkinModeListenerManager.addListener(TAG, this)
}
override fun onSkinModeChange(skinMode: Int) {
when (skinMode) {
0 -> setStatusBarDarkOrLight(false)
1 -> setStatusBarDarkOrLight(true)
}
}
override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
CallerHmiViewControlListenerManager.removeListener(TAG)
CallerSkinModeListenerManager.removeListener(TAG)
CallerDevaToolsManager.hideStatusBar()
}
}

View File

@@ -0,0 +1,104 @@
package com.mogo.och.shuttle.passenger.ui;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.FrameLayout;
import androidx.annotation.NonNull;
import com.mogo.commons.mvp.IView;
import com.mogo.commons.mvp.MvpFragment;
import com.mogo.commons.mvp.Presenter;
import com.mogo.eagle.core.function.hmi.ui.widget.RomaPassengerView;
import com.mogo.eagle.core.function.view.MapBizView;
import com.mogo.och.bus.passenger.R;
/**
* Created on 2022/3/31
* <p>
* Bus乘客端基础Fragment
*/
public abstract class BusPassengerBaseFragment<V extends IView, P extends Presenter<V>> extends MvpFragment<V, P> {
private static final String TAG = BusPassengerBaseFragment.class.getSimpleName();
private MapBizView mapBizView;
private FrameLayout flContainer;
private RomaPassengerView romaPView;
@Override
protected int getLayoutId() {
return R.layout.shuttle_p_jl_base_fragment;
}
@Override
public String getTagName() {
return TAG;
}
@Override
protected void initViews() {
mapBizView = findViewById(R.id.mapBizView);
showRouteFragment();
// mCurrentArriveStation.setOnLongClickListener(new View.OnLongClickListener() {
// @Override
// public boolean onLongClick(View v) {
// showOverviewFragment();
// return false;
// }
// });
}
@Override
protected void initViews(Bundle savedInstanceState) {
super.initViews(savedInstanceState);
mapBizView.onCreate(savedInstanceState);
}
@Override
public void onResume() {
super.onResume();
mapBizView.onResume();
}
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
mapBizView.onSaveInstanceState(outState);
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapBizView.onLowMemory();
}
@Override
public void onPause() {
super.onPause();
mapBizView.onPause();
}
@Override
public void onDestroyView() {
mapBizView.onDestroy();
super.onDestroyView();
}
/**
* 获取站点面板view在{@link #initViews()}时候添加到container中
*
* @return 站点面板view
*/
public abstract int getStationPanelViewId();
/**
* 显示线路信息
*/
public void showRouteFragment() {
flContainer = findViewById(R.id.bus_p_route_panel);
LayoutInflater.from(getContext()).inflate(getStationPanelViewId(), flContainer);
}
}

View File

@@ -0,0 +1,359 @@
package com.mogo.och.shuttle.passenger.ui;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.Group;
import androidx.recyclerview.widget.RecyclerView;
import com.amap.api.maps.model.LatLng;
import com.elegant.utils.UiThreadHandler;
import com.mogo.eagle.core.data.map.MogoLocation;
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener;
import com.mogo.eagle.core.utilcode.mogo.storage.SharedPrefsMgr;
import com.mogo.och.bus.passenger.R;
import com.mogo.och.shuttle.passenger.adapter.BusPassengerLineStationsAdapter;
import com.mogo.och.bus.passenger.constant.BusPassengerConst;
import com.mogo.och.shuttle.passenger.presenter.BaseBusPassengerPresenter;
import com.mogo.och.shuttle.passenger.ui.layoutmanager.CenterLayoutManager;
import com.mogo.och.shuttle.passenger.ui.mapdirectionview.BusPassengerMapDirectionView;
import com.mogo.och.common.module.utils.NumberFormatUtil;
import com.mogo.och.common.module.wigets.MarqueeTextView;
import com.mogo.och.common.module.wigets.OCHGradientTextView;
import com.mogo.och.data.bean.BusStationBean;
import java.util.ArrayList;
import java.util.List;
/**
* @author: wangmingjun
* @date: 2022/4/12
*/
public class BusPassengerRouteFragment extends
BusPassengerBaseFragment<BusPassengerRouteFragment, BaseBusPassengerPresenter> {
public static final String TAG = "BusPassengerRouteFragment";
private final List<BusStationBean> mStationsList = new ArrayList<>();
private OCHGradientTextView mSpeedTv;
private ConstraintLayout mNoLineInfoView;
private MarqueeTextView mLineName;
private Group mRouteInfoView;
private RecyclerView mStationsListRv;
private BusPassengerMapDirectionView mMapDirectionView;
private BusPassengerLineStationsAdapter mAdapter;
private TextView emptyTv;
private AppCompatImageView mAutopilotIv;
private AppCompatTextView mCurrentArriveStation;
private AppCompatTextView mCurrentArriveStationTitle;
private AppCompatTextView mCurrentArriveTip;
private AppCompatImageView mSpeakArrivedIv;
/**
* 改变自动驾驶状态
*
* @param status 2 - running 1 - enable 2 - disable
*/
private int mPrevAPStatus = -1;
@Override
public int getStationPanelViewId() {
return R.layout.shuttle_p_jl_route_fragment;
}
@NonNull
@Override
protected BaseBusPassengerPresenter createPresenter() {
return new BaseBusPassengerPresenter(this);
}
@Override
protected void initViews() {
super.initViews();
mSpeedTv = findViewById(R.id.bus_p_speed_tv);
mSpeedTv.setVertrial(true);
mSpeedTv.setmColorList(new int[]{getResources().getColor(R.color.bus_p_speed_color_start),
getResources().getColor(R.color.bus_p_speed_color_end)});
mNoLineInfoView =findViewById(R.id.bus_p_no_order_data_view);
emptyTv = findViewById(R.id.no_order_data_tv);
// mCarPlateNum = findViewById(R.id.bus_p_driver_num_plate_tv);
mLineName = findViewById(R.id.bus_p_line_name_tv);
mAutopilotIv = findViewById(R.id.auto_status_iv);
mCurrentArriveStation = findViewById(R.id.bus_p_cur_station_name);
mCurrentArriveStationTitle = findViewById(R.id.bus_p_cur_station_title);
mCurrentArriveTip = findViewById(R.id.bus_p_cur_station_tip);
mSpeakArrivedIv = findViewById(R.id.speak_arrived_iv);
// mOperationTime = findViewById(R.id.line_operation_time_tv);
mRouteInfoView = findViewById(R.id.bus_p_line_cl);
mStationsListRv = findViewById(R.id.bus_p_line_stations_rl);
CenterLayoutManager manager = new CenterLayoutManager(getContext());
mStationsListRv.setLayoutManager(manager);
mAdapter = new BusPassengerLineStationsAdapter(getContext(), mStationsList);
mStationsListRv.setAdapter(mAdapter);
// mMapArrowIcon = findViewById(R.id.bus_p_arrow_nor);
}
@Override
protected void initViews(Bundle savedInstanceState) {
super.initViews(savedInstanceState);
mMapDirectionView = findViewById(R.id.bus_p_line_map_view);
mMapDirectionView.onCreateView(savedInstanceState);
}
@Override
public void onResume() {
super.onResume();
if (mMapDirectionView != null) {
mMapDirectionView.onResume();
}
}
@Override
public void onPause() {
super.onPause();
if (mMapDirectionView != null) {
mMapDirectionView.onPause();
}
}
@Override
public void onDestroy() {
super.onDestroy();
if (mMapDirectionView != null) {
mMapDirectionView.onDestroy();
}
}
public void clearMapView() {
if (mMapDirectionView != null) {
UiThreadHandler.post(new Runnable() {
@Override
public void run() {
// mMapDirectionView.clearPolyline();
// mMapDirectionView.clearCoordinatesLatLng();
}
});
}
}
public void clearMapMarkers() {
if (mMapDirectionView != null) {
UiThreadHandler.post(new Runnable() {
@Override
public void run() {
mMapDirectionView.clearLineMarkers();
}
});
}
}
public void changeOperationStatus(boolean status) {
if (!status) {
emptyTv.setText(getString(R.string.bus_p_no_out));
mNoLineInfoView.setVisibility(View.VISIBLE);
mRouteInfoView.setVisibility(View.GONE);
mLineName.setText(getContext().getString(R.string.bus_p_no_line));
updateArrivedStation(null,0,true);
clearMapView();
clearMapMarkers();
}
}
public void showNoTaskView(){
if (mNoLineInfoView.getVisibility() == View.GONE){
mNoLineInfoView.setVisibility(View.VISIBLE);
mRouteInfoView.setVisibility(View.GONE);
mLineName.setText(getContext().getString(R.string.bus_p_no_line));
updateArrivedStation(null,0,true);
clearMapView();
clearMapMarkers();
}
emptyTv.setText(getString(R.string.bus_p_no_task));
}
public void hideNoTaskView(){
if (mNoLineInfoView.getVisibility() == View.VISIBLE){
mNoLineInfoView.setVisibility(View.GONE);
mRouteInfoView.setVisibility(View.VISIBLE);
}
}
public void updateLineInfo(String lineName) {
mLineName.setText(lineName);
}
/**
*
* @param stations
* @param currentStationIndex
* @param isArrived 是否到站并离开true 到达当前站 currentStationIndex 未离开, false 正在前往此站 currentStationIndex
*/
public void updateStationsInfo(List<BusStationBean> stations, int currentStationIndex, boolean isArrived) {
updateArrivedStation(stations.get(currentStationIndex).getName(),currentStationIndex,isArrived);
mStationsList.clear();
mStationsList.addAll(stations);
mAdapter.notifyDataSetChanged();
if (currentStationIndex > -1){
updateCurrentStation(currentStationIndex);
}
if (currentStationIndex == 0 && isArrived){ //到达始发站且并未出发, 恢复站点marker 清楚路径 清空路径点
SharedPrefsMgr.getInstance(getContext())
.remove(BusPassengerConst.BUS_SP_KEY_ORDER_SUM_DIS);
clearMapView();
}
if (stations.size() > 0){
updateWayPointList(stations,currentStationIndex);
}
}
private void updateWayPointList(List<BusStationBean> stations,int currentStationIndex) {
List<LatLng> mLineStationsList = new ArrayList<>();
for (int i = 0; i< stations.size(); i++) {//站点集合
LatLng latLng = new LatLng(stations.get(i).getGcjLat(),stations.get(i).getGcjLon());// lat,lon
mLineStationsList.add(latLng);
}
if (mMapDirectionView != null) {
UiThreadHandler.post(new Runnable() {
@Override
public void run() {
mMapDirectionView.setLinePointMarkerAndDraw(mLineStationsList,currentStationIndex);
}
});
}
}
// @Override
// public void onCameraChange(float bearing) {
//// startIvCompass(bearing);
// }
// /**
// * 设置指南针旋转
// *
// * @param bearing
// */
// private void startIvCompass(float bearing) {
// bearing = 360 - bearing;
// CallerLogger.d(M_BUS_P + TAG, "startIvCompass: " + bearing);
// rotateAnimation = new RotateAnimation(lastBearing, bearing, Animation.RELATIVE_TO_SELF
// , 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
// rotateAnimation.setFillAfter(true);
//
// mMapArrowIcon.startAnimation(rotateAnimation);
// lastBearing = bearing;
// }
public void onCarLocationChanged(MogoLocation location) {
updateSpeedView((float) location.getGnssSpeed());
}
public void updateSpeedView(float speed){
int speedKM = (int) (Math.abs(speed) * 3.6F);
mSpeedTv.setText(String.valueOf(speedKM));
}
public void updateCurrentStation(int position) {
if (mStationsListRv != null){
mStationsListRv.smoothScrollToPosition(position);
}
}
public void updateArrivedStation(String station,int currentIndex,boolean isArrived){
if (null == station){
mCurrentArriveStation.setText("----");
mCurrentArriveStationTitle.setText(getResources().getString(R.string.bus_p_cur_station_title));
mCurrentArriveTip.setText(getResources().getString(R.string.bus_p_cur_station_arrived_tip));
mCurrentArriveTip.setBackgroundResource(R.drawable.shuttle_p_jl_cur_station_arrived_bg);
handleArrivingSpeakIconDrawable();
}else {
mCurrentArriveStation.setText(station);
if (currentIndex == 0){
mCurrentArriveStationTitle.setText(getResources().getString(R.string.bus_p_cur_station_title));
mCurrentArriveTip.setText(getResources().getString(R.string.bus_p_cur_station_arrived_tip));
mCurrentArriveTip.setBackgroundResource(R.drawable.shuttle_p_jl_cur_station_arrived_bg);
handleArrivingSpeakIconDrawable();
return;
}
if (isArrived){
mCurrentArriveStationTitle.setText(getResources().getString(R.string.bus_p_cur_station_title));
mCurrentArriveTip.setText(getResources().getString(R.string.bus_p_cur_station_arrived_tip));
mCurrentArriveTip.setBackgroundResource(R.drawable.shuttle_p_jl_cur_station_arrived_bg);
handleArrivedSpeakIconDrawable();
}else {
mCurrentArriveStationTitle.setText(getResources().getString(R.string.bus_p_cur_next_station_title));
mCurrentArriveTip.setBackgroundResource(R.drawable.shuttle_p_jl_cur_station_un_arrived_bg);
handleArrivingSpeakIconDrawable();
}
}
}
private void handleArrivedSpeakIconDrawable(){
AnimationDrawable animationDrawable = (AnimationDrawable) mSpeakArrivedIv.getDrawable();
animationDrawable.start();
mSpeakArrivedIv.setVisibility(View.VISIBLE);
}
private void handleArrivingSpeakIconDrawable(){
AnimationDrawable animationDrawable = (AnimationDrawable) mSpeakArrivedIv.getDrawable();
animationDrawable.stop();
mSpeakArrivedIv.setVisibility(View.GONE);
}
public void updateRoutePlanningToNextStation(long meters, long timeInSecond){
//更新进度条
String dis = "0";
String disUnit = "公里";
if (meters > 0){
if (meters / 1000 < 1){
disUnit = "";
dis = String.valueOf(Math.round(meters));
}else {
disUnit = "公里";
dis = NumberFormatUtil.formatLong((double)meters / 1000);
}
}
// String strHtml2 = "<font color=\"#2D3E5F\">距离 </font>" + "<b><font color=\"#0043FF\">" + dis + "</font></b>" + "<font color=\"#2D3E5F\"> "+disUnit+"</font>"
// + "<font color=\"#2D3E5F\"> &nbsp 剩余 </font>" + "<b><font color=\"#0043FF\">" + (int)Math.ceil((double)timeInSecond/ 60f) + "</font></b>" + "<font color=\"#2D3E5F\"> 分钟</font>";
String str = dis+disUnit+" | "+(int)Math.ceil((double)timeInSecond/ 60f)+"分钟";
mCurrentArriveTip.setText(Html.fromHtml(str));
}
public void onAutopilotStatusChanged(int status) {
getActivity().runOnUiThread(() -> {
// 3. 其他过程直接更新
if (mPrevAPStatus != status){
AutopilotStatusChanged(status);
}
mPrevAPStatus = status;
});
}
public void AutopilotStatusChanged(int status) {
if (IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING == status) {
mAutopilotIv.setImageResource(R.drawable.shuttle_p_jl_auto_open);
} else {
mAutopilotIv.setImageResource(R.drawable.shuttle_p_jl_auto_close);
}
}
}

View File

@@ -0,0 +1,181 @@
package com.mogo.och.shuttle.passenger.ui
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.LinearLayout
import com.mogo.eagle.core.data.enums.DataSourceType
import com.mogo.eagle.core.data.enums.TrafficLightEnum
import com.mogo.eagle.core.function.api.datacenter.union.IMoGoTrafficLightListener
import com.mogo.eagle.core.function.call.v2x.CallerTrafficLightListenerManager
import com.mogo.eagle.core.utilcode.util.UiThreadHandler
import com.mogo.och.bus.passenger.R
import kotlinx.android.synthetic.main.shuttle_p_jl_traffic_light_view.view.bus_p_traffic_light_bg
import kotlinx.android.synthetic.main.shuttle_p_jl_traffic_light_view.view.bus_p_traffic_light_iv
import kotlinx.android.synthetic.main.shuttle_p_jl_traffic_light_view.view.bus_p_traffic_light_time_tv
/**
* bus乘客端红绿灯view
*
* Created on 2022/3/14
*/
class BusPassengerTrafficLightView @JvmOverloads constructor(
context: Context?,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : LinearLayout(context, attrs, defStyleAttr), IMoGoTrafficLightListener {
companion object {
private const val TAG = "BusPassengerTrafficLightView"
}
private var mCurrentLightId = TrafficLightEnum.BLACK
init {
init(context)
}
private fun init(context: Context?) {
LayoutInflater.from(context).inflate(R.layout.shuttle_p_jl_traffic_light_view, this, true)
}
override fun onAttachedToWindow() {
super.onAttachedToWindow()
CallerTrafficLightListenerManager.addListener(TAG, this)
}
override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
CallerTrafficLightListenerManager.removeListener(TAG)
}
/**
* 展示红绿灯预警
*
* @param checkLightId 0-都是默认1-红2-黄3-绿
* @param lightSource 1:云端下发2:自车感知
*/
override fun showTrafficLight(checkLightId: TrafficLightEnum, lightSource: DataSourceType) {
super.showTrafficLight(checkLightId, lightSource)
mCurrentLightId = checkLightId
updateTrafficLightIcon(checkLightId)
}
/**
* 关闭红绿灯预警展示,并重制灯态
*/
override fun disableTrafficLight() {
super.disableTrafficLight()
UiThreadHandler.post {
mCurrentLightId = TrafficLightEnum.BLACK
this@BusPassengerTrafficLightView.visibility = GONE
}
}
/**
* @param redNum 红灯倒计时
* @param yellowNum 黄灯倒计时
* @param greenNum 绿灯倒计时
*/
override fun changeCountdownTrafficLightNum(redNum: Int, yellowNum: Int, greenNum: Int) {
super.changeCountdownTrafficLightNum(redNum, yellowNum, greenNum)
resetView()
when (mCurrentLightId) {
TrafficLightEnum.RED -> changeCountdownRed(redNum)
TrafficLightEnum.YELLOW -> changeCountdownYellow(yellowNum)
TrafficLightEnum.GREEN -> changeCountdownGreen(greenNum)
else -> UiThreadHandler.post { bus_p_traffic_light_time_tv.text = "" }
}
}
override fun changeCountdownRed(redNum: Int) {
super.changeCountdownRed(redNum)
UiThreadHandler.post {
if (redNum > 0) {
resetView()
bus_p_traffic_light_time_tv.text = redNum.toString()
} else {
disableTrafficLightCountDown()
bus_p_traffic_light_time_tv.text = ""
}
}
}
override fun changeCountdownGreen(greenNum: Int) {
super.changeCountdownGreen(greenNum)
UiThreadHandler.post {
if (greenNum > 0) {
resetView()
bus_p_traffic_light_time_tv.text = greenNum.toString()
} else {
disableTrafficLightCountDown()
bus_p_traffic_light_time_tv.text = ""
}
}
}
override fun changeCountdownYellow(yellowNum: Int) {
super.changeCountdownYellow(yellowNum)
UiThreadHandler.post {
if (yellowNum > 0) {
resetView()
bus_p_traffic_light_time_tv.text = yellowNum.toString()
} else {
disableTrafficLightCountDown()
bus_p_traffic_light_time_tv.text = ""
}
}
}
/**
* 更新红绿灯icon
*
* @param lightId 0-都是默认1-红2-黄3-绿
*/
private fun updateTrafficLightIcon(lightId: TrafficLightEnum) {
UiThreadHandler.post {
when (lightId) {
TrafficLightEnum.RED -> {
bus_p_traffic_light_iv.setBackgroundResource(R.drawable.shuttle_p_jl_light_red_nor)
this@BusPassengerTrafficLightView.visibility = VISIBLE
}
TrafficLightEnum.YELLOW -> {
bus_p_traffic_light_iv.setBackgroundResource(R.drawable.shuttle_p_jl_light_yellow_nor)
this@BusPassengerTrafficLightView.visibility = VISIBLE
}
TrafficLightEnum.GREEN -> {
bus_p_traffic_light_iv.setBackgroundResource(R.drawable.shuttle_p_jl_light_green_nor)
this@BusPassengerTrafficLightView.visibility = VISIBLE
}
else -> this@BusPassengerTrafficLightView.visibility = GONE
}
}
}
override fun disableTrafficLightCountDown() {
super.disableTrafficLightCountDown()
UiThreadHandler.post {
val layoutParams = layoutParams
if (layoutParams is MarginLayoutParams) {
val lp = layoutParams
lp.width = resources.getDimension(R.dimen.bus_p_traffic_light_icon_size).toInt()
setLayoutParams(lp)
bus_p_traffic_light_time_tv.visibility = GONE
bus_p_traffic_light_bg.layoutParams.width =
resources.getDimension(R.dimen.dp_90).toInt()
}
}
}
private fun resetView() {
val layoutParams = layoutParams
if (layoutParams is MarginLayoutParams) {
val lp = layoutParams
lp.width = resources.getDimension(R.dimen.bus_p_route_traffic_light_view_width).toInt()
setLayoutParams(lp)
bus_p_traffic_light_time_tv.visibility = VISIBLE
bus_p_traffic_light_bg.layoutParams.width =
resources.getDimension(R.dimen.bus_p_traffic_light_bg_width).toInt()
}
}
}

View File

@@ -0,0 +1,23 @@
package com.mogo.och.shuttle.passenger.ui;
/**
* @author xiaoyuzhou
* @date 2021/6/24 11:33 上午
*/
public interface IBusPassengerMapDirectionView {
/**
* 绘制路径线
*/
void drawablePolyline();
/**
* 清除路径线
*/
void clearPolyline();
/**
* 设置路径中起终点marker
*/
void setLineMarker();
}

View File

@@ -0,0 +1,42 @@
package com.mogo.och.shuttle.passenger.ui.layoutmanager;
import android.content.Context;
import android.util.AttributeSet;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.LinearSmoothScroller;
import androidx.recyclerview.widget.RecyclerView;
public class CenterLayoutManager extends LinearLayoutManager {
public CenterLayoutManager(Context context) {
super(context);
}
public CenterLayoutManager(Context context, int orientation, boolean reverseLayout) {
super(context, orientation, reverseLayout);
}
public CenterLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
RecyclerView.SmoothScroller smoothScroller = new CenterSmoothScroller(recyclerView.getContext());
smoothScroller.setTargetPosition(position);
startSmoothScroll(smoothScroller);
}
private static class CenterSmoothScroller extends LinearSmoothScroller {
CenterSmoothScroller(Context context) {
super(context);
}
@Override
public int calculateDtToFit(int viewStart, int viewEnd, int boxStart, int boxEnd, int snapPreference) {
return (boxStart + (boxEnd - boxStart) / 2) - (viewStart + (viewEnd - viewStart) / 2);
}
}
}

View File

@@ -0,0 +1,350 @@
package com.mogo.och.shuttle.passenger.ui.mapdirectionview
import android.content.Context
import android.os.Bundle
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.RelativeLayout
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.findViewTreeViewModelStoreOwner
import com.amap.api.maps.AMap
import com.amap.api.maps.CameraUpdateFactory
import com.amap.api.maps.TextureMapView
import com.amap.api.maps.model.BitmapDescriptor
import com.amap.api.maps.model.BitmapDescriptorFactory
import com.amap.api.maps.model.CameraPosition
import com.amap.api.maps.model.CustomMapStyleOptions
import com.amap.api.maps.model.LatLng
import com.amap.api.maps.model.LatLngBounds
import com.amap.api.maps.model.Marker
import com.amap.api.maps.model.MarkerOptions
import com.amap.api.maps.model.Polyline
import com.amap.api.maps.model.PolylineOptions
import com.mogo.eagle.core.data.map.MogoLocation
import com.mogo.eagle.core.function.api.autopilot.IMoGoChassisLocationGCJ02Listener
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationGCJ02ListenerManager
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.d
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant
import com.mogo.eagle.core.utilcode.util.UiThreadHandler
import com.mogo.och.bus.passenger.R
import com.mogo.och.shuttle.passenger.ui.IBusPassengerMapDirectionView
import com.mogo.och.bus.passenger.utils.BusPassengerMapAssetStyleUtil
/**
* 乘客屏小地图
*/
class BusPassengerMapDirectionView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : RelativeLayout(context, attrs, defStyleAttr), IMoGoChassisLocationGCJ02Listener,
IBusPassengerMapDirectionView, AMap.OnCameraChangeListener,
MapDirectionViewModel.ItineraryViewCallback {
companion object {
//小地图名称
const val TAG = "BusPassengerMapDirectionView"
}
private lateinit var mAMapNaviView: TextureMapView
private lateinit var mAMap: AMap
private var mPolyline: Polyline? = null
private val mLineMarkers: MutableList<Marker> = ArrayList()
private lateinit var mCarMarker: Marker
private val mLineStationLatLng: MutableList<LatLng> = ArrayList() //站点坐标数据
var textureList: MutableList<BitmapDescriptor?> = ArrayList()
var texIndexList: MutableList<Int> = ArrayList()
private var mArrivedRes: BitmapDescriptor? = null
private var mUnArrivedRes: BitmapDescriptor? = null
private val routeArrived: MutableList<LatLng> = ArrayList()
private val routeArriving: MutableList<LatLng> = ArrayList()
private var location: MogoLocation? = null
init {
try {
initView(context)
} catch (e: Exception) {
e.printStackTrace()
}
}
private fun initView(context: Context) {
d(SceneConstant.M_BUS_P + TAG, "initView")
val smpView = LayoutInflater.from(context).inflate(R.layout.shuttle_p_jl_map_view, this)
mAMapNaviView = smpView.findViewById<View>(R.id.bus_p_line_amap_view) as TextureMapView
initAMapView()
// 注册定位监听
CallerChassisLocationGCJ02ListenerManager.addListener(TAG, 10, this)
}
override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
// 注册定位监听
CallerChassisLocationGCJ02ListenerManager.removeListener(TAG)
}
private fun initAMapView() {
mAMap = mAMapNaviView.map
// 设置导航地图模式aMap是地图控制器对象。
mAMap.mapType = AMap.MAP_TYPE_NIGHT
// 关闭显示实时路况图层aMap是地图控制器对象。
mAMap.isTrafficEnabled = false
// 设置 锚点 图标
mCarMarker = mAMap.addMarker(
MarkerOptions().icon(BitmapDescriptorFactory.fromResource(R.drawable.shuttle_p_jl_map_car))
.anchor(0.5f, 0.5f)
)
mArrivedRes = BitmapDescriptorFactory.fromResource(R.drawable.shuttle_p_jl_map_arrow_arrived)
mUnArrivedRes = BitmapDescriptorFactory.fromResource(R.drawable.shuttle_p_jl_map_arrow_un_arrive)
// 加载自定义样式
val customMapStyleOptions = CustomMapStyleOptions()
.setEnable(true)
.setStyleData(
BusPassengerMapAssetStyleUtil.getAssetsStyle(
context, "map_style.data"
)
)
.setStyleExtraData(
BusPassengerMapAssetStyleUtil.getAssetsExtraStyle(
context, "map_style_extra.data"
)
)
// 设置自定义样式
mAMap.setCustomMapStyle(customMapStyleOptions)
// 设置地图的样式
mAMap.uiSettings.apply {
isZoomControlsEnabled = false // 地图缩放级别的交换按钮
setAllGesturesEnabled(true) // 所有手势
isMyLocationButtonEnabled = false // 显示默认的定位按钮
setLogoBottomMargin(-150) //设置Logo下边界距离屏幕底部的边距,设置为负值即可
}
mAMap.setOnMapLoadedListener {
d(SceneConstant.M_BUS_P + TAG, "smp---onMapLoaded")
// 加载自定义样式
val options = CustomMapStyleOptions()
.setEnable(true)
.setStyleData(
BusPassengerMapAssetStyleUtil.getAssetsStyle(
context, "map_style.data"
)
)
.setStyleExtraData(
BusPassengerMapAssetStyleUtil.getAssetsExtraStyle(
context, "map_style_extra.data"
)
)
// 设置自定义样式
mAMap.setCustomMapStyle(options)
mAMapNaviView.map.setPointToCenter(
mAMapNaviView.width / 2,
mAMapNaviView.height / 2
)
}
//设置地图状态的监听接口
mAMap.setOnCameraChangeListener(this)
}
override fun onAttachedToWindow() {
super.onAttachedToWindow()
val viewModel = findViewTreeViewModelStoreOwner()?.let {
ViewModelProvider(it).get(MapDirectionViewModel::class.java)
}
viewModel?.setDistanceCallback(this)
}
fun clearMapView() {
UiThreadHandler.post( {
clearPolyline()
clearCoordinatesLatLng()
}, UiThreadHandler.MODE.QUEUE)
}
override fun onChassisLocationGCJ02(mogoLocation: MogoLocation?) {
if (mogoLocation == null) {
return
}
val currentLatLng = LatLng(mogoLocation.latitude, mogoLocation.longitude)
//更新车辆位置
mCarMarker.rotateAngle = (360 - mogoLocation.heading).toFloat()
mCarMarker.position = currentLatLng
mCarMarker.setToTop()
try {
//圈定地图显示范围
val boundsBuilder = LatLngBounds.Builder()
routeArrived.forEach {
boundsBuilder.include(it)
}
routeArriving.forEach {
boundsBuilder.include(it)
}
mLineStationLatLng.forEach {
boundsBuilder.include(it)
}
boundsBuilder.include(currentLatLng)
mAMap.moveCamera(
CameraUpdateFactory.newLatLngBoundsRect(
boundsBuilder.build(),
100,
100,
100,
100
)
)
} catch (e: Exception) {
e.printStackTrace()
}
}
override fun drawablePolyline() {
if (routeArrived.isEmpty() && routeArriving.isEmpty()) {
d(SceneConstant.M_TAXI + TAG, "没有点")
return
}
texIndexList.clear()
val allPoints = ArrayList(routeArrived)
for (i in routeArrived.indices) {
if (routeArrived.size > 1 && i < routeArrived.size - 1) {
texIndexList.add(0)
}
}
texIndexList.add(0)
location?.let {
allPoints.add(LatLng(it.latitude, it.longitude))
}
allPoints.addAll(routeArriving)
for (ignored in routeArrived) {
texIndexList.add(1)
}
mPolyline?.let {
it.points = allPoints
it.options.customTextureIndex = texIndexList
return
}
if (textureList.isEmpty()) {
textureList.add(mArrivedRes)
textureList.add(mUnArrivedRes)
}
//设置线段纹理
val polylineOptions = PolylineOptions().apply {
addAll(allPoints)
isUseTexture = true
width(15f)
lineCapType(PolylineOptions.LineCapType.LineCapRound)
customTextureList = textureList
customTextureIndex = texIndexList
}
// 绘制线
mPolyline = mAMap.addPolyline(polylineOptions)
}
override fun clearPolyline() {
mPolyline?.remove()
mPolyline = null
}
override fun setLineMarker() {}
fun clearCoordinatesLatLng() {
textureList.clear()
texIndexList.clear()
routeArrived.clear()
routeArriving.clear()
mLineStationLatLng.clear()
d(SceneConstant.M_BUS_P + TAG, " mCoordinatesLatLng.clear ")
}
fun onCreateView(savedInstanceState: Bundle?) {
mAMapNaviView.onCreate(savedInstanceState)
}
fun onResume() {
mAMapNaviView.onResume()
}
fun onPause() {
mAMapNaviView.onPause()
}
fun onDestroy() {
mAMapNaviView.onDestroy()
}
override fun setCoordinatesLatLng(
routeArrived: List<LatLng>,
routeArriving: List<LatLng>,
location: MogoLocation?
) {
this.routeArrived.clear()
this.routeArrived.addAll(routeArrived)
this.routeArriving.clear()
this.routeArriving.addAll(routeArriving)
this.location = location
UiThreadHandler.post({
drawablePolyline()
}, UiThreadHandler.MODE.QUEUE)
}
fun clearLineMarkers() {
for (i in mLineMarkers.indices) {
mLineMarkers[i].isVisible = false
mLineMarkers[i].remove()
}
mLineMarkers.clear()
}
fun setLinePointMarkerAndDraw(mLineStationsList: List<LatLng>, currentIndex: Int) {
clearLineMarkers()
mLineStationLatLng.clear()
mLineStationLatLng.addAll(mLineStationsList)
if (mLineStationsList.isNotEmpty()) {
// 起点marker, 终点marker, 过站marker, 未过站marker
val size = mLineStationsList.size
val mStartMarker = mAMap.addMarker(
MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.shuttle_p_jl_map_start_point))
)
val mEndMarker = mAMap.addMarker(
MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.shuttle_p_jl_map_end_point))
)
mStartMarker.position = mLineStationsList[0]
mLineMarkers.add(0, mStartMarker)
for (i in mLineStationsList.indices) {
if (currentIndex <= i && i < size - 1 && i > 0) { //未到达
val unArrivedMarker = mAMap.addMarker(
MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.shuttle_p_jl_map_unarrived_point))
)
unArrivedMarker.position = mLineStationsList[i]
mLineMarkers.add(i, unArrivedMarker)
} else if (i in 1 until currentIndex) {
val arrivedMarker = mAMap.addMarker(
MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.shuttle_p_jl_map_arrived_point))
)
arrivedMarker.position = mLineStationsList[i]
mLineMarkers.add(i, arrivedMarker)
}
}
mEndMarker.position = mLineStationsList[size - 1]
mLineMarkers.add(size - 1, mEndMarker)
}
}
override fun onCameraChange(cameraPosition: CameraPosition) {
}
override fun onCameraChangeFinish(cameraPosition: CameraPosition) {}
}

View File

@@ -0,0 +1,60 @@
package com.mogo.och.shuttle.passenger.ui.mapdirectionview
import androidx.lifecycle.ViewModel
import com.amap.api.maps.model.LatLng
import com.mogo.eagle.core.data.map.MogoLocation
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
import com.mogo.och.common.module.manager.distancemamager.ITrajectoryListener
import com.mogo.och.common.module.manager.distancemamager.TrajectoryAndDistanceManager
class MapDirectionViewModel: ViewModel(), ITrajectoryListener {
private val TAG = MapDirectionViewModel::class.java.simpleName
private var viewCallback: ItineraryViewCallback?=null
init {
TrajectoryAndDistanceManager.addTrajectoryListener(TAG,this)
}
fun setDistanceCallback(viewCallback: ItineraryViewCallback){
this.viewCallback = viewCallback
}
override fun onCleared() {
super.onCleared()
this.viewCallback = null
TrajectoryAndDistanceManager.removeListener(TAG)
}
interface ItineraryViewCallback{
fun setCoordinatesLatLng(routeArrived: List<LatLng>, routeArriving: List<LatLng>, location: MogoLocation?)
}
override fun trajectoryCallback(
routeArrivied: MutableList<MogoLocation>,
routeArriving: MutableList<MogoLocation>,
location: MogoLocation
) {
val routeArrivedTemp: MutableList<LatLng> = ArrayList()
val routeArrivingTemp: MutableList<LatLng> = ArrayList()
var temp: LatLng
for (mogoLocation in routeArrivied) {
temp = LatLng(mogoLocation.latitude, mogoLocation.longitude)
routeArrivedTemp.add(temp)
}
for (mogoLocation in routeArriving) {
temp = LatLng(mogoLocation.latitude, mogoLocation.longitude)
routeArrivingTemp.add(temp)
}
this.viewCallback?.setCoordinatesLatLng(
routeArrivedTemp,
routeArrivingTemp,
location
)
CallerLogger.d(TAG,"已经走过的点routeArrivied:${routeArrivied.size} 未走过的点routeArriving${routeArriving.size}")
}
}

View File

@@ -0,0 +1,16 @@
package com.mogo.och.shuttle.passenger.ui.widget
import android.content.Context
import android.util.AttributeSet
import com.mogo.eagle.core.function.hmi.ui.vehicle.TurnLightViewStatus
/**
* @author: wangmingjun
* @date: 2023/2/13
*/
class BusPTurnLightView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null
) : TurnLightViewStatus(context, attrs) {
}