Android 怎么实现类似于进入开发者模式的点击方式

直接借鉴开发者模式怎么实现的就可以了。如下。

先声明成员变量:

    final static int COUNTS = 10;//点击次数
    final static long DURATION = 5 * 1000;//规定有效时间
    long[] mHits = new long[COUNTS];

设置点击事件:

        app_icon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                System.arraycopy(mHits, 1, mHits, 0, mHits.length - 1);//每次点击时,数组向前移动一位[1]
                mHits[mHits.length - 1] = SystemClock.uptimeMillis();//为数组最后一位赋值
                if ((SystemClock.uptimeMillis() - mHits[0]) <= DURATION) {//检查是否是在我们规定的时间内
                    mHits = new long[COUNTS];//重新初始化数组
                    //执行对应的逻辑
                    try {
                        Intent intent = new Intent();
                        intent.setClass(context,HiddenActivity.class);
                        context.startActivity(intent);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        });

        以上代码的意思是:

        触发点击的时候都将数组向左移动一位,将时间赋值给最后一位,从上面的代码中可以看出当点击了 10次, 那么最后一位就已经被移到了第一位,然后比较时间:mHits[0] >= (SystemClock.uptimeMillis() - DURATION) 如果是在规定的时间内触发的连续点击,那么就生效,执行所要的操作。

[1] If the <code>src</code> and <code>dest</code> arguments refer to the same array object, then the copying is performed as if the components at positions <code>srcPos</code> through <code>srcPos+length-1</code> were first copied to a temporary array with <code>length</code> components and then the contents of the temporary array were copied into positions <code>destPos</code> through <code>destPos+length-1</code> of the destination array. Explanation from the official Android of the System.arraycopy() method.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值