-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
hejiajun
committed
Mar 25, 2022
1 parent
c935501
commit 1fc4ca0
Showing
7 changed files
with
79 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 68 additions & 68 deletions
136
...java/com/returntolife/jjcode/mydemolist/demo/function/AspectButton/SingleClickAspect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,68 @@ | ||
package com.returntolife.jjcode.mydemolist.demo.function.AspectButton; | ||
|
||
import android.view.View; | ||
|
||
import com.tools.jj.tools.utils.LogUtil; | ||
|
||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.aspectj.lang.annotation.Around; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.aspectj.lang.annotation.Pointcut; | ||
import org.aspectj.lang.reflect.MethodSignature; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
/** | ||
* Created by HeJiaJun on 2019/6/25. | ||
* Email:455hejiajun@gmail | ||
* des: | ||
*/ | ||
@Aspect | ||
public class SingleClickAspect { | ||
private static final long DEFAULT_TIME_INTERVAL = 5000; | ||
|
||
/** | ||
* 定义切点,标记切点为所有被@SingleClick注解的方法 | ||
* 注意:这里me.baron.test.annotation.SingleClick需要替换成 | ||
* 你自己项目中SingleClick这个类的全路径哦 | ||
*/ | ||
@Pointcut("execution(@com.returntolife.jjcode.mydemolist.demo.function.AspectButton.SingleClick * *(..))") | ||
public void methodAnnotated() {} | ||
|
||
|
||
@Around("execution(* com.returntolife.jjcode.mydemolist.demo.function.AspectButton.AspectButtonActivity.test())") | ||
public void noParam(ProceedingJoinPoint joinPoint) throws Throwable{ | ||
//joinPoint.proceed(); //方法继续执行 | ||
} | ||
|
||
/** | ||
* 定义一个切面方法,包裹切点方法 | ||
*/ | ||
@Around("methodAnnotated()") | ||
public void aroundJoinPoint(ProceedingJoinPoint joinPoint) throws Throwable { | ||
// 取出方法的参数 | ||
View view = null; | ||
for (Object arg : joinPoint.getArgs()) { | ||
if (arg instanceof View) { | ||
view = (View) arg; | ||
break; | ||
} | ||
} | ||
if (view == null) { | ||
return; | ||
} | ||
// 取出方法的注解 | ||
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature(); | ||
Method method = methodSignature.getMethod(); | ||
if (!method.isAnnotationPresent(SingleClick.class)) { | ||
return; | ||
} | ||
SingleClick singleClick = method.getAnnotation(SingleClick.class); | ||
LogUtil.d("singleClick="+singleClick.value()); | ||
// 判断是否快速点击 | ||
if (!XClickUtil.isFastDoubleClick(view, singleClick.value())) { | ||
// 不是快速点击,执行原方法 | ||
joinPoint.proceed(); | ||
} | ||
} | ||
} | ||
//package com.returntolife.jjcode.mydemolist.demo.function.AspectButton; | ||
// | ||
//import android.view.View; | ||
// | ||
//import com.tools.jj.tools.utils.LogUtil; | ||
// | ||
//import org.aspectj.lang.ProceedingJoinPoint; | ||
//import org.aspectj.lang.annotation.Around; | ||
//import org.aspectj.lang.annotation.Aspect; | ||
//import org.aspectj.lang.annotation.Pointcut; | ||
//import org.aspectj.lang.reflect.MethodSignature; | ||
// | ||
//import java.lang.reflect.Method; | ||
// | ||
///** | ||
// * Created by HeJiaJun on 2019/6/25. | ||
// * Email:455hejiajun@gmail | ||
// * des: | ||
// */ | ||
//@Aspect | ||
//public class SingleClickAspect { | ||
// private static final long DEFAULT_TIME_INTERVAL = 5000; | ||
// | ||
// /** | ||
// * 定义切点,标记切点为所有被@SingleClick注解的方法 | ||
// * 注意:这里me.baron.test.annotation.SingleClick需要替换成 | ||
// * 你自己项目中SingleClick这个类的全路径哦 | ||
// */ | ||
// @Pointcut("execution(@com.returntolife.jjcode.mydemolist.demo.function.AspectButton.SingleClick * *(..))") | ||
// public void methodAnnotated() {} | ||
// | ||
// | ||
// @Around("execution(* com.returntolife.jjcode.mydemolist.demo.function.AspectButton.AspectButtonActivity.test())") | ||
// public void noParam(ProceedingJoinPoint joinPoint) throws Throwable{ | ||
// //joinPoint.proceed(); //方法继续执行 | ||
// } | ||
// | ||
// /** | ||
// * 定义一个切面方法,包裹切点方法 | ||
// */ | ||
// @Around("methodAnnotated()") | ||
// public void aroundJoinPoint(ProceedingJoinPoint joinPoint) throws Throwable { | ||
// // 取出方法的参数 | ||
// View view = null; | ||
// for (Object arg : joinPoint.getArgs()) { | ||
// if (arg instanceof View) { | ||
// view = (View) arg; | ||
// break; | ||
// } | ||
// } | ||
// if (view == null) { | ||
// return; | ||
// } | ||
// // 取出方法的注解 | ||
// MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature(); | ||
// Method method = methodSignature.getMethod(); | ||
// if (!method.isAnnotationPresent(SingleClick.class)) { | ||
// return; | ||
// } | ||
// SingleClick singleClick = method.getAnnotation(SingleClick.class); | ||
// LogUtil.d("singleClick="+singleClick.value()); | ||
// // 判断是否快速点击 | ||
// if (!XClickUtil.isFastDoubleClick(view, singleClick.value())) { | ||
// // 不是快速点击,执行原方法 | ||
// joinPoint.proceed(); | ||
// } | ||
// } | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters