diff --git a/src/com/android/launcher3/ButtonDropTarget.java b/src/com/android/launcher3/ButtonDropTarget.java index 18619f5989..50111111fe 100644 --- a/src/com/android/launcher3/ButtonDropTarget.java +++ b/src/com/android/launcher3/ButtonDropTarget.java @@ -224,7 +224,10 @@ public abstract class ButtonDropTarget extends TextView protected abstract boolean supportsDrop(ItemInfo info); - public abstract boolean supportsAccessibilityDrop(ItemInfo info, View view); + /** + * Returns the accessibility action that {@link ButtonDropTarget} supports for the itemInfo. + */ + public abstract int getSupportedAccessibilityAction(ItemInfo info, View view); @Override public boolean isDropEnabled() { @@ -276,7 +279,8 @@ public abstract class ButtonDropTarget extends TextView @Override public void prepareAccessibilityDrop() { } - public abstract void onAccessibilityDrop(View view, ItemInfo item); + /** Performs a drop in case of accessibility services with the provided action for the item. */ + public abstract void onAccessibilityDrop(View view, ItemInfo item, int action); public abstract void completeDrop(DragObject d); diff --git a/src/com/android/launcher3/DeleteDropTarget.java b/src/com/android/launcher3/DeleteDropTarget.java index 89d54f8cf6..798d8b4046 100644 --- a/src/com/android/launcher3/DeleteDropTarget.java +++ b/src/com/android/launcher3/DeleteDropTarget.java @@ -32,6 +32,7 @@ import com.android.launcher3.model.data.CollectionInfo; 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.util.Preconditions; public class DeleteDropTarget extends ButtonDropTarget { @@ -68,8 +69,7 @@ public class DeleteDropTarget extends ButtonDropTarget { /** * @return true for items that should have a "Remove" action in accessibility. */ - @Override - public boolean supportsAccessibilityDrop(ItemInfo info, View view) { + private boolean supportsAccessibilityDrop(ItemInfo info, View view) { if (info instanceof WorkspaceItemInfo) { // Support the action unless the item is in a context menu. return canRemove(info); @@ -79,6 +79,14 @@ public class DeleteDropTarget extends ButtonDropTarget { || (info instanceof CollectionInfo); } + @Override + public int getSupportedAccessibilityAction(ItemInfo info, View view) { + if (supportsAccessibilityDrop(info, view)) { + return getAccessibilityAction(); + } + return LauncherAccessibilityDelegate.INVALID; + } + @Override public int getAccessibilityAction() { return LauncherAccessibilityDelegate.REMOVE; @@ -143,7 +151,8 @@ public class DeleteDropTarget extends ButtonDropTarget { * Removes the item from the workspace. If the view is not null, it also removes the view. */ @Override - public void onAccessibilityDrop(View view, ItemInfo item) { + public void onAccessibilityDrop(View view, ItemInfo item, int action) { + Preconditions.assertTrue(action == getAccessibilityAction()); // Remove the item from launcher and the db, we can ignore the containerInfo in this call // because we already remove the drag view from the folder (if the drag originated from // a folder) in Folder.beginDrag() diff --git a/src/com/android/launcher3/DropTargetBar.java b/src/com/android/launcher3/DropTargetBar.java index 8bdf61a633..1d5f185635 100644 --- a/src/com/android/launcher3/DropTargetBar.java +++ b/src/com/android/launcher3/DropTargetBar.java @@ -342,7 +342,10 @@ public class DropTargetBar extends FrameLayout } } + /** + * Returns all possible drop targets (including ones that aren't visible) + */ public ButtonDropTarget[] getDropTargets() { - return getVisibility() == View.VISIBLE ? mDropTargets : new ButtonDropTarget[0]; + return mDropTargets; } } diff --git a/src/com/android/launcher3/SecondaryDropTarget.java b/src/com/android/launcher3/SecondaryDropTarget.java index f4d3146ed5..d09da0a1f4 100644 --- a/src/com/android/launcher3/SecondaryDropTarget.java +++ b/src/com/android/launcher3/SecondaryDropTarget.java @@ -144,8 +144,8 @@ public class SecondaryDropTarget extends ButtonDropTarget implements OnAlarmList } @Override - public boolean supportsAccessibilityDrop(ItemInfo info, View view) { - return getButtonType(info, view) != INVALID; + public int getSupportedAccessibilityAction(ItemInfo info, View view) { + return getButtonType(info, view); } private int getButtonType(ItemInfo info, View view) { @@ -222,17 +222,17 @@ public class SecondaryDropTarget extends ButtonDropTarget implements OnAlarmList d.dragSource = new DeferredOnComplete(d.dragSource, getContext()); super.onDrop(d, options); - doLog(d.logInstanceId, d.originalDragInfo); + doLog(d.logInstanceId, d.originalDragInfo, mCurrentAccessibilityAction); } - private void doLog(InstanceId logInstanceId, ItemInfo itemInfo) { + private void doLog(InstanceId logInstanceId, ItemInfo itemInfo, int action) { StatsLogger logger = mStatsLogManager.logger().withInstanceId(logInstanceId); if (itemInfo != null) { logger.withItemInfo(itemInfo); } - if (mCurrentAccessibilityAction == UNINSTALL) { + if (action == UNINSTALL) { logger.log(LAUNCHER_ITEM_DROPPED_ON_UNINSTALL); - } else if (mCurrentAccessibilityAction == DISMISS_PREDICTION) { + } else if (action == DISMISS_PREDICTION) { logger.log(LAUNCHER_ITEM_DROPPED_ON_DONT_SUGGEST); } } @@ -272,7 +272,11 @@ public class SecondaryDropTarget extends ButtonDropTarget implements OnAlarmList * the action was not performed. */ protected ComponentName performDropAction(View view, ItemInfo info) { - if (mCurrentAccessibilityAction == RECONFIGURE) { + return performDropAction(view, info, mCurrentAccessibilityAction); + } + + private ComponentName performDropAction(View view, ItemInfo info, int action) { + if (action == RECONFIGURE) { int widgetId = getReconfigurableWidgetId(view); if (widgetId != INVALID_APPWIDGET_ID) { mDropTargetHandler.reconfigureWidget(widgetId, info); @@ -313,9 +317,9 @@ public class SecondaryDropTarget extends ButtonDropTarget implements OnAlarmList } @Override - public void onAccessibilityDrop(View view, ItemInfo item) { - doLog(new InstanceIdSequence().newInstanceId(), item); - performDropAction(view, item); + public void onAccessibilityDrop(View view, ItemInfo item, int action) { + doLog(new InstanceIdSequence().newInstanceId(), item, action); + performDropAction(view, item, action); } /** diff --git a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java index 643f643274..e16a296947 100644 --- a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java +++ b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java @@ -122,9 +122,12 @@ public class LauncherAccessibilityDelegate extends BaseAccessibilityDelegate