AppsCustomizePagedView.java 文件源码

java
阅读 26 收藏 0 点赞 0 评论 0

项目:androidProject 作者:
private void beginDraggingWidget(View v) {
    // Get the widget preview as the drag representation
    ImageView image = (ImageView) v.findViewById(R.id.widget_preview);
    PendingAddItemInfo createItemInfo = (PendingAddItemInfo) v.getTag();

    // Compose the drag image
    Bitmap b;
    Drawable preview = image.getDrawable();
    RectF mTmpScaleRect = new RectF(0f,0f,1f,1f);
    image.getImageMatrix().mapRect(mTmpScaleRect);
    float scale = mTmpScaleRect.right;
    int w = (int) (preview.getIntrinsicWidth() * scale);
    int h = (int) (preview.getIntrinsicHeight() * scale);
    if (createItemInfo instanceof PendingAddWidgetInfo) {
        PendingAddWidgetInfo createWidgetInfo = (PendingAddWidgetInfo) createItemInfo;
        int[] spanXY = mLauncher.getSpanForWidget(createWidgetInfo, null);
        createItemInfo.spanX = spanXY[0];
        createItemInfo.spanY = spanXY[1];

        b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
        renderDrawableToBitmap(preview, b, 0, 0, w, h, scale, mDragViewMultiplyColor);
    } else {
        // Workaround for the fact that we don't keep the original ResolveInfo associated with
        // the shortcut around.  To get the icon, we just render the preview image (which has
        // the shortcut icon) to a new drag bitmap that clips the non-icon space.
        b = Bitmap.createBitmap(mWidgetPreviewIconPaddedDimension,
                mWidgetPreviewIconPaddedDimension, Bitmap.Config.ARGB_8888);
        mCanvas.setBitmap(b);
        mCanvas.save();
        preview.draw(mCanvas);
        mCanvas.restore();
        mCanvas.drawColor(mDragViewMultiplyColor, PorterDuff.Mode.MULTIPLY);
        mCanvas.setBitmap(null);
        createItemInfo.spanX = createItemInfo.spanY = 1;
    }

    // We use a custom alpha clip table for the default widget previews
    Paint alphaClipPaint = null;
    if (createItemInfo instanceof PendingAddWidgetInfo) {
        if (((PendingAddWidgetInfo) createItemInfo).hasDefaultPreview) {
            MaskFilter alphaClipTable = TableMaskFilter.CreateClipTable(0, 255);
            alphaClipPaint = new Paint();
            alphaClipPaint.setMaskFilter(alphaClipTable);
        }
    }

    // Start the drag
    mLauncher.lockScreenOrientationOnLargeUI();
    mLauncher.getWorkspace().onDragStartedWithItemSpans(createItemInfo.spanX,
            createItemInfo.spanY, b, alphaClipPaint);
    mDragController.startDrag(image, b, this, createItemInfo,
            DragController.DRAG_ACTION_COPY, null);
    b.recycle();
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号