Search in sources :

Example 36 with FastBitmapDrawable

use of com.android.launcher3.FastBitmapDrawable in project android_packages_apps_404Launcher by P-404.

the class PendingItemDragHelper method startDrag.

/**
 * Starts the drag for the pending item associated with the view.
 *
 * @param previewBounds The bounds where the image was displayed,
 *                      {@link WidgetImageView#getBitmapBounds()}
 * @param previewBitmapWidth The actual width of the bitmap displayed in the view.
 * @param previewViewWidth The width of {@link WidgetImageView} displaying the preview
 * @param screenPos Position of {@link WidgetImageView} on the screen
 */
public void startDrag(Rect previewBounds, int previewBitmapWidth, int previewViewWidth, Point screenPos, DragSource source, DragOptions options) {
    if (TestProtocol.sDebugTracing) {
        Log.d(TestProtocol.NO_DROP_TARGET, "3");
    }
    final Launcher launcher = Launcher.getLauncher(mView.getContext());
    LauncherAppState app = LauncherAppState.getInstance(launcher);
    Drawable preview = null;
    final int previewWidth;
    final int previewHeight;
    final float scale;
    final Point dragOffset;
    final Rect dragRegion;
    mEstimatedCellSize = launcher.getWorkspace().estimateItemSize(mAddInfo);
    DraggableView draggableView;
    if (mAddInfo instanceof PendingAddWidgetInfo) {
        PendingAddWidgetInfo createWidgetInfo = (PendingAddWidgetInfo) mAddInfo;
        int maxWidth = Math.min((int) (previewBitmapWidth * MAX_WIDGET_SCALE), mEstimatedCellSize[0]);
        int[] previewSizeBeforeScale = new int[1];
        if (mRemoteViewsPreview != null) {
            mAppWidgetHostViewPreview = new LauncherAppWidgetHostView(launcher);
            mAppWidgetHostViewPreview.setAppWidget(/* appWidgetId= */
            -1, ((PendingAddWidgetInfo) mAddInfo).info);
            DeviceProfile deviceProfile = launcher.getDeviceProfile();
            Rect padding = new Rect();
            mAppWidgetHostViewPreview.getWidgetInset(deviceProfile, padding);
            mAppWidgetHostViewPreview.setPadding(padding.left, padding.top, padding.right, padding.bottom);
            mAppWidgetHostViewPreview.updateAppWidget(/* remoteViews= */
            mRemoteViewsPreview);
            Size widgetSizes = WidgetSizes.getWidgetPaddedSizePx(launcher, mAddInfo.componentName, deviceProfile, mAddInfo.spanX, mAddInfo.spanY);
            mAppWidgetHostViewPreview.measure(MeasureSpec.makeMeasureSpec(widgetSizes.getWidth(), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(widgetSizes.getHeight(), MeasureSpec.EXACTLY));
            mAppWidgetHostViewPreview.setClipChildren(false);
            mAppWidgetHostViewPreview.setClipToPadding(false);
            mAppWidgetHostViewPreview.setScaleToFit(mRemoteViewsPreviewScale);
        }
        if (mAppWidgetHostViewPreview != null) {
            previewSizeBeforeScale[0] = mAppWidgetHostViewPreview.getMeasuredWidth();
            launcher.getDragController().addDragListener(new AppWidgetHostViewDragListener(launcher));
        }
        if (preview == null && mAppWidgetHostViewPreview == null) {
            Drawable p = new FastBitmapDrawable(new DatabaseWidgetPreviewLoader(launcher).generateWidgetPreview(createWidgetInfo.info, maxWidth, previewSizeBeforeScale));
            if (RoundedCornerEnforcement.isRoundedCornerEnabled()) {
                p = new RoundDrawableWrapper(p, mEnforcedRoundedCornersForWidget);
            }
            preview = p;
        }
        if (previewSizeBeforeScale[0] < previewBitmapWidth) {
            // The icon has extra padding around it.
            int padding = (previewBitmapWidth - previewSizeBeforeScale[0]) / 2;
            if (previewBitmapWidth > previewViewWidth) {
                padding = padding * previewViewWidth / previewBitmapWidth;
            }
            previewBounds.left += padding;
            previewBounds.right -= padding;
        }
        if (mAppWidgetHostViewPreview != null) {
            previewWidth = mAppWidgetHostViewPreview.getMeasuredWidth();
            previewHeight = mAppWidgetHostViewPreview.getMeasuredHeight();
        } else {
            previewWidth = preview.getIntrinsicWidth();
            previewHeight = preview.getIntrinsicHeight();
        }
        scale = previewBounds.width() / (float) previewWidth;
        launcher.getDragController().addDragListener(new WidgetHostViewLoader(launcher, mView));
        dragOffset = null;
        dragRegion = null;
        draggableView = DraggableView.ofType(DraggableView.DRAGGABLE_WIDGET);
    } else {
        PendingAddShortcutInfo createShortcutInfo = (PendingAddShortcutInfo) mAddInfo;
        Drawable icon = createShortcutInfo.activityInfo.getFullResIcon(app.getIconCache());
        LauncherIcons li = LauncherIcons.obtain(launcher);
        preview = new FastBitmapDrawable(li.createScaledBitmapWithoutShadow(icon, 0));
        previewWidth = preview.getIntrinsicWidth();
        previewHeight = preview.getIntrinsicHeight();
        li.recycle();
        scale = ((float) launcher.getDeviceProfile().iconSizePx) / previewWidth;
        dragOffset = new Point(previewPadding / 2, previewPadding / 2);
        // Create a preview same as the workspace cell size and draw the icon at the
        // appropriate position.
        DeviceProfile dp = launcher.getDeviceProfile();
        int iconSize = dp.iconSizePx;
        int padding = launcher.getResources().getDimensionPixelSize(R.dimen.widget_preview_shortcut_padding);
        previewBounds.left += padding;
        previewBounds.top += padding;
        dragRegion = new Rect();
        dragRegion.left = (mEstimatedCellSize[0] - iconSize) / 2;
        dragRegion.right = dragRegion.left + iconSize;
        dragRegion.top = (mEstimatedCellSize[1] - iconSize - dp.iconTextSizePx - dp.iconDrawablePaddingPx) / 2;
        dragRegion.bottom = dragRegion.top + iconSize;
        draggableView = DraggableView.ofType(DraggableView.DRAGGABLE_ICON);
    }
    int dragLayerX = screenPos.x + previewBounds.left + (int) ((scale * previewWidth - previewWidth) / 2);
    int dragLayerY = screenPos.y + previewBounds.top + (int) ((scale * previewHeight - previewHeight) / 2);
    // Start the drag
    if (mAppWidgetHostViewPreview != null) {
        launcher.getDragController().startDrag(mAppWidgetHostViewPreview, draggableView, dragLayerX, dragLayerY, source, mAddInfo, dragOffset, dragRegion, scale, scale, options);
    } else {
        launcher.getDragController().startDrag(preview, draggableView, dragLayerX, dragLayerY, source, mAddInfo, dragOffset, dragRegion, scale, scale, options);
    }
}
Also used : Rect(android.graphics.Rect) LauncherAppState(com.android.launcher3.LauncherAppState) Size(android.util.Size) Drawable(android.graphics.drawable.Drawable) FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) RoundDrawableWrapper(com.android.launcher3.icons.RoundDrawableWrapper) Point(android.graphics.Point) DraggableView(com.android.launcher3.dragndrop.DraggableView) Point(android.graphics.Point) Paint(android.graphics.Paint) FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) DeviceProfile(com.android.launcher3.DeviceProfile) AppWidgetHostViewDragListener(com.android.launcher3.widget.dragndrop.AppWidgetHostViewDragListener) LauncherIcons(com.android.launcher3.icons.LauncherIcons) Launcher(com.android.launcher3.Launcher)

