From fdfeb6dd3bcd737c5f7ba513f0e45ab343e20d5f Mon Sep 17 00:00:00 2001 From: Vadim Tryshev Date: Thu, 15 Nov 2018 15:13:53 -0800 Subject: [PATCH] Moving Pause button to the left of the context menu header See this mock: https://www.google.com/url?q=https://docs.google.com/presentation/d/1AepsnLeKcRhjMW35SkB5yMKO3u6waigug8Tyfe0LO5o/edit%23slide%3Did.g455d187f2a_0_45&sa=D&ust=1542320415002000&usg=AFQjCNH-jsy5THG1WqxjeYbj628QFMJKvQ Bug: 117888000 Test: Manual Change-Id: I1edbc569347f09f0806ad6749735c3dec198277a --- res/layout/system_shortcut_icons.xml | 8 +++++++- src/com/android/launcher3/popup/ArrowPopup.java | 6 ++++++ .../launcher3/popup/PopupContainerWithArrow.java | 14 +++++++++++++- .../launcher3/popup/RemoteActionShortcut.java | 5 +++++ .../android/launcher3/popup/SystemShortcut.java | 7 +++++++ 5 files changed, 38 insertions(+), 2 deletions(-) diff --git a/res/layout/system_shortcut_icons.xml b/res/layout/system_shortcut_icons.xml index 4daf469589..a340f4fc9d 100644 --- a/res/layout/system_shortcut_icons.xml +++ b/res/layout/system_shortcut_icons.xml @@ -22,4 +22,10 @@ android:orientation="horizontal" android:gravity="end|center_vertical" android:background="?attr/popupColorSecondary" - android:clipToPadding="true" /> + android:clipToPadding="true"> + + + diff --git a/src/com/android/launcher3/popup/ArrowPopup.java b/src/com/android/launcher3/popup/ArrowPopup.java index 0bb5e2afd2..ccc15f1dc1 100644 --- a/src/com/android/launcher3/popup/ArrowPopup.java +++ b/src/com/android/launcher3/popup/ArrowPopup.java @@ -126,6 +126,12 @@ public abstract class ArrowPopup extends AbstractFloatingView { return (T) view; } + public T inflateAndAdd(int resId, ViewGroup container, int index) { + View view = mInflater.inflate(resId, container, false); + container.addView(view, index); + return (T) view; + } + /** * Called when all view inflation and reordering in complete. */ diff --git a/src/com/android/launcher3/popup/PopupContainerWithArrow.java b/src/com/android/launcher3/popup/PopupContainerWithArrow.java index 12319f75e5..37a000da28 100644 --- a/src/com/android/launcher3/popup/PopupContainerWithArrow.java +++ b/src/com/android/launcher3/popup/PopupContainerWithArrow.java @@ -391,7 +391,8 @@ public class PopupContainerWithArrow extends ArrowPopup implements DragSource, } private void initializeSystemShortcut(int resId, ViewGroup container, SystemShortcut info) { - View view = inflateAndAdd(resId, container); + View view = inflateAndAdd( + resId, container, getInsertIndexForSystemShortcut(container, info)); if (view instanceof DeepShortcutView) { // Expanded system shortcut, with both icon and text shown on white background. final DeepShortcutView shortcutView = (DeepShortcutView) view; @@ -405,6 +406,17 @@ public class PopupContainerWithArrow extends ArrowPopup implements DragSource, (ItemInfo) mOriginalIcon.getTag())); } + /** + * 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. * diff --git a/src/com/android/launcher3/popup/RemoteActionShortcut.java b/src/com/android/launcher3/popup/RemoteActionShortcut.java index c76fb9651e..3e124290aa 100644 --- a/src/com/android/launcher3/popup/RemoteActionShortcut.java +++ b/src/com/android/launcher3/popup/RemoteActionShortcut.java @@ -76,4 +76,9 @@ public class RemoteActionShortcut extends SystemShortcut { LauncherLogProto.ControlType.REMOTE_ACTION_SHORTCUT, view); }; } + + @Override + public boolean isLeftGroup() { + return true; + } } diff --git a/src/com/android/launcher3/popup/SystemShortcut.java b/src/com/android/launcher3/popup/SystemShortcut.java index f9a2007930..fdc1b39d71 100644 --- a/src/com/android/launcher3/popup/SystemShortcut.java +++ b/src/com/android/launcher3/popup/SystemShortcut.java @@ -71,6 +71,13 @@ public abstract class SystemShortcut extends Ite mAccessibilityActionId = other.mAccessibilityActionId; } + /** + * Should be in the left group of icons in app's context menu header. + */ + public boolean isLeftGroup() { + return false; + } + public void setIconAndLabelFor(View iconView, TextView labelView) { if (mIcon != null) { mIcon.loadDrawableAsync(iconView.getContext(),