Me encontré con este problema en un hackathon. No hay forma de que puedas resolverlo con GestureOverlayView, por lo que debes usar eventos de movimiento. Sin embargo, GestureOverlayView funciona con gestos ligeramente más "detallados", como un círculo. Lo que noté es que GestureOverlayView funciona mejor para figuras cerradas. Entonces, el sensor de movimientoEvent es. Encontré el código here. Modifiqué la respuesta de Gav para los golpes verticales también. No lo han probado, pero es positivo que funcione.
He aquí un ejemplo:
public class SelectFilterActivity extends Activity implements OnClickListener
{
private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_MAX_OFF_PATH = 250;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
private GestureDetector gestureDetector;
View.OnTouchListener gestureListener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/* ... */
// Gesture detection
gestureDetector = new GestureDetector(new MyGestureDetector());
gestureListener = new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}
};
}
class MyGestureDetector extends SimpleOnGestureListener {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
try {
// downward swipe
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY)
Toast.makeText(SelectFilterActivity.this, "Downward Swipe", Toast.LENGTH_SHORT).show();
else if (Math.abs(e2.getY() - e1.getY()) > SWIPE_MAX_OFF_PATH && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY)
Toast.makeText(SelectFilterActivity.this, "Upward Swipe", Toast.LENGTH_SHORT).show();
// right to left swipe
else if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
Toast.makeText(SelectFilterActivity.this, "Left Swipe", Toast.LENGTH_SHORT).show();
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
Toast.makeText(SelectFilterActivity.this, "Right Swipe", Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
// nothing
}
return false;
}
}
Ahora añadirlo a las vistas en las que desee detección de las posturas,
// Do this for each view added to the grid
imageView.setOnClickListener(SelectFilterActivity.this);
imageView.setOnTouchListener(gestureListener);
Saludos a Gav para el código!
¿Alguna vez encontró una solución para esto? – capcom
No, todavía no hay ninguna solución para Android ... – Bashevis
Vaya, ¿cómo hago lo que necesito? Realmente necesito hacer esto. Este tutorial se muestra arriba y abajo en Gestures Builder http://www.vogella.com/articles/AndroidGestures/article.html, aunque no se utiliza. Aquí está mi propia pregunta, si quieres echar un vistazo, http://stackoverflow.com/questions/14246998/detecting-vertical-gestures. No tiene sentido que no haya forma de hacerlo, otras aplicaciones usan este tipo de funcionalidad todo el tiempo. – capcom