Example 37 with FastBitmapDrawable

use of com.android.launcher3.FastBitmapDrawable in project android_packages_apps_404Launcher by P-404.

the class WidgetCell method applyPreview.

private void applyPreview(Bitmap bitmap) {
    if (bitmap != null) {
        Drawable drawable = new RoundDrawableWrapper(new FastBitmapDrawable(bitmap), mEnforcedCornerRadius);
        // Scale down the preview size if it's wider than the cell.
        float scale = 1f;
        if (mTargetPreviewWidth > 0) {
            float maxWidth = mTargetPreviewWidth;
            float previewWidth = drawable.getIntrinsicWidth() * mPreviewContainerScale;
            scale = Math.min(maxWidth / previewWidth, 1);
        }
        setContainerSize(Math.round(drawable.getIntrinsicWidth() * scale * mPreviewContainerScale), Math.round(drawable.getIntrinsicHeight() * scale * mPreviewContainerScale));
        mWidgetImage.setDrawable(drawable);
        mWidgetImage.setVisibility(View.VISIBLE);
        if (mAppWidgetHostViewPreview != null) {
            removeView(mAppWidgetHostViewPreview);
            mAppWidgetHostViewPreview = null;
        }
    }
    if (mAnimatePreview) {
        mWidgetImageContainer.setAlpha(0f);
        ViewPropertyAnimator anim = mWidgetImageContainer.animate();
        anim.alpha(1.0f).setDuration(FADE_IN_DURATION_MS);
    } else {
        mWidgetImageContainer.setAlpha(1f);
    }
    if (mActiveRequest != null) {
        mActiveRequest.cancel();
        mActiveRequest = null;
    }
}
Also used : FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) Drawable(android.graphics.drawable.Drawable) FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) RoundDrawableWrapper(com.android.launcher3.icons.RoundDrawableWrapper) ViewPropertyAnimator(android.view.ViewPropertyAnimator)

Example 38 with FastBitmapDrawable

use of com.android.launcher3.FastBitmapDrawable in project android_packages_apps_404Launcher by P-404.

the class DatabaseWidgetPreviewLoader method getBadgeForUser.

/**
 * Returns a drawable that can be used as a badge for the user or null.
 */
