Double click on Android


#1

Hello,
Processing can detect a double click on a phone ?
If so, how to code it ?

Thank you.


#2

You can use the Kentai Library:

http://ketai.org

http://ketai.org/examples/gestures/

http://ketai.org/reference/ui/ketaigesture/


#3

Thank you, I’m going to look.


#4

@hugo===
“standard” way to do that is using android motionEvent() with sequence ActionDown+ActionUp+ ActionDown+ActionUp and millis(): you define time elapsed when it s double tap…


#5

Hello,
Do you have an exemple code ?
Thank you.


#6

@hugo===
all details an examples here: https://developer.android.com/reference/android/view/MotionEvent


#7

You can use the common mouse event functions as well. This post could show one possible approach.

Kf


#8

I’ve been tinkering with this recently … I have code that does various gestures, but not pinch yet. It uses the Android Mode touchStarted(), touchEnded() and touchDragged() callbacks and 2 simple timing threads to determine the gesture type. You then handle the gesture in the functions that get called. It was my way of avoiding having to fathom the MotionEvent developer guide!

Hope it’s useful!


String touchText = "..." ;

void setup() {
  fullScreen() ;
  fill(255);
  textAlign(CENTER, CENTER) ;
  textSize(width/20) ;
}

void draw() {
  background(0);
  text(touchText, 0, height/4, width, height/2) ;
}

// a few variables ...
boolean dragDetected = false ;
boolean longPressDetected = false ;
int touchTime, tapCount, elapsedTime ; 


//run tapTimer() as a thread to count taps
void tapTimer() {
  // set time to wait for taps to happen
  // this avoids calling onSingleTap() if doubleTap() is wanted
  delay(200) ; 
  switch(tapCount) {
  case 1:
    onSingleTap() ;
    break;
  case 2:
    onDoubleTap() ;
    break;
  default:
    break;
  }
  tapCount = 0 ; //reset
} 

//run touchTimer as a thread to capture longPress gesture
void touchTimer() {
  longPressDetected = false ;
  while (!longPressDetected && !dragDetected) {
    elapsedTime = millis() - touchTime ;
    if (elapsedTime > 500) {
      longPressDetected = true ;
      onLongPress() ;
    }
  }
}

// touchStarted(), touchEnded() and touchMoved() are provided by Android Mode
//using then here to 

void touchStarted() {
  touchTime = millis() ;
  thread("touchTimer") ; //checks for longpress
  dragDetected = false ;
}

void touchEnded() {
  //check for longPress and drag and if neither have happened
  //start the tapTimer() thread to count taps
  if (longPressDetected) {
    //do nothing
  } else if (dragDetected) {
    if (millis()-touchTime < 150 ) { 
      onFlick();
    }
    tapCount = 0 ;
  } else {
    if (tapCount == 0) {   
      thread("tapTimer") ;
    }
    tapCount +=1 ;
  } 
  longPressDetected = true ; //leave touchTimer thread if it's running
}

void touchMoved() {
  touchText = "touch moved"  ;
  dragDetected = true ;
  onDrag() ;
}


// the functions below are called from the above code 
// use them to handling gestures
// use touches[0].x and touches[0].y to determine screenlocation

void onSingleTap() {
  touchText = "single tap" ;
  println("single tap") ;
}

void onDoubleTap() {
  touchText = "double tap" ;
  println("double tap") ;
}

void onLongPress() {
  touchText = "long press" ;
  println("longpress") ;
}

void onFlick() {
  touchText = "flick" ;
  println("flick") ;
}

void onDrag() {  
  touchText = "drag"  ;  
  println("drag") ;
}

#9

Hello,
Thank you so much. :grinning: