Home | History | Annotate | Download | only in launcher2
      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     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         /** This indicates whether a drag is in final stages, either drop or cancel. It
     38          * differentiates onDragExit, since this is called when the drag is ending, above
     39          * the current drag target, or when the drag moves off the current drag object.
     40          */
     41         public boolean dragComplete = false;
     42 
     43         /** The view that moves around while you drag.  */
     44         public DragView dragView = null;
     45 
     46         /** The data associated with the object being dragged */
     47         public Object dragInfo = null;
     48 
     49         /** Where the drag originated */
     50         public DragSource dragSource = null;
     51 
     52         /** Post drag animation runnable */
     53         public Runnable postAnimationRunnable = null;
     54 
     55         /** Indicates that the drag operation was cancelled */
     56         public boolean cancelled = false;
     57 
     58         public DragObject() {
     59         }
     60     }
     61 
     62     /**
     63      * Used to temporarily disable certain drop targets
     64      *
     65      * @return boolean specifying whether this drop target is currently enabled
     66      */
     67     boolean isDropEnabled();
     68 
     69     /**
     70      * Handle an object being dropped on the DropTarget
     71      *
     72      * @param source DragSource where the drag started
     73      * @param x X coordinate of the drop location
     74      * @param y Y coordinate of the drop location
     75      * @param xOffset Horizontal offset with the object being dragged where the original
     76      *          touch happened
     77      * @param yOffset Vertical offset with the object being dragged where the original
     78      *          touch happened
     79      * @param dragView The DragView that's being dragged around on screen.
     80      * @param dragInfo Data associated with the object being dragged
     81      *
     82      */
     83     void onDrop(DragObject dragObject);
     84 
     85     void onDragEnter(DragObject dragObject);
     86 
     87     void onDragOver(DragObject dragObject);
     88 
     89     void onDragExit(DragObject dragObject);
     90 
     91     /**
     92      * Allows a DropTarget to delegate drag and drop events to another object.
     93      *
     94      * Most subclasses will should just return null from this method.
     95      *
     96      * @param source DragSource where the drag started
     97      * @param x X coordinate of the drop location
     98      * @param y Y coordinate of the drop location
     99      * @param xOffset Horizontal offset with the object being dragged where the original
    100      *          touch happened
    101      * @param yOffset Vertical offset with the object being dragged where the original
    102      *          touch happened
    103      * @param dragView The DragView that's being dragged around on screen.
    104      * @param dragInfo Data associated with the object being dragged
    105      *
    106      * @return The DropTarget to delegate to, or null to not delegate to another object.
    107      */
    108     DropTarget getDropTargetDelegate(DragObject dragObject);
    109 
    110     /**
    111      * Check if a drop action can occur at, or near, the requested location.
    112      * This will be called just before onDrop.
    113      *
    114      * @param source DragSource where the drag started
    115      * @param x X coordinate of the drop location
    116      * @param y Y coordinate of the drop location
    117      * @param xOffset Horizontal offset with the object being dragged where the
    118      *            original touch happened
    119      * @param yOffset Vertical offset with the object being dragged where the
    120      *            original touch happened
    121      * @param dragView The DragView that's being dragged around on screen.
    122      * @param dragInfo Data associated with the object being dragged
    123      * @return True if the drop will be accepted, false otherwise.
    124      */
    125     boolean acceptDrop(DragObject dragObject);
    126 
    127     // These methods are implemented in Views
    128     void getHitRect(Rect outRect);
    129     void getLocationInDragLayer(int[] loc);
    130     int getLeft();
    131     int getTop();
    132 }
    133