AOP即Aspect Oriented Programming的缩写,习惯称为切面编程;与OOP(面向对象编程)万物模块化的思想不同,AOP则是将涉及到众多模块的某一类问题进行统一管理,AOP的优点是将业务逻辑与系统化功能高度解耦,让我们在开发过程中可以只专注于业务逻辑,其他一些系统化功能(如路由、日志、权限控制、拦截器、埋点、事
件防抖等)则由AOP统一处理;
集成
//root gradledependencies {classpath 'com.hujiang.aspectjx:gradle-android-plugin-aspectjx:2.0.1'}//app或module gradle
apply plugin: 'android-aspectjx' //插件compile 'org.aspectj:aspectjrt:1.8.9' //jar
代码
public class NoDoubleClickUtils {private final static int SPACE_TIME = 500;//2次点击的间隔时间,单位msprivate static long lastClickTime;public synchronized static boolean isDoubleClick() {long currentTime = System.currentTimeMillis();boolean isClick;if (currentTime - lastClickTime > SPACE_TIME) {isClick = false;} else {isClick = true;}lastClickTime = currentTime;return isClick;} }@Aspect public class AspectTest {final String TAG = AspectTest.class.getSimpleName();@Around("execution(* android.view.View.OnClickListener.onClick(..))")public void onClickLitener(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {Log.e(TAG, "OnClick");if (!NoDoubleClickUtils.isDoubleClick()) {proceedingJoinPoint.proceed();}} }
这样就能hook到所有onClick多次重复点击的问题了,有效防止连续点击
(非原创,只为记录问题,以供以后查看)