From 35c5477d5c706a55fa5761a7c3509c1b202bfcfa Mon Sep 17 00:00:00 2001 From: Jon Miranda Date: Fri, 7 May 2021 15:29:54 -0700 Subject: [PATCH] Remove color extraction from popup arrow, add shadows. Bug: 175329686 Bug: 187014675 Test: manual Change-Id: I84a3f23b7a9ceef004a2b1b66e5f8a10585bd113 --- .../deep_shortcuts_text_placeholder.xml | 2 +- res/drawable/ic_deepshortcut_placeholder.xml | 4 +- res/drawable/single_item_secondary.xml | 20 -- res/layout/deep_shortcut.xml | 1 + res/layout/longpress_options_menu.xml | 1 - res/layout/popup_container.xml | 2 +- res/layout/system_shortcut.xml | 1 + res/layout/system_shortcut_icons.xml | 3 +- res/values-v31/colors.xml | 3 +- res/values/attrs.xml | 1 - res/values/colors.xml | 1 - res/values/dimens.xml | 3 +- res/values/styles.xml | 2 - .../notification/NotificationItemView.java | 4 - .../android/launcher3/popup/ArrowPopup.java | 177 ++---------------- .../popup/PopupContainerWithArrow.java | 8 - 16 files changed, 25 insertions(+), 208 deletions(-) delete mode 100644 res/drawable/single_item_secondary.xml diff --git a/res/drawable/deep_shortcuts_text_placeholder.xml b/res/drawable/deep_shortcuts_text_placeholder.xml index 99da50fdca..5820d6b79f 100644 --- a/res/drawable/deep_shortcuts_text_placeholder.xml +++ b/res/drawable/deep_shortcuts_text_placeholder.xml @@ -15,7 +15,7 @@ --> - + diff --git a/res/drawable/ic_deepshortcut_placeholder.xml b/res/drawable/ic_deepshortcut_placeholder.xml index 3fa85065bd..16e7cf3a58 100644 --- a/res/drawable/ic_deepshortcut_placeholder.xml +++ b/res/drawable/ic_deepshortcut_placeholder.xml @@ -15,6 +15,6 @@ limitations under the License. --> - - + + diff --git a/res/drawable/single_item_secondary.xml b/res/drawable/single_item_secondary.xml deleted file mode 100644 index 4edc4813aa..0000000000 --- a/res/drawable/single_item_secondary.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/res/layout/deep_shortcut.xml b/res/layout/deep_shortcut.xml index 0d11b50ab3..b175d1703f 100644 --- a/res/layout/deep_shortcut.xml +++ b/res/layout/deep_shortcut.xml @@ -19,6 +19,7 @@ xmlns:launcher="http://schemas.android.com/apk/res-auto" android:layout_width="@dimen/bg_popup_item_width" android:layout_height="@dimen/bg_popup_item_height" + android:elevation="@dimen/deep_shortcuts_elevation" android:background="@drawable/middle_item_primary" android:theme="@style/PopupItem" > diff --git a/res/layout/longpress_options_menu.xml b/res/layout/longpress_options_menu.xml index 3898365b1c..d2f7a660d9 100644 --- a/res/layout/longpress_options_menu.xml +++ b/res/layout/longpress_options_menu.xml @@ -20,6 +20,5 @@ android:layout_height="wrap_content" android:clipToPadding="false" android:clipChildren="false" - android:elevation="@dimen/deep_shortcuts_elevation" android:importantForAccessibility="yes" android:orientation="vertical" /> diff --git a/res/layout/popup_container.xml b/res/layout/popup_container.xml index 04822fd7a2..7c78e441f2 100644 --- a/res/layout/popup_container.xml +++ b/res/layout/popup_container.xml @@ -21,7 +21,6 @@ android:layout_height="wrap_content" android:clipToPadding="false" android:clipChildren="false" - android:elevation="@dimen/deep_shortcuts_elevation" android:orientation="vertical"> \ No newline at end of file diff --git a/res/layout/system_shortcut.xml b/res/layout/system_shortcut.xml index 9f45f30216..6337faeadb 100644 --- a/res/layout/system_shortcut.xml +++ b/res/layout/system_shortcut.xml @@ -19,6 +19,7 @@ xmlns:launcher="http://schemas.android.com/apk/res-auto" android:layout_width="@dimen/bg_popup_item_width" android:layout_height="@dimen/bg_popup_item_height" + android:elevation="@dimen/deep_shortcuts_elevation" android:background="@drawable/middle_item_primary" android:theme="@style/PopupItem" > diff --git a/res/layout/system_shortcut_icons.xml b/res/layout/system_shortcut_icons.xml index f9922488fb..775a45f47b 100644 --- a/res/layout/system_shortcut_icons.xml +++ b/res/layout/system_shortcut_icons.xml @@ -21,7 +21,8 @@ android:layout_height="@dimen/system_shortcut_header_height" android:orientation="horizontal" android:gravity="end|center_vertical" - android:background="@drawable/single_item_secondary" + android:background="@drawable/single_item_primary" + android:elevation="@dimen/deep_shortcuts_elevation" android:clipToPadding="true"> - @android:color/system_neutral1_0 - @android:color/system_neutral1_50 + @android:color/system_neutral1_0 @android:color/system_neutral2_100 @android:color/system_neutral2_300 @android:color/system_neutral1_1000 diff --git a/res/values/attrs.xml b/res/values/attrs.xml index a81802d87a..ad46d0f7bb 100644 --- a/res/values/attrs.xml +++ b/res/values/attrs.xml @@ -21,7 +21,6 @@ - diff --git a/res/values/colors.xml b/res/values/colors.xml index 56a0e6bd9b..7345be4510 100644 --- a/res/values/colors.xml +++ b/res/values/colors.xml @@ -41,7 +41,6 @@ #FF000000 #B7F29F - #FFF #FFF #F1F3F4 #E0E0E0 diff --git a/res/values/dimens.xml b/res/values/dimens.xml index 3267a5d246..1fbf8a486c 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -202,7 +202,8 @@ 2dp - 0dp + 2dp + 2dp 216dp 56dp 6dp diff --git a/res/values/styles.xml b/res/values/styles.xml index dd72114495..ab415b1eee 100644 --- a/res/values/styles.xml +++ b/res/values/styles.xml @@ -34,7 +34,6 @@ ?android:attr/colorBackgroundFloating #66FFFFFF @style/AllAppsTheme - @color/popup_color_neutral_light @color/popup_color_primary_light @color/popup_color_secondary_light @color/popup_color_tertiary_light @@ -98,7 +97,6 @@ ?android:attr/colorBackgroundFloating #80000000 @style/AllAppsTheme.Dark - @color/popup_color_neutral_dark @color/popup_color_primary_dark @color/popup_color_secondary_dark @color/popup_color_tertiary_dark diff --git a/src/com/android/launcher3/notification/NotificationItemView.java b/src/com/android/launcher3/notification/NotificationItemView.java index e954480ca5..d44d158010 100644 --- a/src/com/android/launcher3/notification/NotificationItemView.java +++ b/src/com/android/launcher3/notification/NotificationItemView.java @@ -92,10 +92,6 @@ public class NotificationItemView { }); } - public void updateBackgroundColor(int color) { - mMainView.updateBackgroundColor(color); - } - public void addGutter() { if (mGutter == null) { mGutter = mPopupContainer.inflateAndAdd(R.layout.notification_gutter, mRootView); diff --git a/src/com/android/launcher3/popup/ArrowPopup.java b/src/com/android/launcher3/popup/ArrowPopup.java index 73ac8f2ab5..8dea14a8c0 100644 --- a/src/com/android/launcher3/popup/ArrowPopup.java +++ b/src/com/android/launcher3/popup/ArrowPopup.java @@ -19,21 +19,15 @@ package com.android.launcher3.popup; import static com.android.launcher3.anim.Interpolators.ACCELERATED_EASE; import static com.android.launcher3.anim.Interpolators.DECELERATED_EASE; import static com.android.launcher3.anim.Interpolators.LINEAR; -import static com.android.launcher3.popup.PopupPopulator.MAX_SHORTCUTS; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.AnimatorSet; -import android.animation.ArgbEvaluator; import android.animation.ObjectAnimator; import android.animation.ValueAnimator; import android.content.Context; import android.content.res.Resources; -import android.graphics.Outline; import android.graphics.Rect; -import android.graphics.RectF; -import android.graphics.drawable.ColorDrawable; -import android.graphics.drawable.Drawable; import android.graphics.drawable.GradientDrawable; import android.util.AttributeSet; import android.util.Pair; @@ -41,32 +35,25 @@ import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.view.ViewOutlineProvider; -import android.view.ViewTreeObserver; import android.view.animation.Interpolator; import android.widget.FrameLayout; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import com.android.launcher3.AbstractFloatingView; import com.android.launcher3.BaseDraggingActivity; import com.android.launcher3.InsettableFrameLayout; -import com.android.launcher3.Launcher; import com.android.launcher3.LauncherState; import com.android.launcher3.R; import com.android.launcher3.Utilities; -import com.android.launcher3.Workspace; import com.android.launcher3.dragndrop.DragLayer; import com.android.launcher3.shortcuts.DeepShortcutView; import com.android.launcher3.statemanager.StatefulActivity; import com.android.launcher3.util.Themes; import com.android.launcher3.views.BaseDragLayer; -import com.android.launcher3.widget.LocalColorExtractor; import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; /** * A container for shortcuts to deep links and notifications associated with an app. @@ -89,9 +76,6 @@ public abstract class ArrowPopup> private static final int CLOSE_CHILD_FADE_START_DELAY = 0; private static final int CLOSE_CHILD_FADE_DURATION = 140; - // +1 for system shortcut view - private static final int MAX_NUM_CHILDREN = MAX_SHORTCUTS + 1; - private final Rect mTempRect = new Rect(); protected final LayoutInflater mInflater; @@ -120,13 +104,8 @@ public abstract class ArrowPopup> private Runnable mOnCloseCallback = () -> { }; - // The rect string of the view that the arrow is attached to, in screen reference frame. - private String mArrowColorRectString; - private int mArrowColor; - private final int[] mColors; - private final HashMap mViewForRect = new HashMap<>(); - - @Nullable private LocalColorExtractor mColorExtractor; + private final float mElevation; + private final int mBackgroundColor; public ArrowPopup(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); @@ -134,13 +113,9 @@ public abstract class ArrowPopup> mOutlineRadius = Themes.getDialogCornerRadius(context); mLauncher = BaseDraggingActivity.fromContext(context); mIsRtl = Utilities.isRtl(getResources()); - setClipToOutline(true); - setOutlineProvider(new ViewOutlineProvider() { - @Override - public void getOutline(View view, Outline outline) { - outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), mOutlineRadius); - } - }); + + mBackgroundColor = Themes.getAttrColor(context, R.attr.popupColorPrimary); + mElevation = getResources().getDimension(R.dimen.deep_shortcuts_elevation); // Initialize arrow view final Resources resources = getResources(); @@ -156,33 +131,14 @@ public abstract class ArrowPopup> int smallerRadius = resources.getDimensionPixelSize(R.dimen.popup_smaller_radius); mRoundedTop = new GradientDrawable(); + mRoundedTop.setColor(mBackgroundColor); mRoundedTop.setCornerRadii(new float[] { mOutlineRadius, mOutlineRadius, mOutlineRadius, mOutlineRadius, smallerRadius, smallerRadius, smallerRadius, smallerRadius}); mRoundedBottom = new GradientDrawable(); + mRoundedBottom.setColor(mBackgroundColor); mRoundedBottom.setCornerRadii(new float[] { smallerRadius, smallerRadius, smallerRadius, smallerRadius, mOutlineRadius, mOutlineRadius, mOutlineRadius, mOutlineRadius}); - - boolean isAboveAnotherSurface = getTopOpenViewWithType(mLauncher, TYPE_FOLDER) != null - || mLauncher.getStateManager().getState() == LauncherState.ALL_APPS; - if (isAboveAnotherSurface) { - mColors = new int[] { Themes.getAttrColor(context, R.attr.popupColorNeutral) }; - } else { - int primaryColor = Themes.getAttrColor(context, R.attr.popupColorPrimary); - int secondaryColor = Themes.getAttrColor(context, R.attr.popupColorSecondary); - ArgbEvaluator argb = new ArgbEvaluator(); - mColors = new int[MAX_NUM_CHILDREN]; - // Interpolate between the two colors, exclusive. - float step = 1f / (MAX_NUM_CHILDREN + 1); - for (int i = 0; i < mColors.length; ++i) { - mColors[i] = - (int) argb.evaluate((i + 1) * step, primaryColor, secondaryColor); - } - - if (supportsColorExtraction()) { - setupColorExtraction(); - } - } } public ArrowPopup(Context context, AttributeSet attrs) { @@ -240,7 +196,6 @@ public abstract class ArrowPopup> int numVisibleShortcut = 0; View lastView = null; - int numVisibleChild = 0; for (int i = 0; i < count; i++) { View view = getChildAt(i); boolean isShortcut = view instanceof DeepShortcutView; @@ -267,35 +222,11 @@ public abstract class ArrowPopup> numVisibleShortcut++; } } - - int color = mColors[numVisibleChild % mColors.length]; - setChildColor(view, color); - - // Arrow color matches the first child or the last child. - if (!mIsAboveIcon && numVisibleChild == 0) { - mArrowColor = color; - } else if (mIsAboveIcon) { - mArrowColor = color; - } - - numVisibleChild++; } } measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); } - /** - * Sets the background color of the child. - */ - protected void setChildColor(View view, int color) { - Drawable bg = view.getBackground(); - if (bg instanceof GradientDrawable) { - ((GradientDrawable) bg.mutate()).setColor(color); - } else if (bg instanceof ColorDrawable) { - ((ColorDrawable) bg.mutate()).setColor(color); - } - } - /** * Shows the popup at the desired location, optionally reversing the children. * @param viewsToFlip number of views from the top to to flip in case of reverse order @@ -366,23 +297,18 @@ public abstract class ArrowPopup> // so we centered it instead. In that case we don't want to showDefaultOptions the arrow. mArrow.setVisibility(INVISIBLE); } else { - updateArrowColor(); - } - - mArrow.setPivotX(mArrowWidth / 2.0f); - mArrow.setPivotY(mIsAboveIcon ? mArrowHeight : 0); - } - - private void updateArrowColor() { - if (!Gravity.isVertical(mGravity)) { mArrow.setBackground(new RoundedArrowDrawable( mArrowWidth, mArrowHeight, mArrowPointRadius, mOutlineRadius, getMeasuredWidth(), getMeasuredHeight(), mArrowOffsetHorizontal, -mArrowOffsetVertical, !mIsAboveIcon, mIsLeftAligned, - mArrowColor)); - mArrow.setElevation(getElevation()); + mBackgroundColor)); + // TODO: Remove elevation when arrow is above as it casts a shadow on the container + mArrow.setElevation(mIsAboveIcon ? mElevation : 0); } + + mArrow.setPivotX(mArrowWidth / 2.0f); + mArrow.setPivotY(mIsAboveIcon ? mArrowHeight : 0); } /** @@ -434,7 +360,7 @@ public abstract class ArrowPopup> } int childMargins = (numVisibleChildren - 1) * mMargin; int height = getMeasuredHeight() + extraVerticalSpace + childMargins; - int width = getMeasuredWidth(); + int width = getMeasuredWidth() + getPaddingLeft() + getPaddingRight(); getTargetObjectLocation(mTempRect); InsettableFrameLayout dragLayer = getPopupContainer(); @@ -667,19 +593,6 @@ public abstract class ArrowPopup> getPopupContainer().removeView(this); getPopupContainer().removeView(mArrow); mOnCloseCallback.run(); - mArrowColorRectString = null; - mViewForRect.clear(); - if (mColorExtractor != null) { - mColorExtractor.removeLocations(); - mColorExtractor.setListener(null); - } - } - - /** - * Returns whether color extraction is supported. - */ - public boolean supportsColorExtraction() { - return Utilities.ATLEAST_S; } /** @@ -689,68 +602,6 @@ public abstract class ArrowPopup> mOnCloseCallback = callback; } - private void setupColorExtraction() { - Workspace workspace = mLauncher.findViewById(R.id.workspace); - if (workspace == null) { - return; - } - - mColorExtractor = LocalColorExtractor.newInstance(mLauncher); - mColorExtractor.setListener((rect, extractedColors) -> { - String rectString = rect.toShortString(); - View v = mViewForRect.get(rectString); - if (v != null) { - int newColor = extractedColors.get(mColorExtractionIndex); - setChildColor(v, newColor); - if (rectString.equals(mArrowColorRectString)) { - mArrowColor = newColor; - updateArrowColor(); - } - } - }); - - getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { - @Override - public boolean onPreDraw() { - getViewTreeObserver().removeOnPreDrawListener(this); - - ArrayList locations = new ArrayList<>(); - Rect r = new Rect(); - - int count = getChildCount(); - int numVisibleChild = 0; - for (int i = 0; i < count; i++) { - View view = getChildAt(i); - if (view.getVisibility() == VISIBLE) { - RectF rf = new RectF(); - mColorExtractor.getExtractedRectForView(Launcher.getLauncher(getContext()), - workspace.getCurrentPage(), view, rf); - if (rf.isEmpty()) { - numVisibleChild++; - continue; - } - - locations.add(rf); - String rectString = rf.toShortString(); - mViewForRect.put(rectString, view); - - // Arrow color matches the first child or the last child. - if (!mIsAboveIcon && numVisibleChild == 0) { - mArrowColorRectString = rectString; - } else if (mIsAboveIcon) { - mArrowColorRectString = rectString; - } - - numVisibleChild++; - } - } - - mColorExtractor.addLocation(locations); - return false; - } - }); - } - protected BaseDragLayer getPopupContainer() { return mLauncher.getDragLayer(); } diff --git a/src/com/android/launcher3/popup/PopupContainerWithArrow.java b/src/com/android/launcher3/popup/PopupContainerWithArrow.java index 1659e6d9cf..b115678562 100644 --- a/src/com/android/launcher3/popup/PopupContainerWithArrow.java +++ b/src/com/android/launcher3/popup/PopupContainerWithArrow.java @@ -172,14 +172,6 @@ public class PopupContainerWithArrow> return false; } - @Override - protected void setChildColor(View v, int color) { - super.setChildColor(v, color); - if (v.getId() == R.id.notification_container && mNotificationItemView != null) { - mNotificationItemView.updateBackgroundColor(color); - } - } - /** * Returns true if we can show the container. */