[dev_arch_opt_3.0] 优化TextView频繁调用setText导致的频繁绘制问题; 优化状态栏上工控机相关状态的处理逻辑

This commit is contained in:
renwj
2023-03-14 16:02:27 +08:00
parent 7e3abc88e0
commit 33a2f2dfe4
8 changed files with 112 additions and 53 deletions

View File

@@ -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);
}
}
}