Im using view.startDrag()
to start dragging operation. While dragging, events are received in OnDragListener
. Also im using DragShadowBuilder
to show the last image of View B
while dragging.
Is there a way to stop or cancel or abort dragging from some external events or operation? for example, there are 2 view, View A
and View B
, i'm dragging View B
over View A
. While dragging, due to some external event or operation, i want to cancel dragging operations or cancel OnDragListener
(without removing my finger from the view B
).
Code Snippet for DragShadowBuilder
:
DragShadowBuilder shadowBuilder = new DragShadowBuilder(view) {
@Override
public void onDrawShadow(Canvas canvas) {
canvas.drawBitmap(b, 0, 0, new Paint());
super.onDrawShadow(canvas);
}
};
boolean dragSuccess = false;
dragSuccess = view.startDrag(null, shadowBuilder, view, 0);
Code Snippet for OnDragListener
:
private final class ViewDragListener implements OnDragListener {
@Override
public boolean onDrag(View v, DragEvent event) {
int action = event.getAction();
switch (event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
log("ACTION_DRAG_STARTED");
break;
case DragEvent.ACTION_DRAG_ENTERED:
log("ACTION_DRAG_ENTERED");
break;
case DragEvent.ACTION_DRAG_EXITED:
log("ACTION_DRAG_EXITED");
case DragEvent.ACTION_DROP:
log("ACTION_DROP");
mX = (int) event.getX();
mY = (int)event.getY();
break;
case DragEvent.ACTION_DRAG_ENDED:
log("ACTION_DRAG_ENDED");
//Doing some cleanup operations.
break;
case DragEvent.ACTION_DRAG_LOCATION:
log("ACTION_DRAG_LOCATION");
break;
default:
break;
}
return true;
}
}