Search in sources :

Example 1 with ShiftedBitmapDrawable

use of com.android.launcher3.graphics.ShiftedBitmapDrawable in project android_packages_apps_Launcher3 by AOSPA.

the class FolderAdaptiveIcon method createDrawableOnUiThread.

private static FolderAdaptiveIcon createDrawableOnUiThread(FolderIcon icon, Point dragViewSize) {
    Preconditions.assertUIThread();
    icon.getPreviewBounds(sTmpRect);
    PreviewBackground bg = icon.getFolderBackground();
    // assume square
    assert (dragViewSize.x == dragViewSize.y);
    final int previewSize = sTmpRect.width();
    final int margin = (dragViewSize.x - previewSize) / 2;
    final float previewShiftX = -sTmpRect.left + margin;
    final float previewShiftY = -sTmpRect.top + margin;
    // Initialize badge, which consists of the outline stroke, shadow and dot; these
    // must be rendered above the foreground
    Bitmap badgeBmp = BitmapRenderer.createHardwareBitmap(dragViewSize.x, dragViewSize.y, (canvas) -> {
        canvas.save();
        canvas.translate(previewShiftX, previewShiftY);
        bg.drawShadow(canvas);
        bg.drawBackgroundStroke(canvas);
        icon.drawDot(canvas);
        canvas.restore();
    });
    // Initialize mask
    Path mask = new Path();
    Matrix m = new Matrix();
    m.setTranslate(previewShiftX, previewShiftY);
    bg.getClipPath().transform(m, mask);
    Bitmap previewBitmap = BitmapRenderer.createHardwareBitmap(dragViewSize.x, dragViewSize.y, (canvas) -> {
        canvas.save();
        canvas.translate(previewShiftX, previewShiftY);
        icon.getPreviewItemManager().draw(canvas);
        canvas.restore();
    });
    Bitmap bgBitmap = BitmapRenderer.createHardwareBitmap(dragViewSize.x, dragViewSize.y, (canvas) -> {
        Paint p = new Paint();
        p.setColor(bg.getBgColor());
        canvas.drawCircle(dragViewSize.x / 2f, dragViewSize.y / 2f, bg.getRadius(), p);
    });
    ShiftedBitmapDrawable badge = new ShiftedBitmapDrawable(badgeBmp, 0, 0);
    ShiftedBitmapDrawable foreground = new ShiftedBitmapDrawable(previewBitmap, 0, 0);
    ShiftedBitmapDrawable background = new ShiftedBitmapDrawable(bgBitmap, 0, 0);
    return new FolderAdaptiveIcon(background, foreground, badge, mask);
}
Also used : Path(android.graphics.Path) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) PreviewBackground(com.android.launcher3.folder.PreviewBackground) ShiftedBitmapDrawable(com.android.launcher3.graphics.ShiftedBitmapDrawable) Paint(android.graphics.Paint) Point(android.graphics.Point) Paint(android.graphics.Paint)

Example 2 with ShiftedBitmapDrawable

use of com.android.launcher3.graphics.ShiftedBitmapDrawable in project android_packages_apps_Trebuchet by LineageOS.

the class FolderAdaptiveIcon method createDrawableOnUiThread.

private static FolderAdaptiveIcon createDrawableOnUiThread(FolderIcon icon, Point dragViewSize) {
    Preconditions.assertUIThread();
    icon.getPreviewBounds(sTmpRect);
    PreviewBackground bg = icon.getFolderBackground();
    // assume square
    assert (dragViewSize.x == dragViewSize.y);
    final int previewSize = sTmpRect.width();
    final int margin = (dragViewSize.x - previewSize) / 2;
    final float previewShiftX = -sTmpRect.left + margin;
    final float previewShiftY = -sTmpRect.top + margin;
    // Initialize badge, which consists of the outline stroke, shadow and dot; these
    // must be rendered above the foreground
    Bitmap badgeBmp = BitmapRenderer.createHardwareBitmap(dragViewSize.x, dragViewSize.y, (canvas) -> {
        canvas.save();
        canvas.translate(previewShiftX, previewShiftY);
        bg.drawShadow(canvas);
        bg.drawBackgroundStroke(canvas);
        icon.drawDot(canvas);
        canvas.restore();
    });
    // Initialize mask
    Path mask = new Path();
    Matrix m = new Matrix();
    m.setTranslate(previewShiftX, previewShiftY);
    bg.getClipPath().transform(m, mask);
    Bitmap previewBitmap = BitmapRenderer.createHardwareBitmap(dragViewSize.x, dragViewSize.y, (canvas) -> {
        canvas.save();
        canvas.translate(previewShiftX, previewShiftY);
        icon.getPreviewItemManager().draw(canvas);
        canvas.restore();
    });
    ShiftedBitmapDrawable badge = new ShiftedBitmapDrawable(badgeBmp, 0, 0);
    ShiftedBitmapDrawable foreground = new ShiftedBitmapDrawable(previewBitmap, 0, 0);
    return new FolderAdaptiveIcon(new ColorDrawable(bg.getBgColor()), foreground, badge, mask);
}
Also used : Path(android.graphics.Path) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) ColorDrawable(android.graphics.drawable.ColorDrawable) PreviewBackground(com.android.launcher3.folder.PreviewBackground) ShiftedBitmapDrawable(com.android.launcher3.graphics.ShiftedBitmapDrawable) Point(android.graphics.Point)

