双击事件屏蔽与监听

package com.iflytek.parrotlib.utils;

public class DoubleClickUtils {

    private static final int SPACE_TIME = 300;
    private static long lastClickTime = 0;


    /**
     * 屏蔽快速双击,只有第一次生效
     * @return
     */
    public static boolean isFirstDoubleClick(){

        long now = System.currentTimeMillis();
        if (now - lastClickTime > SPACE_TIME){
            lastClickTime = now;
            return true;
        }
        return false;
    }

    /**
     * 是否是双击?
     * @return true:是双击; false:不是双击;
     */
    public synchronized static boolean isDoubleClick() {
        long currentTime = System.currentTimeMillis();
        boolean isClick;
        if (currentTime - lastClickTime > SPACE_TIME) {
            isClick = false;
        } else {
            isClick = true;
        }
        lastClickTime = currentTime;
        return isClick;
    }

}

 

©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页