@Tyhj
        
        2019-05-30T13:01:16.000000Z
        字数 1280
        阅读 1177
    Android
Step 1. Add the JitPack repository to your build file
dependencies {classpath 'com.hujiang.aspectjx:gradle-android-plugin-aspectjx:2.0.4'...}...allprojects {repositories {...maven { url 'https://jitpack.io' }}}
Step 2. Add the dependency
apply plugin: 'android-aspectjx'...aspectjx {//排除所有package路径中包含`android.support`的class文件及库(jar文件)exclude 'android.support'}dependencies {implementation "com.github.tyhjh.Annotation:annotationlibrary:v1.0.4"annotationProcessor "com.github.tyhjh.Annotation:annotator:v1.0.4"}
初始化控件,在onCreate的setContentView方法后,初始化ViewInjector,然后,被注解的控件只需要变量名和ID一样就可以,在APP模块里面也可以手动添加value值,其他模块不行
protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);ViewInjector.injectView(this);...}@ViewById(value = R.id.txtView)TextView txtView;@ViewByIdTextView txtView2;
设置点击事件,也是一样,方法名和ID一样就可以,在APP模块也可以手动配置ID
@Clickvoid txtView2() {...}@Click(R.id.txtView)void txtView() {...}
新增防抖动功能,使用了@Click注解的按钮默认在200ms内只能点击一次,可以通过设置全局修改,也可以修改单个点击事件的间隔
//全局修改点击间隔,需要尽早设置AvoidShake.setClickIntervalTime(1000);//单个设置点击间隔@Click(interval = 100)void txtView() {...}
方法在主线程执行,可以添加一个延迟时间,不需要初始化ViewInjector
@UiThread(delay = 1000)void toast(String msg) {...}
方法在子线程执行
@Background(delay = 1000)void backgroud() {...}
