Merge "Fixes several Visual issues with the app shortcut popup" into tm-qpr-dev

This commit is contained in:
Charlie Anderson
2023-03-08 14:15:17 +00:00
committed by Android (Google) Code Review
8 changed files with 90 additions and 109 deletions

View File

@@ -40,6 +40,9 @@ import static com.android.launcher3.config.FeatureFlags.RECEIVE_UNFOLD_EVENTS_FR
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_APP_LAUNCH_TAP;
import static com.android.launcher3.model.data.ItemInfo.NO_MATCHING_ID;
import static com.android.launcher3.popup.QuickstepSystemShortcut.getSplitSelectShortcutByPosition;
import static com.android.launcher3.popup.SystemShortcut.APP_INFO;
import static com.android.launcher3.popup.SystemShortcut.INSTALL;
import static com.android.launcher3.popup.SystemShortcut.WIDGETS;
import static com.android.launcher3.taskbar.LauncherTaskbarUIController.ALL_APPS_PAGE_PROGRESS_INDEX;
import static com.android.launcher3.taskbar.LauncherTaskbarUIController.MINUS_ONE_PAGE_PROGRESS_INDEX;
import static com.android.launcher3.taskbar.LauncherTaskbarUIController.WIDGETS_PAGE_PROGRESS_INDEX;
@@ -186,6 +189,8 @@ import com.android.systemui.unfold.updates.RotationChangeProvider;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;
@@ -385,22 +390,30 @@ public class QuickstepLauncher extends Launcher {
@Override
public Stream<SystemShortcut.Factory> getSupportedShortcuts() {
Stream<SystemShortcut.Factory> base = Stream.of(WellbeingModel.SHORTCUT_FACTORY);
if (ENABLE_SPLIT_FROM_WORKSPACE.get() && mDeviceProfile.isTablet) {
RecentsView recentsView = getOverviewPanel();
// TODO(b/266482558): Pull it out of PagedOrentationHandler for split from workspace.
List<SplitPositionOption> positions =
recentsView.getPagedOrientationHandler().getSplitPositionOptions(
mDeviceProfile);
List<SystemShortcut.Factory<QuickstepLauncher>> splitShortcuts = new ArrayList<>();
for (SplitPositionOption position : positions) {
splitShortcuts.add(getSplitSelectShortcutByPosition(position));
}
base = Stream.concat(base, splitShortcuts.stream());
// Order matters as it affects order of appearance in popup container
List<SystemShortcut.Factory> shortcuts = new ArrayList(Arrays.asList(
APP_INFO, WellbeingModel.SHORTCUT_FACTORY, mHotseatPredictionController));
shortcuts.addAll(getSplitShortcuts());
shortcuts.add(WIDGETS);
shortcuts.add(INSTALL);
return shortcuts.stream();
}
private List<SystemShortcut.Factory<QuickstepLauncher>> getSplitShortcuts() {
if (!ENABLE_SPLIT_FROM_WORKSPACE.get() || !mDeviceProfile.isTablet) {
return Collections.emptyList();
}
return Stream.concat(
Stream.of(mHotseatPredictionController),
Stream.concat(base, super.getSupportedShortcuts()));
RecentsView recentsView = getOverviewPanel();
// TODO(b/266482558): Pull it out of PagedOrentationHandler for split from workspace.
List<SplitPositionOption> positions =
recentsView.getPagedOrientationHandler().getSplitPositionOptions(
mDeviceProfile);
List<SystemShortcut.Factory<QuickstepLauncher>> splitShortcuts = new ArrayList<>();
for (SplitPositionOption position : positions) {
splitShortcuts.add(getSplitSelectShortcutByPosition(position));
}
return splitShortcuts;
}
/**

View File

@@ -1,9 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="20dp"
android:height="16dp"
android:viewportWidth="20"
android:viewportHeight="16">
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M18,14L13,14L13,2L18,2L18,14ZM20,14L20,2C20,0.9 19.1,-0 18,-0L13,-0C11.9,-0 11,0.9 11,2L11,14C11,15.1 11.9,16 13,16L18,16C19.1,16 20,15.1 20,14ZM7,14L2,14L2,2L7,2L7,14ZM9,14L9,2C9,0.9 8.1,-0 7,-0L2,-0C0.9,-0 -0,0.9 -0,2L-0,14C-0,15.1 0.9,16 2,16L7,16C8.1,16 9,15.1 9,14Z"
android:pathData="M4,6L9,6L9,18L4,18L4,6ZM2,6L2,18C2,19.1 2.9,20 4,20L9,20C10.1,20 11,19.1 11,18L11,6C11,4.9 10.1,4 9,4L4,4C2.9,4 2,4.9 2,6ZM15,6L20,6L20,18L15,18L15,6ZM13,6L13,18C13,19.1 13.9,20 15,20L20,20C21.1,20 22,19.1 22,18L22,6C22,4.9 21.1,4 20,4L15,4C13.9,4 13,4.9 13,6Z"
android:fillColor="#000000"/>
</vector>

View File

@@ -22,11 +22,4 @@
android:orientation="horizontal"
android:gravity="end|center_vertical"
android:background="@drawable/single_item_primary"
android:elevation="@dimen/deep_shortcuts_elevation"
android:clipToPadding="true">
<Space android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="@+id/separator"/>
</LinearLayout>
android:elevation="@dimen/deep_shortcuts_elevation"/>

View File

@@ -23,10 +23,4 @@
android:orientation="horizontal"
android:gravity="end|center_vertical"
android:background="@drawable/popup_background_material_u"
android:elevation="@dimen/deep_shortcuts_elevation">
<Space android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="@+id/separator"/>
</LinearLayout>
android:elevation="@dimen/deep_shortcuts_elevation"/>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Space
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="@+id/shortcut_spacer"/>

View File

@@ -60,9 +60,7 @@ import com.android.launcher3.util.Themes;
import com.android.launcher3.views.ActivityContext;
import com.android.launcher3.views.BaseDragLayer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
/**
* A container for shortcuts to deep links and notifications associated with an app.
@@ -336,23 +334,6 @@ public abstract class ArrowPopup<T extends Context & ActivityContext>
}
}
/**
* 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
*/
protected void reorderAndShow(int viewsToFlip) {
setupForDisplay();
boolean reverseOrder = !ENABLE_MATERIAL_U_POPUP.get() && mIsAboveIcon;
if (reverseOrder) {
reverseOrder(viewsToFlip);
}
assignMarginsAndBackgrounds(this);
if (shouldAddArrow()) {
addArrow();
}
animateOpen();
}
/**
* Shows the popup at the desired location.
*/
@@ -372,22 +353,6 @@ public abstract class ArrowPopup<T extends Context & ActivityContext>
orientAboutObject();
}
private void reverseOrder(int viewsToFlip) {
int count = getChildCount();
ArrayList<View> allViews = new ArrayList<>(count);
for (int i = 0; i < count; i++) {
if (i == viewsToFlip) {
Collections.reverse(allViews);
}
allViews.add(getChildAt(i));
}
Collections.reverse(allViews);
removeAllViews();
for (int i = 0; i < count; i++) {
addView(allViews.get(i));
}
}
private int getArrowLeft() {
if (mIsLeftAligned) {
return mArrowOffsetHorizontal;

View File

@@ -257,14 +257,19 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext>
}
// If there is only 1 shortcut, add it to its own container so it can show text and icon
if (shortcuts.size() == 1) {
initializeSystemShortcut(R.layout.system_shortcut, this, shortcuts.get(0));
mSystemShortcutContainer = inflateAndAdd(R.layout.system_shortcut_rows_container,
this, 0);
initializeSystemShortcut(R.layout.system_shortcut, mSystemShortcutContainer,
shortcuts.get(0), false);
return;
}
mSystemShortcutContainer = inflateAndAdd(R.layout.system_shortcut_icons_container, this);
for (SystemShortcut shortcut : shortcuts) {
mSystemShortcutContainer = inflateAndAdd(R.layout.system_shortcut_icons_container, this, 0);
for (int i = 0; i < shortcuts.size(); i++) {
initializeSystemShortcut(
R.layout.system_shortcut_icon_only, mSystemShortcutContainer,
shortcut);
R.layout.system_shortcut_icon_only,
mSystemShortcutContainer,
shortcuts.get(i),
i < shortcuts.size() - 1);
}
}
@@ -289,7 +294,6 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext>
}
updateNotificationHeader();
}
int viewsToFlip = getChildCount();
mSystemShortcutContainer = this;
if (mDeepShortcutContainer == null) {
mDeepShortcutContainer = findViewById(R.id.deep_shortcuts_container);
@@ -314,8 +318,7 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext>
Optional<SystemShortcut.Widgets> widgetShortcutOpt = getWidgetShortcut(shortcuts);
if (widgetShortcutOpt.isPresent()) {
if (mWidgetContainer == null) {
mWidgetContainer = inflateAndAdd(R.layout.widget_shortcut_container,
this);
mWidgetContainer = inflateAndAdd(R.layout.widget_shortcut_container, this, 0);
}
initializeWidgetShortcut(mWidgetContainer, widgetShortcutOpt.get());
}
@@ -324,14 +327,17 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext>
} else {
mDeepShortcutContainer.setVisibility(View.GONE);
if (!shortcuts.isEmpty()) {
for (SystemShortcut shortcut : shortcuts) {
initializeSystemShortcut(R.layout.system_shortcut, this, shortcut);
for (int i = 0; i < shortcuts.size(); i++) {
initializeSystemShortcut(
R.layout.system_shortcut,
this,
shortcuts.get(i),
i < shortcuts.size() - 1);
}
}
}
reorderAndShow(viewsToFlip);
showPopupContainer((ItemInfo) originalIcon.getTag(), notificationKeys);
show();
loadAppShortcuts((ItemInfo) originalIcon.getTag(), notificationKeys);
}
/**
@@ -351,19 +357,17 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext>
addAllShortcutsMaterialU(deepShortcutCount, systemShortcuts);
} else if (!systemShortcuts.isEmpty()) {
addSystemShortcutsMaterialU(systemShortcuts,
R.layout.system_shortcut_rows_container_material_u,
R.layout.system_shortcut_rows_container,
R.layout.system_shortcut);
}
// no reversing needed for U design
reorderAndShow(0);
showPopupContainer((ItemInfo) originalIcon.getTag(), /* notificationKeys= */ emptyList());
show();
loadAppShortcuts((ItemInfo) originalIcon.getTag(), /* notificationKeys= */ emptyList());
}
/**
* Animates and loads shortcuts on background thread for this popup container
*/
private void showPopupContainer(ItemInfo originalItemInfo,
private void loadAppShortcuts(ItemInfo originalItemInfo,
List<NotificationKeyData> notificationKeys) {
if (ATLEAST_P) {
@@ -390,7 +394,7 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext>
if (deepShortcutCount + systemShortcuts.size() <= SHORTCUT_COLLAPSE_THRESHOLD) {
// add all system shortcuts including widgets shortcut to same container
addSystemShortcutsMaterialU(systemShortcuts,
R.layout.system_shortcut_rows_container_material_u,
R.layout.system_shortcut_rows_container,
R.layout.system_shortcut);
addDeepShortcutsMaterialU(deepShortcutCount);
return;
@@ -458,8 +462,12 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext>
return;
}
mSystemShortcutContainer = inflateAndAdd(systemShortcutContainerLayout, this);
for (SystemShortcut shortcut : systemShortcuts) {
initializeSystemShortcut(systemShortcutLayout, mSystemShortcutContainer, shortcut);
for (int i = 0; i < systemShortcuts.size(); i++) {
initializeSystemShortcut(
systemShortcutLayout,
mSystemShortcutContainer,
systemShortcuts.get(i),
i < systemShortcuts.size() - 1);
}
}
@@ -533,20 +541,31 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext>
}
protected void initializeWidgetShortcut(ViewGroup container, SystemShortcut info) {
View view = initializeSystemShortcut(R.layout.system_shortcut, container, info);
View view = initializeSystemShortcut(R.layout.system_shortcut, container, info, false);
view.getLayoutParams().width = mContainerWidth;
}
protected View initializeSystemShortcut(int resId, ViewGroup container, SystemShortcut info) {
View view = inflateAndAdd(
resId, container, getInsertIndexForSystemShortcut(container, info));
/**
* Initializes and adds View for given SystemShortcut to a container.
* @param resId Resource id to use for SystemShortcut View.
* @param container ViewGroup to add the shortcut View to as a parent
* @param info The SystemShortcut instance to create a View for.
* @param shouldAddSpacer If True, will add a spacer after the shortcut, when showing the
* SystemShortcut as an icon only. Used to space the shortcut icons
* evenly.
* @return The view inflated for the SystemShortcut
*/
protected View initializeSystemShortcut(int resId, ViewGroup container, SystemShortcut info,
boolean shouldAddSpacer) {
View view = inflateAndAdd(resId, container);
if (view instanceof DeepShortcutView) {
// Expanded system shortcut, with both icon and text shown on white background.
// System shortcut takes entire row with icon and text
final DeepShortcutView shortcutView = (DeepShortcutView) view;
info.setIconAndLabelFor(shortcutView.getIconView(), shortcutView.getBubbleText());
} else if (view instanceof ImageView) {
// Only the system shortcut icon shows on a gray background header.
// System shortcut is just an icon
info.setIconAndContentDescriptionFor((ImageView) view);
if (shouldAddSpacer) inflateAndAdd(R.layout.system_shortcut_spacer, container);
view.setTooltipText(view.getContentDescription());
}
view.setTag(info);
@@ -554,17 +573,6 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext>
return view;
}
/**
* Returns an index for inserting a shortcut into a container.
*/
private int getInsertIndexForSystemShortcut(ViewGroup container, SystemShortcut shortcut) {
final View separator = container.findViewById(R.id.separator);
return separator != null && shortcut.isLeftGroup() ?
container.indexOfChild(separator) :
container.getChildCount();
}
/**
* Determines when the deferred drag should be started.
*