blob: 2307b89246e66e0b2e3ab51a12671d1616fc31ac [file] [log] [blame]
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001/*
2 * Copyright (C) 2008 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
Daniel Sandler325dc232013-06-05 22:57:57 -040017package com.android.launcher3;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
Jeff Sharkey70864282009-04-07 21:08:40 -070019import android.graphics.Rect;
20
Sunny Goyale78e3d72015-09-24 11:23:31 -070021import com.android.launcher3.accessibility.DragViewStateAnnouncer;
Sunny Goyal3dce5f32017-10-05 11:40:05 -070022import com.android.launcher3.dragndrop.DragOptions;
Sunny Goyal0f76b562016-12-13 19:37:10 -080023import com.android.launcher3.dragndrop.DragView;
Sunny Goyale78e3d72015-09-24 11:23:31 -070024
The Android Open Source Project31dd5032009-03-03 19:32:27 -080025/**
26 * Interface defining an object that can receive a drag.
27 *
28 */
29public interface DropTarget {
Adam Cohencb3382b2011-05-24 14:07:08 -070030
Sunny Goyal9eba1fd2015-10-16 08:58:57 -070031 class DragObject {
Adam Cohencb3382b2011-05-24 14:07:08 -070032 public int x = -1;
33 public int y = -1;
34
35 /** X offset from the upper-left corner of the cell to where we touched. */
36 public int xOffset = -1;
37
38 /** Y offset from the upper-left corner of the cell to where we touched. */
39 public int yOffset = -1;
40
Adam Cohenbfbfd262011-06-13 16:55:12 -070041 /** This indicates whether a drag is in final stages, either drop or cancel. It
42 * differentiates onDragExit, since this is called when the drag is ending, above
43 * the current drag target, or when the drag moves off the current drag object.
44 */
45 public boolean dragComplete = false;
46
Adam Cohencb3382b2011-05-24 14:07:08 -070047 /** The view that moves around while you drag. */
48 public DragView dragView = null;
49
Hyunyoung Song59a23802016-09-01 12:47:12 -070050 /** The data associated with the object, after item is dropped. */
Sunny Goyalaa8ef112015-06-12 20:04:41 -070051 public ItemInfo dragInfo = null;
Adam Cohencb3382b2011-05-24 14:07:08 -070052
Hyunyoung Song59a23802016-09-01 12:47:12 -070053 /** The data associated with the object being dragged */
54 public ItemInfo originalDragInfo = null;
55
Adam Cohencb3382b2011-05-24 14:07:08 -070056 /** Where the drag originated */
57 public DragSource dragSource = null;
58
Adam Cohenc9735cf2015-01-23 16:11:55 -080059 /** The object is part of an accessible drag operation */
60 public boolean accessibleDrag;
61
Winson Chung557d6ed2011-07-08 15:34:52 -070062 /** Post drag animation runnable */
63 public Runnable postAnimationRunnable = null;
64
Adam Cohen36cc09b2011-09-29 17:33:15 -070065 /** Indicates that the drag operation was cancelled */
66 public boolean cancelled = false;
67
Winson Chung7bd1bbb2012-02-13 18:29:29 -080068 /** Defers removing the DragView from the DragLayer until after the drop animation. */
69 public boolean deferDragViewCleanupPostAnimation = true;
70
Sunny Goyale78e3d72015-09-24 11:23:31 -070071 public DragViewStateAnnouncer stateAnnouncer;
72
Adam Cohencb3382b2011-05-24 14:07:08 -070073 public DragObject() {
74 }
Sunny Goyal1587d532015-01-29 09:57:16 -080075
76 /**
77 * This is used to compute the visual center of the dragView. This point is then
78 * used to visualize drop locations and determine where to drop an item. The idea is that
79 * the visual center represents the user's interpretation of where the item is, and hence
80 * is the appropriate point to use when determining drop location.
81 */
82 public final float[] getVisualCenter(float[] recycle) {
83 final float res[] = (recycle == null) ? new float[2] : recycle;
84
85 // These represent the visual top and left of drag view if a dragRect was provided.
86 // If a dragRect was not provided, then they correspond to the actual view left and
87 // top, as the dragRect is in that case taken to be the entire dragView.
88 // R.dimen.dragViewOffsetY.
89 int left = x - xOffset;
90 int top = y - yOffset;
91
92 // In order to find the visual center, we shift by half the dragRect
93 res[0] = left + dragView.getDragRegion().width() / 2;
94 res[1] = top + dragView.getDragRegion().height() / 2;
95
96 return res;
97 }
Adam Cohencb3382b2011-05-24 14:07:08 -070098 }
99
Michael Jurka0280c3b2010-09-17 15:00:07 -0700100 /**
101 * Used to temporarily disable certain drop targets
102 *
103 * @return boolean specifying whether this drop target is currently enabled
104 */
105 boolean isDropEnabled();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800106
107 /**
108 * Handle an object being dropped on the DropTarget
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800109 */
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700110 void onDrop(DragObject dragObject, DragOptions options);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800111
Adam Cohencb3382b2011-05-24 14:07:08 -0700112 void onDragEnter(DragObject dragObject);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800113
Adam Cohencb3382b2011-05-24 14:07:08 -0700114 void onDragOver(DragObject dragObject);
115
116 void onDragExit(DragObject dragObject);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800117
118 /**
Jeff Sharkey70864282009-04-07 21:08:40 -0700119 * Check if a drop action can occur at, or near, the requested location.
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700120 * This will be called just before onDrop.
Jeff Sharkey70864282009-04-07 21:08:40 -0700121 * @return True if the drop will be accepted, false otherwise.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800122 */
Adam Cohencb3382b2011-05-24 14:07:08 -0700123 boolean acceptDrop(DragObject dragObject);
Jeff Sharkey70864282009-04-07 21:08:40 -0700124
Sunny Goyale9b651e2015-04-24 11:44:51 -0700125 void prepareAccessibilityDrop();
126
Joe Onorato00acb122009-08-04 16:04:30 -0400127 // These methods are implemented in Views
Adam Cohen7d30a372013-07-01 17:03:59 -0700128 void getHitRectRelativeToDragLayer(Rect outRect);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800129}