From c10de368a2f0d7831340974452cbfe581a2ba518 Mon Sep 17 00:00:00 2001 From: mpodolian Date: Mon, 29 Jul 2024 16:23:20 -0700 Subject: [PATCH] Change shadow drawing for bubble bar icons. Removed an outline provider for the BubbleView, so framework shadows are not drawn. Use BubbleBarBubbleIconsFactory to generate icon with the shadow so it looks consistent with the taskbar and the hotseat bar. Fixes: 345490679 Flag: com.android.wm.shell.enable_bubble_bar Test: manual, screenshot before fix: https://screenshot.googleplex.com/86ZhQENANboZK87 screenshot after fix: https://screenshot.googleplex.com/3hNboaSaS9tZ9DS Change-Id: I9ae3624e652e4f609b29ae0f57a47d4a6d01e94b --- .../bubbles/BubbleBarBubbleIconsFactory.kt | 32 +++++++++++ .../taskbar/bubbles/BubbleBarView.java | 11 ---- .../launcher3/taskbar/bubbles/BubbleView.java | 54 +++++++++---------- 3 files changed, 56 insertions(+), 41 deletions(-) create mode 100644 quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarBubbleIconsFactory.kt diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarBubbleIconsFactory.kt b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarBubbleIconsFactory.kt new file mode 100644 index 0000000000..4330c5b03b --- /dev/null +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarBubbleIconsFactory.kt @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.launcher3.taskbar.bubbles + +import android.content.Context +import android.graphics.Bitmap +import android.graphics.drawable.Drawable +import com.android.launcher3.icons.BaseIconFactory + +/** Bubble icons factory for the bubble bar. */ +class BubbleBarBubbleIconsFactory(context: Context, bubbleSize: Int) : + BaseIconFactory(context, context.resources.configuration.densityDpi, bubbleSize) { + + /** Creates shadowed icon for the bubble bar. */ + fun createShadowedIconBitmap( + icon: Drawable, + scale: Float, + ): Bitmap = super.createIconBitmap(icon, scale, MODE_WITH_SHADOW) +} diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java index af371f25e7..5d550ae6f6 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java @@ -307,17 +307,6 @@ public class BubbleBarView extends FrameLayout { } } - @Override - public void setAlpha(float alpha) { - super.setAlpha(alpha); - int childCount = getChildCount(); - for (int i = 0; i < childCount; i++) { - View childView = getChildAt(i); - if (!(childView instanceof BubbleView)) continue; - ((BubbleView) childView).setProvideShadowOutline(alpha == 1f); - } - } - /** * Sets new icon sizes and newBubbleBarPadding between icons and bubble bar borders. * diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleView.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleView.java index 6db42a4c53..6d99944c28 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleView.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleView.java @@ -20,15 +20,13 @@ import android.app.Notification; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; -import android.graphics.Outline; import android.graphics.Path; import android.graphics.Rect; +import android.graphics.drawable.BitmapDrawable; import android.os.Bundle; import android.text.TextUtils; import android.util.AttributeSet; import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewOutlineProvider; import android.view.accessibility.AccessibilityNodeInfo; import android.widget.ImageView; @@ -36,7 +34,6 @@ import androidx.constraintlayout.widget.ConstraintLayout; import com.android.launcher3.R; import com.android.launcher3.icons.DotRenderer; -import com.android.launcher3.icons.IconNormalizer; import com.android.wm.shell.animation.Interpolators; import com.android.wm.shell.common.bubbles.BubbleBarLocation; import com.android.wm.shell.common.bubbles.BubbleInfo; @@ -78,9 +75,14 @@ public class BubbleView extends ConstraintLayout { private BubbleBarItem mBubble; + private Bitmap mIcon; + @Nullable private Controller mController; + @Nullable + private BubbleBarBubbleIconsFactory mIconFactory = null; + public BubbleView(Context context) { this(context, null); } @@ -107,36 +109,14 @@ public class BubbleView extends ConstraintLayout { setFocusable(true); setClickable(true); - setOutlineProvider(new ViewOutlineProvider() { - @Override - public void getOutline(View view, Outline outline) { - BubbleView.this.getOutline(outline); - } - }); - } - - //TODO(b/345490679) remove once proper shadow is applied - /** Set whether provide an outline. */ - public void setProvideShadowOutline(boolean provideOutline) { - if (mProvideShadowOutline == provideOutline) return; - mProvideShadowOutline = provideOutline; - invalidateOutline(); - } - - private void getOutline(Outline outline) { - updateBubbleSizeAndDotRender(); - final int normalizedSize = IconNormalizer.getNormalizedCircleSize(mBubbleSize); - final int inset = (mBubbleSize - normalizedSize) / 2; - if (mProvideShadowOutline) { - outline.setOval(inset, inset, inset + normalizedSize, inset + normalizedSize); - } } private void updateBubbleSizeAndDotRender() { int updatedBubbleSize = Math.min(getWidth(), getHeight()); if (updatedBubbleSize == mBubbleSize) return; mBubbleSize = updatedBubbleSize; - invalidateOutline(); + mIconFactory = new BubbleBarBubbleIconsFactory(mContext, mBubbleSize); + updateBubbleIcon(); if (mBubble == null || mBubble instanceof BubbleBarOverflow) return; Path dotPath = ((BubbleBarBubble) mBubble).getDotPath(); mDotRenderer = new DotRenderer(mBubbleSize, dotPath, DEFAULT_PATH_SIZE); @@ -254,7 +234,8 @@ public class BubbleView extends ConstraintLayout { /** Sets the bubble being rendered in this view. */ public void setBubble(BubbleBarBubble bubble) { mBubble = bubble; - mBubbleIcon.setImageBitmap(bubble.getIcon()); + mIcon = bubble.getIcon(); + updateBubbleIcon(); mAppIcon.setImageBitmap(bubble.getBadge()); mDotColor = bubble.getDotColor(); mDotRenderer = new DotRenderer(mBubbleSize, bubble.getDotPath(), DEFAULT_PATH_SIZE); @@ -270,6 +251,18 @@ public class BubbleView extends ConstraintLayout { setContentDescription(contentDesc); } + private void updateBubbleIcon() { + Bitmap icon = null; + if (mIcon != null) { + icon = mIcon; + if (mIconFactory != null) { + BitmapDrawable iconDrawable = new BitmapDrawable(getResources(), icon); + icon = mIconFactory.createShadowedIconBitmap(iconDrawable, /* scale = */ 1f); + } + } + mBubbleIcon.setImageBitmap(icon); + } + /** * Sets that this bubble represents the overflow. The overflow appears in the list of bubbles * but does not represent app content, instead it shows recent bubbles that couldn't fit into @@ -278,7 +271,8 @@ public class BubbleView extends ConstraintLayout { */ public void setOverflow(BubbleBarOverflow overflow, Bitmap bitmap) { mBubble = overflow; - mBubbleIcon.setImageBitmap(bitmap); + mIcon = bitmap; + updateBubbleIcon(); mAppIcon.setVisibility(GONE); // Overflow doesn't show the app badge setContentDescription(getResources().getString(R.string.bubble_bar_overflow_description)); }