blob: d63743fd3d10b8e108e633cd6ff928ada92a7d8e [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 {
Joe Onorato2e5c4322009-10-06 12:34:42 -070043 private static final String TAG = "Launcher.DragController";
44
Joe Onorato00acb122009-08-04 16:04:30 -040045 /** Indicates the drag is a move. */
46 public static int DRAG_ACTION_MOVE = 0;
47
48 /** Indicates the drag is a copy. */
49 public static int DRAG_ACTION_COPY = 1;
50
Winson Chungaa15ffe2012-01-18 15:45:28 -080051 private static final int SCROLL_DELAY = 500;
52 private static final int RESCROLL_DELAY = 750;
Winson Chung61b0c692012-02-23 16:31:13 -080053 private static final int VIBRATE_DURATION = 15;
Joe Onorato00acb122009-08-04 16:04:30 -040054
55 private static final boolean PROFILE_DRAWING_DURING_DRAG = false;
56
57 private static final int SCROLL_OUTSIDE_ZONE = 0;
58 private static final int SCROLL_WAITING_IN_ZONE = 1;
59
Patrick Dubroy54fa3b92010-11-17 12:18:45 -080060 static final int SCROLL_NONE = -1;
Patrick Dubroy1262e362010-10-06 15:49:50 -070061 static final int SCROLL_LEFT = 0;
62 static final int SCROLL_RIGHT = 1;
Joe Onorato00acb122009-08-04 16:04:30 -040063
Winson Chung043f2af2012-03-01 16:09:54 -080064 private static final float MAX_FLING_DEGREES = 35f;
Winson Chung9658b1e2012-04-09 18:30:07 -070065 private static final int FLING_TO_DELETE_THRESHOLD_Y_VELOCITY = -1500;
Winson Chung043f2af2012-03-01 16:09:54 -080066
Adam Cohen8dfcba42011-07-07 16:38:18 -070067 private Launcher mLauncher;
Joe Onorato00acb122009-08-04 16:04:30 -040068 private Handler mHandler;
Jeff Brown8ef85c72012-04-13 02:58:38 -070069 private final Vibrator mVibrator;
Joe Onorato00acb122009-08-04 16:04:30 -040070
71 // temporaries to avoid gc thrash
72 private Rect mRectTemp = new Rect();
73 private final int[] mCoordinatesTemp = new int[2];
74
75 /** Whether or not we're dragging. */
76 private boolean mDragging;
77
78 /** X coordinate of the down event. */
Adam Cohene3e27a82011-04-15 12:07:39 -070079 private int mMotionDownX;
Joe Onorato00acb122009-08-04 16:04:30 -040080
81 /** Y coordinate of the down event. */
Adam Cohene3e27a82011-04-15 12:07:39 -070082 private int mMotionDownY;
Joe Onorato00acb122009-08-04 16:04:30 -040083
Joe Onorato658db742010-09-29 11:40:39 -070084 /** the area at the edge of the screen that makes the workspace go left
85 * or right while you're dragging.
86 */
87 private int mScrollZone;
88
Adam Cohen9932a9b2011-08-02 22:14:07 -070089 private DropTarget.DragObject mDragObject;
Joe Onorato00acb122009-08-04 16:04:30 -040090
91 /** Who can receive drop events */
92 private ArrayList<DropTarget> mDropTargets = new ArrayList<DropTarget>();
Patrick Dubroy4ed62782010-08-17 15:11:18 -070093 private ArrayList<DragListener> mListeners = new ArrayList<DragListener>();
Winson Chung043f2af2012-03-01 16:09:54 -080094 private DropTarget mFlingToDeleteDropTarget;
Joe Onorato00acb122009-08-04 16:04:30 -040095
96 /** The window token used as the parent for the DragView. */
97 private IBinder mWindowToken;
98
99 /** The view that will be scrolled when dragging to the left and right edges of the screen. */
100 private View mScrollView;
101
Romain Guyea3763c2010-01-11 18:02:04 -0800102 private View mMoveTarget;
103
Joe Onorato00acb122009-08-04 16:04:30 -0400104 private DragScroller mDragScroller;
105 private int mScrollState = SCROLL_OUTSIDE_ZONE;
106 private ScrollRunnable mScrollRunnable = new ScrollRunnable();
107
Joe Onorato00acb122009-08-04 16:04:30 -0400108 private DropTarget mLastDropTarget;
109
110 private InputMethodManager mInputMethodManager;
111
Patrick Dubroya16fd5a2010-10-07 16:47:28 -0700112 private int mLastTouch[] = new int[2];
Winson Chung318eee02012-04-12 10:59:27 -0700113 private long mLastTouchUpTime = -1;
Patrick Dubroya16fd5a2010-10-07 16:47:28 -0700114 private int mDistanceSinceScroll = 0;
115
Winson Chung273c1022011-07-11 13:40:52 -0700116 private int mTmpPoint[] = new int[2];
117 private Rect mDragLayerRect = new Rect();
118
Winson Chung043f2af2012-03-01 16:09:54 -0800119 protected int mFlingToDeleteThresholdVelocity;
120 private VelocityTracker mVelocityTracker;
121
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800122 /**
123 * Interface to receive notifications when a drag starts or stops
124 */
125 interface DragListener {
126
127 /**
128 * A drag has begun
129 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800130 * @param source An object representing where the drag originated
131 * @param info The data associated with the object that is being dragged
132 * @param dragAction The drag action: either {@link DragController#DRAG_ACTION_MOVE}
133 * or {@link DragController#DRAG_ACTION_COPY}
134 */
Joe Onorato5162ea92009-09-03 09:39:42 -0700135 void onDragStart(DragSource source, Object info, int dragAction);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800136
137 /**
Winson Chunge3193b92010-09-10 11:44:42 -0700138 * The drag has ended
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800139 */
140 void onDragEnd();
141 }
142
143 /**
Joe Onorato00acb122009-08-04 16:04:30 -0400144 * Used to create a new DragLayer from XML.
145 *
146 * @param context The application's context.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800147 */
Adam Cohen8dfcba42011-07-07 16:38:18 -0700148 public DragController(Launcher launcher) {
149 mLauncher = launcher;
Joe Onorato00acb122009-08-04 16:04:30 -0400150 mHandler = new Handler();
Adam Cohen8dfcba42011-07-07 16:38:18 -0700151 mScrollZone = launcher.getResources().getDimensionPixelSize(R.dimen.scroll_zone);
Winson Chung043f2af2012-03-01 16:09:54 -0800152 mVelocityTracker = VelocityTracker.obtain();
Jeff Brown8ef85c72012-04-13 02:58:38 -0700153 mVibrator = (Vibrator)launcher.getSystemService(Context.VIBRATOR_SERVICE);
Winson Chung043f2af2012-03-01 16:09:54 -0800154
155 float density = launcher.getResources().getDisplayMetrics().density;
156 mFlingToDeleteThresholdVelocity = (int) (FLING_TO_DELETE_THRESHOLD_Y_VELOCITY * density);
Joe Onorato00acb122009-08-04 16:04:30 -0400157 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800158
Patrick Dubroy1262e362010-10-06 15:49:50 -0700159 public boolean dragging() {
160 return mDragging;
161 }
162
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800163 /**
Joe Onorato5162ea92009-09-03 09:39:42 -0700164 * Starts a drag.
Michael Jurkaa63c4522010-08-19 13:52:27 -0700165 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800166 * @param v The view that is being dragged
167 * @param source An object representing where the drag originated
Romain Guyea3763c2010-01-11 18:02:04 -0800168 * @param dragInfo The data associated with the object that is being dragged
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800169 * @param dragAction The drag action: either {@link #DRAG_ACTION_MOVE} or
170 * {@link #DRAG_ACTION_COPY}
171 */
Joe Onorato00acb122009-08-04 16:04:30 -0400172 public void startDrag(View v, DragSource source, Object dragInfo, int dragAction) {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700173 startDrag(v, source, dragInfo, dragAction, null);
174 }
175
176 /**
177 * Starts a drag.
178 *
179 * @param v The view that is being dragged
180 * @param source An object representing where the drag originated
181 * @param dragInfo The data associated with the object that is being dragged
182 * @param dragAction The drag action: either {@link #DRAG_ACTION_MOVE} or
183 * {@link #DRAG_ACTION_COPY}
184 * @param dragRegion Coordinates within the bitmap b for the position of item being dragged.
185 * Makes dragging feel more precise, e.g. you can clip out a transparent border
186 */
187 public void startDrag(View v, DragSource source, Object dragInfo, int dragAction,
188 Rect dragRegion) {
Joe Onorato5162ea92009-09-03 09:39:42 -0700189 Bitmap b = getViewBitmap(v);
190
Daniel Sandler3f8175a2010-05-25 11:48:32 -0400191 if (b == null) {
192 // out of memory?
193 return;
194 }
195
Joe Onorato5162ea92009-09-03 09:39:42 -0700196 int[] loc = mCoordinatesTemp;
Adam Cohen8dfcba42011-07-07 16:38:18 -0700197 mLauncher.getDragLayer().getLocationInDragLayer(v, loc);
198 int dragLayerX = loc[0];
199 int dragLayerY = loc[1];
Joe Onorato5162ea92009-09-03 09:39:42 -0700200
Winson Chung72d59842012-02-22 13:51:36 -0800201 startDrag(b, dragLayerX, dragLayerY, source, dragInfo, dragAction, null, dragRegion, 1f);
Joe Onorato5162ea92009-09-03 09:39:42 -0700202 b.recycle();
203
204 if (dragAction == DRAG_ACTION_MOVE) {
205 v.setVisibility(View.GONE);
206 }
207 }
208
209 /**
210 * Starts a drag.
Michael Jurkaa63c4522010-08-19 13:52:27 -0700211 *
Winson Chunge3193b92010-09-10 11:44:42 -0700212 * @param v The view that is being dragged
213 * @param bmp The bitmap that represents the view being dragged
214 * @param source An object representing where the drag originated
215 * @param dragInfo The data associated with the object that is being dragged
216 * @param dragAction The drag action: either {@link #DRAG_ACTION_MOVE} or
217 * {@link #DRAG_ACTION_COPY}
218 * @param dragRegion Coordinates within the bitmap b for the position of item being dragged.
219 * Makes dragging feel more precise, e.g. you can clip out a transparent border
220 */
221 public void startDrag(View v, Bitmap bmp, DragSource source, Object dragInfo, int dragAction,
Winson Chung72d59842012-02-22 13:51:36 -0800222 Rect dragRegion, float initialDragViewScale) {
Winson Chunge3193b92010-09-10 11:44:42 -0700223 int[] loc = mCoordinatesTemp;
Adam Cohen8dfcba42011-07-07 16:38:18 -0700224 mLauncher.getDragLayer().getLocationInDragLayer(v, loc);
Winson Chung72d59842012-02-22 13:51:36 -0800225 int dragLayerX = loc[0] + v.getPaddingLeft() +
226 (int) ((initialDragViewScale * bmp.getWidth() - bmp.getWidth()) / 2);
227 int dragLayerY = loc[1] + v.getPaddingTop() +
228 (int) ((initialDragViewScale * bmp.getHeight() - bmp.getHeight()) / 2);
Winson Chunge3193b92010-09-10 11:44:42 -0700229
Winson Chung72d59842012-02-22 13:51:36 -0800230 startDrag(bmp, dragLayerX, dragLayerY, source, dragInfo, dragAction, null, dragRegion,
231 initialDragViewScale);
Winson Chunge3193b92010-09-10 11:44:42 -0700232
233 if (dragAction == DRAG_ACTION_MOVE) {
234 v.setVisibility(View.GONE);
235 }
236 }
237
238 /**
239 * Starts a drag.
240 *
Joe Onorato5162ea92009-09-03 09:39:42 -0700241 * @param b The bitmap to display as the drag image. It will be re-scaled to the
242 * enlarged size.
Adam Cohen8dfcba42011-07-07 16:38:18 -0700243 * @param dragLayerX The x position in the DragLayer of the left-top of the bitmap.
244 * @param dragLayerY The y position in the DragLayer of the left-top of the bitmap.
Joe Onorato5162ea92009-09-03 09:39:42 -0700245 * @param source An object representing where the drag originated
Romain Guyea3763c2010-01-11 18:02:04 -0800246 * @param dragInfo The data associated with the object that is being dragged
Joe Onorato5162ea92009-09-03 09:39:42 -0700247 * @param dragAction The drag action: either {@link #DRAG_ACTION_MOVE} or
248 * {@link #DRAG_ACTION_COPY}
Michael Jurkaa63c4522010-08-19 13:52:27 -0700249 * @param dragRegion Coordinates within the bitmap b for the position of item being dragged.
250 * Makes dragging feel more precise, e.g. you can clip out a transparent border
251 */
Adam Cohen8dfcba42011-07-07 16:38:18 -0700252 public void startDrag(Bitmap b, int dragLayerX, int dragLayerY,
Winson Chung72d59842012-02-22 13:51:36 -0800253 DragSource source, Object dragInfo, int dragAction, Point dragOffset, Rect dragRegion,
254 float initialDragViewScale) {
Joe Onorato00acb122009-08-04 16:04:30 -0400255 if (PROFILE_DRAWING_DURING_DRAG) {
256 android.os.Debug.startMethodTracing("Launcher");
257 }
258
259 // Hide soft keyboard, if visible
260 if (mInputMethodManager == null) {
261 mInputMethodManager = (InputMethodManager)
Adam Cohen8dfcba42011-07-07 16:38:18 -0700262 mLauncher.getSystemService(Context.INPUT_METHOD_SERVICE);
Joe Onorato00acb122009-08-04 16:04:30 -0400263 }
264 mInputMethodManager.hideSoftInputFromWindow(mWindowToken, 0);
265
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700266 for (DragListener listener : mListeners) {
267 listener.onDragStart(source, dragInfo, dragAction);
Joe Onorato00acb122009-08-04 16:04:30 -0400268 }
269
Adam Cohen8dfcba42011-07-07 16:38:18 -0700270 final int registrationX = mMotionDownX - dragLayerX;
271 final int registrationY = mMotionDownY - dragLayerY;
Joe Onorato00acb122009-08-04 16:04:30 -0400272
Michael Jurkaa63c4522010-08-19 13:52:27 -0700273 final int dragRegionLeft = dragRegion == null ? 0 : dragRegion.left;
274 final int dragRegionTop = dragRegion == null ? 0 : dragRegion.top;
Adam Cohene3e27a82011-04-15 12:07:39 -0700275
Joe Onorato00acb122009-08-04 16:04:30 -0400276 mDragging = true;
Adam Cohencb3382b2011-05-24 14:07:08 -0700277
Adam Cohen9932a9b2011-08-02 22:14:07 -0700278 mDragObject = new DropTarget.DragObject();
279
Adam Cohenbfbfd262011-06-13 16:55:12 -0700280 mDragObject.dragComplete = false;
Adam Cohen8dfcba42011-07-07 16:38:18 -0700281 mDragObject.xOffset = mMotionDownX - (dragLayerX + dragRegionLeft);
282 mDragObject.yOffset = mMotionDownY - (dragLayerY + dragRegionTop);
Adam Cohencb3382b2011-05-24 14:07:08 -0700283 mDragObject.dragSource = source;
284 mDragObject.dragInfo = dragInfo;
Joe Onorato00acb122009-08-04 16:04:30 -0400285
286 mVibrator.vibrate(VIBRATE_DURATION);
287
Adam Cohen8dfcba42011-07-07 16:38:18 -0700288 final DragView dragView = mDragObject.dragView = new DragView(mLauncher, b, registrationX,
Winson Chung72d59842012-02-22 13:51:36 -0800289 registrationY, 0, 0, b.getWidth(), b.getHeight(), initialDragViewScale);
Michael Jurkaa63c4522010-08-19 13:52:27 -0700290
Winson Chungb8c69f32011-10-19 21:36:08 -0700291 if (dragOffset != null) {
292 dragView.setDragVisualizeOffset(new Point(dragOffset));
293 }
Michael Jurkaa63c4522010-08-19 13:52:27 -0700294 if (dragRegion != null) {
Adam Cohene3e27a82011-04-15 12:07:39 -0700295 dragView.setDragRegion(new Rect(dragRegion));
Michael Jurkaa63c4522010-08-19 13:52:27 -0700296 }
297
Adam Cohen8dfcba42011-07-07 16:38:18 -0700298 dragView.show(mMotionDownX, mMotionDownY);
299 handleMoveEvent(mMotionDownX, mMotionDownY);
Joe Onorato00acb122009-08-04 16:04:30 -0400300 }
301
302 /**
303 * Draw the view into a bitmap.
304 */
Adam Cohen120980b2010-12-08 11:05:37 -0800305 Bitmap getViewBitmap(View v) {
Joe Onorato00acb122009-08-04 16:04:30 -0400306 v.clearFocus();
307 v.setPressed(false);
308
309 boolean willNotCache = v.willNotCacheDrawing();
310 v.setWillNotCacheDrawing(false);
311
312 // Reset the drawing cache background color to fully transparent
313 // for the duration of this operation
314 int color = v.getDrawingCacheBackgroundColor();
315 v.setDrawingCacheBackgroundColor(0);
Adam Cohen120980b2010-12-08 11:05:37 -0800316 float alpha = v.getAlpha();
317 v.setAlpha(1.0f);
Joe Onorato00acb122009-08-04 16:04:30 -0400318
319 if (color != 0) {
320 v.destroyDrawingCache();
321 }
322 v.buildDrawingCache();
323 Bitmap cacheBitmap = v.getDrawingCache();
Daniel Sandler3f8175a2010-05-25 11:48:32 -0400324 if (cacheBitmap == null) {
325 Log.e(TAG, "failed getViewBitmap(" + v + ")", new RuntimeException());
326 return null;
327 }
Joe Onorato00acb122009-08-04 16:04:30 -0400328
329 Bitmap bitmap = Bitmap.createBitmap(cacheBitmap);
330
331 // Restore the view
332 v.destroyDrawingCache();
Adam Cohen120980b2010-12-08 11:05:37 -0800333 v.setAlpha(alpha);
Joe Onorato00acb122009-08-04 16:04:30 -0400334 v.setWillNotCacheDrawing(willNotCache);
335 v.setDrawingCacheBackgroundColor(color);
336
337 return bitmap;
338 }
339
340 /**
341 * Call this from a drag source view like this:
342 *
343 * <pre>
344 * @Override
345 * public boolean dispatchKeyEvent(KeyEvent event) {
346 * return mDragController.dispatchKeyEvent(this, event)
347 * || super.dispatchKeyEvent(event);
348 * </pre>
349 */
350 public boolean dispatchKeyEvent(KeyEvent event) {
351 return mDragging;
352 }
353
Winson Chung304dcde2011-01-07 11:17:23 -0800354 public boolean isDragging() {
355 return mDragging;
356 }
357
Joe Onorato24b6fd82009-11-12 13:47:09 -0800358 /**
359 * Stop dragging without dropping.
360 */
361 public void cancelDrag() {
Winson Chung621e6402011-01-04 16:03:57 -0800362 if (mDragging) {
Winson Chungc07918d2011-07-01 15:35:26 -0700363 if (mLastDropTarget != null) {
364 mLastDropTarget.onDragExit(mDragObject);
365 }
Winson Chung41bb19d2012-03-05 18:36:46 -0800366 mDragObject.deferDragViewCleanupPostAnimation = false;
Adam Cohen36cc09b2011-09-29 17:33:15 -0700367 mDragObject.cancelled = true;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700368 mDragObject.dragComplete = true;
Winson Chunga48487a2012-03-20 16:19:37 -0700369 mDragObject.dragSource.onDropCompleted(null, mDragObject, false, false);
Winson Chung621e6402011-01-04 16:03:57 -0800370 }
Joe Onorato24b6fd82009-11-12 13:47:09 -0800371 endDrag();
372 }
Winson Chunga1820962011-10-03 16:31:06 -0700373 public void onAppsRemoved(ArrayList<ApplicationInfo> apps, Context context) {
374 // Cancel the current drag if we are removing an app that we are dragging
375 if (mDragObject != null) {
376 Object rawDragInfo = mDragObject.dragInfo;
377 if (rawDragInfo instanceof ShortcutInfo) {
378 ShortcutInfo dragInfo = (ShortcutInfo) rawDragInfo;
379 for (ApplicationInfo info : apps) {
Michael Jurka7bcadad2012-04-02 07:23:44 -0700380 // Added null checks to prevent NPE we've seen in the wild
381 if (dragInfo != null &&
382 dragInfo.intent != null &&
383 info.intent != null &&
384 dragInfo.intent.getComponent().equals(info.intent.getComponent())) {
Winson Chunga1820962011-10-03 16:31:06 -0700385 cancelDrag();
386 return;
387 }
388 }
389 }
390 }
391 }
Joe Onorato24b6fd82009-11-12 13:47:09 -0800392
Joe Onorato00acb122009-08-04 16:04:30 -0400393 private void endDrag() {
394 if (mDragging) {
395 mDragging = false;
Winson Chungaa15ffe2012-01-18 15:45:28 -0800396 clearScrollRunnable();
Winson Chung043f2af2012-03-01 16:09:54 -0800397 boolean isDeferred = false;
Adam Cohencb3382b2011-05-24 14:07:08 -0700398 if (mDragObject.dragView != null) {
Winson Chung043f2af2012-03-01 16:09:54 -0800399 isDeferred = mDragObject.deferDragViewCleanupPostAnimation;
400 if (!isDeferred) {
Winson Chung7bd1bbb2012-02-13 18:29:29 -0800401 mDragObject.dragView.remove();
402 }
Adam Cohencb3382b2011-05-24 14:07:08 -0700403 mDragObject.dragView = null;
Joe Onorato00acb122009-08-04 16:04:30 -0400404 }
Winson Chung043f2af2012-03-01 16:09:54 -0800405
406 // Only end the drag if we are not deferred
407 if (!isDeferred) {
408 for (DragListener listener : mListeners) {
409 listener.onDragEnd();
410 }
411 }
412 }
413
414 releaseVelocityTracker();
415 }
416
417 /**
418 * This only gets called as a result of drag view cleanup being deferred in endDrag();
419 */
420 void onDeferredEndDrag(DragView dragView) {
421 dragView.remove();
422
423 // If we skipped calling onDragEnd() before, do it now
424 for (DragListener listener : mListeners) {
425 listener.onDragEnd();
Joe Onorato00acb122009-08-04 16:04:30 -0400426 }
427 }
428
Winson Chunga48487a2012-03-20 16:19:37 -0700429 void onDeferredEndFling(DropTarget.DragObject d) {
430 d.dragSource.onFlingToDeleteCompleted();
431 }
432
Joe Onorato00acb122009-08-04 16:04:30 -0400433 /**
Winson Chung273c1022011-07-11 13:40:52 -0700434 * Clamps the position to the drag layer bounds.
435 */
436 private int[] getClampedDragLayerPos(float x, float y) {
437 mLauncher.getDragLayer().getLocalVisibleRect(mDragLayerRect);
438 mTmpPoint[0] = (int) Math.max(mDragLayerRect.left, Math.min(x, mDragLayerRect.right - 1));
439 mTmpPoint[1] = (int) Math.max(mDragLayerRect.top, Math.min(y, mDragLayerRect.bottom - 1));
440 return mTmpPoint;
441 }
442
Winson Chunga2413752012-04-03 14:22:34 -0700443 long getLastGestureUpTime() {
444 if (mDragging) {
445 return System.currentTimeMillis();
446 } else {
447 return mLastTouchUpTime;
448 }
449 }
450
451 void resetLastGestureUpTime() {
452 mLastTouchUpTime = -1;
453 }
454
Winson Chung273c1022011-07-11 13:40:52 -0700455 /**
Joe Onorato00acb122009-08-04 16:04:30 -0400456 * Call this from a drag source view.
457 */
458 public boolean onInterceptTouchEvent(MotionEvent ev) {
Michael Jurka3a9fced2012-04-13 14:44:29 -0700459 @SuppressWarnings("all") // suppress dead code warning
460 final boolean debug = false;
461 if (debug) {
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();
Winson Chung360e63f2012-04-27 13:48:05 -0700520 mLauncher.getDragLayer().onExitScrollArea();
Winson Chungaa15ffe2012-01-18 15:45:28 -0800521 }
522 }
523
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700524 private void handleMoveEvent(int x, int y) {
Adam Cohencb3382b2011-05-24 14:07:08 -0700525 mDragObject.dragView.move(x, y);
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700526
527 // Drop on someone?
528 final int[] coordinates = mCoordinatesTemp;
529 DropTarget dropTarget = findDropTarget(x, y, coordinates);
Adam Cohencb3382b2011-05-24 14:07:08 -0700530 mDragObject.x = coordinates[0];
531 mDragObject.y = coordinates[1];
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700532 if (dropTarget != null) {
Adam Cohencb3382b2011-05-24 14:07:08 -0700533 DropTarget delegate = dropTarget.getDropTargetDelegate(mDragObject);
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700534 if (delegate != null) {
535 dropTarget = delegate;
536 }
537
538 if (mLastDropTarget != dropTarget) {
539 if (mLastDropTarget != null) {
Adam Cohencb3382b2011-05-24 14:07:08 -0700540 mLastDropTarget.onDragExit(mDragObject);
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700541 }
Adam Cohencb3382b2011-05-24 14:07:08 -0700542 dropTarget.onDragEnter(mDragObject);
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700543 }
Adam Cohencb3382b2011-05-24 14:07:08 -0700544 dropTarget.onDragOver(mDragObject);
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700545 } else {
546 if (mLastDropTarget != null) {
Adam Cohencb3382b2011-05-24 14:07:08 -0700547 mLastDropTarget.onDragExit(mDragObject);
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700548 }
549 }
550 mLastDropTarget = dropTarget;
551
Patrick Dubroya16fd5a2010-10-07 16:47:28 -0700552 // After a scroll, the touch point will still be in the scroll region.
553 // Rather than scrolling immediately, require a bit of twiddling to scroll again
Adam Cohen8dfcba42011-07-07 16:38:18 -0700554 final int slop = ViewConfiguration.get(mLauncher).getScaledWindowTouchSlop();
Patrick Dubroya16fd5a2010-10-07 16:47:28 -0700555 mDistanceSinceScroll +=
556 Math.sqrt(Math.pow(mLastTouch[0] - x, 2) + Math.pow(mLastTouch[1] - y, 2));
557 mLastTouch[0] = x;
558 mLastTouch[1] = y;
Winson Chungaa15ffe2012-01-18 15:45:28 -0800559 final int delay = mDistanceSinceScroll < slop ? RESCROLL_DELAY : SCROLL_DELAY;
Patrick Dubroya16fd5a2010-10-07 16:47:28 -0700560
Winson Chung3f4e1422011-11-17 14:58:51 -0800561 if (x < mScrollZone) {
Winson Chungaa15ffe2012-01-18 15:45:28 -0800562 if (mScrollState == SCROLL_OUTSIDE_ZONE) {
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700563 mScrollState = SCROLL_WAITING_IN_ZONE;
Winson Chung3e0839e2011-10-03 15:15:18 -0700564 if (mDragScroller.onEnterScrollArea(x, y, SCROLL_LEFT)) {
Winson Chung360e63f2012-04-27 13:48:05 -0700565 mLauncher.getDragLayer().onEnterScrollArea(SCROLL_LEFT);
Winson Chung3e0839e2011-10-03 15:15:18 -0700566 mScrollRunnable.setDirection(SCROLL_LEFT);
Winson Chungaa15ffe2012-01-18 15:45:28 -0800567 mHandler.postDelayed(mScrollRunnable, delay);
Winson Chung3e0839e2011-10-03 15:15:18 -0700568 }
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700569 }
Winson Chung3f4e1422011-11-17 14:58:51 -0800570 } else if (x > mScrollView.getWidth() - mScrollZone) {
Winson Chungaa15ffe2012-01-18 15:45:28 -0800571 if (mScrollState == SCROLL_OUTSIDE_ZONE) {
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700572 mScrollState = SCROLL_WAITING_IN_ZONE;
Winson Chung3e0839e2011-10-03 15:15:18 -0700573 if (mDragScroller.onEnterScrollArea(x, y, SCROLL_RIGHT)) {
Winson Chung360e63f2012-04-27 13:48:05 -0700574 mLauncher.getDragLayer().onEnterScrollArea(SCROLL_RIGHT);
Winson Chung3e0839e2011-10-03 15:15:18 -0700575 mScrollRunnable.setDirection(SCROLL_RIGHT);
Winson Chungaa15ffe2012-01-18 15:45:28 -0800576 mHandler.postDelayed(mScrollRunnable, delay);
Winson Chung3e0839e2011-10-03 15:15:18 -0700577 }
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700578 }
579 } else {
Winson Chungaa15ffe2012-01-18 15:45:28 -0800580 clearScrollRunnable();
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700581 }
582 }
583
Winson Chung3bc21c32012-01-20 13:59:18 -0800584 public void forceMoveEvent() {
585 if (mDragging) {
586 handleMoveEvent(mDragObject.x, mDragObject.y);
587 }
588 }
589
Romain Guyea3763c2010-01-11 18:02:04 -0800590 /**
Joe Onorato00acb122009-08-04 16:04:30 -0400591 * Call this from a drag source view.
592 */
593 public boolean onTouchEvent(MotionEvent ev) {
Joe Onorato00acb122009-08-04 16:04:30 -0400594 if (!mDragging) {
595 return false;
596 }
597
Winson Chung043f2af2012-03-01 16:09:54 -0800598 // Update the velocity tracker
599 acquireVelocityTrackerAndAddMovement(ev);
600
Joe Onorato00acb122009-08-04 16:04:30 -0400601 final int action = ev.getAction();
Winson Chung273c1022011-07-11 13:40:52 -0700602 final int[] dragLayerPos = getClampedDragLayerPos(ev.getX(), ev.getY());
603 final int dragLayerX = dragLayerPos[0];
604 final int dragLayerY = dragLayerPos[1];
Joe Onorato00acb122009-08-04 16:04:30 -0400605
606 switch (action) {
607 case MotionEvent.ACTION_DOWN:
Joe Onorato00acb122009-08-04 16:04:30 -0400608 // Remember where the motion event started
Adam Cohen8dfcba42011-07-07 16:38:18 -0700609 mMotionDownX = dragLayerX;
610 mMotionDownY = dragLayerY;
Joe Onorato00acb122009-08-04 16:04:30 -0400611
Adam Cohen8dfcba42011-07-07 16:38:18 -0700612 if ((dragLayerX < mScrollZone) || (dragLayerX > mScrollView.getWidth() - mScrollZone)) {
Joe Onorato00acb122009-08-04 16:04:30 -0400613 mScrollState = SCROLL_WAITING_IN_ZONE;
614 mHandler.postDelayed(mScrollRunnable, SCROLL_DELAY);
615 } else {
616 mScrollState = SCROLL_OUTSIDE_ZONE;
617 }
Joe Onorato00acb122009-08-04 16:04:30 -0400618 break;
619 case MotionEvent.ACTION_MOVE:
Adam Cohen8dfcba42011-07-07 16:38:18 -0700620 handleMoveEvent(dragLayerX, dragLayerY);
Joe Onorato00acb122009-08-04 16:04:30 -0400621 break;
622 case MotionEvent.ACTION_UP:
Patrick Dubroyb0a6bbe2011-03-02 18:40:21 -0800623 // Ensure that we've processed a move event at the current pointer location.
Adam Cohen8dfcba42011-07-07 16:38:18 -0700624 handleMoveEvent(dragLayerX, dragLayerY);
Winson Chung3bc21c32012-01-20 13:59:18 -0800625 mHandler.removeCallbacks(mScrollRunnable);
Winson Chung043f2af2012-03-01 16:09:54 -0800626
Joe Onorato00acb122009-08-04 16:04:30 -0400627 if (mDragging) {
Winson Chung043f2af2012-03-01 16:09:54 -0800628 PointF vec = isFlingingToDelete(mDragObject.dragSource);
629 if (vec != null) {
630 dropOnFlingToDeleteTarget(dragLayerX, dragLayerY, vec);
631 } else {
632 drop(dragLayerX, dragLayerY);
633 }
Joe Onorato00acb122009-08-04 16:04:30 -0400634 }
635 endDrag();
Joe Onorato00acb122009-08-04 16:04:30 -0400636 break;
637 case MotionEvent.ACTION_CANCEL:
Winson Chung3bc21c32012-01-20 13:59:18 -0800638 mHandler.removeCallbacks(mScrollRunnable);
Joe Onorato24b6fd82009-11-12 13:47:09 -0800639 cancelDrag();
Winson Chung621e6402011-01-04 16:03:57 -0800640 break;
Joe Onorato00acb122009-08-04 16:04:30 -0400641 }
642
643 return true;
644 }
645
Winson Chung043f2af2012-03-01 16:09:54 -0800646 /**
647 * Determines whether the user flung the current item to delete it.
648 *
649 * @return the vector at which the item was flung, or null if no fling was detected.
650 */
651 private PointF isFlingingToDelete(DragSource source) {
652 if (mFlingToDeleteDropTarget == null) return null;
653 if (!source.supportsFlingToDelete()) return null;
654
655 ViewConfiguration config = ViewConfiguration.get(mLauncher);
656 mVelocityTracker.computeCurrentVelocity(1000, config.getScaledMaximumFlingVelocity());
657
658 if (mVelocityTracker.getYVelocity() < mFlingToDeleteThresholdVelocity) {
659 // Do a quick dot product test to ensure that we are flinging upwards
660 PointF vel = new PointF(mVelocityTracker.getXVelocity(),
661 mVelocityTracker.getYVelocity());
662 PointF upVec = new PointF(0f, -1f);
663 float theta = (float) Math.acos(((vel.x * upVec.x) + (vel.y * upVec.y)) /
664 (vel.length() * upVec.length()));
665 if (theta <= Math.toRadians(MAX_FLING_DEGREES)) {
666 return vel;
667 }
668 }
669 return null;
670 }
671
672 private void dropOnFlingToDeleteTarget(float x, float y, PointF vel) {
673 final int[] coordinates = mCoordinatesTemp;
674
675 mDragObject.x = coordinates[0];
676 mDragObject.y = coordinates[1];
Winson Chung043f2af2012-03-01 16:09:54 -0800677
678 // Clean up dragging on the target if it's not the current fling delete target otherwise,
679 // start dragging to it.
680 if (mLastDropTarget != null && mFlingToDeleteDropTarget != mLastDropTarget) {
681 mLastDropTarget.onDragExit(mDragObject);
682 }
683
684 // Drop onto the fling-to-delete target
685 boolean accepted = false;
686 mFlingToDeleteDropTarget.onDragEnter(mDragObject);
Winson Chung232decb2012-03-28 15:09:05 -0700687 // We must set dragComplete to true _only_ after we "enter" the fling-to-delete target for
688 // "drop"
689 mDragObject.dragComplete = true;
Winson Chung043f2af2012-03-01 16:09:54 -0800690 mFlingToDeleteDropTarget.onDragExit(mDragObject);
691 if (mFlingToDeleteDropTarget.acceptDrop(mDragObject)) {
692 mFlingToDeleteDropTarget.onFlingToDelete(mDragObject, mDragObject.x, mDragObject.y,
693 vel);
694 accepted = true;
695 }
Winson Chunga48487a2012-03-20 16:19:37 -0700696 mDragObject.dragSource.onDropCompleted((View) mFlingToDeleteDropTarget, mDragObject, true,
Winson Chung043f2af2012-03-01 16:09:54 -0800697 accepted);
698 }
699
Patrick Dubroyb0a6bbe2011-03-02 18:40:21 -0800700 private void drop(float x, float y) {
Joe Onorato00acb122009-08-04 16:04:30 -0400701 final int[] coordinates = mCoordinatesTemp;
Patrick Dubroyb0a6bbe2011-03-02 18:40:21 -0800702 final DropTarget dropTarget = findDropTarget((int) x, (int) y, coordinates);
Joe Onorato00acb122009-08-04 16:04:30 -0400703
Adam Cohencb3382b2011-05-24 14:07:08 -0700704 mDragObject.x = coordinates[0];
705 mDragObject.y = coordinates[1];
Patrick Dubroyb0a6bbe2011-03-02 18:40:21 -0800706 boolean accepted = false;
Joe Onorato00acb122009-08-04 16:04:30 -0400707 if (dropTarget != null) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700708 mDragObject.dragComplete = true;
Adam Cohencb3382b2011-05-24 14:07:08 -0700709 dropTarget.onDragExit(mDragObject);
710 if (dropTarget.acceptDrop(mDragObject)) {
711 dropTarget.onDrop(mDragObject);
Patrick Dubroyb0a6bbe2011-03-02 18:40:21 -0800712 accepted = true;
Joe Onorato00acb122009-08-04 16:04:30 -0400713 }
714 }
Winson Chunga48487a2012-03-20 16:19:37 -0700715 mDragObject.dragSource.onDropCompleted((View) dropTarget, mDragObject, false, accepted);
Joe Onorato00acb122009-08-04 16:04:30 -0400716 }
717
718 private DropTarget findDropTarget(int x, int y, int[] dropCoordinates) {
719 final Rect r = mRectTemp;
720
721 final ArrayList<DropTarget> dropTargets = mDropTargets;
722 final int count = dropTargets.size();
723 for (int i=count-1; i>=0; i--) {
Patrick Dubroy440c3602010-07-13 17:50:32 -0700724 DropTarget target = dropTargets.get(i);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700725 if (!target.isDropEnabled())
726 continue;
727
Joe Onorato00acb122009-08-04 16:04:30 -0400728 target.getHitRect(r);
Patrick Dubroy440c3602010-07-13 17:50:32 -0700729
Adam Cohen8dfcba42011-07-07 16:38:18 -0700730 // Convert the hit rect to DragLayer coordinates
731 target.getLocationInDragLayer(dropCoordinates);
Joe Onorato00acb122009-08-04 16:04:30 -0400732 r.offset(dropCoordinates[0] - target.getLeft(), dropCoordinates[1] - target.getTop());
Patrick Dubroy440c3602010-07-13 17:50:32 -0700733
Adam Cohencb3382b2011-05-24 14:07:08 -0700734 mDragObject.x = x;
735 mDragObject.y = y;
Joe Onorato00acb122009-08-04 16:04:30 -0400736 if (r.contains(x, y)) {
Adam Cohencb3382b2011-05-24 14:07:08 -0700737 DropTarget delegate = target.getDropTargetDelegate(mDragObject);
Patrick Dubroy440c3602010-07-13 17:50:32 -0700738 if (delegate != null) {
739 target = delegate;
Adam Cohen8dfcba42011-07-07 16:38:18 -0700740 target.getLocationInDragLayer(dropCoordinates);
Patrick Dubroy440c3602010-07-13 17:50:32 -0700741 }
742
743 // Make dropCoordinates relative to the DropTarget
Joe Onorato00acb122009-08-04 16:04:30 -0400744 dropCoordinates[0] = x - dropCoordinates[0];
745 dropCoordinates[1] = y - dropCoordinates[1];
Patrick Dubroy440c3602010-07-13 17:50:32 -0700746
Joe Onorato00acb122009-08-04 16:04:30 -0400747 return target;
748 }
749 }
750 return null;
751 }
752
753 public void setDragScoller(DragScroller scroller) {
754 mDragScroller = scroller;
755 }
756
757 public void setWindowToken(IBinder token) {
758 mWindowToken = token;
759 }
760
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800761 /**
762 * Sets the drag listner which will be notified when a drag starts or ends.
763 */
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700764 public void addDragListener(DragListener l) {
765 mListeners.add(l);
Joe Onorato00acb122009-08-04 16:04:30 -0400766 }
767
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800768 /**
769 * Remove a previously installed drag listener.
770 */
Joe Onorato00acb122009-08-04 16:04:30 -0400771 public void removeDragListener(DragListener l) {
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700772 mListeners.remove(l);
Joe Onorato00acb122009-08-04 16:04:30 -0400773 }
774
775 /**
776 * Add a DropTarget to the list of potential places to receive drop events.
777 */
778 public void addDropTarget(DropTarget target) {
779 mDropTargets.add(target);
780 }
781
782 /**
783 * Don't send drop events to <em>target</em> any more.
784 */
785 public void removeDropTarget(DropTarget target) {
786 mDropTargets.remove(target);
787 }
788
789 /**
Winson Chung043f2af2012-03-01 16:09:54 -0800790 * Sets the current fling-to-delete drop target.
791 */
792 public void setFlingToDeleteDropTarget(DropTarget target) {
793 mFlingToDeleteDropTarget = target;
794 }
795
796 private void acquireVelocityTrackerAndAddMovement(MotionEvent ev) {
797 if (mVelocityTracker == null) {
798 mVelocityTracker = VelocityTracker.obtain();
799 }
800 mVelocityTracker.addMovement(ev);
801 }
802
803 private void releaseVelocityTracker() {
804 if (mVelocityTracker != null) {
805 mVelocityTracker.recycle();
806 mVelocityTracker = null;
807 }
808 }
809
810 /**
Joe Onorato00acb122009-08-04 16:04:30 -0400811 * Set which view scrolls for touch events near the edge of the screen.
812 */
813 public void setScrollView(View v) {
814 mScrollView = v;
815 }
816
Patrick Dubroy5f445422011-02-18 14:35:21 -0800817 DragView getDragView() {
Adam Cohencb3382b2011-05-24 14:07:08 -0700818 return mDragObject.dragView;
Patrick Dubroy5f445422011-02-18 14:35:21 -0800819 }
820
Joe Onorato00acb122009-08-04 16:04:30 -0400821 private class ScrollRunnable implements Runnable {
822 private int mDirection;
823
824 ScrollRunnable() {
825 }
826
827 public void run() {
828 if (mDragScroller != null) {
829 if (mDirection == SCROLL_LEFT) {
830 mDragScroller.scrollLeft();
831 } else {
832 mDragScroller.scrollRight();
833 }
834 mScrollState = SCROLL_OUTSIDE_ZONE;
Patrick Dubroya16fd5a2010-10-07 16:47:28 -0700835 mDistanceSinceScroll = 0;
836 mDragScroller.onExitScrollArea();
Winson Chung360e63f2012-04-27 13:48:05 -0700837 mLauncher.getDragLayer().onExitScrollArea();
Winson Chungaa15ffe2012-01-18 15:45:28 -0800838
839 if (isDragging()) {
840 // Force an update so that we can requeue the scroller if necessary
Winson Chung3bc21c32012-01-20 13:59:18 -0800841 forceMoveEvent();
Winson Chungaa15ffe2012-01-18 15:45:28 -0800842 }
Joe Onorato00acb122009-08-04 16:04:30 -0400843 }
844 }
845
846 void setDirection(int direction) {
847 mDirection = direction;
848 }
849 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800850}