import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Created by Administrator (chenPS) on 2020/7/16.
*/
@Retention(RetentionPolicy.CLASS)
@Target({ElementType.TYPE,ElementType.METHOD})
public @interface AopSingleClick {
}
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
/**
* Created by Administrator (chenPS) on 2020/7/16.
*/
@Aspect
public class AopClickListener {
private LOG mLOG=new LOG("AopClickListener");
private long lastClickTime=0;
//这里有个坑OnClickListener 是大写开头
@Pointcut("execution(* android.view.View.OnClickListener.onClick(..))")
public void clickMethod(){
}
//只执行有这个注解的
@Pointcut("@within(AopSingleClick)")
public void annoClassModel(){
}
@Around("clickMethod()&&annoClassModel()")
public void singleClickPotin(ProceedingJoinPoint joinPoint){
long currentClickTime=System.currentTimeMillis();
if(currentClickTime-lastClickTime>1000){
lastClickTime=currentClickTime;
try {
joinPoint.proceed();
} catch (Throwable throwable) {
throwable.printStackTrace();
}
mLOG.e("代理点击事件");
}else {
mLOG.e("点太快了");
}
}
}
不知道对不对方法。
参考
https://blog.csdn.net/sunlihuo/article/details/52701548
网友评论