I have a custom layout pinch zoom code as a parent and a child layout that handle the click feature. Therefore I use on touch intercept, but the problem is that with this it would not know when to click or drag.
@Override
public boolean onInterceptTouchEvent(MotionEvent ev){
switch (ev.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
startClickTime = System.currentTimeMillis(); //start time when first finger land
Log.i("Zoom", " actionDown");
if ( scale > MIN_ZOOM){
mode = Mode.DRAG;
startX = ev.getX() - prevDx;
startY = ev.getY() - prevDy;
}
return false; //go to child layout
case MotionEvent.ACTION_POINTER_DOWN:
mode = Mode.ZOOM;
return true;
case MotionEvent.ACTION_UP:
long clickDuration = System.currentTimeMillis() - startClickTime;
mode = Mode.NONE;
if(clickDuration < MAX_CLICK_DURATION){
return false;
}
else {
// letting go from drag or zooming
return true;
}
case MotionEvent.ACTION_MOVE:
clickDuration = System.currentTimeMillis() - startClickTime;
if (clickDuration > MAX_CLICK_DURATION){
return true;
}
else {
return false;
}
}
return false;
}
In my child layout for click feature:
switch (motionEvent.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
// primary finger down
return true;
case MotionEvent.ACTION_POINTER_DOWN:
// non-primary finger down
return false;
case MotionEvent.ACTION_CANCEL:
return false;
case MotionEvent.ACTION_UP:
// primary finder up
Intent intent = new Intent(context, DeviceActivity.class);
context.startActivity(intent);
return true;
case MotionEvent.ACTION_POINTER_UP:
// non-primary finger up
return false;
}
So is there a way to distinguish drag and click.