Merge "Fix bug where ripple extends out of bounds in pop up container." into sc-dev am: 576179199a
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/15019204
Change-Id: I7104161f3e5b2838afe34c76e21e3d4ca1b6bfc7
diff --git a/src/com/android/launcher3/popup/ArrowPopup.java b/src/com/android/launcher3/popup/ArrowPopup.java
index 2095a0d..cb35f74 100644
--- a/src/com/android/launcher3/popup/ArrowPopup.java
+++ b/src/com/android/launcher3/popup/ArrowPopup.java
@@ -252,9 +252,9 @@
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 cc658c9..71d288c 100644
--- a/src/com/android/launcher3/shortcuts/DeepShortcutView.java
+++ b/src/com/android/launcher3/shortcuts/DeepShortcutView.java
@@ -18,7 +18,13 @@
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.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 @@
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