• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 package com.android.launcher3;
18 
19 import com.android.launcher3.dragndrop.DragView;
20 
21 import android.graphics.PointF;
22 import android.graphics.Rect;
23 
24 import com.android.launcher3.accessibility.DragViewStateAnnouncer;
25 
26 /**
27  * Interface defining an object that can receive a drag.
28  *
29  */
30 public interface DropTarget {
31 
32     class DragObject {
33         public int x = -1;
34         public int y = -1;
35 
36         /** X offset from the upper-left corner of the cell to where we touched.  */
37         public int xOffset = -1;
38 
39         /** Y offset from the upper-left corner of the cell to where we touched.  */
40         public int yOffset = -1;
41 
42         /** This indicates whether a drag is in final stages, either drop or cancel. It
43          * differentiates onDragExit, since this is called when the drag is ending, above
44          * the current drag target, or when the drag moves off the current drag object.
45          */
46         public boolean dragComplete = false;
47 
48         /** The view that moves around while you drag.  */
49         public DragView dragView = null;
50 
51         /** The data associated with the object, after item is dropped. */
52         public ItemInfo dragInfo = null;
53 
54         /** The data associated with the object  being dragged */
55         public ItemInfo originalDragInfo = null;
56 
57         /** Where the drag originated */
58         public DragSource dragSource = null;
59 
60         /** The object is part of an accessible drag operation */
61         public boolean accessibleDrag;
62 
63         /** Post drag animation runnable */
64         public Runnable postAnimationRunnable = null;
65 
66         /** Indicates that the drag operation was cancelled */
67         public boolean cancelled = false;
68 
69         /** Defers removing the DragView from the DragLayer until after the drop animation. */
70         public boolean deferDragViewCleanupPostAnimation = true;
71 
72         public DragViewStateAnnouncer stateAnnouncer;
73 
DragObject()74         public DragObject() {
75         }
76 
77         /**
78          * This is used to compute the visual center of the dragView. This point is then
79          * used to visualize drop locations and determine where to drop an item. The idea is that
80          * the visual center represents the user's interpretation of where the item is, and hence
81          * is the appropriate point to use when determining drop location.
82          */
getVisualCenter(float[] recycle)83         public final float[] getVisualCenter(float[] recycle) {
84             final float res[] = (recycle == null) ? new float[2] : recycle;
85 
86             // These represent the visual top and left of drag view if a dragRect was provided.
87             // If a dragRect was not provided, then they correspond to the actual view left and
88             // top, as the dragRect is in that case taken to be the entire dragView.
89             // R.dimen.dragViewOffsetY.
90             int left = x - xOffset;
91             int top = y - yOffset;
92 
93             // In order to find the visual center, we shift by half the dragRect
94             res[0] = left + dragView.getDragRegion().width() / 2;
95             res[1] = top + dragView.getDragRegion().height() / 2;
96 
97             return res;
98         }
99     }
100 
101     /**
102      * Used to temporarily disable certain drop targets
103      *
104      * @return boolean specifying whether this drop target is currently enabled
105      */
isDropEnabled()106     boolean isDropEnabled();
107 
108     /**
109      * Handle an object being dropped on the DropTarget
110      *
111      * @param source DragSource where the drag started
112      * @param x X coordinate of the drop location
113      * @param y Y coordinate of the drop location
114      * @param xOffset Horizontal offset with the object being dragged where the original
115      *          touch happened
116      * @param yOffset Vertical offset with the object being dragged where the original
117      *          touch happened
118      * @param dragView The DragView that's being dragged around on screen.
119      * @param dragInfo Data associated with the object being dragged
120      *
121      */
onDrop(DragObject dragObject)122     void onDrop(DragObject dragObject);
123 
onDragEnter(DragObject dragObject)124     void onDragEnter(DragObject dragObject);
125 
onDragOver(DragObject dragObject)126     void onDragOver(DragObject dragObject);
127 
onDragExit(DragObject dragObject)128     void onDragExit(DragObject dragObject);
129 
130     /**
131      * Handle an object being dropped as a result of flinging to delete and will be called in place
132      * of onDrop().  (This is only called on objects that are set as the DragController's
133      * fling-to-delete target.
134      */
onFlingToDelete(DragObject dragObject, PointF vec)135     void onFlingToDelete(DragObject dragObject, PointF vec);
136 
137     /**
138      * Check if a drop action can occur at, or near, the requested location.
139      * This will be called just before onDrop.
140      *
141      * @param source DragSource where the drag started
142      * @param x X coordinate of the drop location
143      * @param y Y coordinate of the drop location
144      * @param xOffset Horizontal offset with the object being dragged where the
145      *            original touch happened
146      * @param yOffset Vertical offset with the object being dragged where the
147      *            original touch happened
148      * @param dragView The DragView that's being dragged around on screen.
149      * @param dragInfo Data associated with the object being dragged
150      * @return True if the drop will be accepted, false otherwise.
151      */
acceptDrop(DragObject dragObject)152     boolean acceptDrop(DragObject dragObject);
153 
prepareAccessibilityDrop()154     void prepareAccessibilityDrop();
155 
156     // These methods are implemented in Views
getHitRectRelativeToDragLayer(Rect outRect)157     void getHitRectRelativeToDragLayer(Rect outRect);
158 }
159