美文网首页Android Utils
Android 连续点击例子一个

Android 连续点击例子一个

作者: 几千里也 | 来源:发表于2015-11-06 15:46 被阅读749次
    private static final String PACKAGE_NAME_LAUNCHER = "com.android.launcher3";
    private int mSecretNumber = 0;
    private static final long MIN_CLICK_INTERVAL = 600;
    private long mLastClickTime;
    
    
    // click logo button 10 times continuously to open com.android.launcher3
    findViewById(R.id.logo).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            long currentClickTime = SystemClock.uptimeMillis();
            long elapsedTime = currentClickTime - mLastClickTime;
            mLastClickTime = currentClickTime;
    
            if (elapsedTime < MIN_CLICK_INTERVAL) {
                ++mSecretNumber;
                if (9 == mSecretNumber) {
                    try {
                        Intent intent = getPackageManager().getLaunchIntentForPackage(PACKAGE_NAME_LAUNCHER);
                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                        startActivity(intent);
                    } catch (Exception e) {
                        Log.i(TAG, e.toString());
                    }
    
                    finish();
                }
            } else {
                mSecretNumber = 0;
            }
    
        }
    });
    

    相关文章

      网友评论

        本文标题:Android 连续点击例子一个

        本文链接:https://www.haomeiwen.com/subject/ulschttx.html