当前位置: 首页>>代码示例>>Java>>正文


Java DragEvent.getClipDescription方法代码示例

本文整理汇总了Java中android.view.DragEvent.getClipDescription方法的典型用法代码示例。如果您正苦于以下问题:Java DragEvent.getClipDescription方法的具体用法?Java DragEvent.getClipDescription怎么用?Java DragEvent.getClipDescription使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.view.DragEvent的用法示例。


在下文中一共展示了DragEvent.getClipDescription方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: validateDrag

import android.view.DragEvent; //导入方法依赖的package包/类
/**
 * Tests to see if the drop will be accepted by Launcher, and if so, includes additional data
 * in the returned structure related to the widgets that match the drop (or a null list if it is
 * a shortcut drop).  If the drop is not accepted then a null structure is returned.
 */
private Pair<Integer, List<WidgetMimeTypeHandlerData>> validateDrag(DragEvent event) {
    final LauncherModel model = mLauncher.getModel();
    final ClipDescription desc = event.getClipDescription();
    final int mimeTypeCount = desc.getMimeTypeCount();
    for (int i = 0; i < mimeTypeCount; ++i) {
        final String mimeType = desc.getMimeType(i);
        if (mimeType.equals(InstallShortcutReceiver.SHORTCUT_MIMETYPE)) {
            return new Pair<Integer, List<WidgetMimeTypeHandlerData>>(i, null);
        } else {
            final List<WidgetMimeTypeHandlerData> widgets =
                model.resolveWidgetsForMimeType(mContext, mimeType);
            if (widgets.size() > 0) {
                return new Pair<Integer, List<WidgetMimeTypeHandlerData>>(i, widgets);
            }
        }
    }
    return null;
}
 
开发者ID:pengqinping,项目名称:androidProject,代码行数:24,代码来源:Workspace.java

示例2: processDragStarted

import android.view.DragEvent; //导入方法依赖的package包/类
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;
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:10,代码来源:ContentFragment.java

示例3: handleSystemDragStart

import android.view.DragEvent; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.N)
private void handleSystemDragStart(DragEvent event) {
    if (!FeatureFlags.LAUNCHER3_USE_SYSTEM_DRAG_DRIVER || !Utilities.isNycOrAbove()) {
        return;
    }
    if (mLauncher.isWorkspaceLocked()) {
        return;
    }

    ClipDescription description = event.getClipDescription();
    if (!description.hasMimeType(ClipDescription.MIMETYPE_TEXT_INTENT)) {
        return;
    }
    ShortcutInfo info = new ShortcutInfo();
    // Set a dummy intent until we get the final value
    info.intent = new Intent();

    // Since we are not going through the workspace for starting the drag, set drag related
    // information on the workspace before starting the drag.
    ExternalDragPreviewProvider previewProvider =
            new ExternalDragPreviewProvider(mLauncher, info);
    mLauncher.getWorkspace().prepareDragWithProvider(previewProvider);

    DragOptions options = new DragOptions();
    options.systemDndStartPoint = new Point((int) event.getX(), (int) event.getY());

    int halfPadding = previewProvider.previewPadding / 2;
    mDragController.startDrag(
            Bitmap.createBitmap(1, 1, Config.ARGB_8888),
            0, 0,
            new AnotherWindowDragSource(mLauncher), info,
            new Point(- halfPadding, halfPadding),
            previewProvider.getPreviewBounds(), 1f, options);
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:35,代码来源:DragLayer.java

示例4: onDragStart

import android.view.DragEvent; //导入方法依赖的package包/类
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;
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:51,代码来源:PinItemDragListener.java

示例5: onDragEvent

import android.view.DragEvent; //导入方法依赖的package包/类
@Override
public boolean onDragEvent(@NonNull DragEvent event) {
    PlenProgramAdapter adapter = mAdapter.orElseThrow(AssertionError::new);

    ClipDescription clipDescription = event.getClipDescription();
    if (clipDescription == null || !DRAG_DATA_LABEL.equals(clipDescription.getLabel())) {
        return false;
    }

    int x = (int) event.getX();
    int y = (int) event.getY();
    int position = pointToPosition(x, y);

    switch (event.getAction()) {
        case DragEvent.ACTION_DRAG_ENTERED:
            if (adapter.positionOfBlankRow() == INVALID_POSITION) {
                adapter.moveBlankRowToLast();
            }
            break;

        case DragEvent.ACTION_DRAG_LOCATION:
            removeCallbacks(mRemoveBlankRowCallback);
            // ドロップ予定地に空白行
            if (position != INVALID_POSITION) {
                View view = getChildAt(position - getFirstVisiblePosition());
                double viewCenter = view.getY() + view.getHeight() / 2.;
                if (Math.abs(y - viewCenter) < view.getHeight() / 2.) {
                    adapter.moveBlankRow(position);
                }
            }
            // 端にドラッグすると自動スクロール
            View child = getChildAt(0);
            double scrollZone = child != null ? child.getHeight() : 0;
            final int firstPosition = getFirstVisiblePosition();
            final int lastPosition = getLastVisiblePosition();
            if (y < scrollZone) smoothScrollToPosition(firstPosition - 1);
            if (y > getHeight() - scrollZone) smoothScrollToPosition(lastPosition + 1);
            break;

        case DragEvent.ACTION_DROP:
            getDragData(event.getClipData()).ifPresent(adapter::dropToBlankRow);
            break;

        case DragEvent.ACTION_DRAG_ENDED:
        case DragEvent.ACTION_DRAG_EXITED:
            adapter.removeBlankRow();
            break;
    }
    return true;
}
 
开发者ID:plenprojectcompany,项目名称:plen-Scenography_Android,代码行数:51,代码来源:PlenProgramView.java

示例6: onDragEvent

import android.view.DragEvent; //导入方法依赖的package包/类
/**
 * @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;
}
 
开发者ID:mogoweb,项目名称:365browser,代码行数:49,代码来源:ContentViewCore.java


注:本文中的android.view.DragEvent.getClipDescription方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。