av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術(shù)文章
文章詳情頁

Android kotlin使用注解實(shí)現(xiàn)防按鈕連點(diǎn)功能的示例

瀏覽:85日期:2022-09-20 16:39:39
SingleClick:

@Retention(AnnotationRetention.RUNTIME)@Target(AnnotationTarget.FUNCTION)annotation class SingleClick( // 點(diǎn)擊間隔時(shí)間,毫秒 val value: Long = 500)SingleClickAspect:

import android.os.SystemClockimport org.aspectj.lang.ProceedingJoinPointimport org.aspectj.lang.annotation.Aroundimport org.aspectj.lang.annotation.Aspectimport org.aspectj.lang.annotation.Pointcutimport org.aspectj.lang.reflect.MethodSignature@Aspectclass SingleClickAspect { /** * 定義切點(diǎn),標(biāo)記切點(diǎn)為所有被@SingleClick注解的方法 * 注意:這里 你的包名.SingleClick 需要替換成 * 你自己項(xiàng)目中SingleClick這個(gè)類的全路徑 */ @Pointcut('execution(@你的包名.SingleClick * *(..))') fun methodAnnotated() { } /** * 定義一個(gè)切面方法,包裹切點(diǎn)方法 */ @Around('methodAnnotated()') @Throws(Throwable::class) fun aroundJoinPoint(joinPoint: ProceedingJoinPoint) { try { // 取出方法的注解 val signature = joinPoint.signature as MethodSignature val method = signature.method // 檢查方法是否有注解 val hasAnnotation = method != null && method.isAnnotationPresent(SingleClick::class.java) if (hasAnnotation) {// 計(jì)算點(diǎn)擊間隔,沒有注解默認(rèn)500,有注解按注解參數(shù)來,注解參數(shù)為空默認(rèn)500;val singleClick = method.getAnnotation(SingleClick::class.java)val interval = singleClick.value// 檢測間隔時(shí)間是否達(dá)到預(yù)設(shè)時(shí)間并且線程空閑if (canClick(interval)) { joinPoint.proceed()} } else {joinPoint.proceed() } } catch (e: Exception) { // 出現(xiàn)異常不攔截點(diǎn)擊事件 joinPoint.proceed() } } // 判斷是否響應(yīng)點(diǎn)擊 private fun canClick(interval: Long): Boolean { val time = SystemClock.elapsedRealtime() val timeInterval = Math.abs(time - mLastClickTime) if (timeInterval > interval) { mLastClickTime = time return true } return false } companion object { // 最后一次點(diǎn)擊的時(shí)間 private var mLastClickTime: Long = 0 }}build.gradle(項(xiàng)目):

buildscript { dependencies { classpath ’com.hujiang.aspectjx:gradle-android-plugin-aspectjx:2.0.4’ }}build.gradle(APP):

plugins { id ’android-aspectjx’}使用:

<?xml version='1.0' encoding='utf-8'?><androidx.constraintlayout.widget.ConstraintLayout xmlns:android='http://schemas.android.com/apk/res/android' xmlns:app='http://schemas.android.com/apk/res-auto' xmlns:tools='http://schemas.android.com/tools' android:layout_width='match_parent' android:layout_height='match_parent' tools:context='.MainActivity'> <TextView android:onClick='onTextClick' android:layout_width='wrap_content' android:layout_height='wrap_content' android:text='Hello World!' app:layout_constraintBottom_toBottomOf='parent' app:layout_constraintLeft_toLeftOf='parent' app:layout_constraintRight_toRightOf='parent' app:layout_constraintTop_toTopOf='parent' /></androidx.constraintlayout.widget.ConstraintLayout>

class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) } @SingleClick(800) fun onTextClick(view: View) { }}

以上就是Android kotlin使用注解實(shí)現(xiàn)防按鈕連點(diǎn)功能的示例的詳細(xì)內(nèi)容,更多關(guān)于Android kotlin實(shí)現(xiàn)防按鈕連點(diǎn)功能的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: Android
相關(guān)文章:
主站蜘蛛池模板: 国产精品免费一区二区三区 | 久久久亚洲一区 | 三级黄色片网站 | 俺去俺来也在线www色官网 | 成人激情视频网 | 五月天激情综合网 | 成 人 黄 色 片 在线播放 | 超碰在线国产 | 日韩在线毛片 | 国产视频www| 午夜影院在线观看视频 | 日韩黄色大片 | 免费国产黄色 | 中文字幕在线免费观看 | 久久一级片| 亚洲高清视频在线观看 | 久久久一区二区 | 中文字幕在线看片 | 国产日韩视频 | 精产国产伦理一二三区 | 午夜精品视频 | 欧美福利在线观看 | 国产精品www | 亚洲天堂成人 | 欧美日视频 | 国产黄a三级 | 欧美1区2区 | 91av免费在线观看 | 超碰中文字幕 | 亚洲第一视频网站 | 免费特级毛片 | 精品视频在线观看 | 黄色大片一级 | 激情五月综合色婷婷一区二区 | 日韩在线免费播放 | 欧美日韩一区在线 | 日韩激情久久 | 黄色一级大片 | 欧美精品在线观看视频 | 男人操女人视频网站 | 欧美综合在线视频 |