blob: efdeb1fa3778dafee8a4ded36ec07d185259b09a [file] [log] [blame]
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001/*
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
Daniel Sandler325dc232013-06-05 22:57:57 -040017package com.android.launcher3;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
Vadim Tryshevfedca432015-08-19 17:55:02 -070019import com.android.launcher3.dragndrop.DragView;
20
Winson Chung043f2af2012-03-01 16:09:54 -080021import android.graphics.PointF;
Jeff Sharkey70864282009-04-07 21:08:40 -070022import android.graphics.Rect;
23
Sunny Goyale78e3d72015-09-24 11:23:31 -070024import com.android.launcher3.accessibility.DragViewStateAnnouncer;
25
The Android Open Source Project31dd5032009-03-03 19:32:27 -080026/**
27 * Interface defining an object that can receive a drag.
28 *
29 */
30public interface DropTarget {
Adam Cohencb3382b2011-05-24 14:07:08 -070031
Sunny Goyal9eba1fd2015-10-16 08:58:57 -070032 class DragObject {
Adam Cohencb3382b2011-05-24 14:07:08 -070033 public int x = -1;
34 public int y = -1;
35
36 /** X offset from the upper-left corner of the cell to where we touched. */
37 public int xOffset = -1;
38
39 /** Y offset from the upper-left corner of the cell to where we touched. */
40 public int yOffset = -1;
41
Adam Cohenbfbfd262011-06-13 16:55:12 -070042 /** This indicates whether a drag is in final stages, either drop or cancel. It
43 * differentiates onDragExit, since this is called when the drag is ending, above
44 * the current drag target, or when the drag moves off the current drag object.
45 */
46 public boolean dragComplete = false;
47
Adam Cohencb3382b2011-05-24 14:07:08 -070048 /** The view that moves around while you drag. */
49 public DragView dragView = null;
50
Hyunyoung Song59a23802016-09-01 12:47:12 -070051 /** The data associated with the object, after item is dropped. */
Sunny Goyalaa8ef112015-06-12 20:04:41 -070052 public ItemInfo dragInfo = null;
Adam Cohencb3382b2011-05-24 14:07:08 -070053
Hyunyoung Song59a23802016-09-01 12:47:12 -070054 /** The data associated with the object being dragged */
55 public ItemInfo originalDragInfo = null;
56
Adam Cohencb3382b2011-05-24 14:07:08 -070057 /** Where the drag originated */
58 public DragSource dragSource = null;
59
Adam Cohenc9735cf2015-01-23 16:11:55 -080060 /** The object is part of an accessible drag operation */
61 public boolean accessibleDrag;
62
Winson Chung557d6ed2011-07-08 15:34:52 -070063 /** Post drag animation runnable */
64 public Runnable postAnimationRunnable = null;
65
Adam Cohen36cc09b2011-09-29 17:33:15 -070066 /** Indicates that the drag operation was cancelled */
67 public boolean cancelled = false;
68
Winson Chung7bd1bbb2012-02-13 18:29:29 -080069 /** Defers removing the DragView from the DragLayer until after the drop animation. */
70 public boolean deferDragViewCleanupPostAnimation = true;
71
Sunny Goyale78e3d72015-09-24 11:23:31 -070072 public DragViewStateAnnouncer stateAnnouncer;
73
Adam Cohencb3382b2011-05-24 14:07:08 -070074 public DragObject() {
75 }
Sunny Goyal1587d532015-01-29 09:57:16 -080076
77 /**
78 * This is used to compute the visual center of the dragView. This point is then
79 * used to visualize drop locations and determine where to drop an item. The idea is that
80 * the visual center represents the user's interpretation of where the item is, and hence
81 * is the appropriate point to use when determining drop location.
82 */
83 public final float[] getVisualCenter(float[] recycle) {
84 final float res[] = (recycle == null) ? new float[2] : recycle;
85
86 // These represent the visual top and left of drag view if a dragRect was provided.
87 // If a dragRect was not provided, then they correspond to the actual view left and
88 // top, as the dragRect is in that case taken to be the entire dragView.
89 // R.dimen.dragViewOffsetY.
90 int left = x - xOffset;
91 int top = y - yOffset;
92
93 // In order to find the visual center, we shift by half the dragRect
94 res[0] = left + dragView.getDragRegion().width() / 2;
95 res[1] = top + dragView.getDragRegion().height() / 2;
96
97 return res;
98 }
Adam Cohencb3382b2011-05-24 14:07:08 -070099 }
100
Michael Jurka0280c3b2010-09-17 15:00:07 -0700101 /**
102 * Used to temporarily disable certain drop targets
103 *
104 * @return boolean specifying whether this drop target is currently enabled
105 */
106 boolean isDropEnabled();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800107
108 /**
109 * Handle an object being dropped on the DropTarget
Sunny Goyalfa401a12015-04-10 13:45:42 -0700110 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800111 * @param source DragSource where the drag started
112 * @param x X coordinate of the drop location
113 * @param y Y coordinate of the drop location
Joe Onorato00acb122009-08-04 16:04:30 -0400114 * @param xOffset Horizontal offset with the object being dragged where the original
115 * touch happened
116 * @param yOffset Vertical offset with the object being dragged where the original
117 * touch happened
118 * @param dragView The DragView that's being dragged around on screen.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800119 * @param dragInfo Data associated with the object being dragged
Mindy DelliCarpini53b8d072013-07-03 08:23:13 -0700120 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800121 */
Adam Cohencb3382b2011-05-24 14:07:08 -0700122 void onDrop(DragObject dragObject);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800123
Adam Cohencb3382b2011-05-24 14:07:08 -0700124 void onDragEnter(DragObject dragObject);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800125
Adam Cohencb3382b2011-05-24 14:07:08 -0700126 void onDragOver(DragObject dragObject);
127
128 void onDragExit(DragObject dragObject);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800129
130 /**
Winson Chung043f2af2012-03-01 16:09:54 -0800131 * Handle an object being dropped as a result of flinging to delete and will be called in place
132 * of onDrop(). (This is only called on objects that are set as the DragController's
133 * fling-to-delete target.
134 */
Sunny Goyalddec7342015-04-29 18:12:37 -0700135 void onFlingToDelete(DragObject dragObject, PointF vec);
Winson Chung043f2af2012-03-01 16:09:54 -0800136
137 /**
Jeff Sharkey70864282009-04-07 21:08:40 -0700138 * Check if a drop action can occur at, or near, the requested location.
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700139 * This will be called just before onDrop.
Sunny Goyalfa401a12015-04-10 13:45:42 -0700140 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800141 * @param source DragSource where the drag started
142 * @param x X coordinate of the drop location
143 * @param y Y coordinate of the drop location
Jeff Sharkey70864282009-04-07 21:08:40 -0700144 * @param xOffset Horizontal offset with the object being dragged where the
145 * original touch happened
146 * @param yOffset Vertical offset with the object being dragged where the
147 * original touch happened
Joe Onorato00acb122009-08-04 16:04:30 -0400148 * @param dragView The DragView that's being dragged around on screen.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800149 * @param dragInfo Data associated with the object being dragged
Jeff Sharkey70864282009-04-07 21:08:40 -0700150 * @return True if the drop will be accepted, false otherwise.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800151 */
Adam Cohencb3382b2011-05-24 14:07:08 -0700152 boolean acceptDrop(DragObject dragObject);
Jeff Sharkey70864282009-04-07 21:08:40 -0700153
Sunny Goyale9b651e2015-04-24 11:44:51 -0700154 void prepareAccessibilityDrop();
155
Joe Onorato00acb122009-08-04 16:04:30 -0400156 // These methods are implemented in Views
Adam Cohen7d30a372013-07-01 17:03:59 -0700157 void getHitRectRelativeToDragLayer(Rect outRect);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800158}