Example 3 with ShiftedBitmapDrawable

use of com.android.launcher3.graphics.ShiftedBitmapDrawable in project Neo-Launcher by NeoApplications.

the class FloatingIconView method setIcon.

/**
 * Sets the drawables of the {@param originalView} onto this view.
 *
 * @param originalView The View that the FloatingIconView will replace.
 * @param drawable The drawable of the original view.
 * @param badge The badge of the original view.
 * @param iconOffset The amount of offset needed to match this view with the original view.
 */
@UiThread
private void setIcon(View originalView, @Nullable Drawable drawable, @Nullable Drawable badge, int iconOffset) {
    mBadge = badge;
    mIsAdaptiveIcon = drawable instanceof AdaptiveIconDrawable;
    if (mIsAdaptiveIcon) {
        boolean isFolderIcon = drawable instanceof FolderAdaptiveIcon;
        AdaptiveIconDrawable adaptiveIcon = (AdaptiveIconDrawable) drawable;
        Drawable background = adaptiveIcon.getBackground();
        if (background == null) {
            background = new ColorDrawable(Color.TRANSPARENT);
        }
        mBackground = background;
        Drawable foreground = adaptiveIcon.getForeground();
        if (foreground == null) {
            foreground = new ColorDrawable(Color.TRANSPARENT);
        }
        mForeground = foreground;
        final LayoutParams lp = (LayoutParams) getLayoutParams();
        final int originalHeight = lp.height;
        final int originalWidth = lp.width;
        int blurMargin = mBlurSizeOutline / 2;
        mFinalDrawableBounds.set(0, 0, originalWidth, originalHeight);
        if (!isFolderIcon) {
            mFinalDrawableBounds.inset(iconOffset - blurMargin, iconOffset - blurMargin);
        }
        mForeground.setBounds(mFinalDrawableBounds);
        mBackground.setBounds(mFinalDrawableBounds);
        mStartRevealRect.set(0, 0, originalWidth, originalHeight);
        if (mBadge != null) {
            mBadge.setBounds(mStartRevealRect);
            if (!mIsOpening && !isFolderIcon) {
                DRAWABLE_ALPHA.set(mBadge, 0);
            }
        }
        if (isFolderIcon) {
            ((FolderIcon) originalView).getPreviewBounds(sTmpRect);
            float bgStroke = ((FolderIcon) originalView).getBackgroundStrokeWidth();
            if (mForeground instanceof ShiftedBitmapDrawable) {
                ShiftedBitmapDrawable sbd = (ShiftedBitmapDrawable) mForeground;
                sbd.setShiftX(sbd.getShiftX() - sTmpRect.left - bgStroke);
                sbd.setShiftY(sbd.getShiftY() - sTmpRect.top - bgStroke);
            }
            if (mBadge instanceof ShiftedBitmapDrawable) {
                ShiftedBitmapDrawable sbd = (ShiftedBitmapDrawable) mBadge;
                sbd.setShiftX(sbd.getShiftX() - sTmpRect.left - bgStroke);
                sbd.setShiftY(sbd.getShiftY() - sTmpRect.top - bgStroke);
            }
        } else {
            Utilities.scaleRectAboutCenter(mStartRevealRect, IconShape.getNormalizationScale());
        }
        float aspectRatio = mLauncher.getDeviceProfile().aspectRatio;
        if (mIsVerticalBarLayout) {
            lp.width = (int) Math.max(lp.width, lp.height * aspectRatio);
        } else {
            lp.height = (int) Math.max(lp.height, lp.width * aspectRatio);
        }
        int left = mIsRtl ? mLauncher.getDeviceProfile().widthPx - lp.getMarginStart() - lp.width : lp.leftMargin;
        layout(left, lp.topMargin, left + lp.width, lp.topMargin + lp.height);
        float scale = Math.max((float) lp.height / originalHeight, (float) lp.width / originalWidth);
        float bgDrawableStartScale;
        if (mIsOpening) {
            bgDrawableStartScale = 1f;
            mOutline.set(0, 0, originalWidth, originalHeight);
        } else {
            bgDrawableStartScale = scale;
            mOutline.set(0, 0, lp.width, lp.height);
        }
        setBackgroundDrawableBounds(bgDrawableStartScale);
        mEndRevealRect.set(0, 0, lp.width, lp.height);
        setOutlineProvider(new ViewOutlineProvider() {

            @Override
            public void getOutline(View view, Outline outline) {
                outline.setRoundRect(mOutline, mTaskCornerRadius);
            }
        });
        setClipToOutline(true);
    } else {
        setBackground(drawable);
        setClipToOutline(false);
    }
    invalidate();
    invalidateOutline();
}
Also used : FolderAdaptiveIcon(com.android.launcher3.dragndrop.FolderAdaptiveIcon) LayoutParams(com.android.launcher3.InsettableFrameLayout.LayoutParams) AdaptiveIconDrawable(android.graphics.drawable.AdaptiveIconDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) ShiftedBitmapDrawable(com.android.launcher3.graphics.ShiftedBitmapDrawable) Utilities.getFullDrawable(com.android.launcher3.Utilities.getFullDrawable) Outline(android.graphics.Outline) ViewOutlineProvider(android.view.ViewOutlineProvider) ImageView(android.widget.ImageView) BubbleTextView(com.android.launcher3.BubbleTextView) View(android.view.View) DeepShortcutView(com.android.launcher3.shortcuts.DeepShortcutView) ColorDrawable(android.graphics.drawable.ColorDrawable) FolderIcon(com.android.launcher3.folder.FolderIcon) ShiftedBitmapDrawable(com.android.launcher3.graphics.ShiftedBitmapDrawable) AdaptiveIconDrawable(android.graphics.drawable.AdaptiveIconDrawable) UiThread(androidx.annotation.UiThread)

