1a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate/* 2a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate * Copyright (C) 2010 The Android Open Source Project 3a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate * 4a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate * Licensed under the Apache License, Version 2.0 (the "License"); 5a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate * you may not use this file except in compliance with the License. 6a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate * You may obtain a copy of the License at 7a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate * 8a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate * http://www.apache.org/licenses/LICENSE-2.0 9a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate * 10a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate * Unless required by applicable law or agreed to in writing, software 11a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate * distributed under the License is distributed on an "AS IS" BASIS, 12a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate * See the License for the specific language governing permissions and 14a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate * limitations under the License. 15a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate */ 16a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate 17a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tatepackage android.view; 18a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate 19a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tateimport android.content.ClipData; 20a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tateimport android.content.ClipDescription; 21a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tateimport android.os.Parcel; 22a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tateimport android.os.Parcelable; 23a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate 2432736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin//TODO: Improve Javadoc 2532736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin/** 2632736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * Represents an event that is sent out by the system at various times during a drag and drop 2732736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * operation. It is a complex data structure that contains several important pieces of data about 2832736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * the operation and the underlying data. 2932736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <p> 3032736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * View objects that receive a DragEvent call {@link #getAction()}, which returns 3132736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * an action type that indicates the state of the drag and drop operation. This allows a View 3232736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * object to react to a change in state by changing its appearance or performing other actions. 3332736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * For example, a View can react to the {@link #ACTION_DRAG_ENTERED} action type by 3432736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * by changing one or more colors in its displayed image. 3532736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * </p> 3632736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <p> 3732736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * During a drag and drop operation, the system displays an image that the user drags. This image 3832736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * is called a drag shadow. Several action types reflect the position of the drag shadow relative 3932736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * to the View receiving the event. 4032736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * </p> 4132736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <p> 4232736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * Most methods return valid data only for certain event actions. This is summarized in the 4332736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * following table. Each possible {@link #getAction()} value is listed in the first column. The 4432736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * other columns indicate which method or methods return valid data for that getAction() value: 4532736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * </p> 4632736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <table> 4732736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <tr> 4832736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <th scope="col">getAction() Value</th> 4932736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <th scope="col">getClipDescription()</th> 5032736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <th scope="col">getLocalState()</th> 5132736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <th scope="col">getX()</th> 5232736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <th scope="col">getY()</th> 5332736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <th scope="col">getClipData()</th> 5432736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <th scope="col">getResult()</th> 5532736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * </tr> 5632736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <tr> 5732736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td>ACTION_DRAG_STARTED</td> 5832736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td style="text-align: center;">X</td> 5932736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td style="text-align: center;">X</td> 6032736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td style="text-align: center;">X</td> 6132736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td style="text-align: center;">X</td> 6232736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td style="text-align: center;"> </td> 6332736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td style="text-align: center;"> </td> 6432736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * </tr> 6532736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <tr> 6632736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td>ACTION_DRAG_ENTERED</td> 6732736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td style="text-align: center;">X</td> 6832736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td style="text-align: center;">X</td> 6932736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td style="text-align: center;"> </td> 7032736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td style="text-align: center;"> </td> 7132736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td style="text-align: center;"> </td> 7232736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td style="text-align: center;"> </td> 7332736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * </tr> 7432736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <tr> 7532736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td>ACTION_DRAG_LOCATION</td> 7632736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td style="text-align: center;">X</td> 7732736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td style="text-align: center;">X</td> 7832736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td style="text-align: center;">X</td> 7932736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td style="text-align: center;">X</td> 8032736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td style="text-align: center;"> </td> 8132736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td style="text-align: center;"> </td> 8232736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * </tr> 8332736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <tr> 8432736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td>ACTION_DRAG_EXITED</td> 8532736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td style="text-align: center;">X</td> 8632736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td style="text-align: center;">X</td> 8732736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td style="text-align: center;"> </td> 8832736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td style="text-align: center;"> </td> 8932736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td style="text-align: center;"> </td> 9032736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td style="text-align: center;"> </td> 9132736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * </tr> 9232736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <tr> 9332736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td>ACTION_DROP</td> 9432736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td style="text-align: center;">X</td> 9532736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td style="text-align: center;">X</td> 9632736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td style="text-align: center;">X</td> 9732736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td style="text-align: center;">X</td> 9832736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td style="text-align: center;">X</td> 9932736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td style="text-align: center;"> </td> 10032736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * </tr> 10132736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <tr> 10232736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td>ACTION_DRAG_ENDED</td> 10332736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td style="text-align: center;">X</td> 10432736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td style="text-align: center;">X</td> 10532736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td style="text-align: center;"> </td> 10632736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td style="text-align: center;"> </td> 10732736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td style="text-align: center;"> </td> 10832736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <td style="text-align: center;">X</td> 10932736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * </tr> 11032736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * </table> 11132736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <p> 11232736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * The {@link android.view.DragEvent#getAction()}, 11332736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * {@link android.view.DragEvent#describeContents()}, 11432736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * {@link android.view.DragEvent#writeToParcel(Parcel,int)}, and 11532736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * {@link android.view.DragEvent#toString()} methods always return valid data. 11632736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * </p> 117558459fe85f56f29a6ed6a4d0adb4a0bd6665884Joe Fernandez * 118558459fe85f56f29a6ed6a4d0adb4a0bd6665884Joe Fernandez * <div class="special reference"> 119558459fe85f56f29a6ed6a4d0adb4a0bd6665884Joe Fernandez * <h3>Developer Guides</h3> 120558459fe85f56f29a6ed6a4d0adb4a0bd6665884Joe Fernandez * <p>For a guide to implementing drag and drop features, read the 121558459fe85f56f29a6ed6a4d0adb4a0bd6665884Joe Fernandez * <a href="{@docRoot}guide/topics/ui/drag-drop.html">Drag and Drop</a> developer guide.</p> 122558459fe85f56f29a6ed6a4d0adb4a0bd6665884Joe Fernandez * </div> 12332736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin */ 124a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tatepublic class DragEvent implements Parcelable { 125a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate private static final boolean TRACK_RECYCLED_LOCATION = false; 126a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate 127a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate int mAction; 128a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate float mX, mY; 129a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate ClipDescription mClipDescription; 130a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate ClipData mClipData; 131407b4e91fe7627545b8110e683953353236b4543Christopher Tate Object mLocalState; 132d4533f1469990582e4a2dd0898429093fe2690c0Chris Tate boolean mDragResult; 133a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate 134a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate private DragEvent mNext; 135a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate private RuntimeException mRecycledLocation; 136a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate private boolean mRecycled; 137a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate 138a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate private static final int MAX_RECYCLED = 10; 139a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate private static final Object gRecyclerLock = new Object(); 140a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate private static int gRecyclerUsed = 0; 141a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate private static DragEvent gRecyclerTop = null; 142a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate 143a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate /** 14432736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * Action constant returned by {@link #getAction()}: Signals the start of a 14532736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * drag and drop operation. The View should return {@code true} from its 14632736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * {@link View#onDragEvent(DragEvent) onDragEvent()} handler method or 14732736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * {@link View.View.OnDragListener#onDrag(View,DragEvent) OnDragListener.onDrag()} listener 14832736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * if it can accept a drop. The onDragEvent() or onDrag() methods usually inspect the metadata 14932736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * from {@link #getClipDescription()} to determine if they can accept the data contained in 15032736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * this drag. For an operation that doesn't represent data transfer, these methods may 15132736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * perform other actions to determine whether or not the View should accept the drag. 15232736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * If the View wants to indicate that it is a valid drop target, it can also react by 15332736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * changing its appearance. 154855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate * <p> 15532736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * A View only receives further drag events if it returns {@code true} in response to 15632736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * ACTION_DRAG_STARTED. 15732736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * </p> 15832736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * @see #ACTION_DRAG_ENDED 159a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate */ 160a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate public static final int ACTION_DRAG_STARTED = 1; 161855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate 162855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate /** 16332736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * Action constant returned by {@link #getAction()}: Sent to a View after 16432736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * {@link #ACTION_DRAG_ENTERED} if the drag shadow is still within the View object's bounding 16532736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * box. The {@link #getX()} and {@link #getY()} methods supply 16632736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * the X and Y position of of the drag point within the View object's bounding box. 16732736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <p> 16832736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * A View receives an {@link #ACTION_DRAG_ENTERED} event before receiving any 16932736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * ACTION_DRAG_LOCATION events. 17032736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * </p> 171855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate * <p> 17232736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * The system stops sending ACTION_DRAG_LOCATION events to a View once the user moves the 17332736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * drag shadow out of the View object's bounding box. If the user moves the drag shadow back 17432736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * into the View object's bounding box, the View receives an ACTION_DRAG_ENTERED again before 17532736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * receiving any more ACTION_DRAG_LOCATION events. 17632736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * </p> 17732736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * @see #ACTION_DRAG_ENTERED 17832736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * @see #getX() 17932736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * @see #getY() 180855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate */ 181a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate public static final int ACTION_DRAG_LOCATION = 2; 182855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate 183855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate /** 18432736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * Action constant returned by {@link #getAction()}: Signals to a View that the user 18532736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * has released the drag shadow, and the drag point is within the bounding box of the View. 18632736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * The View should retrieve the data from the DragEvent by calling {@link #getClipData()}. 18732736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * The methods {@link #getX()} and {@link #getY()} return the X and Y position of the drop point 18832736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * within the View object's bounding box. 18932736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <p> 19032736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * The View should return {@code true} from its {@link View#onDragEvent(DragEvent)} 19132736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * handler or {@link View.View.OnDragListener#onDrag(View,DragEvent) OnDragListener.onDrag()} 19232736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * listener if it accepted the drop, and {@code false} if it ignored the drop. 19332736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * </p> 194855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate * <p> 19532736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * The View can also react to this action by changing its appearance. 19632736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * </p> 19732736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * @see #getClipData() 19832736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * @see #getX() 19932736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * @see #getY() 200855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate */ 201a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate public static final int ACTION_DROP = 3; 202855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate 203855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate /** 20432736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * Action constant returned by {@link #getAction()}: Signals to a View that the drag and drop 20532736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * operation has concluded. A View that changed its appearance during the operation should 20632736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * return to its usual drawing state in response to this event. 207855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate * <p> 208855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate * All views that received an ACTION_DRAG_STARTED event will receive the 20932736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * ACTION_DRAG_ENDED event even if they are not currently visible when the drag ends. 21032736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * </p> 21132736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <p> 21232736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * The View object can call {@link #getResult()} to see the result of the operation. 21332736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * If a View returned {@code true} in response to {@link #ACTION_DROP}, then 21432736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * getResult() returns {@code true}, otherwise it returns {@code false}. 21532736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * </p> 21632736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * @see #ACTION_DRAG_STARTED 21732736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * @see #getResult() 218855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate */ 219a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate public static final int ACTION_DRAG_ENDED = 4; 220855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate 221855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate /** 22232736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * Action constant returned by {@link #getAction()}: Signals to a View that the drag point has 22332736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * entered the bounding box of the View. 224855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate * <p> 22532736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * If the View can accept a drop, it can react to ACTION_DRAG_ENTERED 22632736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * by changing its appearance in a way that tells the user that the View is the current 22732736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * drop target. 22832736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * </p> 22932736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * The system stops sending ACTION_DRAG_LOCATION events to a View once the user moves the 23032736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * drag shadow out of the View object's bounding box. If the user moves the drag shadow back 23132736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * into the View object's bounding box, the View receives an ACTION_DRAG_ENTERED again before 23232736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * receiving any more ACTION_DRAG_LOCATION events. 23332736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * </p> 23432736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * @see #ACTION_DRAG_ENTERED 23532736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * @see #ACTION_DRAG_LOCATION 236855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate */ 237a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate public static final int ACTION_DRAG_ENTERED = 5; 238a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate 239855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate /** 24032736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * Action constant returned by {@link #getAction()}: Signals that the user has moved the 24132736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * drag shadow outside the bounding box of the View. 24232736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * The View can react by changing its appearance in a way that tells the user that 24332736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * View is no longer the immediate drop target. 244855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate * <p> 24532736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * After the system sends an ACTION_DRAG_EXITED event to the View, the View receives no more 24632736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * ACTION_DRAG_LOCATION events until the user drags the drag shadow back over the View. 24732736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * </p> 24832736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * 249855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate */ 25032736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin public static final int ACTION_DRAG_EXITED = 6; 251855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate 2522c095f367779ef32130c72849936a2e3013c8492Christopher Tate private DragEvent() { 253a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate } 254a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate 255d4533f1469990582e4a2dd0898429093fe2690c0Chris Tate private void init(int action, float x, float y, ClipDescription description, ClipData data, 2567fb8b565f9cd2ec6a63ff4d8a89f98f68a1a138cChristopher Tate Object localState, boolean result) { 257c02c7af0ec88ec56089a11138d5fcfafcf891c58Chris Tate mAction = action; 258c02c7af0ec88ec56089a11138d5fcfafcf891c58Chris Tate mX = x; 259c02c7af0ec88ec56089a11138d5fcfafcf891c58Chris Tate mY = y; 260c02c7af0ec88ec56089a11138d5fcfafcf891c58Chris Tate mClipDescription = description; 261c02c7af0ec88ec56089a11138d5fcfafcf891c58Chris Tate mClipData = data; 2627fb8b565f9cd2ec6a63ff4d8a89f98f68a1a138cChristopher Tate mLocalState = localState; 263d4533f1469990582e4a2dd0898429093fe2690c0Chris Tate mDragResult = result; 264c02c7af0ec88ec56089a11138d5fcfafcf891c58Chris Tate } 265c02c7af0ec88ec56089a11138d5fcfafcf891c58Chris Tate 2662c095f367779ef32130c72849936a2e3013c8492Christopher Tate static DragEvent obtain() { 267407b4e91fe7627545b8110e683953353236b4543Christopher Tate return DragEvent.obtain(0, 0f, 0f, null, null, null, false); 268a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate } 269a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate 270855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate /** @hide */ 271407b4e91fe7627545b8110e683953353236b4543Christopher Tate public static DragEvent obtain(int action, float x, float y, Object localState, 272d4533f1469990582e4a2dd0898429093fe2690c0Chris Tate ClipDescription description, ClipData data, boolean result) { 273a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate final DragEvent ev; 274a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate synchronized (gRecyclerLock) { 275a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate if (gRecyclerTop == null) { 276c02c7af0ec88ec56089a11138d5fcfafcf891c58Chris Tate ev = new DragEvent(); 2777fb8b565f9cd2ec6a63ff4d8a89f98f68a1a138cChristopher Tate ev.init(action, x, y, description, data, localState, result); 278c02c7af0ec88ec56089a11138d5fcfafcf891c58Chris Tate return ev; 279a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate } 280a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate ev = gRecyclerTop; 281a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate gRecyclerTop = ev.mNext; 282a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate gRecyclerUsed -= 1; 283a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate } 284a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate ev.mRecycledLocation = null; 285a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate ev.mRecycled = false; 286a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate ev.mNext = null; 287a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate 2887fb8b565f9cd2ec6a63ff4d8a89f98f68a1a138cChristopher Tate ev.init(action, x, y, description, data, localState, result); 289a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate 290a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate return ev; 291a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate } 292a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate 293855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate /** @hide */ 2942c095f367779ef32130c72849936a2e3013c8492Christopher Tate public static DragEvent obtain(DragEvent source) { 295407b4e91fe7627545b8110e683953353236b4543Christopher Tate return obtain(source.mAction, source.mX, source.mY, source.mLocalState, 296d4533f1469990582e4a2dd0898429093fe2690c0Chris Tate source.mClipDescription, source.mClipData, source.mDragResult); 2972c095f367779ef32130c72849936a2e3013c8492Christopher Tate } 2982c095f367779ef32130c72849936a2e3013c8492Christopher Tate 299855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate /** 300855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate * Inspect the action value of this event. 30132736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * @return One of the following action constants, in the order in which they usually occur 30232736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * during a drag and drop operation: 30332736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <ul> 30432736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <li>{@link #ACTION_DRAG_STARTED}</li> 30532736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <li>{@link #ACTION_DRAG_ENTERED}</li> 30632736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <li>{@link #ACTION_DRAG_LOCATION}</li> 30732736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <li>{@link #ACTION_DROP}</li> 30832736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <li>{@link #ACTION_DRAG_EXITED}</li> 30932736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <li>{@link #ACTION_DRAG_ENDED}</li> 31032736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * </ul> 311855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate */ 312a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate public int getAction() { 313a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate return mAction; 314a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate } 315a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate 316855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate /** 31732736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * Gets the X coordinate of the drag point. The value is only valid if the event action is 31832736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * {@link #ACTION_DRAG_LOCATION} or {@link #ACTION_DROP}. 31932736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * @return The current drag point's Y coordinate 320855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate */ 321a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate public float getX() { 322a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate return mX; 323a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate } 324a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate 325855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate /** 32632736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * Gets the Y coordinate of the drag point. The value is valid if the 32732736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * event action is {@link #ACTION_DRAG_ENTERED}, {@link #ACTION_DRAG_LOCATION}, 32832736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * {@link #ACTION_DROP}, or {@link #ACTION_DRAG_EXITED}. 32932736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * @return The current drag point's Y coordinate 330855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate */ 331a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate public float getY() { 332a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate return mY; 333a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate } 334a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate 335855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate /** 33632736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * Returns the {@link android.content.ClipData} object sent to the system as part of the call 33732736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * to 33832736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * {@link android.view.View#startDrag(ClipData,View.DragShadowBuilder,Object,int) startDrag()}. 33932736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * This method only returns valid data if the event action is {@link #ACTION_DROP}. 34032736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * @return The ClipData sent to the system by startDrag(). 341855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate */ 342a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate public ClipData getClipData() { 343a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate return mClipData; 344a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate } 345a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate 346855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate /** 34732736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * Returns the {@link android.content.ClipDescription} object contained in the 34832736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * {@link android.content.ClipData} object sent to the system as part of the call to 34932736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * {@link android.view.View#startDrag(ClipData,View.DragShadowBuilder,Object,int) startDrag()}. 35032736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * The drag handler or listener for a View can use the metadata in this object to decide if the 35132736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * View can accept the dragged View object's data. 35232736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <p> 35332736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * This method returns valid data for all event actions. 35432736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * @return The ClipDescription that was part of the ClipData sent to the system by startDrag(). 355855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate */ 356a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate public ClipDescription getClipDescription() { 357a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate return mClipDescription; 358a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate } 359a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate 360855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate /** 36132736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * Returns the local state object sent to the system as part of the call to 36232736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * {@link android.view.View#startDrag(ClipData,View.DragShadowBuilder,Object,int) startDrag()}. 36332736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * The object is intended to provide local information about the drag and drop operation. For 36432736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * example, it can indicate whether the drag and drop operation is a copy or a move. 36532736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <p> 36632736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * This method returns valid data for all event actions. 36732736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * </p> 36832736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * @return The local state object sent to the system by startDrag(). 369407b4e91fe7627545b8110e683953353236b4543Christopher Tate */ 370407b4e91fe7627545b8110e683953353236b4543Christopher Tate public Object getLocalState() { 371407b4e91fe7627545b8110e683953353236b4543Christopher Tate return mLocalState; 372407b4e91fe7627545b8110e683953353236b4543Christopher Tate } 373407b4e91fe7627545b8110e683953353236b4543Christopher Tate 374407b4e91fe7627545b8110e683953353236b4543Christopher Tate /** 37532736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <p> 37632736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * Returns an indication of the result of the drag and drop operation. 37732736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * This method only returns valid data if the action type is {@link #ACTION_DRAG_ENDED}. 37832736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * The return value depends on what happens after the user releases the drag shadow. 37932736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * </p> 38032736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <p> 38132736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * If the user releases the drag shadow on a View that can accept a drop, the system sends an 38232736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * {@link #ACTION_DROP} event to the View object's drag event listener. If the listener 38332736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * returns {@code true}, then getResult() will return {@code true}. 38432736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * If the listener returns {@code false}, then getResult() returns {@code false}. 38532736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * </p> 38632736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * <p> 38732736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * Notice that getResult() also returns {@code false} if no {@link #ACTION_DROP} is sent. This 38832736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * happens, for example, when the user releases the drag shadow over an area outside of the 38932736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * application. In this case, the system sends out {@link #ACTION_DRAG_ENDED} for the current 39032736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * operation, but never sends out {@link #ACTION_DROP}. 39132736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * </p> 39232736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * @return {@code true} if a drag event listener returned {@code true} in response to 39332736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * {@link #ACTION_DROP}. If the system did not send {@link #ACTION_DROP} before 39432736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * {@link #ACTION_DRAG_ENDED}, or if the listener returned {@code false} in response to 39532736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * {@link #ACTION_DROP}, then {@code false} is returned. 396855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate */ 397d4533f1469990582e4a2dd0898429093fe2690c0Chris Tate public boolean getResult() { 398d4533f1469990582e4a2dd0898429093fe2690c0Chris Tate return mDragResult; 399d4533f1469990582e4a2dd0898429093fe2690c0Chris Tate } 400d4533f1469990582e4a2dd0898429093fe2690c0Chris Tate 401a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate /** 402a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate * Recycle the DragEvent, to be re-used by a later caller. After calling 403a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate * this function you must never touch the event again. 404855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate * 405855e4c98846a4264b7a27ad68cfa66c12ac0591cChristopher Tate * @hide 406a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate */ 407a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate public final void recycle() { 408a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate // Ensure recycle is only called once! 409a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate if (TRACK_RECYCLED_LOCATION) { 410a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate if (mRecycledLocation != null) { 411a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate throw new RuntimeException(toString() + " recycled twice!", mRecycledLocation); 412a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate } 413a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate mRecycledLocation = new RuntimeException("Last recycled here"); 414a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate } else { 415a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate if (mRecycled) { 416a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate throw new RuntimeException(toString() + " recycled twice!"); 417a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate } 418a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate mRecycled = true; 419a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate } 420a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate 421a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate mClipData = null; 422a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate mClipDescription = null; 423407b4e91fe7627545b8110e683953353236b4543Christopher Tate mLocalState = null; 424a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate 425a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate synchronized (gRecyclerLock) { 426a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate if (gRecyclerUsed < MAX_RECYCLED) { 427a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate gRecyclerUsed++; 428a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate mNext = gRecyclerTop; 429a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate gRecyclerTop = this; 430a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate } 431a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate } 432a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate } 433a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate 43432736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin /** 43532736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * Returns a string containing a concise, human-readable representation of this DragEvent 43632736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * object. 43732736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * @return A string representation of the DragEvent object. 43832736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin */ 439a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate @Override 440a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate public String toString() { 441a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate return "DragEvent{" + Integer.toHexString(System.identityHashCode(this)) 442a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate + " action=" + mAction + " @ (" + mX + ", " + mY + ") desc=" + mClipDescription 443f01af7551b3cf8853d3a76412c2745a543063434Christopher Tate + " data=" + mClipData + " local=" + mLocalState + " result=" + mDragResult 444a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate + "}"; 445a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate } 446a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate 447a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate /* Parcelable interface */ 448a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate 44932736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin /** 45032736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * Returns information about the {@link android.os.Parcel} representation of this DragEvent 45132736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * object. 45232736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * @return Information about the {@link android.os.Parcel} representation. 45332736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin */ 454a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate public int describeContents() { 455a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate return 0; 456a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate } 457a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate 45832736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin /** 45932736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * Creates a {@link android.os.Parcel} object from this DragEvent object. 46032736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * @param dest A {@link android.os.Parcel} object in which to put the DragEvent object. 46132736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * @param flags Flags to store in the Parcel. 46232736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin */ 463a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate public void writeToParcel(Parcel dest, int flags) { 464a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate dest.writeInt(mAction); 465a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate dest.writeFloat(mX); 466a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate dest.writeFloat(mY); 467d4533f1469990582e4a2dd0898429093fe2690c0Chris Tate dest.writeInt(mDragResult ? 1 : 0); 468a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate if (mClipData == null) { 469a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate dest.writeInt(0); 470a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate } else { 471a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate dest.writeInt(1); 472a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate mClipData.writeToParcel(dest, flags); 473a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate } 474a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate if (mClipDescription == null) { 475a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate dest.writeInt(0); 476a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate } else { 477a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate dest.writeInt(1); 478a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate mClipDescription.writeToParcel(dest, flags); 479a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate } 480a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate } 481a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate 48232736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin /** 48332736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin * A container for creating a DragEvent from a Parcel. 48432736f085b74c4dcc9da61212ccbd6fe2de193a7Joe Malin */ 485a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate public static final Parcelable.Creator<DragEvent> CREATOR = 486a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate new Parcelable.Creator<DragEvent>() { 487a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate public DragEvent createFromParcel(Parcel in) { 488a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate DragEvent event = DragEvent.obtain(); 489a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate event.mAction = in.readInt(); 490a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate event.mX = in.readFloat(); 491a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate event.mY = in.readFloat(); 492d4533f1469990582e4a2dd0898429093fe2690c0Chris Tate event.mDragResult = (in.readInt() != 0); 493a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate if (in.readInt() != 0) { 494a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate event.mClipData = ClipData.CREATOR.createFromParcel(in); 495a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate } 496a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate if (in.readInt() != 0) { 497a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate event.mClipDescription = ClipDescription.CREATOR.createFromParcel(in); 498a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate } 499a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate return event; 500a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate } 501a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate 502a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate public DragEvent[] newArray(int size) { 503a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate return new DragEvent[size]; 504a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate } 505a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate }; 506a53146c5569f8ff5f7eb55e9ad35d23ddacf2addChristopher Tate} 507