The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 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 | |
Joe Onorato | a590252 | 2009-07-30 13:37:37 -0700 | [diff] [blame] | 17 | package com.android.launcher2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 18 | |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame^] | 19 | import android.graphics.PointF; |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 20 | import android.graphics.Rect; |
| 21 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 22 | /** |
| 23 | * Interface defining an object that can receive a drag. |
| 24 | * |
| 25 | */ |
| 26 | public interface DropTarget { |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 27 | |
| 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 Cohen | bfbfd26 | 2011-06-13 16:55:12 -0700 | [diff] [blame] | 38 | /** 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 Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 44 | /** 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 Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 53 | /** Post drag animation runnable */ |
| 54 | public Runnable postAnimationRunnable = null; |
| 55 | |
Adam Cohen | 36cc09b | 2011-09-29 17:33:15 -0700 | [diff] [blame] | 56 | /** Indicates that the drag operation was cancelled */ |
| 57 | public boolean cancelled = false; |
| 58 | |
Winson Chung | 7bd1bbb | 2012-02-13 18:29:29 -0800 | [diff] [blame] | 59 | /** Defers removing the DragView from the DragLayer until after the drop animation. */ |
| 60 | public boolean deferDragViewCleanupPostAnimation = true; |
| 61 | |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 62 | public DragObject() { |
| 63 | } |
| 64 | } |
| 65 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 66 | /** |
| 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 Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 72 | |
| 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 Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 79 | * @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 Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 84 | * @param dragInfo Data associated with the object being dragged |
| 85 | * |
| 86 | */ |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 87 | void onDrop(DragObject dragObject); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 88 | |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 89 | void onDragEnter(DragObject dragObject); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 90 | |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 91 | void onDragOver(DragObject dragObject); |
| 92 | |
| 93 | void onDragExit(DragObject dragObject); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 94 | |
| 95 | /** |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame^] | 96 | * 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 Dubroy | 440c360 | 2010-07-13 17:50:32 -0700 | [diff] [blame] | 103 | * 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 Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 119 | DropTarget getDropTargetDelegate(DragObject dragObject); |
Patrick Dubroy | 440c360 | 2010-07-13 17:50:32 -0700 | [diff] [blame] | 120 | |
| 121 | /** |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 122 | * Check if a drop action can occur at, or near, the requested location. |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 123 | * This will be called just before onDrop. |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 124 | * |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 125 | * @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 Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 128 | * @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 Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 132 | * @param dragView The DragView that's being dragged around on screen. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 133 | * @param dragInfo Data associated with the object being dragged |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 134 | * @return True if the drop will be accepted, false otherwise. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 135 | */ |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 136 | boolean acceptDrop(DragObject dragObject); |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 137 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 138 | // These methods are implemented in Views |
| 139 | void getHitRect(Rect outRect); |
Adam Cohen | 8dfcba4 | 2011-07-07 16:38:18 -0700 | [diff] [blame] | 140 | void getLocationInDragLayer(int[] loc); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 141 | int getLeft(); |
| 142 | int getTop(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 143 | } |