DropTarget.java revision 8dfcba4af7a7ece09e8c7d96053e54f3a383e905
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
17package com.android.launcher2;
18
19import android.graphics.Rect;
20
21/**
22 * Interface defining an object that can receive a drag.
23 *
24 */
25public interface DropTarget {
26
27    class DragObject {
28        public int x = -1;
29        public int y = -1;
30
31        /** X offset from the upper-left corner of the cell to where we touched.  */
32        public int xOffset = -1;
33
34        /** Y offset from the upper-left corner of the cell to where we touched.  */
35        public int yOffset = -1;
36
37        /** This indicates whether a drag is in final stages, either drop or cancel. It
38         * differentiates onDragExit, since this is called when the drag is ending, above
39         * the current drag target, or when the drag moves off the current drag object.
40         */
41        public boolean dragComplete = false;
42
43        /** The view that moves around while you drag.  */
44        public DragView dragView = null;
45
46        /** The data associated with the object being dragged */
47        public Object dragInfo = null;
48
49        /** Where the drag originated */
50        public DragSource dragSource = null;
51
52        public DragObject() {
53        }
54    }
55
56    /**
57     * Used to temporarily disable certain drop targets
58     *
59     * @return boolean specifying whether this drop target is currently enabled
60     */
61    boolean isDropEnabled();
62
63    /**
64     * Handle an object being dropped on the DropTarget
65     *
66     * @param source DragSource where the drag started
67     * @param x X coordinate of the drop location
68     * @param y Y coordinate of the drop location
69     * @param xOffset Horizontal offset with the object being dragged where the original
70     *          touch happened
71     * @param yOffset Vertical offset with the object being dragged where the original
72     *          touch happened
73     * @param dragView The DragView that's being dragged around on screen.
74     * @param dragInfo Data associated with the object being dragged
75     *
76     */
77    void onDrop(DragObject dragObject);
78
79    void onDragEnter(DragObject dragObject);
80
81    void onDragOver(DragObject dragObject);
82
83    void onDragExit(DragObject dragObject);
84
85    /**
86     * Allows a DropTarget to delegate drag and drop events to another object.
87     *
88     * Most subclasses will should just return null from this method.
89     *
90     * @param source DragSource where the drag started
91     * @param x X coordinate of the drop location
92     * @param y Y coordinate of the drop location
93     * @param xOffset Horizontal offset with the object being dragged where the original
94     *          touch happened
95     * @param yOffset Vertical offset with the object being dragged where the original
96     *          touch happened
97     * @param dragView The DragView that's being dragged around on screen.
98     * @param dragInfo Data associated with the object being dragged
99     *
100     * @return The DropTarget to delegate to, or null to not delegate to another object.
101     */
102    DropTarget getDropTargetDelegate(DragObject dragObject);
103
104    /**
105     * Check if a drop action can occur at, or near, the requested location.
106     * This will be called just before onDrop.
107     *
108     * @param source DragSource where the drag started
109     * @param x X coordinate of the drop location
110     * @param y Y coordinate of the drop location
111     * @param xOffset Horizontal offset with the object being dragged where the
112     *            original touch happened
113     * @param yOffset Vertical offset with the object being dragged where the
114     *            original touch happened
115     * @param dragView The DragView that's being dragged around on screen.
116     * @param dragInfo Data associated with the object being dragged
117     * @return True if the drop will be accepted, false otherwise.
118     */
119    boolean acceptDrop(DragObject dragObject);
120
121    // These methods are implemented in Views
122    void getHitRect(Rect outRect);
123    void getLocationInDragLayer(int[] loc);
124    int getLeft();
125    int getTop();
126}
127