1 /* 2 * Copyright (C) 2016 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 17 package com.android.launcher3.accessibility; 18 19 import static com.android.launcher3.LauncherState.NORMAL; 20 import static com.android.launcher3.anim.AnimatorListeners.forSuccessCallback; 21 22 import android.view.View; 23 24 import com.android.launcher3.AbstractFloatingView; 25 import com.android.launcher3.Launcher; 26 import com.android.launcher3.LauncherSettings; 27 import com.android.launcher3.R; 28 import com.android.launcher3.model.data.ItemInfo; 29 import com.android.launcher3.model.data.WorkspaceItemInfo; 30 import com.android.launcher3.shortcuts.DeepShortcutView; 31 32 import java.util.Collections; 33 import java.util.List; 34 35 /** 36 * Extension of {@link LauncherAccessibilityDelegate} with actions specific to shortcuts in 37 * deep shortcuts menu. 38 */ 39 public class ShortcutMenuAccessibilityDelegate extends LauncherAccessibilityDelegate { 40 ShortcutMenuAccessibilityDelegate(Launcher launcher)41 public ShortcutMenuAccessibilityDelegate(Launcher launcher) { 42 super(launcher); 43 } 44 45 @Override getSupportedActions(View host, ItemInfo item, List<LauncherAction> out)46 protected void getSupportedActions(View host, ItemInfo item, List<LauncherAction> out) { 47 if ((host.getParent() instanceof DeepShortcutView)) { 48 out.add(mActions.get(ADD_TO_WORKSPACE)); 49 } 50 } 51 52 @Override performAction(View host, ItemInfo item, int action, boolean fromKeyboard)53 protected boolean performAction(View host, ItemInfo item, int action, boolean fromKeyboard) { 54 if (action == ADD_TO_WORKSPACE) { 55 if (!(host.getParent() instanceof DeepShortcutView)) { 56 return false; 57 } 58 final WorkspaceItemInfo info = ((DeepShortcutView) host.getParent()).getFinalInfo(); 59 final int[] coordinates = new int[2]; 60 final int screenId = findSpaceOnWorkspace(item, coordinates); 61 if (screenId == -1) { 62 return false; 63 } 64 mContext.getStateManager().goToState(NORMAL, true, forSuccessCallback(() -> { 65 mContext.getModelWriter().addItemToDatabase(info, 66 LauncherSettings.Favorites.CONTAINER_DESKTOP, 67 screenId, coordinates[0], coordinates[1]); 68 mContext.bindItems(Collections.singletonList(info), true); 69 AbstractFloatingView.closeAllOpenViews(mContext); 70 announceConfirmation(R.string.item_added_to_workspace); 71 })); 72 return true; 73 } 74 return false; 75 } 76 } 77