am e431b97c: Merge "Fixed Drag-and-Drop sample code"
* commit 'e431b97c1f1692a42c9a348a5ff930f82eee2537': Fixed Drag-and-Drop sample code
This commit is contained in:
@@ -873,7 +873,7 @@ imageView.setOnDragListener(mDragListen);
|
|||||||
|
|
||||||
...
|
...
|
||||||
|
|
||||||
protected class myDragEventListener implements View.OnDragEventListener {
|
protected class myDragEventListener implements View.OnDragListener {
|
||||||
|
|
||||||
// This is the method that the system calls when it dispatches a drag event to the
|
// This is the method that the system calls when it dispatches a drag event to the
|
||||||
// listener.
|
// listener.
|
||||||
@@ -901,16 +901,13 @@ protected class myDragEventListener implements View.OnDragEventListener {
|
|||||||
// returns true to indicate that the View can accept the dragged data.
|
// returns true to indicate that the View can accept the dragged data.
|
||||||
return(true);
|
return(true);
|
||||||
|
|
||||||
} else {
|
}
|
||||||
|
|
||||||
// Returns false. During the current drag and drop operation, this View will
|
// Returns false. During the current drag and drop operation, this View will
|
||||||
// not receive events again until ACTION_DRAG_ENDED is sent.
|
// not receive events again until ACTION_DRAG_ENDED is sent.
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
}
|
case DragEvent.ACTION_DRAG_ENTERED:
|
||||||
break;
|
|
||||||
|
|
||||||
case DragEvent.ACTION_DRAG_ENTERED: {
|
|
||||||
|
|
||||||
// Applies a green tint to the View. Return true; the return value is ignored.
|
// Applies a green tint to the View. Return true; the return value is ignored.
|
||||||
|
|
||||||
@@ -921,77 +918,68 @@ protected class myDragEventListener implements View.OnDragEventListener {
|
|||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
|
|
||||||
break;
|
case DragEvent.ACTION_DRAG_LOCATION:
|
||||||
|
|
||||||
case DragEvent.ACTION_DRAG_LOCATION:
|
|
||||||
|
|
||||||
// Ignore the event
|
// Ignore the event
|
||||||
return(true);
|
return(true);
|
||||||
|
|
||||||
|
case DragEvent.ACTION_DRAG_EXITED:
|
||||||
|
|
||||||
|
// Re-sets the color tint to blue. Returns true; the return value is ignored.
|
||||||
|
v.setColorFilter(Color.BLUE);
|
||||||
|
|
||||||
|
// Invalidate the view to force a redraw in the new tint
|
||||||
|
v.invalidate();
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
|
||||||
|
case DragEvent.ACTION_DROP:
|
||||||
|
|
||||||
|
// Gets the item containing the dragged data
|
||||||
|
ClipData.Item item = event.getClipData().getItemAt(0);
|
||||||
|
|
||||||
|
// Gets the text data from the item.
|
||||||
|
dragData = item.getText();
|
||||||
|
|
||||||
|
// Displays a message containing the dragged data.
|
||||||
|
Toast.makeText(this, "Dragged data is " + dragData, Toast.LENGTH_LONG);
|
||||||
|
|
||||||
|
// Turns off any color tints
|
||||||
|
v.clearColorFilter();
|
||||||
|
|
||||||
|
// Invalidates the view to force a redraw
|
||||||
|
v.invalidate();
|
||||||
|
|
||||||
|
// Returns true. DragEvent.getResult() will return true.
|
||||||
|
return(true);
|
||||||
|
|
||||||
|
case DragEvent.ACTION_DRAG_ENDED:
|
||||||
|
|
||||||
|
// Turns off any color tinting
|
||||||
|
v.clearColorFilter();
|
||||||
|
|
||||||
|
// Invalidates the view to force a redraw
|
||||||
|
v.invalidate();
|
||||||
|
|
||||||
|
// Does a getResult(), and displays what happened.
|
||||||
|
if (event.getResult()) {
|
||||||
|
Toast.makeText(this, "The drop was handled.", Toast.LENGTH_LONG);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
Toast.makeText(this, "The drop didn't work.", Toast.LENGTH_LONG);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns true; the value is ignored.
|
||||||
|
return(true);
|
||||||
|
|
||||||
|
// An unknown action type was received.
|
||||||
|
default:
|
||||||
|
Log.e("DragDrop Example","Unknown action type received by OnDragListener.");
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case DragEvent.ACTION_DRAG_EXITED:
|
|
||||||
|
return(false);
|
||||||
// Re-sets the color tint to blue. Returns true; the return value is ignored.
|
}
|
||||||
v.setColorFilter(Color.BLUE);
|
|
||||||
|
|
||||||
// Invalidate the view to force a redraw in the new tint
|
|
||||||
v.invalidate();
|
|
||||||
|
|
||||||
return(true);
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DragEvent.ACTION_DROP:
|
|
||||||
|
|
||||||
// Gets the item containing the dragged data
|
|
||||||
ClipData.Item item = event.getClipData().getItemAt(0);
|
|
||||||
|
|
||||||
// Gets the text data from the item.
|
|
||||||
dragData = item.getText();
|
|
||||||
|
|
||||||
// Displays a message containing the dragged data.
|
|
||||||
Toast.makeText(this, "Dragged data is " + dragData, Toast.LENGTH_LONG);
|
|
||||||
|
|
||||||
// Turns off any color tints
|
|
||||||
v.clearColorFilter();
|
|
||||||
|
|
||||||
// Invalidates the view to force a redraw
|
|
||||||
v.invalidate();
|
|
||||||
|
|
||||||
// Returns true. DragEvent.getResult() will return true.
|
|
||||||
return(true);
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DragEvent.ACTION_DRAG_ENDED:
|
|
||||||
|
|
||||||
// Turns off any color tinting
|
|
||||||
v.clearColorFilter();
|
|
||||||
|
|
||||||
// Invalidates the view to force a redraw
|
|
||||||
v.invalidate();
|
|
||||||
|
|
||||||
// Does a getResult(), and displays what happened.
|
|
||||||
if (event.getResult()) {
|
|
||||||
Toast.makeText(this, "The drop was handled.", Toast.LENGTH_LONG);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Toast.makeText(this, "The drop didn't work.", Toast.LENGTH_LONG);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
// returns true; the value is ignored.
|
|
||||||
return(true);
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
// An unknown action type was received.
|
|
||||||
default:
|
|
||||||
Log.e("DragDrop Example","Unknown action type received by OnDragListener.");
|
|
||||||
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
</pre>
|
</pre>
|
||||||
|
|||||||
Reference in New Issue
Block a user