Merge "Adding a case when there is only 1 system shortcut on the Popup Container" into tm-qpr-dev am: 2545f45a1f
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/18284907 Change-Id: Icc4848f780ae139a3a39fe747e383c00be25d94e Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -72,6 +72,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -244,23 +245,32 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext>
|
||||
mNotificationContainer);
|
||||
}
|
||||
|
||||
private void initializeSystemShortcuts(List<SystemShortcut> shortcuts) {
|
||||
if (shortcuts.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
// 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));
|
||||
return;
|
||||
}
|
||||
mSystemShortcutContainer = inflateAndAdd(R.layout.system_shortcut_icons, this);
|
||||
for (SystemShortcut shortcut : shortcuts) {
|
||||
initializeSystemShortcut(
|
||||
R.layout.system_shortcut_icon_only, mSystemShortcutContainer,
|
||||
shortcut);
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.P)
|
||||
public void populateAndShow(final BubbleTextView originalIcon, int shortcutCount,
|
||||
final List<NotificationKeyData> notificationKeys, List<SystemShortcut> systemShortcuts) {
|
||||
final List<NotificationKeyData> notificationKeys, List<SystemShortcut> shortcuts) {
|
||||
mNumNotifications = notificationKeys.size();
|
||||
mOriginalIcon = originalIcon;
|
||||
|
||||
boolean hasDeepShortcuts = shortcutCount > 0;
|
||||
mContainerWidth = getResources().getDimensionPixelSize(R.dimen.bg_popup_item_width);
|
||||
|
||||
// if there are deep shortcuts, we might want to increase the width of shortcuts to fit
|
||||
// horizontally laid out system shortcuts.
|
||||
if (hasDeepShortcuts) {
|
||||
mContainerWidth = Math.max(mContainerWidth,
|
||||
systemShortcuts.size() * getResources()
|
||||
.getDimensionPixelSize(R.dimen.system_shortcut_header_icon_touch_size)
|
||||
);
|
||||
}
|
||||
// Add views
|
||||
if (mNumNotifications > 0) {
|
||||
// Add notification entries
|
||||
@@ -279,6 +289,24 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext>
|
||||
mDeepShortcutContainer = findViewById(R.id.deep_shortcuts_container);
|
||||
}
|
||||
if (hasDeepShortcuts) {
|
||||
// Remove the widget shortcut fom the list
|
||||
List<SystemShortcut> systemShortcuts = shortcuts
|
||||
.stream()
|
||||
.filter(shortcut -> !(shortcut instanceof SystemShortcut.Widgets))
|
||||
.collect(Collectors.toList());
|
||||
Optional<SystemShortcut.Widgets> widgetShortcutOpt = shortcuts
|
||||
.stream()
|
||||
.filter(shortcut -> shortcut instanceof SystemShortcut.Widgets)
|
||||
.map(SystemShortcut.Widgets.class::cast)
|
||||
.findFirst();
|
||||
|
||||
// if there are deep shortcuts, we might want to increase the width of shortcuts to fit
|
||||
// horizontally laid out system shortcuts.
|
||||
mContainerWidth = Math.max(mContainerWidth,
|
||||
systemShortcuts.size() * getResources()
|
||||
.getDimensionPixelSize(R.dimen.system_shortcut_header_icon_touch_size)
|
||||
);
|
||||
|
||||
mDeepShortcutContainer.setVisibility(View.VISIBLE);
|
||||
|
||||
for (int i = shortcutCount; i > 0; i--) {
|
||||
@@ -288,30 +316,19 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext>
|
||||
}
|
||||
updateHiddenShortcuts();
|
||||
|
||||
if (!systemShortcuts.isEmpty()) {
|
||||
for (SystemShortcut shortcut : systemShortcuts) {
|
||||
if (shortcut instanceof SystemShortcut.Widgets) {
|
||||
if (mWidgetContainer == null) {
|
||||
mWidgetContainer = inflateAndAdd(R.layout.widget_shortcut_container,
|
||||
this);
|
||||
}
|
||||
initializeWidgetShortcut(mWidgetContainer, shortcut);
|
||||
}
|
||||
}
|
||||
mSystemShortcutContainer = inflateAndAdd(R.layout.system_shortcut_icons, this);
|
||||
|
||||
for (SystemShortcut shortcut : systemShortcuts) {
|
||||
if (!(shortcut instanceof SystemShortcut.Widgets)) {
|
||||
initializeSystemShortcut(
|
||||
R.layout.system_shortcut_icon_only, mSystemShortcutContainer,
|
||||
shortcut);
|
||||
}
|
||||
if (widgetShortcutOpt.isPresent()) {
|
||||
if (mWidgetContainer == null) {
|
||||
mWidgetContainer = inflateAndAdd(R.layout.widget_shortcut_container,
|
||||
this);
|
||||
}
|
||||
initializeWidgetShortcut(mWidgetContainer, widgetShortcutOpt.get());
|
||||
}
|
||||
|
||||
initializeSystemShortcuts(systemShortcuts);
|
||||
} else {
|
||||
mDeepShortcutContainer.setVisibility(View.GONE);
|
||||
if (!systemShortcuts.isEmpty()) {
|
||||
for (SystemShortcut shortcut : systemShortcuts) {
|
||||
if (!shortcuts.isEmpty()) {
|
||||
for (SystemShortcut shortcut : shortcuts) {
|
||||
initializeSystemShortcut(R.layout.system_shortcut, this, shortcut);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user