DropTarget.java revision bfbfd26c627a18f8e1e3e6d0e53e78feab360203
131dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project/* 231dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * Copyright (C) 2008 The Android Open Source Project 331dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * 431dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License"); 531dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * you may not use this file except in compliance with the License. 631dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * You may obtain a copy of the License at 731dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * 831dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * http://www.apache.org/licenses/LICENSE-2.0 931dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * 1031dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * Unless required by applicable law or agreed to in writing, software 1131dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS, 1231dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1331dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * See the License for the specific language governing permissions and 1431dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * limitations under the License. 1531dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project */ 1631dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project 17a5902524d4403885eb4c50360bf3465c6be796efJoe Onoratopackage com.android.launcher2; 1831dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project 1970864289fba6daf07b8de98524cdfb765a62552dJeff Sharkeyimport android.graphics.Rect; 2070864289fba6daf07b8de98524cdfb765a62552dJeff Sharkey 2131dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project/** 2231dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * Interface defining an object that can receive a drag. 2331dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * 2431dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project */ 2531dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Projectpublic interface DropTarget { 26cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen 27cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen class DragObject { 28cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen public int x = -1; 29cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen public int y = -1; 30cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen 31cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen /** X offset from the upper-left corner of the cell to where we touched. */ 32cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen public int xOffset = -1; 33cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen 34cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen /** Y offset from the upper-left corner of the cell to where we touched. */ 35cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen public int yOffset = -1; 36cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen 37bfbfd26c627a18f8e1e3e6d0e53e78feab360203Adam Cohen /** This indicates whether a drag is in final stages, either drop or cancel. It 38bfbfd26c627a18f8e1e3e6d0e53e78feab360203Adam Cohen * differentiates onDragExit, since this is called when the drag is ending, above 39bfbfd26c627a18f8e1e3e6d0e53e78feab360203Adam Cohen * the current drag target, or when the drag moves off the current drag object. 40bfbfd26c627a18f8e1e3e6d0e53e78feab360203Adam Cohen */ 41bfbfd26c627a18f8e1e3e6d0e53e78feab360203Adam Cohen public boolean dragComplete = false; 42bfbfd26c627a18f8e1e3e6d0e53e78feab360203Adam Cohen 43cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen /** The view that moves around while you drag. */ 44cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen public DragView dragView = null; 45cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen 46cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen /** The data associated with the object being dragged */ 47cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen public Object dragInfo = null; 48cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen 49cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen /** Where the drag originated */ 50cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen public DragSource dragSource = null; 51cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen 52cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen public DragObject() { 53cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen } 54cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen } 55cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen 560280c3be4d9f8fc6fdf015b7ecd276eb26f76f2dMichael Jurka /** 570280c3be4d9f8fc6fdf015b7ecd276eb26f76f2dMichael Jurka * Used to temporarily disable certain drop targets 580280c3be4d9f8fc6fdf015b7ecd276eb26f76f2dMichael Jurka * 590280c3be4d9f8fc6fdf015b7ecd276eb26f76f2dMichael Jurka * @return boolean specifying whether this drop target is currently enabled 600280c3be4d9f8fc6fdf015b7ecd276eb26f76f2dMichael Jurka */ 610280c3be4d9f8fc6fdf015b7ecd276eb26f76f2dMichael Jurka boolean isDropEnabled(); 6231dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project 6331dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project /** 6431dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * Handle an object being dropped on the DropTarget 6531dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * 6631dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * @param source DragSource where the drag started 6731dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * @param x X coordinate of the drop location 6831dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * @param y Y coordinate of the drop location 6900acb123c5100f06b8e89e8ec8978ebafc6f6d26Joe Onorato * @param xOffset Horizontal offset with the object being dragged where the original 7000acb123c5100f06b8e89e8ec8978ebafc6f6d26Joe Onorato * touch happened 7100acb123c5100f06b8e89e8ec8978ebafc6f6d26Joe Onorato * @param yOffset Vertical offset with the object being dragged where the original 7200acb123c5100f06b8e89e8ec8978ebafc6f6d26Joe Onorato * touch happened 7300acb123c5100f06b8e89e8ec8978ebafc6f6d26Joe Onorato * @param dragView The DragView that's being dragged around on screen. 7431dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * @param dragInfo Data associated with the object being dragged 7531dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * 7631dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project */ 77cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen void onDrop(DragObject dragObject); 78cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen 79cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen void onDragEnter(DragObject dragObject); 8031dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project 81cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen void onDragOver(DragObject dragObject); 8231dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project 83cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen void onDragExit(DragObject dragObject); 8431dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project 8531dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project /** 86440c360bc395c43683fa9ca226e59f9e35f9e926Patrick Dubroy * Allows a DropTarget to delegate drag and drop events to another object. 87440c360bc395c43683fa9ca226e59f9e35f9e926Patrick Dubroy * 88440c360bc395c43683fa9ca226e59f9e35f9e926Patrick Dubroy * Most subclasses will should just return null from this method. 89440c360bc395c43683fa9ca226e59f9e35f9e926Patrick Dubroy * 90440c360bc395c43683fa9ca226e59f9e35f9e926Patrick Dubroy * @param source DragSource where the drag started 91440c360bc395c43683fa9ca226e59f9e35f9e926Patrick Dubroy * @param x X coordinate of the drop location 92440c360bc395c43683fa9ca226e59f9e35f9e926Patrick Dubroy * @param y Y coordinate of the drop location 93440c360bc395c43683fa9ca226e59f9e35f9e926Patrick Dubroy * @param xOffset Horizontal offset with the object being dragged where the original 94440c360bc395c43683fa9ca226e59f9e35f9e926Patrick Dubroy * touch happened 95440c360bc395c43683fa9ca226e59f9e35f9e926Patrick Dubroy * @param yOffset Vertical offset with the object being dragged where the original 96440c360bc395c43683fa9ca226e59f9e35f9e926Patrick Dubroy * touch happened 97440c360bc395c43683fa9ca226e59f9e35f9e926Patrick Dubroy * @param dragView The DragView that's being dragged around on screen. 98440c360bc395c43683fa9ca226e59f9e35f9e926Patrick Dubroy * @param dragInfo Data associated with the object being dragged 99440c360bc395c43683fa9ca226e59f9e35f9e926Patrick Dubroy * 100440c360bc395c43683fa9ca226e59f9e35f9e926Patrick Dubroy * @return The DropTarget to delegate to, or null to not delegate to another object. 101440c360bc395c43683fa9ca226e59f9e35f9e926Patrick Dubroy */ 102cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen DropTarget getDropTargetDelegate(DragObject dragObject); 103440c360bc395c43683fa9ca226e59f9e35f9e926Patrick Dubroy 104440c360bc395c43683fa9ca226e59f9e35f9e926Patrick Dubroy /** 10570864289fba6daf07b8de98524cdfb765a62552dJeff Sharkey * Check if a drop action can occur at, or near, the requested location. 1064ed6278e518cc6894cb150b606382e8e6a012599Patrick Dubroy * This will be called just before onDrop. 10770864289fba6daf07b8de98524cdfb765a62552dJeff Sharkey * 10831dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * @param source DragSource where the drag started 10931dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * @param x X coordinate of the drop location 11031dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * @param y Y coordinate of the drop location 11170864289fba6daf07b8de98524cdfb765a62552dJeff Sharkey * @param xOffset Horizontal offset with the object being dragged where the 11270864289fba6daf07b8de98524cdfb765a62552dJeff Sharkey * original touch happened 11370864289fba6daf07b8de98524cdfb765a62552dJeff Sharkey * @param yOffset Vertical offset with the object being dragged where the 11470864289fba6daf07b8de98524cdfb765a62552dJeff Sharkey * original touch happened 11500acb123c5100f06b8e89e8ec8978ebafc6f6d26Joe Onorato * @param dragView The DragView that's being dragged around on screen. 11631dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project * @param dragInfo Data associated with the object being dragged 11770864289fba6daf07b8de98524cdfb765a62552dJeff Sharkey * @return True if the drop will be accepted, false otherwise. 11831dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project */ 119cb3382b1bfe1a534b1b44f5c4def9b2db605ac90Adam Cohen boolean acceptDrop(DragObject dragObject); 12070864289fba6daf07b8de98524cdfb765a62552dJeff Sharkey 12100acb123c5100f06b8e89e8ec8978ebafc6f6d26Joe Onorato // These methods are implemented in Views 12200acb123c5100f06b8e89e8ec8978ebafc6f6d26Joe Onorato void getHitRect(Rect outRect); 12300acb123c5100f06b8e89e8ec8978ebafc6f6d26Joe Onorato void getLocationOnScreen(int[] loc); 12400acb123c5100f06b8e89e8ec8978ebafc6f6d26Joe Onorato int getLeft(); 12500acb123c5100f06b8e89e8ec8978ebafc6f6d26Joe Onorato int getTop(); 12631dd503c6aa69018e694d91724d46db49ea09327The Android Open Source Project} 127