[CrashFix]由于系统配置更改导致Timer创建过多
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
package com.mogo.eagle.core.function.hmi.ui.widget
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.graphics.*
|
||||
import android.location.Location
|
||||
import android.util.AttributeSet
|
||||
import android.util.*
|
||||
import android.view.Gravity
|
||||
import android.widget.FrameLayout
|
||||
import com.alibaba.android.arouter.launcher.ARouter
|
||||
import com.mogo.eagle.core.data.constants.MogoServicePaths
|
||||
import com.mogo.eagle.core.function.call.hmi.CallerHmiManager
|
||||
import com.mogo.eagle.core.function.hmi.R
|
||||
import com.mogo.eagle.core.utilcode.util.UiThreadHandler
|
||||
import com.mogo.map.MogoMapUIController
|
||||
import com.mogo.eagle.core.utilcode.util.*
|
||||
import com.mogo.map.*
|
||||
import com.mogo.map.navi.IMogoCarLocationChangedListener2
|
||||
import com.mogo.service.IMogoServiceApis
|
||||
import java.util.*
|
||||
@@ -38,6 +38,11 @@ class SpeedPanelView @JvmOverloads constructor(
|
||||
|
||||
var mSpeedLimmit = 60;
|
||||
|
||||
|
||||
private val timer by lazy {
|
||||
Timer()
|
||||
}
|
||||
|
||||
init {
|
||||
initEvent(context)
|
||||
|
||||
@@ -61,29 +66,31 @@ class SpeedPanelView @JvmOverloads constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private val timerTask = object : TimerTask() {
|
||||
override fun run() {
|
||||
if (mLatLng != null) {
|
||||
mSpeedLimmit = MogoMapUIController.getInstance()
|
||||
.getLimitSpeed(mLatLng!!.longitude, mLatLng!!.latitude, mLatLng!!.bearing)
|
||||
UiThreadHandler.post {
|
||||
val speed = (mLatLng!!.speed * 3.6f).toInt()
|
||||
mSpeedChartView.setArcColor(Color.parseColor(if (speed > mSpeedLimmit) "#DB3137" else "#3E77F6"))
|
||||
mSpeedChartView.setValues(speed)
|
||||
setBackgroundResource(if (speed > mSpeedLimmit) R.drawable.yi_biao_pan_bg_speeding else R.drawable.yi_biao_pan_bg_nor)
|
||||
private var timerTask : TimerTask? = null
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow() // 注册位置回调
|
||||
mMogoServiceApis.registerCenterApi.registerCarLocationChangedListener(TAG, this)
|
||||
// 开启定时查询速度
|
||||
timerTask?.cancel()
|
||||
val task = object : TimerTask() {
|
||||
override fun run() {
|
||||
Log.d("TTT", "---- timer run ----")
|
||||
if (mLatLng != null) {
|
||||
|
||||
mSpeedLimmit = MogoMapUIController.getInstance()
|
||||
.getLimitSpeed(mLatLng!!.longitude, mLatLng!!.latitude, mLatLng!!.bearing)
|
||||
UiThreadHandler.post {
|
||||
val speed = (mLatLng!!.speed * 3.6f).toInt()
|
||||
mSpeedChartView.setArcColor(Color.parseColor(if (speed > mSpeedLimmit) "#DB3137" else "#3E77F6"))
|
||||
mSpeedChartView.setValues(speed)
|
||||
setBackgroundResource(if (speed > mSpeedLimmit) R.drawable.yi_biao_pan_bg_speeding else R.drawable.yi_biao_pan_bg_nor)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
// 注册位置回调
|
||||
mMogoServiceApis.registerCenterApi
|
||||
.registerCarLocationChangedListener(TAG, this)
|
||||
|
||||
// 开启定时查询速度
|
||||
Timer().schedule(timerTask, Date(), 100)
|
||||
this.timerTask = task
|
||||
timer.schedule(task, Date(), 100)
|
||||
}
|
||||
|
||||
override fun onDetachedFromWindow() {
|
||||
@@ -92,7 +99,7 @@ class SpeedPanelView @JvmOverloads constructor(
|
||||
mMogoServiceApis.registerCenterApi
|
||||
.unregisterMogoLocationListener(TAG)
|
||||
try {
|
||||
timerTask.cancel()
|
||||
timerTask?.cancel()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user