日期:2017-8-23 浏览次数:11次 点赞次数:0

public class MainActivity extends Activity {
private long startTime = 0;
private long[] mHits = new long[5];
 
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
 
Button bt_click = (Button) findViewById(R.id.bt_click);
Button bt_many_click = (Button) findViewById(R.id.bt_many_click);
 
bt_click.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//两次点击在一定的时间间隔内,才是双击
if(startTime!=0){
long endTime = System.currentTimeMillis();
if(endTime-startTime<500){
Toast.makeText(getApplicationContext(), "是男人", 0).show();
}
}
startTime = System.currentTimeMillis();
}
});
 
bt_many_click.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//了解
//1,原数组(要被拷贝的数组)
//2,原数组的拷贝起始位置索引值
//3,目标数组(原数组的数据---拷贝-->目标数组)
//4,目标数组接受值的起始索引位置
//5,拷贝的长度
System.arraycopy(mHits, 1, mHits, 0, mHits.length-1);
        mHits[mHits.length-1] = SystemClock.uptimeMillis();
        if(mHits[mHits.length-1]-mHits[0]<500){
        //响应了一个三击事件
        Toast.makeText(getApplicationContext(), "超级赛亚人!!!!", 0).show();
        }
}
});
 
 
/* System.arraycopy(mHits, 1, mHits, 0, mHits.length-1);
        mHits[mHits.length-1] = SystemClock.uptimeMillis();
        if (mHits[0] >= (SystemClock.uptimeMillis()-500)) {
            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.setClassName("android",
                    com.android.internal.app.PlatLogoActivity.class.getName());
            try {
                startActivity(intent);
            } catch (Exception e) {
                Log.e(LOG_TAG, "Unable to start activity " + intent.toString());
            }
        }*/
}
 
}