├── .gitignore
├── .idea
├── codeStyles
│ └── Project.xml
├── encodings.xml
├── gradle.xml
├── misc.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── zj
│ │ └── it
│ │ └── bhne
│ │ └── androidaop
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── zj
│ │ │ └── it
│ │ │ └── bhne
│ │ │ └── androidaop
│ │ │ ├── Main2Activity.java
│ │ │ ├── MainActivity.kt
│ │ │ └── OnClick.kt
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ └── activity_main2.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── zj
│ └── it
│ └── bhne
│ └── androidaop
│ └── ExampleUnitTest.kt
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
├── singclick
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── zj
│ │ └── singclick
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── zj
│ │ │ └── singclick
│ │ │ ├── OnClick.kt
│ │ │ ├── SingleClick.java
│ │ │ ├── SingleClickAspect.java
│ │ │ └── XClickUtil.java
│ └── res
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── zj
│ └── singclick
│ └── ExampleUnitTest.java
└── test
├── .gitignore
├── build.gradle
├── consumer-rules.pro
├── proguard-rules.pro
└── src
├── androidTest
└── java
│ └── com
│ └── zj
│ └── test
│ └── ExampleInstrumentedTest.kt
├── main
├── AndroidManifest.xml
├── java
│ └── com
│ │ └── zj
│ │ └── test
│ │ ├── TestActivity.kt
│ │ └── reified.kt
└── res
│ ├── layout
│ └── activity_test.xml
│ └── values
│ └── strings.xml
└── test
└── java
└── com
└── zj
└── test
└── ExampleUnitTest.kt
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/libraries
5 | /.idea/modules.xml
6 | /.idea/workspace.xml
7 | .DS_Store
8 | /build
9 | /captures
10 | .externalNativeBuild
11 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | xmlns:android
14 |
15 | ^$
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | xmlns:.*
25 |
26 | ^$
27 |
28 |
29 | BY_NAME
30 |
31 |
32 |
33 |
34 |
35 |
36 | .*:id
37 |
38 | http://schemas.android.com/apk/res/android
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | .*:name
48 |
49 | http://schemas.android.com/apk/res/android
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 | name
59 |
60 | ^$
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | style
70 |
71 | ^$
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 | .*
81 |
82 | ^$
83 |
84 |
85 | BY_NAME
86 |
87 |
88 |
89 |
90 |
91 |
92 | .*
93 |
94 | http://schemas.android.com/apk/res/android
95 |
96 |
97 | ANDROID_ATTRIBUTE_ORDER
98 |
99 |
100 |
101 |
102 |
103 |
104 | .*
105 |
106 | .*
107 |
108 |
109 | BY_NAME
110 |
111 |
112 |
113 |
114 |
115 |
116 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AndroidAOP
2 |
3 | > AOP的方式实现防止按钮多次点击,Java和Kotlin都能使用。
4 |
5 | 使用方法很简单,需要几步配置,配置完成之后直接添加注解即可使用,下面是配置方法:
6 |
7 | ## 引入
8 |
9 | 1. 在项目的`build.gradle`中的`buildscript`中的`dependencies`添加:
10 |
11 | ```
12 | dependencies {
13 | ...
14 | classpath 'com.hujiang.aspectjx:gradle-android-plugin-aspectjx:2.0.10'
15 | }
16 | ```
17 |
18 | 2. 在项目的`build.gradle`中的`allprojects`中的`repositories`添加:
19 |
20 | ```
21 | allprojects {
22 | repositories {
23 | ...
24 | maven { url 'https://jitpack.io' }
25 | }
26 | }
27 | ```
28 |
29 | 3. 在`app`的`build.gradle`中的最上面添加
30 |
31 | ```
32 | apply plugin: 'android-aspectjx'
33 | ```
34 |
35 | 4. 在`app`的`build.gradle`中的`dependencies`添加
36 | [](https://jitpack.io/#zhujiang521/AndroidAOP)
37 |
38 | ```
39 | implementation 'com.github.zhujiang521:AndroidAOP:1.1.1'
40 | ```
41 |
42 | ## 使用方法
43 |
44 | 直接在按钮的点击事件上面添加注解即可使用。
45 |
46 | 在`Java`中:
47 |
48 | ```
49 | @SingleClick
50 | @Override
51 | public void onClick(View v) {
52 | switch (v.getId()) {
53 | case R.id.btnClick2:
54 | ToastUtils.showShort("哈哈哈");
55 | Log.e("刘沛星","wwww");
56 | break;
57 | }
58 | }
59 | ```
60 |
61 | 在`Kotlin`中:
62 |
63 | ```
64 | @SingleClick
65 | override fun onClick(v: View?) {
66 | if (v != null) {
67 | when(v.id){
68 | R.id.btnClick ->{
69 | ToastUtils.showShort("哈哈哈")
70 | Log.e("刘沛星","wwww")
71 | }
72 | }
73 | }
74 | }
75 | ```
76 |
77 | 默认间隔时间为`1500`毫秒,可以自行修改,在注解后面添加括号,在括号中声明需要的时间值即可。
78 |
79 | ```
80 | @SingleClick(1000)
81 | override fun onClick(v: View?) {
82 | if (v != null) {
83 | when(v.id){
84 | R.id.btnClick ->{
85 | ToastUtils.showShort("哈哈哈")
86 | Log.e("刘沛星","wwww")
87 | }
88 | }
89 | }
90 | }
91 | ```
92 |
93 | OK。
94 |
95 | 新增了`Kotlin`的判断重复的方法,大家可以按照下面的方法直接进行调用,比写注解更加灵活方便:
96 |
97 | ```
98 | btnKuoZhan.setSafeListener {
99 | ToastUtils.showShort("222")
100 | Log.e("kuozhan","wwww")
101 | }
102 | ```
103 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | apply plugin: 'kotlin-android'
4 |
5 | apply plugin: 'kotlin-android-extensions'
6 |
7 | apply plugin: 'android-aspectjx'
8 | android {
9 | compileSdkVersion 29
10 | defaultConfig {
11 | applicationId "zj.it.bhne.androidaop"
12 | minSdkVersion 21
13 | targetSdkVersion 29
14 | versionCode 1
15 | versionName "1.0"
16 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
17 | }
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 | compileOptions {
25 | sourceCompatibility JavaVersion.VERSION_1_8
26 | targetCompatibility JavaVersion.VERSION_1_8
27 | }
28 |
29 | }
30 |
31 | dependencies {
32 | implementation fileTree(dir: 'libs', include: ['*.jar'])
33 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
34 | //noinspection GradleCompatible
35 | implementation 'com.android.support:appcompat-v7:28.0.0'
36 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
37 |
38 | //安卓Utils
39 | implementation 'com.blankj:utilcode:1.23.6'
40 |
41 | testImplementation 'junit:junit:4.12'
42 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
43 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
44 | implementation project(path: ':singclick')
45 | implementation project(path: ':test')
46 | }
47 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/zj/it/bhne/androidaop/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package zj.it.bhne.androidaop
2 |
3 | import android.support.test.InstrumentationRegistry
4 | import android.support.test.runner.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getTargetContext()
22 | assertEquals("zj.it.bhne.androidaop", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/java/zj/it/bhne/androidaop/Main2Activity.java:
--------------------------------------------------------------------------------
1 | package zj.it.bhne.androidaop;
2 |
3 | import android.app.ProgressDialog;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.util.Log;
7 | import android.view.View;
8 | import android.widget.Button;
9 |
10 | import androidx.appcompat.app.AppCompatActivity;
11 |
12 | import com.blankj.utilcode.util.ToastUtils;
13 | import com.zj.singclick.SingleClick;
14 | import com.zj.test.TestActivity;
15 |
16 |
17 | public class Main2Activity extends AppCompatActivity{
18 |
19 | private final static String TAG = "Main2Activity";
20 | //全局定义
21 | private long lastClickTime = 0L;
22 | // 两次点击间隔不能少于1000ms
23 | private static final int FAST_CLICK_DELAY_TIME = 1000;
24 |
25 |
26 | @Override
27 | protected void onCreate(Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 | setContentView(R.layout.activity_main2);
30 | }
31 |
32 | /**
33 | * 弹窗等待
34 | *
35 | * @param view /
36 | */
37 | public void btnDialog(View view) {
38 | ProgressDialog progressDialog = new ProgressDialog(this);
39 | progressDialog.setTitle("等待");
40 | progressDialog.setMessage("等待内容");
41 | progressDialog.setCanceledOnTouchOutside(false);
42 | progressDialog.show();
43 |
44 | }
45 |
46 | public void btnStop(View view) {
47 | startActivity(new Intent(this, TestActivity.class));
48 | }
49 |
50 | public void btnInter(View view) {
51 | if (System.currentTimeMillis() - lastClickTime >= FAST_CLICK_DELAY_TIME) {
52 | lastClickTime = System.currentTimeMillis();
53 | }
54 | }
55 |
56 | @SingleClick(2000)
57 | public void btnAop(View view) {
58 | ToastUtils.showShort("btnAop");
59 | Log.e(TAG, "btnAop");
60 | }
61 |
62 | public void btnKotlin(View view) {
63 | startActivity(new Intent(this,MainActivity.class));
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/app/src/main/java/zj/it/bhne/androidaop/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package zj.it.bhne.androidaop
2 |
3 | import android.os.Bundle
4 |
5 | import android.util.Log
6 | import android.view.View
7 | import androidx.appcompat.app.AppCompatActivity
8 | import com.blankj.utilcode.util.ToastUtils
9 | import com.zj.singclick.SingleClick
10 | import com.zj.singclick.click
11 | import com.zj.singclick.setSafeListener
12 | import kotlinx.android.synthetic.main.activity_main.*
13 |
14 | class MainActivity : AppCompatActivity() ,View.OnClickListener{
15 |
16 |
17 | override fun onCreate(savedInstanceState: Bundle?){
18 | super.onCreate(savedInstanceState)
19 | setContentView(R.layout.activity_main)
20 | btnClick.setOnClickListener(this)
21 | initView()
22 | }
23 |
24 | private fun initView() {
25 | btnKuoZhan.setSafeListener {
26 | ToastUtils.showShort("222")
27 | Log.e("kuozhan","wwww")
28 | }
29 |
30 | btnKuoZhanClick.click {
31 | ToastUtils.showShort("ss")
32 | Log.e("kuozhan","呵呵呵")
33 | }
34 | }
35 |
36 |
37 | @SingleClick
38 | override fun onClick(v: View?) {
39 | if (v != null) {
40 | when(v.id){
41 | R.id.btnClick->{
42 | ToastUtils.showShort("哈哈哈")
43 | Log.e("ee","wwww")
44 | }
45 | }
46 | }
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/app/src/main/java/zj/it/bhne/androidaop/OnClick.kt:
--------------------------------------------------------------------------------
1 | package zj.it.bhne.androidaop
2 |
3 | import android.view.View
4 |
5 | /**
6 | * 版权:渤海新能 版权所有
7 | * @author zhujiang
8 | * 版本:1.5
9 | * 创建日期:2020/4/29
10 | * 描述:AndroidAOP
11 | *
12 | */
13 |
14 | //inline fun View.setSafeListener(crossinline action:()->Unit){
15 | // var lastClick=0L
16 | // setOnClickListener {
17 | // val gap = System.currentTimeMillis() - lastClick
18 | // lastClick=System.currentTimeMillis()
19 | // if(gap<1500) return@setOnClickListener
20 | // action.invoke()
21 | // }
22 | //}
23 | //
24 | //
25 | //var _viewClickFlag = false
26 | //var _clickRunnable = Runnable { _viewClickFlag = false }
27 | //fun View.click(action: (view: View) -> Unit) {
28 | // setOnClickListener {
29 | // if (!_viewClickFlag) {
30 | // _viewClickFlag = true
31 | // action(it)
32 | // }
33 | // removeCallbacks(_clickRunnable)
34 | // postDelayed(_clickRunnable, 1000)
35 | // }
36 | //}
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
19 |
20 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main2.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
15 |
22 |
23 |
30 |
31 |
38 |
39 |
46 |
47 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhujiang521/AndroidAOP/0794b06547edb90afb464704f4d84b7412e6c214/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhujiang521/AndroidAOP/0794b06547edb90afb464704f4d84b7412e6c214/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhujiang521/AndroidAOP/0794b06547edb90afb464704f4d84b7412e6c214/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhujiang521/AndroidAOP/0794b06547edb90afb464704f4d84b7412e6c214/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhujiang521/AndroidAOP/0794b06547edb90afb464704f4d84b7412e6c214/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhujiang521/AndroidAOP/0794b06547edb90afb464704f4d84b7412e6c214/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhujiang521/AndroidAOP/0794b06547edb90afb464704f4d84b7412e6c214/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhujiang521/AndroidAOP/0794b06547edb90afb464704f4d84b7412e6c214/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhujiang521/AndroidAOP/0794b06547edb90afb464704f4d84b7412e6c214/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhujiang521/AndroidAOP/0794b06547edb90afb464704f4d84b7412e6c214/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AndroidAOP
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/zj/it/bhne/androidaop/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package zj.it.bhne.androidaop
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | ext.kotlin_version = '1.3.72'
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.6.3'
11 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
12 | classpath 'com.hujiang.aspectjx:gradle-android-plugin-aspectjx:2.0.10'
13 |
14 | // NOTE: Do not place your application dependencies here; they belong
15 | // in the individual module build.gradle files
16 | }
17 | }
18 |
19 | allprojects {
20 | repositories {
21 | google()
22 | jcenter()
23 | }
24 | }
25 |
26 | task clean(type: Delete) {
27 | delete rootProject.buildDir
28 | }
29 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhujiang521/AndroidAOP/0794b06547edb90afb464704f4d84b7412e6c214/gradle.properties
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhujiang521/AndroidAOP/0794b06547edb90afb464704f4d84b7412e6c214/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Apr 29 11:21:21 CST 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':singclick'
2 | include ':test'
3 |
--------------------------------------------------------------------------------
/singclick/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/singclick/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 | apply plugin: 'android-aspectjx'
5 | android {
6 | compileSdkVersion 28
7 |
8 |
9 | defaultConfig {
10 | minSdkVersion 21
11 | targetSdkVersion 28
12 | versionCode 1
13 | versionName "1.0"
14 |
15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16 |
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 |
26 | }
27 |
28 | dependencies {
29 | implementation fileTree(dir: 'libs', include: ['*.jar'])
30 |
31 | implementation 'com.android.support:appcompat-v7:28.0.0'
32 | api 'org.aspectj:aspectjrt:1.9.5'
33 | testImplementation 'junit:junit:4.13'
34 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
35 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
36 | implementation "androidx.core:core-ktx:1.2.0"
37 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
38 | }
39 | repositories {
40 | mavenCentral()
41 | }
42 |
--------------------------------------------------------------------------------
/singclick/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/singclick/src/androidTest/java/com/zj/singclick/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.zj.singclick;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.zj.singclick.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/singclick/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/singclick/src/main/java/com/zj/singclick/OnClick.kt:
--------------------------------------------------------------------------------
1 | package com.zj.singclick
2 |
3 | import android.view.View
4 |
5 | /**
6 | * 版权:渤海新能 版权所有
7 | * @author zhujiang
8 | * 版本:1.5
9 | * 创建日期:2020/4/29
10 | * 描述:AndroidAOP
11 | *
12 | */
13 |
14 |
15 | inline fun View.setSafeListener(crossinline action:()->Unit){
16 | var lastClick=0L
17 | setOnClickListener {
18 | val gap = System.currentTimeMillis() - lastClick
19 | lastClick=System.currentTimeMillis()
20 | if(gap<1500) return@setOnClickListener
21 | action.invoke()
22 | }
23 | }
24 |
25 |
26 | var _viewClickFlag = false
27 | var _clickRunnable = Runnable { _viewClickFlag = false }
28 | fun View.click(action: (view: View) -> Unit) {
29 | setOnClickListener {
30 | if (!_viewClickFlag) {
31 | _viewClickFlag = true
32 | action(it)
33 | }
34 | removeCallbacks(_clickRunnable)
35 | postDelayed(_clickRunnable, 1000)
36 | }
37 | }
--------------------------------------------------------------------------------
/singclick/src/main/java/com/zj/singclick/SingleClick.java:
--------------------------------------------------------------------------------
1 | package com.zj.singclick;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * 实现防止按钮连续点击
10 | * @author jiang zhu on 2019/4/19
11 | */
12 | @Retention(RetentionPolicy.RUNTIME)
13 | @Target(ElementType.METHOD)
14 | public @interface SingleClick {
15 | /* 点击间隔时间 */
16 | long value() default 1500;
17 | }
--------------------------------------------------------------------------------
/singclick/src/main/java/com/zj/singclick/SingleClickAspect.java:
--------------------------------------------------------------------------------
1 | package com.zj.singclick;
2 |
3 | import android.view.View;
4 |
5 | import org.aspectj.lang.ProceedingJoinPoint;
6 | import org.aspectj.lang.annotation.Around;
7 | import org.aspectj.lang.annotation.Aspect;
8 | import org.aspectj.lang.annotation.Pointcut;
9 | import org.aspectj.lang.reflect.MethodSignature;
10 |
11 | import java.lang.reflect.Method;
12 |
13 | /**
14 | * 实现防止按钮连续点击
15 | * @author jiang zhu on 2019/4/19
16 | */
17 | @Aspect
18 | public class SingleClickAspect {
19 | private static final long DEFAULT_TIME_INTERVAL = 5000;
20 |
21 | /**
22 | * 定义切点,标记切点为所有被@SingleClick注解的方法
23 | * com.zj.singclick.SingleClick需要替换成
24 | * 自己项目中SingleClick这个类的全路径哦
25 | */
26 | @Pointcut("execution(@com.zj.singclick.SingleClick * *(..))")
27 | public void methodAnnotated() {}
28 |
29 | /**
30 | * 定义一个切面方法,包裹切点方法
31 | */
32 | @Around("methodAnnotated()")
33 | public void aroundJoinPoint(ProceedingJoinPoint joinPoint) throws Throwable {
34 | // 取出方法的参数
35 | View view = null;
36 | for (Object arg : joinPoint.getArgs()) {
37 | if (arg instanceof View) {
38 | view = (View) arg;
39 | break;
40 | }
41 | }
42 | if (view == null) {
43 | return;
44 | }
45 | // 取出方法的注解
46 | MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
47 | Method method = methodSignature.getMethod();
48 | if (!method.isAnnotationPresent(SingleClick.class)) {
49 | return;
50 | }
51 | SingleClick singleClick = method.getAnnotation(SingleClick.class);
52 | // 判断是否快速点击
53 | if (!XClickUtil.isFastDoubleClick(view, singleClick.value())) {
54 | // 不是快速点击,执行原方法
55 | joinPoint.proceed();
56 | }
57 | }
58 | }
--------------------------------------------------------------------------------
/singclick/src/main/java/com/zj/singclick/XClickUtil.java:
--------------------------------------------------------------------------------
1 | package com.zj.singclick;
2 |
3 | import android.view.View;
4 |
5 | /**
6 | * @author jiang zhu on 2019/4/19
7 | */
8 | public final class XClickUtil {
9 |
10 | /**
11 | * 最近一次点击的时间
12 | */
13 | private static long mLastClickTime;
14 | /**
15 | * 最近一次点击的控件ID
16 | */
17 | private static int mLastClickViewId;
18 |
19 | /**
20 | * 是否是快速点击
21 | *
22 | * @param v 点击的控件
23 | * @param intervalMillis 时间间期(毫秒)
24 | * @return true:是,false:不是
25 | */
26 | public static boolean isFastDoubleClick(View v, long intervalMillis) {
27 | int viewId = v.getId();
28 | long time = System.currentTimeMillis();
29 | long timeInterval = Math.abs(time - mLastClickTime);
30 | if (timeInterval < intervalMillis && viewId == mLastClickViewId) {
31 | return true;
32 | } else {
33 | mLastClickTime = time;
34 | mLastClickViewId = viewId;
35 | return false;
36 | }
37 | }
38 | }
--------------------------------------------------------------------------------
/singclick/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | SingClick
3 |
4 |
--------------------------------------------------------------------------------
/singclick/src/test/java/com/zj/singclick/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.zj.singclick;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/test/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/test/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 |
5 | android {
6 | compileSdkVersion 29
7 | buildToolsVersion "29.0.3"
8 |
9 | defaultConfig {
10 | minSdkVersion 21
11 | targetSdkVersion 29
12 | versionCode 1
13 | versionName "1.0"
14 |
15 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16 | consumerProguardFiles 'consumer-rules.pro'
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 |
26 | }
27 |
28 | dependencies {
29 | implementation fileTree(dir: 'libs', include: ['*.jar'])
30 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
31 | implementation 'androidx.appcompat:appcompat:1.1.0'
32 | implementation 'androidx.core:core-ktx:1.2.0'
33 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
34 | testImplementation 'junit:junit:4.12'
35 | androidTestImplementation 'androidx.test.ext:junit:1.1.1'
36 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
37 | implementation project(path: ':singclick')
38 | }
39 |
--------------------------------------------------------------------------------
/test/consumer-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhujiang521/AndroidAOP/0794b06547edb90afb464704f4d84b7412e6c214/test/consumer-rules.pro
--------------------------------------------------------------------------------
/test/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/test/src/androidTest/java/com/zj/test/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.zj.test
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.zj.test.test", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/test/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/test/src/main/java/com/zj/test/TestActivity.kt:
--------------------------------------------------------------------------------
1 | package com.zj.test
2 |
3 | import androidx.appcompat.app.AppCompatActivity
4 | import android.os.Bundle
5 | import android.util.Log
6 | import android.view.View
7 | import android.widget.Toast
8 | import com.zj.singclick.SingleClick
9 | import kotlinx.android.synthetic.main.activity_test.*
10 |
11 | class TestActivity : AppCompatActivity(), View.OnClickListener {
12 |
13 | override fun onCreate(savedInstanceState: Bundle?) {
14 | super.onCreate(savedInstanceState)
15 | setContentView(R.layout.activity_test)
16 | btnTest.setOnClickListener(this)
17 | }
18 |
19 | @SingleClick
20 | override fun onClick(v: View) {
21 | Toast.makeText(this,"测试",Toast.LENGTH_SHORT).show()
22 | Log.e("测试时","cee")
23 | //startActivity(this){}
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/test/src/main/java/com/zj/test/reified.kt:
--------------------------------------------------------------------------------
1 | package com.zj.test
2 |
3 | import android.content.Context
4 | import android.content.Intent
5 |
6 | /**
7 | * 版权:渤海新能 版权所有
8 | * @author zhujiang
9 | * 版本:1.5
10 | * 创建日期:2020/4/27
11 | * 描述:AndroidAOP
12 | *
13 | */
14 |
15 | inline fun startActivity(context: Context,block: Intent.() -> Unit){
16 | val intent = Intent(context, T::class.java)
17 | intent.block()
18 | context.startActivity(intent)
19 | }
--------------------------------------------------------------------------------
/test/src/main/res/layout/activity_test.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
--------------------------------------------------------------------------------
/test/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/src/test/java/com/zj/test/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.zj.test
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------