├── .gitignore
├── .idea
├── $CACHE_FILE$
├── checkstyle-idea.xml
├── codeStyles
│ └── Project.xml
├── encodings.xml
├── gradle.xml
├── jarRepositories.xml
├── misc.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── example
│ │ └── aop2
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── example
│ │ │ └── aop2
│ │ │ ├── Animal.java
│ │ │ └── MainActivity.java
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ ├── dialog.xml
│ │ └── simple_list_item.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
│ └── com
│ └── example
│ └── aop2
│ └── ExampleUnitTest.java
├── aspectj
├── .gitignore
├── build.gradle
├── consumer-rules.pro
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── example
│ │ └── aspectj
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ └── java
│ │ └── com
│ │ └── example
│ │ └── aspectj
│ │ ├── HookAddOnScrollListenerHelper.java
│ │ ├── HookOnClickListener.java
│ │ ├── HookRecyclerViewOnBindViewHolder.java
│ │ ├── HookTextChangedListener.java
│ │ ├── SuperClassReflectionUtils.java
│ │ ├── Tracker.java
│ │ ├── TrackerAspect.java
│ │ ├── ViewAspect.java
│ │ └── ViewPath.java
│ └── test
│ └── java
│ └── com
│ └── example
│ └── aspectj
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 |
--------------------------------------------------------------------------------
/.idea/$CACHE_FILE$:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | Abstraction issuesJava
10 |
11 |
12 | Android
13 |
14 |
15 | Code style issuesJava
16 |
17 |
18 | Compiler issuesJava
19 |
20 |
21 | CorrectnessLintAndroid
22 |
23 |
24 | Declaration redundancyJava
25 |
26 |
27 | GPathGroovy
28 |
29 |
30 | Groovy
31 |
32 |
33 | IconsUsabilityLintAndroid
34 |
35 |
36 | Inheritance issuesJava
37 |
38 |
39 | Java
40 |
41 |
42 | Java 9Java language level migration aidsJava
43 |
44 |
45 | Java language level migration aidsJava
46 |
47 |
48 | Kotlin
49 |
50 |
51 | LintAndroid
52 |
53 |
54 | Other problemsKotlin
55 |
56 |
57 | PerformanceJava
58 |
59 |
60 | PerformanceLintAndroid
61 |
62 |
63 | Potentially confusing code constructsGroovy
64 |
65 |
66 | Probable bugsJava
67 |
68 |
69 | Serialization issuesJava
70 |
71 |
72 | Style issuesKotlin
73 |
74 |
75 | UsabilityLintAndroid
76 |
77 |
78 |
79 |
80 | Android
81 |
82 |
83 |
84 |
85 |
86 |
--------------------------------------------------------------------------------
/.idea/checkstyle-idea.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
15 |
16 |
--------------------------------------------------------------------------------
/.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 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/jarRepositories.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 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.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 | ## 插件使用
2 | 1. 在项目根目录的build.gradle里依赖AspectJX
3 | ```
4 | dependencies {
5 | classpath 'com.hujiang.aspectjx:gradle-android-plugin-aspectjx:2.0.10'
6 | // 如果build:gradle在3.6.0以下,使用2.0.8版本
7 | }
8 | ```
9 | 2. 在app目录的build.gradle里添加Aspectj的插件
10 | `apply plugin: 'android-aspectjx'`
11 | 3. 在app目录的build.gradle里去掉不必要侵入的类
12 | 不去掉可能会导致 java.util.zip.ZipException: zip file is empty 或者 classNotDefFoundException
13 | ```
14 | aspectjx{
15 | exclude 'com.google','com.squareup','com.alipay','org.apache'
16 | }
17 | ```
18 | 4. 如果你使用得分组件时androidx版本则用master分支,否则使用support分支
19 | ## 文章介绍
20 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'android-aspectjx'
3 | android {
4 | compileSdkVersion 29
5 | buildToolsVersion "29.0.3"
6 |
7 | defaultConfig {
8 | applicationId "com.example.aop2"
9 | minSdkVersion 24
10 | targetSdkVersion 29
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
15 | }
16 |
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | }
24 |
25 | dependencies {
26 | implementation fileTree(dir: "libs", include: ["*.jar"])
27 | implementation 'androidx.appcompat:appcompat:1.1.0'
28 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
29 | implementation 'androidx.recyclerview:recyclerview:1.1.0'
30 | testImplementation 'junit:junit:4.12'
31 | androidTestImplementation 'androidx.test.ext:junit:1.1.1'
32 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
33 | implementation project(':aspectj')
34 | }
--------------------------------------------------------------------------------
/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
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/example/aop2/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.example.aop2;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.platform.app.InstrumentationRegistry;
6 | import androidx.test.ext.junit.runners.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24 | assertEquals("com.example.aop2", appContext.getPackageName());
25 | }
26 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/aop2/Animal.java:
--------------------------------------------------------------------------------
1 | package com.example.aop2;
2 |
3 | import android.util.Log;
4 |
5 | /**
6 | * @author youer
7 | * @date 2020/8/7
8 | */
9 | public class Animal {
10 | private static final String TAG = "Animal";
11 |
12 | public void fly() {
13 | Log.e(TAG, "animal fly method:" + this.toString() + "#fly");
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/aop2/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.aop2;
2 |
3 | import android.app.Dialog;
4 | import android.os.Bundle;
5 | import android.os.Handler;
6 | import android.text.Editable;
7 | import android.text.TextWatcher;
8 | import android.util.Log;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.widget.EditText;
13 | import android.widget.LinearLayout;
14 | import android.widget.PopupWindow;
15 | import android.widget.TextView;
16 |
17 | import androidx.annotation.NonNull;
18 | import androidx.appcompat.app.AppCompatActivity;
19 | import androidx.recyclerview.widget.LinearLayoutManager;
20 | import androidx.recyclerview.widget.RecyclerView;
21 |
22 | public class MainActivity extends AppCompatActivity {
23 | private static final String TAG = "MainActivity";
24 |
25 | @Override
26 | protected void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.activity_main);
29 |
30 | Animal animal = new Animal();
31 | Log.d(TAG, " onCreate fly start...");
32 | animal.fly();
33 |
34 | // ViewGroup viewGroup = (ViewGroup)findViewById(ID_ANDROID_CONTENT);
35 | // viewGroup.getChildCount();
36 | // TextView textView = findViewById(R.id.text);
37 | // textView.setOnClickListener(new View.OnClickListener() {
38 | // @Override
39 | // public void onClick(View v) {
40 | //
41 | // }
42 | // });
43 |
44 | // textView.setOnClickListener(new View.OnClickListener() {
45 | // @Override
46 | // public void onClick(View v) {
47 | // Log.d(TAG, "onClick: ");
48 | // }
49 | // });
50 | //
51 | // textView.setOnLongClickListener(new View.OnLongClickListener() {
52 | // @Override
53 | // public boolean onLongClick(View v) {
54 | // return false;
55 | // }
56 | // });
57 | View contentView = LayoutInflater.from(MainActivity.this).inflate(R.layout.dialog, null);
58 | final PopupWindow popWnd = new PopupWindow(this);
59 | popWnd.setContentView(contentView);
60 |
61 | EditText editText = findViewById(R.id.edit);
62 | editText.addTextChangedListener(new TextWatcher() {
63 | @Override
64 | public void beforeTextChanged(CharSequence s, int start, int count, int after) {
65 |
66 | }
67 |
68 | @Override
69 | public void onTextChanged(CharSequence s, int start, int before, int count) {
70 | Log.d(TAG, "onTextChanged: " + s.toString());
71 | }
72 |
73 | @Override
74 | public void afterTextChanged(Editable s) {
75 |
76 | }
77 | });
78 |
79 | RecyclerView recyclerView = findViewById(R.id.list);
80 | recyclerView.setAdapter(new RecyclerViewAdapter());
81 | recyclerView.setLayoutManager(new LinearLayoutManager(this));
82 | recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
83 | @Override
84 | public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
85 | super.onScrollStateChanged(recyclerView, newState);
86 | }
87 |
88 | @Override
89 | public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
90 | super.onScrolled(recyclerView, dx, dy);
91 | Log.d(TAG, "onScrolled: dx--" + dx + ";dy--" + dy);
92 | }
93 | });
94 |
95 | final TextView title = findViewById(R.id.title);
96 | new Handler().postDelayed(new Runnable() {
97 | @Override
98 | public void run() {
99 | Log.d(TAG, "run: ");
100 | title.setOnClickListener(new View.OnClickListener() {
101 | @Override
102 | public void onClick(View v) {
103 | Dialog dialog = new Dialog(MainActivity.this);
104 | dialog.setContentView(R.layout.dialog);
105 | dialog.show();
106 | // popWnd.showAsDropDown(title);
107 | }
108 | });
109 | }
110 | }, 1500);
111 |
112 | }
113 |
114 | private class RecyclerViewAdapter extends RecyclerView.Adapter {
115 | private static final String TAG = "RecyclerViewAdapter";
116 |
117 | @NonNull
118 | @Override
119 | public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
120 | View view = LayoutInflater.from(MainActivity.this).inflate(R.layout.simple_list_item, parent, false);
121 | Log.d(TAG, "onCreateViewHolder: ");
122 | return new ViewHolder(view);
123 | }
124 |
125 | @Override
126 | public void onBindViewHolder(ViewHolder holder, int position) {
127 | Log.d(TAG, "onBindViewHolder: ");
128 | holder.textView.setText("第" + position + "行数据");
129 | holder.textView.setOnClickListener(new View.OnClickListener() {
130 | @Override
131 | public void onClick(View v) {
132 |
133 | }
134 | });
135 | }
136 |
137 | @Override
138 | public int getItemCount() {
139 | return 10;
140 | }
141 |
142 | class ViewHolder extends RecyclerView.ViewHolder {
143 | TextView textView;
144 |
145 | private ViewHolder(View itemView) {
146 | super(itemView);
147 | textView = (TextView) itemView.findViewById(R.id.list_title);
148 | }
149 | }
150 | }
151 |
152 | public void onTestClick(View view) {
153 | // CheckBox checkBox = findViewById(R.id.checkbox);
154 | // checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
155 | // @Override
156 | // public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
157 | // Log.d(TAG, "onCheckedChanged: ");
158 | // }
159 | // });
160 |
161 | TextView textView = new TextView(this);
162 | textView.setText("sfdadasdas");
163 | textView.setOnClickListener(new View.OnClickListener() {
164 | @Override
165 | public void onClick(View v) {
166 | Log.d(TAG, "onClick: ");
167 | }
168 | });
169 | LinearLayout layout = findViewById(R.id.container);
170 | layout.addView(textView, LinearLayout.LayoutParams.WRAP_CONTENT, 200);
171 | }
172 |
173 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/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 |
9 |
10 |
15 |
16 |
20 |
21 |
25 |
26 |
30 |
31 |
37 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/simple_list_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
15 |
16 |
--------------------------------------------------------------------------------
/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/PettyWing/aop/28bf3d356531951128a7b59cbd38da8cf7316a77/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PettyWing/aop/28bf3d356531951128a7b59cbd38da8cf7316a77/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PettyWing/aop/28bf3d356531951128a7b59cbd38da8cf7316a77/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PettyWing/aop/28bf3d356531951128a7b59cbd38da8cf7316a77/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PettyWing/aop/28bf3d356531951128a7b59cbd38da8cf7316a77/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PettyWing/aop/28bf3d356531951128a7b59cbd38da8cf7316a77/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PettyWing/aop/28bf3d356531951128a7b59cbd38da8cf7316a77/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PettyWing/aop/28bf3d356531951128a7b59cbd38da8cf7316a77/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PettyWing/aop/28bf3d356531951128a7b59cbd38da8cf7316a77/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PettyWing/aop/28bf3d356531951128a7b59cbd38da8cf7316a77/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #6200EE
4 | #3700B3
5 | #03DAC5
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AOP2
3 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/test/java/com/example/aop2/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.example.aop2;
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 | }
--------------------------------------------------------------------------------
/aspectj/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/aspectj/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'android-aspectjx'
3 | android {
4 | compileSdkVersion 29
5 | buildToolsVersion "29.0.3"
6 |
7 | defaultConfig {
8 | minSdkVersion 19
9 | targetSdkVersion 29
10 | versionCode 1
11 | versionName "1.0"
12 |
13 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
14 | consumerProguardFiles "consumer-rules.pro"
15 | }
16 |
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | }
24 |
25 | aspectjx{
26 | include 'android.view.View'
27 | }
28 |
29 | dependencies {
30 | implementation fileTree(dir: "libs", include: ["*.jar"])
31 | implementation 'androidx.appcompat:appcompat:1.1.0'
32 | implementation 'androidx.recyclerview:recyclerview:1.1.0'
33 | testImplementation 'junit:junit:4.12'
34 | androidTestImplementation 'androidx.test.ext:junit:1.1.1'
35 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
36 | api 'org.aspectj:aspectjrt:1.9.5'
37 | }
--------------------------------------------------------------------------------
/aspectj/consumer-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PettyWing/aop/28bf3d356531951128a7b59cbd38da8cf7316a77/aspectj/consumer-rules.pro
--------------------------------------------------------------------------------
/aspectj/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
--------------------------------------------------------------------------------
/aspectj/src/androidTest/java/com/example/aspectj/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.example.aspectj;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.platform.app.InstrumentationRegistry;
6 | import androidx.test.ext.junit.runners.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24 | assertEquals("com.example.aspectj.test", appContext.getPackageName());
25 | }
26 | }
--------------------------------------------------------------------------------
/aspectj/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 | /
5 |
--------------------------------------------------------------------------------
/aspectj/src/main/java/com/example/aspectj/HookAddOnScrollListenerHelper.java:
--------------------------------------------------------------------------------
1 | package com.example.aspectj;
2 |
3 | import android.util.Log;
4 |
5 | import java.util.List;
6 |
7 | import androidx.annotation.NonNull;
8 | import androidx.recyclerview.widget.RecyclerView;
9 |
10 | /**
11 | * @author youer
12 | * @date 2020/8/20
13 | */
14 | public class HookAddOnScrollListenerHelper {
15 |
16 | private static final String TAG = "HookAddOnScrollListener";
17 |
18 | public static void hook(final RecyclerView recyclerView) {//
19 | List mScrollListeners = (List) SuperClassReflectionUtils.getFieldValue(recyclerView, "mScrollListeners");
20 | if (mScrollListeners != null && !mScrollListeners.isEmpty()) {
21 | for (RecyclerView.OnScrollListener listener : mScrollListeners) {
22 | // 去掉重复的滑动监听
23 | if (listener instanceof HookOnScrollListener) {
24 | return;
25 | }
26 | }
27 | }
28 | recyclerView.addOnScrollListener(new HookOnScrollListener());
29 | }
30 |
31 | static class HookOnScrollListener extends RecyclerView.OnScrollListener {
32 | private static final String TAG = "OnScrollListener";
33 | int scrollerState = 0;
34 | int scrollerX = 0;
35 | int scrollerY = 0;
36 |
37 | @Override
38 | public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
39 | super.onScrollStateChanged(recyclerView, newState);
40 | scrollerState = newState;
41 | switch (scrollerState) {
42 | case RecyclerView.SCROLL_STATE_DRAGGING:
43 | break;
44 | case RecyclerView.SCROLL_STATE_IDLE:
45 | // 当页面滚动停止的时候进行数据上报,并且置零参数1
46 | Log.d(TAG, "afterRecycleViewOnScrollStateChangedMethodCall1: " + scrollerX);
47 | Log.d(TAG, "afterRecycleViewOnScrollStateChangedMethodCall1: " + scrollerY);
48 | Log.d(TAG, "afterRecycleViewOnScrollStateChangedMethodCall getThis->" + recyclerView.getContentDescription()); //切面代码运行所在的类对象
49 | scrollerX = 0;
50 | scrollerY = 0;
51 | break;
52 | default:
53 | }
54 |
55 | }
56 |
57 | @Override
58 | public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
59 | super.onScrolled(recyclerView, dx, dy);
60 | if (scrollerState == RecyclerView.SCROLL_STATE_DRAGGING || scrollerState == RecyclerView.SCROLL_STATE_SETTLING) {
61 | scrollerX += dx;
62 | scrollerY += dy;
63 | }
64 | }
65 | }
66 | }
67 |
68 |
69 |
--------------------------------------------------------------------------------
/aspectj/src/main/java/com/example/aspectj/HookOnClickListener.java:
--------------------------------------------------------------------------------
1 | package com.example.aspectj;
2 |
3 | import android.util.Log;
4 | import android.view.View;
5 | import android.view.accessibility.AccessibilityEvent;
6 |
7 | /**
8 | * @author youer
9 | * @date 2020/8/28
10 | */
11 | public class HookOnClickListener {
12 | private static final String TAG = "HookOnClickListener";
13 |
14 | public static void hook(View view) {
15 | view.setAccessibilityDelegate(new View.AccessibilityDelegate() {
16 | @Override
17 | public void sendAccessibilityEvent(View host, int eventType) {
18 | super.sendAccessibilityEvent(host, eventType);
19 | switch (eventType) {
20 | // 页面点击
21 | case AccessibilityEvent.TYPE_VIEW_CLICKED:
22 | Log.d(TAG, "sendAccessibilityEvent: " + host.getContentDescription());
23 | break;
24 | // 页面输入
25 | // case AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED:
26 | // TrackEvent.postUTSendKey(host.getContentDescription().toString(), ((TextView) host).getText().toString());
27 | // Log.d(TAG, "postUTSendKey: " + host.getContentDescription() + "|value:" + ((TextView) host).getText().toString());
28 | // break;
29 | // 其他
30 | default:
31 | break;
32 | }
33 | }
34 | });
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/aspectj/src/main/java/com/example/aspectj/HookRecyclerViewOnBindViewHolder.java:
--------------------------------------------------------------------------------
1 | package com.example.aspectj;
2 |
3 | import android.view.ViewGroup;
4 |
5 | import java.util.List;
6 |
7 | import androidx.annotation.NonNull;
8 | import androidx.recyclerview.widget.RecyclerView;
9 |
10 | /**
11 | * @author youer
12 | * @date 2020/8/20
13 | */
14 | public class HookRecyclerViewOnBindViewHolder {
15 |
16 | private static final String TAG = "HookRecyclerViewOnBindV";
17 |
18 | public static void hook(final RecyclerView recyclerView) {
19 | RecyclerView.Adapter adapter = recyclerView.getAdapter();
20 | // TODO: 2020/8/28 做成动态代理的形式
21 | recyclerView.setAdapter(new HookAdapter(recyclerView, adapter));
22 | }
23 |
24 | static class HookAdapter extends RecyclerView.Adapter {
25 |
26 | private RecyclerView recyclerView;
27 | private RecyclerView.Adapter realAdapter;
28 |
29 | public HookAdapter(RecyclerView recyclerView, RecyclerView.Adapter realAdapter) {
30 | this.recyclerView = recyclerView;
31 | this.realAdapter = realAdapter;
32 | }
33 |
34 | @Override
35 | public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position, @NonNull List payloads) {
36 | if (realAdapter != null) {
37 | realAdapter.onBindViewHolder(holder, position, payloads);
38 | }
39 | Tracker.setViewTracker(holder.itemView, ViewPath.getPath(holder.itemView, recyclerView, position));
40 | }
41 |
42 | @Override
43 | public int getItemViewType(int position) {
44 | if (realAdapter != null) {
45 | return realAdapter.getItemViewType(position);
46 | } else {
47 | return super.getItemViewType(position);
48 | }
49 | }
50 |
51 | @Override
52 | public void setHasStableIds(boolean hasStableIds) {
53 | if (realAdapter != null) {
54 | realAdapter.setHasStableIds(hasStableIds);
55 | }
56 | }
57 |
58 | @Override
59 | public long getItemId(int position) {
60 | if (realAdapter != null) {
61 | return realAdapter.getItemId(position);
62 | } else {
63 | return super.getItemId(position);
64 | }
65 | }
66 |
67 | @Override
68 | public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
69 | if (realAdapter != null) {
70 | realAdapter.onViewRecycled(holder);
71 | }
72 | }
73 |
74 | @Override
75 | public boolean onFailedToRecycleView(@NonNull RecyclerView.ViewHolder holder) {
76 | if (realAdapter != null) {
77 | return realAdapter.onFailedToRecycleView(holder);
78 | } else {
79 | return super.onFailedToRecycleView(holder);
80 | }
81 | }
82 |
83 | @Override
84 | public void onViewAttachedToWindow(@NonNull RecyclerView.ViewHolder holder) {
85 | if (realAdapter != null) {
86 | realAdapter.onViewAttachedToWindow(holder);
87 | }
88 | }
89 |
90 | @Override
91 | public void onViewDetachedFromWindow(@NonNull RecyclerView.ViewHolder holder) {
92 | if (realAdapter != null) {
93 | realAdapter.onViewDetachedFromWindow(holder);
94 | }
95 | }
96 |
97 | @Override
98 | public void registerAdapterDataObserver(@NonNull RecyclerView.AdapterDataObserver observer) {
99 | if (realAdapter != null) {
100 | realAdapter.registerAdapterDataObserver(observer);
101 | }
102 | }
103 |
104 | @Override
105 | public void unregisterAdapterDataObserver(@NonNull RecyclerView.AdapterDataObserver observer) {
106 | if (realAdapter != null) {
107 | realAdapter.unregisterAdapterDataObserver(observer);
108 | }
109 | }
110 |
111 | @Override
112 | public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
113 | if (realAdapter != null) {
114 | realAdapter.onAttachedToRecyclerView(recyclerView);
115 | }
116 | }
117 |
118 | @Override
119 | public void onDetachedFromRecyclerView(@NonNull RecyclerView recyclerView) {
120 | if (realAdapter != null) {
121 | realAdapter.onDetachedFromRecyclerView(recyclerView);
122 | }
123 | }
124 |
125 | @NonNull
126 | @Override
127 | public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
128 | return realAdapter.onCreateViewHolder(parent, viewType);
129 | }
130 |
131 | @Override
132 | public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
133 | realAdapter.onBindViewHolder(holder, position);
134 | }
135 |
136 | @Override
137 | public int getItemCount() {
138 | return realAdapter.getItemCount();
139 | }
140 | }
141 |
142 | }
143 |
--------------------------------------------------------------------------------
/aspectj/src/main/java/com/example/aspectj/HookTextChangedListener.java:
--------------------------------------------------------------------------------
1 | package com.example.aspectj;
2 |
3 | import android.text.Editable;
4 | import android.text.TextWatcher;
5 | import android.util.Log;
6 | import android.widget.EditText;
7 |
8 | import java.util.ArrayList;
9 |
10 | /**
11 | * @author youer
12 | * @date 2020/8/20
13 | */
14 | public class HookTextChangedListener {
15 | private static final String TAG = "HookTextChangedListener";
16 |
17 | /**
18 | * @param editText
19 | */
20 | public static void hook(final EditText editText) {//
21 | ArrayList textWatchers = (ArrayList) SuperClassReflectionUtils.getFieldValue(editText, "mListeners");
22 | if (textWatchers != null && !textWatchers.isEmpty()) {
23 | for (TextWatcher watcher : textWatchers) {
24 | // 去掉重复的滑动监听
25 | if (watcher instanceof HookTextWatcher) {
26 | return;
27 | }
28 | }
29 | }
30 | editText.addTextChangedListener(new HookTextWatcher(editText));
31 | }
32 |
33 | static class HookTextWatcher implements TextWatcher {
34 |
35 | private EditText editText;
36 |
37 | public HookTextWatcher(EditText editText) {
38 | this.editText = editText;
39 | }
40 |
41 | @Override
42 | public void beforeTextChanged(CharSequence s, int start, int count, int after) {
43 |
44 | }
45 |
46 | @Override
47 | public void onTextChanged(CharSequence s, int start, int before, int count) {
48 | Log.d(TAG, "view:" + editText.getContentDescription() + "\nword:" + s);
49 | }
50 |
51 | @Override
52 | public void afterTextChanged(Editable s) {
53 |
54 | }
55 | }
56 | }
57 |
58 |
--------------------------------------------------------------------------------
/aspectj/src/main/java/com/example/aspectj/SuperClassReflectionUtils.java:
--------------------------------------------------------------------------------
1 | package com.example.aspectj;
2 |
3 | import java.lang.reflect.Field;
4 | import java.lang.reflect.InvocationTargetException;
5 | import java.lang.reflect.Method;
6 |
7 | /**
8 | * @author youer
9 | * @date 2020/8/24
10 | */
11 | public class SuperClassReflectionUtils {
12 | /**
13 | * 循环向上转型, 获取对象的 DeclaredMethod
14 | *
15 | * @param object : 子类对象
16 | * @param methodName : 父类中的方法名
17 | * @param parameterTypes : 父类中的方法参数类型
18 | * @return 父类中的方法对象
19 | */
20 | public static Method getDeclaredMethod(Object object, String methodName, Class>... parameterTypes) {
21 | Method method = null;
22 | for (Class> clazz = object.getClass(); clazz != Object.class; clazz = clazz.getSuperclass()) {
23 | try {
24 | method = clazz.getDeclaredMethod(methodName, parameterTypes);
25 | return method;
26 | } catch (Exception e) {
27 | //这里甚么都不要做!并且这里的异常必须这样写,不能抛出去。
28 | //如果这里的异常打印或者往外抛,则就不会执行clazz = clazz.getSuperclass(),最后就不会进入到父类中了
29 | }
30 | }
31 | return null;
32 | }
33 |
34 | /**
35 | * 直接调用对象方法, 而忽略修饰符(private, protected, default)
36 | *
37 | * @param object : 子类对象
38 | * @param methodName : 父类中的方法名
39 | * @param parameterTypes : 父类中的方法参数类型
40 | * @param parameters : 父类中的方法参数
41 | * @return 父类中方法的执行结果
42 | */
43 | public static Object invokeMethod(Object object, String methodName, Class>[] parameterTypes,
44 | Object[] parameters) {
45 | //根据 对象、方法名和对应的方法参数 通过反射 调用上面的方法获取 Method 对象
46 | Method method = getDeclaredMethod(object, methodName, parameterTypes);
47 |
48 | //抑制Java对方法进行检查,主要是针对私有方法而言
49 | method.setAccessible(true);
50 |
51 | try {
52 | if (null != method) {
53 | //调用object 的 method 所代表的方法,其方法的参数是 parameters
54 | return method.invoke(object, parameters);
55 | }
56 | } catch (IllegalArgumentException e) {
57 | e.printStackTrace();
58 | } catch (IllegalAccessException e) {
59 | e.printStackTrace();
60 | } catch (InvocationTargetException e) {
61 | e.printStackTrace();
62 | }
63 | return null;
64 | }
65 |
66 | /**
67 | * 循环向上转型, 获取对象的 DeclaredField
68 | *
69 | * @param object : 子类对象
70 | * @param fieldName : 父类中的属性名
71 | * @return 父类中的属性对象
72 | */
73 | public static Field getDeclaredField(Object object, String fieldName) {
74 | Field field = null;
75 | Class> clazz = object.getClass();
76 | for (; clazz != Object.class; clazz = clazz.getSuperclass()) {
77 | try {
78 | field = clazz.getDeclaredField(fieldName);
79 | return field;
80 | } catch (Exception e) {
81 | //这里甚么都不要做!并且这里的异常必须这样写,不能抛出去。
82 | //如果这里的异常打印或者往外抛,则就不会执行clazz = clazz.getSuperclass(),最后就不会进入到父类中了
83 | }
84 | }
85 | return null;
86 | }
87 |
88 | /**
89 | * 直接设置对象属性值, 忽略 private/protected 修饰符, 也不经过 setter
90 | *
91 | * @param object : 子类对象
92 | * @param fieldName : 父类中的属性名
93 | * @param value : 将要设置的值
94 | */
95 | public static void setFieldValue(Object object, String fieldName, Object value) {
96 | //根据 对象和属性名通过反射 调用上面的方法获取 Field对象
97 | Field field = getDeclaredField(object, fieldName);
98 | //抑制Java对其的检查
99 | field.setAccessible(true);
100 | try {
101 | //将 object 中 field 所代表的值 设置为 value
102 | field.set(object, value);
103 | } catch (IllegalArgumentException e) {
104 | e.printStackTrace();
105 | } catch (IllegalAccessException e) {
106 | e.printStackTrace();
107 | }
108 | }
109 |
110 | /**
111 | * 直接读取对象的属性值, 忽略 private/protected 修饰符, 也不经过 getter
112 | *
113 | * @param object : 子类对象
114 | * @param fieldName : 父类中的属性名
115 | * @return : 父类中的属性值
116 | */
117 | public static Object getFieldValue(Object object, String fieldName) {
118 |
119 | //根据 对象和属性名通过反射 调用上面的方法获取 Field对象
120 | Field field = getDeclaredField(object, fieldName);
121 | //抑制Java对其的检查
122 | field.setAccessible(true);
123 | try {
124 | //获取 object 中 field 所代表的属性值
125 | return field.get(object);
126 | } catch (Exception e) {
127 | e.printStackTrace();
128 | }
129 | return null;
130 | }
131 |
132 |
133 | }
--------------------------------------------------------------------------------
/aspectj/src/main/java/com/example/aspectj/Tracker.java:
--------------------------------------------------------------------------------
1 | package com.example.aspectj;
2 |
3 | import android.app.Activity;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 | import android.widget.EditText;
7 |
8 | import androidx.recyclerview.widget.RecyclerView;
9 |
10 | /**
11 | * @author youer
12 | * @date 2020/8/20
13 | */
14 | public class Tracker {
15 | private static final String TAG = "Tracker";
16 |
17 | /**
18 | * 开始进行页面的埋点,获取页面的根布局
19 | *
20 | * @param activity
21 | */
22 | public static void startViewTracker(Activity activity) {
23 | startViewTracker(activity.getWindow().getDecorView());
24 | }
25 |
26 | public static void startViewTracker(View view) {
27 | startViewTracker(view, ViewPath.getPath(view));
28 | }
29 |
30 | public static void startViewTracker(View view, String parentContentDescription) {
31 | setViewTracker(view, parentContentDescription);
32 | }
33 |
34 | /**
35 | * 给View设置setContentDescription以及监听
36 | *
37 | * @param view
38 | */
39 | public static void setViewTracker(View view) {
40 | setViewTracker(view, ViewPath.getPath(view));
41 | }
42 |
43 | public static void setViewTracker(View view, String contentDescription) {
44 | view.setContentDescription(contentDescription);
45 | HookOnClickListener.hook(view);
46 | if (view instanceof RecyclerView) {
47 | HookAddOnScrollListenerHelper.hook((RecyclerView) view);
48 | HookRecyclerViewOnBindViewHolder.hook((RecyclerView) view);
49 | } else if (view instanceof ViewGroup) {
50 | setChildViewTracker((ViewGroup) view);
51 | } else if (view instanceof EditText) {
52 | HookTextChangedListener.hook((EditText) view);
53 | }
54 | }
55 |
56 | /**
57 | * 给ViewGroup的View添加埋点
58 | *
59 | * @param viewGroup
60 | */
61 | private static void setChildViewTracker(ViewGroup viewGroup) {
62 | // 给ViewGroup添加监听,如果有页面元素的变化,重新构建其tracker
63 | viewGroup.setOnHierarchyChangeListener(new ViewGroup.OnHierarchyChangeListener() {
64 | @Override
65 | public void onChildViewAdded(View parent, View child) {
66 | setViewTracker(parent);
67 | }
68 |
69 | @Override
70 | public void onChildViewRemoved(View parent, View child) {
71 | setViewTracker(parent);
72 | }
73 | });
74 | int childCount = viewGroup.getChildCount();
75 | for (int i = 0; i < childCount; i++) {
76 | setViewTracker(viewGroup.getChildAt(i));
77 | }
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/aspectj/src/main/java/com/example/aspectj/TrackerAspect.java:
--------------------------------------------------------------------------------
1 | package com.example.aspectj;
2 |
3 | import android.app.Activity;
4 | import android.app.Dialog;
5 | import android.util.Log;
6 | import android.widget.FrameLayout;
7 | import android.widget.PopupWindow;
8 |
9 | import org.aspectj.lang.JoinPoint;
10 | import org.aspectj.lang.annotation.After;
11 | import org.aspectj.lang.annotation.Aspect;
12 |
13 | import java.lang.reflect.Field;
14 |
15 | /**
16 | * @author youer
17 | * @date 2020/8/10
18 | */
19 | @Aspect
20 | public class TrackerAspect {
21 |
22 | private static final String TAG = "TrackerAspect";
23 |
24 | @After("execution(* android.app.Activity+.onCreate(..))")
25 | public void onActivityResume(JoinPoint joinPoint) {
26 | Log.d(TAG, "onActivityResume: ");
27 | Tracker.startViewTracker((Activity) joinPoint.getThis());
28 | }
29 |
30 | @After("call(* android.app.Dialog+.show(..))")
31 | public void onDialogShow(JoinPoint joinPoint) {
32 | Log.d(TAG, "onDialogShow: " + joinPoint.getSignature().getName());
33 | Dialog dialog = (Dialog) joinPoint.getTarget();
34 | Tracker.startViewTracker(dialog.getWindow().getDecorView());
35 | }
36 |
37 | @After("call(* android.widget.PopupWindow+.showAsDropDown(..))")
38 | public void onPopupWindowShow(JoinPoint joinPoint) {
39 | Log.d(TAG, "onPopupWindowShow: " + joinPoint.getSignature().getName());
40 | PopupWindow popupWindow = (PopupWindow) joinPoint.getTarget();
41 | try {
42 | Field field = SuperClassReflectionUtils.getDeclaredField(popupWindow, "mDecorView");
43 | field.setAccessible(true);
44 | FrameLayout popupDecorView = (FrameLayout) field.get(popupWindow);
45 | Tracker.startViewTracker(popupDecorView);
46 | } catch (IllegalAccessException e) {
47 | e.printStackTrace();
48 | }
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/aspectj/src/main/java/com/example/aspectj/ViewAspect.java:
--------------------------------------------------------------------------------
1 | package com.example.aspectj;
2 |
3 |
4 | import android.util.Log;
5 |
6 | import org.aspectj.lang.JoinPoint;
7 | import org.aspectj.lang.annotation.After;
8 | import org.aspectj.lang.annotation.Aspect;
9 | import org.aspectj.lang.annotation.Pointcut;
10 |
11 | import java.lang.reflect.Field;
12 |
13 | import androidx.recyclerview.widget.RecyclerView;
14 |
15 | /**
16 | * @author youer
17 | * @date 2020/8/10
18 | */
19 | @Aspect
20 | public class ViewAspect {
21 |
22 | private static final String TAG = "ViewAspect";
23 |
24 | /**
25 | * 监控OnClick点击事件
26 | */
27 | @Pointcut
28 | @After("execution(* android.view.View.OnClickListener+.onClick(..))")
29 | public void afterOnClickMethodCall(JoinPoint joinPoint) {
30 | Object[] args = joinPoint.getArgs();
31 | Log.e(TAG, "afterOnClickMethodCall -> view:" + args[0]);
32 | Log.e(TAG, "afterOnClickMethodCall getTarget->" + joinPoint.getTarget().toString());// 被切面的animal对象
33 | Log.e(TAG, "afterOnClickMethodCall getThis->" + joinPoint.getThis()); //切面代码运行所在的类对象
34 | Log.e(TAG, "afterOnClickMethodCall getKind->" + joinPoint.getKind());//切面的类型 method-call
35 | Log.e(TAG, "afterOnClickMethodCall getSourceLocation->" + joinPoint.getSourceLocation());//源码位置 MainActivity.java:26
36 | Log.e(TAG, "afterOnClickMethodCall getDeclaringTypeName->" + joinPoint.getSignature().getDeclaringTypeName());//com.wandering.sample.aspectj.Animal
37 | Log.e(TAG, "afterOnClickMethodCall getModifiers->" + joinPoint.getSignature().getModifiers());//方法修饰符 1--public
38 | Log.e(TAG, "afterOnClickMethodCall getName->" + joinPoint.getSignature().getName());//方法名 run
39 | Log.e(TAG, "afterOnClickMethodCall getDeclaringType->" + joinPoint.getSignature().getDeclaringType());//Animal.class
40 | }
41 |
42 | /**
43 | * 监控OnLongClick点击事件
44 | */
45 | @Pointcut
46 | @After("execution(* android.view.View.OnLongClickListener+.onLongClick(..))")
47 | public void afterOnLongClickMethodCall(JoinPoint joinPoint) {
48 | Object[] args = joinPoint.getArgs();
49 | Log.e(TAG, "afterOnLongClickMethodCall -> view:" + args[0]);
50 | Log.e(TAG, "afterOnLongClickMethodCall getTarget->" + joinPoint.getTarget().toString());// 被切面的animal对象
51 | Log.e(TAG, "afterOnLongClickMethodCall getThis->" + joinPoint.getThis()); //切面代码运行所在的类对象
52 | Log.e(TAG, "afterOnLongClickMethodCall getKind->" + joinPoint.getKind());//切面的类型 method-call
53 | Log.e(TAG, "afterOnLongClickMethodCall getSourceLocation->" + joinPoint.getSourceLocation());//源码位置 MainActivity.java:26
54 | Log.e(TAG, "afterOnLongClickMethodCall getDeclaringTypeName->" + joinPoint.getSignature().getDeclaringTypeName());//com.wandering.sample.aspectj.Animal
55 | Log.e(TAG, "afterOnLongClickMethodCall getModifiers->" + joinPoint.getSignature().getModifiers());//方法修饰符 1--public
56 | Log.e(TAG, "afterOnLongClickMethodCall getName->" + joinPoint.getSignature().getName());//方法名 run
57 | Log.e(TAG, "afterOnLongClickMethodCall getDeclaringType->" + joinPoint.getSignature().getDeclaringType());//Animal.class
58 | }
59 |
60 | /**
61 | * 监控OnCheckChange点击事件
62 | */
63 | @Pointcut
64 | @After("execution(* android.widget.CompoundButton.OnCheckedChangeListener+.onCheckedChanged(..))")
65 | public void afterOnCheckChangeMethodCall(JoinPoint joinPoint) {
66 | Object[] args = joinPoint.getArgs();
67 | Log.e(TAG, "afterOnCheckChangeMethodCall -> view:" + args[0]);
68 | Log.e(TAG, "afterOnCheckChangeMethodCall -> isChecked:" + args[1]);
69 | Log.e(TAG, "afterOnCheckChangeMethodCall getTarget->" + joinPoint.getTarget().toString());// 被切面的animal对象
70 | Log.e(TAG, "afterOnCheckChangeMethodCall getThis->" + joinPoint.getThis()); //切面代码运行所在的类对象
71 | Log.e(TAG, "afterOnCheckChangeMethodCall getKind->" + joinPoint.getKind());//切面的类型 method-call
72 | Log.e(TAG, "afterOnCheckChangeMethodCall getSourceLocation->" + joinPoint.getSourceLocation());//源码位置 MainActivity.java:26
73 | Log.e(TAG, "afterOnCheckChangeMethodCall getDeclaringTypeName->" + joinPoint.getSignature().getDeclaringTypeName());//com.wandering.sample.aspectj.Animal
74 | Log.e(TAG, "afterOnCheckChangeMethodCall getModifiers->" + joinPoint.getSignature().getModifiers());//方法修饰符 1--public
75 | Log.e(TAG, "afterOnCheckChangeMethodCall getName->" + joinPoint.getSignature().getName());//方法名 run
76 | Log.e(TAG, "afterOnCheckChangeMethodCall getDeclaringType->" + joinPoint.getSignature().getDeclaringType());//Animal.class
77 | }
78 |
79 | /**
80 | * 监控文本输入事件
81 | */
82 | @Pointcut
83 | @After("execution(* android.text.TextWatcher.onTextChanged(..))")
84 | public void afterOnTextChangedMethodCall(JoinPoint joinPoint) {
85 | // 方法的几个参数
86 | Object[] args = joinPoint.getArgs();
87 | Log.e(TAG, "afterOnTextChangedMethodCall -> CharSequence:" + args[0]);
88 | Log.e(TAG, "afterOnTextChangedMethodCall getTarget->" + joinPoint.getTarget().toString());// 被切面的animal对象
89 | Log.e(TAG, "afterOnTextChangedMethodCall getThis->" + joinPoint.getThis()); //切面代码运行所在的类对象
90 | Log.e(TAG, "afterOnTextChangedMethodCall getKind->" + joinPoint.getKind());//切面的类型 method-call
91 | Log.e(TAG, "afterOnTextChangedMethodCall getSourceLocation->" + joinPoint.getSourceLocation());//源码位置 MainActivity.java:26
92 | Log.e(TAG, "afterOnTextChangedMethodCall getDeclaringTypeName->" + joinPoint.getSignature().getDeclaringTypeName());//com.wandering.sample.aspectj.Animal
93 | Log.e(TAG, "afterOnTextChangedMethodCall getModifiers->" + joinPoint.getSignature().getModifiers());//方法修饰符 1--public
94 | Log.e(TAG, "afterOnTextChangedMethodCall getName->" + joinPoint.getSignature().getName());//方法名 run
95 | Log.e(TAG, "afterOnTextChangedMethodCall getDeclaringType->" + joinPoint.getSignature().getDeclaringType());//Animal.class
96 | }
97 |
98 |
99 | int scrollerState = 0;
100 | int scrollerX = 0;
101 | int scrollerY = 0;
102 |
103 | /**
104 | * 监控android.support.v7.widget.RecyclerView的滑动事件
105 | *
106 | * @param joinPoint
107 | */
108 | @Pointcut
109 | @After("call(* android.support.v7.widget.RecyclerView.onScrollStateChanged(..))")
110 | public void afterRecycleViewOnScrollStateChangedMethodCall1(JoinPoint joinPoint) {
111 | // 方法的几个参数
112 | Object[] args = joinPoint.getArgs();
113 | scrollerState = (int) args[0];
114 | switch (scrollerState) {
115 | case RecyclerView.SCROLL_STATE_DRAGGING:
116 | break;
117 | case RecyclerView.SCROLL_STATE_IDLE:
118 | // 当页面滚动停止的时候进行数据上报,并且置零参数1
119 | Log.d(TAG, "afterRecycleViewOnScrollStateChangedMethodCall1: " + scrollerX);
120 | Log.d(TAG, "afterRecycleViewOnScrollStateChangedMethodCall1: " + scrollerY);
121 | Log.d(TAG, "afterRecycleViewOnScrollStateChangedMethodCall getThis->" + ((RecyclerView) joinPoint.getThis()).getContentDescription()); //切面代码运行所在的类对象
122 | scrollerX = 0;
123 | scrollerY = 0;
124 | break;
125 | default:
126 | }
127 | }
128 |
129 | /**
130 | * 监控RecycleView的滑动事件
131 | */
132 | @Pointcut
133 | @After("call(* android.support.v7.widget.RecyclerView.onScrolled(..))")
134 | public void afterRecycleViewOnScrolledMethodCall1(JoinPoint joinPoint) {
135 | // 方法的几个参数
136 | Object[] args = joinPoint.getArgs();
137 | // 当滚动状态为1或者2的时候,移动距离进行叠加。
138 | if (scrollerState == RecyclerView.SCROLL_STATE_DRAGGING || scrollerState == RecyclerView.SCROLL_STATE_SETTLING) {
139 | scrollerX += (int) args[0];
140 | scrollerY += (int) args[1];
141 | }
142 | }
143 |
144 | /**
145 | * 监控Androidx RecycleView的滑动事件
146 | *
147 | * @param joinPoint
148 | */
149 | @Pointcut
150 | @After("call(* androidx.recyclerview.widget.RecyclerView.onScrollStateChanged(..))")
151 | public void afterRecycleViewOnScrollStateChangedMethodCall(JoinPoint joinPoint) {
152 | // 方法的几个参数
153 | Object[] args = joinPoint.getArgs();
154 | scrollerState = (int) args[0];
155 |
156 | switch (scrollerState) {
157 | case RecyclerView.SCROLL_STATE_DRAGGING:
158 | break;
159 | case RecyclerView.SCROLL_STATE_IDLE:
160 | // 当页面滚动停止的时候进行数据上报,并且置零参数1
161 | Log.d(TAG, "afterRecycleViewOnScrollStateChangedMethodCall: " + scrollerX);
162 | Log.d(TAG, "afterRecycleViewOnScrollStateChangedMethodCall: " + scrollerY);
163 | Log.d(TAG, "afterRecycleViewOnScrollStateChangedMethodCall getThis->" + joinPoint.getThis()); //切面代码运行所在的类对象
164 | scrollerX = 0;
165 | scrollerY = 0;
166 | break;
167 | default:
168 | }
169 | }
170 |
171 | /**
172 | * 监控RecycleView的滑动事件
173 | */
174 | @Pointcut
175 | @After("call(* androidx.recyclerview.widget.RecyclerView.onScrolled(..))")
176 | public void afterRecycleViewOnScrolledMethodCall(JoinPoint joinPoint) {
177 | // 方法的几个参数
178 | Object[] args = joinPoint.getArgs();
179 | // 当滚动状态为1或者2的时候,移动距离进行叠加。
180 | if (scrollerState == RecyclerView.SCROLL_STATE_DRAGGING || scrollerState == RecyclerView.SCROLL_STATE_SETTLING) {
181 | scrollerX += (int) args[0];
182 | scrollerY += (int) args[1];
183 | }
184 | }
185 |
186 |
187 | /**
188 | * 初始化布局的监控
189 | *
190 | * @param joinPoint
191 | */
192 | @After("execution(* androidx.recyclerview.widget.RecyclerView.Adapter.onBindViewHolder(..))")
193 | public void afterRecycleAdapterOnBind(JoinPoint joinPoint) {
194 | Object[] args = joinPoint.getArgs();
195 | RecyclerView.ViewHolder viewHolder = (RecyclerView.ViewHolder) args[0];
196 | int position = (int) args[1];
197 | try {
198 | // 获取listView对象
199 | Field recyclerViewField = SuperClassReflectionUtils.getDeclaredField(viewHolder, "mOwnerRecyclerView");
200 | recyclerViewField.setAccessible(true);
201 | RecyclerView recyclerView = (RecyclerView) recyclerViewField.get(viewHolder);
202 | // 获取listView对象
203 | Tracker.setViewTracker(viewHolder.itemView, ViewPath.getPath(viewHolder.itemView, recyclerView, position));
204 | } catch (Exception e) {
205 | e.printStackTrace();
206 | }
207 | }
208 |
209 | }
210 |
--------------------------------------------------------------------------------
/aspectj/src/main/java/com/example/aspectj/ViewPath.java:
--------------------------------------------------------------------------------
1 | package com.example.aspectj;
2 |
3 | import android.text.TextUtils;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 |
7 | import androidx.appcompat.widget.ContentFrameLayout;
8 | import androidx.recyclerview.widget.RecyclerView;
9 |
10 |
11 | /**
12 | * @author youer
13 | * @date 2020/8/19
14 | */
15 | public class ViewPath {
16 | /**
17 | * 获取view的viewTree
18 | * 优化点:
19 | * 如果这个item有id,则返回id,如果没有,则返回他在ViewTree的第几个
20 | *
21 | * @param view
22 | * @return
23 | */
24 | public static String getPath(View view) {
25 | String parentPath = "";
26 | if (view == null) {
27 | return parentPath;
28 | }
29 | if (view.getParent() == null) {
30 | parentPath = "rootView";
31 | } else {
32 | if (!(view.getParent() instanceof View) || TextUtils.isEmpty(((View) view.getParent()).getContentDescription())) {
33 | parentPath = view.getParent().getClass().getSimpleName();
34 | } else {
35 | parentPath = String.valueOf(((View) view.getParent()).getContentDescription());
36 | }
37 | }
38 | String viewType = view.getClass().getSimpleName();
39 | int index = 0;
40 | try {
41 | index = indexOfChild((ViewGroup) view.getParent(), view);
42 | } catch (Exception e) {
43 | }
44 | viewType = viewType + "[" + index + "]";
45 | return parentPath + "/" + viewType;
46 | }
47 |
48 | /**
49 | * @param view
50 | * @param recyclerView
51 | * @param position
52 | * @return
53 | */
54 | public static String getPath(View view, RecyclerView recyclerView, int position) {
55 | String parentPath = "";
56 | if (view == null) {
57 | return parentPath;
58 | }
59 | if (view.getParent() instanceof ContentFrameLayout) {
60 | parentPath = "rootView";
61 | } else {
62 | parentPath = String.valueOf(recyclerView.getContentDescription());
63 | }
64 | String viewType = view.getClass().getSimpleName();
65 | viewType = viewType + "[position" + position + "]";
66 | return parentPath + "/" + viewType;
67 | }
68 |
69 |
70 | /**
71 | * 获取子view在viewTree的第几个
72 | * 优化点
73 | * 1:index从"兄弟节点的第几个”优化为:“相同类型兄弟节点的第几个
74 | *
75 | * @param parent
76 | * @param child
77 | * @return
78 | */
79 | private static int indexOfChild(ViewGroup parent, View child) {
80 | if (parent == null) {
81 | return 0;
82 | }
83 | final int count = parent.getChildCount();
84 | int j = 0;
85 | for (int i = 0; i < count; i++) {
86 | View view = parent.getChildAt(i);
87 | if (child.getClass().isInstance(view)) {
88 | if (view == child) {
89 | return j;
90 | }
91 | j++;
92 | }
93 | }
94 | return -1;
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/aspectj/src/test/java/com/example/aspectj/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.example.aspectj;
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 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | buildscript {
3 | repositories {
4 | google()
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:4.0.1'
9 | classpath 'com.hujiang.aspectjx:gradle-android-plugin-aspectjx:2.0.10'
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | google()
18 | jcenter()
19 | }
20 | }
21 |
22 | task clean(type: Delete) {
23 | delete rootProject.buildDir
24 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app"s APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PettyWing/aop/28bf3d356531951128a7b59cbd38da8cf7316a77/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Aug 07 11:43:04 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-6.1.1-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 ':aspectj'
2 | include ':app'
3 | rootProject.name = "AOP2"
--------------------------------------------------------------------------------