Giter Club home page Giter Club logo

androidaop's Introduction

AndroidAOP

AOP的方式实现防止按钮多次点击,Java和Kotlin都能使用。

使用方法很简单,需要几步配置,配置完成之后直接添加注解即可使用,下面是配置方法:

引入

  1. 在项目的build.gradle中的buildscript中的dependencies添加:
dependencies {
    ...
    classpath 'com.hujiang.aspectjx:gradle-android-plugin-aspectjx:2.0.10'
}
  1. 在项目的build.gradle中的allprojects中的repositories添加:
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
  1. appbuild.gradle中的最上面添加
apply plugin: 'android-aspectjx'
  1. appbuild.gradle中的dependencies添加
implementation 'com.github.zhujiang521:AndroidAOP:1.1.1'

使用方法

直接在按钮的点击事件上面添加注解即可使用。

Java中:

@SingleClick
@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.btnClick2:
            ToastUtils.showShort("哈哈哈");
            Log.e("刘沛星","wwww");
        break;
    }
}

Kotlin中:

@SingleClick
override fun onClick(v: View?) {
    if (v != null) {
        when(v.id){
            R.id.btnClick ->{
                ToastUtils.showShort("哈哈哈")
                Log.e("刘沛星","wwww")
            }
        }
    }
}

默认间隔时间为1500毫秒,可以自行修改,在注解后面添加括号,在括号中声明需要的时间值即可。

@SingleClick(1000)
override fun onClick(v: View?) {
    if (v != null) {
        when(v.id){
            R.id.btnClick ->{
                ToastUtils.showShort("哈哈哈")
                Log.e("刘沛星","wwww")
            }
        }
    }
}

OK。

新增了Kotlin的判断重复的方法,大家可以按照下面的方法直接进行调用,比写注解更加灵活方便:

btnKuoZhan.setSafeListener {
    ToastUtils.showShort("222")
    Log.e("kuozhan","wwww")
}

androidaop's People

Contributors

plain-dev avatar zhujiang521 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.