百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
C

click-debounce

> 包管理
开源

使用 ASM 处理 Android 的点击抖动,特别是快速双击。

192 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

使用 ASM 处理 Android 的点击抖动,特别是快速双击。

README.md

click-debounce

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 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.

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 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.

Support

  • View.OnClickListener
  • 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. 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 : 小鄧子

weibo : -小鄧子-

License

See the LICENSE file for license rights and limitations (MIT).

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Javaandroidaopaop-pluginasm

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类包管理
定价开源

> 相关工具

N
npm
Node.js 默认包管理器
P
pnpm
高效节省磁盘的 Node 包管理器
I
is-gif
Check if a Buffer/Uint8Array is a GIF image