[Taxi无人化] refactor: DebugView 新增打印日志;

This commit is contained in:
aibingbing
2023-08-29 11:56:32 +08:00
parent 353e4463f1
commit 6f528f7b0c
3 changed files with 75 additions and 18 deletions

View File

@@ -4,11 +4,17 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.text.SpannableString
import android.text.Spanned
import android.text.method.ScrollingMovementMethod
import android.text.style.ForegroundColorSpan
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import android.widget.TextView
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import com.mogo.eagle.core.function.main.MainMoGoApplication
import com.mogo.eagle.core.network.utils.GsonUtil
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.d
import com.mogo.och.common.module.utils.DateTimeUtil
@@ -28,6 +34,7 @@ import kotlinx.android.synthetic.main.taxi_debug_order.view.currentOrderStopInfo
import kotlinx.android.synthetic.main.taxi_debug_order.view.currentOrderTrajectoryInfo
import kotlinx.android.synthetic.main.taxi_debug_order.view.currentStatus
import kotlinx.android.synthetic.main.taxi_debug_order.view.currentTaskType
import kotlinx.android.synthetic.main.taxi_debug_order.view.debugLogHistoryTextView
import kotlinx.android.synthetic.main.taxi_debug_order.view.orderEndSiteInfo
import kotlinx.android.synthetic.main.taxi_debug_order.view.orderNo
import kotlinx.android.synthetic.main.taxi_debug_order.view.orderPreLoadLines
@@ -36,16 +43,52 @@ import kotlinx.android.synthetic.main.taxi_debug_order.view.orderStatus
import kotlinx.android.synthetic.main.taxi_debug_order.view.taskEndSite
import kotlinx.android.synthetic.main.taxi_debug_order.view.taskStartSite
public class DebugView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
defStyleRes: Int = 0
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0, defStyleRes: Int = 0
) : LinearLayout(context, attrs, defStyleAttr, defStyleRes), ITaxiTaskWithOrderCallback {
companion object {
const val TAG = "DebugView"
const val BROADCAST_ACTION = "com.mogo.och.driver.debugview.show"
const val BROADCAST_DATA_SHOW = "isShow"
private var logHistoryTextView: TextView? = null
fun printInfoMsg(msg: String) {
printMsg(msg, MainMoGoApplication.getApp().getColor(R.color.background_info))
}
fun printWarnMsg(msg: String) {
printMsg(msg, MainMoGoApplication.getApp().getColor(R.color.background_warn))
}
fun printErrorMsg(msg: String) {
printMsg(msg, MainMoGoApplication.getApp().getColor(R.color.background_error))
}
private fun printMsg(msg: String, textColor: Int) {
logHistoryTextView?.also {
val msg = "${currentDateTimeString()} $msg"
val spannableMsg = SpannableString(msg)
spannableMsg.setSpan(
ForegroundColorSpan(textColor), 0, msg.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
)
it.append(spannableMsg.toString())
val offset: Int = it.lineCount * it.lineHeight
if (offset > it.height) {
it.scrollTo(0, offset - it.height)
}
}
}
private fun currentDateTimeString(): String {
return DateTimeUtil.formatCalendarToString(
DateTimeUtil.formatLongToCalendar(System.currentTimeMillis()),
DateTimeUtil.yyyy_MM_dd_HH_mm_ss
)
}
}
private val broadcastReceiver = object : BroadcastReceiver() {
@@ -59,9 +102,10 @@ public class DebugView @JvmOverloads constructor(
init {
initBroadcastReceiver()
LayoutInflater.from(context)
.inflate(R.layout.taxi_debug_order, this, true)
LayoutInflater.from(context).inflate(R.layout.taxi_debug_order, this, true)
debugLogHistoryTextView.setMovementMethod(ScrollingMovementMethod.getInstance())
visibility = GONE
logHistoryTextView = debugLogHistoryTextView
}
private fun initBroadcastReceiver() {
@@ -71,11 +115,8 @@ public class DebugView @JvmOverloads constructor(
}
fun toggleOrderDebugView() {
visibility =
if (visibility == View.VISIBLE)
View.GONE
else
View.VISIBLE
visibility = if (visibility == View.VISIBLE) View.GONE
else View.VISIBLE
val data = TaxiTaskModel.getCurrentTaskWithOrder()
initViewByData(data)
}
@@ -100,15 +141,11 @@ public class DebugView @JvmOverloads constructor(
private fun initViewByData(data: QueryCurrentTaskRespBean.Result?) {
val curContrail = TaxiTaskModel.getCurrentTaskTrajectory()
currentDataTimestamps.text = "【当前数据返回时间】${
DateTimeUtil.formatCalendarToString(
DateTimeUtil.formatLongToCalendar(System.currentTimeMillis()),
DateTimeUtil.yyyy_MM_dd_HH_mm_ss
)
}"
currentDataTimestamps.text = "【当前数据返回时间】${currentDateTimeString()}"
currentCarStatus.text =
"【当前车辆状态】${data?.servingStatus} / ${if (data?.servingStatus == 1) "开始接单" else "暂停接单"}"
currentTaskType.text = "【当前任务类型】${data?.taskType} / ${TaskTypeEnum.valueOf(data?.taskType ?: -1)?.name}"
currentTaskType.text =
"【当前任务类型】${data?.taskType} / ${TaskTypeEnum.valueOf(data?.taskType ?: -1)?.name}"
currentStatus.text =
"【当前任务状态】${data?.currentStatus} / ${TaskStatusEnum.valueOf(data?.currentStatus ?: -1)?.name}"
currentLineId.text = "【当前任务lineId】 ${data?.lineId}"

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="8dp" />
<stroke
android:width="@dimen/dp_2"
android:color="@color/background_verbose" />
</shape>

View File

@@ -158,4 +158,16 @@
android:text="Mock模拟轨迹"
android:textSize="12sp" />
</LinearLayout>
<TextView
android:id="@+id/debugLogHistoryTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_10"
android:background="@drawable/taxi_debug_view_log_history_bg"
android:maxLines="10"
android:textColor="@android:color/white"
android:scrollbars="vertical"
android:fadeScrollbars="false"
android:textSize="@dimen/dp_24" />
</LinearLayout>