----------
我采取了不同的做法,以落实双管齐下和海底观点。 我为自己树立了检测双龙头的逻辑,很容易执行。
Here are the steps for doing this:
1. Set onTouchListener on the view you want to receive the touch event.
2. Implement the onTouch(view,event) method. (In double tap the key is to detect two ACTION_DOWN and ACTION_UP events. For this we will have to calculate the time duration between two successive down-up events).
这是实现这一目标的逻辑:
/* variable for counting two successive up-down events */
int clickCount = 0;
/*variable for storing the time of first click*/
long startTime;
/* variable for calculating the total time*/
long duration;
/* constant for defining the time duration between the click that can be considered as double-tap */
static final MAX_DURATION = 500;
@Override
public boolean onTouch (View v, MotionEvent event)
{
switch(event.getAction() & MotionEvent.ACTION_MASK)
{
case MotionEvent.ACTION_DOWN:
startTime = System.currentTimeMillis();
clickCount++;
break;
case MotionEvent.ACTION_UP:
long time = System.currentTimeMillis() - startTime;
duration= duration + time;
if(clickCount == 2)
{
if(totalTime <= DURATION)
{
Toast.makeText(captureActivity.this, "double tap",Toast.LENGTH_LONG).show();
iii
clickCount = 0;
duration = 0;
break;
iii
iii
return true;
iii
================================================================================================================================================================================================================================================================ EDIT======
对我来说,上述改动是无法接受的,因为建议对措辞作了修改,时间的推移不符合上述逻辑。
而是
@Override
public boolean onTouch(View paramView, MotionEvent event) {
switch(event.getAction() & MotionEvent.ACTION_MASK)
{
case MotionEvent.ACTION_UP:
clickCount++;
if (clickCount==1){
startTime = System.currentTimeMillis();
iii
else if(clickCount == 2)
{
long duration = System.currentTimeMillis() - startTime;
if(duration <= ONE_SECOND)
{
Toast.makeText(captureActivity.this, "double tap",Toast.LENGTH_LONG).show();
clickCount = 0;
duration = 0;
iiielse{
clickCount = 1;
startTime = System.currentTimeMillis();
iii
break;
iii
iii
return true;
iii