Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/smartdengg/click-debounce
Using ASM to handle Android's click debounce, specially a quick double click.
https://github.com/smartdengg/click-debounce
android aop aop-plugin asm asm-clickdebounce gradle gradle-android-plugin gradle-plugin gradleplugin groovy
Last synced: 4 days ago
JSON representation
Using ASM to handle Android's click debounce, specially a quick double click.
- Host: GitHub
- URL: https://github.com/smartdengg/click-debounce
- Owner: SmartDengg
- License: mit
- Created: 2018-03-27T10:43:15.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-04-19T14:07:36.000Z (over 3 years ago)
- Last Synced: 2024-12-20T08:08:48.990Z (4 days ago)
- Topics: android, aop, aop-plugin, asm, asm-clickdebounce, gradle, gradle-android-plugin, gradle-plugin, gradleplugin, groovy
- Language: Java
- Homepage:
- Size: 334 KB
- Stars: 190
- Watchers: 6
- Forks: 17
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
| README.md |
|:---|# click-debounce
[![](https://jitpack.io/v/SmartDengg/asm-clickdebounce.svg)](https://jitpack.io/#SmartDengg/asm-clickdebounce)
**Support incremental compilation! Support parallel compilation! Faster compilation speed, and shorter compilation time.**
It is a gradle plugin that uses bytecode weaving technology to solve the click jitter problem of Android applications.
For example, a normal `onClick` method without any debounce plan, multiple quick clicks may trigger multiple Activity starts:
```java
@Override public void onClick(View v) {
startActivity(new Intent(MainActivity.this, SecondActivity.class));
}
```modify the bytecode at compile time to:
```java
@Debounced
public void onClick(View var1) {
if (DebouncedPredictor.shouldDoClick(var1)) {
startActivity(new Intent(this, SecondActivity.class));
}
}
```The `@Debounced` annotation indicates that the method has been debounced. The `shouldDoClick(View)` method will determine which are the jitters and which are the correct clicks.
I also wrote a **[BLOG](https://www.jianshu.com/p/28751130c038)** to share my ideas to solve the click jitter.
*Note: This repository is just a gradle plugin, responsible for bytecode weaving work. Android runtime library please move [here](https://github.com/SmartDengg/asm-clickdebounce-runtime).*
## Requirements
- JDK 1.7 +
- Gradle 4.0.0 +## To build
```bash
$ git clone [email protected]:SmartDengg/asm-clickdebounce.git
$ cd asm-clickdebounce/
$ ./gradlew build```
## Getting Started
**Step 1**. Add the JitPack repository and the plugin to your buildscript:
```groovy
buildscript {
repositories {
...
maven { url 'https://jitpack.io' }
}
dependencies {
...
classpath 'com.github.SmartDengg.click-debounce:click-debounce-gradle-plugin:2.1.0'
}
}```
**Step 2**. Apply it in your module:
Supports `com.android.application`, `com.android.library` and `com.android.feature`.
```groovy
apply plugin: 'smartdengg.clickdebounce'
// or apply plugin: 'clickdebounce'```
**Step 3 (Optional)**. By adding the following code to your `build.gradle` to enable printe the beautiful log or add an exclusive list to indicate which methods do not need to be debounced. By default, the log is not printed, and process all the methods in the [support](#jump) list.
**It is not recommended to manually add @Debounce annotations to methods, you should use the **exclusive** feature that which methods should not be debounced, as follows:**
```groovy
debounce {
// enable log
loggable = true
// java bytecode descriptor: [class: [methods]]
exclusion = ["com/smartdengg/clickdebounce/ClickProxy": ['onClick(Landroid/view/View;)V',
'onItemClick(Landroid/widget/AdapterView;Landroid/view/View;IJ)V']]
}```
**Step 4 (Optional)**. Set the debounce window time in your Java code(default is 300 milliseconds):
```java
DebouncedPredictor.FROZEN_WINDOW_MILLIS = 400L
```
## Artifact
We output some log files to help developers better understand the build information.
These file path is located in **buildDir/outputs/debounce/logs//**, as follows:```
.
+-- app (apply this AGP)
| +-- build
| +-- generated
| +-- intermediates
| +-- outputs
| +-- debounce
| +-- logs
| +-- debug
| +-- files.txt
| +-- classes.txt
+-- build.gradle
+-- gradle.properties
+-- gradlew
+-- gradlew.bat
+-- settings.gradle```
- **files.txt** :Record the class files consumed by this build,it can help you better understand this build.
- **classes.txt** :Record information about the classes and methods woven in this build.## How it works
**Will not intercept the touch event delivery, only intercepted in the callback of the click event, so that it will not be passed to the business logic.**
![](art/clickdebounce.png)
## Support
- [x] [View.OnClickListener](https://developer.android.com/reference/android/view/View.OnClickListener)
- [x] [AdapterView.OnItemClickListener](https://developer.android.com/reference/android/widget/AdapterView.OnItemClickListener)## R8 / ProGuard (Not Required)
Pure bytecode weaving without any reflections. No Proguard rules are required.
## Bugs and Feedback
For bugs, feature requests, and discussion please use [GitHub Issues](https://github.com/SmartDengg/asm-clickdebounce/issues). Or send email to [email protected].
## Found this project useful
:heart: Hope this article can help you. Support by clicking the :star:, or share it with people around you. :heart:
## About me
email : [email protected]
blog : [小鄧子](https://www.jianshu.com/u/df40282480b4)
weibo : [-小鄧子-](https://weibo.com/5367097592/profile?topnav=1&wvr=6)
## License
See the [LICENSE](LICENSE) file for license rights and limitations (MIT).