Java Code Examples for android.view.DragEvent#getClipDescription()
The following examples show how to use
android.view.DragEvent#getClipDescription() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DropTargetFragment.java From user-interface-samples with Apache License 2.0 | 5 votes |
@Override public boolean onDrag(View view, DragEvent event) { // DragTarget is peeking into the MIME types of the dragged event in order to ignore // non-image drags completely. // DragSource does not do that but rejects non-image content once a drop has happened. ClipDescription clipDescription = event.getClipDescription(); if (clipDescription != null && !clipDescription.hasMimeType("image/*")) { return false; } // Callback received when image is being dragged. return super.onDrag(view, event); }
Example 2
Source File: DropTargetFragment.java From user-interface-samples with Apache License 2.0 | 5 votes |
/** * DragEvents can contain additional data packaged in a {@link PersistableBundle}. * Extract the extras from the event and return the String stored for the * {@link #EXTRA_IMAGE_INFO} entry. */ private String getExtra(DragEvent event) { // The extras are contained in the ClipDescription in the DragEvent. ClipDescription clipDescription = event.getClipDescription(); if (clipDescription != null) { PersistableBundle extras = clipDescription.getExtras(); if (extras != null) { return extras.getString(EXTRA_IMAGE_INFO); } } return null; }
Example 3
Source File: DropTargetFragment.java From android-DragAndDropAcrossApps with Apache License 2.0 | 5 votes |
@Override public boolean onDrag(View view, DragEvent event) { // DragTarget is peeking into the MIME types of the dragged event in order to ignore // non-image drags completely. // DragSource does not do that but rejects non-image content once a drop has happened. ClipDescription clipDescription = event.getClipDescription(); if (clipDescription != null && !clipDescription.hasMimeType("image/*")) { return false; } // Callback received when image is being dragged. return super.onDrag(view, event); }
Example 4
Source File: DropTargetFragment.java From android-DragAndDropAcrossApps with Apache License 2.0 | 5 votes |
/** * DragEvents can contain additional data packaged in a {@link PersistableBundle}. * Extract the extras from the event and return the String stored for the * {@link #EXTRA_IMAGE_INFO} entry. */ private String getExtra(DragEvent event) { // The extras are contained in the ClipDescription in the DragEvent. ClipDescription clipDescription = event.getClipDescription(); if (clipDescription != null) { PersistableBundle extras = clipDescription.getExtras(); if (extras != null) { return extras.getString(EXTRA_IMAGE_INFO); } } return null; }
Example 5
Source File: ContentFragment.java From androidtestdebug with MIT License | 5 votes |
boolean processDragStarted(DragEvent event) { // Determine whether to continue processing drag and drop based on the // plain text mime type. ClipDescription clipDesc = event.getClipDescription(); if (clipDesc != null) { return clipDesc.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN); } return false; }
Example 6
Source File: ContentFragment.java From androidtestdebug with MIT License | 5 votes |
boolean processDragStarted(DragEvent event) { // Determine whether to continue processing drag and drop based on the // plain text mime type. ClipDescription clipDesc = event.getClipDescription(); if (clipDesc != null) { return clipDesc.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN); } return false; }
Example 7
Source File: ContentFragment.java From androidtestdebug with MIT License | 5 votes |
boolean processDragStarted(DragEvent event) { // Determine whether to continue processing drag and drop based on the // plain text mime type. ClipDescription clipDesc = event.getClipDescription(); if (clipDesc != null) { return clipDesc.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN); } return false; }
Example 8
Source File: ContentFragment.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
boolean processDragStarted(DragEvent event) { // Determine whether to continue processing drag and drop based on the // plain text mime type. ClipDescription clipDesc = event.getClipDescription(); if (clipDesc != null) { return clipDesc.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN); } return false; }
Example 9
Source File: ContentFragment.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
boolean processDragStarted(DragEvent event) { // Determine whether to continue processing drag and drop based on the // plain text mime type. ClipDescription clipDesc = event.getClipDescription(); if (clipDesc != null) { return clipDesc.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN); } return false; }
Example 10
Source File: PinItemDragListener.java From LaunchEnr with GNU General Public License v3.0 | 4 votes |
private boolean onDragStart(DragEvent event) { if (!mRequest.isValid()) { return false; } ClipDescription desc = event.getClipDescription(); if (desc == null || !desc.hasMimeType(getMimeType())) { return false; } final PendingAddItemInfo item; if (mRequest.getRequestType() == PinItemRequestCompat.REQUEST_TYPE_SHORTCUT) { item = new PendingAddShortcutInfo( new PinShortcutRequestActivityInfo(mRequest, mLauncher)); } else { // mRequest.getRequestType() == PinItemRequestCompat.REQUEST_TYPE_APPWIDGET LauncherAppWidgetProviderInfo providerInfo = LauncherAppWidgetProviderInfo.fromProviderInfo( mLauncher, mRequest.getAppWidgetProviderInfo(mLauncher)); final PinWidgetFlowHandler flowHandler = new PinWidgetFlowHandler(providerInfo, mRequest); item = new PendingAddWidgetInfo(providerInfo) { @Override public WidgetAddFlowHandler getHandler() { return flowHandler; } }; } View view = new View(mLauncher); view.setTag(item); Point downPos = new Point((int) event.getX(), (int) event.getY()); DragOptions options = new DragOptions(); options.systemDndStartPoint = downPos; options.preDragCondition = this; // We use drag event position as the screenPos for the preview image. Since mPreviewRect // already includes the view position relative to the drag event on the source window, // and the absolute position (position relative to the screen) of drag event is same // across windows, using drag position here give a good estimate for relative position // to source window. PendingItemDragHelper dragHelper = new PendingItemDragHelper(view); if (mRequest.getRequestType() == PinItemRequestCompat.REQUEST_TYPE_APPWIDGET) { dragHelper.setPreview(getPreview(mRequest)); } dragHelper.startDrag(new Rect(mPreviewRect), mPreviewBitmapWidth, mPreviewViewWidth, downPos, this, options); mDragStartTime = SystemClock.uptimeMillis(); return true; }
Example 11
Source File: ContentViewCore.java From 365browser with Apache License 2.0 | 4 votes |
/** * @see View#onDragEvent(DragEvent) */ @TargetApi(Build.VERSION_CODES.N) public boolean onDragEvent(DragEvent event) { if (mNativeContentViewCore == 0 || Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) { return false; } ClipDescription clipDescription = event.getClipDescription(); // text/* will match text/uri-list, text/html, text/plain. String[] mimeTypes = clipDescription == null ? new String[0] : clipDescription.filterMimeTypes("text/*"); if (event.getAction() == DragEvent.ACTION_DRAG_STARTED) { // TODO(hush): support dragging more than just text. return mimeTypes != null && mimeTypes.length > 0 && nativeIsTouchDragDropEnabled(mNativeContentViewCore); } StringBuilder content = new StringBuilder(""); if (event.getAction() == DragEvent.ACTION_DROP) { // TODO(hush): obtain dragdrop permissions, when dragging files into Chrome/WebView is // supported. Not necessary to do so for now, because only text dragging is supported. ClipData clipData = event.getClipData(); final int itemCount = clipData.getItemCount(); for (int i = 0; i < itemCount; i++) { ClipData.Item item = clipData.getItemAt(i); content.append(item.coerceToStyledText(mContainerView.getContext())); } } int[] locationOnScreen = new int[2]; mContainerView.getLocationOnScreen(locationOnScreen); float xPix = event.getX() + mCurrentTouchOffsetX; float yPix = event.getY() + mCurrentTouchOffsetY; int xCss = (int) mRenderCoordinates.fromPixToDip(xPix); int yCss = (int) mRenderCoordinates.fromPixToDip(yPix); int screenXCss = (int) mRenderCoordinates.fromPixToDip(xPix + locationOnScreen[0]); int screenYCss = (int) mRenderCoordinates.fromPixToDip(yPix + locationOnScreen[1]); nativeOnDragEvent(mNativeContentViewCore, event.getAction(), xCss, yCss, screenXCss, screenYCss, mimeTypes, content.toString()); return true; }