Loading packages/SystemUI/src/com/android/systemui/bubbles/BadgedImageView.java +0 −19 Original line number Diff line number Diff line Loading @@ -18,8 +18,6 @@ package com.android.systemui.bubbles; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Path; import android.graphics.Point; import android.graphics.Rect; import android.util.AttributeSet; Loading @@ -36,11 +34,9 @@ public class BadgedImageView extends ImageView { private int mIconSize; private Rect mTempBounds = new Rect(); private Point mTempPoint = new Point(); private Path mClipPath = new Path(); private float mDotScale = 0f; private int mUpdateDotColor; private int mBubbleDefaultBgColor; private boolean mShowUpdateDot; private boolean mOnLeft; Loading @@ -59,32 +55,17 @@ public class BadgedImageView extends ImageView { public BadgedImageView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); setScaleType(ScaleType.CENTER_CROP); mIconSize = getResources().getDimensionPixelSize(R.dimen.individual_bubble_size); mDotRenderer = new BadgeRenderer(mIconSize); TypedArray ta = context.obtainStyledAttributes( new int[] {android.R.attr.colorBackgroundFloating}); mBubbleDefaultBgColor = ta.getColor(0, Color.WHITE); ta.recycle(); } // TODO: Clipping oval path isn't great: rerender image into a separate, rounded bitmap and // then draw would be better @Override public void onDraw(Canvas canvas) { canvas.save(); // Circle crop mClipPath.addOval(getPaddingStart(), getPaddingTop(), getWidth() - getPaddingEnd(), getHeight() - getPaddingBottom(), Path.Direction.CW); canvas.clipPath(mClipPath); canvas.drawColor(mBubbleDefaultBgColor); super.onDraw(canvas); // After we've circle cropped what we're showing, restore so we don't clip the badge canvas.restore(); // Draw the badge if (mShowUpdateDot) { getDrawingRect(mTempBounds); mTempPoint.set((getWidth() - mIconSize) / 2, getPaddingTop()); Loading packages/SystemUI/src/com/android/systemui/bubbles/BubbleView.java +22 −7 Original line number Diff line number Diff line Loading @@ -20,11 +20,11 @@ import android.annotation.Nullable; import android.app.Notification; import android.content.Context; import android.graphics.Color; import android.graphics.drawable.AdaptiveIconDrawable; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.Icon; import android.graphics.drawable.InsetDrawable; import android.graphics.drawable.LayerDrawable; import android.util.AttributeSet; import android.widget.FrameLayout; import android.widget.TextView; Loading @@ -41,6 +41,9 @@ import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow public class BubbleView extends FrameLayout { private static final String TAG = "BubbleView"; private static final int DARK_ICON_ALPHA = 180; private static final double ICON_MIN_CONTRAST = 4.1; private static final int DEFAULT_BACKGROUND_COLOR = Color.LTGRAY; // Same value as Launcher3 badge code private static final float WHITE_SCRIM_ALPHA = 0.54f; private Context mContext; Loading Loading @@ -205,12 +208,7 @@ public class BubbleView extends FrameLayout { } Drawable iconDrawable = ic.loadDrawable(mContext); if (needsTint) { // Center icon on coloured background iconDrawable.setTint(Color.WHITE); // TODO: dark mode Drawable bg = new ColorDrawable(n.color); InsetDrawable d = new InsetDrawable(iconDrawable, mIconInset); Drawable[] layers = {bg, d}; mBadgedImageView.setImageDrawable(new LayerDrawable(layers)); mBadgedImageView.setImageDrawable(buildIconWithTint(iconDrawable, n.color)); } else { mBadgedImageView.setImageDrawable(iconDrawable); } Loading @@ -219,6 +217,23 @@ public class BubbleView extends FrameLayout { animateDot(mEntry.showInShadeWhenBubble() /* showDot */); } private Drawable buildIconWithTint(Drawable iconDrawable, int backgroundColor) { backgroundColor = ColorUtils.setAlphaComponent(backgroundColor, 255 /* alpha */); if (backgroundColor == Color.TRANSPARENT) { // ColorUtils throws exception when background is translucent. backgroundColor = DEFAULT_BACKGROUND_COLOR; } iconDrawable.setTint(Color.WHITE); double contrastRatio = ColorUtils.calculateContrast(Color.WHITE, backgroundColor); if (contrastRatio < ICON_MIN_CONTRAST) { int dark = ColorUtils.setAlphaComponent(Color.BLACK, DARK_ICON_ALPHA); iconDrawable.setTint(dark); } InsetDrawable foreground = new InsetDrawable(iconDrawable, mIconInset); ColorDrawable background = new ColorDrawable(backgroundColor); return new AdaptiveIconDrawable(background, foreground); } private int determineDominateColor(Drawable d, int defaultTint) { // XXX: should we pull from the drawable, app icon, notif tint? return ColorUtils.blendARGB(defaultTint, Color.WHITE, WHITE_SCRIM_ALPHA); Loading Loading
packages/SystemUI/src/com/android/systemui/bubbles/BadgedImageView.java +0 −19 Original line number Diff line number Diff line Loading @@ -18,8 +18,6 @@ package com.android.systemui.bubbles; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Path; import android.graphics.Point; import android.graphics.Rect; import android.util.AttributeSet; Loading @@ -36,11 +34,9 @@ public class BadgedImageView extends ImageView { private int mIconSize; private Rect mTempBounds = new Rect(); private Point mTempPoint = new Point(); private Path mClipPath = new Path(); private float mDotScale = 0f; private int mUpdateDotColor; private int mBubbleDefaultBgColor; private boolean mShowUpdateDot; private boolean mOnLeft; Loading @@ -59,32 +55,17 @@ public class BadgedImageView extends ImageView { public BadgedImageView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); setScaleType(ScaleType.CENTER_CROP); mIconSize = getResources().getDimensionPixelSize(R.dimen.individual_bubble_size); mDotRenderer = new BadgeRenderer(mIconSize); TypedArray ta = context.obtainStyledAttributes( new int[] {android.R.attr.colorBackgroundFloating}); mBubbleDefaultBgColor = ta.getColor(0, Color.WHITE); ta.recycle(); } // TODO: Clipping oval path isn't great: rerender image into a separate, rounded bitmap and // then draw would be better @Override public void onDraw(Canvas canvas) { canvas.save(); // Circle crop mClipPath.addOval(getPaddingStart(), getPaddingTop(), getWidth() - getPaddingEnd(), getHeight() - getPaddingBottom(), Path.Direction.CW); canvas.clipPath(mClipPath); canvas.drawColor(mBubbleDefaultBgColor); super.onDraw(canvas); // After we've circle cropped what we're showing, restore so we don't clip the badge canvas.restore(); // Draw the badge if (mShowUpdateDot) { getDrawingRect(mTempBounds); mTempPoint.set((getWidth() - mIconSize) / 2, getPaddingTop()); Loading
packages/SystemUI/src/com/android/systemui/bubbles/BubbleView.java +22 −7 Original line number Diff line number Diff line Loading @@ -20,11 +20,11 @@ import android.annotation.Nullable; import android.app.Notification; import android.content.Context; import android.graphics.Color; import android.graphics.drawable.AdaptiveIconDrawable; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.Icon; import android.graphics.drawable.InsetDrawable; import android.graphics.drawable.LayerDrawable; import android.util.AttributeSet; import android.widget.FrameLayout; import android.widget.TextView; Loading @@ -41,6 +41,9 @@ import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow public class BubbleView extends FrameLayout { private static final String TAG = "BubbleView"; private static final int DARK_ICON_ALPHA = 180; private static final double ICON_MIN_CONTRAST = 4.1; private static final int DEFAULT_BACKGROUND_COLOR = Color.LTGRAY; // Same value as Launcher3 badge code private static final float WHITE_SCRIM_ALPHA = 0.54f; private Context mContext; Loading Loading @@ -205,12 +208,7 @@ public class BubbleView extends FrameLayout { } Drawable iconDrawable = ic.loadDrawable(mContext); if (needsTint) { // Center icon on coloured background iconDrawable.setTint(Color.WHITE); // TODO: dark mode Drawable bg = new ColorDrawable(n.color); InsetDrawable d = new InsetDrawable(iconDrawable, mIconInset); Drawable[] layers = {bg, d}; mBadgedImageView.setImageDrawable(new LayerDrawable(layers)); mBadgedImageView.setImageDrawable(buildIconWithTint(iconDrawable, n.color)); } else { mBadgedImageView.setImageDrawable(iconDrawable); } Loading @@ -219,6 +217,23 @@ public class BubbleView extends FrameLayout { animateDot(mEntry.showInShadeWhenBubble() /* showDot */); } private Drawable buildIconWithTint(Drawable iconDrawable, int backgroundColor) { backgroundColor = ColorUtils.setAlphaComponent(backgroundColor, 255 /* alpha */); if (backgroundColor == Color.TRANSPARENT) { // ColorUtils throws exception when background is translucent. backgroundColor = DEFAULT_BACKGROUND_COLOR; } iconDrawable.setTint(Color.WHITE); double contrastRatio = ColorUtils.calculateContrast(Color.WHITE, backgroundColor); if (contrastRatio < ICON_MIN_CONTRAST) { int dark = ColorUtils.setAlphaComponent(Color.BLACK, DARK_ICON_ALPHA); iconDrawable.setTint(dark); } InsetDrawable foreground = new InsetDrawable(iconDrawable, mIconInset); ColorDrawable background = new ColorDrawable(backgroundColor); return new AdaptiveIconDrawable(background, foreground); } private int determineDominateColor(Drawable d, int defaultTint) { // XXX: should we pull from the drawable, app icon, notif tint? return ColorUtils.blendARGB(defaultTint, Color.WHITE, WHITE_SCRIM_ALPHA); Loading