blob: e49f7829b7955ae5be10c93e8c97f719dfb5a6e0 [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
Joe Onoratoa5902522009-07-30 13:37:37 -070017package com.android.launcher2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
Jeff Sharkey70864282009-04-07 21:08:40 -070019import android.graphics.Rect;
20
The Android Open Source Project31dd5032009-03-03 19:32:27 -080021/**
22 * Interface defining an object that can receive a drag.
23 *
24 */
25public interface DropTarget {
Adam Cohencb3382b2011-05-24 14:07:08 -070026
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
Adam Cohenbfbfd262011-06-13 16:55:12 -070037 /** 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
Adam Cohencb3382b2011-05-24 14:07:08 -070043 /** 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
Winson Chung557d6ed2011-07-08 15:34:52 -070052 /** Post drag animation runnable */
53 public Runnable postAnimationRunnable = null;
54
Adam Cohen36cc09b2011-09-29 17:33:15 -070055 /** Indicates that the drag operation was cancelled */
56 public boolean cancelled = false;
57
Winson Chung7bd1bbb2012-02-13 18:29:29 -080058 /** Defers removing the DragView from the DragLayer until after the drop animation. */
59 public boolean deferDragViewCleanupPostAnimation = true;
60
Adam Cohencb3382b2011-05-24 14:07:08 -070061 public DragObject() {
62 }
63 }
64
Michael Jurka0280c3b2010-09-17 15:00:07 -070065 /**
66 * Used to temporarily disable certain drop targets
67 *
68 * @return boolean specifying whether this drop target is currently enabled
69 */
70 boolean isDropEnabled();
The Android Open Source Project31dd5032009-03-03 19:32:27 -080071
72 /**
73 * Handle an object being dropped on the DropTarget
74 *
75 * @param source DragSource where the drag started
76 * @param x X coordinate of the drop location
77 * @param y Y coordinate of the drop location
Joe Onorato00acb122009-08-04 16:04:30 -040078 * @param xOffset Horizontal offset with the object being dragged where the original
79 * touch happened
80 * @param yOffset Vertical offset with the object being dragged where the original
81 * touch happened
82 * @param dragView The DragView that's being dragged around on screen.
The Android Open Source Project31dd5032009-03-03 19:32:27 -080083 * @param dragInfo Data associated with the object being dragged
84 *
85 */
Adam Cohencb3382b2011-05-24 14:07:08 -070086 void onDrop(DragObject dragObject);
The Android Open Source Project31dd5032009-03-03 19:32:27 -080087
Adam Cohencb3382b2011-05-24 14:07:08 -070088 void onDragEnter(DragObject dragObject);
The Android Open Source Project31dd5032009-03-03 19:32:27 -080089
Adam Cohencb3382b2011-05-24 14:07:08 -070090 void onDragOver(DragObject dragObject);
91
92 void onDragExit(DragObject dragObject);
The Android Open Source Project31dd5032009-03-03 19:32:27 -080093
94 /**
Patrick Dubroy440c3602010-07-13 17:50:32 -070095 * Allows a DropTarget to delegate drag and drop events to another object.
96 *
97 * Most subclasses will should just return null from this method.
98 *
99 * @param source DragSource where the drag started
100 * @param x X coordinate of the drop location
101 * @param y Y coordinate of the drop location
102 * @param xOffset Horizontal offset with the object being dragged where the original
103 * touch happened
104 * @param yOffset Vertical offset with the object being dragged where the original
105 * touch happened
106 * @param dragView The DragView that's being dragged around on screen.
107 * @param dragInfo Data associated with the object being dragged
108 *
109 * @return The DropTarget to delegate to, or null to not delegate to another object.
110 */
Adam Cohencb3382b2011-05-24 14:07:08 -0700111 DropTarget getDropTargetDelegate(DragObject dragObject);
Patrick Dubroy440c3602010-07-13 17:50:32 -0700112
113 /**
Jeff Sharkey70864282009-04-07 21:08:40 -0700114 * Check if a drop action can occur at, or near, the requested location.
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700115 * This will be called just before onDrop.
Jeff Sharkey70864282009-04-07 21:08:40 -0700116 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800117 * @param source DragSource where the drag started
118 * @param x X coordinate of the drop location
119 * @param y Y coordinate of the drop location
Jeff Sharkey70864282009-04-07 21:08:40 -0700120 * @param xOffset Horizontal offset with the object being dragged where the
121 * original touch happened
122 * @param yOffset Vertical offset with the object being dragged where the
123 * original touch happened
Joe Onorato00acb122009-08-04 16:04:30 -0400124 * @param dragView The DragView that's being dragged around on screen.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800125 * @param dragInfo Data associated with the object being dragged
Jeff Sharkey70864282009-04-07 21:08:40 -0700126 * @return True if the drop will be accepted, false otherwise.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800127 */
Adam Cohencb3382b2011-05-24 14:07:08 -0700128 boolean acceptDrop(DragObject dragObject);
Jeff Sharkey70864282009-04-07 21:08:40 -0700129
Joe Onorato00acb122009-08-04 16:04:30 -0400130 // These methods are implemented in Views
131 void getHitRect(Rect outRect);
Adam Cohen8dfcba42011-07-07 16:38:18 -0700132 void getLocationInDragLayer(int[] loc);
Joe Onorato00acb122009-08-04 16:04:30 -0400133 int getLeft();
134 int getTop();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800135}