|
@@ -0,0 +1,73 @@
|
|
|
|
+package com.yc.videotool;
|
|
|
|
+
|
|
|
|
+import android.text.TextUtils;
|
|
|
|
+
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * <pre>
|
|
|
|
+ * @author yangchong
|
|
|
|
+ * blog : https://github.com/yangchong211
|
|
|
|
+ * time : 2017/10/21
|
|
|
|
+ * desc : 防暴力点击
|
|
|
|
+ * revise:
|
|
|
|
+ * </pre>
|
|
|
|
+ */
|
|
|
|
+public final class ClickUtils {
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 默认最大点击间隔时间
|
|
|
|
+ */
|
|
|
|
+ private static final int MAX_INTERVAL = 500;
|
|
|
|
+ private static long mLastClickTime;
|
|
|
|
+ private static final HashMap<String, Long> tagMaps = new HashMap<>();
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 判断一个控件是否短时间内重复点击
|
|
|
|
+ * @return true表示是重复点击
|
|
|
|
+ */
|
|
|
|
+ public static boolean isFastDoubleClick() {
|
|
|
|
+ return isFastDoubleClick(MAX_INTERVAL);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 判断一个控件是否xx时间内重复点击
|
|
|
|
+ * @param maxInterval 设置间隔时间
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public static boolean isFastDoubleClick(int maxInterval) {
|
|
|
|
+ long current = System.currentTimeMillis();
|
|
|
|
+ long interval = current - mLastClickTime;
|
|
|
|
+ if ((interval > 0) && (interval < maxInterval)) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ mLastClickTime = current;
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 判断一个控件是否xx时间内重复点击
|
|
|
|
+ * @param maxInterval 设置间隔时间
|
|
|
|
+ * @param tag 标记
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public static boolean isFastDoubleClickWithTag(int maxInterval, String tag) {
|
|
|
|
+ if (TextUtils.isEmpty(tag)) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ long current = System.currentTimeMillis();
|
|
|
|
+ long interval = 0;
|
|
|
|
+ if (tagMaps.containsKey(tag)) {
|
|
|
|
+ // 获取上次保存时间离现在的时间间距.
|
|
|
|
+ interval = current - tagMaps.get(tag);
|
|
|
|
+ }
|
|
|
|
+ if ((interval > 0) && (interval < maxInterval)) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ // 放入当前tag对应的时间
|
|
|
|
+ tagMaps.put(tag, current);
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|