import android.app.Activity;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.widget.LinearLayout;
public class CountdownTimerActivity extends Activity {
/** Called when the activity is first created. */
private boolean mTimerRunning = false;
private boolean doubleTapFlag = false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LinearLayout listView = (LinearLayout) findViewById(R.id.LinearLayout1);
//ダブルタップの間隔取得
final int doubleTime = ViewConfiguration.getDoubleTapTimeout();
listView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
Log.i("TAG", "タップされた");
// 二重起動を防止する
if (!mTimerRunning) {
mTimerRunning = true;
// カウントダウンする
new CountDownTimer(doubleTime, 1) {
// カウントダウン処理
public void onTick(long millisUntilFinished) {
}
// カウントが0になった時の処理
public void onFinish() {
if( doubleTapFlag ){
Log.v("LOG", "ダブルタップ");
doubleTapFlag = false;
}else{
Log.i("LOG", "シングルタップ");
}
mTimerRunning = false;
}
}.start();
}else{
//ダブルタップ
doubleTapFlag = true;
}
return false;
}
});
}
}
ダブルタップを単に取得したいなら、GestureDetectorクラスで簡単に取得できます。
0 件のコメント:
コメントを投稿