droid注解注入AspectJ面向切面AOP插桩技术改变android原生类对象行为记录View点击事件,Java(3)
动态改变Toast提示的内容,弹之前修改。Button在每次点击后记录。
import android.util.Log;
import android.widget.Toast;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
//一个切面
@Aspect
public class MyActivityAspect {
//将在Toast弹出显示前改写文本内容,最终显示zhangphil
@Before("call(* android.widget.Toast.show())")
public void changeToast(JoinPoint joinPoint) {
Toast toast = (Toast) joinPoint.getTarget();
toast.setText("zhangphil");
Log.d("zhangphil", "改变Toast行为");
}
//监测Button点击事件
@Pointcut("execution(* android.view.View.OnClickListener.onClick(..))")
public void onClickPointcut() {
}
//在Button点击事件后触发,日志输出
@After("onClickPointcut()")
public void clickPoint(ProceedingJoinPoint joinPoint) throws Throwable {
Log.d("zhangphil", "onClick");
}
}
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toast.makeText(this, "hello,world!", Toast.LENGTH_LONG).show();
Button button = findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
}
}
android注解注入AspectJ面向切面AOP插桩技术性能监测android原生类函数/方法运行耗时/时长(2)_zhangphil的博客-CSDN博客android注解注入AspectJ面向切面AOP插桩技术,Java(1)通知注解例如,一个Before:切点匹配规则。android注解注入AspectJ面向切面AOP插桩技术,Java(1)_zhangphil的博客-CSDN博客。https://blog.csdn.net/zhangphil/article/details/129559160
android注解注入AspectJ面向切面AOP插桩技术,Java(1)_zhangphil的博客-CSDN博客android注解注入AspectJ面向切面AOP插桩技术,Java(1)通知注解例如,一个Before:切点匹配规则https://blog.csdn.net/zhangphil/article/details/129559632