blob: a476650c99105dd73ffe5dd0eb71082cb2a418f0 [file] [log] [blame]
Sunny Goyal83a8f042015-05-19 12:52:12 -07001package com.android.launcher3.accessibility;
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08002
Sunny Goyal9ca9c132015-04-29 14:57:22 -07003import android.app.AlertDialog;
4import android.appwidget.AppWidgetProviderInfo;
5import android.content.DialogInterface;
Adam Cohenc9735cf2015-01-23 16:11:55 -08006import android.graphics.Rect;
Sunny Goyal71b5c0b2015-01-08 16:59:04 -08007import android.os.Bundle;
Sunny Goyal9ae77772015-04-29 16:30:23 -07008import android.os.Handler;
Sunny Goyal1a70cef2015-04-22 11:29:51 -07009import android.text.TextUtils;
Sunny Goyala9116722015-04-29 13:55:58 -070010import android.util.Log;
Sunny Goyal71b5c0b2015-01-08 16:59:04 -080011import android.util.SparseArray;
12import android.view.View;
13import android.view.View.AccessibilityDelegate;
14import android.view.accessibility.AccessibilityNodeInfo;
15import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
16
Sunny Goyal83a8f042015-05-19 12:52:12 -070017import com.android.launcher3.AppInfo;
18import com.android.launcher3.AppWidgetResizeFrame;
Sunny Goyal3ffa64d2016-07-25 13:54:32 -070019import com.android.launcher3.BubbleTextView;
Sunny Goyal83a8f042015-05-19 12:52:12 -070020import com.android.launcher3.CellLayout;
Tony Wickham540913e2017-01-23 11:47:51 -080021import com.android.launcher3.popup.PopupContainerWithArrow;
Sunny Goyal83a8f042015-05-19 12:52:12 -070022import com.android.launcher3.DeleteDropTarget;
Sunny Goyal94b510c2016-08-16 15:36:48 -070023import com.android.launcher3.DropTarget.DragObject;
Sunny Goyal83a8f042015-05-19 12:52:12 -070024import com.android.launcher3.FolderInfo;
25import com.android.launcher3.InfoDropTarget;
26import com.android.launcher3.ItemInfo;
27import com.android.launcher3.Launcher;
28import com.android.launcher3.LauncherAppWidgetHostView;
29import com.android.launcher3.LauncherAppWidgetInfo;
30import com.android.launcher3.LauncherModel;
31import com.android.launcher3.LauncherSettings;
32import com.android.launcher3.PendingAddItemInfo;
33import com.android.launcher3.R;
34import com.android.launcher3.ShortcutInfo;
35import com.android.launcher3.UninstallDropTarget;
36import com.android.launcher3.Workspace;
Vadim Tryshevfedca432015-08-19 17:55:02 -070037import com.android.launcher3.dragndrop.DragController.DragListener;
Sunny Goyala52ecb02016-12-16 15:04:51 -080038import com.android.launcher3.dragndrop.DragOptions;
39import com.android.launcher3.folder.Folder;
Adam Cohen091440a2015-03-18 14:16:05 -070040import com.android.launcher3.util.Thunk;
Sunny Goyal71b5c0b2015-01-08 16:59:04 -080041
42import java.util.ArrayList;
43
Sunny Goyal45478022015-06-08 16:52:41 -070044public class LauncherAccessibilityDelegate extends AccessibilityDelegate implements DragListener {
Sunny Goyal71b5c0b2015-01-08 16:59:04 -080045
Sunny Goyala9116722015-04-29 13:55:58 -070046 private static final String TAG = "LauncherAccessibilityDelegate";
47
Sunny Goyal3ffa64d2016-07-25 13:54:32 -070048 protected static final int REMOVE = R.id.action_remove;
49 protected static final int INFO = R.id.action_info;
50 protected static final int UNINSTALL = R.id.action_uninstall;
51 protected static final int ADD_TO_WORKSPACE = R.id.action_add_to_workspace;
52 protected static final int MOVE = R.id.action_move;
53 protected static final int MOVE_TO_WORKSPACE = R.id.action_move_to_workspace;
54 protected static final int RESIZE = R.id.action_resize;
Sunny Goyal66b24572016-09-21 15:57:55 -070055 public static final int DEEP_SHORTCUTS = R.id.action_deep_shortcuts;
Adam Cohenc9735cf2015-01-23 16:11:55 -080056
Sunny Goyale9b651e2015-04-24 11:44:51 -070057 public enum DragType {
Adam Cohenc9735cf2015-01-23 16:11:55 -080058 ICON,
59 FOLDER,
60 WIDGET
61 }
62
63 public static class DragInfo {
Sunny Goyale9b651e2015-04-24 11:44:51 -070064 public DragType dragType;
65 public ItemInfo info;
66 public View item;
Adam Cohenc9735cf2015-01-23 16:11:55 -080067 }
68
Sunny Goyal3ffa64d2016-07-25 13:54:32 -070069 protected final SparseArray<AccessibilityAction> mActions = new SparseArray<>();
Adam Cohen091440a2015-03-18 14:16:05 -070070 @Thunk final Launcher mLauncher;
Sunny Goyal71b5c0b2015-01-08 16:59:04 -080071
Sunny Goyale9b651e2015-04-24 11:44:51 -070072 private DragInfo mDragInfo = null;
Sunny Goyale9b651e2015-04-24 11:44:51 -070073
Sunny Goyal71b5c0b2015-01-08 16:59:04 -080074 public LauncherAccessibilityDelegate(Launcher launcher) {
75 mLauncher = launcher;
76
77 mActions.put(REMOVE, new AccessibilityAction(REMOVE,
Tony Wickham9aae47f2015-10-01 13:04:22 -070078 launcher.getText(R.string.remove_drop_target_label)));
Sunny Goyal71b5c0b2015-01-08 16:59:04 -080079 mActions.put(INFO, new AccessibilityAction(INFO,
Tony Wickham9aae47f2015-10-01 13:04:22 -070080 launcher.getText(R.string.app_info_drop_target_label)));
Sunny Goyal71b5c0b2015-01-08 16:59:04 -080081 mActions.put(UNINSTALL, new AccessibilityAction(UNINSTALL,
Tony Wickham9aae47f2015-10-01 13:04:22 -070082 launcher.getText(R.string.uninstall_drop_target_label)));
Sunny Goyal71b5c0b2015-01-08 16:59:04 -080083 mActions.put(ADD_TO_WORKSPACE, new AccessibilityAction(ADD_TO_WORKSPACE,
84 launcher.getText(R.string.action_add_to_workspace)));
Adam Cohenc9735cf2015-01-23 16:11:55 -080085 mActions.put(MOVE, new AccessibilityAction(MOVE,
86 launcher.getText(R.string.action_move)));
Sunny Goyal9ae77772015-04-29 16:30:23 -070087 mActions.put(MOVE_TO_WORKSPACE, new AccessibilityAction(MOVE_TO_WORKSPACE,
88 launcher.getText(R.string.action_move_to_workspace)));
Sunny Goyal9ca9c132015-04-29 14:57:22 -070089 mActions.put(RESIZE, new AccessibilityAction(RESIZE,
90 launcher.getText(R.string.action_resize)));
Sunny Goyal3ffa64d2016-07-25 13:54:32 -070091 mActions.put(DEEP_SHORTCUTS, new AccessibilityAction(DEEP_SHORTCUTS,
92 launcher.getText(R.string.action_deep_shortcut)));
Sunny Goyal71b5c0b2015-01-08 16:59:04 -080093 }
94
95 @Override
96 public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) {
97 super.onInitializeAccessibilityNodeInfo(host, info);
Sunny Goyal66b24572016-09-21 15:57:55 -070098 addSupportedActions(host, info, false);
Sunny Goyal3ffa64d2016-07-25 13:54:32 -070099 }
100
Sunny Goyal66b24572016-09-21 15:57:55 -0700101 public void addSupportedActions(View host, AccessibilityNodeInfo info, boolean fromKeyboard) {
Sunny Goyal71b5c0b2015-01-08 16:59:04 -0800102 if (!(host.getTag() instanceof ItemInfo)) return;
103 ItemInfo item = (ItemInfo) host.getTag();
104
Sunny Goyal66b24572016-09-21 15:57:55 -0700105 // If the request came from keyboard, do not add custom shortcuts as that is already
106 // exposed as a direct shortcut
107 if (!fromKeyboard && host instanceof BubbleTextView
108 && ((BubbleTextView) host).hasDeepShortcuts()) {
Sunny Goyal3ffa64d2016-07-25 13:54:32 -0700109 info.addAction(mActions.get(DEEP_SHORTCUTS));
110 }
111
Tony Wickham9aae47f2015-10-01 13:04:22 -0700112 if (DeleteDropTarget.supportsAccessibleDrop(item)) {
Sunny Goyal1a70cef2015-04-22 11:29:51 -0700113 info.addAction(mActions.get(REMOVE));
114 }
115 if (UninstallDropTarget.supportsDrop(host.getContext(), item)) {
116 info.addAction(mActions.get(UNINSTALL));
117 }
Sunny Goyal8ad02b82016-12-29 13:31:43 -0800118 if (InfoDropTarget.supportsDrop(host.getContext(), item)) {
Sunny Goyal1a70cef2015-04-22 11:29:51 -0700119 info.addAction(mActions.get(INFO));
120 }
121
Sunny Goyal66b24572016-09-21 15:57:55 -0700122 // Do not add move actions for keyboard request as this uses virtual nodes.
123 if (!fromKeyboard && ((item instanceof ShortcutInfo)
Sunny Goyal71b5c0b2015-01-08 16:59:04 -0800124 || (item instanceof LauncherAppWidgetInfo)
Sunny Goyal66b24572016-09-21 15:57:55 -0700125 || (item instanceof FolderInfo))) {
Adam Cohenc9735cf2015-01-23 16:11:55 -0800126 info.addAction(mActions.get(MOVE));
Sunny Goyal9ae77772015-04-29 16:30:23 -0700127
128 if (item.container >= 0) {
129 info.addAction(mActions.get(MOVE_TO_WORKSPACE));
Sunny Goyal9ca9c132015-04-29 14:57:22 -0700130 } else if (item instanceof LauncherAppWidgetInfo) {
131 if (!getSupportedResizeActions(host, (LauncherAppWidgetInfo) item).isEmpty()) {
132 info.addAction(mActions.get(RESIZE));
133 }
Sunny Goyal9ae77772015-04-29 16:30:23 -0700134 }
Adam Cohen6e92f052016-06-07 14:30:10 -0700135 }
136
137 if ((item instanceof AppInfo) || (item instanceof PendingAddItemInfo)) {
Sunny Goyal71b5c0b2015-01-08 16:59:04 -0800138 info.addAction(mActions.get(ADD_TO_WORKSPACE));
139 }
140 }
141
142 @Override
143 public boolean performAccessibilityAction(View host, int action, Bundle args) {
144 if ((host.getTag() instanceof ItemInfo)
145 && performAction(host, (ItemInfo) host.getTag(), action)) {
146 return true;
147 }
148 return super.performAccessibilityAction(host, action, args);
149 }
150
Sunny Goyal9ca9c132015-04-29 14:57:22 -0700151 public boolean performAction(final View host, final ItemInfo item, int action) {
Sunny Goyal71b5c0b2015-01-08 16:59:04 -0800152 if (action == REMOVE) {
Sunny Goyale78e3d72015-09-24 11:23:31 -0700153 DeleteDropTarget.removeWorkspaceOrFolderItem(mLauncher, item, host);
154 return true;
Sunny Goyal71b5c0b2015-01-08 16:59:04 -0800155 } else if (action == INFO) {
Sunny Goyald5bd67d2016-03-11 01:10:19 -0800156 InfoDropTarget.startDetailsActivityForInfo(item, mLauncher, null);
Sunny Goyal71b5c0b2015-01-08 16:59:04 -0800157 return true;
158 } else if (action == UNINSTALL) {
Sunny Goyal1a70cef2015-04-22 11:29:51 -0700159 return UninstallDropTarget.startUninstallActivity(mLauncher, item);
Adam Cohenc9735cf2015-01-23 16:11:55 -0800160 } else if (action == MOVE) {
161 beginAccessibleDrag(host, item);
Sunny Goyal71b5c0b2015-01-08 16:59:04 -0800162 } else if (action == ADD_TO_WORKSPACE) {
Sunny Goyala9116722015-04-29 13:55:58 -0700163 final int[] coordinates = new int[2];
164 final long screenId = findSpaceOnWorkspace(item, coordinates);
165 mLauncher.showWorkspace(true, new Runnable() {
Sunny Goyal71b5c0b2015-01-08 16:59:04 -0800166
167 @Override
Sunny Goyala9116722015-04-29 13:55:58 -0700168 public void run() {
169 if (item instanceof AppInfo) {
170 ShortcutInfo info = ((AppInfo) item).makeShortcut();
Sunny Goyal43bf11d2017-02-02 13:52:53 -0800171 mLauncher.getModelWriter().addItemToDatabase(info,
Sunny Goyala9116722015-04-29 13:55:58 -0700172 LauncherSettings.Favorites.CONTAINER_DESKTOP,
173 screenId, coordinates[0], coordinates[1]);
174
175 ArrayList<ItemInfo> itemList = new ArrayList<>();
176 itemList.add(info);
177 mLauncher.bindItems(itemList, 0, itemList.size(), true);
178 } else if (item instanceof PendingAddItemInfo) {
179 PendingAddItemInfo info = (PendingAddItemInfo) item;
180 Workspace workspace = mLauncher.getWorkspace();
181 workspace.snapToPage(workspace.getPageIndexForScreenId(screenId));
182 mLauncher.addPendingItem(info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
183 screenId, coordinates, info.spanX, info.spanY);
Sunny Goyal71b5c0b2015-01-08 16:59:04 -0800184 }
Sunny Goyala9116722015-04-29 13:55:58 -0700185 announceConfirmation(R.string.item_added_to_workspace);
186 }
187 });
188 return true;
Sunny Goyal9ae77772015-04-29 16:30:23 -0700189 } else if (action == MOVE_TO_WORKSPACE) {
Sunny Goyal740ac7f2016-09-28 16:47:32 -0700190 Folder folder = Folder.getOpen(mLauncher);
191 folder.close(true);
Sunny Goyal9ae77772015-04-29 16:30:23 -0700192 ShortcutInfo info = (ShortcutInfo) item;
Sunny Goyalc52ba712016-04-05 15:59:05 -0700193 folder.getInfo().remove(info, false);
Sunny Goyal9ae77772015-04-29 16:30:23 -0700194
195 final int[] coordinates = new int[2];
196 final long screenId = findSpaceOnWorkspace(item, coordinates);
Sunny Goyal43bf11d2017-02-02 13:52:53 -0800197 mLauncher.getModelWriter().moveItemInDatabase(info,
Sunny Goyal9ae77772015-04-29 16:30:23 -0700198 LauncherSettings.Favorites.CONTAINER_DESKTOP,
199 screenId, coordinates[0], coordinates[1]);
200
201 // Bind the item in next frame so that if a new workspace page was created,
202 // it will get laid out.
203 new Handler().post(new Runnable() {
204
205 @Override
206 public void run() {
207 ArrayList<ItemInfo> itemList = new ArrayList<>();
208 itemList.add(item);
209 mLauncher.bindItems(itemList, 0, itemList.size(), true);
210 announceConfirmation(R.string.item_moved);
211 }
212 });
Sunny Goyal9ca9c132015-04-29 14:57:22 -0700213 } else if (action == RESIZE) {
214 final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) item;
215 final ArrayList<Integer> actions = getSupportedResizeActions(host, info);
216 CharSequence[] labels = new CharSequence[actions.size()];
217 for (int i = 0; i < actions.size(); i++) {
218 labels[i] = mLauncher.getText(actions.get(i));
219 }
220
221 new AlertDialog.Builder(mLauncher)
222 .setTitle(R.string.action_resize)
223 .setItems(labels, new DialogInterface.OnClickListener() {
224
225 @Override
226 public void onClick(DialogInterface dialog, int which) {
227 performResizeAction(actions.get(which), host, info);
228 dialog.dismiss();
229 }
230 })
231 .show();
Sunny Goyal3ffa64d2016-07-25 13:54:32 -0700232 return true;
233 } else if (action == DEEP_SHORTCUTS) {
Tony Wickham540913e2017-01-23 11:47:51 -0800234 return PopupContainerWithArrow.showForIcon((BubbleTextView) host) != null;
Sunny Goyal71b5c0b2015-01-08 16:59:04 -0800235 }
236 return false;
237 }
Adam Cohenc9735cf2015-01-23 16:11:55 -0800238
Sunny Goyal9ca9c132015-04-29 14:57:22 -0700239 private ArrayList<Integer> getSupportedResizeActions(View host, LauncherAppWidgetInfo info) {
Sunny Goyal9ca9c132015-04-29 14:57:22 -0700240 ArrayList<Integer> actions = new ArrayList<>();
241
Sunny Goyald3d8c952015-06-01 10:09:06 -0700242 AppWidgetProviderInfo providerInfo = ((LauncherAppWidgetHostView) host).getAppWidgetInfo();
243 if (providerInfo == null) {
244 return actions;
245 }
246
Sunny Goyal9ca9c132015-04-29 14:57:22 -0700247 CellLayout layout = (CellLayout) host.getParent().getParent();
248 if ((providerInfo.resizeMode & AppWidgetProviderInfo.RESIZE_HORIZONTAL) != 0) {
249 if (layout.isRegionVacant(info.cellX + info.spanX, info.cellY, 1, info.spanY) ||
250 layout.isRegionVacant(info.cellX - 1, info.cellY, 1, info.spanY)) {
251 actions.add(R.string.action_increase_width);
252 }
253
254 if (info.spanX > info.minSpanX && info.spanX > 1) {
255 actions.add(R.string.action_decrease_width);
256 }
257 }
258
259 if ((providerInfo.resizeMode & AppWidgetProviderInfo.RESIZE_VERTICAL) != 0) {
260 if (layout.isRegionVacant(info.cellX, info.cellY + info.spanY, info.spanX, 1) ||
261 layout.isRegionVacant(info.cellX, info.cellY - 1, info.spanX, 1)) {
262 actions.add(R.string.action_increase_height);
263 }
264
265 if (info.spanY > info.minSpanY && info.spanY > 1) {
266 actions.add(R.string.action_decrease_height);
267 }
268 }
269 return actions;
270 }
271
Sunny Goyal316490e2015-06-02 09:38:28 -0700272 @Thunk void performResizeAction(int action, View host, LauncherAppWidgetInfo info) {
Sunny Goyal9ca9c132015-04-29 14:57:22 -0700273 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) host.getLayoutParams();
274 CellLayout layout = (CellLayout) host.getParent().getParent();
275 layout.markCellsAsUnoccupiedForView(host);
276
277 if (action == R.string.action_increase_width) {
278 if (((host.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL)
279 && layout.isRegionVacant(info.cellX - 1, info.cellY, 1, info.spanY))
280 || !layout.isRegionVacant(info.cellX + info.spanX, info.cellY, 1, info.spanY)) {
281 lp.cellX --;
282 info.cellX --;
283 }
284 lp.cellHSpan ++;
285 info.spanX ++;
286 } else if (action == R.string.action_decrease_width) {
287 lp.cellHSpan --;
288 info.spanX --;
289 } else if (action == R.string.action_increase_height) {
290 if (!layout.isRegionVacant(info.cellX, info.cellY + info.spanY, info.spanX, 1)) {
291 lp.cellY --;
292 info.cellY --;
293 }
294 lp.cellVSpan ++;
295 info.spanY ++;
296 } else if (action == R.string.action_decrease_height) {
297 lp.cellVSpan --;
298 info.spanY --;
299 }
300
301 layout.markCellsAsOccupiedForView(host);
302 Rect sizeRange = new Rect();
303 AppWidgetResizeFrame.getWidgetSizeRanges(mLauncher, info.spanX, info.spanY, sizeRange);
304 ((LauncherAppWidgetHostView) host).updateAppWidgetSize(null,
305 sizeRange.left, sizeRange.top, sizeRange.right, sizeRange.bottom);
306 host.requestLayout();
Sunny Goyal43bf11d2017-02-02 13:52:53 -0800307 mLauncher.getModelWriter().updateItemInDatabase(info);
Sunny Goyal9ca9c132015-04-29 14:57:22 -0700308 announceConfirmation(mLauncher.getString(R.string.widget_resized, info.spanX, info.spanY));
309 }
310
Adam Cohen091440a2015-03-18 14:16:05 -0700311 @Thunk void announceConfirmation(int resId) {
Adam Cohenc9735cf2015-01-23 16:11:55 -0800312 announceConfirmation(mLauncher.getResources().getString(resId));
313 }
314
Adam Cohen091440a2015-03-18 14:16:05 -0700315 @Thunk void announceConfirmation(String confirmation) {
Adam Cohenc9735cf2015-01-23 16:11:55 -0800316 mLauncher.getDragLayer().announceForAccessibility(confirmation);
317
318 }
319
320 public boolean isInAccessibleDrag() {
321 return mDragInfo != null;
322 }
323
324 public DragInfo getDragInfo() {
325 return mDragInfo;
326 }
327
Sunny Goyal1a70cef2015-04-22 11:29:51 -0700328 /**
329 * @param clickedTarget the actual view that was clicked
330 * @param dropLocation relative to {@param clickedTarget}. If provided, its center is used
331 * as the actual drop location otherwise the views center is used.
332 */
333 public void handleAccessibleDrop(View clickedTarget, Rect dropLocation,
Adam Cohenc9735cf2015-01-23 16:11:55 -0800334 String confirmation) {
335 if (!isInAccessibleDrag()) return;
336
337 int[] loc = new int[2];
Sunny Goyal1a70cef2015-04-22 11:29:51 -0700338 if (dropLocation == null) {
339 loc[0] = clickedTarget.getWidth() / 2;
340 loc[1] = clickedTarget.getHeight() / 2;
341 } else {
342 loc[0] = dropLocation.centerX();
343 loc[1] = dropLocation.centerY();
344 }
Adam Cohenc9735cf2015-01-23 16:11:55 -0800345
Sunny Goyal1a70cef2015-04-22 11:29:51 -0700346 mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(clickedTarget, loc);
Adam Cohenc9735cf2015-01-23 16:11:55 -0800347 mLauncher.getDragController().completeAccessibleDrag(loc);
348
Sunny Goyal1a70cef2015-04-22 11:29:51 -0700349 if (!TextUtils.isEmpty(confirmation)) {
350 announceConfirmation(confirmation);
351 }
Adam Cohenc9735cf2015-01-23 16:11:55 -0800352 }
353
354 public void beginAccessibleDrag(View item, ItemInfo info) {
355 mDragInfo = new DragInfo();
356 mDragInfo.info = info;
357 mDragInfo.item = item;
358 mDragInfo.dragType = DragType.ICON;
359 if (info instanceof FolderInfo) {
360 mDragInfo.dragType = DragType.FOLDER;
361 } else if (info instanceof LauncherAppWidgetInfo) {
362 mDragInfo.dragType = DragType.WIDGET;
363 }
364
365 CellLayout.CellInfo cellInfo = new CellLayout.CellInfo(item, info);
366
367 Rect pos = new Rect();
368 mLauncher.getDragLayer().getDescendantRectRelativeToSelf(item, pos);
Adam Cohenc9735cf2015-01-23 16:11:55 -0800369 mLauncher.getDragController().prepareAccessibleDrag(pos.centerX(), pos.centerY());
Sunny Goyale9b651e2015-04-24 11:44:51 -0700370
Sunny Goyal740ac7f2016-09-28 16:47:32 -0700371 Folder folder = Folder.getOpen(mLauncher);
Sunny Goyale9b651e2015-04-24 11:44:51 -0700372 if (folder != null) {
Sunny Goyal94b510c2016-08-16 15:36:48 -0700373 if (!folder.getItemsInReadingOrder().contains(item)) {
Sunny Goyal740ac7f2016-09-28 16:47:32 -0700374 folder.close(true);
Sunny Goyal94b510c2016-08-16 15:36:48 -0700375 folder = null;
Sunny Goyale9b651e2015-04-24 11:44:51 -0700376 }
377 }
Adam Cohenc9735cf2015-01-23 16:11:55 -0800378
Sunny Goyal94b510c2016-08-16 15:36:48 -0700379 mLauncher.getDragController().addDragListener(this);
380
381 DragOptions options = new DragOptions();
382 options.isAccessibleDrag = true;
383 if (folder != null) {
384 folder.startDrag(cellInfo.cell, options);
385 } else {
Sunny Goyal740ac7f2016-09-28 16:47:32 -0700386 mLauncher.getWorkspace().startDrag(cellInfo, options);
Adam Cohenc9735cf2015-01-23 16:11:55 -0800387 }
Adam Cohenc9735cf2015-01-23 16:11:55 -0800388 }
389
Sunny Goyal45478022015-06-08 16:52:41 -0700390 @Override
Sunny Goyal94b510c2016-08-16 15:36:48 -0700391 public void onDragStart(DragObject dragObject, DragOptions options) {
Sunny Goyal45478022015-06-08 16:52:41 -0700392 // No-op
Adam Cohenc9735cf2015-01-23 16:11:55 -0800393 }
394
Sunny Goyal45478022015-06-08 16:52:41 -0700395 @Override
396 public void onDragEnd() {
397 mLauncher.getDragController().removeDragListener(this);
Adam Cohenc9735cf2015-01-23 16:11:55 -0800398 mDragInfo = null;
Adam Cohenc9735cf2015-01-23 16:11:55 -0800399 }
Sunny Goyala9116722015-04-29 13:55:58 -0700400
401 /**
402 * Find empty space on the workspace and returns the screenId.
403 */
Sunny Goyal3ffa64d2016-07-25 13:54:32 -0700404 protected long findSpaceOnWorkspace(ItemInfo info, int[] outCoordinates) {
Sunny Goyala9116722015-04-29 13:55:58 -0700405 Workspace workspace = mLauncher.getWorkspace();
406 ArrayList<Long> workspaceScreens = workspace.getScreenOrder();
407 long screenId;
408
409 // First check if there is space on the current screen.
410 int screenIndex = workspace.getCurrentPage();
411 screenId = workspaceScreens.get(screenIndex);
412 CellLayout layout = (CellLayout) workspace.getPageAt(screenIndex);
413
414 boolean found = layout.findCellForSpan(outCoordinates, info.spanX, info.spanY);
415 screenIndex = workspace.hasCustomContent() ? 1 : 0;
416 while (!found && screenIndex < workspaceScreens.size()) {
417 screenId = workspaceScreens.get(screenIndex);
418 layout = (CellLayout) workspace.getPageAt(screenIndex);
419 found = layout.findCellForSpan(outCoordinates, info.spanX, info.spanY);
420 screenIndex++;
421 }
422
423 if (found) {
424 return screenId;
425 }
426
427 workspace.addExtraEmptyScreen();
428 screenId = workspace.commitExtraEmptyScreen();
429 layout = workspace.getScreenWithId(screenId);
430 found = layout.findCellForSpan(outCoordinates, info.spanX, info.spanY);
431
432 if (!found) {
433 Log.wtf(TAG, "Not enough space on an empty screen");
434 }
435 return screenId;
436 }
Sunny Goyal71b5c0b2015-01-08 16:59:04 -0800437}