• 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 android.graphics.Rect;
20 
21 import com.android.launcher3.accessibility.DragViewStateAnnouncer;
22 import com.android.launcher3.dragndrop.DragOptions;
23 import com.android.launcher3.dragndrop.DragView;
24 
25 /**
26  * Interface defining an object that can receive a drag.
27  *
28  */
29 public interface DropTarget {
30 
31     class DragObject {
32         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 
41         /** 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 
47         /** The view that moves around while you drag.  */
48         public DragView dragView = null;
49 
50         /** The data associated with the object, after item is dropped. */
51         public ItemInfo dragInfo = null;
52 
53         /** The data associated with the object  being dragged */
54         public ItemInfo originalDragInfo = null;
55 
56         /** Where the drag originated */
57         public DragSource dragSource = null;
58 
59         /** The object is part of an accessible drag operation */
60         public boolean accessibleDrag;
61 
62         /** Indicates that the drag operation was cancelled */
63         public boolean cancelled = false;
64 
65         /** Defers removing the DragView from the DragLayer until after the drop animation. */
66         public boolean deferDragViewCleanupPostAnimation = true;
67 
68         public DragViewStateAnnouncer stateAnnouncer;
69 
DragObject()70         public DragObject() {
71         }
72 
73         /**
74          * This is used to compute the visual center of the dragView. This point is then
75          * used to visualize drop locations and determine where to drop an item. The idea is that
76          * the visual center represents the user's interpretation of where the item is, and hence
77          * is the appropriate point to use when determining drop location.
78          */
getVisualCenter(float[] recycle)79         public final float[] getVisualCenter(float[] recycle) {
80             final float res[] = (recycle == null) ? new float[2] : recycle;
81             Rect dragRegion = dragView.getDragRegion();
82 
83             // These represent the visual top and left of drag view if a dragRect was provided.
84             // If a dragRect was not provided, then they correspond to the actual view left and
85             // top, as the dragRect is in that case taken to be the entire dragView.
86             int left = x - xOffset - dragRegion.left;
87             int top = y - yOffset - dragRegion.top;
88 
89             // In order to find the visual center, we shift by half the dragRect
90             res[0] = left + dragRegion.width() / 2;
91             res[1] = top + dragRegion.height() / 2;
92 
93             return res;
94         }
95     }
96 
97     /**
98      * Used to temporarily disable certain drop targets
99      *
100      * @return boolean specifying whether this drop target is currently enabled
101      */
isDropEnabled()102     boolean isDropEnabled();
103 
104     /**
105      * Handle an object being dropped on the DropTarget.
106      *
107      * This will be called only if this target previously returned true for {@link #acceptDrop}. It
108      * is the responsibility of this target to exit out of the spring loaded mode (either
109      * immediately or after any pending animations).
110      *
111      * If the drop was cancelled for some reason, onDrop will never get called, the UI will
112      * automatically exit out of this mode.
113      */
onDrop(DragObject dragObject, DragOptions options)114     void onDrop(DragObject dragObject, DragOptions options);
115 
onDragEnter(DragObject dragObject)116     void onDragEnter(DragObject dragObject);
117 
onDragOver(DragObject dragObject)118     void onDragOver(DragObject dragObject);
119 
onDragExit(DragObject dragObject)120     void onDragExit(DragObject dragObject);
121 
122     /**
123      * Check if a drop action can occur at, or near, the requested location.
124      * This will be called just before onDrop.
125      * @return True if the drop will be accepted, false otherwise.
126      */
acceptDrop(DragObject dragObject)127     boolean acceptDrop(DragObject dragObject);
128 
prepareAccessibilityDrop()129     void prepareAccessibilityDrop();
130 
131     // These methods are implemented in Views
getHitRectRelativeToDragLayer(Rect outRect)132     void getHitRectRelativeToDragLayer(Rect outRect);
133 }
134