// @UiThread
public Drawable getBadgeForUser(UserHandle user, int badgeSize) {
    if (mMyUser.equals(user)) {
        return null;
    }
    Bitmap badgeBitmap = getUserBadge(user, badgeSize);
    FastBitmapDrawable d = new FastBitmapDrawable(badgeBitmap);
    d.setFilterBitmap(true);
    d.setBounds(0, 0, badgeBitmap.getWidth(), badgeBitmap.getHeight());
    return d;
}
Also used : FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) Bitmap(android.graphics.Bitmap)

Example 39 with FastBitmapDrawable

use of com.android.launcher3.FastBitmapDrawable in project android_packages_apps_404Launcher by P-404.

the class Workspace method createWidgetDrawable.

private Drawable createWidgetDrawable(ItemInfo widgetInfo, View layout) {
    int[] unScaledSize = estimateItemSize(widgetInfo);
    int visibility = layout.getVisibility();
    layout.setVisibility(VISIBLE);
    int width = MeasureSpec.makeMeasureSpec(unScaledSize[0], MeasureSpec.EXACTLY);
    int height = MeasureSpec.makeMeasureSpec(unScaledSize[1], MeasureSpec.EXACTLY);
    layout.measure(width, height);
    layout.layout(0, 0, unScaledSize[0], unScaledSize[1]);
    Bitmap b = BitmapRenderer.createHardwareBitmap(unScaledSize[0], unScaledSize[1], layout::draw);
    layout.setVisibility(visibility);
    return new FastBitmapDrawable(b);
}
Also used : FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) Bitmap(android.graphics.Bitmap) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Example 40 with FastBitmapDrawable

use of com.android.launcher3.FastBitmapDrawable in project android_packages_apps_404Launcher by P-404.

the class DragPreviewProvider method createDrawable.

/**
 * Returns a new drawable to show when the {@link #mView} is being dragged around.
 * Responsibility for the drawable is transferred to the caller.
 */
public Drawable createDrawable() {
    if (mView instanceof LauncherAppWidgetHostView) {
        return null;
    }
    int width = 0;
    int height = 0;
    // Assume scaleX == scaleY, which is always the case for workspace items.
    float scale = mView.getScaleX();
    if (mView instanceof DraggableView) {
        ((DraggableView) mView).getSourceVisualDragBounds(mTempRect);
        width = mTempRect.width();
        height = mTempRect.height();
    } else {
        width = mView.getWidth();
        height = mView.getHeight();
    }
    return new FastBitmapDrawable(BitmapRenderer.createHardwareBitmap(width + blurSizeOutline, height + blurSizeOutline, (c) -> drawDragView(c, scale)));
}
Also used : FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) Context(android.content.Context) Rect(android.graphics.Rect) BitmapRenderer(com.android.launcher3.icons.BitmapRenderer) UI_HELPER_EXECUTOR(com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR) ActivityContext(com.android.launcher3.views.ActivityContext) FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) BlurMaskFilter(android.graphics.BlurMaskFilter) FeatureFlags(com.android.launcher3.config.FeatureFlags) PorterDuff(android.graphics.PorterDuff) SafeCloseable(com.android.launcher3.util.SafeCloseable) Drawable(android.graphics.drawable.Drawable) DraggableView(com.android.launcher3.dragndrop.DraggableView) BubbleTextView(com.android.launcher3.BubbleTextView) ByteBuffer(java.nio.ByteBuffer) PorterDuffXfermode(android.graphics.PorterDuffXfermode) Nullable(androidx.annotation.Nullable) R(com.android.launcher3.R) Bitmap(android.graphics.Bitmap) View(android.view.View) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) DraggableView(com.android.launcher3.dragndrop.DraggableView) Paint(android.graphics.Paint)

Aggregations

FastBitmapDrawable (com.android.launcher3.icons.FastBitmapDrawable)66 Drawable (android.graphics.drawable.Drawable)40 Point (android.graphics.Point)35 Bitmap (android.graphics.Bitmap)33 Rect (android.graphics.Rect)27 Paint (android.graphics.Paint)17 DraggableView (com.android.launcher3.dragndrop.DraggableView)16 TargetApi (android.annotation.TargetApi)14 FastBitmapDrawable (com.android.launcher3.FastBitmapDrawable)13 LauncherIcons (com.android.launcher3.icons.LauncherIcons)13 SuppressLint (android.annotation.SuppressLint)12 UiThread (androidx.annotation.UiThread)12 AdaptiveIconDrawable (android.graphics.drawable.AdaptiveIconDrawable)11 BubbleTextView (com.android.launcher3.BubbleTextView)11 ItemInfoWithIcon (com.android.launcher3.model.data.ItemInfoWithIcon)11 PendingAddShortcutInfo (com.android.launcher3.widget.PendingAddShortcutInfo)11 View (android.view.View)10 RoundDrawableWrapper (com.android.launcher3.icons.RoundDrawableWrapper)10 LauncherAppWidgetHostView (com.android.launcher3.widget.LauncherAppWidgetHostView)10 ShortcutInfo (android.content.pm.ShortcutInfo)8