Example usage for android.os PersistableBundle PersistableBundle

List of usage examples for android.os PersistableBundle PersistableBundle

Introduction

In this page you can find the example usage for android.os PersistableBundle PersistableBundle.

Prototype

PersistableBundle(boolean doInit) 

Source Link

Document

Constructs a PersistableBundle without initializing it.

Usage

From source file:com.example.android.dragsource.DragSourceFragment.java

private void setUpDraggableImage(ImageView imageView, final Uri imageUri) {

    // Set up a listener that starts the drag and drop event with flags and extra data.
    DragStartHelper.OnDragStartListener listener = new DragStartHelper.OnDragStartListener() {
        @Override// w ww  . ja  va2s.  c  o  m
        public boolean onDragStart(View view, final DragStartHelper helper) {
            Log.d(TAG, "Drag start event received from helper.");

            // Use a DragShadowBuilder
            View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view) {
                @Override
                public void onProvideShadowMetrics(Point shadowSize, Point shadowTouchPoint) {
                    super.onProvideShadowMetrics(shadowSize, shadowTouchPoint);
                    // Notify the DragStartHelper of point where the view was touched.
                    helper.getTouchPosition(shadowTouchPoint);
                    Log.d(TAG, "View was touched at: " + shadowTouchPoint);
                }
            };

            // Set up the flags for the drag event.
            // Enable drag and drop across apps (global)
            // and require read permissions for this URI.
            int flags = View.DRAG_FLAG_GLOBAL | View.DRAG_FLAG_GLOBAL_URI_READ;

            // Add an optional clip description that that contains an extra String that is
            // read out by the target app.
            final ClipDescription clipDescription = new ClipDescription("",
                    new String[] { getContext().getContentResolver().getType(imageUri) });
            // Extras are stored within a PersistableBundle.
            PersistableBundle extras = new PersistableBundle(1);
            // Add a String that the target app will display.
            extras.putString(EXTRA_IMAGE_INFO, "Drag Started at " + new Date());
            clipDescription.setExtras(extras);

            // The ClipData object describes the object that is being dragged and dropped.
            final ClipData clipData = new ClipData(clipDescription, new ClipData.Item(imageUri));

            Log.d(TAG, "Created ClipDescription. Starting drag and drop.");
            // Start the drag and drop event.
            return view.startDragAndDrop(clipData, shadowBuilder, null, flags);

        }

    };

    // Use the DragStartHelper to detect drag and drop events and use the OnDragStartListener
    // defined above to start the event when it has been detected.
    DragStartHelper helper = new DragStartHelper(imageView, listener);
    helper.attach();
    Log.d(TAG, "DragStartHelper attached to view.");
}