[Taxi无人化] refactor: DebugView 新增打印日志;
This commit is contained in:
@@ -4,11 +4,17 @@ import android.content.BroadcastReceiver
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.IntentFilter
|
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.util.AttributeSet
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
|
import android.widget.TextView
|
||||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
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.network.utils.GsonUtil
|
||||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.d
|
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.d
|
||||||
import com.mogo.och.common.module.utils.DateTimeUtil
|
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.currentOrderTrajectoryInfo
|
||||||
import kotlinx.android.synthetic.main.taxi_debug_order.view.currentStatus
|
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.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.orderEndSiteInfo
|
||||||
import kotlinx.android.synthetic.main.taxi_debug_order.view.orderNo
|
import kotlinx.android.synthetic.main.taxi_debug_order.view.orderNo
|
||||||
import kotlinx.android.synthetic.main.taxi_debug_order.view.orderPreLoadLines
|
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.taskEndSite
|
||||||
import kotlinx.android.synthetic.main.taxi_debug_order.view.taskStartSite
|
import kotlinx.android.synthetic.main.taxi_debug_order.view.taskStartSite
|
||||||
|
|
||||||
|
|
||||||
public class DebugView @JvmOverloads constructor(
|
public class DebugView @JvmOverloads constructor(
|
||||||
context: Context,
|
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0, defStyleRes: Int = 0
|
||||||
attrs: AttributeSet? = null,
|
|
||||||
defStyleAttr: Int = 0,
|
|
||||||
defStyleRes: Int = 0
|
|
||||||
) : LinearLayout(context, attrs, defStyleAttr, defStyleRes), ITaxiTaskWithOrderCallback {
|
) : LinearLayout(context, attrs, defStyleAttr, defStyleRes), ITaxiTaskWithOrderCallback {
|
||||||
companion object {
|
companion object {
|
||||||
const val TAG = "DebugView"
|
const val TAG = "DebugView"
|
||||||
const val BROADCAST_ACTION = "com.mogo.och.driver.debugview.show"
|
const val BROADCAST_ACTION = "com.mogo.och.driver.debugview.show"
|
||||||
const val BROADCAST_DATA_SHOW = "isShow"
|
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() {
|
private val broadcastReceiver = object : BroadcastReceiver() {
|
||||||
@@ -59,9 +102,10 @@ public class DebugView @JvmOverloads constructor(
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
initBroadcastReceiver()
|
initBroadcastReceiver()
|
||||||
LayoutInflater.from(context)
|
LayoutInflater.from(context).inflate(R.layout.taxi_debug_order, this, true)
|
||||||
.inflate(R.layout.taxi_debug_order, this, true)
|
debugLogHistoryTextView.setMovementMethod(ScrollingMovementMethod.getInstance())
|
||||||
visibility = GONE
|
visibility = GONE
|
||||||
|
logHistoryTextView = debugLogHistoryTextView
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initBroadcastReceiver() {
|
private fun initBroadcastReceiver() {
|
||||||
@@ -71,11 +115,8 @@ public class DebugView @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun toggleOrderDebugView() {
|
fun toggleOrderDebugView() {
|
||||||
visibility =
|
visibility = if (visibility == View.VISIBLE) View.GONE
|
||||||
if (visibility == View.VISIBLE)
|
else View.VISIBLE
|
||||||
View.GONE
|
|
||||||
else
|
|
||||||
View.VISIBLE
|
|
||||||
val data = TaxiTaskModel.getCurrentTaskWithOrder()
|
val data = TaxiTaskModel.getCurrentTaskWithOrder()
|
||||||
initViewByData(data)
|
initViewByData(data)
|
||||||
}
|
}
|
||||||
@@ -100,15 +141,11 @@ public class DebugView @JvmOverloads constructor(
|
|||||||
|
|
||||||
private fun initViewByData(data: QueryCurrentTaskRespBean.Result?) {
|
private fun initViewByData(data: QueryCurrentTaskRespBean.Result?) {
|
||||||
val curContrail = TaxiTaskModel.getCurrentTaskTrajectory()
|
val curContrail = TaxiTaskModel.getCurrentTaskTrajectory()
|
||||||
currentDataTimestamps.text = "【当前数据返回时间】${
|
currentDataTimestamps.text = "【当前数据返回时间】${currentDateTimeString()}"
|
||||||
DateTimeUtil.formatCalendarToString(
|
|
||||||
DateTimeUtil.formatLongToCalendar(System.currentTimeMillis()),
|
|
||||||
DateTimeUtil.yyyy_MM_dd_HH_mm_ss
|
|
||||||
)
|
|
||||||
}"
|
|
||||||
currentCarStatus.text =
|
currentCarStatus.text =
|
||||||
"【当前车辆状态】${data?.servingStatus} / ${if (data?.servingStatus == 1) "开始接单" else "暂停接单"}"
|
"【当前车辆状态】${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 =
|
currentStatus.text =
|
||||||
"【当前任务状态】${data?.currentStatus} / ${TaskStatusEnum.valueOf(data?.currentStatus ?: -1)?.name}"
|
"【当前任务状态】${data?.currentStatus} / ${TaskStatusEnum.valueOf(data?.currentStatus ?: -1)?.name}"
|
||||||
currentLineId.text = "【当前任务lineId】 ${data?.lineId}"
|
currentLineId.text = "【当前任务lineId】 ${data?.lineId}"
|
||||||
|
|||||||
@@ -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>
|
||||||
@@ -158,4 +158,16 @@
|
|||||||
android:text="Mock模拟轨迹"
|
android:text="Mock模拟轨迹"
|
||||||
android:textSize="12sp" />
|
android:textSize="12sp" />
|
||||||
</LinearLayout>
|
</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>
|
</LinearLayout>
|
||||||
Reference in New Issue
Block a user