用数组的方式实现连续点击效果

2018-09-21  本文已影响0人  穷格万物
final static int COUNTS = 5;// 点击次数
    long[] mHits = new long[COUNTS];


private void continuousClick(long time) {
        //每次点击时,数组向前移动一位
        System.arraycopy(mHits, 1, mHits, 0, mHits.length - 1);
        //为数组最后一位赋值
        mHits[mHits.length - 1] = SystemClock.uptimeMillis();
        if (mHits[0] >= (SystemClock.uptimeMillis() - time)) {
            mHits = new long[COUNTS];//重新初始化数组
            Toast.makeText(this, "连续点击了5次", Toast.LENGTH_LONG).show();
            SystemUtils.launchFactoryMode(this);
        }
}
上一篇下一篇

猜你喜欢

热点阅读