diff --git a/app/src/main/java/zj/it/bhne/androidaop/Main2Activity.java b/app/src/main/java/zj/it/bhne/androidaop/Main2Activity.java
index f7e3ebb..5718841 100644
--- a/app/src/main/java/zj/it/bhne/androidaop/Main2Activity.java
+++ b/app/src/main/java/zj/it/bhne/androidaop/Main2Activity.java
@@ -59,4 +59,7 @@ public void btnAop(View view) {
Log.e(TAG, "btnAop");
}
+ public void btnKotlin(View view) {
+ startActivity(new Intent(this,MainActivity.class));
+ }
}
diff --git a/app/src/main/java/zj/it/bhne/androidaop/MainActivity.kt b/app/src/main/java/zj/it/bhne/androidaop/MainActivity.kt
index ae1b043..168c30d 100644
--- a/app/src/main/java/zj/it/bhne/androidaop/MainActivity.kt
+++ b/app/src/main/java/zj/it/bhne/androidaop/MainActivity.kt
@@ -16,6 +16,19 @@ class MainActivity : AppCompatActivity() ,View.OnClickListener{
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
btnClick.setOnClickListener(this)
+ initView()
+ }
+
+ private fun initView() {
+ btnKuoZhan.setSafeListener {
+ ToastUtils.showShort("222")
+ Log.e("kuozhan","wwww")
+ }
+
+ btnKuoZhanClick.click {
+ ToastUtils.showShort("ss")
+ Log.e("kuozhan","呵呵呵")
+ }
}
@@ -25,7 +38,7 @@ class MainActivity : AppCompatActivity() ,View.OnClickListener{
when(v.id){
R.id.btnClick->{
ToastUtils.showShort("哈哈哈")
- Log.e("刘佩希","wwww")
+ Log.e("ee","wwww")
}
}
}
diff --git a/app/src/main/java/zj/it/bhne/androidaop/OnClick.kt b/app/src/main/java/zj/it/bhne/androidaop/OnClick.kt
new file mode 100644
index 0000000..94e6b2a
--- /dev/null
+++ b/app/src/main/java/zj/it/bhne/androidaop/OnClick.kt
@@ -0,0 +1,36 @@
+package zj.it.bhne.androidaop
+
+import android.view.View
+
+/**
+ * 版权:渤海新能 版权所有
+ * @author zhujiang
+ * 版本:1.5
+ * 创建日期:2020/4/29
+ * 描述:AndroidAOP
+ *
+ */
+
+inline fun View.setSafeListener(crossinline action:()->Unit){
+ var lastClick=0L
+ setOnClickListener {
+ val gap = System.currentTimeMillis() - lastClick
+ lastClick=System.currentTimeMillis()
+ if(gap<1500) return@setOnClickListener
+ action.invoke()
+ }
+}
+
+
+var _viewClickFlag = false
+var _clickRunnable = Runnable { _viewClickFlag = false }
+fun View.click(action: (view: View) -> Unit) {
+ setOnClickListener {
+ if (!_viewClickFlag) {
+ _viewClickFlag = true
+ action(it)
+ }
+ removeCallbacks(_clickRunnable)
+ postDelayed(_clickRunnable, 1000)
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 4396ef3..9ef186b 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -2,6 +2,7 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_main2.xml b/app/src/main/res/layout/activity_main2.xml
index 4c5fefc..b199f98 100644
--- a/app/src/main/res/layout/activity_main2.xml
+++ b/app/src/main/res/layout/activity_main2.xml
@@ -12,6 +12,14 @@
android:layout_gravity="center"
android:onClick="btnDialog"/>
+
+