blob: 77a23fbe7ca90c792d522451f874e430e3fb3cf9 [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
Joe Onoratoa5902522009-07-30 13:37:37 -070017package com.android.launcher2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
Joe Onorato00acb122009-08-04 16:04:30 -040019import android.content.Context;
20import android.graphics.Bitmap;
Winson Chungb8c69f32011-10-19 21:36:08 -070021import android.graphics.Point;
Winson Chung043f2af2012-03-01 16:09:54 -080022import android.graphics.PointF;
Joe Onorato00acb122009-08-04 16:04:30 -040023import android.graphics.Rect;
Joe Onorato00acb122009-08-04 16:04:30 -040024import android.os.Handler;
Michael Jurka0280c3b2010-09-17 15:00:07 -070025import android.os.IBinder;
Joe Onorato00acb122009-08-04 16:04:30 -040026import android.os.Vibrator;
Joe Onorato00acb122009-08-04 16:04:30 -040027import android.util.Log;
Joe Onorato00acb122009-08-04 16:04:30 -040028import android.view.KeyEvent;
29import android.view.MotionEvent;
Winson Chung043f2af2012-03-01 16:09:54 -080030import android.view.VelocityTracker;
Michael Jurka0280c3b2010-09-17 15:00:07 -070031import android.view.View;
Patrick Dubroya16fd5a2010-10-07 16:47:28 -070032import android.view.ViewConfiguration;
Joe Onorato00acb122009-08-04 16:04:30 -040033import android.view.inputmethod.InputMethodManager;
Joe Onorato00acb122009-08-04 16:04:30 -040034
Adam Cohen120980b2010-12-08 11:05:37 -080035import com.android.launcher.R;
Adam Cohenc0dcf592011-06-01 15:30:43 -070036
37import java.util.ArrayList;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080038
39/**
Joe Onorato00acb122009-08-04 16:04:30 -040040 * Class for initiating a drag within a view or across multiple views.
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041 */
Joe Onorato00acb122009-08-04 16:04:30 -040042public class DragController {
Romain Guyea3763c2010-01-11 18:02:04 -080043 @SuppressWarnings({"UnusedDeclaration"})
Joe Onorato2e5c4322009-10-06 12:34:42 -070044 private static final String TAG = "Launcher.DragController";
45
Joe Onorato00acb122009-08-04 16:04:30 -040046 /** Indicates the drag is a move. */
47 public static int DRAG_ACTION_MOVE = 0;
48
49 /** Indicates the drag is a copy. */
50 public static int DRAG_ACTION_COPY = 1;
51
Winson Chungaa15ffe2012-01-18 15:45:28 -080052 private static final int SCROLL_DELAY = 500;
53 private static final int RESCROLL_DELAY = 750;
Winson Chung61b0c692012-02-23 16:31:13 -080054 private static final int VIBRATE_DURATION = 15;
Joe Onorato00acb122009-08-04 16:04:30 -040055
56 private static final boolean PROFILE_DRAWING_DURING_DRAG = false;
57
58 private static final int SCROLL_OUTSIDE_ZONE = 0;
59 private static final int SCROLL_WAITING_IN_ZONE = 1;
60
Patrick Dubroy54fa3b92010-11-17 12:18:45 -080061 static final int SCROLL_NONE = -1;
Patrick Dubroy1262e362010-10-06 15:49:50 -070062 static final int SCROLL_LEFT = 0;
63 static final int SCROLL_RIGHT = 1;
Joe Onorato00acb122009-08-04 16:04:30 -040064
Winson Chung043f2af2012-03-01 16:09:54 -080065 private static final float MAX_FLING_DEGREES = 35f;
Winson Chung9658b1e2012-04-09 18:30:07 -070066 private static final int FLING_TO_DELETE_THRESHOLD_Y_VELOCITY = -1500;
Winson Chung043f2af2012-03-01 16:09:54 -080067
Adam Cohen8dfcba42011-07-07 16:38:18 -070068 private Launcher mLauncher;
Joe Onorato00acb122009-08-04 16:04:30 -040069 private Handler mHandler;
Jeff Brown8ef85c72012-04-13 02:58:38 -070070 private final Vibrator mVibrator;
Joe Onorato00acb122009-08-04 16:04:30 -040071
72 // temporaries to avoid gc thrash
73 private Rect mRectTemp = new Rect();
74 private final int[] mCoordinatesTemp = new int[2];
75
76 /** Whether or not we're dragging. */
77 private boolean mDragging;
78
79 /** X coordinate of the down event. */
Adam Cohene3e27a82011-04-15 12:07:39 -070080 private int mMotionDownX;
Joe Onorato00acb122009-08-04 16:04:30 -040081
82 /** Y coordinate of the down event. */
Adam Cohene3e27a82011-04-15 12:07:39 -070083 private int mMotionDownY;
Joe Onorato00acb122009-08-04 16:04:30 -040084
Joe Onorato658db742010-09-29 11:40:39 -070085 /** the area at the edge of the screen that makes the workspace go left
86 * or right while you're dragging.
87 */
88 private int mScrollZone;
89
Adam Cohen9932a9b2011-08-02 22:14:07 -070090 private DropTarget.DragObject mDragObject;
Joe Onorato00acb122009-08-04 16:04:30 -040091
92 /** Who can receive drop events */
93 private ArrayList<DropTarget> mDropTargets = new ArrayList<DropTarget>();
Patrick Dubroy4ed62782010-08-17 15:11:18 -070094 private ArrayList<DragListener> mListeners = new ArrayList<DragListener>();
Winson Chung043f2af2012-03-01 16:09:54 -080095 private DropTarget mFlingToDeleteDropTarget;
Joe Onorato00acb122009-08-04 16:04:30 -040096
97 /** The window token used as the parent for the DragView. */
98 private IBinder mWindowToken;
99
100 /** The view that will be scrolled when dragging to the left and right edges of the screen. */
101 private View mScrollView;
102
Romain Guyea3763c2010-01-11 18:02:04 -0800103 private View mMoveTarget;
104
Joe Onorato00acb122009-08-04 16:04:30 -0400105 private DragScroller mDragScroller;
106 private int mScrollState = SCROLL_OUTSIDE_ZONE;
107 private ScrollRunnable mScrollRunnable = new ScrollRunnable();
108
Joe Onorato00acb122009-08-04 16:04:30 -0400109 private DropTarget mLastDropTarget;
110
111 private InputMethodManager mInputMethodManager;
112
Patrick Dubroya16fd5a2010-10-07 16:47:28 -0700113 private int mLastTouch[] = new int[2];
Winson Chung318eee02012-04-12 10:59:27 -0700114 private long mLastTouchUpTime = -1;
Patrick Dubroya16fd5a2010-10-07 16:47:28 -0700115 private int mDistanceSinceScroll = 0;
116
Winson Chung273c1022011-07-11 13:40:52 -0700117 private int mTmpPoint[] = new int[2];
118 private Rect mDragLayerRect = new Rect();
119
Winson Chung043f2af2012-03-01 16:09:54 -0800120 protected int mFlingToDeleteThresholdVelocity;
121 private VelocityTracker mVelocityTracker;
122
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800123 /**
124 * Interface to receive notifications when a drag starts or stops
125 */
126 interface DragListener {
127
128 /**
129 * A drag has begun
130 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800131 * @param source An object representing where the drag originated
132 * @param info The data associated with the object that is being dragged
133 * @param dragAction The drag action: either {@link DragController#DRAG_ACTION_MOVE}
134 * or {@link DragController#DRAG_ACTION_COPY}
135 */
Joe Onorato5162ea92009-09-03 09:39:42 -0700136 void onDragStart(DragSource source, Object info, int dragAction);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800137
138 /**
Winson Chunge3193b92010-09-10 11:44:42 -0700139 * The drag has ended
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800140 */
141 void onDragEnd();
142 }
143
144 /**
Joe Onorato00acb122009-08-04 16:04:30 -0400145 * Used to create a new DragLayer from XML.
146 *
147 * @param context The application's context.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800148 */
Adam Cohen8dfcba42011-07-07 16:38:18 -0700149 public DragController(Launcher launcher) {
150 mLauncher = launcher;
Joe Onorato00acb122009-08-04 16:04:30 -0400151 mHandler = new Handler();
Adam Cohen8dfcba42011-07-07 16:38:18 -0700152 mScrollZone = launcher.getResources().getDimensionPixelSize(R.dimen.scroll_zone);
Winson Chung043f2af2012-03-01 16:09:54 -0800153 mVelocityTracker = VelocityTracker.obtain();
Jeff Brown8ef85c72012-04-13 02:58:38 -0700154 mVibrator = (Vibrator)launcher.getSystemService(Context.VIBRATOR_SERVICE);
Winson Chung043f2af2012-03-01 16:09:54 -0800155
156 float density = launcher.getResources().getDisplayMetrics().density;
157 mFlingToDeleteThresholdVelocity = (int) (FLING_TO_DELETE_THRESHOLD_Y_VELOCITY * density);
Joe Onorato00acb122009-08-04 16:04:30 -0400158 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800159
Patrick Dubroy1262e362010-10-06 15:49:50 -0700160 public boolean dragging() {
161 return mDragging;
162 }
163
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800164 /**
Joe Onorato5162ea92009-09-03 09:39:42 -0700165 * Starts a drag.
Michael Jurkaa63c4522010-08-19 13:52:27 -0700166 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800167 * @param v The view that is being dragged
168 * @param source An object representing where the drag originated
Romain Guyea3763c2010-01-11 18:02:04 -0800169 * @param dragInfo The data associated with the object that is being dragged
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800170 * @param dragAction The drag action: either {@link #DRAG_ACTION_MOVE} or
171 * {@link #DRAG_ACTION_COPY}
172 */
Joe Onorato00acb122009-08-04 16:04:30 -0400173 public void startDrag(View v, DragSource source, Object dragInfo, int dragAction) {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700174 startDrag(v, source, dragInfo, dragAction, null);
175 }
176
177 /**
178 * Starts a drag.
179 *
180 * @param v The view that is being dragged
181 * @param source An object representing where the drag originated
182 * @param dragInfo The data associated with the object that is being dragged
183 * @param dragAction The drag action: either {@link #DRAG_ACTION_MOVE} or
184 * {@link #DRAG_ACTION_COPY}
185 * @param dragRegion Coordinates within the bitmap b for the position of item being dragged.
186 * Makes dragging feel more precise, e.g. you can clip out a transparent border
187 */
188 public void startDrag(View v, DragSource source, Object dragInfo, int dragAction,
189 Rect dragRegion) {
Joe Onorato5162ea92009-09-03 09:39:42 -0700190 Bitmap b = getViewBitmap(v);
191
Daniel Sandler3f8175a2010-05-25 11:48:32 -0400192 if (b == null) {
193 // out of memory?
194 return;
195 }
196
Joe Onorato5162ea92009-09-03 09:39:42 -0700197 int[] loc = mCoordinatesTemp;
Adam Cohen8dfcba42011-07-07 16:38:18 -0700198 mLauncher.getDragLayer().getLocationInDragLayer(v, loc);
199 int dragLayerX = loc[0];
200 int dragLayerY = loc[1];
Joe Onorato5162ea92009-09-03 09:39:42 -0700201
Winson Chung72d59842012-02-22 13:51:36 -0800202 startDrag(b, dragLayerX, dragLayerY, source, dragInfo, dragAction, null, dragRegion, 1f);
Joe Onorato5162ea92009-09-03 09:39:42 -0700203 b.recycle();
204
205 if (dragAction == DRAG_ACTION_MOVE) {
206 v.setVisibility(View.GONE);
207 }
208 }
209
210 /**
211 * Starts a drag.
Michael Jurkaa63c4522010-08-19 13:52:27 -0700212 *
Winson Chunge3193b92010-09-10 11:44:42 -0700213 * @param v The view that is being dragged
214 * @param bmp The bitmap that represents the view being dragged
215 * @param source An object representing where the drag originated
216 * @param dragInfo The data associated with the object that is being dragged
217 * @param dragAction The drag action: either {@link #DRAG_ACTION_MOVE} or
218 * {@link #DRAG_ACTION_COPY}
219 * @param dragRegion Coordinates within the bitmap b for the position of item being dragged.
220 * Makes dragging feel more precise, e.g. you can clip out a transparent border
221 */
222 public void startDrag(View v, Bitmap bmp, DragSource source, Object dragInfo, int dragAction,
Winson Chung72d59842012-02-22 13:51:36 -0800223 Rect dragRegion, float initialDragViewScale) {
Winson Chunge3193b92010-09-10 11:44:42 -0700224 int[] loc = mCoordinatesTemp;
Adam Cohen8dfcba42011-07-07 16:38:18 -0700225 mLauncher.getDragLayer().getLocationInDragLayer(v, loc);
Winson Chung72d59842012-02-22 13:51:36 -0800226 int dragLayerX = loc[0] + v.getPaddingLeft() +
227 (int) ((initialDragViewScale * bmp.getWidth() - bmp.getWidth()) / 2);
228 int dragLayerY = loc[1] + v.getPaddingTop() +
229 (int) ((initialDragViewScale * bmp.getHeight() - bmp.getHeight()) / 2);
Winson Chunge3193b92010-09-10 11:44:42 -0700230
Winson Chung72d59842012-02-22 13:51:36 -0800231 startDrag(bmp, dragLayerX, dragLayerY, source, dragInfo, dragAction, null, dragRegion,
232 initialDragViewScale);
Winson Chunge3193b92010-09-10 11:44:42 -0700233
234 if (dragAction == DRAG_ACTION_MOVE) {
235 v.setVisibility(View.GONE);
236 }
237 }
238
239 /**
240 * Starts a drag.
241 *
Joe Onorato5162ea92009-09-03 09:39:42 -0700242 * @param b The bitmap to display as the drag image. It will be re-scaled to the
243 * enlarged size.
Adam Cohen8dfcba42011-07-07 16:38:18 -0700244 * @param dragLayerX The x position in the DragLayer of the left-top of the bitmap.
245 * @param dragLayerY The y position in the DragLayer of the left-top of the bitmap.
Joe Onorato5162ea92009-09-03 09:39:42 -0700246 * @param source An object representing where the drag originated
Romain Guyea3763c2010-01-11 18:02:04 -0800247 * @param dragInfo The data associated with the object that is being dragged
Joe Onorato5162ea92009-09-03 09:39:42 -0700248 * @param dragAction The drag action: either {@link #DRAG_ACTION_MOVE} or
249 * {@link #DRAG_ACTION_COPY}
Michael Jurkaa63c4522010-08-19 13:52:27 -0700250 * @param dragRegion Coordinates within the bitmap b for the position of item being dragged.
251 * Makes dragging feel more precise, e.g. you can clip out a transparent border
252 */
Adam Cohen8dfcba42011-07-07 16:38:18 -0700253 public void startDrag(Bitmap b, int dragLayerX, int dragLayerY,
Winson Chung72d59842012-02-22 13:51:36 -0800254 DragSource source, Object dragInfo, int dragAction, Point dragOffset, Rect dragRegion,
255 float initialDragViewScale) {
Joe Onorato00acb122009-08-04 16:04:30 -0400256 if (PROFILE_DRAWING_DURING_DRAG) {
257 android.os.Debug.startMethodTracing("Launcher");
258 }
259
260 // Hide soft keyboard, if visible
261 if (mInputMethodManager == null) {
262 mInputMethodManager = (InputMethodManager)
Adam Cohen8dfcba42011-07-07 16:38:18 -0700263 mLauncher.getSystemService(Context.INPUT_METHOD_SERVICE);
Joe Onorato00acb122009-08-04 16:04:30 -0400264 }
265 mInputMethodManager.hideSoftInputFromWindow(mWindowToken, 0);
266
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700267 for (DragListener listener : mListeners) {
268 listener.onDragStart(source, dragInfo, dragAction);
Joe Onorato00acb122009-08-04 16:04:30 -0400269 }
270
Adam Cohen8dfcba42011-07-07 16:38:18 -0700271 final int registrationX = mMotionDownX - dragLayerX;
272 final int registrationY = mMotionDownY - dragLayerY;
Joe Onorato00acb122009-08-04 16:04:30 -0400273
Michael Jurkaa63c4522010-08-19 13:52:27 -0700274 final int dragRegionLeft = dragRegion == null ? 0 : dragRegion.left;
275 final int dragRegionTop = dragRegion == null ? 0 : dragRegion.top;
Adam Cohene3e27a82011-04-15 12:07:39 -0700276
Joe Onorato00acb122009-08-04 16:04:30 -0400277 mDragging = true;
Adam Cohencb3382b2011-05-24 14:07:08 -0700278
Adam Cohen9932a9b2011-08-02 22:14:07 -0700279 mDragObject = new DropTarget.DragObject();
280
Adam Cohenbfbfd262011-06-13 16:55:12 -0700281 mDragObject.dragComplete = false;
Adam Cohen8dfcba42011-07-07 16:38:18 -0700282 mDragObject.xOffset = mMotionDownX - (dragLayerX + dragRegionLeft);
283 mDragObject.yOffset = mMotionDownY - (dragLayerY + dragRegionTop);
Adam Cohencb3382b2011-05-24 14:07:08 -0700284 mDragObject.dragSource = source;
285 mDragObject.dragInfo = dragInfo;
Joe Onorato00acb122009-08-04 16:04:30 -0400286
287 mVibrator.vibrate(VIBRATE_DURATION);
288
Adam Cohen8dfcba42011-07-07 16:38:18 -0700289 final DragView dragView = mDragObject.dragView = new DragView(mLauncher, b, registrationX,
Winson Chung72d59842012-02-22 13:51:36 -0800290 registrationY, 0, 0, b.getWidth(), b.getHeight(), initialDragViewScale);
Michael Jurkaa63c4522010-08-19 13:52:27 -0700291
Winson Chungb8c69f32011-10-19 21:36:08 -0700292 if (dragOffset != null) {
293 dragView.setDragVisualizeOffset(new Point(dragOffset));
294 }
Michael Jurkaa63c4522010-08-19 13:52:27 -0700295 if (dragRegion != null) {
Adam Cohene3e27a82011-04-15 12:07:39 -0700296 dragView.setDragRegion(new Rect(dragRegion));
Michael Jurkaa63c4522010-08-19 13:52:27 -0700297 }
298
Adam Cohen8dfcba42011-07-07 16:38:18 -0700299 dragView.show(mMotionDownX, mMotionDownY);
300 handleMoveEvent(mMotionDownX, mMotionDownY);
Joe Onorato00acb122009-08-04 16:04:30 -0400301 }
302
303 /**
304 * Draw the view into a bitmap.
305 */
Adam Cohen120980b2010-12-08 11:05:37 -0800306 Bitmap getViewBitmap(View v) {
Joe Onorato00acb122009-08-04 16:04:30 -0400307 v.clearFocus();
308 v.setPressed(false);
309
310 boolean willNotCache = v.willNotCacheDrawing();
311 v.setWillNotCacheDrawing(false);
312
313 // Reset the drawing cache background color to fully transparent
314 // for the duration of this operation
315 int color = v.getDrawingCacheBackgroundColor();
316 v.setDrawingCacheBackgroundColor(0);
Adam Cohen120980b2010-12-08 11:05:37 -0800317 float alpha = v.getAlpha();
318 v.setAlpha(1.0f);
Joe Onorato00acb122009-08-04 16:04:30 -0400319
320 if (color != 0) {
321 v.destroyDrawingCache();
322 }
323 v.buildDrawingCache();
324 Bitmap cacheBitmap = v.getDrawingCache();
Daniel Sandler3f8175a2010-05-25 11:48:32 -0400325 if (cacheBitmap == null) {
326 Log.e(TAG, "failed getViewBitmap(" + v + ")", new RuntimeException());
327 return null;
328 }
Joe Onorato00acb122009-08-04 16:04:30 -0400329
330 Bitmap bitmap = Bitmap.createBitmap(cacheBitmap);
331
332 // Restore the view
333 v.destroyDrawingCache();
Adam Cohen120980b2010-12-08 11:05:37 -0800334 v.setAlpha(alpha);
Joe Onorato00acb122009-08-04 16:04:30 -0400335 v.setWillNotCacheDrawing(willNotCache);
336 v.setDrawingCacheBackgroundColor(color);
337
338 return bitmap;
339 }
340
341 /**
342 * Call this from a drag source view like this:
343 *
344 * <pre>
345 * @Override
346 * public boolean dispatchKeyEvent(KeyEvent event) {
347 * return mDragController.dispatchKeyEvent(this, event)
348 * || super.dispatchKeyEvent(event);
349 * </pre>
350 */
Romain Guyea3763c2010-01-11 18:02:04 -0800351 @SuppressWarnings({"UnusedDeclaration"})
Joe Onorato00acb122009-08-04 16:04:30 -0400352 public boolean dispatchKeyEvent(KeyEvent event) {
353 return mDragging;
354 }
355
Winson Chung304dcde2011-01-07 11:17:23 -0800356 public boolean isDragging() {
357 return mDragging;
358 }
359
Joe Onorato24b6fd82009-11-12 13:47:09 -0800360 /**
361 * Stop dragging without dropping.
362 */
363 public void cancelDrag() {
Winson Chung621e6402011-01-04 16:03:57 -0800364 if (mDragging) {
Winson Chungc07918d2011-07-01 15:35:26 -0700365 if (mLastDropTarget != null) {
366 mLastDropTarget.onDragExit(mDragObject);
367 }
Winson Chung41bb19d2012-03-05 18:36:46 -0800368 mDragObject.deferDragViewCleanupPostAnimation = false;
Adam Cohen36cc09b2011-09-29 17:33:15 -0700369 mDragObject.cancelled = true;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700370 mDragObject.dragComplete = true;
Winson Chunga48487a2012-03-20 16:19:37 -0700371 mDragObject.dragSource.onDropCompleted(null, mDragObject, false, false);
Winson Chung621e6402011-01-04 16:03:57 -0800372 }
Joe Onorato24b6fd82009-11-12 13:47:09 -0800373 endDrag();
374 }
Winson Chunga1820962011-10-03 16:31:06 -0700375 public void onAppsRemoved(ArrayList<ApplicationInfo> apps, Context context) {
376 // Cancel the current drag if we are removing an app that we are dragging
377 if (mDragObject != null) {
378 Object rawDragInfo = mDragObject.dragInfo;
379 if (rawDragInfo instanceof ShortcutInfo) {
380 ShortcutInfo dragInfo = (ShortcutInfo) rawDragInfo;
381 for (ApplicationInfo info : apps) {
Michael Jurka7bcadad2012-04-02 07:23:44 -0700382 // Added null checks to prevent NPE we've seen in the wild
383 if (dragInfo != null &&
384 dragInfo.intent != null &&
385 info.intent != null &&
386 dragInfo.intent.getComponent().equals(info.intent.getComponent())) {
Winson Chunga1820962011-10-03 16:31:06 -0700387 cancelDrag();
388 return;
389 }
390 }
391 }
392 }
393 }
Joe Onorato24b6fd82009-11-12 13:47:09 -0800394
Joe Onorato00acb122009-08-04 16:04:30 -0400395 private void endDrag() {
396 if (mDragging) {
397 mDragging = false;
Winson Chungaa15ffe2012-01-18 15:45:28 -0800398 clearScrollRunnable();
Winson Chung043f2af2012-03-01 16:09:54 -0800399 boolean isDeferred = false;
Adam Cohencb3382b2011-05-24 14:07:08 -0700400 if (mDragObject.dragView != null) {
Winson Chung043f2af2012-03-01 16:09:54 -0800401 isDeferred = mDragObject.deferDragViewCleanupPostAnimation;
402 if (!isDeferred) {
Winson Chung7bd1bbb2012-02-13 18:29:29 -0800403 mDragObject.dragView.remove();
404 }
Adam Cohencb3382b2011-05-24 14:07:08 -0700405 mDragObject.dragView = null;
Joe Onorato00acb122009-08-04 16:04:30 -0400406 }
Winson Chung043f2af2012-03-01 16:09:54 -0800407
408 // Only end the drag if we are not deferred
409 if (!isDeferred) {
410 for (DragListener listener : mListeners) {
411 listener.onDragEnd();
412 }
413 }
414 }
415
416 releaseVelocityTracker();
417 }
418
419 /**
420 * This only gets called as a result of drag view cleanup being deferred in endDrag();
421 */
422 void onDeferredEndDrag(DragView dragView) {
423 dragView.remove();
424
425 // If we skipped calling onDragEnd() before, do it now
426 for (DragListener listener : mListeners) {
427 listener.onDragEnd();
Joe Onorato00acb122009-08-04 16:04:30 -0400428 }
429 }
430
Winson Chunga48487a2012-03-20 16:19:37 -0700431 void onDeferredEndFling(DropTarget.DragObject d) {
432 d.dragSource.onFlingToDeleteCompleted();
433 }
434
Joe Onorato00acb122009-08-04 16:04:30 -0400435 /**
Winson Chung273c1022011-07-11 13:40:52 -0700436 * Clamps the position to the drag layer bounds.
437 */
438 private int[] getClampedDragLayerPos(float x, float y) {
439 mLauncher.getDragLayer().getLocalVisibleRect(mDragLayerRect);
440 mTmpPoint[0] = (int) Math.max(mDragLayerRect.left, Math.min(x, mDragLayerRect.right - 1));
441 mTmpPoint[1] = (int) Math.max(mDragLayerRect.top, Math.min(y, mDragLayerRect.bottom - 1));
442 return mTmpPoint;
443 }
444
Winson Chunga2413752012-04-03 14:22:34 -0700445 long getLastGestureUpTime() {
446 if (mDragging) {
447 return System.currentTimeMillis();
448 } else {
449 return mLastTouchUpTime;
450 }
451 }
452
453 void resetLastGestureUpTime() {
454 mLastTouchUpTime = -1;
455 }
456
Winson Chung273c1022011-07-11 13:40:52 -0700457 /**
Joe Onorato00acb122009-08-04 16:04:30 -0400458 * Call this from a drag source view.
459 */
460 public boolean onInterceptTouchEvent(MotionEvent ev) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400461 if (false) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800462 Log.d(Launcher.TAG, "DragController.onInterceptTouchEvent " + ev + " mDragging="
Joe Onorato9c1289c2009-08-17 11:03:03 -0400463 + mDragging);
464 }
Joe Onorato00acb122009-08-04 16:04:30 -0400465
Winson Chung043f2af2012-03-01 16:09:54 -0800466 // Update the velocity tracker
467 acquireVelocityTrackerAndAddMovement(ev);
468
469 final int action = ev.getAction();
Winson Chung273c1022011-07-11 13:40:52 -0700470 final int[] dragLayerPos = getClampedDragLayerPos(ev.getX(), ev.getY());
471 final int dragLayerX = dragLayerPos[0];
472 final int dragLayerY = dragLayerPos[1];
Joe Onorato00acb122009-08-04 16:04:30 -0400473
474 switch (action) {
475 case MotionEvent.ACTION_MOVE:
476 break;
Joe Onorato00acb122009-08-04 16:04:30 -0400477 case MotionEvent.ACTION_DOWN:
478 // Remember location of down touch
Adam Cohen8dfcba42011-07-07 16:38:18 -0700479 mMotionDownX = dragLayerX;
480 mMotionDownY = dragLayerY;
Joe Onorato00acb122009-08-04 16:04:30 -0400481 mLastDropTarget = null;
482 break;
Joe Onorato00acb122009-08-04 16:04:30 -0400483 case MotionEvent.ACTION_UP:
Winson Chunga2413752012-04-03 14:22:34 -0700484 mLastTouchUpTime = System.currentTimeMillis();
Joe Onorato00acb122009-08-04 16:04:30 -0400485 if (mDragging) {
Winson Chung043f2af2012-03-01 16:09:54 -0800486 PointF vec = isFlingingToDelete(mDragObject.dragSource);
487 if (vec != null) {
488 dropOnFlingToDeleteTarget(dragLayerX, dragLayerY, vec);
489 } else {
490 drop(dragLayerX, dragLayerY);
491 }
Joe Onorato00acb122009-08-04 16:04:30 -0400492 }
493 endDrag();
494 break;
Winson Chung621e6402011-01-04 16:03:57 -0800495 case MotionEvent.ACTION_CANCEL:
496 cancelDrag();
497 break;
Joe Onorato00acb122009-08-04 16:04:30 -0400498 }
499
500 return mDragging;
501 }
502
503 /**
Romain Guyea3763c2010-01-11 18:02:04 -0800504 * Sets the view that should handle move events.
505 */
506 void setMoveTarget(View view) {
507 mMoveTarget = view;
508 }
509
510 public boolean dispatchUnhandledMove(View focused, int direction) {
511 return mMoveTarget != null && mMoveTarget.dispatchUnhandledMove(focused, direction);
512 }
513
Winson Chungaa15ffe2012-01-18 15:45:28 -0800514 private void clearScrollRunnable() {
515 mHandler.removeCallbacks(mScrollRunnable);
516 if (mScrollState == SCROLL_WAITING_IN_ZONE) {
517 mScrollState = SCROLL_OUTSIDE_ZONE;
518 mScrollRunnable.setDirection(SCROLL_RIGHT);
519 mDragScroller.onExitScrollArea();
520 }
521 }
522
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700523 private void handleMoveEvent(int x, int y) {
Adam Cohencb3382b2011-05-24 14:07:08 -0700524 mDragObject.dragView.move(x, y);
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700525
526 // Drop on someone?
527 final int[] coordinates = mCoordinatesTemp;
528 DropTarget dropTarget = findDropTarget(x, y, coordinates);
Adam Cohencb3382b2011-05-24 14:07:08 -0700529 mDragObject.x = coordinates[0];
530 mDragObject.y = coordinates[1];
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700531 if (dropTarget != null) {
Adam Cohencb3382b2011-05-24 14:07:08 -0700532 DropTarget delegate = dropTarget.getDropTargetDelegate(mDragObject);
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700533 if (delegate != null) {
534 dropTarget = delegate;
535 }
536
537 if (mLastDropTarget != dropTarget) {
538 if (mLastDropTarget != null) {
Adam Cohencb3382b2011-05-24 14:07:08 -0700539 mLastDropTarget.onDragExit(mDragObject);
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700540 }
Adam Cohencb3382b2011-05-24 14:07:08 -0700541 dropTarget.onDragEnter(mDragObject);
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700542 }
Adam Cohencb3382b2011-05-24 14:07:08 -0700543 dropTarget.onDragOver(mDragObject);
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700544 } else {
545 if (mLastDropTarget != null) {
Adam Cohencb3382b2011-05-24 14:07:08 -0700546 mLastDropTarget.onDragExit(mDragObject);
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700547 }
548 }
549 mLastDropTarget = dropTarget;
550
Patrick Dubroya16fd5a2010-10-07 16:47:28 -0700551 // After a scroll, the touch point will still be in the scroll region.
552 // Rather than scrolling immediately, require a bit of twiddling to scroll again
Adam Cohen8dfcba42011-07-07 16:38:18 -0700553 final int slop = ViewConfiguration.get(mLauncher).getScaledWindowTouchSlop();
Patrick Dubroya16fd5a2010-10-07 16:47:28 -0700554 mDistanceSinceScroll +=
555 Math.sqrt(Math.pow(mLastTouch[0] - x, 2) + Math.pow(mLastTouch[1] - y, 2));
556 mLastTouch[0] = x;
557 mLastTouch[1] = y;
Winson Chungaa15ffe2012-01-18 15:45:28 -0800558 final int delay = mDistanceSinceScroll < slop ? RESCROLL_DELAY : SCROLL_DELAY;
Patrick Dubroya16fd5a2010-10-07 16:47:28 -0700559
Winson Chung3f4e1422011-11-17 14:58:51 -0800560 if (x < mScrollZone) {
Winson Chungaa15ffe2012-01-18 15:45:28 -0800561 if (mScrollState == SCROLL_OUTSIDE_ZONE) {
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700562 mScrollState = SCROLL_WAITING_IN_ZONE;
Winson Chung3e0839e2011-10-03 15:15:18 -0700563 if (mDragScroller.onEnterScrollArea(x, y, SCROLL_LEFT)) {
564 mScrollRunnable.setDirection(SCROLL_LEFT);
Winson Chungaa15ffe2012-01-18 15:45:28 -0800565 mHandler.postDelayed(mScrollRunnable, delay);
Winson Chung3e0839e2011-10-03 15:15:18 -0700566 }
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700567 }
Winson Chung3f4e1422011-11-17 14:58:51 -0800568 } else if (x > mScrollView.getWidth() - mScrollZone) {
Winson Chungaa15ffe2012-01-18 15:45:28 -0800569 if (mScrollState == SCROLL_OUTSIDE_ZONE) {
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700570 mScrollState = SCROLL_WAITING_IN_ZONE;
Winson Chung3e0839e2011-10-03 15:15:18 -0700571 if (mDragScroller.onEnterScrollArea(x, y, SCROLL_RIGHT)) {
572 mScrollRunnable.setDirection(SCROLL_RIGHT);
Winson Chungaa15ffe2012-01-18 15:45:28 -0800573 mHandler.postDelayed(mScrollRunnable, delay);
Winson Chung3e0839e2011-10-03 15:15:18 -0700574 }
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700575 }
576 } else {
Winson Chungaa15ffe2012-01-18 15:45:28 -0800577 clearScrollRunnable();
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700578 }
579 }
580
Winson Chung3bc21c32012-01-20 13:59:18 -0800581 public void forceMoveEvent() {
582 if (mDragging) {
583 handleMoveEvent(mDragObject.x, mDragObject.y);
584 }
585 }
586
Romain Guyea3763c2010-01-11 18:02:04 -0800587 /**
Joe Onorato00acb122009-08-04 16:04:30 -0400588 * Call this from a drag source view.
589 */
590 public boolean onTouchEvent(MotionEvent ev) {
Joe Onorato00acb122009-08-04 16:04:30 -0400591 if (!mDragging) {
592 return false;
593 }
594
Winson Chung043f2af2012-03-01 16:09:54 -0800595 // Update the velocity tracker
596 acquireVelocityTrackerAndAddMovement(ev);
597
Joe Onorato00acb122009-08-04 16:04:30 -0400598 final int action = ev.getAction();
Winson Chung273c1022011-07-11 13:40:52 -0700599 final int[] dragLayerPos = getClampedDragLayerPos(ev.getX(), ev.getY());
600 final int dragLayerX = dragLayerPos[0];
601 final int dragLayerY = dragLayerPos[1];
Joe Onorato00acb122009-08-04 16:04:30 -0400602
603 switch (action) {
604 case MotionEvent.ACTION_DOWN:
Joe Onorato00acb122009-08-04 16:04:30 -0400605 // Remember where the motion event started
Adam Cohen8dfcba42011-07-07 16:38:18 -0700606 mMotionDownX = dragLayerX;
607 mMotionDownY = dragLayerY;
Joe Onorato00acb122009-08-04 16:04:30 -0400608
Adam Cohen8dfcba42011-07-07 16:38:18 -0700609 if ((dragLayerX < mScrollZone) || (dragLayerX > mScrollView.getWidth() - mScrollZone)) {
Joe Onorato00acb122009-08-04 16:04:30 -0400610 mScrollState = SCROLL_WAITING_IN_ZONE;
611 mHandler.postDelayed(mScrollRunnable, SCROLL_DELAY);
612 } else {
613 mScrollState = SCROLL_OUTSIDE_ZONE;
614 }
Joe Onorato00acb122009-08-04 16:04:30 -0400615 break;
616 case MotionEvent.ACTION_MOVE:
Adam Cohen8dfcba42011-07-07 16:38:18 -0700617 handleMoveEvent(dragLayerX, dragLayerY);
Joe Onorato00acb122009-08-04 16:04:30 -0400618 break;
619 case MotionEvent.ACTION_UP:
Patrick Dubroyb0a6bbe2011-03-02 18:40:21 -0800620 // Ensure that we've processed a move event at the current pointer location.
Adam Cohen8dfcba42011-07-07 16:38:18 -0700621 handleMoveEvent(dragLayerX, dragLayerY);
Winson Chung3bc21c32012-01-20 13:59:18 -0800622 mHandler.removeCallbacks(mScrollRunnable);
Winson Chung043f2af2012-03-01 16:09:54 -0800623
Joe Onorato00acb122009-08-04 16:04:30 -0400624 if (mDragging) {
Winson Chung043f2af2012-03-01 16:09:54 -0800625 PointF vec = isFlingingToDelete(mDragObject.dragSource);
626 if (vec != null) {
627 dropOnFlingToDeleteTarget(dragLayerX, dragLayerY, vec);
628 } else {
629 drop(dragLayerX, dragLayerY);
630 }
Joe Onorato00acb122009-08-04 16:04:30 -0400631 }
632 endDrag();
Joe Onorato00acb122009-08-04 16:04:30 -0400633 break;
634 case MotionEvent.ACTION_CANCEL:
Winson Chung3bc21c32012-01-20 13:59:18 -0800635 mHandler.removeCallbacks(mScrollRunnable);
Joe Onorato24b6fd82009-11-12 13:47:09 -0800636 cancelDrag();
Winson Chung621e6402011-01-04 16:03:57 -0800637 break;
Joe Onorato00acb122009-08-04 16:04:30 -0400638 }
639
640 return true;
641 }
642
Winson Chung043f2af2012-03-01 16:09:54 -0800643 /**
644 * Determines whether the user flung the current item to delete it.
645 *
646 * @return the vector at which the item was flung, or null if no fling was detected.
647 */
648 private PointF isFlingingToDelete(DragSource source) {
649 if (mFlingToDeleteDropTarget == null) return null;
650 if (!source.supportsFlingToDelete()) return null;
651
652 ViewConfiguration config = ViewConfiguration.get(mLauncher);
653 mVelocityTracker.computeCurrentVelocity(1000, config.getScaledMaximumFlingVelocity());
654
655 if (mVelocityTracker.getYVelocity() < mFlingToDeleteThresholdVelocity) {
656 // Do a quick dot product test to ensure that we are flinging upwards
657 PointF vel = new PointF(mVelocityTracker.getXVelocity(),
658 mVelocityTracker.getYVelocity());
659 PointF upVec = new PointF(0f, -1f);
660 float theta = (float) Math.acos(((vel.x * upVec.x) + (vel.y * upVec.y)) /
661 (vel.length() * upVec.length()));
662 if (theta <= Math.toRadians(MAX_FLING_DEGREES)) {
663 return vel;
664 }
665 }
666 return null;
667 }
668
669 private void dropOnFlingToDeleteTarget(float x, float y, PointF vel) {
670 final int[] coordinates = mCoordinatesTemp;
671
672 mDragObject.x = coordinates[0];
673 mDragObject.y = coordinates[1];
Winson Chung043f2af2012-03-01 16:09:54 -0800674
675 // Clean up dragging on the target if it's not the current fling delete target otherwise,
676 // start dragging to it.
677 if (mLastDropTarget != null && mFlingToDeleteDropTarget != mLastDropTarget) {
678 mLastDropTarget.onDragExit(mDragObject);
679 }
680
681 // Drop onto the fling-to-delete target
682 boolean accepted = false;
683 mFlingToDeleteDropTarget.onDragEnter(mDragObject);
Winson Chung232decb2012-03-28 15:09:05 -0700684 // We must set dragComplete to true _only_ after we "enter" the fling-to-delete target for
685 // "drop"
686 mDragObject.dragComplete = true;
Winson Chung043f2af2012-03-01 16:09:54 -0800687 mFlingToDeleteDropTarget.onDragExit(mDragObject);
688 if (mFlingToDeleteDropTarget.acceptDrop(mDragObject)) {
689 mFlingToDeleteDropTarget.onFlingToDelete(mDragObject, mDragObject.x, mDragObject.y,
690 vel);
691 accepted = true;
692 }
Winson Chunga48487a2012-03-20 16:19:37 -0700693 mDragObject.dragSource.onDropCompleted((View) mFlingToDeleteDropTarget, mDragObject, true,
Winson Chung043f2af2012-03-01 16:09:54 -0800694 accepted);
695 }
696
Patrick Dubroyb0a6bbe2011-03-02 18:40:21 -0800697 private void drop(float x, float y) {
Joe Onorato00acb122009-08-04 16:04:30 -0400698 final int[] coordinates = mCoordinatesTemp;
Patrick Dubroyb0a6bbe2011-03-02 18:40:21 -0800699 final DropTarget dropTarget = findDropTarget((int) x, (int) y, coordinates);
Joe Onorato00acb122009-08-04 16:04:30 -0400700
Adam Cohencb3382b2011-05-24 14:07:08 -0700701 mDragObject.x = coordinates[0];
702 mDragObject.y = coordinates[1];
Patrick Dubroyb0a6bbe2011-03-02 18:40:21 -0800703 boolean accepted = false;
Joe Onorato00acb122009-08-04 16:04:30 -0400704 if (dropTarget != null) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700705 mDragObject.dragComplete = true;
Adam Cohencb3382b2011-05-24 14:07:08 -0700706 dropTarget.onDragExit(mDragObject);
707 if (dropTarget.acceptDrop(mDragObject)) {
708 dropTarget.onDrop(mDragObject);
Patrick Dubroyb0a6bbe2011-03-02 18:40:21 -0800709 accepted = true;
Joe Onorato00acb122009-08-04 16:04:30 -0400710 }
711 }
Winson Chunga48487a2012-03-20 16:19:37 -0700712 mDragObject.dragSource.onDropCompleted((View) dropTarget, mDragObject, false, accepted);
Joe Onorato00acb122009-08-04 16:04:30 -0400713 }
714
715 private DropTarget findDropTarget(int x, int y, int[] dropCoordinates) {
716 final Rect r = mRectTemp;
717
718 final ArrayList<DropTarget> dropTargets = mDropTargets;
719 final int count = dropTargets.size();
720 for (int i=count-1; i>=0; i--) {
Patrick Dubroy440c3602010-07-13 17:50:32 -0700721 DropTarget target = dropTargets.get(i);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700722 if (!target.isDropEnabled())
723 continue;
724
Joe Onorato00acb122009-08-04 16:04:30 -0400725 target.getHitRect(r);
Patrick Dubroy440c3602010-07-13 17:50:32 -0700726
Adam Cohen8dfcba42011-07-07 16:38:18 -0700727 // Convert the hit rect to DragLayer coordinates
728 target.getLocationInDragLayer(dropCoordinates);
Joe Onorato00acb122009-08-04 16:04:30 -0400729 r.offset(dropCoordinates[0] - target.getLeft(), dropCoordinates[1] - target.getTop());
Patrick Dubroy440c3602010-07-13 17:50:32 -0700730
Adam Cohencb3382b2011-05-24 14:07:08 -0700731 mDragObject.x = x;
732 mDragObject.y = y;
Joe Onorato00acb122009-08-04 16:04:30 -0400733 if (r.contains(x, y)) {
Adam Cohencb3382b2011-05-24 14:07:08 -0700734 DropTarget delegate = target.getDropTargetDelegate(mDragObject);
Patrick Dubroy440c3602010-07-13 17:50:32 -0700735 if (delegate != null) {
736 target = delegate;
Adam Cohen8dfcba42011-07-07 16:38:18 -0700737 target.getLocationInDragLayer(dropCoordinates);
Patrick Dubroy440c3602010-07-13 17:50:32 -0700738 }
739
740 // Make dropCoordinates relative to the DropTarget
Joe Onorato00acb122009-08-04 16:04:30 -0400741 dropCoordinates[0] = x - dropCoordinates[0];
742 dropCoordinates[1] = y - dropCoordinates[1];
Patrick Dubroy440c3602010-07-13 17:50:32 -0700743
Joe Onorato00acb122009-08-04 16:04:30 -0400744 return target;
745 }
746 }
747 return null;
748 }
749
750 public void setDragScoller(DragScroller scroller) {
751 mDragScroller = scroller;
752 }
753
754 public void setWindowToken(IBinder token) {
755 mWindowToken = token;
756 }
757
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800758 /**
759 * Sets the drag listner which will be notified when a drag starts or ends.
760 */
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700761 public void addDragListener(DragListener l) {
762 mListeners.add(l);
Joe Onorato00acb122009-08-04 16:04:30 -0400763 }
764
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800765 /**
766 * Remove a previously installed drag listener.
767 */
Joe Onorato00acb122009-08-04 16:04:30 -0400768 public void removeDragListener(DragListener l) {
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700769 mListeners.remove(l);
Joe Onorato00acb122009-08-04 16:04:30 -0400770 }
771
772 /**
773 * Add a DropTarget to the list of potential places to receive drop events.
774 */
775 public void addDropTarget(DropTarget target) {
776 mDropTargets.add(target);
777 }
778
779 /**
780 * Don't send drop events to <em>target</em> any more.
781 */
782 public void removeDropTarget(DropTarget target) {
783 mDropTargets.remove(target);
784 }
785
786 /**
Winson Chung043f2af2012-03-01 16:09:54 -0800787 * Sets the current fling-to-delete drop target.
788 */
789 public void setFlingToDeleteDropTarget(DropTarget target) {
790 mFlingToDeleteDropTarget = target;
791 }
792
793 private void acquireVelocityTrackerAndAddMovement(MotionEvent ev) {
794 if (mVelocityTracker == null) {
795 mVelocityTracker = VelocityTracker.obtain();
796 }
797 mVelocityTracker.addMovement(ev);
798 }
799
800 private void releaseVelocityTracker() {
801 if (mVelocityTracker != null) {
802 mVelocityTracker.recycle();
803 mVelocityTracker = null;
804 }
805 }
806
807 /**
Joe Onorato00acb122009-08-04 16:04:30 -0400808 * Set which view scrolls for touch events near the edge of the screen.
809 */
810 public void setScrollView(View v) {
811 mScrollView = v;
812 }
813
Patrick Dubroy5f445422011-02-18 14:35:21 -0800814 DragView getDragView() {
Adam Cohencb3382b2011-05-24 14:07:08 -0700815 return mDragObject.dragView;
Patrick Dubroy5f445422011-02-18 14:35:21 -0800816 }
817
Joe Onorato00acb122009-08-04 16:04:30 -0400818 private class ScrollRunnable implements Runnable {
819 private int mDirection;
820
821 ScrollRunnable() {
822 }
823
824 public void run() {
825 if (mDragScroller != null) {
826 if (mDirection == SCROLL_LEFT) {
827 mDragScroller.scrollLeft();
828 } else {
829 mDragScroller.scrollRight();
830 }
831 mScrollState = SCROLL_OUTSIDE_ZONE;
Patrick Dubroya16fd5a2010-10-07 16:47:28 -0700832 mDistanceSinceScroll = 0;
833 mDragScroller.onExitScrollArea();
Winson Chungaa15ffe2012-01-18 15:45:28 -0800834
835 if (isDragging()) {
836 // Force an update so that we can requeue the scroller if necessary
Winson Chung3bc21c32012-01-20 13:59:18 -0800837 forceMoveEvent();
Winson Chungaa15ffe2012-01-18 15:45:28 -0800838 }
Joe Onorato00acb122009-08-04 16:04:30 -0400839 }
840 }
841
842 void setDirection(int direction) {
843 mDirection = direction;
844 }
845 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800846}