I knows its too late, but if someone is struggling with this for a clean solution, here it is.
These are used for measuring the time between touching and removing the finger.
private long clickTime = 0;
public static final long CLICK_TIMEOUT = 200; // 200ms
This my onTouchListner
. Works like a charm
private final View.OnTouchListener onTouchListener = (v, event) -> {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
clickTime = System.currentTimeMillis();
return true;
} else if(event.getAction() == MotionEvent.ACTION_UP) {
if(System.currentTimeMillis()-clickTime < Constants.CLICK_TIMEOUT)
{
Toast.makeText(getContext(), "clicked", Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
else if(event.getAction() == MotionEvent.ACTION_MOVE){
if(System.currentTimeMillis()-clickTime > Constants.CLICK_TIMEOUT)
{
ClipData data = ClipData.newPlainText("" , "");
View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(v);
v.startDrag(data , shadowBuilder , v , 0);
return false;
}
return false;
}
return false;
};