美文网首页
2020-07-16

2020-07-16

作者: 细雨么么 | 来源:发表于2020-07-16 15:13 被阅读0次


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

相关文章

网友评论

      本文标题:2020-07-16

      本文链接:https://www.haomeiwen.com/subject/okiphktx.html