blob: e0de5b4592a0e8252feae3a46a8b4c42caa240a0 [file] [log] [blame]
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Daniel Sandler325dc232013-06-05 22:57:57 -040017package com.android.launcher3;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
Joe Onorato00acb122009-08-04 16:04:30 -040019import android.content.Context;
Winson Chung6e1bdaf2012-05-29 17:03:45 -070020import android.content.res.Resources;
Joe Onorato00acb122009-08-04 16:04:30 -040021import android.graphics.Bitmap;
Winson Chungb8c69f32011-10-19 21:36:08 -070022import android.graphics.Point;
Winson Chung043f2af2012-03-01 16:09:54 -080023import android.graphics.PointF;
Joe Onorato00acb122009-08-04 16:04:30 -040024import android.graphics.Rect;
Joe Onorato00acb122009-08-04 16:04:30 -040025import android.os.Handler;
Michael Jurka0280c3b2010-09-17 15:00:07 -070026import android.os.IBinder;
Joe Onorato00acb122009-08-04 16:04:30 -040027import android.os.Vibrator;
Joe Onorato00acb122009-08-04 16:04:30 -040028import android.util.Log;
Joe Onorato00acb122009-08-04 16:04:30 -040029import android.view.KeyEvent;
30import android.view.MotionEvent;
Winson Chung043f2af2012-03-01 16:09:54 -080031import android.view.VelocityTracker;
Michael Jurka0280c3b2010-09-17 15:00:07 -070032import android.view.View;
Patrick Dubroya16fd5a2010-10-07 16:47:28 -070033import android.view.ViewConfiguration;
Joe Onorato00acb122009-08-04 16:04:30 -040034import android.view.inputmethod.InputMethodManager;
Joe Onorato00acb122009-08-04 16:04:30 -040035
Daniel Sandler325dc232013-06-05 22:57:57 -040036import com.android.launcher3.R;
Adam Cohenc0dcf592011-06-01 15:30:43 -070037
38import java.util.ArrayList;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080039
40/**
Joe Onorato00acb122009-08-04 16:04:30 -040041 * Class for initiating a drag within a view or across multiple views.
The Android Open Source Project31dd5032009-03-03 19:32:27 -080042 */
Joe Onorato00acb122009-08-04 16:04:30 -040043public class DragController {
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 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) {
Winson Chung6e1bdaf2012-05-29 17:03:45 -0700149 Resources r = launcher.getResources();
Adam Cohen8dfcba42011-07-07 16:38:18 -0700150 mLauncher = launcher;
Joe Onorato00acb122009-08-04 16:04:30 -0400151 mHandler = new Handler();
Winson Chung6e1bdaf2012-05-29 17:03:45 -0700152 mScrollZone = r.getDimensionPixelSize(R.dimen.scroll_zone);
Winson Chung043f2af2012-03-01 16:09:54 -0800153 mVelocityTracker = VelocityTracker.obtain();
Winson Chung6e1bdaf2012-05-29 17:03:45 -0700154 mVibrator = (Vibrator) launcher.getSystemService(Context.VIBRATOR_SERVICE);
Winson Chung043f2af2012-03-01 16:09:54 -0800155
Winson Chung6e1bdaf2012-05-29 17:03:45 -0700156 float density = r.getDisplayMetrics().density;
157 mFlingToDeleteThresholdVelocity =
158 (int) (r.getInteger(R.integer.config_flingToDeleteMinVelocity) * density);
Joe Onorato00acb122009-08-04 16:04:30 -0400159 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800160
Patrick Dubroy1262e362010-10-06 15:49:50 -0700161 public boolean dragging() {
162 return mDragging;
163 }
164
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800165 /**
Joe Onorato5162ea92009-09-03 09:39:42 -0700166 * Starts a drag.
Michael Jurkaa63c4522010-08-19 13:52:27 -0700167 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800168 * @param v The view that is being dragged
Winson Chunge3193b92010-09-10 11:44:42 -0700169 * @param bmp The bitmap that represents the view being dragged
170 * @param source An object representing where the drag originated
171 * @param dragInfo The data associated with the object that is being dragged
172 * @param dragAction The drag action: either {@link #DRAG_ACTION_MOVE} or
173 * {@link #DRAG_ACTION_COPY}
174 * @param dragRegion Coordinates within the bitmap b for the position of item being dragged.
175 * Makes dragging feel more precise, e.g. you can clip out a transparent border
176 */
177 public void startDrag(View v, Bitmap bmp, DragSource source, Object dragInfo, int dragAction,
Michael Jurka05713af2013-01-23 12:39:24 +0100178 Point extraPadding, float initialDragViewScale) {
Winson Chunge3193b92010-09-10 11:44:42 -0700179 int[] loc = mCoordinatesTemp;
Adam Cohen8dfcba42011-07-07 16:38:18 -0700180 mLauncher.getDragLayer().getLocationInDragLayer(v, loc);
Michael Jurka05713af2013-01-23 12:39:24 +0100181 int viewExtraPaddingLeft = extraPadding != null ? extraPadding.x : 0;
182 int viewExtraPaddingTop = extraPadding != null ? extraPadding.y : 0;
183 int dragLayerX = loc[0] + v.getPaddingLeft() + viewExtraPaddingLeft +
Winson Chung72d59842012-02-22 13:51:36 -0800184 (int) ((initialDragViewScale * bmp.getWidth() - bmp.getWidth()) / 2);
Michael Jurka05713af2013-01-23 12:39:24 +0100185 int dragLayerY = loc[1] + v.getPaddingTop() + viewExtraPaddingTop +
Winson Chung72d59842012-02-22 13:51:36 -0800186 (int) ((initialDragViewScale * bmp.getHeight() - bmp.getHeight()) / 2);
Winson Chunge3193b92010-09-10 11:44:42 -0700187
Michael Jurka05713af2013-01-23 12:39:24 +0100188 startDrag(bmp, dragLayerX, dragLayerY, source, dragInfo, dragAction, null,
189 null, initialDragViewScale);
Winson Chunge3193b92010-09-10 11:44:42 -0700190
191 if (dragAction == DRAG_ACTION_MOVE) {
192 v.setVisibility(View.GONE);
193 }
194 }
195
196 /**
197 * Starts a drag.
198 *
Joe Onorato5162ea92009-09-03 09:39:42 -0700199 * @param b The bitmap to display as the drag image. It will be re-scaled to the
200 * enlarged size.
Adam Cohen8dfcba42011-07-07 16:38:18 -0700201 * @param dragLayerX The x position in the DragLayer of the left-top of the bitmap.
202 * @param dragLayerY The y position in the DragLayer of the left-top of the bitmap.
Joe Onorato5162ea92009-09-03 09:39:42 -0700203 * @param source An object representing where the drag originated
Romain Guyea3763c2010-01-11 18:02:04 -0800204 * @param dragInfo The data associated with the object that is being dragged
Joe Onorato5162ea92009-09-03 09:39:42 -0700205 * @param dragAction The drag action: either {@link #DRAG_ACTION_MOVE} or
206 * {@link #DRAG_ACTION_COPY}
Michael Jurkaa63c4522010-08-19 13:52:27 -0700207 * @param dragRegion Coordinates within the bitmap b for the position of item being dragged.
208 * Makes dragging feel more precise, e.g. you can clip out a transparent border
209 */
Adam Cohen8dfcba42011-07-07 16:38:18 -0700210 public void startDrag(Bitmap b, int dragLayerX, int dragLayerY,
Winson Chung72d59842012-02-22 13:51:36 -0800211 DragSource source, Object dragInfo, int dragAction, Point dragOffset, Rect dragRegion,
212 float initialDragViewScale) {
Joe Onorato00acb122009-08-04 16:04:30 -0400213 if (PROFILE_DRAWING_DURING_DRAG) {
214 android.os.Debug.startMethodTracing("Launcher");
215 }
216
217 // Hide soft keyboard, if visible
218 if (mInputMethodManager == null) {
219 mInputMethodManager = (InputMethodManager)
Adam Cohen8dfcba42011-07-07 16:38:18 -0700220 mLauncher.getSystemService(Context.INPUT_METHOD_SERVICE);
Joe Onorato00acb122009-08-04 16:04:30 -0400221 }
222 mInputMethodManager.hideSoftInputFromWindow(mWindowToken, 0);
223
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700224 for (DragListener listener : mListeners) {
225 listener.onDragStart(source, dragInfo, dragAction);
Joe Onorato00acb122009-08-04 16:04:30 -0400226 }
227
Adam Cohen8dfcba42011-07-07 16:38:18 -0700228 final int registrationX = mMotionDownX - dragLayerX;
229 final int registrationY = mMotionDownY - dragLayerY;
Joe Onorato00acb122009-08-04 16:04:30 -0400230
Michael Jurkaa63c4522010-08-19 13:52:27 -0700231 final int dragRegionLeft = dragRegion == null ? 0 : dragRegion.left;
232 final int dragRegionTop = dragRegion == null ? 0 : dragRegion.top;
Adam Cohene3e27a82011-04-15 12:07:39 -0700233
Joe Onorato00acb122009-08-04 16:04:30 -0400234 mDragging = true;
Adam Cohencb3382b2011-05-24 14:07:08 -0700235
Adam Cohen9932a9b2011-08-02 22:14:07 -0700236 mDragObject = new DropTarget.DragObject();
237
Adam Cohenbfbfd262011-06-13 16:55:12 -0700238 mDragObject.dragComplete = false;
Adam Cohen8dfcba42011-07-07 16:38:18 -0700239 mDragObject.xOffset = mMotionDownX - (dragLayerX + dragRegionLeft);
240 mDragObject.yOffset = mMotionDownY - (dragLayerY + dragRegionTop);
Adam Cohencb3382b2011-05-24 14:07:08 -0700241 mDragObject.dragSource = source;
242 mDragObject.dragInfo = dragInfo;
Joe Onorato00acb122009-08-04 16:04:30 -0400243
244 mVibrator.vibrate(VIBRATE_DURATION);
245
Adam Cohen8dfcba42011-07-07 16:38:18 -0700246 final DragView dragView = mDragObject.dragView = new DragView(mLauncher, b, registrationX,
Winson Chung72d59842012-02-22 13:51:36 -0800247 registrationY, 0, 0, b.getWidth(), b.getHeight(), initialDragViewScale);
Michael Jurkaa63c4522010-08-19 13:52:27 -0700248
Winson Chungb8c69f32011-10-19 21:36:08 -0700249 if (dragOffset != null) {
250 dragView.setDragVisualizeOffset(new Point(dragOffset));
251 }
Michael Jurkaa63c4522010-08-19 13:52:27 -0700252 if (dragRegion != null) {
Adam Cohene3e27a82011-04-15 12:07:39 -0700253 dragView.setDragRegion(new Rect(dragRegion));
Michael Jurkaa63c4522010-08-19 13:52:27 -0700254 }
255
Adam Cohen8dfcba42011-07-07 16:38:18 -0700256 dragView.show(mMotionDownX, mMotionDownY);
257 handleMoveEvent(mMotionDownX, mMotionDownY);
Joe Onorato00acb122009-08-04 16:04:30 -0400258 }
259
260 /**
261 * Draw the view into a bitmap.
262 */
Adam Cohen120980b2010-12-08 11:05:37 -0800263 Bitmap getViewBitmap(View v) {
Joe Onorato00acb122009-08-04 16:04:30 -0400264 v.clearFocus();
265 v.setPressed(false);
266
267 boolean willNotCache = v.willNotCacheDrawing();
268 v.setWillNotCacheDrawing(false);
269
270 // Reset the drawing cache background color to fully transparent
271 // for the duration of this operation
272 int color = v.getDrawingCacheBackgroundColor();
273 v.setDrawingCacheBackgroundColor(0);
Adam Cohen120980b2010-12-08 11:05:37 -0800274 float alpha = v.getAlpha();
275 v.setAlpha(1.0f);
Joe Onorato00acb122009-08-04 16:04:30 -0400276
277 if (color != 0) {
278 v.destroyDrawingCache();
279 }
280 v.buildDrawingCache();
281 Bitmap cacheBitmap = v.getDrawingCache();
Daniel Sandler3f8175a2010-05-25 11:48:32 -0400282 if (cacheBitmap == null) {
283 Log.e(TAG, "failed getViewBitmap(" + v + ")", new RuntimeException());
284 return null;
285 }
Joe Onorato00acb122009-08-04 16:04:30 -0400286
287 Bitmap bitmap = Bitmap.createBitmap(cacheBitmap);
288
289 // Restore the view
290 v.destroyDrawingCache();
Adam Cohen120980b2010-12-08 11:05:37 -0800291 v.setAlpha(alpha);
Joe Onorato00acb122009-08-04 16:04:30 -0400292 v.setWillNotCacheDrawing(willNotCache);
293 v.setDrawingCacheBackgroundColor(color);
294
295 return bitmap;
296 }
297
298 /**
299 * Call this from a drag source view like this:
300 *
301 * <pre>
302 * @Override
303 * public boolean dispatchKeyEvent(KeyEvent event) {
304 * return mDragController.dispatchKeyEvent(this, event)
305 * || super.dispatchKeyEvent(event);
306 * </pre>
307 */
308 public boolean dispatchKeyEvent(KeyEvent event) {
309 return mDragging;
310 }
311
Winson Chung304dcde2011-01-07 11:17:23 -0800312 public boolean isDragging() {
313 return mDragging;
314 }
315
Joe Onorato24b6fd82009-11-12 13:47:09 -0800316 /**
317 * Stop dragging without dropping.
318 */
319 public void cancelDrag() {
Winson Chung621e6402011-01-04 16:03:57 -0800320 if (mDragging) {
Winson Chungc07918d2011-07-01 15:35:26 -0700321 if (mLastDropTarget != null) {
322 mLastDropTarget.onDragExit(mDragObject);
323 }
Winson Chung41bb19d2012-03-05 18:36:46 -0800324 mDragObject.deferDragViewCleanupPostAnimation = false;
Adam Cohen36cc09b2011-09-29 17:33:15 -0700325 mDragObject.cancelled = true;
Adam Cohenbfbfd262011-06-13 16:55:12 -0700326 mDragObject.dragComplete = true;
Winson Chunga48487a2012-03-20 16:19:37 -0700327 mDragObject.dragSource.onDropCompleted(null, mDragObject, false, false);
Winson Chung621e6402011-01-04 16:03:57 -0800328 }
Joe Onorato24b6fd82009-11-12 13:47:09 -0800329 endDrag();
330 }
Winson Chung83892cc2013-05-01 16:53:33 -0700331 public void onAppsRemoved(ArrayList<ApplicationInfo> appInfos, Context context) {
Winson Chunga1820962011-10-03 16:31:06 -0700332 // Cancel the current drag if we are removing an app that we are dragging
333 if (mDragObject != null) {
334 Object rawDragInfo = mDragObject.dragInfo;
335 if (rawDragInfo instanceof ShortcutInfo) {
336 ShortcutInfo dragInfo = (ShortcutInfo) rawDragInfo;
Winson Chung83892cc2013-05-01 16:53:33 -0700337 for (ApplicationInfo info : appInfos) {
Michael Jurka7bcadad2012-04-02 07:23:44 -0700338 // Added null checks to prevent NPE we've seen in the wild
339 if (dragInfo != null &&
Winson Chungcd810732012-06-18 16:45:43 -0700340 dragInfo.intent != null) {
Winson Chung83892cc2013-05-01 16:53:33 -0700341 boolean isSameComponent =
342 dragInfo.intent.getComponent().equals(info.componentName);
343 if (isSameComponent) {
Winson Chung11a49372012-04-27 15:12:38 -0700344 cancelDrag();
345 return;
346 }
Winson Chunga1820962011-10-03 16:31:06 -0700347 }
348 }
349 }
350 }
351 }
Joe Onorato24b6fd82009-11-12 13:47:09 -0800352
Joe Onorato00acb122009-08-04 16:04:30 -0400353 private void endDrag() {
354 if (mDragging) {
355 mDragging = false;
Winson Chungaa15ffe2012-01-18 15:45:28 -0800356 clearScrollRunnable();
Winson Chung043f2af2012-03-01 16:09:54 -0800357 boolean isDeferred = false;
Adam Cohencb3382b2011-05-24 14:07:08 -0700358 if (mDragObject.dragView != null) {
Winson Chung043f2af2012-03-01 16:09:54 -0800359 isDeferred = mDragObject.deferDragViewCleanupPostAnimation;
360 if (!isDeferred) {
Winson Chung7bd1bbb2012-02-13 18:29:29 -0800361 mDragObject.dragView.remove();
362 }
Adam Cohencb3382b2011-05-24 14:07:08 -0700363 mDragObject.dragView = null;
Joe Onorato00acb122009-08-04 16:04:30 -0400364 }
Winson Chung043f2af2012-03-01 16:09:54 -0800365
366 // Only end the drag if we are not deferred
367 if (!isDeferred) {
368 for (DragListener listener : mListeners) {
369 listener.onDragEnd();
370 }
371 }
372 }
373
374 releaseVelocityTracker();
375 }
376
377 /**
378 * This only gets called as a result of drag view cleanup being deferred in endDrag();
379 */
380 void onDeferredEndDrag(DragView dragView) {
381 dragView.remove();
382
383 // If we skipped calling onDragEnd() before, do it now
384 for (DragListener listener : mListeners) {
385 listener.onDragEnd();
Joe Onorato00acb122009-08-04 16:04:30 -0400386 }
387 }
388
Winson Chunga48487a2012-03-20 16:19:37 -0700389 void onDeferredEndFling(DropTarget.DragObject d) {
390 d.dragSource.onFlingToDeleteCompleted();
391 }
392
Joe Onorato00acb122009-08-04 16:04:30 -0400393 /**
Winson Chung273c1022011-07-11 13:40:52 -0700394 * Clamps the position to the drag layer bounds.
395 */
396 private int[] getClampedDragLayerPos(float x, float y) {
397 mLauncher.getDragLayer().getLocalVisibleRect(mDragLayerRect);
398 mTmpPoint[0] = (int) Math.max(mDragLayerRect.left, Math.min(x, mDragLayerRect.right - 1));
399 mTmpPoint[1] = (int) Math.max(mDragLayerRect.top, Math.min(y, mDragLayerRect.bottom - 1));
400 return mTmpPoint;
401 }
402
Winson Chunga2413752012-04-03 14:22:34 -0700403 long getLastGestureUpTime() {
404 if (mDragging) {
405 return System.currentTimeMillis();
406 } else {
407 return mLastTouchUpTime;
408 }
409 }
410
411 void resetLastGestureUpTime() {
412 mLastTouchUpTime = -1;
413 }
414
Winson Chung273c1022011-07-11 13:40:52 -0700415 /**
Joe Onorato00acb122009-08-04 16:04:30 -0400416 * Call this from a drag source view.
417 */
418 public boolean onInterceptTouchEvent(MotionEvent ev) {
Michael Jurka3a9fced2012-04-13 14:44:29 -0700419 @SuppressWarnings("all") // suppress dead code warning
420 final boolean debug = false;
421 if (debug) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800422 Log.d(Launcher.TAG, "DragController.onInterceptTouchEvent " + ev + " mDragging="
Joe Onorato9c1289c2009-08-17 11:03:03 -0400423 + mDragging);
424 }
Joe Onorato00acb122009-08-04 16:04:30 -0400425
Winson Chung043f2af2012-03-01 16:09:54 -0800426 // Update the velocity tracker
427 acquireVelocityTrackerAndAddMovement(ev);
428
429 final int action = ev.getAction();
Winson Chung273c1022011-07-11 13:40:52 -0700430 final int[] dragLayerPos = getClampedDragLayerPos(ev.getX(), ev.getY());
431 final int dragLayerX = dragLayerPos[0];
432 final int dragLayerY = dragLayerPos[1];
Joe Onorato00acb122009-08-04 16:04:30 -0400433
434 switch (action) {
435 case MotionEvent.ACTION_MOVE:
436 break;
Joe Onorato00acb122009-08-04 16:04:30 -0400437 case MotionEvent.ACTION_DOWN:
438 // Remember location of down touch
Adam Cohen8dfcba42011-07-07 16:38:18 -0700439 mMotionDownX = dragLayerX;
440 mMotionDownY = dragLayerY;
Joe Onorato00acb122009-08-04 16:04:30 -0400441 mLastDropTarget = null;
442 break;
Joe Onorato00acb122009-08-04 16:04:30 -0400443 case MotionEvent.ACTION_UP:
Winson Chunga2413752012-04-03 14:22:34 -0700444 mLastTouchUpTime = System.currentTimeMillis();
Joe Onorato00acb122009-08-04 16:04:30 -0400445 if (mDragging) {
Winson Chung043f2af2012-03-01 16:09:54 -0800446 PointF vec = isFlingingToDelete(mDragObject.dragSource);
447 if (vec != null) {
448 dropOnFlingToDeleteTarget(dragLayerX, dragLayerY, vec);
449 } else {
450 drop(dragLayerX, dragLayerY);
451 }
Joe Onorato00acb122009-08-04 16:04:30 -0400452 }
453 endDrag();
454 break;
Winson Chung621e6402011-01-04 16:03:57 -0800455 case MotionEvent.ACTION_CANCEL:
456 cancelDrag();
457 break;
Joe Onorato00acb122009-08-04 16:04:30 -0400458 }
459
460 return mDragging;
461 }
462
463 /**
Romain Guyea3763c2010-01-11 18:02:04 -0800464 * Sets the view that should handle move events.
465 */
466 void setMoveTarget(View view) {
467 mMoveTarget = view;
468 }
469
470 public boolean dispatchUnhandledMove(View focused, int direction) {
471 return mMoveTarget != null && mMoveTarget.dispatchUnhandledMove(focused, direction);
472 }
473
Winson Chungaa15ffe2012-01-18 15:45:28 -0800474 private void clearScrollRunnable() {
475 mHandler.removeCallbacks(mScrollRunnable);
476 if (mScrollState == SCROLL_WAITING_IN_ZONE) {
477 mScrollState = SCROLL_OUTSIDE_ZONE;
478 mScrollRunnable.setDirection(SCROLL_RIGHT);
479 mDragScroller.onExitScrollArea();
Winson Chung360e63f2012-04-27 13:48:05 -0700480 mLauncher.getDragLayer().onExitScrollArea();
Winson Chungaa15ffe2012-01-18 15:45:28 -0800481 }
482 }
483
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700484 private void handleMoveEvent(int x, int y) {
Adam Cohencb3382b2011-05-24 14:07:08 -0700485 mDragObject.dragView.move(x, y);
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700486
487 // Drop on someone?
488 final int[] coordinates = mCoordinatesTemp;
489 DropTarget dropTarget = findDropTarget(x, y, coordinates);
Adam Cohencb3382b2011-05-24 14:07:08 -0700490 mDragObject.x = coordinates[0];
491 mDragObject.y = coordinates[1];
Winson Chung25460a12013-04-01 18:21:28 -0700492 checkTouchMove(dropTarget);
493
494 // Check if we are hovering over the scroll areas
495 mDistanceSinceScroll +=
496 Math.sqrt(Math.pow(mLastTouch[0] - x, 2) + Math.pow(mLastTouch[1] - y, 2));
497 mLastTouch[0] = x;
498 mLastTouch[1] = y;
499 checkScrollState(x, y);
500 }
501
502 public void forceTouchMove() {
503 int[] dummyCoordinates = mCoordinatesTemp;
504 DropTarget dropTarget = findDropTarget(mLastTouch[0], mLastTouch[1], dummyCoordinates);
505 checkTouchMove(dropTarget);
506 }
507
508 private void checkTouchMove(DropTarget dropTarget) {
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700509 if (dropTarget != null) {
Adam Cohencb3382b2011-05-24 14:07:08 -0700510 DropTarget delegate = dropTarget.getDropTargetDelegate(mDragObject);
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700511 if (delegate != null) {
512 dropTarget = delegate;
513 }
514
515 if (mLastDropTarget != dropTarget) {
516 if (mLastDropTarget != null) {
Adam Cohencb3382b2011-05-24 14:07:08 -0700517 mLastDropTarget.onDragExit(mDragObject);
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700518 }
Adam Cohencb3382b2011-05-24 14:07:08 -0700519 dropTarget.onDragEnter(mDragObject);
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700520 }
Adam Cohencb3382b2011-05-24 14:07:08 -0700521 dropTarget.onDragOver(mDragObject);
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700522 } else {
523 if (mLastDropTarget != null) {
Adam Cohencb3382b2011-05-24 14:07:08 -0700524 mLastDropTarget.onDragExit(mDragObject);
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700525 }
526 }
527 mLastDropTarget = dropTarget;
Winson Chung25460a12013-04-01 18:21:28 -0700528 }
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700529
Winson Chung25460a12013-04-01 18:21:28 -0700530 private void checkScrollState(int x, int y) {
Adam Cohen8dfcba42011-07-07 16:38:18 -0700531 final int slop = ViewConfiguration.get(mLauncher).getScaledWindowTouchSlop();
Winson Chungaa15ffe2012-01-18 15:45:28 -0800532 final int delay = mDistanceSinceScroll < slop ? RESCROLL_DELAY : SCROLL_DELAY;
Winson Chungfe1fe262013-04-01 16:52:31 -0700533 final DragLayer dragLayer = mLauncher.getDragLayer();
534 final boolean isRtl = (dragLayer.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL);
535 final int forwardDirection = isRtl ? SCROLL_RIGHT : SCROLL_LEFT;
536 final int backwardsDirection = isRtl ? SCROLL_LEFT : SCROLL_RIGHT;
Patrick Dubroya16fd5a2010-10-07 16:47:28 -0700537
Winson Chung3f4e1422011-11-17 14:58:51 -0800538 if (x < mScrollZone) {
Winson Chungaa15ffe2012-01-18 15:45:28 -0800539 if (mScrollState == SCROLL_OUTSIDE_ZONE) {
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700540 mScrollState = SCROLL_WAITING_IN_ZONE;
Winson Chungfe1fe262013-04-01 16:52:31 -0700541 if (mDragScroller.onEnterScrollArea(x, y, forwardDirection)) {
542 dragLayer.onEnterScrollArea(forwardDirection);
543 mScrollRunnable.setDirection(forwardDirection);
Winson Chungaa15ffe2012-01-18 15:45:28 -0800544 mHandler.postDelayed(mScrollRunnable, delay);
Winson Chung3e0839e2011-10-03 15:15:18 -0700545 }
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700546 }
Winson Chung3f4e1422011-11-17 14:58:51 -0800547 } else if (x > mScrollView.getWidth() - mScrollZone) {
Winson Chungaa15ffe2012-01-18 15:45:28 -0800548 if (mScrollState == SCROLL_OUTSIDE_ZONE) {
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700549 mScrollState = SCROLL_WAITING_IN_ZONE;
Winson Chungfe1fe262013-04-01 16:52:31 -0700550 if (mDragScroller.onEnterScrollArea(x, y, backwardsDirection)) {
551 dragLayer.onEnterScrollArea(backwardsDirection);
552 mScrollRunnable.setDirection(backwardsDirection);
Winson Chungaa15ffe2012-01-18 15:45:28 -0800553 mHandler.postDelayed(mScrollRunnable, delay);
Winson Chung3e0839e2011-10-03 15:15:18 -0700554 }
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700555 }
556 } else {
Winson Chungaa15ffe2012-01-18 15:45:28 -0800557 clearScrollRunnable();
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700558 }
559 }
560
Romain Guyea3763c2010-01-11 18:02:04 -0800561 /**
Joe Onorato00acb122009-08-04 16:04:30 -0400562 * Call this from a drag source view.
563 */
564 public boolean onTouchEvent(MotionEvent ev) {
Joe Onorato00acb122009-08-04 16:04:30 -0400565 if (!mDragging) {
566 return false;
567 }
568
Winson Chung043f2af2012-03-01 16:09:54 -0800569 // Update the velocity tracker
570 acquireVelocityTrackerAndAddMovement(ev);
571
Joe Onorato00acb122009-08-04 16:04:30 -0400572 final int action = ev.getAction();
Winson Chung273c1022011-07-11 13:40:52 -0700573 final int[] dragLayerPos = getClampedDragLayerPos(ev.getX(), ev.getY());
574 final int dragLayerX = dragLayerPos[0];
575 final int dragLayerY = dragLayerPos[1];
Joe Onorato00acb122009-08-04 16:04:30 -0400576
577 switch (action) {
578 case MotionEvent.ACTION_DOWN:
Joe Onorato00acb122009-08-04 16:04:30 -0400579 // Remember where the motion event started
Adam Cohen8dfcba42011-07-07 16:38:18 -0700580 mMotionDownX = dragLayerX;
581 mMotionDownY = dragLayerY;
Joe Onorato00acb122009-08-04 16:04:30 -0400582
Adam Cohen8dfcba42011-07-07 16:38:18 -0700583 if ((dragLayerX < mScrollZone) || (dragLayerX > mScrollView.getWidth() - mScrollZone)) {
Joe Onorato00acb122009-08-04 16:04:30 -0400584 mScrollState = SCROLL_WAITING_IN_ZONE;
585 mHandler.postDelayed(mScrollRunnable, SCROLL_DELAY);
586 } else {
587 mScrollState = SCROLL_OUTSIDE_ZONE;
588 }
Joe Onorato00acb122009-08-04 16:04:30 -0400589 break;
590 case MotionEvent.ACTION_MOVE:
Adam Cohen8dfcba42011-07-07 16:38:18 -0700591 handleMoveEvent(dragLayerX, dragLayerY);
Joe Onorato00acb122009-08-04 16:04:30 -0400592 break;
593 case MotionEvent.ACTION_UP:
Patrick Dubroyb0a6bbe2011-03-02 18:40:21 -0800594 // Ensure that we've processed a move event at the current pointer location.
Adam Cohen8dfcba42011-07-07 16:38:18 -0700595 handleMoveEvent(dragLayerX, dragLayerY);
Winson Chung3bc21c32012-01-20 13:59:18 -0800596 mHandler.removeCallbacks(mScrollRunnable);
Winson Chung043f2af2012-03-01 16:09:54 -0800597
Joe Onorato00acb122009-08-04 16:04:30 -0400598 if (mDragging) {
Winson Chung043f2af2012-03-01 16:09:54 -0800599 PointF vec = isFlingingToDelete(mDragObject.dragSource);
Adam Cohen947dc542013-06-06 22:43:33 -0700600 if (!(mDragObject.dragInfo instanceof LauncherAppWidgetInfo) &&
601 !(mDragObject.dragInfo instanceof PendingAddWidgetInfo)) {
602 vec = null;
603 }
Winson Chung043f2af2012-03-01 16:09:54 -0800604 if (vec != null) {
605 dropOnFlingToDeleteTarget(dragLayerX, dragLayerY, vec);
606 } else {
607 drop(dragLayerX, dragLayerY);
608 }
Joe Onorato00acb122009-08-04 16:04:30 -0400609 }
610 endDrag();
Joe Onorato00acb122009-08-04 16:04:30 -0400611 break;
612 case MotionEvent.ACTION_CANCEL:
Winson Chung3bc21c32012-01-20 13:59:18 -0800613 mHandler.removeCallbacks(mScrollRunnable);
Joe Onorato24b6fd82009-11-12 13:47:09 -0800614 cancelDrag();
Winson Chung621e6402011-01-04 16:03:57 -0800615 break;
Joe Onorato00acb122009-08-04 16:04:30 -0400616 }
617
618 return true;
619 }
620
Winson Chung043f2af2012-03-01 16:09:54 -0800621 /**
622 * Determines whether the user flung the current item to delete it.
623 *
624 * @return the vector at which the item was flung, or null if no fling was detected.
625 */
626 private PointF isFlingingToDelete(DragSource source) {
627 if (mFlingToDeleteDropTarget == null) return null;
628 if (!source.supportsFlingToDelete()) return null;
629
630 ViewConfiguration config = ViewConfiguration.get(mLauncher);
631 mVelocityTracker.computeCurrentVelocity(1000, config.getScaledMaximumFlingVelocity());
632
633 if (mVelocityTracker.getYVelocity() < mFlingToDeleteThresholdVelocity) {
634 // Do a quick dot product test to ensure that we are flinging upwards
635 PointF vel = new PointF(mVelocityTracker.getXVelocity(),
636 mVelocityTracker.getYVelocity());
637 PointF upVec = new PointF(0f, -1f);
638 float theta = (float) Math.acos(((vel.x * upVec.x) + (vel.y * upVec.y)) /
639 (vel.length() * upVec.length()));
640 if (theta <= Math.toRadians(MAX_FLING_DEGREES)) {
641 return vel;
642 }
643 }
644 return null;
645 }
646
647 private void dropOnFlingToDeleteTarget(float x, float y, PointF vel) {
648 final int[] coordinates = mCoordinatesTemp;
649
650 mDragObject.x = coordinates[0];
651 mDragObject.y = coordinates[1];
Winson Chung043f2af2012-03-01 16:09:54 -0800652
653 // Clean up dragging on the target if it's not the current fling delete target otherwise,
654 // start dragging to it.
655 if (mLastDropTarget != null && mFlingToDeleteDropTarget != mLastDropTarget) {
656 mLastDropTarget.onDragExit(mDragObject);
657 }
658
659 // Drop onto the fling-to-delete target
660 boolean accepted = false;
661 mFlingToDeleteDropTarget.onDragEnter(mDragObject);
Winson Chung232decb2012-03-28 15:09:05 -0700662 // We must set dragComplete to true _only_ after we "enter" the fling-to-delete target for
663 // "drop"
664 mDragObject.dragComplete = true;
Winson Chung043f2af2012-03-01 16:09:54 -0800665 mFlingToDeleteDropTarget.onDragExit(mDragObject);
666 if (mFlingToDeleteDropTarget.acceptDrop(mDragObject)) {
667 mFlingToDeleteDropTarget.onFlingToDelete(mDragObject, mDragObject.x, mDragObject.y,
668 vel);
669 accepted = true;
670 }
Winson Chunga48487a2012-03-20 16:19:37 -0700671 mDragObject.dragSource.onDropCompleted((View) mFlingToDeleteDropTarget, mDragObject, true,
Winson Chung043f2af2012-03-01 16:09:54 -0800672 accepted);
673 }
674
Patrick Dubroyb0a6bbe2011-03-02 18:40:21 -0800675 private void drop(float x, float y) {
Joe Onorato00acb122009-08-04 16:04:30 -0400676 final int[] coordinates = mCoordinatesTemp;
Patrick Dubroyb0a6bbe2011-03-02 18:40:21 -0800677 final DropTarget dropTarget = findDropTarget((int) x, (int) y, coordinates);
Joe Onorato00acb122009-08-04 16:04:30 -0400678
Adam Cohencb3382b2011-05-24 14:07:08 -0700679 mDragObject.x = coordinates[0];
680 mDragObject.y = coordinates[1];
Patrick Dubroyb0a6bbe2011-03-02 18:40:21 -0800681 boolean accepted = false;
Joe Onorato00acb122009-08-04 16:04:30 -0400682 if (dropTarget != null) {
Adam Cohenbfbfd262011-06-13 16:55:12 -0700683 mDragObject.dragComplete = true;
Adam Cohencb3382b2011-05-24 14:07:08 -0700684 dropTarget.onDragExit(mDragObject);
685 if (dropTarget.acceptDrop(mDragObject)) {
686 dropTarget.onDrop(mDragObject);
Patrick Dubroyb0a6bbe2011-03-02 18:40:21 -0800687 accepted = true;
Joe Onorato00acb122009-08-04 16:04:30 -0400688 }
689 }
Winson Chunga48487a2012-03-20 16:19:37 -0700690 mDragObject.dragSource.onDropCompleted((View) dropTarget, mDragObject, false, accepted);
Joe Onorato00acb122009-08-04 16:04:30 -0400691 }
692
693 private DropTarget findDropTarget(int x, int y, int[] dropCoordinates) {
694 final Rect r = mRectTemp;
695
696 final ArrayList<DropTarget> dropTargets = mDropTargets;
697 final int count = dropTargets.size();
698 for (int i=count-1; i>=0; i--) {
Patrick Dubroy440c3602010-07-13 17:50:32 -0700699 DropTarget target = dropTargets.get(i);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700700 if (!target.isDropEnabled())
701 continue;
702
Joe Onorato00acb122009-08-04 16:04:30 -0400703 target.getHitRect(r);
Patrick Dubroy440c3602010-07-13 17:50:32 -0700704
Adam Cohen8dfcba42011-07-07 16:38:18 -0700705 // Convert the hit rect to DragLayer coordinates
706 target.getLocationInDragLayer(dropCoordinates);
Joe Onorato00acb122009-08-04 16:04:30 -0400707 r.offset(dropCoordinates[0] - target.getLeft(), dropCoordinates[1] - target.getTop());
Patrick Dubroy440c3602010-07-13 17:50:32 -0700708
Adam Cohencb3382b2011-05-24 14:07:08 -0700709 mDragObject.x = x;
710 mDragObject.y = y;
Joe Onorato00acb122009-08-04 16:04:30 -0400711 if (r.contains(x, y)) {
Adam Cohencb3382b2011-05-24 14:07:08 -0700712 DropTarget delegate = target.getDropTargetDelegate(mDragObject);
Patrick Dubroy440c3602010-07-13 17:50:32 -0700713 if (delegate != null) {
714 target = delegate;
Adam Cohen8dfcba42011-07-07 16:38:18 -0700715 target.getLocationInDragLayer(dropCoordinates);
Patrick Dubroy440c3602010-07-13 17:50:32 -0700716 }
717
718 // Make dropCoordinates relative to the DropTarget
Joe Onorato00acb122009-08-04 16:04:30 -0400719 dropCoordinates[0] = x - dropCoordinates[0];
720 dropCoordinates[1] = y - dropCoordinates[1];
Patrick Dubroy440c3602010-07-13 17:50:32 -0700721
Joe Onorato00acb122009-08-04 16:04:30 -0400722 return target;
723 }
724 }
725 return null;
726 }
727
728 public void setDragScoller(DragScroller scroller) {
729 mDragScroller = scroller;
730 }
731
732 public void setWindowToken(IBinder token) {
733 mWindowToken = token;
734 }
735
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800736 /**
737 * Sets the drag listner which will be notified when a drag starts or ends.
738 */
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700739 public void addDragListener(DragListener l) {
740 mListeners.add(l);
Joe Onorato00acb122009-08-04 16:04:30 -0400741 }
742
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800743 /**
744 * Remove a previously installed drag listener.
745 */
Joe Onorato00acb122009-08-04 16:04:30 -0400746 public void removeDragListener(DragListener l) {
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700747 mListeners.remove(l);
Joe Onorato00acb122009-08-04 16:04:30 -0400748 }
749
750 /**
751 * Add a DropTarget to the list of potential places to receive drop events.
752 */
753 public void addDropTarget(DropTarget target) {
754 mDropTargets.add(target);
755 }
756
757 /**
758 * Don't send drop events to <em>target</em> any more.
759 */
760 public void removeDropTarget(DropTarget target) {
761 mDropTargets.remove(target);
762 }
763
764 /**
Winson Chung043f2af2012-03-01 16:09:54 -0800765 * Sets the current fling-to-delete drop target.
766 */
767 public void setFlingToDeleteDropTarget(DropTarget target) {
768 mFlingToDeleteDropTarget = target;
769 }
770
771 private void acquireVelocityTrackerAndAddMovement(MotionEvent ev) {
772 if (mVelocityTracker == null) {
773 mVelocityTracker = VelocityTracker.obtain();
774 }
775 mVelocityTracker.addMovement(ev);
776 }
777
778 private void releaseVelocityTracker() {
779 if (mVelocityTracker != null) {
780 mVelocityTracker.recycle();
781 mVelocityTracker = null;
782 }
783 }
784
785 /**
Joe Onorato00acb122009-08-04 16:04:30 -0400786 * Set which view scrolls for touch events near the edge of the screen.
787 */
788 public void setScrollView(View v) {
789 mScrollView = v;
790 }
791
Patrick Dubroy5f445422011-02-18 14:35:21 -0800792 DragView getDragView() {
Adam Cohencb3382b2011-05-24 14:07:08 -0700793 return mDragObject.dragView;
Patrick Dubroy5f445422011-02-18 14:35:21 -0800794 }
795
Joe Onorato00acb122009-08-04 16:04:30 -0400796 private class ScrollRunnable implements Runnable {
797 private int mDirection;
798
799 ScrollRunnable() {
800 }
801
802 public void run() {
803 if (mDragScroller != null) {
804 if (mDirection == SCROLL_LEFT) {
805 mDragScroller.scrollLeft();
806 } else {
807 mDragScroller.scrollRight();
808 }
809 mScrollState = SCROLL_OUTSIDE_ZONE;
Patrick Dubroya16fd5a2010-10-07 16:47:28 -0700810 mDistanceSinceScroll = 0;
811 mDragScroller.onExitScrollArea();
Winson Chung360e63f2012-04-27 13:48:05 -0700812 mLauncher.getDragLayer().onExitScrollArea();
Winson Chungaa15ffe2012-01-18 15:45:28 -0800813
814 if (isDragging()) {
Winson Chung25460a12013-04-01 18:21:28 -0700815 // Check the scroll again so that we can requeue the scroller if necessary
816 checkScrollState(mLastTouch[0], mLastTouch[1]);
Winson Chungaa15ffe2012-01-18 15:45:28 -0800817 }
Joe Onorato00acb122009-08-04 16:04:30 -0400818 }
819 }
820
821 void setDirection(int direction) {
822 mDirection = direction;
823 }
824 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800825}