Merge "Ensure that bubble badge is always circle" into rvc-qpr-dev am: 441d5a3cd5
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/12132201 Change-Id: Id14db768e8bbd073ed8df7134a2fd51738c8e75b
This commit is contained in:
@@ -24,6 +24,8 @@ import android.content.pm.ShortcutInfo;
|
|||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
|
import android.graphics.Path;
|
||||||
|
import android.graphics.drawable.AdaptiveIconDrawable;
|
||||||
import android.graphics.drawable.BitmapDrawable;
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.graphics.drawable.Icon;
|
import android.graphics.drawable.Icon;
|
||||||
@@ -40,15 +42,15 @@ import com.android.systemui.R;
|
|||||||
*/
|
*/
|
||||||
public class BubbleIconFactory extends BaseIconFactory {
|
public class BubbleIconFactory extends BaseIconFactory {
|
||||||
|
|
||||||
|
private int mBadgeSize;
|
||||||
|
|
||||||
protected BubbleIconFactory(Context context) {
|
protected BubbleIconFactory(Context context) {
|
||||||
super(context, context.getResources().getConfiguration().densityDpi,
|
super(context, context.getResources().getConfiguration().densityDpi,
|
||||||
context.getResources().getDimensionPixelSize(R.dimen.individual_bubble_size));
|
context.getResources().getDimensionPixelSize(R.dimen.individual_bubble_size));
|
||||||
}
|
mBadgeSize = mContext.getResources().getDimensionPixelSize(
|
||||||
|
|
||||||
int getBadgeSize() {
|
|
||||||
return mContext.getResources().getDimensionPixelSize(
|
|
||||||
com.android.launcher3.icons.R.dimen.profile_badge_size);
|
com.android.launcher3.icons.R.dimen.profile_badge_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the drawable that the developer has provided to display in the bubble.
|
* Returns the drawable that the developer has provided to display in the bubble.
|
||||||
*/
|
*/
|
||||||
@@ -78,18 +80,20 @@ public class BubbleIconFactory extends BaseIconFactory {
|
|||||||
* will include the workprofile indicator on the badge if appropriate.
|
* will include the workprofile indicator on the badge if appropriate.
|
||||||
*/
|
*/
|
||||||
BitmapInfo getBadgeBitmap(Drawable userBadgedAppIcon, boolean isImportantConversation) {
|
BitmapInfo getBadgeBitmap(Drawable userBadgedAppIcon, boolean isImportantConversation) {
|
||||||
Bitmap userBadgedBitmap = createIconBitmap(
|
ShadowGenerator shadowGenerator = new ShadowGenerator(mBadgeSize);
|
||||||
userBadgedAppIcon, 1f, getBadgeSize());
|
Bitmap userBadgedBitmap = createIconBitmap(userBadgedAppIcon, 1f, mBadgeSize);
|
||||||
ShadowGenerator shadowGenerator = new ShadowGenerator(getBadgeSize());
|
|
||||||
if (!isImportantConversation) {
|
if (userBadgedAppIcon instanceof AdaptiveIconDrawable) {
|
||||||
Canvas c = new Canvas();
|
userBadgedBitmap = Bitmap.createScaledBitmap(
|
||||||
c.setBitmap(userBadgedBitmap);
|
getCircleBitmap((AdaptiveIconDrawable) userBadgedAppIcon, /* size */
|
||||||
shadowGenerator.recreateIcon(Bitmap.createBitmap(userBadgedBitmap), c);
|
userBadgedAppIcon.getIntrinsicWidth()),
|
||||||
return createIconBitmap(userBadgedBitmap);
|
mBadgeSize, mBadgeSize, /* filter */ true);
|
||||||
} else {
|
}
|
||||||
float ringStrokeWidth = mContext.getResources().getDimensionPixelSize(
|
|
||||||
|
if (isImportantConversation) {
|
||||||
|
final float ringStrokeWidth = mContext.getResources().getDimensionPixelSize(
|
||||||
com.android.internal.R.dimen.importance_ring_stroke_width);
|
com.android.internal.R.dimen.importance_ring_stroke_width);
|
||||||
int importantConversationColor = mContext.getResources().getColor(
|
final int importantConversationColor = mContext.getResources().getColor(
|
||||||
com.android.settingslib.R.color.important_conversation, null);
|
com.android.settingslib.R.color.important_conversation, null);
|
||||||
Bitmap badgeAndRing = Bitmap.createBitmap(userBadgedBitmap.getWidth(),
|
Bitmap badgeAndRing = Bitmap.createBitmap(userBadgedBitmap.getWidth(),
|
||||||
userBadgedBitmap.getHeight(), userBadgedBitmap.getConfig());
|
userBadgedBitmap.getHeight(), userBadgedBitmap.getConfig());
|
||||||
@@ -114,9 +118,45 @@ public class BubbleIconFactory extends BaseIconFactory {
|
|||||||
|
|
||||||
shadowGenerator.recreateIcon(Bitmap.createBitmap(badgeAndRing), c);
|
shadowGenerator.recreateIcon(Bitmap.createBitmap(badgeAndRing), c);
|
||||||
return createIconBitmap(badgeAndRing);
|
return createIconBitmap(badgeAndRing);
|
||||||
|
} else {
|
||||||
|
Canvas c = new Canvas();
|
||||||
|
c.setBitmap(userBadgedBitmap);
|
||||||
|
shadowGenerator.recreateIcon(Bitmap.createBitmap(userBadgedBitmap), c);
|
||||||
|
return createIconBitmap(userBadgedBitmap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Bitmap getCircleBitmap(AdaptiveIconDrawable icon, int size) {
|
||||||
|
Drawable foreground = icon.getForeground();
|
||||||
|
Drawable background = icon.getBackground();
|
||||||
|
Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
|
||||||
|
Canvas canvas = new Canvas();
|
||||||
|
canvas.setBitmap(bitmap);
|
||||||
|
|
||||||
|
// Clip canvas to circle.
|
||||||
|
Path circlePath = new Path();
|
||||||
|
circlePath.addCircle(/* x */ size / 2f,
|
||||||
|
/* y */ size / 2f,
|
||||||
|
/* radius */ size / 2f,
|
||||||
|
Path.Direction.CW);
|
||||||
|
canvas.clipPath(circlePath);
|
||||||
|
|
||||||
|
// Draw background.
|
||||||
|
background.setBounds(0, 0, size, size);
|
||||||
|
background.draw(canvas);
|
||||||
|
|
||||||
|
// Draw foreground. The foreground and background drawables are derived from adaptive icons
|
||||||
|
// Some icon shapes fill more space than others, so adaptive icons are normalized to about
|
||||||
|
// the same size. This size is smaller than the original bounds, so we estimate
|
||||||
|
// the difference in this offset.
|
||||||
|
int offset = size / 5;
|
||||||
|
foreground.setBounds(-offset, -offset, size + offset, size + offset);
|
||||||
|
foreground.draw(canvas);
|
||||||
|
|
||||||
|
canvas.setBitmap(null);
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a {@link BitmapInfo} for the entire bubble icon including the badge.
|
* Returns a {@link BitmapInfo} for the entire bubble icon including the badge.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user