Files
assistant-android/app/src/main/java/com/gh/common/util/ClickUtils.java

45 lines
1.3 KiB
Java
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.gh.common.util;
import android.util.Log;
public class ClickUtils {
private static long lastClickTime = 0;
private static long DIFF = 800;
private static int lastButtonId = -1;
/**
* 判断两次点击的间隔如果小于800则认为是多次无效点击 * * @return
*/
public static boolean isFastDoubleClick() {
return isFastDoubleClick(-1, DIFF);
}
/**
* 判断两次点击的间隔如果小于800则认为是多次无效点击 * * @return
*/
public static boolean isFastDoubleClick(int buttonId) {
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.v("isFastDoubleClick", "短时间内按钮多次触发");
return true;
}
lastClickTime = time;
lastButtonId = buttonId;
return false;
}
public static void releaseInterval() {
lastButtonId = 0;
}
}