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 17 package com.android.launcher2; 18 19 import android.graphics.Rect; 20 21 /** 22 * Interface defining an object that can receive a drag. 23 * 24 */ 25 public interface DropTarget { 26 27 /** 28 * Handle an object being dropped on the DropTarget 29 * 30 * @param source DragSource where the drag started 31 * @param x X coordinate of the drop location 32 * @param y Y coordinate of the drop location 33 * @param xOffset Horizontal offset with the object being dragged where the original 34 * touch happened 35 * @param yOffset Vertical offset with the object being dragged where the original 36 * touch happened 37 * @param dragView The DragView that's being dragged around on screen. 38 * @param dragInfo Data associated with the object being dragged 39 * 40 */ onDrop(DragSource source, int x, int y, int xOffset, int yOffset, DragView dragView, Object dragInfo)41 void onDrop(DragSource source, int x, int y, int xOffset, int yOffset, 42 DragView dragView, Object dragInfo); 43 onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset, DragView dragView, Object dragInfo)44 void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset, 45 DragView dragView, Object dragInfo); 46 onDragOver(DragSource source, int x, int y, int xOffset, int yOffset, DragView dragView, Object dragInfo)47 void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset, 48 DragView dragView, Object dragInfo); 49 onDragExit(DragSource source, int x, int y, int xOffset, int yOffset, DragView dragView, Object dragInfo)50 void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset, 51 DragView dragView, Object dragInfo); 52 53 /** 54 * Check if a drop action can occur at, or near, the requested location. 55 * This may be called repeatedly during a drag, so any calls should return 56 * quickly. 57 * 58 * @param source DragSource where the drag started 59 * @param x X coordinate of the drop location 60 * @param y Y coordinate of the drop location 61 * @param xOffset Horizontal offset with the object being dragged where the 62 * original touch happened 63 * @param yOffset Vertical offset with the object being dragged where the 64 * original touch happened 65 * @param dragView The DragView that's being dragged around on screen. 66 * @param dragInfo Data associated with the object being dragged 67 * @return True if the drop will be accepted, false otherwise. 68 */ acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset, DragView dragView, Object dragInfo)69 boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset, 70 DragView dragView, Object dragInfo); 71 72 /** 73 * Estimate the surface area where this object would land if dropped at the 74 * given location. 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 79 * @param xOffset Horizontal offset with the object being dragged where the 80 * original touch happened 81 * @param yOffset Vertical offset with the object being dragged where the 82 * original touch happened 83 * @param dragView The DragView that's being dragged around on screen. 84 * @param dragInfo Data associated with the object being dragged 85 * @param recycle {@link Rect} object to be possibly recycled. 86 * @return Estimated area that would be occupied if object was dropped at 87 * the given location. Should return null if no estimate is found, 88 * or if this target doesn't provide estimations. 89 */ estimateDropLocation(DragSource source, int x, int y, int xOffset, int yOffset, DragView dragView, Object dragInfo, Rect recycle)90 Rect estimateDropLocation(DragSource source, int x, int y, int xOffset, int yOffset, 91 DragView dragView, Object dragInfo, Rect recycle); 92 93 // These methods are implemented in Views getHitRect(Rect outRect)94 void getHitRect(Rect outRect); getLocationOnScreen(int[] loc)95 void getLocationOnScreen(int[] loc); getLeft()96 int getLeft(); getTop()97 int getTop(); 98 } 99