From f13ddbd333d7b2aabcd45e4e708b8479e99d3cc9 Mon Sep 17 00:00:00 2001 From: Jon Miranda Date: Thu, 17 Jun 2021 15:40:04 -0700 Subject: [PATCH] Fix bug where ripple extends out of bounds in pop up container. Bug: 186820908 Test: test apps with diff. pop up container arrangements test prefs in all apps Change-Id: I4d3e26871416835ab2a851fcc6fe2c4f70235b62 --- .../android/launcher3/popup/ArrowPopup.java | 4 +- .../launcher3/shortcuts/DeepShortcutView.java | 51 ++++++++++++++++++- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/src/com/android/launcher3/popup/ArrowPopup.java b/src/com/android/launcher3/popup/ArrowPopup.java index 2095a0de54..cb35f74135 100644 --- a/src/com/android/launcher3/popup/ArrowPopup.java +++ b/src/com/android/launcher3/popup/ArrowPopup.java @@ -252,9 +252,9 @@ public abstract class ArrowPopup> view.setBackgroundResource(R.drawable.single_item_primary); } else if (totalVisibleShortcuts > 1) { if (numVisibleShortcut == 0) { - view.setBackground(mRoundedTop); + view.setBackground(mRoundedTop.getConstantState().newDrawable()); } else if (numVisibleShortcut == (totalVisibleShortcuts - 1)) { - view.setBackground(mRoundedBottom); + view.setBackground(mRoundedBottom.getConstantState().newDrawable()); } else { view.setBackgroundResource(R.drawable.middle_item_primary); } diff --git a/src/com/android/launcher3/shortcuts/DeepShortcutView.java b/src/com/android/launcher3/shortcuts/DeepShortcutView.java index cc658c9ba0..71d288c0ab 100644 --- a/src/com/android/launcher3/shortcuts/DeepShortcutView.java +++ b/src/com/android/launcher3/shortcuts/DeepShortcutView.java @@ -18,7 +18,13 @@ package com.android.launcher3.shortcuts; import android.content.Context; import android.content.pm.ShortcutInfo; +import android.content.res.ColorStateList; +import android.graphics.Color; import android.graphics.Point; +import android.graphics.drawable.ColorDrawable; +import android.graphics.drawable.Drawable; +import android.graphics.drawable.GradientDrawable; +import android.graphics.drawable.RippleDrawable; import android.text.TextUtils; import android.util.AttributeSet; import android.view.View; @@ -30,16 +36,20 @@ import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.model.data.WorkspaceItemInfo; import com.android.launcher3.popup.PopupContainerWithArrow; +import com.android.launcher3.util.Themes; import com.android.launcher3.views.BubbleTextHolder; /** - * A {@link android.widget.FrameLayout} that contains a {@link DeepShortcutView}. - * This lets us animate the DeepShortcutView (icon and text) separately from the background. + * A {@link android.widget.FrameLayout} that contains an icon and a {@link BubbleTextView} for text. + * This lets us animate the child BubbleTextView's background (transparent ripple) separately from + * the {@link DeepShortcutView} background color. */ public class DeepShortcutView extends FrameLayout implements BubbleTextHolder { private static final Point sTempPoint = new Point(); + private final Drawable mTransparentDrawable = new ColorDrawable(Color.TRANSPARENT); + private BubbleTextView mBubbleText; private View mIconView; @@ -63,6 +73,43 @@ public class DeepShortcutView extends FrameLayout implements BubbleTextHolder { super.onFinishInflate(); mBubbleText = findViewById(R.id.bubble_text); mIconView = findViewById(R.id.icon); + tryUpdateTextBackground(); + } + + @Override + public void setBackground(Drawable background) { + super.setBackground(background); + tryUpdateTextBackground(); + } + + @Override + public void setBackgroundResource(int resid) { + super.setBackgroundResource(resid); + tryUpdateTextBackground(); + } + + /** + * Updates the text background to match the shape of this background (when applicable). + */ + private void tryUpdateTextBackground() { + if (!(getBackground() instanceof GradientDrawable) || mBubbleText == null) { + return; + } + GradientDrawable background = (GradientDrawable) getBackground(); + + int color = Themes.getAttrColor(getContext(), android.R.attr.colorControlHighlight); + GradientDrawable backgroundMask = new GradientDrawable(); + backgroundMask.setColor(color); + backgroundMask.setShape(GradientDrawable.RECTANGLE); + if (background.getCornerRadii() != null) { + backgroundMask.setCornerRadii(background.getCornerRadii()); + } else { + backgroundMask.setCornerRadius(background.getCornerRadius()); + } + + RippleDrawable drawable = new RippleDrawable(ColorStateList.valueOf(color), + mTransparentDrawable, backgroundMask); + mBubbleText.setBackground(drawable); } @Override