XiMengJianYu/.svn/pristine/bd/bd5a86853f1505c8b729c8aa4e9a4d791fb15fe3.svn-base
2023-04-17 17:58:44 +08:00

53 lines
1.6 KiB
Plaintext
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.example.administrator.ximengjianyu.utils;
import android.util.Log;
/**
* Created by wuxiaohui on 2017/7/28.
* 判断用户点击按钮间隔时间,如果间隔时间太短,则认为是无效操作,否则进行相关业务处理
*/
public class ButtonUtils {
private static long lastClickTime = 0;
private static long DIFF = 1000;
private static int lastButtonId = -1;
/**
* 判断两次点击的间隔如果小于1000则认为是多次无效点击
*
* @return
*/
public static boolean isFastDoubleClick() {
Log.e("isFastDoubleClick", "短时间内按钮多次触发");
return isFastDoubleClick(-1, DIFF);
}
/**
* 判断两次点击的间隔如果小于1000则认为是多次无效点击
*
* @return
*/
public static boolean isFastDoubleClick(int buttonId) {
Log.e("isFastDoubleClick", "短时间内按钮多次触发");
return isFastDoubleClick(buttonId, DIFF);
}
/**
* 判断两次点击的间隔如果小于diff则认为是多次无效点击
*
* @param diff
* @return
*/
public static boolean isFastDoubleClick(int buttonId, long diff) {
long time = System.currentTimeMillis();
long timeD = time - lastClickTime;
if (lastButtonId == buttonId && lastClickTime > 0 && timeD < diff) {
Log.e("isFastDoubleClick", "短时间内按钮多次触发");
return true;
}
lastClickTime = time;
lastButtonId = buttonId;
return false;
}
}