1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.launcher3.taskbar; 17 18 import static com.android.launcher3.accessibility.LauncherAccessibilityDelegate.DEEP_SHORTCUTS; 19 import static com.android.launcher3.accessibility.LauncherAccessibilityDelegate.SHORTCUTS_AND_NOTIFICATIONS; 20 import static com.android.launcher3.util.SplitConfigurationOptions.STAGE_POSITION_BOTTOM_OR_RIGHT; 21 import static com.android.launcher3.util.SplitConfigurationOptions.STAGE_POSITION_TOP_OR_LEFT; 22 import static com.android.launcher3.util.SplitConfigurationOptions.getLogEventForPosition; 23 24 import android.content.Intent; 25 import android.content.pm.LauncherApps; 26 import android.util.Pair; 27 import android.view.KeyEvent; 28 import android.view.View; 29 30 import com.android.internal.logging.InstanceId; 31 import com.android.launcher3.BubbleTextView; 32 import com.android.launcher3.LauncherSettings; 33 import com.android.launcher3.R; 34 import com.android.launcher3.accessibility.BaseAccessibilityDelegate; 35 import com.android.launcher3.config.FeatureFlags; 36 import com.android.launcher3.logging.StatsLogManager; 37 import com.android.launcher3.model.data.ItemInfo; 38 import com.android.launcher3.model.data.WorkspaceItemInfo; 39 import com.android.launcher3.notification.NotificationListener; 40 import com.android.launcher3.util.ShortcutUtil; 41 import com.android.quickstep.SystemUiProxy; 42 import com.android.quickstep.util.LogUtils; 43 44 import java.util.List; 45 46 /** 47 * Accessibility delegate for the Taskbar. This provides an accessible interface for taskbar 48 * features. 49 */ 50 public class TaskbarShortcutMenuAccessibilityDelegate 51 extends BaseAccessibilityDelegate<TaskbarActivityContext> { 52 53 public static final int MOVE_TO_TOP_OR_LEFT = R.id.action_move_to_top_or_left; 54 public static final int MOVE_TO_BOTTOM_OR_RIGHT = R.id.action_move_to_bottom_or_right; 55 56 private final LauncherApps mLauncherApps; 57 private final StatsLogManager mStatsLogManager; 58 TaskbarShortcutMenuAccessibilityDelegate(TaskbarActivityContext context)59 public TaskbarShortcutMenuAccessibilityDelegate(TaskbarActivityContext context) { 60 super(context); 61 mLauncherApps = context.getSystemService(LauncherApps.class); 62 mStatsLogManager = context.getStatsLogManager(); 63 64 mActions.put(DEEP_SHORTCUTS, new LauncherAction(DEEP_SHORTCUTS, 65 R.string.action_deep_shortcut, KeyEvent.KEYCODE_S)); 66 mActions.put(SHORTCUTS_AND_NOTIFICATIONS, new LauncherAction(DEEP_SHORTCUTS, 67 R.string.shortcuts_menu_with_notifications_description, KeyEvent.KEYCODE_S)); 68 mActions.put(MOVE_TO_TOP_OR_LEFT, new LauncherAction( 69 MOVE_TO_TOP_OR_LEFT, R.string.move_drop_target_top_or_left, KeyEvent.KEYCODE_L)); 70 mActions.put(MOVE_TO_BOTTOM_OR_RIGHT, new LauncherAction( 71 MOVE_TO_BOTTOM_OR_RIGHT, 72 R.string.move_drop_target_bottom_or_right, 73 KeyEvent.KEYCODE_R)); 74 } 75 76 @Override getSupportedActions(View host, ItemInfo item, List<LauncherAction> out)77 protected void getSupportedActions(View host, ItemInfo item, List<LauncherAction> out) { 78 if (ShortcutUtil.supportsShortcuts(item) && FeatureFlags.ENABLE_TASKBAR_POPUP_MENU.get()) { 79 out.add(mActions.get(NotificationListener.getInstanceIfConnected() != null 80 ? SHORTCUTS_AND_NOTIFICATIONS : DEEP_SHORTCUTS)); 81 } 82 out.add(mActions.get(MOVE_TO_TOP_OR_LEFT)); 83 out.add(mActions.get(MOVE_TO_BOTTOM_OR_RIGHT)); 84 } 85 86 @Override performAction(View host, ItemInfo item, int action, boolean fromKeyboard)87 protected boolean performAction(View host, ItemInfo item, int action, boolean fromKeyboard) { 88 if (item instanceof WorkspaceItemInfo 89 && (action == MOVE_TO_TOP_OR_LEFT || action == MOVE_TO_BOTTOM_OR_RIGHT)) { 90 WorkspaceItemInfo info = (WorkspaceItemInfo) item; 91 int side = action == MOVE_TO_TOP_OR_LEFT 92 ? STAGE_POSITION_TOP_OR_LEFT : STAGE_POSITION_BOTTOM_OR_RIGHT; 93 94 Pair<InstanceId, com.android.launcher3.logging.InstanceId> instanceIds = 95 LogUtils.getShellShareableInstanceId(); 96 mStatsLogManager.logger() 97 .withItemInfo(item) 98 .withInstanceId(instanceIds.second) 99 .log(getLogEventForPosition(side)); 100 101 if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) { 102 SystemUiProxy.INSTANCE.get(mContext).startShortcut( 103 info.getIntent().getPackage(), 104 info.getDeepShortcutId(), 105 side, 106 /* bundleOpts= */ null, 107 info.user, 108 instanceIds.first); 109 } else { 110 SystemUiProxy.INSTANCE.get(mContext).startIntent( 111 mLauncherApps.getMainActivityLaunchIntent( 112 item.getIntent().getComponent(), 113 /* startActivityOptions= */null, 114 item.user), 115 new Intent(), side, null, instanceIds.first); 116 } 117 return true; 118 } else if (action == DEEP_SHORTCUTS || action == SHORTCUTS_AND_NOTIFICATIONS) { 119 mContext.showPopupMenuForIcon((BubbleTextView) host); 120 121 return true; 122 } 123 return false; 124 } 125 126 @Override beginAccessibleDrag(View item, ItemInfo info, boolean fromKeyboard)127 protected boolean beginAccessibleDrag(View item, ItemInfo info, boolean fromKeyboard) { 128 return false; 129 } 130 } 131