Android 连续点击例子一个
2015-11-06 本文已影响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;
}
}
});