blob: e8127c45fd522b453d220a1e0b868aaef2c0a64b [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;
21import com.android.launcher3.DeleteDropTarget;
Sunny Goyal94b510c2016-08-16 15:36:48 -070022import com.android.launcher3.DropTarget.DragObject;
Sunny Goyal83a8f042015-05-19 12:52:12 -070023import com.android.launcher3.FolderInfo;
24import com.android.launcher3.InfoDropTarget;
25import com.android.launcher3.ItemInfo;
26import com.android.launcher3.Launcher;
27import com.android.launcher3.LauncherAppWidgetHostView;
28import com.android.launcher3.LauncherAppWidgetInfo;
Sunny Goyal83a8f042015-05-19 12:52:12 -070029import com.android.launcher3.LauncherSettings;
30import com.android.launcher3.PendingAddItemInfo;
31import com.android.launcher3.R;
32import com.android.launcher3.ShortcutInfo;
33import com.android.launcher3.UninstallDropTarget;
34import com.android.launcher3.Workspace;
Vadim Tryshevfedca432015-08-19 17:55:02 -070035import com.android.launcher3.dragndrop.DragController.DragListener;
Sunny Goyala52ecb02016-12-16 15:04:51 -080036import com.android.launcher3.dragndrop.DragOptions;
37import com.android.launcher3.folder.Folder;
Mario Bertschlerc06af332017-03-28 12:23:22 -070038import com.android.launcher3.popup.PopupContainerWithArrow;
Adam Cohen091440a2015-03-18 14:16:05 -070039import com.android.launcher3.util.Thunk;
Sunny Goyal71b5c0b2015-01-08 16:59:04 -080040
41import java.util.ArrayList;
42
Sunny Goyal45478022015-06-08 16:52:41 -070043public class LauncherAccessibilityDelegate extends AccessibilityDelegate implements DragListener {
Sunny Goyal71b5c0b2015-01-08 16:59:04 -080044
Sunny Goyala9116722015-04-29 13:55:58 -070045 private static final String TAG = "LauncherAccessibilityDelegate";
46
Sunny Goyal3ffa64d2016-07-25 13:54:32 -070047 protected static final int REMOVE = R.id.action_remove;
48 protected static final int INFO = R.id.action_info;
49 protected static final int UNINSTALL = R.id.action_uninstall;
50 protected static final int ADD_TO_WORKSPACE = R.id.action_add_to_workspace;
51 protected static final int MOVE = R.id.action_move;
52 protected static final int MOVE_TO_WORKSPACE = R.id.action_move_to_workspace;
53 protected static final int RESIZE = R.id.action_resize;
Sunny Goyal66b24572016-09-21 15:57:55 -070054 public static final int DEEP_SHORTCUTS = R.id.action_deep_shortcuts;
Adam Cohenc9735cf2015-01-23 16:11:55 -080055
Sunny Goyale9b651e2015-04-24 11:44:51 -070056 public enum DragType {
Adam Cohenc9735cf2015-01-23 16:11:55 -080057 ICON,
58 FOLDER,
59 WIDGET
60 }
61
62 public static class DragInfo {
Sunny Goyale9b651e2015-04-24 11:44:51 -070063 public DragType dragType;
64 public ItemInfo info;
65 public View item;
Adam Cohenc9735cf2015-01-23 16:11:55 -080066 }
67
Sunny Goyal3ffa64d2016-07-25 13:54:32 -070068 protected final SparseArray<AccessibilityAction> mActions = new SparseArray<>();
Adam Cohen091440a2015-03-18 14:16:05 -070069 @Thunk final Launcher mLauncher;
Sunny Goyal71b5c0b2015-01-08 16:59:04 -080070
Sunny Goyale9b651e2015-04-24 11:44:51 -070071 private DragInfo mDragInfo = null;
Sunny Goyale9b651e2015-04-24 11:44:51 -070072
Sunny Goyal71b5c0b2015-01-08 16:59:04 -080073 public LauncherAccessibilityDelegate(Launcher launcher) {
74 mLauncher = launcher;
75
76 mActions.put(REMOVE, new AccessibilityAction(REMOVE,
Tony Wickham9aae47f2015-10-01 13:04:22 -070077 launcher.getText(R.string.remove_drop_target_label)));
Sunny Goyal71b5c0b2015-01-08 16:59:04 -080078 mActions.put(INFO, new AccessibilityAction(INFO,
Tony Wickham9aae47f2015-10-01 13:04:22 -070079 launcher.getText(R.string.app_info_drop_target_label)));
Sunny Goyal71b5c0b2015-01-08 16:59:04 -080080 mActions.put(UNINSTALL, new AccessibilityAction(UNINSTALL,
Tony Wickham9aae47f2015-10-01 13:04:22 -070081 launcher.getText(R.string.uninstall_drop_target_label)));
Sunny Goyal71b5c0b2015-01-08 16:59:04 -080082 mActions.put(ADD_TO_WORKSPACE, new AccessibilityAction(ADD_TO_WORKSPACE,
83 launcher.getText(R.string.action_add_to_workspace)));
Adam Cohenc9735cf2015-01-23 16:11:55 -080084 mActions.put(MOVE, new AccessibilityAction(MOVE,
85 launcher.getText(R.string.action_move)));
Sunny Goyal9ae77772015-04-29 16:30:23 -070086 mActions.put(MOVE_TO_WORKSPACE, new AccessibilityAction(MOVE_TO_WORKSPACE,
87 launcher.getText(R.string.action_move_to_workspace)));
Sunny Goyal9ca9c132015-04-29 14:57:22 -070088 mActions.put(RESIZE, new AccessibilityAction(RESIZE,
89 launcher.getText(R.string.action_resize)));
Sunny Goyal3ffa64d2016-07-25 13:54:32 -070090 mActions.put(DEEP_SHORTCUTS, new AccessibilityAction(DEEP_SHORTCUTS,
91 launcher.getText(R.string.action_deep_shortcut)));
Sunny Goyal71b5c0b2015-01-08 16:59:04 -080092 }
93
94 @Override
95 public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) {
96 super.onInitializeAccessibilityNodeInfo(host, info);
Sunny Goyal66b24572016-09-21 15:57:55 -070097 addSupportedActions(host, info, false);
Sunny Goyal3ffa64d2016-07-25 13:54:32 -070098 }
99
Sunny Goyal66b24572016-09-21 15:57:55 -0700100 public void addSupportedActions(View host, AccessibilityNodeInfo info, boolean fromKeyboard) {
Sunny Goyal71b5c0b2015-01-08 16:59:04 -0800101 if (!(host.getTag() instanceof ItemInfo)) return;
102 ItemInfo item = (ItemInfo) host.getTag();
103
Sunny Goyal66b24572016-09-21 15:57:55 -0700104 // If the request came from keyboard, do not add custom shortcuts as that is already
105 // exposed as a direct shortcut
106 if (!fromKeyboard && host instanceof BubbleTextView
107 && ((BubbleTextView) host).hasDeepShortcuts()) {
Sunny Goyal3ffa64d2016-07-25 13:54:32 -0700108 info.addAction(mActions.get(DEEP_SHORTCUTS));
109 }
110
Tony Wickham9aae47f2015-10-01 13:04:22 -0700111 if (DeleteDropTarget.supportsAccessibleDrop(item)) {
Sunny Goyal1a70cef2015-04-22 11:29:51 -0700112 info.addAction(mActions.get(REMOVE));
113 }
114 if (UninstallDropTarget.supportsDrop(host.getContext(), item)) {
115 info.addAction(mActions.get(UNINSTALL));
116 }
Sunny Goyal8ad02b82016-12-29 13:31:43 -0800117 if (InfoDropTarget.supportsDrop(host.getContext(), item)) {
Sunny Goyal1a70cef2015-04-22 11:29:51 -0700118 info.addAction(mActions.get(INFO));
119 }
120
Sunny Goyal66b24572016-09-21 15:57:55 -0700121 // Do not add move actions for keyboard request as this uses virtual nodes.
122 if (!fromKeyboard && ((item instanceof ShortcutInfo)
Sunny Goyal71b5c0b2015-01-08 16:59:04 -0800123 || (item instanceof LauncherAppWidgetInfo)
Sunny Goyal66b24572016-09-21 15:57:55 -0700124 || (item instanceof FolderInfo))) {
Adam Cohenc9735cf2015-01-23 16:11:55 -0800125 info.addAction(mActions.get(MOVE));
Sunny Goyal9ae77772015-04-29 16:30:23 -0700126
127 if (item.container >= 0) {
128 info.addAction(mActions.get(MOVE_TO_WORKSPACE));
Sunny Goyal9ca9c132015-04-29 14:57:22 -0700129 } else if (item instanceof LauncherAppWidgetInfo) {
130 if (!getSupportedResizeActions(host, (LauncherAppWidgetInfo) item).isEmpty()) {
131 info.addAction(mActions.get(RESIZE));
132 }
Sunny Goyal9ae77772015-04-29 16:30:23 -0700133 }
Adam Cohen6e92f052016-06-07 14:30:10 -0700134 }
135
136 if ((item instanceof AppInfo) || (item instanceof PendingAddItemInfo)) {
Sunny Goyal71b5c0b2015-01-08 16:59:04 -0800137 info.addAction(mActions.get(ADD_TO_WORKSPACE));
138 }
139 }
140
141 @Override
142 public boolean performAccessibilityAction(View host, int action, Bundle args) {
143 if ((host.getTag() instanceof ItemInfo)
144 && performAction(host, (ItemInfo) host.getTag(), action)) {
145 return true;
146 }
147 return super.performAccessibilityAction(host, action, args);
148 }
149
Sunny Goyal9ca9c132015-04-29 14:57:22 -0700150 public boolean performAction(final View host, final ItemInfo item, int action) {
Sunny Goyal71b5c0b2015-01-08 16:59:04 -0800151 if (action == REMOVE) {
Sunny Goyale78e3d72015-09-24 11:23:31 -0700152 DeleteDropTarget.removeWorkspaceOrFolderItem(mLauncher, item, host);
153 return true;
Sunny Goyal71b5c0b2015-01-08 16:59:04 -0800154 } else if (action == INFO) {
Sunny Goyald5bd67d2016-03-11 01:10:19 -0800155 InfoDropTarget.startDetailsActivityForInfo(item, mLauncher, null);
Sunny Goyal71b5c0b2015-01-08 16:59:04 -0800156 return true;
157 } else if (action == UNINSTALL) {
Sunny Goyal1a70cef2015-04-22 11:29:51 -0700158 return UninstallDropTarget.startUninstallActivity(mLauncher, item);
Adam Cohenc9735cf2015-01-23 16:11:55 -0800159 } else if (action == MOVE) {
160 beginAccessibleDrag(host, item);
Sunny Goyal71b5c0b2015-01-08 16:59:04 -0800161 } else if (action == ADD_TO_WORKSPACE) {
Sunny Goyala9116722015-04-29 13:55:58 -0700162 final int[] coordinates = new int[2];
163 final long screenId = findSpaceOnWorkspace(item, coordinates);
164 mLauncher.showWorkspace(true, new Runnable() {
Sunny Goyal71b5c0b2015-01-08 16:59:04 -0800165
166 @Override
Sunny Goyala9116722015-04-29 13:55:58 -0700167 public void run() {
168 if (item instanceof AppInfo) {
169 ShortcutInfo info = ((AppInfo) item).makeShortcut();
Sunny Goyal43bf11d2017-02-02 13:52:53 -0800170 mLauncher.getModelWriter().addItemToDatabase(info,
Sunny Goyala9116722015-04-29 13:55:58 -0700171 LauncherSettings.Favorites.CONTAINER_DESKTOP,
172 screenId, coordinates[0], coordinates[1]);
173
174 ArrayList<ItemInfo> itemList = new ArrayList<>();
175 itemList.add(info);
176 mLauncher.bindItems(itemList, 0, itemList.size(), true);
177 } else if (item instanceof PendingAddItemInfo) {
178 PendingAddItemInfo info = (PendingAddItemInfo) item;
179 Workspace workspace = mLauncher.getWorkspace();
180 workspace.snapToPage(workspace.getPageIndexForScreenId(screenId));
181 mLauncher.addPendingItem(info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
182 screenId, coordinates, info.spanX, info.spanY);
Sunny Goyal71b5c0b2015-01-08 16:59:04 -0800183 }
Sunny Goyala9116722015-04-29 13:55:58 -0700184 announceConfirmation(R.string.item_added_to_workspace);
185 }
186 });
187 return true;
Sunny Goyal9ae77772015-04-29 16:30:23 -0700188 } else if (action == MOVE_TO_WORKSPACE) {
Sunny Goyal740ac7f2016-09-28 16:47:32 -0700189 Folder folder = Folder.getOpen(mLauncher);
190 folder.close(true);
Sunny Goyal9ae77772015-04-29 16:30:23 -0700191 ShortcutInfo info = (ShortcutInfo) item;
Sunny Goyalc52ba712016-04-05 15:59:05 -0700192 folder.getInfo().remove(info, false);
Sunny Goyal9ae77772015-04-29 16:30:23 -0700193
194 final int[] coordinates = new int[2];
195 final long screenId = findSpaceOnWorkspace(item, coordinates);
Sunny Goyal43bf11d2017-02-02 13:52:53 -0800196 mLauncher.getModelWriter().moveItemInDatabase(info,
Sunny Goyal9ae77772015-04-29 16:30:23 -0700197 LauncherSettings.Favorites.CONTAINER_DESKTOP,
198 screenId, coordinates[0], coordinates[1]);
199
200 // Bind the item in next frame so that if a new workspace page was created,
201 // it will get laid out.
202 new Handler().post(new Runnable() {
203
204 @Override
205 public void run() {
206 ArrayList<ItemInfo> itemList = new ArrayList<>();
207 itemList.add(item);
208 mLauncher.bindItems(itemList, 0, itemList.size(), true);
209 announceConfirmation(R.string.item_moved);
210 }
211 });
Sunny Goyal9ca9c132015-04-29 14:57:22 -0700212 } else if (action == RESIZE) {
213 final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) item;
214 final ArrayList<Integer> actions = getSupportedResizeActions(host, info);
215 CharSequence[] labels = new CharSequence[actions.size()];
216 for (int i = 0; i < actions.size(); i++) {
217 labels[i] = mLauncher.getText(actions.get(i));
218 }
219
220 new AlertDialog.Builder(mLauncher)
221 .setTitle(R.string.action_resize)
222 .setItems(labels, new DialogInterface.OnClickListener() {
223
224 @Override
225 public void onClick(DialogInterface dialog, int which) {
226 performResizeAction(actions.get(which), host, info);
227 dialog.dismiss();
228 }
229 })
230 .show();
Sunny Goyal3ffa64d2016-07-25 13:54:32 -0700231 return true;
232 } else if (action == DEEP_SHORTCUTS) {
Tony Wickham540913e2017-01-23 11:47:51 -0800233 return PopupContainerWithArrow.showForIcon((BubbleTextView) host) != null;
Sunny Goyal71b5c0b2015-01-08 16:59:04 -0800234 }
235 return false;
236 }
Adam Cohenc9735cf2015-01-23 16:11:55 -0800237
Sunny Goyal9ca9c132015-04-29 14:57:22 -0700238 private ArrayList<Integer> getSupportedResizeActions(View host, LauncherAppWidgetInfo info) {
Sunny Goyal9ca9c132015-04-29 14:57:22 -0700239 ArrayList<Integer> actions = new ArrayList<>();
240
Sunny Goyald3d8c952015-06-01 10:09:06 -0700241 AppWidgetProviderInfo providerInfo = ((LauncherAppWidgetHostView) host).getAppWidgetInfo();
242 if (providerInfo == null) {
243 return actions;
244 }
245
Sunny Goyal9ca9c132015-04-29 14:57:22 -0700246 CellLayout layout = (CellLayout) host.getParent().getParent();
247 if ((providerInfo.resizeMode & AppWidgetProviderInfo.RESIZE_HORIZONTAL) != 0) {
248 if (layout.isRegionVacant(info.cellX + info.spanX, info.cellY, 1, info.spanY) ||
249 layout.isRegionVacant(info.cellX - 1, info.cellY, 1, info.spanY)) {
250 actions.add(R.string.action_increase_width);
251 }
252
253 if (info.spanX > info.minSpanX && info.spanX > 1) {
254 actions.add(R.string.action_decrease_width);
255 }
256 }
257
258 if ((providerInfo.resizeMode & AppWidgetProviderInfo.RESIZE_VERTICAL) != 0) {
259 if (layout.isRegionVacant(info.cellX, info.cellY + info.spanY, info.spanX, 1) ||
260 layout.isRegionVacant(info.cellX, info.cellY - 1, info.spanX, 1)) {
261 actions.add(R.string.action_increase_height);
262 }
263
264 if (info.spanY > info.minSpanY && info.spanY > 1) {
265 actions.add(R.string.action_decrease_height);
266 }
267 }
268 return actions;
269 }
270
Sunny Goyal316490e2015-06-02 09:38:28 -0700271 @Thunk void performResizeAction(int action, View host, LauncherAppWidgetInfo info) {
Sunny Goyal9ca9c132015-04-29 14:57:22 -0700272 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) host.getLayoutParams();
273 CellLayout layout = (CellLayout) host.getParent().getParent();
274 layout.markCellsAsUnoccupiedForView(host);
275
276 if (action == R.string.action_increase_width) {
277 if (((host.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL)
278 && layout.isRegionVacant(info.cellX - 1, info.cellY, 1, info.spanY))
279 || !layout.isRegionVacant(info.cellX + info.spanX, info.cellY, 1, info.spanY)) {
280 lp.cellX --;
281 info.cellX --;
282 }
283 lp.cellHSpan ++;
284 info.spanX ++;
285 } else if (action == R.string.action_decrease_width) {
286 lp.cellHSpan --;
287 info.spanX --;
288 } else if (action == R.string.action_increase_height) {
289 if (!layout.isRegionVacant(info.cellX, info.cellY + info.spanY, info.spanX, 1)) {
290 lp.cellY --;
291 info.cellY --;
292 }
293 lp.cellVSpan ++;
294 info.spanY ++;
295 } else if (action == R.string.action_decrease_height) {
296 lp.cellVSpan --;
297 info.spanY --;
298 }
299
300 layout.markCellsAsOccupiedForView(host);
301 Rect sizeRange = new Rect();
302 AppWidgetResizeFrame.getWidgetSizeRanges(mLauncher, info.spanX, info.spanY, sizeRange);
303 ((LauncherAppWidgetHostView) host).updateAppWidgetSize(null,
304 sizeRange.left, sizeRange.top, sizeRange.right, sizeRange.bottom);
305 host.requestLayout();
Sunny Goyal43bf11d2017-02-02 13:52:53 -0800306 mLauncher.getModelWriter().updateItemInDatabase(info);
Sunny Goyal9ca9c132015-04-29 14:57:22 -0700307 announceConfirmation(mLauncher.getString(R.string.widget_resized, info.spanX, info.spanY));
308 }
309
Adam Cohen091440a2015-03-18 14:16:05 -0700310 @Thunk void announceConfirmation(int resId) {
Adam Cohenc9735cf2015-01-23 16:11:55 -0800311 announceConfirmation(mLauncher.getResources().getString(resId));
312 }
313
Adam Cohen091440a2015-03-18 14:16:05 -0700314 @Thunk void announceConfirmation(String confirmation) {
Adam Cohenc9735cf2015-01-23 16:11:55 -0800315 mLauncher.getDragLayer().announceForAccessibility(confirmation);
316
317 }
318
319 public boolean isInAccessibleDrag() {
320 return mDragInfo != null;
321 }
322
323 public DragInfo getDragInfo() {
324 return mDragInfo;
325 }
326
Sunny Goyal1a70cef2015-04-22 11:29:51 -0700327 /**
328 * @param clickedTarget the actual view that was clicked
329 * @param dropLocation relative to {@param clickedTarget}. If provided, its center is used
330 * as the actual drop location otherwise the views center is used.
331 */
332 public void handleAccessibleDrop(View clickedTarget, Rect dropLocation,
Adam Cohenc9735cf2015-01-23 16:11:55 -0800333 String confirmation) {
334 if (!isInAccessibleDrag()) return;
335
336 int[] loc = new int[2];
Sunny Goyal1a70cef2015-04-22 11:29:51 -0700337 if (dropLocation == null) {
338 loc[0] = clickedTarget.getWidth() / 2;
339 loc[1] = clickedTarget.getHeight() / 2;
340 } else {
341 loc[0] = dropLocation.centerX();
342 loc[1] = dropLocation.centerY();
343 }
Adam Cohenc9735cf2015-01-23 16:11:55 -0800344
Sunny Goyal1a70cef2015-04-22 11:29:51 -0700345 mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(clickedTarget, loc);
Adam Cohenc9735cf2015-01-23 16:11:55 -0800346 mLauncher.getDragController().completeAccessibleDrag(loc);
347
Sunny Goyal1a70cef2015-04-22 11:29:51 -0700348 if (!TextUtils.isEmpty(confirmation)) {
349 announceConfirmation(confirmation);
350 }
Adam Cohenc9735cf2015-01-23 16:11:55 -0800351 }
352
353 public void beginAccessibleDrag(View item, ItemInfo info) {
354 mDragInfo = new DragInfo();
355 mDragInfo.info = info;
356 mDragInfo.item = item;
357 mDragInfo.dragType = DragType.ICON;
358 if (info instanceof FolderInfo) {
359 mDragInfo.dragType = DragType.FOLDER;
360 } else if (info instanceof LauncherAppWidgetInfo) {
361 mDragInfo.dragType = DragType.WIDGET;
362 }
363
364 CellLayout.CellInfo cellInfo = new CellLayout.CellInfo(item, info);
365
366 Rect pos = new Rect();
367 mLauncher.getDragLayer().getDescendantRectRelativeToSelf(item, pos);
Adam Cohenc9735cf2015-01-23 16:11:55 -0800368 mLauncher.getDragController().prepareAccessibleDrag(pos.centerX(), pos.centerY());
Sunny Goyale9b651e2015-04-24 11:44:51 -0700369
Sunny Goyal740ac7f2016-09-28 16:47:32 -0700370 Folder folder = Folder.getOpen(mLauncher);
Sunny Goyale9b651e2015-04-24 11:44:51 -0700371 if (folder != null) {
Sunny Goyal94b510c2016-08-16 15:36:48 -0700372 if (!folder.getItemsInReadingOrder().contains(item)) {
Sunny Goyal740ac7f2016-09-28 16:47:32 -0700373 folder.close(true);
Sunny Goyal94b510c2016-08-16 15:36:48 -0700374 folder = null;
Sunny Goyale9b651e2015-04-24 11:44:51 -0700375 }
376 }
Adam Cohenc9735cf2015-01-23 16:11:55 -0800377
Sunny Goyal94b510c2016-08-16 15:36:48 -0700378 mLauncher.getDragController().addDragListener(this);
379
380 DragOptions options = new DragOptions();
381 options.isAccessibleDrag = true;
382 if (folder != null) {
383 folder.startDrag(cellInfo.cell, options);
384 } else {
Sunny Goyal740ac7f2016-09-28 16:47:32 -0700385 mLauncher.getWorkspace().startDrag(cellInfo, options);
Adam Cohenc9735cf2015-01-23 16:11:55 -0800386 }
Adam Cohenc9735cf2015-01-23 16:11:55 -0800387 }
388
Sunny Goyal45478022015-06-08 16:52:41 -0700389 @Override
Sunny Goyal94b510c2016-08-16 15:36:48 -0700390 public void onDragStart(DragObject dragObject, DragOptions options) {
Sunny Goyal45478022015-06-08 16:52:41 -0700391 // No-op
Adam Cohenc9735cf2015-01-23 16:11:55 -0800392 }
393
Sunny Goyal45478022015-06-08 16:52:41 -0700394 @Override
395 public void onDragEnd() {
396 mLauncher.getDragController().removeDragListener(this);
Adam Cohenc9735cf2015-01-23 16:11:55 -0800397 mDragInfo = null;
Adam Cohenc9735cf2015-01-23 16:11:55 -0800398 }
Sunny Goyala9116722015-04-29 13:55:58 -0700399
400 /**
401 * Find empty space on the workspace and returns the screenId.
402 */
Sunny Goyal3ffa64d2016-07-25 13:54:32 -0700403 protected long findSpaceOnWorkspace(ItemInfo info, int[] outCoordinates) {
Sunny Goyala9116722015-04-29 13:55:58 -0700404 Workspace workspace = mLauncher.getWorkspace();
405 ArrayList<Long> workspaceScreens = workspace.getScreenOrder();
406 long screenId;
407
408 // First check if there is space on the current screen.
409 int screenIndex = workspace.getCurrentPage();
410 screenId = workspaceScreens.get(screenIndex);
411 CellLayout layout = (CellLayout) workspace.getPageAt(screenIndex);
412
413 boolean found = layout.findCellForSpan(outCoordinates, info.spanX, info.spanY);
414 screenIndex = workspace.hasCustomContent() ? 1 : 0;
415 while (!found && screenIndex < workspaceScreens.size()) {
416 screenId = workspaceScreens.get(screenIndex);
417 layout = (CellLayout) workspace.getPageAt(screenIndex);
418 found = layout.findCellForSpan(outCoordinates, info.spanX, info.spanY);
419 screenIndex++;
420 }
421
422 if (found) {
423 return screenId;
424 }
425
426 workspace.addExtraEmptyScreen();
427 screenId = workspace.commitExtraEmptyScreen();
428 layout = workspace.getScreenWithId(screenId);
429 found = layout.findCellForSpan(outCoordinates, info.spanX, info.spanY);
430
431 if (!found) {
432 Log.wtf(TAG, "Not enough space on an empty screen");
433 }
434 return screenId;
435 }
Sunny Goyal71b5c0b2015-01-08 16:59:04 -0800436}