[driver passenger ] bus 乘客屏剩余里程和时间计算
This commit is contained in:
@@ -12,4 +12,5 @@ import mogo.telematics.pad.MessagePad;
|
||||
*/
|
||||
public interface IBusPassengerAutopilotPlanningCallback {
|
||||
void routeResult(List<LatLng> models);
|
||||
void routePlanningToNextStationChanged(long meters, long timeInSecond);
|
||||
}
|
||||
|
||||
@@ -10,5 +10,5 @@ import java.util.List;
|
||||
*/
|
||||
public interface IBusPassengerRouteLineInfoCallback {
|
||||
void updateLineInfo(String lineName, String lineDurTime);
|
||||
void updateStationsInfo(List<BusPassengerStation> stations,int currentStationIndex);
|
||||
void updateStationsInfo(List<BusPassengerStation> stations,int currentStationIndex,boolean isArrived);
|
||||
}
|
||||
|
||||
@@ -37,5 +37,8 @@ class BusPassengerConst {
|
||||
const val STATION_STATUS_STOPPED = 2
|
||||
// 未到站(未到站)
|
||||
const val STATION_STATUS_ARRIVING = 3
|
||||
|
||||
//bus平均速度
|
||||
const val BUS_AVERAGE_SPEED = 25
|
||||
}
|
||||
}
|
||||
@@ -8,8 +8,10 @@ import android.net.ConnectivityManager;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.amap.api.maps.model.LatLng;
|
||||
import com.mogo.aicloud.services.socket.IMogoLifecycleListener;
|
||||
import com.mogo.aicloud.services.socket.MogoAiCloudSocketManager;
|
||||
import com.mogo.cloud.commons.utils.CoordinateUtils;
|
||||
import com.mogo.commons.debug.DebugConfig;
|
||||
import com.mogo.eagle.core.data.autopilot.AutopilotStatusInfo;
|
||||
import com.mogo.eagle.core.data.config.FunctionBuildConfig;
|
||||
@@ -32,6 +34,7 @@ import com.mogo.och.bus.passenger.callback.IBusPassengerADASStatusCallback;
|
||||
import com.mogo.och.bus.passenger.callback.IBusPassengerAutopilotPlanningCallback;
|
||||
import com.mogo.och.bus.passenger.callback.IBusPassengerControllerStatusCallback;
|
||||
import com.mogo.och.bus.passenger.callback.IBusPassengerRouteLineInfoCallback;
|
||||
import com.mogo.och.bus.passenger.constant.BusPassengerConst;
|
||||
import com.mogo.och.bus.passenger.network.BusPassengerModelLoopManager;
|
||||
import com.mogo.och.bus.passenger.network.BusPassengerServiceCallback;
|
||||
import com.mogo.och.bus.passenger.network.BusPassengerServiceManager;
|
||||
@@ -59,6 +62,8 @@ import static com.mogo.och.bus.passenger.constant.BusPassengerConst.STATION_STAT
|
||||
public class BusPassengerModel {
|
||||
private static final String TAG = BusPassengerModel.class.getSimpleName();
|
||||
|
||||
private List<LatLng> mRoutePoints = new ArrayList<>();
|
||||
|
||||
private static final class SingletonHolder {
|
||||
private static final BusPassengerModel INSTANCE = new BusPassengerModel();
|
||||
}
|
||||
@@ -142,10 +147,11 @@ public class BusPassengerModel {
|
||||
for (int i = 0; i< stations.size(); i++){
|
||||
BusPassengerStation station = stations.get(i);
|
||||
if (station.getDrivingStatus() == STATION_STATUS_STOPPED && station.isLeaving() && i+1 < stations.size()){
|
||||
mRouteLineInfoCallback.updateStationsInfo(stations,i+1);
|
||||
startOrStopCalculateRouteInfo(false);
|
||||
mRouteLineInfoCallback.updateStationsInfo(stations,i+1,false);
|
||||
return;
|
||||
}else if (station.getDrivingStatus() == STATION_STATUS_STOPPED && !station.isLeaving()){
|
||||
mRouteLineInfoCallback.updateStationsInfo(stations,i);
|
||||
mRouteLineInfoCallback.updateStationsInfo(stations,i,true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -230,7 +236,7 @@ public class BusPassengerModel {
|
||||
if ( ConnectivityManager.CONNECTIVITY_ACTION.equals( intentStr ) ) {
|
||||
if ( NetworkUtils.isConnected( mContext ) ) {
|
||||
if (AppIdentityModeUtils.isDriver(FunctionBuildConfig.appIdentityMode)) {
|
||||
// TODO: 2022/3/31
|
||||
queryDriverOperationStatus();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -342,11 +348,52 @@ public class BusPassengerModel {
|
||||
}
|
||||
};
|
||||
|
||||
public void updateRoutePoints(List<MessagePad.Location> routePoints) {
|
||||
mAutopilotPlanningCallback.routeResult(
|
||||
BPCoordinateCalculateRouteUtil.coordinateConverterWgsToGcjListCommon(mContext
|
||||
, routePoints));
|
||||
public void dynamicCalculateRouteInfo() {
|
||||
List<LatLng> lastPoints = BPCoordinateCalculateRouteUtil
|
||||
.getRemainPointListByCompare(mRoutePoints,mLongitude,mLatitude);
|
||||
|
||||
float lastSumLength = 0;
|
||||
if (lastPoints.size() == 1){ //只是最后一个点,计算当前位置和最后一个点的距离
|
||||
lastSumLength = CoordinateUtils.calculateLineDistance(
|
||||
lastPoints.get(0).longitude, lastPoints.get(0).latitude,
|
||||
mLongitude, mLatitude);
|
||||
}else {
|
||||
lastSumLength = BPCoordinateCalculateRouteUtil.calculateRouteSumLength(lastPoints);
|
||||
}
|
||||
double lastTime = lastSumLength / BusPassengerConst.BUS_AVERAGE_SPEED * 3.6 ; //秒
|
||||
|
||||
if (mAutopilotPlanningCallback != null){
|
||||
mAutopilotPlanningCallback.routePlanningToNextStationChanged((long)lastSumLength,(long) lastTime);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void updateRoutePoints(List<MessagePad.Location> routePoints) {
|
||||
if (mAutopilotPlanningCallback != null){
|
||||
mAutopilotPlanningCallback.routeResult(
|
||||
BPCoordinateCalculateRouteUtil.coordinateConverterWgsToGcjListCommon(mContext
|
||||
, routePoints));
|
||||
}
|
||||
|
||||
//转换成高德坐标系
|
||||
mRoutePoints.clear();
|
||||
mRoutePoints.addAll(BPCoordinateCalculateRouteUtil.coordinateConverterWgsToGcjListCommon(mContext,routePoints));
|
||||
//开启实时计算剩余距离,剩余时间,预计时间
|
||||
startOrStopCalculateRouteInfo(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始轮询计算剩余里程和时间
|
||||
* @param isStart
|
||||
*/
|
||||
public void startOrStopCalculateRouteInfo(boolean isStart) {
|
||||
CallerLogger.INSTANCE.d(M_BUS_P + TAG, "startOrStopOrderLoop() " + isStart);
|
||||
if (isStart) {
|
||||
BusPassengerModelLoopManager.getInstance().startCalculateRouteInfoLoop();
|
||||
} else {
|
||||
mRoutePoints.clear();
|
||||
BusPassengerModelLoopManager.getInstance().stopCalculateRouteInfLoop();
|
||||
}
|
||||
}
|
||||
|
||||
private void startOrStopOrderLoop(boolean start) {
|
||||
|
||||
@@ -23,6 +23,8 @@ public class BusPassengerModelLoopManager {
|
||||
|
||||
private static final String TAG = BusPassengerModelLoopManager.class.getSimpleName();
|
||||
|
||||
private Disposable mCalculateRouteDisposable; //每隔2s计算一次剩余里程和时间
|
||||
|
||||
private static final class SingletonHolder {
|
||||
private static final BusPassengerModelLoopManager INSTANCE = new BusPassengerModelLoopManager();
|
||||
}
|
||||
@@ -53,4 +55,25 @@ public class BusPassengerModelLoopManager {
|
||||
mHeartbeatDisposable = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void startCalculateRouteInfoLoop() {
|
||||
if (mCalculateRouteDisposable != null && !mCalculateRouteDisposable.isDisposed()) {
|
||||
return;
|
||||
}
|
||||
CallerLogger.INSTANCE.i(M_BUS_P + TAG, "startCalculateRouteInfoLoop()");
|
||||
mCalculateRouteDisposable = Observable.interval(LOOP_DELAY,
|
||||
LOOP_LINE_2S, TimeUnit.MILLISECONDS)
|
||||
.map((aLong -> aLong + 1))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(aLong -> BusPassengerModel.getInstance().dynamicCalculateRouteInfo());
|
||||
}
|
||||
|
||||
public void stopCalculateRouteInfLoop() {
|
||||
if (mCalculateRouteDisposable != null) {
|
||||
CallerLogger.INSTANCE.i(M_BUS_P + TAG, "stopCalculateRouteInfLoop()");
|
||||
mCalculateRouteDisposable.dispose();
|
||||
mCalculateRouteDisposable = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,12 +126,17 @@ public class BaseBusPassengerPresenter extends Presenter<BusPassengerRouteFragme
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStationsInfo(List<BusPassengerStation> stations,int currentStationIndex) {
|
||||
runOnUIThread(() -> mView.updateStationsInfo(stations,currentStationIndex));
|
||||
public void updateStationsInfo(List<BusPassengerStation> stations,int currentStationIndex,boolean isArrived) {
|
||||
runOnUIThread(() -> mView.updateStationsInfo(stations,currentStationIndex, isArrived));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void routeResult(List<LatLng> models) {
|
||||
runOnUIThread(() -> mView.routeResult(models));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void routePlanningToNextStationChanged(long meters, long timeInSecond) {
|
||||
runOnUIThread(() -> mView.updateRoutePlanningToNextStation(meters, timeInSecond));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.mogo.commons.mvp.Presenter;
|
||||
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener;
|
||||
import com.mogo.eagle.core.function.call.map.CallerSmpManager;
|
||||
import com.mogo.och.bus.passenger.R;
|
||||
import com.mogo.och.bus.passenger.utils.BPDateTimeUtil;
|
||||
|
||||
/**
|
||||
* Created on 2022/3/31
|
||||
@@ -28,6 +29,7 @@ public abstract class BusPassengerBaseFragment<V extends IView, P extends Presen
|
||||
private ImageView mAutopilotIv;
|
||||
private FrameLayout flContainer;
|
||||
|
||||
|
||||
/**
|
||||
* 改变自动驾驶状态
|
||||
*
|
||||
@@ -79,22 +81,43 @@ public abstract class BusPassengerBaseFragment<V extends IView, P extends Presen
|
||||
LayoutInflater.from(getContext()).inflate(getStationPanelViewId(), flContainer);
|
||||
}
|
||||
|
||||
public void updateArrivedStation(String station,int currentIndex){
|
||||
public void updateArrivedStation(String station,int currentIndex,boolean isArrived){
|
||||
if (null == station){
|
||||
mCurrentArriveStation.setText("----");
|
||||
}else {
|
||||
mCurrentArriveStation.setText(station);
|
||||
if (currentIndex == 0){
|
||||
mCurrentArriveStationTitle.setText(getResources().getString(R.string.bus_p_cur_station_title_init));
|
||||
mCurrentArriveTip.setText(getResources().getString(R.string.bus_p_cur_station_arrived_tip_init));
|
||||
}else {
|
||||
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));
|
||||
}else {
|
||||
mCurrentArriveStationTitle.setText(getResources().getString(R.string.bus_p_cur_next_station_title));
|
||||
}
|
||||
mCurrentArriveStation.setText(station);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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 = BPDateTimeUtil.formatLong((double)meters / 1000);
|
||||
}
|
||||
}
|
||||
String strHtml2 = "<font color=\"#CAD6FF\">距离 </font>" + "<b><font color=\"#FFFFFF\">" + dis + "</font></b>" + "<font color=\"#CAD6FF\"> "+disUnit+"</font>"
|
||||
+ "<font color=\"#CAD6FF\">"+" "+"剩余 </font>" + "<b><font color=\"#FFFFFF\">" + (int)Math.ceil((double)timeInSecond/ 60f) + "</font></b>" + "<font color=\"#CAD6FF\"> 分钟</font>";
|
||||
mCurrentArriveTip.setText(strHtml2);
|
||||
}
|
||||
|
||||
public void onAutopilotStatusChanged(int status) {
|
||||
getActivity().runOnUiThread(() -> {
|
||||
// 3. 其他过程直接更新
|
||||
|
||||
@@ -385,8 +385,8 @@ public class BusPassengerRouteFragment extends
|
||||
}
|
||||
}
|
||||
|
||||
public void updateStationsInfo(List<BusPassengerStation> stations, int currentStationIndex) {
|
||||
updateArrivedStation(stations.get(currentStationIndex).getName(),currentStationIndex);
|
||||
public void updateStationsInfo(List<BusPassengerStation> stations, int currentStationIndex,boolean isArrived) {
|
||||
updateArrivedStation(stations.get(currentStationIndex).getName(),currentStationIndex,isArrived);
|
||||
mStationsList.clear();
|
||||
mStationsList.addAll(stations);
|
||||
mAdapter.notifyDataSetChanged();
|
||||
|
||||
@@ -5,12 +5,15 @@ import android.content.Context;
|
||||
import com.amap.api.maps.CoordinateConverter;
|
||||
import com.amap.api.maps.model.LatLng;
|
||||
import com.mogo.cloud.commons.utils.CoordinateUtils;
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import mogo.telematics.pad.MessagePad;
|
||||
|
||||
import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_BUS_P;
|
||||
|
||||
/**
|
||||
* @author: wangmingjun
|
||||
* @date: 2022/3/28
|
||||
@@ -52,4 +55,41 @@ public class BPCoordinateCalculateRouteUtil {
|
||||
LatLng latLng = mCoordinateConverter.convert();
|
||||
return latLng;
|
||||
}
|
||||
|
||||
/**
|
||||
* 简单粗暴 直接比较 todo 需要优化
|
||||
* @param mRoutePoints
|
||||
* @param realLon
|
||||
* @param realLat
|
||||
* @return
|
||||
*/
|
||||
public static List<LatLng> getRemainPointListByCompare(List<LatLng> mRoutePoints,double realLon,double realLat) {
|
||||
List<LatLng> latePoints = new ArrayList<>();
|
||||
int currentIndex = 0; //记录疑似点
|
||||
if (mRoutePoints.size() > 0){
|
||||
//基础点
|
||||
LatLng baseLatLng = mRoutePoints.get(0);
|
||||
float baseDiffDis = CoordinateUtils.calculateLineDistance(realLon,realLat
|
||||
,baseLatLng.longitude,baseLatLng.latitude);// lon,lat, prelon, prelat
|
||||
|
||||
for (int i= 1; i < mRoutePoints.size(); i++){
|
||||
LatLng latLng = mRoutePoints.get(i);
|
||||
float diff = CoordinateUtils.calculateLineDistance(realLon,realLat
|
||||
,latLng.longitude,latLng.latitude);
|
||||
if (baseDiffDis > diff){
|
||||
// Logger.d(M_TAXI + "calculateRouteSumLength", "点:"+i+"-------先记录点----- ");
|
||||
baseDiffDis = diff;
|
||||
currentIndex = i;
|
||||
}
|
||||
}
|
||||
Logger.d(M_BUS_P + "calculateRouteSumLength", "点:"+currentIndex+"-------是最近的点------ ");
|
||||
if (currentIndex == mRoutePoints.size()-1){
|
||||
latePoints.add(mRoutePoints.get(currentIndex));
|
||||
}else {
|
||||
latePoints.addAll(mRoutePoints.subList(currentIndex,mRoutePoints.size()-1));
|
||||
}
|
||||
return latePoints;
|
||||
}
|
||||
return latePoints;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
package com.mogo.och.bus.passenger.utils;
|
||||
|
||||
import com.mogo.eagle.core.utilcode.util.DateTimeUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
|
||||
/**
|
||||
* @author: wangmingjun
|
||||
* @date: 2021/8/20
|
||||
*/
|
||||
public class BPDateTimeUtil {
|
||||
|
||||
public static final String TAXI_HH_mm = "HH:mm";
|
||||
public static final String TAXI_MM_dd = "MM-dd";
|
||||
public static final String TAXI_MM_dd_HH_mm = "MM-dd HH:mm";
|
||||
public static final String TAXI_yyyy_MM_dd = "yyyy-MM-dd";
|
||||
public static final String TAXI_yyyy_MM_dd_HH_mm = "yyyy-MM-dd HH:mm";
|
||||
|
||||
public static String formatCalendarToString(Calendar calendar, String format){
|
||||
if (calendar == null) return "";
|
||||
try {
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
|
||||
return dateFormat.format(calendar.getTime());
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static boolean compareDateIsCurrentDay(Calendar targetCalendar){
|
||||
Calendar currentCale = DateTimeUtils.getCurrentDateTime();
|
||||
String currentDay = formatCalendarToString(currentCale, TAXI_yyyy_MM_dd);
|
||||
if (currentDay.equals(formatCalendarToString(targetCalendar, TAXI_yyyy_MM_dd))){
|
||||
return true;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static Calendar formatLongToCalendar(long time){
|
||||
Calendar calendar = null;
|
||||
try {
|
||||
calendar = Calendar.getInstance();
|
||||
calendar.setTimeInMillis(time);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return calendar;
|
||||
}
|
||||
public static String formatLongToString(long time, String format){
|
||||
try {
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
|
||||
return dateFormat.format(time);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
public static String getYMDTime(long time){//格式为 2021.8.21
|
||||
try {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTimeInMillis(time);
|
||||
int month = calendar.get(Calendar.MONTH) + 1;
|
||||
return calendar.get(Calendar.YEAR)+"."+month+"."+ calendar.get(Calendar.DAY_OF_MONTH);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param seconds 60
|
||||
* @return 1 时
|
||||
*/
|
||||
public static String secondsToHourStr(long seconds){//秒数转成相应的 小时分钟数
|
||||
if (seconds >= 3600){
|
||||
int hours = (int)seconds/3600;
|
||||
return String.valueOf(hours);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param seconds 60
|
||||
* @return 1 时
|
||||
*/
|
||||
public static String secondsToMinuteStr(long seconds){//秒数转成相应的 小时分钟数
|
||||
int minute = (int)(seconds % 3600)/60;
|
||||
return String.valueOf(minute);
|
||||
}
|
||||
|
||||
/**
|
||||
* 有小数两位, 没有小数保留整数
|
||||
* @param d
|
||||
* @return
|
||||
*/
|
||||
public static String formatLong(double d) {
|
||||
BigDecimal bg = new BigDecimal(d).setScale(1, RoundingMode.HALF_UP);
|
||||
double num = bg.doubleValue();
|
||||
if (Math.ceil(num) - num == 0) {
|
||||
return String.valueOf((long) num);
|
||||
}
|
||||
return String.valueOf(num);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 7.5 KiB After Width: | Height: | Size: 8.6 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.3 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 7.5 KiB After Width: | Height: | Size: 8.6 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.3 KiB |
@@ -82,5 +82,13 @@
|
||||
android:layout_height="match_parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"/>
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="@dimen/dp_40"
|
||||
android:layout_marginBottom="@dimen/dp_48"
|
||||
android:src="@drawable/bus_p_mogo_nor"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintRight_toLeftOf="@+id/bus_p_route_panel"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -5,6 +5,7 @@
|
||||
<string name="bus_p_start_station_txt_tag">起</string>
|
||||
<string name="bus_p_end_station_txt_tag">终</string>
|
||||
<string name="bus_p_cur_station_title">到达站:</string>
|
||||
<string name="bus_p_cur_next_station_title">下一站:</string>
|
||||
<string name="bus_p_cur_station_title_init">始发站:</string>
|
||||
<string name="bus_p_cur_station_arrived_tip">请携带好随身物品下车。</string>
|
||||
<string name="bus_p_cur_station_arrived_tip_init">欢迎乘坐蘑菇车联无人驾驶车。</string>
|
||||
|
||||
Reference in New Issue
Block a user