blob: fb714c60ac89a4a72cec71e20479e5dac3245f8b [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
Winson Chung043f2af2012-03-01 16:09:54 -080019import android.graphics.PointF;
Jeff Sharkey70864282009-04-07 21:08:40 -070020import android.graphics.Rect;
21
The Android Open Source Project31dd5032009-03-03 19:32:27 -080022/**
23 * Interface defining an object that can receive a drag.
24 *
25 */
26public interface DropTarget {
Adam Cohencb3382b2011-05-24 14:07:08 -070027
28 class DragObject {
29 public int x = -1;
30 public int y = -1;
31
32 /** X offset from the upper-left corner of the cell to where we touched. */
33 public int xOffset = -1;
34
35 /** Y offset from the upper-left corner of the cell to where we touched. */
36 public int yOffset = -1;
37
Adam Cohenbfbfd262011-06-13 16:55:12 -070038 /** This indicates whether a drag is in final stages, either drop or cancel. It
39 * differentiates onDragExit, since this is called when the drag is ending, above
40 * the current drag target, or when the drag moves off the current drag object.
41 */
42 public boolean dragComplete = false;
43
Adam Cohencb3382b2011-05-24 14:07:08 -070044 /** The view that moves around while you drag. */
45 public DragView dragView = null;
46
47 /** The data associated with the object being dragged */
48 public Object dragInfo = null;
49
50 /** Where the drag originated */
51 public DragSource dragSource = null;
52
Winson Chung557d6ed2011-07-08 15:34:52 -070053 /** Post drag animation runnable */
54 public Runnable postAnimationRunnable = null;
55
Adam Cohen36cc09b2011-09-29 17:33:15 -070056 /** Indicates that the drag operation was cancelled */
57 public boolean cancelled = false;
58
Winson Chung7bd1bbb2012-02-13 18:29:29 -080059 /** Defers removing the DragView from the DragLayer until after the drop animation. */
60 public boolean deferDragViewCleanupPostAnimation = true;
61
Adam Cohencb3382b2011-05-24 14:07:08 -070062 public DragObject() {
63 }
64 }
65
Michael Jurka0280c3b2010-09-17 15:00:07 -070066 /**
67 * Used to temporarily disable certain drop targets
68 *
69 * @return boolean specifying whether this drop target is currently enabled
70 */
71 boolean isDropEnabled();
The Android Open Source Project31dd5032009-03-03 19:32:27 -080072
73 /**
74 * Handle an object being dropped on the DropTarget
75 *
76 * @param source DragSource where the drag started
77 * @param x X coordinate of the drop location
78 * @param y Y coordinate of the drop location
Joe Onorato00acb122009-08-04 16:04:30 -040079 * @param xOffset Horizontal offset with the object being dragged where the original
80 * touch happened
81 * @param yOffset Vertical offset with the object being dragged where the original
82 * touch happened
83 * @param dragView The DragView that's being dragged around on screen.
The Android Open Source Project31dd5032009-03-03 19:32:27 -080084 * @param dragInfo Data associated with the object being dragged
85 *
86 */
Adam Cohencb3382b2011-05-24 14:07:08 -070087 void onDrop(DragObject dragObject);
The Android Open Source Project31dd5032009-03-03 19:32:27 -080088
Adam Cohencb3382b2011-05-24 14:07:08 -070089 void onDragEnter(DragObject dragObject);
The Android Open Source Project31dd5032009-03-03 19:32:27 -080090
Adam Cohencb3382b2011-05-24 14:07:08 -070091 void onDragOver(DragObject dragObject);
92
93 void onDragExit(DragObject dragObject);
The Android Open Source Project31dd5032009-03-03 19:32:27 -080094
95 /**
Winson Chung043f2af2012-03-01 16:09:54 -080096 * Handle an object being dropped as a result of flinging to delete and will be called in place
97 * of onDrop(). (This is only called on objects that are set as the DragController's
98 * fling-to-delete target.
99 */
100 void onFlingToDelete(DragObject dragObject, int x, int y, PointF vec);
101
102 /**
Patrick Dubroy440c3602010-07-13 17:50:32 -0700103 * Allows a DropTarget to delegate drag and drop events to another object.
104 *
105 * Most subclasses will should just return null from this method.
106 *
107 * @param source DragSource where the drag started
108 * @param x X coordinate of the drop location
109 * @param y Y coordinate of the drop location
110 * @param xOffset Horizontal offset with the object being dragged where the original
111 * touch happened
112 * @param yOffset Vertical offset with the object being dragged where the original
113 * touch happened
114 * @param dragView The DragView that's being dragged around on screen.
115 * @param dragInfo Data associated with the object being dragged
116 *
117 * @return The DropTarget to delegate to, or null to not delegate to another object.
118 */
Adam Cohencb3382b2011-05-24 14:07:08 -0700119 DropTarget getDropTargetDelegate(DragObject dragObject);
Patrick Dubroy440c3602010-07-13 17:50:32 -0700120
121 /**
Jeff Sharkey70864282009-04-07 21:08:40 -0700122 * Check if a drop action can occur at, or near, the requested location.
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700123 * This will be called just before onDrop.
Jeff Sharkey70864282009-04-07 21:08:40 -0700124 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800125 * @param source DragSource where the drag started
126 * @param x X coordinate of the drop location
127 * @param y Y coordinate of the drop location
Jeff Sharkey70864282009-04-07 21:08:40 -0700128 * @param xOffset Horizontal offset with the object being dragged where the
129 * original touch happened
130 * @param yOffset Vertical offset with the object being dragged where the
131 * original touch happened
Joe Onorato00acb122009-08-04 16:04:30 -0400132 * @param dragView The DragView that's being dragged around on screen.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800133 * @param dragInfo Data associated with the object being dragged
Jeff Sharkey70864282009-04-07 21:08:40 -0700134 * @return True if the drop will be accepted, false otherwise.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800135 */
Adam Cohencb3382b2011-05-24 14:07:08 -0700136 boolean acceptDrop(DragObject dragObject);
Jeff Sharkey70864282009-04-07 21:08:40 -0700137
Joe Onorato00acb122009-08-04 16:04:30 -0400138 // These methods are implemented in Views
139 void getHitRect(Rect outRect);
Adam Cohen8dfcba42011-07-07 16:38:18 -0700140 void getLocationInDragLayer(int[] loc);
Joe Onorato00acb122009-08-04 16:04:30 -0400141 int getLeft();
142 int getTop();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800143}