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 | |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 19 | import android.graphics.Rect; |
| 20 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 21 | /** |
| 22 | * Interface defining an object that can receive a drag. |
| 23 | * |
| 24 | */ |
| 25 | public interface DropTarget { |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 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 | /** The view that moves around while you drag. */ |
| 38 | public DragView dragView = null; |
| 39 | |
| 40 | /** The data associated with the object being dragged */ |
| 41 | public Object dragInfo = null; |
| 42 | |
| 43 | /** Where the drag originated */ |
| 44 | public DragSource dragSource = null; |
| 45 | |
| 46 | public DragObject() { |
| 47 | } |
| 48 | } |
| 49 | |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 50 | /** |
| 51 | * Used to temporarily disable certain drop targets |
| 52 | * |
| 53 | * @return boolean specifying whether this drop target is currently enabled |
| 54 | */ |
| 55 | boolean isDropEnabled(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 56 | |
| 57 | /** |
| 58 | * Handle an object being dropped on the DropTarget |
| 59 | * |
| 60 | * @param source DragSource where the drag started |
| 61 | * @param x X coordinate of the drop location |
| 62 | * @param y Y coordinate of the drop location |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 63 | * @param xOffset Horizontal offset with the object being dragged where the original |
| 64 | * touch happened |
| 65 | * @param yOffset Vertical offset with the object being dragged where the original |
| 66 | * touch happened |
| 67 | * @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] | 68 | * @param dragInfo Data associated with the object being dragged |
| 69 | * |
| 70 | */ |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 71 | void onDrop(DragObject dragObject); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 72 | |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 73 | void onDragEnter(DragObject dragObject); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 74 | |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 75 | void onDragOver(DragObject dragObject); |
| 76 | |
| 77 | void onDragExit(DragObject dragObject); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 78 | |
| 79 | /** |
Patrick Dubroy | 440c360 | 2010-07-13 17:50:32 -0700 | [diff] [blame] | 80 | * Allows a DropTarget to delegate drag and drop events to another object. |
| 81 | * |
| 82 | * Most subclasses will should just return null from this method. |
| 83 | * |
| 84 | * @param source DragSource where the drag started |
| 85 | * @param x X coordinate of the drop location |
| 86 | * @param y Y coordinate of the drop location |
| 87 | * @param xOffset Horizontal offset with the object being dragged where the original |
| 88 | * touch happened |
| 89 | * @param yOffset Vertical offset with the object being dragged where the original |
| 90 | * touch happened |
| 91 | * @param dragView The DragView that's being dragged around on screen. |
| 92 | * @param dragInfo Data associated with the object being dragged |
| 93 | * |
| 94 | * @return The DropTarget to delegate to, or null to not delegate to another object. |
| 95 | */ |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 96 | DropTarget getDropTargetDelegate(DragObject dragObject); |
Patrick Dubroy | 440c360 | 2010-07-13 17:50:32 -0700 | [diff] [blame] | 97 | |
| 98 | /** |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 99 | * 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] | 100 | * This will be called just before onDrop. |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 101 | * |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 102 | * @param source DragSource where the drag started |
| 103 | * @param x X coordinate of the drop location |
| 104 | * @param y Y coordinate of the drop location |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 105 | * @param xOffset Horizontal offset with the object being dragged where the |
| 106 | * original touch happened |
| 107 | * @param yOffset Vertical offset with the object being dragged where the |
| 108 | * original touch happened |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 109 | * @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] | 110 | * @param dragInfo Data associated with the object being dragged |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 111 | * @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] | 112 | */ |
Adam Cohen | cb3382b | 2011-05-24 14:07:08 -0700 | [diff] [blame] | 113 | boolean acceptDrop(DragObject dragObject); |
Jeff Sharkey | 7086428 | 2009-04-07 21:08:40 -0700 | [diff] [blame] | 114 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 115 | // These methods are implemented in Views |
| 116 | void getHitRect(Rect outRect); |
| 117 | void getLocationOnScreen(int[] loc); |
| 118 | int getLeft(); |
| 119 | int getTop(); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 120 | } |