mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-03-04 09:56:49 +00:00
Merge "Add "New Window" option to Taskbar menu." into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
4cf02b8538
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.android.launcher3.taskbar;
|
||||
|
||||
import static com.android.launcher3.model.data.AppInfo.COMPONENT_KEY_COMPARATOR;
|
||||
import static com.android.launcher3.util.SplitConfigurationOptions.getLogEventForPosition;
|
||||
|
||||
import android.content.Intent;
|
||||
@@ -29,11 +30,13 @@ import androidx.annotation.NonNull;
|
||||
import com.android.internal.logging.InstanceId;
|
||||
import com.android.launcher3.AbstractFloatingView;
|
||||
import com.android.launcher3.BubbleTextView;
|
||||
import com.android.launcher3.Flags;
|
||||
import com.android.launcher3.LauncherSettings;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.dot.FolderDotInfo;
|
||||
import com.android.launcher3.folder.Folder;
|
||||
import com.android.launcher3.folder.FolderIcon;
|
||||
import com.android.launcher3.model.data.AppInfo;
|
||||
import com.android.launcher3.model.data.FolderInfo;
|
||||
import com.android.launcher3.model.data.ItemInfo;
|
||||
import com.android.launcher3.model.data.WorkspaceItemInfo;
|
||||
@@ -51,9 +54,11 @@ import com.android.launcher3.util.SplitConfigurationOptions.SplitPositionOption;
|
||||
import com.android.launcher3.views.ActivityContext;
|
||||
import com.android.quickstep.SystemUiProxy;
|
||||
import com.android.quickstep.util.LogUtils;
|
||||
import com.android.wm.shell.shared.desktopmode.DesktopModeStatus;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@@ -79,6 +84,7 @@ public class TaskbarPopupController implements TaskbarControllers.LoggableTaskba
|
||||
// Initialized in init.
|
||||
private TaskbarControllers mControllers;
|
||||
private boolean mAllowInitialSplitSelection;
|
||||
private AppInfo[] mAppInfosList;
|
||||
|
||||
public TaskbarPopupController(TaskbarActivityContext context) {
|
||||
mContext = context;
|
||||
@@ -195,6 +201,10 @@ public class TaskbarPopupController implements TaskbarControllers.LoggableTaskba
|
||||
if (com.android.wm.shell.Flags.enableBubbleAnything()) {
|
||||
shortcuts.add(BUBBLE);
|
||||
}
|
||||
if (Flags.enableMultiInstanceMenuTaskbar()
|
||||
&& DesktopModeStatus.canEnterDesktopMode(mContext)) {
|
||||
shortcuts.addAll(getMultiInstanceMenuOptions().toList());
|
||||
}
|
||||
return shortcuts.stream();
|
||||
}
|
||||
|
||||
@@ -258,7 +268,55 @@ public class TaskbarPopupController implements TaskbarControllers.LoggableTaskba
|
||||
originalView, position, mAllowInitialSplitSelection);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Set the list of AppInfos to be able to pull from later
|
||||
*/
|
||||
public void setApps(AppInfo[] apps) {
|
||||
mAppInfosList = apps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds and returns an AppInfo object from a list, using its ComponentKey for identification.
|
||||
* Based off of {@link com.android.launcher3.allapps.AllAppsStore#getApp(ComponentKey)}
|
||||
* since we cannot access AllAppsStore from here.
|
||||
*/
|
||||
public AppInfo getApp(ComponentKey key) {
|
||||
if (key == null) {
|
||||
return null;
|
||||
}
|
||||
AppInfo tempInfo = new AppInfo();
|
||||
tempInfo.componentName = key.componentName;
|
||||
tempInfo.user = key.user;
|
||||
int index = Arrays.binarySearch(mAppInfosList, tempInfo, COMPONENT_KEY_COMPARATOR);
|
||||
return index < 0 ? null : mAppInfosList[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a stream of Multi Instance menu options if an app supports it.
|
||||
*/
|
||||
Stream<SystemShortcut.Factory<BaseTaskbarContext>> getMultiInstanceMenuOptions() {
|
||||
SystemShortcut.Factory<BaseTaskbarContext> factory = createNewWindowShortcutFactory();
|
||||
return factory != null ? Stream.of(factory) : Stream.empty();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a factory function representing a "New Window" menu item only if the calling app
|
||||
* supports multi-instance.
|
||||
* @return A factory function to be used in populating the long-press menu.
|
||||
*/
|
||||
SystemShortcut.Factory<BaseTaskbarContext> createNewWindowShortcutFactory() {
|
||||
return (context, itemInfo, originalView) -> {
|
||||
ComponentKey key = itemInfo.getComponentKey();
|
||||
AppInfo app = getApp(key);
|
||||
if (app != null && app.supportsMultiInstance()) {
|
||||
return new NewWindowTaskbarShortcut<>(context, itemInfo, originalView);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* A single menu item ("Split left," "Split right," or "Split top") that executes a split
|
||||
* from the taskbar, as if the user performed a drag and drop split.
|
||||
* Includes an onClick method that initiates the actual split.
|
||||
|
||||
Reference in New Issue
Block a user