blob: 9b617552e20f1abb247691d7185184addf9ce94a [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 &&
Winson Chung11a49372012-04-27 15:12:38 -0700383 info.intent != null) {
Winson Chung579225f2012-05-06 19:19:43 -0700384 boolean isSamePackage = info.intent.getComponent().getPackageName().equals(
385 dragInfo.intent.getComponent().getPackageName());
Winson Chung11a49372012-04-27 15:12:38 -0700386 if (isSamePackage) {
387 cancelDrag();
388 return;
389 }
Winson Chunga1820962011-10-03 16:31:06 -0700390 }
391 }
392 }
393 }
394 }
Joe Onorato24b6fd82009-11-12 13:47:09 -0800395
Joe Onorato00acb122009-08-04 16:04:30 -0400396 private void endDrag() {
397 if (mDragging) {
398 mDragging = false;
Winson Chungaa15ffe2012-01-18 15:45:28 -0800399 clearScrollRunnable();
Winson Chung043f2af2012-03-01 16:09:54 -0800400 boolean isDeferred = false;
Adam Cohencb3382b2011-05-24 14:07:08 -0700401 if (mDragObject.dragView != null) {
Winson Chung043f2af2012-03-01 16:09:54 -0800402 isDeferred = mDragObject.deferDragViewCleanupPostAnimation;
403 if (!isDeferred) {
Winson Chung7bd1bbb2012-02-13 18:29:29 -0800404 mDragObject.dragView.remove();
405 }
Adam Cohencb3382b2011-05-24 14:07:08 -0700406 mDragObject.dragView = null;
Joe Onorato00acb122009-08-04 16:04:30 -0400407 }
Winson Chung043f2af2012-03-01 16:09:54 -0800408
409 // Only end the drag if we are not deferred
410 if (!isDeferred) {
411 for (DragListener listener : mListeners) {
412 listener.onDragEnd();
413 }
414 }
415 }
416
417 releaseVelocityTracker();
418 }
419
420 /**
421 * This only gets called as a result of drag view cleanup being deferred in endDrag();
422 */
423 void onDeferredEndDrag(DragView dragView) {
424 dragView.remove();
425
426 // If we skipped calling onDragEnd() before, do it now
427 for (DragListener listener : mListeners) {
428 listener.onDragEnd();
Joe Onorato00acb122009-08-04 16:04:30 -0400429 }
430 }
431
Winson Chunga48487a2012-03-20 16:19:37 -0700432 void onDeferredEndFling(DropTarget.DragObject d) {
433 d.dragSource.onFlingToDeleteCompleted();
434 }
435
Joe Onorato00acb122009-08-04 16:04:30 -0400436 /**
Winson Chung273c1022011-07-11 13:40:52 -0700437 * Clamps the position to the drag layer bounds.
438 */
439 private int[] getClampedDragLayerPos(float x, float y) {
440 mLauncher.getDragLayer().getLocalVisibleRect(mDragLayerRect);
441 mTmpPoint[0] = (int) Math.max(mDragLayerRect.left, Math.min(x, mDragLayerRect.right - 1));
442 mTmpPoint[1] = (int) Math.max(mDragLayerRect.top, Math.min(y, mDragLayerRect.bottom - 1));
443 return mTmpPoint;
444 }
445
Winson Chunga2413752012-04-03 14:22:34 -0700446 long getLastGestureUpTime() {
447 if (mDragging) {
448 return System.currentTimeMillis();
449 } else {
450 return mLastTouchUpTime;
451 }
452 }
453
454 void resetLastGestureUpTime() {
455 mLastTouchUpTime = -1;
456 }
457
Winson Chung273c1022011-07-11 13:40:52 -0700458 /**
Joe Onorato00acb122009-08-04 16:04:30 -0400459 * Call this from a drag source view.
460 */
461 public boolean onInterceptTouchEvent(MotionEvent ev) {
Michael Jurka3a9fced2012-04-13 14:44:29 -0700462 @SuppressWarnings("all") // suppress dead code warning
463 final boolean debug = false;
464 if (debug) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800465 Log.d(Launcher.TAG, "DragController.onInterceptTouchEvent " + ev + " mDragging="
Joe Onorato9c1289c2009-08-17 11:03:03 -0400466 + mDragging);
467 }
Joe Onorato00acb122009-08-04 16:04:30 -0400468
Winson Chung043f2af2012-03-01 16:09:54 -0800469 // Update the velocity tracker
470 acquireVelocityTrackerAndAddMovement(ev);
471
472 final int action = ev.getAction();
Winson Chung273c1022011-07-11 13:40:52 -0700473 final int[] dragLayerPos = getClampedDragLayerPos(ev.getX(), ev.getY());
474 final int dragLayerX = dragLayerPos[0];
475 final int dragLayerY = dragLayerPos[1];
Joe Onorato00acb122009-08-04 16:04:30 -0400476
477 switch (action) {
478 case MotionEvent.ACTION_MOVE:
479 break;
Joe Onorato00acb122009-08-04 16:04:30 -0400480 case MotionEvent.ACTION_DOWN:
481 // Remember location of down touch
Adam Cohen8dfcba42011-07-07 16:38:18 -0700482 mMotionDownX = dragLayerX;
483 mMotionDownY = dragLayerY;
Joe Onorato00acb122009-08-04 16:04:30 -0400484 mLastDropTarget = null;
485 break;
Joe Onorato00acb122009-08-04 16:04:30 -0400486 case MotionEvent.ACTION_UP:
Winson Chunga2413752012-04-03 14:22:34 -0700487 mLastTouchUpTime = System.currentTimeMillis();
Joe Onorato00acb122009-08-04 16:04:30 -0400488 if (mDragging) {
Winson Chung043f2af2012-03-01 16:09:54 -0800489 PointF vec = isFlingingToDelete(mDragObject.dragSource);
490 if (vec != null) {
491 dropOnFlingToDeleteTarget(dragLayerX, dragLayerY, vec);
492 } else {
493 drop(dragLayerX, dragLayerY);
494 }
Joe Onorato00acb122009-08-04 16:04:30 -0400495 }
496 endDrag();
497 break;
Winson Chung621e6402011-01-04 16:03:57 -0800498 case MotionEvent.ACTION_CANCEL:
499 cancelDrag();
500 break;
Joe Onorato00acb122009-08-04 16:04:30 -0400501 }
502
503 return mDragging;
504 }
505
506 /**
Romain Guyea3763c2010-01-11 18:02:04 -0800507 * Sets the view that should handle move events.
508 */
509 void setMoveTarget(View view) {
510 mMoveTarget = view;
511 }
512
513 public boolean dispatchUnhandledMove(View focused, int direction) {
514 return mMoveTarget != null && mMoveTarget.dispatchUnhandledMove(focused, direction);
515 }
516
Winson Chungaa15ffe2012-01-18 15:45:28 -0800517 private void clearScrollRunnable() {
518 mHandler.removeCallbacks(mScrollRunnable);
519 if (mScrollState == SCROLL_WAITING_IN_ZONE) {
520 mScrollState = SCROLL_OUTSIDE_ZONE;
521 mScrollRunnable.setDirection(SCROLL_RIGHT);
522 mDragScroller.onExitScrollArea();
Winson Chung360e63f2012-04-27 13:48:05 -0700523 mLauncher.getDragLayer().onExitScrollArea();
Winson Chungaa15ffe2012-01-18 15:45:28 -0800524 }
525 }
526
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700527 private void handleMoveEvent(int x, int y) {
Adam Cohencb3382b2011-05-24 14:07:08 -0700528 mDragObject.dragView.move(x, y);
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700529
530 // Drop on someone?
531 final int[] coordinates = mCoordinatesTemp;
532 DropTarget dropTarget = findDropTarget(x, y, coordinates);
Adam Cohencb3382b2011-05-24 14:07:08 -0700533 mDragObject.x = coordinates[0];
534 mDragObject.y = coordinates[1];
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700535 if (dropTarget != null) {
Adam Cohencb3382b2011-05-24 14:07:08 -0700536 DropTarget delegate = dropTarget.getDropTargetDelegate(mDragObject);
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700537 if (delegate != null) {
538 dropTarget = delegate;
539 }
540
541 if (mLastDropTarget != dropTarget) {
542 if (mLastDropTarget != null) {
Adam Cohencb3382b2011-05-24 14:07:08 -0700543 mLastDropTarget.onDragExit(mDragObject);
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700544 }
Adam Cohencb3382b2011-05-24 14:07:08 -0700545 dropTarget.onDragEnter(mDragObject);
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700546 }
Adam Cohencb3382b2011-05-24 14:07:08 -0700547 dropTarget.onDragOver(mDragObject);
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700548 } else {
549 if (mLastDropTarget != null) {
Adam Cohencb3382b2011-05-24 14:07:08 -0700550 mLastDropTarget.onDragExit(mDragObject);
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700551 }
552 }
553 mLastDropTarget = dropTarget;
554
Patrick Dubroya16fd5a2010-10-07 16:47:28 -0700555 // After a scroll, the touch point will still be in the scroll region.
556 // Rather than scrolling immediately, require a bit of twiddling to scroll again
Adam Cohen8dfcba42011-07-07 16:38:18 -0700557 final int slop = ViewConfiguration.get(mLauncher).getScaledWindowTouchSlop();
Patrick Dubroya16fd5a2010-10-07 16:47:28 -0700558 mDistanceSinceScroll +=
559 Math.sqrt(Math.pow(mLastTouch[0] - x, 2) + Math.pow(mLastTouch[1] - y, 2));
560 mLastTouch[0] = x;
561 mLastTouch[1] = y;
Winson Chungaa15ffe2012-01-18 15:45:28 -0800562 final int delay = mDistanceSinceScroll < slop ? RESCROLL_DELAY : SCROLL_DELAY;
Patrick Dubroya16fd5a2010-10-07 16:47:28 -0700563
Winson Chung3f4e1422011-11-17 14:58:51 -0800564 if (x < mScrollZone) {
Winson Chungaa15ffe2012-01-18 15:45:28 -0800565 if (mScrollState == SCROLL_OUTSIDE_ZONE) {
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700566 mScrollState = SCROLL_WAITING_IN_ZONE;
Winson Chung3e0839e2011-10-03 15:15:18 -0700567 if (mDragScroller.onEnterScrollArea(x, y, SCROLL_LEFT)) {
Winson Chung360e63f2012-04-27 13:48:05 -0700568 mLauncher.getDragLayer().onEnterScrollArea(SCROLL_LEFT);
Winson Chung3e0839e2011-10-03 15:15:18 -0700569 mScrollRunnable.setDirection(SCROLL_LEFT);
Winson Chungaa15ffe2012-01-18 15:45:28 -0800570 mHandler.postDelayed(mScrollRunnable, delay);
Winson Chung3e0839e2011-10-03 15:15:18 -0700571 }
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700572 }
Winson Chung3f4e1422011-11-17 14:58:51 -0800573 } else if (x > mScrollView.getWidth() - mScrollZone) {
Winson Chungaa15ffe2012-01-18 15:45:28 -0800574 if (mScrollState == SCROLL_OUTSIDE_ZONE) {
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700575 mScrollState = SCROLL_WAITING_IN_ZONE;
Winson Chung3e0839e2011-10-03 15:15:18 -0700576 if (mDragScroller.onEnterScrollArea(x, y, SCROLL_RIGHT)) {
Winson Chung360e63f2012-04-27 13:48:05 -0700577 mLauncher.getDragLayer().onEnterScrollArea(SCROLL_RIGHT);
Winson Chung3e0839e2011-10-03 15:15:18 -0700578 mScrollRunnable.setDirection(SCROLL_RIGHT);
Winson Chungaa15ffe2012-01-18 15:45:28 -0800579 mHandler.postDelayed(mScrollRunnable, delay);
Winson Chung3e0839e2011-10-03 15:15:18 -0700580 }
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700581 }
582 } else {
Winson Chungaa15ffe2012-01-18 15:45:28 -0800583 clearScrollRunnable();
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700584 }
585 }
586
Winson Chung3bc21c32012-01-20 13:59:18 -0800587 public void forceMoveEvent() {
588 if (mDragging) {
589 handleMoveEvent(mDragObject.x, mDragObject.y);
590 }
591 }
592
Romain Guyea3763c2010-01-11 18:02:04 -0800593 /**
Joe Onorato00acb122009-08-04 16:04:30 -0400594 * Call this from a drag source view.
595 */
596 public boolean onTouchEvent(MotionEvent ev) {
Joe Onorato00acb122009-08-04 16:04:30 -0400597 if (!mDragging) {
598 return false;
599 }
600
Winson Chung043f2af2012-03-01 16:09:54 -0800601 // Update the velocity tracker
602 acquireVelocityTrackerAndAddMovement(ev);
603
Joe Onorato00acb122009-08-04 16:04:30 -0400604 final int action = ev.getAction();
Winson Chung273c1022011-07-11 13:40:52 -0700605 final int[] dragLayerPos = getClampedDragLayerPos(ev.getX(), ev.getY());
606 final int dragLayerX = dragLayerPos[0];
607 final int dragLayerY = dragLayerPos[1];
Joe Onorato00acb122009-08-04 16:04:30 -0400608
609 switch (action) {
610 case MotionEvent.ACTION_DOWN:
Joe Onorato00acb122009-08-04 16:04:30 -0400611 // Remember where the motion event started
Adam Cohen8dfcba42011-07-07 16:38:18 -0700612 mMotionDownX = dragLayerX;
613 mMotionDownY = dragLayerY;
Joe Onorato00acb122009-08-04 16:04:30 -0400614
Adam Cohen8dfcba42011-07-07 16:38:18 -0700615 if ((dragLayerX < mScrollZone) || (dragLayerX > mScrollView.getWidth() - mScrollZone)) {
Joe Onorato00acb122009-08-04 16:04:30 -0400616 mScrollState = SCROLL_WAITING_IN_ZONE;
617 mHandler.postDelayed(mScrollRunnable, SCROLL_DELAY);
618 } else {
619 mScrollState = SCROLL_OUTSIDE_ZONE;
620 }
Joe Onorato00acb122009-08-04 16:04:30 -0400621 break;
622 case MotionEvent.ACTION_MOVE:
Adam Cohen8dfcba42011-07-07 16:38:18 -0700623 handleMoveEvent(dragLayerX, dragLayerY);
Joe Onorato00acb122009-08-04 16:04:30 -0400624 break;
625 case MotionEvent.ACTION_UP:
Patrick Dubroyb0a6bbe2011-03-02 18:40:21 -0800626 // Ensure that we've processed a move event at the current pointer location.
Adam Cohen8dfcba42011-07-07 16:38:18 -0700627 handleMoveEvent(dragLayerX, dragLayerY);
Winson Chung3bc21c32012-01-20 13:59:18 -0800628 mHandler.removeCallbacks(mScrollRunnable);
Winson Chung043f2af2012-03-01 16:09:54 -0800629
Joe Onorato00acb122009-08-04 16:04:30 -0400630 if (mDragging) {
Winson Chung043f2af2012-03-01 16:09:54 -0800631 PointF vec = isFlingingToDelete(mDragObject.dragSource);
632 if (vec != null) {
633 dropOnFlingToDeleteTarget(dragLayerX, dragLayerY, vec);
634 } else {
635 drop(dragLayerX, dragLayerY);
636 }
Joe Onorato00acb122009-08-04 16:04:30 -0400637 }
638 endDrag();
Joe Onorato00acb122009-08-04 16:04:30 -0400639 break;
640 case MotionEvent.ACTION_CANCEL:
Winson Chung3bc21c32012-01-20 13:59:18 -0800641 mHandler.removeCallbacks(mScrollRunnable);
Joe Onorato24b6fd82009-11-12 13:47:09 -0800642 cancelDrag();
Winson Chung621e6402011-01-04 16:03:57 -0800643 break;
Joe Onorato00acb122009-08-04 16:04:30 -0400644 }
645
646 return true;
647 }
648
Winson Chung043f2af2012-03-01 16:09:54 -0800649 /**
650 * Determines whether the user flung the current item to delete it.
651 *
652 * @return the vector at which the item was flung, or null if no fling was detected.
653 */
654 private PointF isFlingingToDelete(DragSource source) {
655 if (mFlingToDeleteDropTarget == null) return null;
656 if (!source.supportsFlingToDelete()) return null;
657
658 ViewConfiguration config = ViewConfiguration.get(mLauncher);
659 mVelocityTracker.computeCurrentVelocity(1000, config.getScaledMaximumFlingVelocity());
660
661 if (mVelocityTracker.getYVelocity() < mFlingToDeleteThresholdVelocity) {
662 // Do a quick dot product test to ensure that we are flinging upwards
663 PointF vel = new PointF(mVelocityTracker.getXVelocity(),
664 mVelocityTracker.getYVelocity());
665 PointF upVec = new PointF(0f, -1f);
666 float theta = (float) Math.acos(((vel.x * upVec.x) + (vel.y * upVec.y)) /
667 (vel.length() * upVec.length()));
668 if (theta <= Math.toRadians(MAX_FLING_DEGREES)) {
669 return vel;
670 }
671 }
672 return null;
673 }
674
675 private void dropOnFlingToDeleteTarget(float x, float y, PointF vel) {
676 final int[] coordinates = mCoordinatesTemp;
677
678 mDragObject.x = coordinates[0];
679 mDragObject.y = coordinates[1];
Winson Chung043f2af2012-03-01 16:09:54 -0800680
681 // Clean up dragging on the target if it's not the current fling delete target otherwise,
682 // start dragging to it.
683 if (mLastDropTarget != null && mFlingToDeleteDropTarget != mLastDropTarget) {
684 mLastDropTarget.onDragExit(mDragObject);
685 }
686
687 // Drop onto the fling-to-delete target
688 boolean accepted = false;
689 mFlingToDeleteDropTarget.onDragEnter(mDragObject);
Winson Chung232decb2012-03-28 15:09:05 -0700690 // We must set dragComplete to true _only_ after we "enter" the fling-to-delete target for
691 // "drop"
692 mDragObject.dragComplete = true;
Winson Chung043f2af2012-03-01 16:09:54 -0800693 mFlingToDeleteDropTarget.onDragExit(mDragObject);
694 if (mFlingToDeleteDropTarget.acceptDrop(mDragObject)) {
695 mFlingToDeleteDropTarget.onFlingToDelete(mDragObject, mDragObject.x, mDragObject.y,
696 vel);
697 accepted = true;
698 }
Winson Chunga48487a2012-03-20 16:19:37 -0700699 mDragObject.dragSource.onDropCompleted((View) mFlingToDeleteDropTarget, mDragObject, true,
Winson Chung043f2af2012-03-01 16:09:54 -0800700 accepted);
701 }
702
Patrick Dubroyb0a6bbe2011-03-02 18:40:21 -0800703 private void drop(float x, float y) {
Joe Onorato00acb122009-08-04 16:04:30 -0400704 final int[] coordinates = mCoordinatesTemp;
Patrick Dubroyb0a6bbe2011-03-02 18:40:21 -0800705 final DropTarget dropTarget = findDropTarget((int) x, (int) y, coordinates);
Joe Onorato00acb122009-08-04 16:04:30 -0400706
Adam Cohencb3382b2011-05-24 14:07:08 -0700707 mDragObject.x = coordinates[0];
708 mDragObject.y = coordinates[1];
Patrick Dubroyb0a6bbe2011-03-02 18:40:21 -0800709 boolean accepted = false;
Joe Onorato00acb122009-08-04 16:04:30 -0400710 if (dropTarget != null) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700711 mDragObject.dragComplete = true;
Adam Cohencb3382b2011-05-24 14:07:08 -0700712 dropTarget.onDragExit(mDragObject);
713 if (dropTarget.acceptDrop(mDragObject)) {
714 dropTarget.onDrop(mDragObject);
Patrick Dubroyb0a6bbe2011-03-02 18:40:21 -0800715 accepted = true;
Joe Onorato00acb122009-08-04 16:04:30 -0400716 }
717 }
Winson Chunga48487a2012-03-20 16:19:37 -0700718 mDragObject.dragSource.onDropCompleted((View) dropTarget, mDragObject, false, accepted);
Joe Onorato00acb122009-08-04 16:04:30 -0400719 }
720
721 private DropTarget findDropTarget(int x, int y, int[] dropCoordinates) {
722 final Rect r = mRectTemp;
723
724 final ArrayList<DropTarget> dropTargets = mDropTargets;
725 final int count = dropTargets.size();
726 for (int i=count-1; i>=0; i--) {
Patrick Dubroy440c3602010-07-13 17:50:32 -0700727 DropTarget target = dropTargets.get(i);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700728 if (!target.isDropEnabled())
729 continue;
730
Joe Onorato00acb122009-08-04 16:04:30 -0400731 target.getHitRect(r);
Patrick Dubroy440c3602010-07-13 17:50:32 -0700732
Adam Cohen8dfcba42011-07-07 16:38:18 -0700733 // Convert the hit rect to DragLayer coordinates
734 target.getLocationInDragLayer(dropCoordinates);
Joe Onorato00acb122009-08-04 16:04:30 -0400735 r.offset(dropCoordinates[0] - target.getLeft(), dropCoordinates[1] - target.getTop());
Patrick Dubroy440c3602010-07-13 17:50:32 -0700736
Adam Cohencb3382b2011-05-24 14:07:08 -0700737 mDragObject.x = x;
738 mDragObject.y = y;
Joe Onorato00acb122009-08-04 16:04:30 -0400739 if (r.contains(x, y)) {
Adam Cohencb3382b2011-05-24 14:07:08 -0700740 DropTarget delegate = target.getDropTargetDelegate(mDragObject);
Patrick Dubroy440c3602010-07-13 17:50:32 -0700741 if (delegate != null) {
742 target = delegate;
Adam Cohen8dfcba42011-07-07 16:38:18 -0700743 target.getLocationInDragLayer(dropCoordinates);
Patrick Dubroy440c3602010-07-13 17:50:32 -0700744 }
745
746 // Make dropCoordinates relative to the DropTarget
Joe Onorato00acb122009-08-04 16:04:30 -0400747 dropCoordinates[0] = x - dropCoordinates[0];
748 dropCoordinates[1] = y - dropCoordinates[1];
Patrick Dubroy440c3602010-07-13 17:50:32 -0700749
Joe Onorato00acb122009-08-04 16:04:30 -0400750 return target;
751 }
752 }
753 return null;
754 }
755
756 public void setDragScoller(DragScroller scroller) {
757 mDragScroller = scroller;
758 }
759
760 public void setWindowToken(IBinder token) {
761 mWindowToken = token;
762 }
763
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800764 /**
765 * Sets the drag listner which will be notified when a drag starts or ends.
766 */
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700767 public void addDragListener(DragListener l) {
768 mListeners.add(l);
Joe Onorato00acb122009-08-04 16:04:30 -0400769 }
770
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800771 /**
772 * Remove a previously installed drag listener.
773 */
Joe Onorato00acb122009-08-04 16:04:30 -0400774 public void removeDragListener(DragListener l) {
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700775 mListeners.remove(l);
Joe Onorato00acb122009-08-04 16:04:30 -0400776 }
777
778 /**
779 * Add a DropTarget to the list of potential places to receive drop events.
780 */
781 public void addDropTarget(DropTarget target) {
782 mDropTargets.add(target);
783 }
784
785 /**
786 * Don't send drop events to <em>target</em> any more.
787 */
788 public void removeDropTarget(DropTarget target) {
789 mDropTargets.remove(target);
790 }
791
792 /**
Winson Chung043f2af2012-03-01 16:09:54 -0800793 * Sets the current fling-to-delete drop target.
794 */
795 public void setFlingToDeleteDropTarget(DropTarget target) {
796 mFlingToDeleteDropTarget = target;
797 }
798
799 private void acquireVelocityTrackerAndAddMovement(MotionEvent ev) {
800 if (mVelocityTracker == null) {
801 mVelocityTracker = VelocityTracker.obtain();
802 }
803 mVelocityTracker.addMovement(ev);
804 }
805
806 private void releaseVelocityTracker() {
807 if (mVelocityTracker != null) {
808 mVelocityTracker.recycle();
809 mVelocityTracker = null;
810 }
811 }
812
813 /**
Joe Onorato00acb122009-08-04 16:04:30 -0400814 * Set which view scrolls for touch events near the edge of the screen.
815 */
816 public void setScrollView(View v) {
817 mScrollView = v;
818 }
819
Patrick Dubroy5f445422011-02-18 14:35:21 -0800820 DragView getDragView() {
Adam Cohencb3382b2011-05-24 14:07:08 -0700821 return mDragObject.dragView;
Patrick Dubroy5f445422011-02-18 14:35:21 -0800822 }
823
Joe Onorato00acb122009-08-04 16:04:30 -0400824 private class ScrollRunnable implements Runnable {
825 private int mDirection;
826
827 ScrollRunnable() {
828 }
829
830 public void run() {
831 if (mDragScroller != null) {
832 if (mDirection == SCROLL_LEFT) {
833 mDragScroller.scrollLeft();
834 } else {
835 mDragScroller.scrollRight();
836 }
837 mScrollState = SCROLL_OUTSIDE_ZONE;
Patrick Dubroya16fd5a2010-10-07 16:47:28 -0700838 mDistanceSinceScroll = 0;
839 mDragScroller.onExitScrollArea();
Winson Chung360e63f2012-04-27 13:48:05 -0700840 mLauncher.getDragLayer().onExitScrollArea();
Winson Chungaa15ffe2012-01-18 15:45:28 -0800841
842 if (isDragging()) {
843 // Force an update so that we can requeue the scroller if necessary
Winson Chung3bc21c32012-01-20 13:59:18 -0800844 forceMoveEvent();
Winson Chungaa15ffe2012-01-18 15:45:28 -0800845 }
Joe Onorato00acb122009-08-04 16:04:30 -0400846 }
847 }
848
849 void setDirection(int direction) {
850 mDirection = direction;
851 }
852 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800853}