mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-03-04 09:56:49 +00:00
pin-shortcut: Tracks hotseat states and adds unpin option for taskbar
This cl adds the unpin option by tracking the hotseat/taskbar state. The option shown is determined by the following conditions: 1. If the target non-predicted item is on the taskbar, shows "Unpin from taskbar" 2. If the taskbar is not full, that is, reaching the limit of the available spaces, and the target item is anywhere outside of the taskbar, including All apps, shows "Pin to taskbar". 3. If the taskbar is full, simply don't show any shortcut option. This cl also removes the option that will be shown on Launcher homescreen or hotseat, as further UX alignment is needed. One note about why the pin shortcut is not implemented in the getShortcuts(). The reason is that getShortcuts does not have the ItemInfo of the triggered item, while the SystemShortcut.Factory doesn't have the hotseat/taskbar information. The simplest way at this point is to check all the conditions in the controller and then manually add the shortcut into the list. Bug: 375648361 Test: Manual, Recording uploaded to buganizer Flag: com.android.launcher3.enable_pinning_app_with_context_menu Change-Id: I7d048bcb1b00f78651e909fbfcd911052a4cd4ef
This commit is contained in:
@@ -16,18 +16,20 @@
|
||||
package com.android.launcher3.taskbar;
|
||||
|
||||
import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_ALL_APPS;
|
||||
import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT;
|
||||
import static com.android.launcher3.model.data.AppInfo.COMPONENT_KEY_COMPARATOR;
|
||||
import static com.android.launcher3.popup.SystemShortcut.PIN_UNPIN_ITEM;
|
||||
import static com.android.launcher3.util.SplitConfigurationOptions.getLogEventForPosition;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.pm.LauncherApps;
|
||||
import android.graphics.Point;
|
||||
import android.util.Pair;
|
||||
import android.util.SparseArray;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.internal.logging.InstanceId;
|
||||
import com.android.launcher3.AbstractFloatingView;
|
||||
@@ -88,6 +90,8 @@ public class TaskbarPopupController implements TaskbarControllers.LoggableTaskba
|
||||
private TaskbarControllers mControllers;
|
||||
private boolean mAllowInitialSplitSelection;
|
||||
private AppInfo[] mAppInfosList;
|
||||
// Saves the ItemInfos in the hotseat without the predicted items.
|
||||
private SparseArray<ItemInfo> mHotseatInfosList;
|
||||
private ManageWindowsTaskbarShortcut<BaseTaskbarContext> mManageWindowsTaskbarShortcut;
|
||||
|
||||
|
||||
@@ -189,6 +193,14 @@ public class TaskbarPopupController implements TaskbarControllers.LoggableTaskba
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// TODO(b/375648361): Revisit to see if this can be implemented within getSystemShortcuts().
|
||||
if (Flags.enablePinningAppWithContextMenu()) {
|
||||
SystemShortcut shortcut = createPinShortcut(context, item, icon);
|
||||
if (shortcut != null) {
|
||||
systemShortcuts.add(0, shortcut);
|
||||
}
|
||||
}
|
||||
|
||||
container = (PopupContainerWithArrow) context.getLayoutInflater().inflate(
|
||||
R.layout.popup_container, context.getDragLayer(), false);
|
||||
container.populateAndShowRows(icon, deepShortcutCount, systemShortcuts);
|
||||
@@ -212,9 +224,6 @@ public class TaskbarPopupController implements TaskbarControllers.LoggableTaskba
|
||||
// append split options to APP_INFO shortcut if not in Desktop Windowing mode, the order
|
||||
// here will reflect in the popup
|
||||
ArrayList<SystemShortcut.Factory> shortcuts = new ArrayList<>();
|
||||
if (Flags.enablePinningAppWithContextMenu()) {
|
||||
shortcuts.add(PIN_UNPIN_ITEM);
|
||||
}
|
||||
shortcuts.add(APP_INFO);
|
||||
if (!mControllers.taskbarDesktopModeController
|
||||
.isInDesktopModeAndNotInOverview(mContext.getDisplayId())) {
|
||||
@@ -233,6 +242,24 @@ public class TaskbarPopupController implements TaskbarControllers.LoggableTaskba
|
||||
return shortcuts.stream();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private SystemShortcut createPinShortcut(BaseTaskbarContext target, ItemInfo itemInfo,
|
||||
BubbleTextView originalView) {
|
||||
// Predicted items use {@code HotseatPredictionController.PinPrediction} shortcut to pin.
|
||||
if (itemInfo.isPredictedItem()) {
|
||||
return null;
|
||||
}
|
||||
if (itemInfo.container == CONTAINER_HOTSEAT) {
|
||||
return new PinToTaskbarShortcut<>(target, itemInfo, originalView, false);
|
||||
}
|
||||
if (mHotseatInfosList.size()
|
||||
< mContext.getTaskbarSpecsEvaluator().getNumShownHotseatIcons()) {
|
||||
return new PinToTaskbarShortcut<>(target, itemInfo, originalView, true);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dumpLogs(String prefix, PrintWriter pw) {
|
||||
pw.println(prefix + "TaskbarPopupController:");
|
||||
@@ -316,6 +343,10 @@ public class TaskbarPopupController implements TaskbarControllers.LoggableTaskba
|
||||
return index < 0 ? null : mAppInfosList[index];
|
||||
}
|
||||
|
||||
public void setHotseatInfosList(SparseArray<ItemInfo> info) {
|
||||
mHotseatInfosList = info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a stream of Multi Instance menu options if an app supports it.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user