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);
}
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);
}
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();
}
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);
}
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);
}
Aggregations