-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ff43ee
commit e9493eb
Showing
143 changed files
with
6,811 additions
and
1,079 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# 多次点击判断库 | ||
#### 目录介绍 | ||
- 01.基础概念介绍 | ||
- 02.常见思路和做法 | ||
- 03.Api调用说明 | ||
- 04.遇到的坑分析 | ||
- 05.其他问题说明 | ||
|
||
|
||
|
||
### 01.基础概念介绍 | ||
#### 1.1 业务需求说明 | ||
- 经常遇到这样的需求类似进入开发者模式,即多次点击后执行操作。 | ||
|
||
|
||
#### 1.5 多次点击事件的原理 | ||
- 记录每次点击事件的当前时间,判断最后一次点击与第一次点击事件的时间的差值,如果小于500ms(可以自己定义这个值),认为是多次点击事件。 | ||
|
||
|
||
|
||
### 02.常见思路和做法 | ||
|
||
|
||
|
||
### 03.Api调用说明 | ||
|
||
|
||
|
||
|
||
### 04.遇到的坑分析 | ||
|
||
|
||
|
||
|
||
### 05.其他问题说明 | ||
|
||
|
||
|
||
### 06.参考博客说明 | ||
- https://www.jb51.net/article/149349.htm | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
plugins { | ||
id 'com.android.library' | ||
} | ||
apply from: rootProject.projectDir.absolutePath + "/yc.gradle" | ||
//迁移到jitpack | ||
apply plugin: 'com.github.dcendents.android-maven' | ||
|
||
|
||
android { | ||
compileSdkVersion rootProject.ext.android["compileSdkVersion"] | ||
//buildToolsVersion rootProject.ext.android["buildToolsVersion"] | ||
defaultConfig { | ||
minSdkVersion rootProject.ext.android["minSdkVersion"] | ||
targetSdkVersion rootProject.ext.android["targetSdkVersion"] | ||
versionCode rootProject.ext.android["versionCode"] | ||
versionName rootProject.ext.android["versionName"] | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
implementation(rootProject.ext.dependencies["appcompat"]) | ||
implementation(rootProject.ext.dependencies["annotation"]) | ||
} |
2 changes: 1 addition & 1 deletion
2
ComponentLib/src/main/AndroidManifest.xml → AppClickHelper/src/main/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.yc.componentlib"> | ||
package="com.yc.clickhelper"> | ||
|
||
</manifest> |
148 changes: 148 additions & 0 deletions
148
AppClickHelper/src/main/java/com/yc/clickhelper/ClickHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
package com.yc.clickhelper; | ||
|
||
|
||
import android.os.Handler; | ||
import android.os.Looper; | ||
import android.text.TextUtils; | ||
import android.util.Log; | ||
|
||
import java.util.LinkedList; | ||
|
||
public final class ClickHelper { | ||
|
||
private final String TAG = ClickHelper.class.getSimpleName(); | ||
private static final ClickHelper INSTANCE = new ClickHelper(); | ||
private final LinkedList<Long> clickList = new LinkedList<>(); | ||
/** | ||
* 检测多次按下的时间间隔 | ||
*/ | ||
private int TIME_SEP = 300; | ||
private final Handler handler; | ||
|
||
private ClickHelper() { | ||
handler = new Handler(Looper.getMainLooper()); | ||
} | ||
|
||
public static ClickHelper getInstance() { | ||
return ClickHelper.INSTANCE; | ||
} | ||
|
||
public void setTimeSep(int timeSep){ | ||
if (timeSep < 0){ | ||
return; | ||
} | ||
TIME_SEP = timeSep; | ||
} | ||
|
||
public void onClickKey(String key) { | ||
if (TextUtils.isEmpty(key)) { | ||
return; | ||
} | ||
//有单击就清理定时器 | ||
clearHandle(); | ||
//判断三连击 | ||
if (clickList.size() == 3) { | ||
clickList.removeFirst(); | ||
} | ||
clickList.add(System.currentTimeMillis()); | ||
Log.d(TAG, "click add :" + System.currentTimeMillis() + " size:" + clickList.size()); | ||
handler.postDelayed(() -> { | ||
//检测是否发生三连击 | ||
if (clickList.size() == 3) { | ||
long fistSep = (long) clickList.get(1) - clickList.get(0); | ||
long secondSep = (long) clickList.get(2) - clickList.get(1); | ||
Log.d(TAG, "fistSep :" + fistSep + "secondSep:" + secondSep); | ||
if (fistSep < TIME_SEP && secondSep < TIME_SEP) { | ||
//判定为三连击 | ||
onMultipleClick(key); | ||
} | ||
} else { | ||
if (clickList.size() < 3) { | ||
//单击行为 | ||
onSingleClick(key); | ||
} else { | ||
Log.d(TAG, "click error " + key); | ||
} | ||
} | ||
//最后一定会清掉 | ||
clickList.clear(); | ||
}, TIME_SEP); | ||
} | ||
|
||
public void onThreeClick(String key) { | ||
onClickKey(key, 3); | ||
} | ||
|
||
public void onClickKey(String key, int clickNum) { | ||
if (TextUtils.isEmpty(key)) { | ||
return; | ||
} | ||
//有单击就清理定时器 | ||
clearHandle(); | ||
//判断三连击 | ||
if (clickList.size() == clickNum) { | ||
clickList.removeFirst(); | ||
} | ||
clickList.add(System.currentTimeMillis()); | ||
Log.d(TAG, "click add :" + System.currentTimeMillis() + " size:" + clickList.size()); | ||
handler.postDelayed(() -> { | ||
//检测是否发生三连击 | ||
if (clickList.size() == clickNum) { | ||
boolean isMultipleClick = true; | ||
for (int i = 0; (i < clickNum - 1); i++) { | ||
long sep = (long) clickList.get(i + 1) - (long) clickList.get(i); | ||
//只要有一个不符合条件,则就不是num多次连击 | ||
if (sep > TIME_SEP) { | ||
isMultipleClick = false; | ||
break; | ||
} | ||
} | ||
if (isMultipleClick) { | ||
onMultipleClick(key); | ||
} | ||
} else { | ||
if (clickList.size() < clickNum) { | ||
//单击行为 | ||
onSingleClick(key); | ||
} else { | ||
Log.d(TAG, "click error " + key); | ||
} | ||
} | ||
//最后一定会清掉 | ||
clickList.clear(); | ||
}, TIME_SEP); | ||
} | ||
|
||
|
||
private void onSingleClick(String key) { | ||
if (onClickListener != null) { | ||
onClickListener.onSingleClick(key); | ||
} | ||
} | ||
|
||
private void onMultipleClick(String key) { | ||
if (onClickListener != null) { | ||
onClickListener.onMultipleClick(key); | ||
} | ||
} | ||
|
||
/** | ||
* 清除消息队列 | ||
*/ | ||
private void clearHandle() { | ||
Log.d(TAG, "clearHandle:清理定时器"); | ||
handler.removeCallbacksAndMessages(null); | ||
} | ||
|
||
private OnClickListener onClickListener; | ||
|
||
public void setOnClickListener(OnClickListener clickListener) { | ||
this.onClickListener = clickListener; | ||
} | ||
|
||
public interface OnClickListener { | ||
void onSingleClick(String key); | ||
|
||
void onMultipleClick(String key); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...c/toolutils/click/CountClickListener.java → ...om/yc/clickhelper/CountClickListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...om/yc/toolutils/click/FastClickUtils.java → ...va/com/yc/clickhelper/FastClickUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.yc.toolutils.click; | ||
package com.yc.clickhelper; | ||
|
||
import android.text.TextUtils; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...toolutils/click/PerfectClickListener.java → .../yc/clickhelper/PerfectClickListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.yc.toolutils.click; | ||
package com.yc.clickhelper; | ||
|
||
|
||
import android.view.View; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.