Example 4 with ShiftedBitmapDrawable

use of com.android.launcher3.graphics.ShiftedBitmapDrawable in project android_packages_apps_Launcher3 by ProtonAOSP.

the class FolderAdaptiveIcon method createDrawableOnUiThread.

private static FolderAdaptiveIcon createDrawableOnUiThread(FolderIcon icon, Point dragViewSize) {
    Preconditions.assertUIThread();
    icon.getPreviewBounds(sTmpRect);
    PreviewBackground bg = icon.getFolderBackground();
    // assume square
    assert (dragViewSize.x == dragViewSize.y);
    final int previewSize = sTmpRect.width();
    final int margin = (dragViewSize.x - previewSize) / 2;
    final float previewShiftX = -sTmpRect.left + margin;
    final float previewShiftY = -sTmpRect.top + margin;
    // Initialize badge, which consists of the outline stroke, shadow and dot; these
    // must be rendered above the foreground
    Bitmap badgeBmp = BitmapRenderer.createHardwareBitmap(dragViewSize.x, dragViewSize.y, (canvas) -> {
        canvas.save();
        canvas.translate(previewShiftX, previewShiftY);
        bg.drawShadow(canvas);
        bg.drawBackgroundStroke(canvas);
        icon.drawDot(canvas);
        canvas.restore();
    });
    // Initialize mask
    Path mask = new Path();
    Matrix m = new Matrix();
    m.setTranslate(previewShiftX, previewShiftY);
    bg.getClipPath().transform(m, mask);
    Bitmap previewBitmap = BitmapRenderer.createHardwareBitmap(dragViewSize.x, dragViewSize.y, (canvas) -> {
        canvas.save();
        canvas.translate(previewShiftX, previewShiftY);
        icon.getPreviewItemManager().draw(canvas);
        canvas.restore();
    });
    Bitmap bgBitmap = BitmapRenderer.createHardwareBitmap(dragViewSize.x, dragViewSize.y, (canvas) -> {
        Paint p = new Paint();
        p.setColor(bg.getBgColor());
        canvas.drawCircle(dragViewSize.x / 2f, dragViewSize.y / 2f, bg.getRadius(), p);
    });
    ShiftedBitmapDrawable badge = new ShiftedBitmapDrawable(badgeBmp, 0, 0);
    ShiftedBitmapDrawable foreground = new ShiftedBitmapDrawable(previewBitmap, 0, 0);
    ShiftedBitmapDrawable background = new ShiftedBitmapDrawable(bgBitmap, 0, 0);
    return new FolderAdaptiveIcon(background, foreground, badge, mask);
}
Also used : Path(android.graphics.Path) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) PreviewBackground(com.android.launcher3.folder.PreviewBackground) ShiftedBitmapDrawable(com.android.launcher3.graphics.ShiftedBitmapDrawable) Paint(android.graphics.Paint) Point(android.graphics.Point) Paint(android.graphics.Paint)

