Last active
December 16, 2021 16:42
-
-
Save pflammertsma/8733d46fa5c3ad5813ab3e083bceeb5a to your computer and use it in GitHub Desktop.
Sample of DragStartHelper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Copyright 2021 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 */ | |
// Make a view draggable to share a file. DragStartHelper takes care of | |
// intercepting drag gestures and attaching the listener. | |
DragStartHelper(draggableView) { view, _ -> | |
// Sets the appropriate MIME types automatically. | |
val dragClipData = ClipData.newUri(contentResolver, "File", fileUri) | |
// Set the visual look of the dragged object. | |
// Can be extended and customized; we use the default here. | |
val dragShadow = View.DragShadowBuilder(view) | |
// Starts the drag. Note that the global flag allows for cross-app dragging. | |
view.startDragAndDrop( | |
dragClipData, | |
dragShadow, | |
null, // Optional extra local state information | |
// Since this is a "content:" URI and not just plain text, we can use the | |
// DRAG_FLAG_GLOBAL_URI_READ to allow other apps to read from our content | |
// provider. Without it, other apps won't receive the drag events. | |
DRAG_FLAG_GLOBAL or DRAG_FLAG_GLOBAL_URI_READ) | |
) | |
}.attach() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment