forked from naXa777/SoundRecorder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix naXa777#35 Prevent mis-clicks on buttons
- Loading branch information
Showing
7 changed files
with
85 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
public enum RecorderState { | ||
STOPPED, | ||
PREPARING, | ||
RECORDING, | ||
PAUSED | ||
} |
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
44 changes: 44 additions & 0 deletions
44
app/src/main/java/by/naxa/soundrecorder/listeners/OnSingleClickListener.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,44 @@ | ||
package by.naxa.soundrecorder.listeners; | ||
|
||
import android.os.SystemClock; | ||
import android.view.View; | ||
|
||
/** | ||
* Mis-clicking prevention, using threshold of 600 ms | ||
* Source: https://stackoverflow.com/a/20672997/1429387 | ||
* | ||
* 处理快速在某个控件上双击2次(或多次)会导致onClick被触发2次(或多次)的问题 | ||
* 通过判断2次click事件的时间间隔进行过滤 | ||
* <p> | ||
* 子类通过实现{@link #onSingleClick}响应click事件 | ||
*/ | ||
public abstract class OnSingleClickListener implements View.OnClickListener { | ||
/** | ||
* 最短click事件的时间间隔 | ||
*/ | ||
private static final long MIN_CLICK_INTERVAL = 600; | ||
/** | ||
* 上次click的时间 | ||
*/ | ||
private long mLastClickTime; | ||
|
||
/** | ||
* click响应函数 | ||
* | ||
* @param v The view that was clicked. | ||
*/ | ||
public abstract void onSingleClick(View v); | ||
|
||
@Override | ||
public final void onClick(View v) { | ||
long currentClickTime = SystemClock.uptimeMillis(); | ||
long elapsedTime = currentClickTime - mLastClickTime; | ||
|
||
if (elapsedTime <= MIN_CLICK_INTERVAL) | ||
return; | ||
mLastClickTime = currentClickTime; | ||
|
||
onSingleClick(v); | ||
} | ||
|
||
} |
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