Refactor LauncherAccessibilityDelegate so it can be used outside of Launcher

Bug: 198438631
Test: used talkback on launcher
Change-Id: I991320184ad93816c4ba21fb8fcfe12202bfae25
diff --git a/quickstep/src/com/android/launcher3/QuickstepAccessibilityDelegate.java b/quickstep/src/com/android/launcher3/QuickstepAccessibilityDelegate.java
index 96559cb..962fd91 100644
--- a/quickstep/src/com/android/launcher3/QuickstepAccessibilityDelegate.java
+++ b/quickstep/src/com/android/launcher3/QuickstepAccessibilityDelegate.java
@@ -44,7 +44,7 @@
 
     @Override
     protected boolean performAction(View host, ItemInfo item, int action, boolean fromKeyboard) {
-        QuickstepLauncher launcher = (QuickstepLauncher) mLauncher;
+        QuickstepLauncher launcher = (QuickstepLauncher) mContext;
         if (action == PIN_PREDICTION) {
             if (launcher.getHotseatPredictionController() == null) {
                 return false;
diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java
index 5a6365a..f016965 100644
--- a/src/com/android/launcher3/BubbleTextView.java
+++ b/src/com/android/launcher3/BubbleTextView.java
@@ -48,7 +48,7 @@
 import androidx.annotation.Nullable;
 import androidx.annotation.UiThread;
 
-import com.android.launcher3.accessibility.LauncherAccessibilityDelegate;
+import com.android.launcher3.accessibility.BaseAccessibilityDelegate;
 import com.android.launcher3.dot.DotInfo;
 import com.android.launcher3.dragndrop.DraggableView;
 import com.android.launcher3.folder.FolderIcon;
@@ -296,7 +296,7 @@
 
     @Override
     public void setAccessibilityDelegate(AccessibilityDelegate delegate) {
-        if (delegate instanceof LauncherAccessibilityDelegate) {
+        if (delegate instanceof BaseAccessibilityDelegate) {
             super.setAccessibilityDelegate(delegate);
         } else {
             // NO-OP
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 0656125..ab9b980 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -115,8 +115,8 @@
 import androidx.annotation.VisibleForTesting;
 
 import com.android.launcher3.DropTarget.DragObject;
+import com.android.launcher3.accessibility.BaseAccessibilityDelegate.LauncherAction;
 import com.android.launcher3.accessibility.LauncherAccessibilityDelegate;
-import com.android.launcher3.accessibility.LauncherAccessibilityDelegate.LauncherAction;
 import com.android.launcher3.allapps.AllAppsContainerView;
 import com.android.launcher3.allapps.AllAppsStore;
 import com.android.launcher3.allapps.AllAppsTransitionController;
diff --git a/src/com/android/launcher3/accessibility/BaseAccessibilityDelegate.java b/src/com/android/launcher3/accessibility/BaseAccessibilityDelegate.java
new file mode 100644
index 0000000..14b2431
--- /dev/null
+++ b/src/com/android/launcher3/accessibility/BaseAccessibilityDelegate.java
@@ -0,0 +1,192 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.launcher3.accessibility;
+
+import android.content.Context;
+import android.graphics.Rect;
+import android.os.Bundle;
+import android.text.TextUtils;
+import android.util.SparseArray;
+import android.view.View;
+import android.view.accessibility.AccessibilityNodeInfo;
+
+import com.android.launcher3.DropTarget;
+import com.android.launcher3.LauncherSettings;
+import com.android.launcher3.dragndrop.DragController;
+import com.android.launcher3.dragndrop.DragOptions;
+import com.android.launcher3.model.data.FolderInfo;
+import com.android.launcher3.model.data.ItemInfo;
+import com.android.launcher3.model.data.LauncherAppWidgetInfo;
+import com.android.launcher3.model.data.WorkspaceItemInfo;
+import com.android.launcher3.popup.PopupContainerWithArrow;
+import com.android.launcher3.util.Thunk;
+import com.android.launcher3.views.ActivityContext;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public abstract class BaseAccessibilityDelegate<T extends Context & ActivityContext>
+        extends View.AccessibilityDelegate implements DragController.DragListener {
+
+    public enum DragType {
+        ICON,
+        FOLDER,
+        WIDGET
+    }
+
+    public static class DragInfo {
+        public DragType dragType;
+        public ItemInfo info;
+        public View item;
+    }
+
+    protected final SparseArray<LauncherAction> mActions = new SparseArray<>();
+    protected final T mContext;
+
+    protected DragInfo mDragInfo = null;
+
+    protected BaseAccessibilityDelegate(T context) {
+        mContext = context;
+    }
+
+    @Override
+    public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) {
+        super.onInitializeAccessibilityNodeInfo(host, info);
+        if (host.getTag() instanceof ItemInfo) {
+            ItemInfo item = (ItemInfo) host.getTag();
+
+            List<LauncherAction> actions = new ArrayList<>();
+            getSupportedActions(host, item, actions);
+            actions.forEach(la -> info.addAction(la.accessibilityAction));
+
+            if (!itemSupportsLongClick(host, item)) {
+                info.setLongClickable(false);
+                info.removeAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_LONG_CLICK);
+            }
+        }
+    }
+
+    /**
+     * Adds all the accessibility actions that can be handled.
+     */
+    protected abstract void getSupportedActions(View host, ItemInfo item, List<LauncherAction> out);
+
+    private boolean itemSupportsLongClick(View host, ItemInfo info) {
+        return PopupContainerWithArrow.canShow(host, info);
+    }
+
+    protected boolean itemSupportsAccessibleDrag(ItemInfo item) {
+        if (item instanceof WorkspaceItemInfo) {
+            // Support the action unless the item is in a context menu.
+            return item.screenId >= 0
+                    && item.container != LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION;
+        }
+        return (item instanceof LauncherAppWidgetInfo)
+                || (item instanceof FolderInfo);
+    }
+
+    @Override
+    public boolean performAccessibilityAction(View host, int action, Bundle args) {
+        if ((host.getTag() instanceof ItemInfo)
+                && performAction(host, (ItemInfo) host.getTag(), action, false)) {
+            return true;
+        }
+        return super.performAccessibilityAction(host, action, args);
+    }
+
+    protected abstract boolean performAction(
+            View host, ItemInfo item, int action, boolean fromKeyboard);
+
+    @Thunk
+    protected void announceConfirmation(String confirmation) {
+        mContext.getDragLayer().announceForAccessibility(confirmation);
+
+    }
+
+    public boolean isInAccessibleDrag() {
+        return mDragInfo != null;
+    }
+
+    public DragInfo getDragInfo() {
+        return mDragInfo;
+    }
+
+    /**
+     * @param clickedTarget the actual view that was clicked
+     * @param dropLocation relative to {@param clickedTarget}. If provided, its center is used
+     * as the actual drop location otherwise the views center is used.
+     */
+    public void handleAccessibleDrop(View clickedTarget, Rect dropLocation,
+            String confirmation) {
+        if (!isInAccessibleDrag()) return;
+
+        int[] loc = new int[2];
+        if (dropLocation == null) {
+            loc[0] = clickedTarget.getWidth() / 2;
+            loc[1] = clickedTarget.getHeight() / 2;
+        } else {
+            loc[0] = dropLocation.centerX();
+            loc[1] = dropLocation.centerY();
+        }
+
+        mContext.getDragLayer().getDescendantCoordRelativeToSelf(clickedTarget, loc);
+        mContext.getDragController().completeAccessibleDrag(loc);
+
+        if (!TextUtils.isEmpty(confirmation)) {
+            announceConfirmation(confirmation);
+        }
+    }
+
+    protected abstract boolean beginAccessibleDrag(View item, ItemInfo info, boolean fromKeyboard);
+
+
+    @Override
+    public void onDragEnd() {
+        mContext.getDragController().removeDragListener(this);
+        mDragInfo = null;
+    }
+
+    @Override
+    public void onDragStart(DropTarget.DragObject dragObject, DragOptions options) {
+        // No-op
+    }
+
+    public class LauncherAction {
+        public final int keyCode;
+        public final AccessibilityNodeInfo.AccessibilityAction accessibilityAction;
+
+        private final BaseAccessibilityDelegate<T> mDelegate;
+
+        public LauncherAction(int id, int labelRes, int keyCode) {
+            this.keyCode = keyCode;
+            accessibilityAction = new AccessibilityNodeInfo.AccessibilityAction(
+                    id, mContext.getString(labelRes));
+            mDelegate = BaseAccessibilityDelegate.this;
+        }
+
+        /**
+         * Invokes the action for the provided host
+         */
+        public boolean invokeFromKeyboard(View host) {
+            if (host != null && host.getTag() instanceof ItemInfo) {
+                return mDelegate.performAction(
+                        host, (ItemInfo) host.getTag(), accessibilityAction.getId(), true);
+            } else {
+                return false;
+            }
+        }
+    }
+}
diff --git a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java
index 157df5d..18c05eb 100644
--- a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java
+++ b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java
@@ -10,27 +10,19 @@
 import android.graphics.Point;
 import android.graphics.Rect;
 import android.graphics.RectF;
-import android.os.Bundle;
 import android.os.Handler;
-import android.text.TextUtils;
 import android.util.Log;
-import android.util.SparseArray;
 import android.view.KeyEvent;
 import android.view.View;
-import android.view.View.AccessibilityDelegate;
-import android.view.accessibility.AccessibilityNodeInfo;
-import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
 
 import com.android.launcher3.BubbleTextView;
 import com.android.launcher3.ButtonDropTarget;
 import com.android.launcher3.CellLayout;
-import com.android.launcher3.DropTarget.DragObject;
 import com.android.launcher3.Launcher;
 import com.android.launcher3.LauncherSettings.Favorites;
 import com.android.launcher3.PendingAddItemInfo;
 import com.android.launcher3.R;
 import com.android.launcher3.Workspace;
-import com.android.launcher3.dragndrop.DragController.DragListener;
 import com.android.launcher3.dragndrop.DragOptions;
 import com.android.launcher3.dragndrop.DragView;
 import com.android.launcher3.folder.Folder;
@@ -57,7 +49,7 @@
 import java.util.Collections;
 import java.util.List;
 
-public class LauncherAccessibilityDelegate extends AccessibilityDelegate implements DragListener {
+public class LauncherAccessibilityDelegate extends BaseAccessibilityDelegate<Launcher> {
 
     private static final String TAG = "LauncherAccessibilityDelegate";
 
@@ -73,25 +65,8 @@
     public static final int DEEP_SHORTCUTS = R.id.action_deep_shortcuts;
     public static final int SHORTCUTS_AND_NOTIFICATIONS = R.id.action_shortcuts_and_notifications;
 
-    public enum DragType {
-        ICON,
-        FOLDER,
-        WIDGET
-    }
-
-    public static class DragInfo {
-        public DragType dragType;
-        public ItemInfo info;
-        public View item;
-    }
-
-    protected final SparseArray<LauncherAction> mActions = new SparseArray<>();
-    protected final Launcher mLauncher;
-
-    private DragInfo mDragInfo = null;
-
     public LauncherAccessibilityDelegate(Launcher launcher) {
-        mLauncher = launcher;
+        super(launcher);
 
         mActions.put(REMOVE, new LauncherAction(
                 REMOVE, R.string.remove_drop_target_label, KeyEvent.KEYCODE_X));
@@ -116,25 +91,6 @@
     }
 
     @Override
-    public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) {
-        super.onInitializeAccessibilityNodeInfo(host, info);
-        if (host.getTag() instanceof ItemInfo) {
-            ItemInfo item = (ItemInfo) host.getTag();
-
-            List<LauncherAction> actions = new ArrayList<>();
-            getSupportedActions(host, item, actions);
-            actions.forEach(la -> info.addAction(la.accessibilityAction));
-
-            if (!itemSupportsLongClick(host, item)) {
-                info.setLongClickable(false);
-                info.removeAction(AccessibilityAction.ACTION_LONG_CLICK);
-            }
-        }
-    }
-
-    /**
-     * Adds all the accessibility actions that can be handled.
-     */
     protected void getSupportedActions(View host, ItemInfo item, List<LauncherAction> out) {
         // If the request came from keyboard, do not add custom shortcuts as that is already
         // exposed as a direct shortcut
@@ -143,7 +99,7 @@
                     ? SHORTCUTS_AND_NOTIFICATIONS : DEEP_SHORTCUTS));
         }
 
-        for (ButtonDropTarget target : mLauncher.getDropTargetBar().getDropTargets()) {
+        for (ButtonDropTarget target : mContext.getDropTargetBar().getDropTargets()) {
             if (target.supportsAccessibilityDrop(item, host)) {
                 out.add(mActions.get(target.getAccessibilityAction()));
             }
@@ -183,31 +139,7 @@
         return result;
     }
 
-    private boolean itemSupportsLongClick(View host, ItemInfo info) {
-        return PopupContainerWithArrow.canShow(host, info);
-    }
-
-    private boolean itemSupportsAccessibleDrag(ItemInfo item) {
-        if (item instanceof WorkspaceItemInfo) {
-            // Support the action unless the item is in a context menu.
-            return item.screenId >= 0 && item.container != Favorites.CONTAINER_HOTSEAT_PREDICTION;
-        }
-        return (item instanceof LauncherAppWidgetInfo)
-                || (item instanceof FolderInfo);
-    }
-
     @Override
-    public boolean performAccessibilityAction(View host, int action, Bundle args) {
-        if ((host.getTag() instanceof ItemInfo)
-                && performAction(host, (ItemInfo) host.getTag(), action, false)) {
-            return true;
-        }
-        return super.performAccessibilityAction(host, action, args);
-    }
-
-    /**
-     * Performs the provided action on the host
-     */
     protected boolean performAction(final View host, final ItemInfo item, int action,
             boolean fromKeyboard) {
         if (action == ACTION_LONG_CLICK) {
@@ -226,36 +158,36 @@
             if (screenId == -1) {
                 return false;
             }
-            mLauncher.getStateManager().goToState(NORMAL, true, forSuccessCallback(() -> {
+            mContext.getStateManager().goToState(NORMAL, true, forSuccessCallback(() -> {
                 if (item instanceof AppInfo) {
                     WorkspaceItemInfo info = ((AppInfo) item).makeWorkspaceItem();
-                    mLauncher.getModelWriter().addItemToDatabase(info,
+                    mContext.getModelWriter().addItemToDatabase(info,
                             Favorites.CONTAINER_DESKTOP,
                             screenId, coordinates[0], coordinates[1]);
 
-                    mLauncher.bindItems(
+                    mContext.bindItems(
                             Collections.singletonList(info),
                             /* forceAnimateIcons= */ true,
                             /* focusFirstItemForAccessibility= */ true);
                     announceConfirmation(R.string.item_added_to_workspace);
                 } else if (item instanceof PendingAddItemInfo) {
                     PendingAddItemInfo info = (PendingAddItemInfo) item;
-                    Workspace workspace = mLauncher.getWorkspace();
+                    Workspace workspace = mContext.getWorkspace();
                     workspace.snapToPage(workspace.getPageIndexForScreenId(screenId));
-                    mLauncher.addPendingItem(info, Favorites.CONTAINER_DESKTOP,
+                    mContext.addPendingItem(info, Favorites.CONTAINER_DESKTOP,
                             screenId, coordinates, info.spanX, info.spanY);
                 }
                 else if (item instanceof WorkspaceItemInfo) {
                     WorkspaceItemInfo info = ((WorkspaceItemInfo) item).clone();
-                    mLauncher.getModelWriter().addItemToDatabase(info,
+                    mContext.getModelWriter().addItemToDatabase(info,
                             Favorites.CONTAINER_DESKTOP,
                             screenId, coordinates[0], coordinates[1]);
-                    mLauncher.bindItems(Collections.singletonList(info), true, true);
+                    mContext.bindItems(Collections.singletonList(info), true, true);
                 }
             }));
             return true;
         } else if (action == MOVE_TO_WORKSPACE) {
-            Folder folder = Folder.getOpen(mLauncher);
+            Folder folder = Folder.getOpen(mContext);
             folder.close(true);
             WorkspaceItemInfo info = (WorkspaceItemInfo) item;
             folder.getInfo().remove(info, false);
@@ -265,14 +197,14 @@
             if (screenId == -1) {
                 return false;
             }
-            mLauncher.getModelWriter().moveItemInDatabase(info,
+            mContext.getModelWriter().moveItemInDatabase(info,
                     Favorites.CONTAINER_DESKTOP,
                     screenId, coordinates[0], coordinates[1]);
 
             // Bind the item in next frame so that if a new workspace page was created,
             // it will get laid out.
             new Handler().post(() -> {
-                mLauncher.bindItems(Collections.singletonList(item), true);
+                mContext.bindItems(Collections.singletonList(item), true);
                 announceConfirmation(R.string.item_moved);
             });
             return true;
@@ -280,15 +212,15 @@
             final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) item;
             List<OptionItem> actions = getSupportedResizeActions(host, info);
             Rect pos = new Rect();
-            mLauncher.getDragLayer().getDescendantRectRelativeToSelf(host, pos);
-            ArrowPopup popup = OptionsPopupView.show(mLauncher, new RectF(pos), actions, false);
+            mContext.getDragLayer().getDescendantRectRelativeToSelf(host, pos);
+            ArrowPopup popup = OptionsPopupView.show(mContext, new RectF(pos), actions, false);
             popup.requestFocus();
             popup.setOnCloseCallback(host::requestFocus);
             return true;
         } else if (action == DEEP_SHORTCUTS || action == SHORTCUTS_AND_NOTIFICATIONS) {
             return PopupContainerWithArrow.showForIcon((BubbleTextView) host) != null;
         } else {
-            for (ButtonDropTarget dropTarget : mLauncher.getDropTargetBar().getDropTargets()) {
+            for (ButtonDropTarget dropTarget : mContext.getDropTargetBar().getDropTargets()) {
                 if (dropTarget.supportsAccessibilityDrop(item, host)
                         && action == dropTarget.getAccessibilityAction()) {
                     dropTarget.onAccessibilityDrop(host, item);
@@ -315,7 +247,7 @@
         if ((providerInfo.resizeMode & AppWidgetProviderInfo.RESIZE_HORIZONTAL) != 0) {
             if (layout.isRegionVacant(info.cellX + info.spanX, info.cellY, 1, info.spanY) ||
                     layout.isRegionVacant(info.cellX - 1, info.cellY, 1, info.spanY)) {
-                actions.add(new OptionItem(mLauncher,
+                actions.add(new OptionItem(mContext,
                         R.string.action_increase_width,
                         R.drawable.ic_widget_width_increase,
                         IGNORE,
@@ -323,7 +255,7 @@
             }
 
             if (info.spanX > info.minSpanX && info.spanX > 1) {
-                actions.add(new OptionItem(mLauncher,
+                actions.add(new OptionItem(mContext,
                         R.string.action_decrease_width,
                         R.drawable.ic_widget_width_decrease,
                         IGNORE,
@@ -334,7 +266,7 @@
         if ((providerInfo.resizeMode & AppWidgetProviderInfo.RESIZE_VERTICAL) != 0) {
             if (layout.isRegionVacant(info.cellX, info.cellY + info.spanY, info.spanX, 1) ||
                     layout.isRegionVacant(info.cellX, info.cellY - 1, info.spanX, 1)) {
-                actions.add(new OptionItem(mLauncher,
+                actions.add(new OptionItem(mContext,
                         R.string.action_increase_height,
                         R.drawable.ic_widget_height_increase,
                         IGNORE,
@@ -342,7 +274,7 @@
             }
 
             if (info.spanY > info.minSpanY && info.spanY > 1) {
-                actions.add(new OptionItem(mLauncher,
+                actions.add(new OptionItem(mContext,
                         R.string.action_decrease_height,
                         R.drawable.ic_widget_height_decrease,
                         IGNORE,
@@ -382,58 +314,20 @@
         }
 
         layout.markCellsAsOccupiedForView(host);
-        WidgetSizes.updateWidgetSizeRanges(((LauncherAppWidgetHostView) host), mLauncher,
+        WidgetSizes.updateWidgetSizeRanges(((LauncherAppWidgetHostView) host), mContext,
                 info.spanX, info.spanY);
         host.requestLayout();
-        mLauncher.getModelWriter().updateItemInDatabase(info);
-        announceConfirmation(mLauncher.getString(R.string.widget_resized, info.spanX, info.spanY));
+        mContext.getModelWriter().updateItemInDatabase(info);
+        announceConfirmation(mContext.getString(R.string.widget_resized, info.spanX, info.spanY));
         return true;
     }
 
     @Thunk void announceConfirmation(int resId) {
-        announceConfirmation(mLauncher.getResources().getString(resId));
+        announceConfirmation(mContext.getResources().getString(resId));
     }
 
-    @Thunk void announceConfirmation(String confirmation) {
-        mLauncher.getDragLayer().announceForAccessibility(confirmation);
-
-    }
-
-    public boolean isInAccessibleDrag() {
-        return mDragInfo != null;
-    }
-
-    public DragInfo getDragInfo() {
-        return mDragInfo;
-    }
-
-    /**
-     * @param clickedTarget the actual view that was clicked
-     * @param dropLocation relative to {@param clickedTarget}. If provided, its center is used
-     * as the actual drop location otherwise the views center is used.
-     */
-    public void handleAccessibleDrop(View clickedTarget, Rect dropLocation,
-            String confirmation) {
-        if (!isInAccessibleDrag()) return;
-
-        int[] loc = new int[2];
-        if (dropLocation == null) {
-            loc[0] = clickedTarget.getWidth() / 2;
-            loc[1] = clickedTarget.getHeight() / 2;
-        } else {
-            loc[0] = dropLocation.centerX();
-            loc[1] = dropLocation.centerY();
-        }
-
-        mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(clickedTarget, loc);
-        mLauncher.getDragController().completeAccessibleDrag(loc);
-
-        if (!TextUtils.isEmpty(confirmation)) {
-            announceConfirmation(confirmation);
-        }
-    }
-
-    private boolean beginAccessibleDrag(View item, ItemInfo info, boolean fromKeyboard) {
+    @Override
+    protected boolean beginAccessibleDrag(View item, ItemInfo info, boolean fromKeyboard) {
         if (!itemSupportsAccessibleDrag(info)) {
             return false;
         }
@@ -449,8 +343,8 @@
         }
 
         Rect pos = new Rect();
-        mLauncher.getDragLayer().getDescendantRectRelativeToSelf(item, pos);
-        mLauncher.getDragController().addDragListener(this);
+        mContext.getDragLayer().getDescendantRectRelativeToSelf(item, pos);
+        mContext.getDragController().addDragListener(this);
 
         DragOptions options = new DragOptions();
         options.isAccessibleDrag = true;
@@ -458,31 +352,20 @@
         options.simulatedDndStartPoint = new Point(pos.centerX(), pos.centerY());
 
         if (fromKeyboard) {
-            KeyboardDragAndDropView popup = (KeyboardDragAndDropView) mLauncher.getLayoutInflater()
-                    .inflate(R.layout.keyboard_drag_and_drop, mLauncher.getDragLayer(), false);
+            KeyboardDragAndDropView popup = (KeyboardDragAndDropView) mContext.getLayoutInflater()
+                    .inflate(R.layout.keyboard_drag_and_drop, mContext.getDragLayer(), false);
             popup.showForIcon(item, info, options);
         } else {
-            ItemLongClickListener.beginDrag(item, mLauncher, info, options);
+            ItemLongClickListener.beginDrag(item, mContext, info, options);
         }
         return true;
     }
 
-    @Override
-    public void onDragStart(DragObject dragObject, DragOptions options) {
-        // No-op
-    }
-
-    @Override
-    public void onDragEnd() {
-        mLauncher.getDragController().removeDragListener(this);
-        mDragInfo = null;
-    }
-
     /**
      * Find empty space on the workspace and returns the screenId.
      */
     protected int findSpaceOnWorkspace(ItemInfo info, int[] outCoordinates) {
-        Workspace workspace = mLauncher.getWorkspace();
+        Workspace workspace = mContext.getWorkspace();
         IntArray workspaceScreens = workspace.getScreenOrder();
         int screenId;
 
@@ -520,29 +403,4 @@
         }
         return screenId;
     }
-
-    public class LauncherAction {
-        public final int keyCode;
-        public final AccessibilityAction accessibilityAction;
-
-        private final LauncherAccessibilityDelegate mDelegate;
-
-        public LauncherAction(int id, int labelRes, int keyCode) {
-            this.keyCode = keyCode;
-            accessibilityAction = new AccessibilityAction(id, mLauncher.getString(labelRes));
-            mDelegate = LauncherAccessibilityDelegate.this;
-        }
-
-        /**
-         * Invokes the action for the provided host
-         */
-        public boolean invokeFromKeyboard(View host) {
-            if (host != null && host.getTag() instanceof ItemInfo) {
-                return mDelegate.performAction(
-                        host, (ItemInfo) host.getTag(), accessibilityAction.getId(), true);
-            } else {
-                return false;
-            }
-        }
-    }
 }
diff --git a/src/com/android/launcher3/accessibility/ShortcutMenuAccessibilityDelegate.java b/src/com/android/launcher3/accessibility/ShortcutMenuAccessibilityDelegate.java
index bf5a24b..fb847ec 100644
--- a/src/com/android/launcher3/accessibility/ShortcutMenuAccessibilityDelegate.java
+++ b/src/com/android/launcher3/accessibility/ShortcutMenuAccessibilityDelegate.java
@@ -71,12 +71,12 @@
             if (screenId == -1) {
                 return false;
             }
-            mLauncher.getStateManager().goToState(NORMAL, true, forSuccessCallback(() -> {
-                mLauncher.getModelWriter().addItemToDatabase(info,
+            mContext.getStateManager().goToState(NORMAL, true, forSuccessCallback(() -> {
+                mContext.getModelWriter().addItemToDatabase(info,
                         LauncherSettings.Favorites.CONTAINER_DESKTOP,
                         screenId, coordinates[0], coordinates[1]);
-                mLauncher.bindItems(Collections.singletonList(info), true);
-                AbstractFloatingView.closeAllOpenViews(mLauncher);
+                mContext.bindItems(Collections.singletonList(info), true);
+                AbstractFloatingView.closeAllOpenViews(mContext);
                 announceConfirmation(R.string.item_added_to_workspace);
             }));
             return true;
diff --git a/src/com/android/launcher3/accessibility/WorkspaceAccessibilityHelper.java b/src/com/android/launcher3/accessibility/WorkspaceAccessibilityHelper.java
index a331924..a8624dd 100644
--- a/src/com/android/launcher3/accessibility/WorkspaceAccessibilityHelper.java
+++ b/src/com/android/launcher3/accessibility/WorkspaceAccessibilityHelper.java
@@ -22,7 +22,7 @@
 
 import com.android.launcher3.CellLayout;
 import com.android.launcher3.R;
-import com.android.launcher3.accessibility.LauncherAccessibilityDelegate.DragType;
+import com.android.launcher3.accessibility.BaseAccessibilityDelegate.DragType;
 import com.android.launcher3.model.data.AppInfo;
 import com.android.launcher3.model.data.FolderInfo;
 import com.android.launcher3.model.data.ItemInfo;