[2.15.0] 优化子线程切主线程操作
This commit is contained in:
40
app/src/main/java/com/mogo/launcher/lancet/TextViewOpt.java
Normal file
40
app/src/main/java/com/mogo/launcher/lancet/TextViewOpt.java
Normal 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_opt")
|
||||
public class TextViewOpt {
|
||||
|
||||
@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());
|
||||
return;
|
||||
}
|
||||
CharSequence old = view.getText();
|
||||
if (old != null && !old.equals(text)) {
|
||||
view.setText(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user