I am trying to detect gesture events on the emulator by making mouse clicks, should this work? I’ve tried double clicking (which i would expect to produce a onDoubleTap), clicking (which I would expect to produce a onSingleTapConfirmed), and dragging (to hopeful produce a onScroll), but these all produce the same three series of events: onDown, onShowPress, onLongPress.
Is there a particular way mouse clicks/drags must be made to produce gesture events on the emulator? Or is there something wrong with the below code, which I am using to detect events:
public class GestureEnabledImageView extends ImageView implements OnGestureListener, OnDoubleTapListener
{
private GestureDetector gestureScanner;
public GestureEnabledImageView(Context context)
{
super(context);
gestureScanner = new GestureDetector(this);
gestureScanner.setOnDoubleTapListener(this);
}
public GestureEnabledImageView(Context context, AttributeSet atts)
{
super(context, atts);
gestureScanner = new GestureDetector(this);
gestureScanner.setOnDoubleTapListener(this);
}
public GestureEnabledImageView(Context context, AttributeSet atts, int style)
{
super(context, atts, style);
gestureScanner = new GestureDetector(this);
gestureScanner.setOnDoubleTapListener(this);
}
@Override
public boolean onTouchEvent(MotionEvent me)
{
return gestureScanner.onTouchEvent(me);
}
@Override
public boolean onDown(MotionEvent e)
{
log("onDown: " + e.getRawX() + ", " +e.getRawY());
return false;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
log("onFling: " + e1.getX() + ", " + e1.getY() + " -- " + e2.getX() + ", " + e2.getY() + " -- " + velocityX + " -- " + velocityY);
return false;
}
@Override
public void onLongPress(MotionEvent e)
{
log("onLongPress: " + e.getRawX() + ", " +e.getRawY());
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
{
log("onScroll: " + e1.getX() + ", " + e1.getY() + " -- " + e2.getX() + ", " + e2.getY() + " -- " + distanceX + " -- " + distanceY);
return false;
}
@Override
public void onShowPress(MotionEvent e)
{
// TODO Auto-generated method stub
log("onShowPress: " + e.getRawX() + ", " +e.getRawY());
System.out.println();
}
@Override
public boolean onSingleTapUp(MotionEvent e)
{
log("onSingleTapUp: " + e.getRawX() + ", " +e.getRawY());
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onDoubleTap(MotionEvent e)
{
log("onDoubleTap: " + e.getRawX() + ", " +e.getRawY());
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onDoubleTapEvent(MotionEvent e)
{
log("onDoubleTapEvent: " + e.getRawX() + ", " +e.getRawY());
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e)
{
log("onSingleTapConfirmed: " + e.getRawX() + ", " +e.getRawY());
// TODO Auto-generated method stub
return false;
}
private void log(String text)
{
Log.i("MyInfo", text);
}
}
Ok, found the solution, just wanted to post here for anyone else with similar problems:
The gestureListener methods should return “true”, not “false”. This is surprising, because the documentation states that returning “true” indicates that the event has been consumed, which, I would think, would keep further MotionEvents from being fired. But, apparently not…