Example 5 with ShiftedBitmapDrawable

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

the class FolderAdaptiveIcon method createDrawableOnUiThread.

private static FolderAdaptiveIcon createDrawableOnUiThread(FolderIcon icon, Point dragViewSize) {
    Preconditions.assertUIThread();
    icon.getPreviewBounds(sTmpRect);
    PreviewBackground bg = icon.getFolderBackground();
    // assume square
    assert (dragViewSize.x == dragViewSize.y);
    final int previewSize = sTmpRect.width();
    final int margin = (dragViewSize.x - previewSize) / 2;
    final float previewShiftX = -sTmpRect.left + margin;
    final float previewShiftY = -sTmpRect.top + margin;
    // Initialize badge, which consists of the outline stroke, shadow and dot; these
    // must be rendered above the foreground
    Bitmap badgeBmp = BitmapRenderer.createHardwareBitmap(dragViewSize.x, dragViewSize.y, (canvas) -> {
        canvas.save();
        canvas.translate(previewShiftX, previewShiftY);
        bg.drawShadow(canvas);
        bg.drawBackgroundStroke(canvas);
        icon.drawDot(canvas);
        canvas.restore();
    });
    // Initialize mask
    Path mask = new Path();
    Matrix m = new Matrix();
    m.setTranslate(previewShiftX, previewShiftY);
    bg.getClipPath().transform(m, mask);
    Bitmap previewBitmap = BitmapRenderer.createHardwareBitmap(dragViewSize.x, dragViewSize.y, (canvas) -> {
        canvas.save();
        canvas.translate(previewShiftX, previewShiftY);
        icon.getPreviewItemManager().draw(canvas);
        canvas.restore();
    });
    Bitmap bgBitmap = BitmapRenderer.createHardwareBitmap(dragViewSize.x, dragViewSize.y, (canvas) -> {
        Paint p = new Paint();
        p.setColor(bg.getBgColor());
        canvas.drawCircle(dragViewSize.x / 2f, dragViewSize.y / 2f, bg.getRadius(), p);
    });
    ShiftedBitmapDrawable badge = new ShiftedBitmapDrawable(badgeBmp, 0, 0);
    ShiftedBitmapDrawable foreground = new ShiftedBitmapDrawable(previewBitmap, 0, 0);
    ShiftedBitmapDrawable background = new ShiftedBitmapDrawable(bgBitmap, 0, 0);
    return new FolderAdaptiveIcon(background, foreground, badge, mask);
}
Also used : Path(android.graphics.Path) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) PreviewBackground(com.android.launcher3.folder.PreviewBackground) ShiftedBitmapDrawable(com.android.launcher3.graphics.ShiftedBitmapDrawable) Paint(android.graphics.Paint) Point(android.graphics.Point) Paint(android.graphics.Paint)

Aggregations

ShiftedBitmapDrawable (com.android.launcher3.graphics.ShiftedBitmapDrawable)8 Bitmap (android.graphics.Bitmap)7 Matrix (android.graphics.Matrix)7 Path (android.graphics.Path)7 Point (android.graphics.Point)7 PreviewBackground (com.android.launcher3.folder.PreviewBackground)7 Paint (android.graphics.Paint)5 ColorDrawable (android.graphics.drawable.ColorDrawable)3 Canvas (android.graphics.Canvas)1 Outline (android.graphics.Outline)1 AdaptiveIconDrawable (android.graphics.drawable.AdaptiveIconDrawable)1 Drawable (android.graphics.drawable.Drawable)1 View (android.view.View)1 ViewOutlineProvider (android.view.ViewOutlineProvider)1 ImageView (android.widget.ImageView)1 UiThread (androidx.annotation.UiThread)1 BubbleTextView (com.android.launcher3.BubbleTextView)1 LayoutParams (com.android.launcher3.InsettableFrameLayout.LayoutParams)1 Utilities.getFullDrawable (com.android.launcher3.Utilities.getFullDrawable)1 FolderAdaptiveIcon (com.android.launcher3.dragndrop.FolderAdaptiveIcon)1