[剩余时间距离]
This commit is contained in:
yangyakun
2023-07-14 19:52:33 +08:00
parent 13f2d75b2a
commit 795a0178ea
10 changed files with 198 additions and 27 deletions

View File

@@ -6,7 +6,8 @@ interface IDistanceListener {
/**
* @param distance 距离终点坐标的距离
*/
fun distanceCallback(distance: Float)
fun distanceCallback(distance: Float){}
fun stationDistanceCallback(stationDistance:Float){}
}
interface ITrajectoryListener{

View File

@@ -57,8 +57,11 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
@Volatile
private var mRoutePoints: MutableList<MogoLocation>? = ArrayList()
// 0-1 1-2 2-3 各个轨迹点的距离
private var mRoutePointsDistance: MutableList<Float>? = ArrayList()
// 所有轨迹点距离的和
private var maxDistanceAllPoint:Double = 0.0
private val stationDistance: ConcurrentHashMap<String, Float> = ConcurrentHashMap()
@Volatile
private var lineId:Long? = null
@@ -155,14 +158,17 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
this.endStationInfo.stationPoint = null
this.startStationInfo.stationPoint = null
this.lineId = null
stationDistance.clear()
}else{
if(isSameStation(this.startStationInfo.stationPoint,startStationInfo)&&
isSameStation(this.endStationInfo.stationPoint,endStationInfo)){
if(this.lineId!=lineId){
resetStation()
stationDistance.clear()
}
}else{
resetStation()
stationDistance.clear()
}
this.endStationInfo.stationPoint = endStationInfo
this.startStationInfo.stationPoint = startStationInfo
@@ -306,6 +312,22 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
preCarLocationIndexInTrajectory = carLocationInfo.first
try {
if (endStationInfo.stationPoint != null
&& endStationInfo.isNext!= null
&& endStationInfo.index != null
&& endStationInfo.distance != null
&& startStationInfo.stationPoint != null
&& startStationInfo.isNext != null
&& startStationInfo.index != null
&& startStationInfo.distance != null
) {
calculateStationDistance()
}
}catch (e:Exception){
e(M_OCHCOMMON+ TAG,"计算两个站点间的距离")
}
// 距离回调
try {
if(distanceListeners.size>0) {
@@ -334,6 +356,56 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{
}
/**
* 计算站点间距离
*/
private fun calculateStationDistance() {
var lastSumLength = 0f
val key = getKey()
if (stationDistance[key] !=null) {
return
}
val stationIndex = endStationInfo.index?:0
if (startStationInfo.index!! < stationIndex-1) {
// subList 是[) 需要的是[]
val subList = mRoutePoints!!.subList(startStationInfo.index!!, stationIndex + 1)
// 轨迹点所有的距离
lastSumLength = CoordinateCalculateRouteUtil.calculateRouteSumLength(subList)
val stationDistance = endStationInfo.distance ?: 0f
if (endStationInfo.isNext == true) {// isNext = true
lastSumLength -= stationDistance
} else {// isNext = false
lastSumLength += stationDistance
}
if (startStationInfo.isNext==true) {// 是否是下一个 true 下一个
lastSumLength += startStationInfo.distance!!
} else {
lastSumLength -= startStationInfo.distance!!
}
} else {
val lastPoints = endStationInfo.stationPoint
lastSumLength = CoordinateUtils.calculateLineDistance(
startStationInfo.stationPoint!!.longitude, startStationInfo.stationPoint!!.latitude,
lastPoints!!.longitude, lastPoints.latitude
)
}
d(M_OCHCOMMON+ TAG,"距离终点:$lastSumLength")
stationDistance[key] = lastSumLength
if(distanceListeners.size>0) {
distanceListeners.forEach {
//val tag = it.key
val listener = it.value
listener.stationDistanceCallback(lastSumLength)
}
}
}
private fun getKey(): String {
return "${startStationInfo.stationPoint!!.longitude}${startStationInfo.stationPoint!!.latitude}${endStationInfo.stationPoint!!.longitude}${endStationInfo.stationPoint!!.latitude}"
}
private fun invokeDistance(
carLocationInfo: Triple<Int, Boolean?, Float>,

View File

@@ -1,20 +1,19 @@
package com.mogo.och.taxi.passenger.callback;
package com.mogo.och.taxi.passenger.callback
import com.mogo.och.taxi.passenger.bean.TaxiPassengerOrderQueryRespBean;
import com.mogo.och.taxi.passenger.bean.TaxiPassengerOrderQueryRespBean
/**
* Created on 2021/9/8
*
* Model->Presenter回调订单相关进行中/待服务单变更当前进行单状态变更新到预约单抢单抢单结果状态等等
*/
public interface IOCHTaxiPassengerOrderStatusCallback {
interface IOCHTaxiPassengerOrderStatusCallback {
// 当前进行单状态变更:新到进行中订单、进行中单状态变更
void onCurrentOrderStatusChanged(TaxiPassengerOrderQueryRespBean.Result order);
fun onCurrentOrderStatusChanged(order: TaxiPassengerOrderQueryRespBean.Result?){}
// 当前位置距离上车点的距离(米)、预估时间(秒)
void onCurrentOrderDistToEndChanged(long meters, long timeInSecond);
fun onCurrentOrderDistToEndChanged(meters: Long, timeInSecond: Long,stationDistance:Int){}
// 司机已确认开启自动驾驶环境
void onDriverHasCheckedPilotCondition(boolean isBoarded);
}
fun onDriverHasCheckedPilotCondition(isBoarded: Boolean){}
}

View File

@@ -173,9 +173,8 @@ object TaxiPassengerModel {
//监听网络变化,避免启动机器时无网导致无法更新订单信息
private val distanceListener: IDistanceListener = object : IDistanceListener {
override fun distanceCallback(distance: Float) {
// TODO: 计算站点到站点的距离 calculateRouteLineSum()
SharedPrefsMgr.getInstance(mContext!!).putInt(TaxiPassengerConst.SP_KEY_ORDER_SUM_DIS, 12)
override fun stationDistanceCallback(stationDistance: Float) {
SharedPrefsMgr.getInstance(mContext!!).putInt(TaxiPassengerConst.SP_KEY_ORDER_SUM_DIS, stationDistance.toInt())
}
}
private val mNetWorkIntentListener = IMogoIntentListener { intentStr, intent ->
@@ -221,8 +220,10 @@ object TaxiPassengerModel {
override fun onSuccess(data: TaxiPassengerOrderQueryRemainingResp) {
if (data.data != null) {
e(M_TAXI_P + TAG, "distance = " + data.data.distance + " ,duration = " + data.data.duration)
val stationDistance = SharedPrefsMgr.getInstance(mContext!!)
.getInt(TaxiPassengerConst.SP_KEY_ORDER_SUM_DIS, 0)
for (callback in mOrderStatusCallbackMap.values) {
callback.onCurrentOrderDistToEndChanged(data.data.distance, data.data.duration)
callback.onCurrentOrderDistToEndChanged(data.data.distance, data.data.duration,stationDistance)
}
}
}

View File

@@ -87,7 +87,7 @@ public class BaseTaxiPassengerPresenter extends Presenter<TaxiPassengerBaseFragm
}
@Override
public void onCurrentOrderDistToEndChanged(long meters, long timeInSecond) {
public void onCurrentOrderDistToEndChanged(long meters, long timeInSecond,int stationDistance) {
}

View File

@@ -5,6 +5,7 @@ import android.graphics.drawable.ClipDrawable
import android.graphics.drawable.GradientDrawable
import android.graphics.drawable.LayerDrawable
import android.graphics.drawable.ScaleDrawable
import android.os.Build
import android.util.AttributeSet
import android.view.Gravity
import android.view.LayoutInflater
@@ -40,35 +41,45 @@ class ItineraryView : ConstraintLayout, OrderInfoViewModel.ItineraryViewCallback
constructor(context: Context, attributeSet: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attributeSet, defStyleAttr, defStyleRes)
private fun initView(context: Context) {
private fun initView() {
LayoutInflater.from(context).inflate(R.layout.taxi_p_itinerary, this, true)
setDrawable(true)
progress_distance.progress = 0
progress_distance.max = 100
}
private fun setDrawable(normal:Boolean) {
val gradientDrawable = GradientDrawable()
gradientDrawable.shape = GradientDrawable.RECTANGLE
val corner = AutoSizeUtils.dp2px(context, 40f).toFloat()
val cornerTop = AutoSizeUtils.dp2px(context, 20f).toFloat()
gradientDrawable.cornerRadii = floatArrayOf(0f, 0f, cornerTop, cornerTop, cornerTop, cornerTop, corner, corner)
if(normal) {
gradientDrawable.cornerRadii =
floatArrayOf(0f, 0f, cornerTop, cornerTop, cornerTop, cornerTop, corner, corner)
}else {
gradientDrawable.cornerRadii =
floatArrayOf(0f, 0f, 0f, 0f, corner, corner, corner, corner)
}
val firstColor = ContextCompat.getColor(context, R.color.taxi_p_OF5FFF)
val setondColor = ContextCompat.getColor(context, R.color.taxi_p_44C8FF)
val thirdColor = ContextCompat.getColor(context, R.color.taxi_p_8AE4ED)
val fourceColor = ContextCompat.getColor(context, R.color.taxi_p_C8F3F4)
val bottomColor = ContextCompat.getColor(context, R.color.taxi_p_476FBE)
gradientDrawable.colors = intArrayOf(firstColor,setondColor,thirdColor,fourceColor)
gradientDrawable.colors = intArrayOf(firstColor, setondColor, thirdColor, fourceColor)
gradientDrawable.orientation = GradientDrawable.Orientation.LEFT_RIGHT
val temp01 = GradientDrawable()
temp01.cornerRadii = floatArrayOf(0f, 0f, 0f, 0f, corner, corner, corner, corner)
temp01.colors = intArrayOf(bottomColor,bottomColor)
temp01.colors = intArrayOf(bottomColor, bottomColor)
val scaleDrawable3 = ScaleDrawable(gradientDrawable, Gravity.START, 1f,-1f)
val scaleDrawable3 = ScaleDrawable(gradientDrawable, Gravity.START, 1f, -1f)
val arr = arrayOf(temp01, scaleDrawable3)
val ld = LayerDrawable(arr)
ld.setDrawableByLayerId(android.R.id.background, temp01)
ld.setDrawableByLayerId(android.R.id.progress, scaleDrawable3)
progress_distance.setProgressDrawableTiled(ld)
progress_distance.progress = 0
progress_distance.max = 100
}
override fun onAttachedToWindow() {
@@ -88,20 +99,44 @@ class ItineraryView : ConstraintLayout, OrderInfoViewModel.ItineraryViewCallback
actv_endstation.text = endStation
}
var prePercentage = 0
val needChangeStyleNumber = 0.98622
override fun setDistanceInfo(surplusdistance:String,distanceUnit:String,
surplusTime:String,surplusTimeUnit:String,
arrivedTime:String,alreadyGone:Int,distance:Int
arrivedTime:String,alreadyGone:Int,stationDistance:Int
){
actv_distance.text = surplusdistance
actv_distance_unit.text = distanceUnit
actv_surplus_time .text= surplusTime
actv_surplus_time_unit.text = surplusTimeUnit
actv_arrived_time.text= arrivedTime
if(stationDistance>0&&alreadyGone<stationDistance){
val currentPercentage = alreadyGone.toFloat() / stationDistance
if((prePercentage>needChangeStyleNumber) xor (currentPercentage>needChangeStyleNumber)){
if(currentPercentage>needChangeStyleNumber){
setDrawable(false)
}else{
setDrawable(true)
}
}
if (progress_distance.max != stationDistance) {
progress_distance.max = stationDistance
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
progress_distance.setProgress(alreadyGone,true)
}else{
progress_distance.progress = alreadyGone
}
}
}
init {
try {
initView(context)
initView()
} catch (e: Exception) {
e.printStackTrace()
}

View File

@@ -1,13 +1,22 @@
package com.mogo.och.taxi.passenger.ui.orderinfo
import androidx.lifecycle.ViewModel
import com.mogo.commons.AbsMogoApplication
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.util.UiThreadHandler
import com.mogo.och.common.module.utils.DateTimeUtil
import com.mogo.och.common.module.utils.NumberFormatUtil
import com.mogo.och.taxi.passenger.R
import com.mogo.och.taxi.passenger.bean.TaxiPassengerOrderQueryRespBean
import com.mogo.och.taxi.passenger.callback.IOCHTaxiPassengerOrderStatusCallback
import com.mogo.och.taxi.passenger.model.TaxiPassengerModel
import kotlin.math.abs
import kotlin.math.ceil
class OrderInfoViewModel: ViewModel(), IMoGoChassisLocationGCJ02Listener {
class OrderInfoViewModel: ViewModel(), IMoGoChassisLocationGCJ02Listener,
IOCHTaxiPassengerOrderStatusCallback {
private val TAG = OrderInfoViewModel::class.java.simpleName
@@ -16,6 +25,7 @@ class OrderInfoViewModel: ViewModel(), IMoGoChassisLocationGCJ02Listener {
init {
// 设置起点和终点marker和实时车辆位置
CallerChassisLocationGCJ02ListenerManager.addListener(TAG, 4, this)
TaxiPassengerModel.setOrderStatusCallback(TAG,this)
}
fun setDistanceCallback(viewCallback:ItineraryViewCallback){
@@ -45,4 +55,34 @@ class OrderInfoViewModel: ViewModel(), IMoGoChassisLocationGCJ02Listener {
fun setSpeed(speedValue:String)
}
override fun onCurrentOrderStatusChanged(order: TaxiPassengerOrderQueryRespBean.Result?) {
order?.endSiteAddr?.let {
UiThreadHandler.post {
viewCallback?.setEndStation(it)
}
}
}
override fun onCurrentOrderDistToEndChanged(meters: Long, timeInSecond: Long,stationDistance:Int) {
var dis: String? = "0"
var disUnit = "KM"
if (meters > 0) {
if (meters / 1000 < 1) {
disUnit = AbsMogoApplication.getApp().getString(R.string.taxi_p_distance_unit_m)
dis = Math.round(meters.toFloat()).toString()
} else {
dis = NumberFormatUtil.formatLong(meters.toDouble() / 1000)
}
}
val time = ceil(timeInSecond / 60f).toInt()
val arriveTime = DateTimeUtil.getAfterSecondTime(timeInSecond.toInt())
val surplusTimeUnit = AbsMogoApplication.getApp().getString(R.string.taxi_p_surplustime)
UiThreadHandler.post {
viewCallback?.setDistanceInfo(
dis!!,disUnit,time.toString(),surplusTimeUnit,arriveTime,stationDistance-meters.toInt(),stationDistance)
}
}
}

View File

@@ -73,6 +73,14 @@
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.mogo.eagle.core.function.hmi.ui.setting.ToggleDebugViewTrigger
android:layout_width="@dimen/dp_400"
android:layout_height="@dimen/dp_100"
android:longClickable="true"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
<!-- 路程信息 -->
<com.mogo.och.taxi.passenger.ui.orderinfo.ItineraryView
android:id="@+id/itinerary"

View File

@@ -36,4 +36,10 @@
<string name="taxi_p_start_autopilot_loading">启动中...</string>
<string name="taxi_p_start_autopilot_fail_10s_tip">自动驾驶启动失败,请与司机确认车辆状态</string>
<string name="taxi_p_start_autopilot_un_click_tip">车辆尚未完成准备,不能启动自动驾驶</string>
<string name="taxi_p_distance_unit_km">距离(KM)</string>
<string name="taxi_p_distance_unit_m">距离(M)</string>
<string name="taxi_p_surplustime">剩余(分)</string>
</resources>

View File

@@ -1481,7 +1481,16 @@ public class TaxiModel {
}
}
private final IDistanceListener distanceListener = this::updateDistance;
private final IDistanceListener distanceListener = new IDistanceListener() {
@Override
public void distanceCallback(float distance) {
updateDistance(distance);
}
@Override
public void stationDistanceCallback(float stationDistance) {
}
};
private final ITrajectoryListener trajectoryListener = (routeArrivied, routeArriving, location) -> {
if (mAutopilotPlanningCallback != null) {