[dev_arch_opt_3.0] 优化TextView频繁调用setText导致的频繁绘制问题; 优化状态栏上工控机相关状态的处理逻辑
This commit is contained in:
@@ -67,6 +67,9 @@ if (!isAndroidTestBuild()) {
|
||||
object_hashcode {
|
||||
enable true
|
||||
}
|
||||
TextView_setTextProxy {
|
||||
enable true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.knightboost.lancet.api.annotations.Group;
|
||||
import com.knightboost.lancet.api.annotations.ImplementedInterface;
|
||||
import com.knightboost.lancet.api.annotations.NameRegex;
|
||||
import com.knightboost.lancet.api.annotations.ReplaceInvoke;
|
||||
import com.knightboost.lancet.api.annotations.TargetClass;
|
||||
import com.knightboost.lancet.api.annotations.TargetMethod;
|
||||
import com.knightboost.lancet.api.annotations.Weaver;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -18,7 +19,7 @@ public class ObjectHashCodeProxy {
|
||||
public static final ConcurrentHashMap<String, Integer> hashCodes = new ConcurrentHashMap<>();
|
||||
|
||||
@NameRegex("(com\\.mogo\\.eagle\\.core\\.utilcode\\.util\\.ThreadUtils|com\\.mogo\\.eagle\\.core\\.utilcode\\.util\\.UiThreadHandler)")
|
||||
@ImplementedInterface(value = "java.lang.Object",scope = Scope.SELF)
|
||||
@TargetClass(value = "java.lang.Object",scope = Scope.SELF)
|
||||
@TargetMethod(methodName = "hashCode")
|
||||
@ReplaceInvoke
|
||||
public static int hashCodeProxy(Object r) {
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.mogo.launcher.lancet;
|
||||
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.knightboost.lancet.api.Scope;
|
||||
import com.knightboost.lancet.api.annotations.Group;
|
||||
import com.knightboost.lancet.api.annotations.NameRegex;
|
||||
import com.knightboost.lancet.api.annotations.ReplaceInvoke;
|
||||
import com.knightboost.lancet.api.annotations.TargetClass;
|
||||
import com.knightboost.lancet.api.annotations.TargetMethod;
|
||||
import com.knightboost.lancet.api.annotations.Weaver;
|
||||
|
||||
@Weaver
|
||||
@Group("TextView_setTextProxy")
|
||||
public class TextViewSetTextOpt {
|
||||
|
||||
@NameRegex("(com\\.mogo|com\\.zhidao|com\\.elegant|com\\.zhidaoauto|com\\.zhjt).*")
|
||||
@TargetClass(value = "android.widget.TextView",scope = Scope.ALL)
|
||||
@TargetMethod(methodName = "setText")
|
||||
@ReplaceInvoke
|
||||
public static void setText(TextView view, CharSequence text) {
|
||||
if (Looper.myLooper() != Looper.getMainLooper()) {
|
||||
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (StackTraceElement trace : stackTrace) {
|
||||
sb.append(trace.getClassName()).append(".").append(trace.getMethodName()).append("(").append(trace.getLineNumber()).append(")").append("\n");
|
||||
}
|
||||
if (sb.length() > 1) {
|
||||
sb.setLength(sb.length() - 1);
|
||||
}
|
||||
Log.e("ALERT", sb.toString());
|
||||
}
|
||||
CharSequence old = view.getText();
|
||||
if (old != null && !old.equals(text)) {
|
||||
view.setText(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@ buildscript {
|
||||
classpath 'com.mogo.cloud:systrace:1.0.1'
|
||||
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.18'
|
||||
classpath 'com.mogo.sticky:service:1.0.8'
|
||||
classpath 'io.github.knight-zxw:lancet-plugin:0.0.4.5_mogo'
|
||||
classpath 'io.github.knight-zxw:lancet-plugin:0.0.4.8_mogo'
|
||||
|
||||
// classpath ("com.tencent.matrix:matrix-gradle-plugin:0.6.6") { changing = true }
|
||||
}
|
||||
|
||||
@@ -10,10 +10,7 @@ import com.mogo.eagle.core.function.call.autopilot.*
|
||||
import com.mogo.eagle.core.utilcode.kotlin.safeCancel
|
||||
import com.zhjt.mogo_core_function_devatools.status.entity.CanStatus
|
||||
import com.zhjt.mogo_core_function_devatools.status.flow.IFlow
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import mogo_msg.MogoReportMsg.MogoReportMessage
|
||||
import system_master.SystemStatusInfo.StatusInfo
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
@@ -55,7 +52,6 @@ internal class CanImpl(ctx: Context) :
|
||||
|
||||
override fun onAutopilotLightSwitchData(lightSwitch: LightSwitch?) {
|
||||
send(CanStatus(isCanEnabled()))
|
||||
timeOutCheck()
|
||||
}
|
||||
|
||||
private fun isCanEnabled(): Boolean {
|
||||
@@ -66,23 +62,19 @@ internal class CanImpl(ctx: Context) :
|
||||
|
||||
override fun onAutopilotBrakeLightData(brakeLight: Boolean) {
|
||||
send(CanStatus(isCanEnabled()))
|
||||
timeOutCheck()
|
||||
}
|
||||
|
||||
override fun onAutopilotSteeringData(steering: Float) {
|
||||
send(CanStatus(isCanEnabled()))
|
||||
timeOutCheck()
|
||||
}
|
||||
|
||||
override fun onAutopilotGearData(gear: GearPosition) {
|
||||
send(CanStatus(isCanEnabled()))
|
||||
timeOutCheck()
|
||||
}
|
||||
|
||||
override fun onAutopilotIpcConnectStatusChanged(status: Int, reason: String?) {
|
||||
super.onAutopilotIpcConnectStatusChanged(status, reason)
|
||||
send(CanStatus(isCanEnabled()))
|
||||
timeOutCheck()
|
||||
}
|
||||
|
||||
override fun onAutopilotDataException(timestamp: Long) {
|
||||
@@ -92,28 +84,23 @@ internal class CanImpl(ctx: Context) :
|
||||
|
||||
override fun onAutopilotAcc(carAcc: Float) {
|
||||
send(CanStatus(isCanEnabled()))
|
||||
timeOutCheck()
|
||||
}
|
||||
|
||||
override fun onAutopilotThrottle(throttle: Float) {
|
||||
send(CanStatus(isCanEnabled()))
|
||||
timeOutCheck()
|
||||
}
|
||||
|
||||
override fun onAutopilotBrake(brake: Float) {
|
||||
send(CanStatus(isCanEnabled()))
|
||||
timeOutCheck()
|
||||
}
|
||||
|
||||
override fun onSweeperFutianCleanSystemState(cleanSystemState: ChassisStatesOuterClass.SweeperFuTianTaskSystemStates) {
|
||||
send(CanStatus(isCanEnabled()))
|
||||
timeOutCheck()
|
||||
}
|
||||
|
||||
override fun onAutopilotGuardian(guardianInfo: MogoReportMessage?) {
|
||||
super.onAutopilotGuardian(guardianInfo)
|
||||
send(CanStatus(isCanEnabled()))
|
||||
timeOutCheck()
|
||||
}
|
||||
|
||||
override fun onAutopilotStatusRespByQuery(status: StatusInfo) {
|
||||
@@ -124,24 +111,14 @@ internal class CanImpl(ctx: Context) :
|
||||
}
|
||||
}
|
||||
|
||||
private fun timeOutCheck() {
|
||||
job?.safeCancel()
|
||||
launch(Dispatchers.Unconfined) {
|
||||
delay(4000)
|
||||
send(CanStatus(isCanEnabled()))
|
||||
}.also { job = it }
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
job?.safeCancel()
|
||||
|
||||
CallerChassisAccStateListenerManager.removeListener(TAG)
|
||||
CallerChassisBrakeStateListenerManager.removeListener(TAG)
|
||||
CallerChassisGearStateListenerManager.removeListener(TAG)
|
||||
CallerChassisSteeringStateListenerManager.removeListener(TAG)
|
||||
CallerChassisThrottleStateListenerManager.removeListener(TAG)
|
||||
|
||||
CallerAutoPilotStatusListenerManager.removeListener(TAG)
|
||||
CallerChassisLamplightListenerManager.removeListener(TAG)
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ import com.zhjt.mogo_core_function_devatools.status.entity.*
|
||||
import com.zhjt.mogo_core_function_devatools.status.entity.TracingStatus.Tracing.*
|
||||
import com.zhjt.mogo_core_function_devatools.status.flow.*
|
||||
import mogo_msg.MogoReportMsg.MogoReportMessage
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
|
||||
internal class TracingImpl(ctx: Context): IFlow<TracingStatus>(ctx), IMoGoAutopilotStatusListener {
|
||||
|
||||
@@ -18,6 +20,14 @@ internal class TracingImpl(ctx: Context): IFlow<TracingStatus>(ctx), IMoGoAutopi
|
||||
|
||||
private var old: TracingStatus.Tracing = UNKNOWN
|
||||
|
||||
private val ipcConnectStatus by lazy { AtomicInteger() }
|
||||
|
||||
private val ipcStatus by lazy { AtomicInteger() }
|
||||
|
||||
private val reportCode by lazy { AtomicReference<String>() }
|
||||
|
||||
private val reportMsg by lazy { AtomicReference<String>() }
|
||||
|
||||
override fun onCreate() {
|
||||
val code = CallerAutoPilotStatusListenerManager.getAutoPilotReportMessageCode()
|
||||
val msg = CallerAutoPilotStatusListenerManager.getAutoPilotReportMessageContent()
|
||||
@@ -30,32 +40,53 @@ internal class TracingImpl(ctx: Context): IFlow<TracingStatus>(ctx), IMoGoAutopi
|
||||
|
||||
override fun onAutopilotGuardian(guardianInfo: MogoReportMessage?) {
|
||||
super.onAutopilotGuardian(guardianInfo)
|
||||
val current = guardianInfo?.code
|
||||
val newState = current?.toState(guardianInfo.msg)
|
||||
if (newState != null) {
|
||||
old = newState
|
||||
send(TracingStatus(newState))
|
||||
val code = guardianInfo?.code
|
||||
val message = guardianInfo?.msg
|
||||
try {
|
||||
if (code != reportCode.get() || message != reportMsg.get()) {
|
||||
val newState = code?.toState(message)
|
||||
if (newState != null) {
|
||||
old = newState
|
||||
send(TracingStatus(newState))
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
reportCode.set(code)
|
||||
reportMsg.set(message)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAutopilotIpcConnectStatusChanged(status: Int, reason: String?) {
|
||||
super.onAutopilotIpcConnectStatusChanged(status, reason)
|
||||
if (!CallerAutoPilotControlManager.isConnected()) {
|
||||
old = UNKNOWN
|
||||
send(TracingStatus(UNKNOWN))
|
||||
try {
|
||||
if (ipcConnectStatus.get() != status) {
|
||||
if (!CallerAutoPilotControlManager.isConnected()) {
|
||||
old = UNKNOWN
|
||||
send(TracingStatus(UNKNOWN))
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
ipcConnectStatus.set(status)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAutopilotStatusResponse(autoPilotStatusInfo: AutopilotStatusInfo) {
|
||||
super.onAutopilotStatusResponse(autoPilotStatusInfo)
|
||||
if (autoPilotStatusInfo.state != STATUS_AUTOPILOT_RUNNING) {
|
||||
old = UNKNOWN
|
||||
send(TracingStatus(UNKNOWN))
|
||||
return
|
||||
}
|
||||
if (old.isException()) {
|
||||
old = TRACK_LOADED
|
||||
send(TracingStatus(TRACK_LOADED))
|
||||
val state = autoPilotStatusInfo.state
|
||||
try {
|
||||
if (ipcStatus.get() != state) {
|
||||
if (state != STATUS_AUTOPILOT_RUNNING) {
|
||||
old = UNKNOWN
|
||||
send(TracingStatus(UNKNOWN))
|
||||
return
|
||||
}
|
||||
if (old.isException()) {
|
||||
old = TRACK_LOADED
|
||||
send(TracingStatus(TRACK_LOADED))
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
ipcStatus.set(state)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,10 +11,12 @@ import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListener
|
||||
import com.mogo.eagle.core.function.call.devatools.CallerDevaToolsManager
|
||||
import com.mogo.eagle.core.function.hmi.R
|
||||
import com.mogo.eagle.core.function.main.AppListActivity
|
||||
import com.mogo.eagle.core.utilcode.kotlin.*
|
||||
import com.mogo.eagle.core.utilcode.util.ActivityUtils
|
||||
import com.mogo.eagle.core.utilcode.util.AppUtils
|
||||
import com.mogo.eagle.core.utilcode.util.UiThreadHandler
|
||||
import kotlinx.android.synthetic.main.view_version_name.view.*
|
||||
import kotlinx.coroutines.*
|
||||
|
||||
/**
|
||||
* @author XuXinChao
|
||||
@@ -65,13 +67,16 @@ class VersionNameView @JvmOverloads constructor(
|
||||
*/
|
||||
@SuppressLint("SetTextI18n")
|
||||
private fun showCurrentMapVersion() {
|
||||
UiThreadHandler.post {
|
||||
tvMapVersionName?.let {
|
||||
if (!dockerVersion.isNullOrEmpty()) {
|
||||
it.text = "MAP:${dockerVersion}"
|
||||
val old = tvMapVersionName?.text
|
||||
val version = dockerVersion
|
||||
if (!version.isNullOrEmpty() && old != version) {
|
||||
scope.launch {
|
||||
tvMapVersionName?.also {
|
||||
it.text = version
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
|
||||
@@ -39,16 +39,18 @@ val <T: View> T.lifecycleOwner: LifecycleOwner
|
||||
init {
|
||||
if (ViewCompat.isAttachedToWindow(this@lifecycleOwner)) {
|
||||
lifecycle.let {
|
||||
if (it.currentState.isAtLeast(Lifecycle.State.INITIALIZED)) {
|
||||
it.currentState = Lifecycle.State.CREATED
|
||||
}
|
||||
post {
|
||||
if (it.currentState.isAtLeast(Lifecycle.State.INITIALIZED)) {
|
||||
it.currentState = Lifecycle.State.CREATED
|
||||
}
|
||||
|
||||
if (it.currentState.isAtLeast(Lifecycle.State.CREATED)) {
|
||||
it.currentState = Lifecycle.State.STARTED
|
||||
}
|
||||
if (it.currentState.isAtLeast(Lifecycle.State.CREATED)) {
|
||||
it.currentState = Lifecycle.State.STARTED
|
||||
}
|
||||
|
||||
if (it.currentState.isAtLeast(Lifecycle.State.STARTED)) {
|
||||
it.currentState = Lifecycle.State.RESUMED
|
||||
if (it.currentState.isAtLeast(Lifecycle.State.STARTED)) {
|
||||
it.currentState = Lifecycle.State.RESUMED
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user