Merge "Adding color back to popup container." into sc-dev am: d88f572864

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/14796372

Change-Id: I04cf5e44f34ef354959ccc9fe7aaac5f09bb2f45
This commit is contained in:
Jonathan Miranda authored and Automerger Merge Worker committed 2021-06-11 17:29:26 +00:00
commit 8b14b2da8a
13 files changed
+300 -45

No files matched your search

+1 -1
View File
@@ -15,7 +15,7 @@
--> -->
<com.android.launcher3.views.OptionsPopupView <com.android.launcher3.views.OptionsPopupView
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/deep_shortcuts_container" android:id="@+id/popup_container"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:clipToPadding="false" android:clipToPadding="false"
+10 -1
View File
@@ -16,12 +16,21 @@
<com.android.launcher3.popup.PopupContainerWithArrow <com.android.launcher3.popup.PopupContainerWithArrow
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/deep_shortcuts_container" android:id="@+id/popup_container"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:clipToPadding="false" android:clipToPadding="false"
android:clipChildren="false" android:clipChildren="false"
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout
android:id="@+id/deep_shortcuts_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tag="@string/popup_container_iterate_children"
android:elevation="@dimen/deep_shortcuts_elevation"
android:orientation="vertical"/>
<LinearLayout <LinearLayout
android:id="@+id/notification_container" android:id="@+id/notification_container"
android:layout_width="match_parent" android:layout_width="match_parent"
+2 -2
View File
@@ -17,11 +17,11 @@
*/ */
--> -->
<resources> <resources>
<color name="popup_color_primary_light">@android:color/system_neutral1_0</color> <color name="popup_color_primary_light">@android:color/system_accent2_50</color>
<color name="popup_color_secondary_light">@android:color/system_neutral2_100</color> <color name="popup_color_secondary_light">@android:color/system_neutral2_100</color>
<color name="popup_color_tertiary_light">@android:color/system_neutral2_300</color> <color name="popup_color_tertiary_light">@android:color/system_neutral2_300</color>
<color name="popup_color_neutral_dark">@android:color/system_neutral1_1000</color> <color name="popup_color_neutral_dark">@android:color/system_neutral1_1000</color>
<color name="popup_color_primary_dark">@android:color/system_neutral1_800</color> <color name="popup_color_primary_dark">@android:color/system_neutral2_800</color>
<color name="popup_color_secondary_dark">@android:color/system_neutral1_900</color> <color name="popup_color_secondary_dark">@android:color/system_neutral1_900</color>
<color name="popup_color_tertiary_dark">@android:color/system_neutral2_700</color> <color name="popup_color_tertiary_dark">@android:color/system_neutral2_700</color>
+3
View File
@@ -31,6 +31,9 @@
<!-- View tag key used to store SpringAnimation data. --> <!-- View tag key used to store SpringAnimation data. -->
<item type="id" name="spring_animation_tag" /> <item type="id" name="spring_animation_tag" />
<!-- View tag key used to determine if we should fade in the child views.. -->
<string name="popup_container_iterate_children" translatable="false">popup_container_iterate_children</string>
<!-- Workspace --> <!-- Workspace -->
<!-- The duration (in ms) of the fade animation on the object outlines, used when <!-- The duration (in ms) of the fade animation on the object outlines, used when
we are dragging objects around on the home screen. --> we are dragging objects around on the home screen. -->
@@ -18,6 +18,7 @@ package com.android.launcher3.notification;
import static com.android.launcher3.touch.SingleAxisSwipeDetector.HORIZONTAL; import static com.android.launcher3.touch.SingleAxisSwipeDetector.HORIZONTAL;
import android.animation.AnimatorSet;
import android.app.Notification; import android.app.Notification;
import android.content.Context; import android.content.Context;
import android.graphics.Color; import android.graphics.Color;
@@ -92,6 +93,15 @@ public class NotificationItemView {
}); });
} }
/**
* Animates the background color to a new color.
* @param color The color to change to.
* @param animatorSetOut The AnimatorSet where we add the color animator to.
*/
public void updateBackgroundColor(int color, AnimatorSet animatorSetOut) {
mMainView.updateBackgroundColor(color, animatorSetOut);
}
public void addGutter() { public void addGutter() {
if (mGutter == null) { if (mGutter == null) {
mGutter = mPopupContainer.inflateAndAdd(R.layout.notification_gutter, mRootView); mGutter = mPopupContainer.inflateAndAdd(R.layout.notification_gutter, mRootView);
@@ -20,10 +20,13 @@ import static com.android.launcher3.anim.Interpolators.scrollInterpolatorForVelo
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_NOTIFICATION_DISMISSED; import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_NOTIFICATION_DISMISSED;
import android.animation.Animator; import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator; import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.content.Context; import android.content.Context;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.RippleDrawable; import android.graphics.drawable.RippleDrawable;
import android.os.Build; import android.os.Build;
@@ -78,6 +81,9 @@ public class NotificationMainView extends FrameLayout implements SingleAxisSwipe
private SingleAxisSwipeDetector mSwipeDetector; private SingleAxisSwipeDetector mSwipeDetector;
private final ColorDrawable mColorDrawable;
private final RippleDrawable mRippleDrawable;
public NotificationMainView(Context context) { public NotificationMainView(Context context) {
this(context, null, 0); this(context, null, 0);
} }
@@ -90,6 +96,10 @@ public class NotificationMainView extends FrameLayout implements SingleAxisSwipe
super(context, attrs, defStyle); super(context, attrs, defStyle);
mContentTranslateAnimator = ObjectAnimator.ofFloat(this, CONTENT_TRANSLATION, 0); mContentTranslateAnimator = ObjectAnimator.ofFloat(this, CONTENT_TRANSLATION, 0);
mColorDrawable = new ColorDrawable(Color.TRANSPARENT);
mRippleDrawable = new RippleDrawable(ColorStateList.valueOf(
Themes.getAttrColor(getContext(), android.R.attr.colorControlHighlight)),
mColorDrawable, null);
} }
@Override @Override
@@ -105,18 +115,31 @@ public class NotificationMainView extends FrameLayout implements SingleAxisSwipe
updateBackgroundColor(colorBackground.getColor()); updateBackgroundColor(colorBackground.getColor());
} }
public void updateBackgroundColor(int color) { private void updateBackgroundColor(int color) {
mBackgroundColor = color; mBackgroundColor = color;
RippleDrawable rippleBackground = new RippleDrawable(ColorStateList.valueOf( mColorDrawable.setColor(color);
Themes.getAttrColor(getContext(), android.R.attr.colorControlHighlight)), mTextAndBackground.setBackground(mRippleDrawable);
new ColorDrawable(color), null);
mTextAndBackground.setBackground(rippleBackground);
if (mNotificationInfo != null) { if (mNotificationInfo != null) {
mIconView.setBackground(mNotificationInfo.getIconForBackground(getContext(), mIconView.setBackground(mNotificationInfo.getIconForBackground(getContext(),
mBackgroundColor)); mBackgroundColor));
} }
} }
/**
* Animates the background color to a new color.
* @param color The color to change to.
* @param animatorSetOut The AnimatorSet where we add the color animator to.
*/
public void updateBackgroundColor(int color, AnimatorSet animatorSetOut) {
int oldColor = mBackgroundColor;
ValueAnimator colors = ValueAnimator.ofArgb(oldColor, color);
colors.addUpdateListener(valueAnimator -> {
int newColor = (int) valueAnimator.getAnimatedValue();
updateBackgroundColor(newColor);
});
animatorSetOut.play(colors);
}
public void setSwipeDetector(SingleAxisSwipeDetector swipeDetector) { public void setSwipeDetector(SingleAxisSwipeDetector swipeDetector) {
mSwipeDetector = swipeDetector; mSwipeDetector = swipeDetector;
} }
+194 -22
View File
@@ -25,35 +25,48 @@ import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet; import android.animation.AnimatorSet;
import android.animation.ObjectAnimator; import android.animation.ObjectAnimator;
import android.animation.ValueAnimator; import android.animation.ValueAnimator;
import android.annotation.TargetApi;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Rect; 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.graphics.drawable.GradientDrawable;
import android.os.Build;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Pair; import android.util.Pair;
import android.util.SparseIntArray;
import android.view.Gravity; import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.animation.Interpolator; import android.view.animation.Interpolator;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.android.launcher3.AbstractFloatingView; import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.BaseDraggingActivity; import com.android.launcher3.BaseDraggingActivity;
import com.android.launcher3.InsettableFrameLayout; import com.android.launcher3.InsettableFrameLayout;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState; import com.android.launcher3.LauncherState;
import com.android.launcher3.R; import com.android.launcher3.R;
import com.android.launcher3.Utilities; import com.android.launcher3.Utilities;
import com.android.launcher3.Workspace;
import com.android.launcher3.dragndrop.DragLayer; import com.android.launcher3.dragndrop.DragLayer;
import com.android.launcher3.shortcuts.DeepShortcutView; import com.android.launcher3.shortcuts.DeepShortcutView;
import com.android.launcher3.statemanager.StatefulActivity; import com.android.launcher3.statemanager.StatefulActivity;
import com.android.launcher3.util.Themes; import com.android.launcher3.util.Themes;
import com.android.launcher3.views.BaseDragLayer; import com.android.launcher3.views.BaseDragLayer;
import com.android.launcher3.widget.LocalColorExtractor;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.List;
/** /**
* A container for shortcuts to deep links and notifications associated with an app. * A container for shortcuts to deep links and notifications associated with an app.
@@ -76,6 +89,10 @@ public abstract class ArrowPopup<T extends StatefulActivity<LauncherState>>
private static final int CLOSE_CHILD_FADE_START_DELAY = 0; private static final int CLOSE_CHILD_FADE_START_DELAY = 0;
private static final int CLOSE_CHILD_FADE_DURATION = 140; private static final int CLOSE_CHILD_FADE_DURATION = 140;
// Index used to get background color when using local wallpaper color extraction,
private static final int DARK_COLOR_EXTRACTION_INDEX = android.R.color.system_neutral2_800;
private static final int LIGHT_COLOR_EXTRACTION_INDEX = android.R.color.system_accent2_50;
private final Rect mTempRect = new Rect(); private final Rect mTempRect = new Rect();
protected final LayoutInflater mInflater; protected final LayoutInflater mInflater;
@@ -104,9 +121,18 @@ public abstract class ArrowPopup<T extends StatefulActivity<LauncherState>>
private Runnable mOnCloseCallback = () -> { }; private Runnable mOnCloseCallback = () -> { };
// The rect string of the view that the arrow is attached to, in screen reference frame.
protected String mArrowColorRectString;
private int mArrowColor;
protected final HashMap<String, View> mViewForRect = new HashMap<>();
@Nullable protected LocalColorExtractor mColorExtractor;
private final float mElevation; private final float mElevation;
private final int mBackgroundColor; private final int mBackgroundColor;
private final String mIterateChildrenTag;
public ArrowPopup(Context context, AttributeSet attrs, int defStyleAttr) { public ArrowPopup(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr); super(context, attrs, defStyleAttr);
mInflater = LayoutInflater.from(context); mInflater = LayoutInflater.from(context);
@@ -115,6 +141,7 @@ public abstract class ArrowPopup<T extends StatefulActivity<LauncherState>>
mIsRtl = Utilities.isRtl(getResources()); mIsRtl = Utilities.isRtl(getResources());
mBackgroundColor = Themes.getAttrColor(context, R.attr.popupColorPrimary); mBackgroundColor = Themes.getAttrColor(context, R.attr.popupColorPrimary);
mArrowColor = mBackgroundColor;
mElevation = getResources().getDimension(R.dimen.deep_shortcuts_elevation); mElevation = getResources().getDimension(R.dimen.deep_shortcuts_elevation);
// Initialize arrow view // Initialize arrow view
@@ -139,6 +166,14 @@ public abstract class ArrowPopup<T extends StatefulActivity<LauncherState>>
mRoundedBottom.setColor(mBackgroundColor); mRoundedBottom.setColor(mBackgroundColor);
mRoundedBottom.setCornerRadii(new float[] { smallerRadius, smallerRadius, smallerRadius, mRoundedBottom.setCornerRadii(new float[] { smallerRadius, smallerRadius, smallerRadius,
smallerRadius, mOutlineRadius, mOutlineRadius, mOutlineRadius, mOutlineRadius}); smallerRadius, mOutlineRadius, mOutlineRadius, mOutlineRadius, mOutlineRadius});
mIterateChildrenTag = getContext().getString(R.string.popup_container_iterate_children);
boolean isAboveAnotherSurface = getTopOpenViewWithType(mLauncher, TYPE_FOLDER) != null
|| mLauncher.getStateManager().getState() == LauncherState.ALL_APPS;
if (!isAboveAnotherSurface && Utilities.ATLEAST_S) {
setupColorExtraction();
}
} }
public ArrowPopup(Context context, AttributeSet attrs) { public ArrowPopup(Context context, AttributeSet attrs) {
@@ -184,11 +219,11 @@ public abstract class ArrowPopup<T extends StatefulActivity<LauncherState>>
/** /**
* Set the margins and radius of backgrounds after views are properly ordered. * Set the margins and radius of backgrounds after views are properly ordered.
*/ */
protected void assignMarginsAndBackgrounds() { public void assignMarginsAndBackgrounds(ViewGroup viewGroup) {
int count = getChildCount(); int count = viewGroup.getChildCount();
int totalVisibleShortcuts = 0; int totalVisibleShortcuts = 0;
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
View view = getChildAt(i); View view = viewGroup.getChildAt(i);
if (view.getVisibility() == VISIBLE && view instanceof DeepShortcutView) { if (view.getVisibility() == VISIBLE && view instanceof DeepShortcutView) {
totalVisibleShortcuts++; totalVisibleShortcuts++;
} }
@@ -197,8 +232,7 @@ public abstract class ArrowPopup<T extends StatefulActivity<LauncherState>>
int numVisibleShortcut = 0; int numVisibleShortcut = 0;
View lastView = null; View lastView = null;
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
View view = getChildAt(i); View view = viewGroup.getChildAt(i);
boolean isShortcut = view instanceof DeepShortcutView;
if (view.getVisibility() == VISIBLE) { if (view.getVisibility() == VISIBLE) {
if (lastView != null) { if (lastView != null) {
MarginLayoutParams mlp = (MarginLayoutParams) lastView.getLayoutParams(); MarginLayoutParams mlp = (MarginLayoutParams) lastView.getLayoutParams();
@@ -208,7 +242,12 @@ public abstract class ArrowPopup<T extends StatefulActivity<LauncherState>>
MarginLayoutParams mlp = (MarginLayoutParams) lastView.getLayoutParams(); MarginLayoutParams mlp = (MarginLayoutParams) lastView.getLayoutParams();
mlp.bottomMargin = 0; mlp.bottomMargin = 0;
if (isShortcut) { if (view instanceof ViewGroup && mIterateChildrenTag.equals(view.getTag())) {
assignMarginsAndBackgrounds((ViewGroup) view);
continue;
}
if (view instanceof DeepShortcutView) {
if (totalVisibleShortcuts == 1) { if (totalVisibleShortcuts == 1) {
view.setBackgroundResource(R.drawable.single_item_primary); view.setBackgroundResource(R.drawable.single_item_primary);
} else if (totalVisibleShortcuts > 1) { } else if (totalVisibleShortcuts > 1) {
@@ -227,6 +266,118 @@ public abstract class ArrowPopup<T extends StatefulActivity<LauncherState>>
measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
} }
@TargetApi(Build.VERSION_CODES.S)
private int getExtractedColor(SparseIntArray colors) {
int index = Utilities.isDarkTheme(getContext())
? DARK_COLOR_EXTRACTION_INDEX
: LIGHT_COLOR_EXTRACTION_INDEX;
return colors.get(index, mBackgroundColor);
}
@TargetApi(Build.VERSION_CODES.S)
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);
AnimatorSet colors = new AnimatorSet();
if (v != null) {
int newColor = getExtractedColor(extractedColors);
setChildColor(v, newColor, colors);
int numChildren = v instanceof ViewGroup ? ((ViewGroup) v).getChildCount() : 0;
for (int i = 0; i < numChildren; ++i) {
View childView = ((ViewGroup) v).getChildAt(i);
setChildColor(childView, newColor, colors);
}
if (rectString.equals(mArrowColorRectString)) {
mArrowColor = newColor;
updateArrowColor();
}
}
colors.setDuration(150);
v.post(colors::start);
});
}
protected void addPreDrawForColorExtraction(Launcher launcher) {
getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
getViewTreeObserver().removeOnPreDrawListener(this);
initColorExtractionLocations(launcher);
return true;
}
});
}
/**
* Returns list of child views that will receive local color extraction treatment.
* Note: Order should match the view hierarchy.
*/
protected List<View> getChildrenForColorExtraction() {
return Collections.emptyList();
}
private void initColorExtractionLocations(Launcher launcher) {
if (mColorExtractor == null) {
return;
}
ArrayList<RectF> locations = new ArrayList<>();
boolean firstVisibleChild = true;
// Order matters here, since we need the arrow to match the color of its adjacent view.
for (View view : getChildrenForColorExtraction()) {
if (view != null && view.getVisibility() == VISIBLE) {
RectF rf = new RectF();
mColorExtractor.getExtractedRectForView(launcher,
launcher.getWorkspace().getCurrentPage(), view, rf);
if (!rf.isEmpty()) {
locations.add(rf);
String rectString = rf.toShortString();
mViewForRect.put(rectString, view);
if (mIsAboveIcon) {
mArrowColorRectString = rectString;
} else {
if (firstVisibleChild) {
mArrowColorRectString = rectString;
}
}
if (firstVisibleChild) {
firstVisibleChild = false;
}
}
}
}
if (!locations.isEmpty()) {
mColorExtractor.addLocation(locations);
}
}
/**
* Sets the background color of the child.
*/
protected void setChildColor(View view, int color, AnimatorSet animatorSetOut) {
Drawable bg = view.getBackground();
if (bg instanceof GradientDrawable) {
GradientDrawable gd = (GradientDrawable) bg.mutate();
int oldColor = ((GradientDrawable) bg).getColor().getDefaultColor();
animatorSetOut.play(ObjectAnimator.ofArgb(gd, "color", oldColor, color));
} else if (bg instanceof ColorDrawable) {
ColorDrawable cd = (ColorDrawable) bg.mutate();
int oldColor = ((ColorDrawable) bg).getColor();
animatorSetOut.play(ObjectAnimator.ofArgb(cd, "color", oldColor, color));
}
}
/** /**
* Shows the popup at the desired location, optionally reversing the children. * 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 * @param viewsToFlip number of views from the top to to flip in case of reverse order
@@ -238,7 +389,7 @@ public abstract class ArrowPopup<T extends StatefulActivity<LauncherState>>
reverseOrder(viewsToFlip); reverseOrder(viewsToFlip);
} }
onInflationComplete(reverseOrder); onInflationComplete(reverseOrder);
assignMarginsAndBackgrounds(); assignMarginsAndBackgrounds(this);
if (shouldAddArrow()) { if (shouldAddArrow()) {
addArrow(); addArrow();
} }
@@ -251,7 +402,7 @@ public abstract class ArrowPopup<T extends StatefulActivity<LauncherState>>
protected void show() { protected void show() {
setupForDisplay(); setupForDisplay();
onInflationComplete(false); onInflationComplete(false);
assignMarginsAndBackgrounds(); assignMarginsAndBackgrounds(this);
if (shouldAddArrow()) { if (shouldAddArrow()) {
addArrow(); addArrow();
} }
@@ -297,18 +448,24 @@ public abstract class ArrowPopup<T extends StatefulActivity<LauncherState>>
// so we centered it instead. In that case we don't want to showDefaultOptions the arrow. // so we centered it instead. In that case we don't want to showDefaultOptions the arrow.
mArrow.setVisibility(INVISIBLE); mArrow.setVisibility(INVISIBLE);
} else { } else {
updateArrowColor();
}
mArrow.setPivotX(mArrowWidth / 2.0f);
mArrow.setPivotY(mIsAboveIcon ? mArrowHeight : 0);
}
private void updateArrowColor() {
if (!Gravity.isVertical(mGravity)) {
mArrow.setBackground(new RoundedArrowDrawable( mArrow.setBackground(new RoundedArrowDrawable(
mArrowWidth, mArrowHeight, mArrowPointRadius, mArrowWidth, mArrowHeight, mArrowPointRadius,
mOutlineRadius, getMeasuredWidth(), getMeasuredHeight(), mOutlineRadius, getMeasuredWidth(), getMeasuredHeight(),
mArrowOffsetHorizontal, -mArrowOffsetVertical, mArrowOffsetHorizontal, -mArrowOffsetVertical,
!mIsAboveIcon, mIsLeftAligned, !mIsAboveIcon, mIsLeftAligned,
mBackgroundColor)); mArrowColor));
// TODO: Remove elevation when arrow is above as it casts a shadow on the container // TODO: Remove elevation when arrow is above as it casts a shadow on the container
mArrow.setElevation(mIsAboveIcon ? mElevation : 0); mArrow.setElevation(mIsAboveIcon ? mElevation : 0);
} }
mArrow.setPivotX(mArrowWidth / 2.0f);
mArrow.setPivotY(mIsAboveIcon ? mArrowHeight : 0);
} }
/** /**
@@ -506,7 +663,7 @@ public abstract class ArrowPopup<T extends StatefulActivity<LauncherState>>
private AnimatorSet getOpenCloseAnimator(boolean isOpening, int totalDuration, private AnimatorSet getOpenCloseAnimator(boolean isOpening, int totalDuration,
int fadeStartDelay, int fadeDuration, int childFadeStartDelay, int fadeStartDelay, int fadeDuration, int childFadeStartDelay,
int childFadeDuration, Interpolator interpolator) { int childFadeDuration, Interpolator interpolator) {
final AnimatorSet openAnim = new AnimatorSet(); final AnimatorSet animatorSet = new AnimatorSet();
float[] alphaValues = isOpening ? new float[] {0, 1} : new float[] {1, 0}; float[] alphaValues = isOpening ? new float[] {0, 1} : new float[] {1, 0};
float[] scaleValues = isOpening ? new float[] {0.5f, 1} : new float[] {1, 0.5f}; float[] scaleValues = isOpening ? new float[] {0.5f, 1} : new float[] {1, 0.5f};
@@ -519,32 +676,41 @@ public abstract class ArrowPopup<T extends StatefulActivity<LauncherState>>
mArrow.setAlpha(alpha); mArrow.setAlpha(alpha);
setAlpha(alpha); setAlpha(alpha);
}); });
openAnim.play(fade); animatorSet.play(fade);
setPivotX(mIsLeftAligned ? 0 : getMeasuredWidth()); setPivotX(mIsLeftAligned ? 0 : getMeasuredWidth());
setPivotY(mIsAboveIcon ? getMeasuredHeight() : 0); setPivotY(mIsAboveIcon ? getMeasuredHeight() : 0);
Animator scale = ObjectAnimator.ofFloat(this, View.SCALE_Y, scaleValues); Animator scale = ObjectAnimator.ofFloat(this, View.SCALE_Y, scaleValues);
scale.setDuration(totalDuration); scale.setDuration(totalDuration);
scale.setInterpolator(interpolator); scale.setInterpolator(interpolator);
openAnim.play(scale); animatorSet.play(scale);
for (int i = getChildCount() - 1; i >= 0; --i) { fadeInChildViews(this, alphaValues, childFadeStartDelay, childFadeDuration, animatorSet);
View view = getChildAt(i);
return animatorSet;
}
private void fadeInChildViews(ViewGroup group, float[] alphaValues, long startDelay,
long duration, AnimatorSet out) {
for (int i = group.getChildCount() - 1; i >= 0; --i) {
View view = group.getChildAt(i);
if (view.getVisibility() == VISIBLE && view instanceof ViewGroup) { if (view.getVisibility() == VISIBLE && view instanceof ViewGroup) {
if (mIterateChildrenTag.equals(view.getTag())) {
fadeInChildViews((ViewGroup) view, alphaValues, startDelay, duration, out);
continue;
}
for (int j = ((ViewGroup) view).getChildCount() - 1; j >= 0; --j) { for (int j = ((ViewGroup) view).getChildCount() - 1; j >= 0; --j) {
View childView = ((ViewGroup) view).getChildAt(j); View childView = ((ViewGroup) view).getChildAt(j);
childView.setAlpha(alphaValues[0]); childView.setAlpha(alphaValues[0]);
ValueAnimator childFade = ObjectAnimator.ofFloat(childView, ALPHA, alphaValues); ValueAnimator childFade = ObjectAnimator.ofFloat(childView, ALPHA, alphaValues);
childFade.setStartDelay(childFadeStartDelay); childFade.setStartDelay(startDelay);
childFade.setDuration(childFadeDuration); childFade.setDuration(duration);
childFade.setInterpolator(LINEAR); childFade.setInterpolator(LINEAR);
openAnim.play(childFade); out.play(childFade);
} }
} }
} }
return openAnim;
} }
@@ -593,6 +759,12 @@ public abstract class ArrowPopup<T extends StatefulActivity<LauncherState>>
getPopupContainer().removeView(this); getPopupContainer().removeView(this);
getPopupContainer().removeView(mArrow); getPopupContainer().removeView(mArrow);
mOnCloseCallback.run(); mOnCloseCallback.run();
mArrowColorRectString = null;
mViewForRect.clear();
if (mColorExtractor != null) {
mColorExtractor.removeLocations();
mColorExtractor.setListener(null);
}
} }
/** /**
@@ -71,6 +71,7 @@ import com.android.launcher3.util.ShortcutUtil;
import com.android.launcher3.views.BaseDragLayer; import com.android.launcher3.views.BaseDragLayer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@@ -95,6 +96,8 @@ public class PopupContainerWithArrow<T extends StatefulActivity<LauncherState>>
private int mNumNotifications; private int mNumNotifications;
private ViewGroup mNotificationContainer; private ViewGroup mNotificationContainer;
private ViewGroup mDeepShortcutContainer;
private ViewGroup mSystemShortcutContainer; private ViewGroup mSystemShortcutContainer;
protected PopupItemDragHandler mPopupItemDragHandler; protected PopupItemDragHandler mPopupItemDragHandler;
@@ -172,6 +175,14 @@ public class PopupContainerWithArrow<T extends StatefulActivity<LauncherState>>
return false; return false;
} }
@Override
protected void setChildColor(View view, int color, AnimatorSet animatorSetOut) {
super.setChildColor(view, color, animatorSetOut);
if (view.getId() == R.id.notification_container && mNotificationItemView != null) {
mNotificationItemView.updateBackgroundColor(color, animatorSetOut);
}
}
/** /**
* Returns true if we can show the container. * Returns true if we can show the container.
*/ */
@@ -218,6 +229,13 @@ public class PopupContainerWithArrow<T extends StatefulActivity<LauncherState>>
mPopupItemDragHandler = new LauncherPopupItemDragHandler(launcher, this); mPopupItemDragHandler = new LauncherPopupItemDragHandler(launcher, this);
mAccessibilityDelegate = new ShortcutMenuAccessibilityDelegate(launcher); mAccessibilityDelegate = new ShortcutMenuAccessibilityDelegate(launcher);
launcher.getDragController().addDragListener(this); launcher.getDragController().addDragListener(this);
addPreDrawForColorExtraction(launcher);
}
@Override
protected List<View> getChildrenForColorExtraction() {
return Arrays.asList(mSystemShortcutContainer, mDeepShortcutContainer,
mNotificationContainer);
} }
@Override @Override
@@ -262,13 +280,18 @@ public class PopupContainerWithArrow<T extends StatefulActivity<LauncherState>>
} }
int viewsToFlip = getChildCount(); int viewsToFlip = getChildCount();
mSystemShortcutContainer = this; mSystemShortcutContainer = this;
if (mDeepShortcutContainer == null) {
mDeepShortcutContainer = findViewById(R.id.deep_shortcuts_container);
}
if (hasDeepShortcuts) { if (hasDeepShortcuts) {
mDeepShortcutContainer.setVisibility(View.VISIBLE);
if (mNotificationItemView != null) { if (mNotificationItemView != null) {
mNotificationItemView.addGutter(); mNotificationItemView.addGutter();
} }
for (int i = shortcutCount; i > 0; i--) { for (int i = shortcutCount; i > 0; i--) {
DeepShortcutView v = inflateAndAdd(R.layout.deep_shortcut, this); DeepShortcutView v = inflateAndAdd(R.layout.deep_shortcut, mDeepShortcutContainer);
v.getLayoutParams().width = containerWidth; v.getLayoutParams().width = containerWidth;
mShortcuts.add(v); mShortcuts.add(v);
} }
@@ -281,13 +304,16 @@ public class PopupContainerWithArrow<T extends StatefulActivity<LauncherState>>
R.layout.system_shortcut_icon_only, mSystemShortcutContainer, shortcut); R.layout.system_shortcut_icon_only, mSystemShortcutContainer, shortcut);
} }
} }
} else if (!systemShortcuts.isEmpty()) { } else {
if (mNotificationItemView != null) { mDeepShortcutContainer.setVisibility(View.GONE);
mNotificationItemView.addGutter(); if (!systemShortcuts.isEmpty()) {
} if (mNotificationItemView != null) {
mNotificationItemView.addGutter();
}
for (SystemShortcut shortcut : systemShortcuts) { for (SystemShortcut shortcut : systemShortcuts) {
initializeSystemShortcut(R.layout.system_shortcut, this, shortcut); initializeSystemShortcut(R.layout.system_shortcut, this, shortcut);
}
} }
} }
@@ -563,7 +589,7 @@ public class PopupContainerWithArrow<T extends StatefulActivity<LauncherState>>
mNotificationItemView = null; mNotificationItemView = null;
mNotificationContainer.setVisibility(GONE); mNotificationContainer.setVisibility(GONE);
updateHiddenShortcuts(); updateHiddenShortcuts();
assignMarginsAndBackgrounds(); assignMarginsAndBackgrounds(PopupContainerWithArrow.this);
} else { } else {
mNotificationItemView.trimNotifications( mNotificationItemView.trimNotifications(
NotificationKeyData.extractKeysOnly(dotInfo.getNotificationKeys())); NotificationKeyData.extractKeysOnly(dotInfo.getNotificationKeys()));
@@ -146,13 +146,25 @@ public class OptionsPopupView extends ArrowPopup
view.setOnLongClickListener(popup); view.setOnLongClickListener(popup);
popup.mItemMap.put(view, item); popup.mItemMap.put(view, item);
} }
popup.addPreDrawForColorExtraction(launcher);
popup.show(); popup.show();
return popup; return popup;
} }
@Override
protected List<View> getChildrenForColorExtraction() {
int childCount = getChildCount();
ArrayList<View> children = new ArrayList<>(childCount);
for (int i = 0; i < childCount; ++i) {
children.add(getChildAt(i));
}
return children;
}
@VisibleForTesting @VisibleForTesting
public static ArrowPopup getOptionsPopup(Launcher launcher) { public static ArrowPopup getOptionsPopup(Launcher launcher) {
return launcher.findViewById(R.id.deep_shortcuts_container); return launcher.findViewById(R.id.popup_container);
} }
public static void showDefaultOptions(Launcher launcher, float x, float y) { public static void showDefaultOptions(Launcher launcher, float x, float y) {
@@ -47,7 +47,7 @@ public final class AppIcon extends Launchable {
public AppIconMenu openMenu() { public AppIconMenu openMenu() {
try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) { try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) {
return new AppIconMenu(mLauncher, mLauncher.clickAndGet( return new AppIconMenu(mLauncher, mLauncher.clickAndGet(
mObject, "deep_shortcuts_container", LONG_CLICK_EVENT)); mObject, "popup_container", LONG_CLICK_EVENT));
} }
} }
@@ -58,7 +58,7 @@ public final class AppIcon extends Launchable {
@Override @Override
protected String getLongPressIndicator() { protected String getLongPressIndicator() {
return "deep_shortcuts_container"; return "popup_container";
} }
@Override @Override
@@ -155,7 +155,7 @@ public final class LauncherInstrumentation {
private static final String APPS_RES_ID = "apps_view"; private static final String APPS_RES_ID = "apps_view";
private static final String OVERVIEW_RES_ID = "overview_panel"; private static final String OVERVIEW_RES_ID = "overview_panel";
private static final String WIDGETS_RES_ID = "primary_widgets_list_view"; private static final String WIDGETS_RES_ID = "primary_widgets_list_view";
private static final String CONTEXT_MENU_RES_ID = "deep_shortcuts_container"; private static final String CONTEXT_MENU_RES_ID = "popup_container";
public static final int WAIT_TIME_MS = 60000; public static final int WAIT_TIME_MS = 60000;
private static final String SYSTEMUI_PACKAGE = "com.android.systemui"; private static final String SYSTEMUI_PACKAGE = "com.android.systemui";
private static final String ANDROID_PACKAGE = "android"; private static final String ANDROID_PACKAGE = "android";
@@ -26,7 +26,7 @@ public class OptionsPopupMenu {
OptionsPopupMenu(LauncherInstrumentation launcher) { OptionsPopupMenu(LauncherInstrumentation launcher) {
mLauncher = launcher; mLauncher = launcher;
mDeepShortcutsContainer = launcher.waitForLauncherObject("deep_shortcuts_container"); mDeepShortcutsContainer = launcher.waitForLauncherObject("popup_container");
} }
/** /**
@@ -179,7 +179,7 @@ public final class Workspace extends Home {
getHotseatAppIcon("Chrome"), getHotseatAppIcon("Chrome"),
new Point(mLauncher.getDevice().getDisplayWidth(), new Point(mLauncher.getDevice().getDisplayWidth(),
mLauncher.getVisibleBounds(workspace).centerY()), mLauncher.getVisibleBounds(workspace).centerY()),
"deep_shortcuts_container", "popup_container",
false, false,
false, false,
() -> mLauncher.expectEvent( () -> mLauncher.expectEvent(