The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 1 | /* |
| 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 Onorato | a590252 | 2009-07-30 13:37:37 -0700 | [diff] [blame] | 17 | package com.android.launcher2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 18 | |
Adam Cohen | 120980b | 2010-12-08 11:05:37 -0800 | [diff] [blame] | 19 | import java.util.ArrayList; |
Patrick Dubroy | a16fd5a | 2010-10-07 16:47:28 -0700 | [diff] [blame] | 20 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 21 | import android.content.Context; |
| 22 | import android.graphics.Bitmap; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 23 | import android.graphics.Rect; |
| 24 | import android.graphics.RectF; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 25 | import android.os.Handler; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 26 | import android.os.IBinder; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 27 | import android.os.Vibrator; |
Joe Onorato | e048e8a | 2009-09-25 10:39:17 -0700 | [diff] [blame] | 28 | import android.util.DisplayMetrics; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 29 | import android.util.Log; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 30 | import android.view.KeyEvent; |
| 31 | import android.view.MotionEvent; |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 32 | import android.view.View; |
Patrick Dubroy | a16fd5a | 2010-10-07 16:47:28 -0700 | [diff] [blame] | 33 | import android.view.ViewConfiguration; |
Joe Onorato | e048e8a | 2009-09-25 10:39:17 -0700 | [diff] [blame] | 34 | import android.view.WindowManager; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 35 | import android.view.inputmethod.InputMethodManager; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 36 | |
Adam Cohen | 120980b | 2010-12-08 11:05:37 -0800 | [diff] [blame] | 37 | import com.android.launcher.R; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 38 | |
| 39 | /** |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 40 | * Class for initiating a drag within a view or across multiple views. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 41 | */ |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 42 | public class DragController { |
Romain Guy | ea3763c | 2010-01-11 18:02:04 -0800 | [diff] [blame] | 43 | @SuppressWarnings({"UnusedDeclaration"}) |
Joe Onorato | 2e5c432 | 2009-10-06 12:34:42 -0700 | [diff] [blame] | 44 | private static final String TAG = "Launcher.DragController"; |
| 45 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 46 | /** 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 | |
| 52 | private static final int SCROLL_DELAY = 600; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 53 | private static final int VIBRATE_DURATION = 35; |
| 54 | |
| 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 Dubroy | 54fa3b9 | 2010-11-17 12:18:45 -0800 | [diff] [blame] | 60 | static final int SCROLL_NONE = -1; |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 61 | static final int SCROLL_LEFT = 0; |
| 62 | static final int SCROLL_RIGHT = 1; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 63 | |
| 64 | private Context mContext; |
| 65 | private Handler mHandler; |
| 66 | private final Vibrator mVibrator = new Vibrator(); |
| 67 | |
| 68 | // temporaries to avoid gc thrash |
| 69 | private Rect mRectTemp = new Rect(); |
| 70 | private final int[] mCoordinatesTemp = new int[2]; |
| 71 | |
| 72 | /** Whether or not we're dragging. */ |
| 73 | private boolean mDragging; |
| 74 | |
| 75 | /** X coordinate of the down event. */ |
| 76 | private float mMotionDownX; |
| 77 | |
| 78 | /** Y coordinate of the down event. */ |
| 79 | private float mMotionDownY; |
| 80 | |
Joe Onorato | e048e8a | 2009-09-25 10:39:17 -0700 | [diff] [blame] | 81 | /** Info about the screen for clamping. */ |
| 82 | private DisplayMetrics mDisplayMetrics = new DisplayMetrics(); |
| 83 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 84 | /** Original view that is being dragged. */ |
| 85 | private View mOriginator; |
| 86 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 87 | /** X offset from the upper-left corner of the cell to where we touched. */ |
| 88 | private float mTouchOffsetX; |
| 89 | |
| 90 | /** Y offset from the upper-left corner of the cell to where we touched. */ |
| 91 | private float mTouchOffsetY; |
| 92 | |
Joe Onorato | 658db74 | 2010-09-29 11:40:39 -0700 | [diff] [blame] | 93 | /** the area at the edge of the screen that makes the workspace go left |
| 94 | * or right while you're dragging. |
| 95 | */ |
| 96 | private int mScrollZone; |
| 97 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 98 | /** Where the drag originated */ |
| 99 | private DragSource mDragSource; |
| 100 | |
| 101 | /** The data associated with the object being dragged */ |
| 102 | private Object mDragInfo; |
| 103 | |
| 104 | /** The view that moves around while you drag. */ |
| 105 | private DragView mDragView; |
| 106 | |
| 107 | /** Who can receive drop events */ |
| 108 | private ArrayList<DropTarget> mDropTargets = new ArrayList<DropTarget>(); |
| 109 | |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 110 | private ArrayList<DragListener> mListeners = new ArrayList<DragListener>(); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 111 | |
| 112 | /** The window token used as the parent for the DragView. */ |
| 113 | private IBinder mWindowToken; |
| 114 | |
| 115 | /** The view that will be scrolled when dragging to the left and right edges of the screen. */ |
| 116 | private View mScrollView; |
| 117 | |
Romain Guy | ea3763c | 2010-01-11 18:02:04 -0800 | [diff] [blame] | 118 | private View mMoveTarget; |
| 119 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 120 | private DragScroller mDragScroller; |
| 121 | private int mScrollState = SCROLL_OUTSIDE_ZONE; |
| 122 | private ScrollRunnable mScrollRunnable = new ScrollRunnable(); |
| 123 | |
| 124 | private RectF mDeleteRegion; |
| 125 | private DropTarget mLastDropTarget; |
| 126 | |
| 127 | private InputMethodManager mInputMethodManager; |
| 128 | |
Patrick Dubroy | a16fd5a | 2010-10-07 16:47:28 -0700 | [diff] [blame] | 129 | private int mLastTouch[] = new int[2]; |
| 130 | private int mDistanceSinceScroll = 0; |
| 131 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 132 | /** |
| 133 | * Interface to receive notifications when a drag starts or stops |
| 134 | */ |
| 135 | interface DragListener { |
| 136 | |
| 137 | /** |
| 138 | * A drag has begun |
| 139 | * |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 140 | * @param source An object representing where the drag originated |
| 141 | * @param info The data associated with the object that is being dragged |
| 142 | * @param dragAction The drag action: either {@link DragController#DRAG_ACTION_MOVE} |
| 143 | * or {@link DragController#DRAG_ACTION_COPY} |
| 144 | */ |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 145 | void onDragStart(DragSource source, Object info, int dragAction); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 146 | |
| 147 | /** |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 148 | * The drag has ended |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 149 | */ |
| 150 | void onDragEnd(); |
| 151 | } |
| 152 | |
| 153 | /** |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 154 | * Used to create a new DragLayer from XML. |
| 155 | * |
| 156 | * @param context The application's context. |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 157 | */ |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 158 | public DragController(Context context) { |
| 159 | mContext = context; |
| 160 | mHandler = new Handler(); |
Joe Onorato | 658db74 | 2010-09-29 11:40:39 -0700 | [diff] [blame] | 161 | mScrollZone = context.getResources().getDimensionPixelSize(R.dimen.scroll_zone); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 162 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 163 | |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 164 | public boolean dragging() { |
| 165 | return mDragging; |
| 166 | } |
| 167 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 168 | /** |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 169 | * Starts a drag. |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 170 | * |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 171 | * @param v The view that is being dragged |
| 172 | * @param source An object representing where the drag originated |
Romain Guy | ea3763c | 2010-01-11 18:02:04 -0800 | [diff] [blame] | 173 | * @param dragInfo The data associated with the object that is being dragged |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 174 | * @param dragAction The drag action: either {@link #DRAG_ACTION_MOVE} or |
| 175 | * {@link #DRAG_ACTION_COPY} |
| 176 | */ |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 177 | public void startDrag(View v, DragSource source, Object dragInfo, int dragAction) { |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 178 | startDrag(v, source, dragInfo, dragAction, null); |
| 179 | } |
| 180 | |
| 181 | /** |
| 182 | * Starts a drag. |
| 183 | * |
| 184 | * @param v The view that is being dragged |
| 185 | * @param source An object representing where the drag originated |
| 186 | * @param dragInfo The data associated with the object that is being dragged |
| 187 | * @param dragAction The drag action: either {@link #DRAG_ACTION_MOVE} or |
| 188 | * {@link #DRAG_ACTION_COPY} |
| 189 | * @param dragRegion Coordinates within the bitmap b for the position of item being dragged. |
| 190 | * Makes dragging feel more precise, e.g. you can clip out a transparent border |
| 191 | */ |
| 192 | public void startDrag(View v, DragSource source, Object dragInfo, int dragAction, |
| 193 | Rect dragRegion) { |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 194 | mOriginator = v; |
| 195 | |
| 196 | Bitmap b = getViewBitmap(v); |
| 197 | |
Daniel Sandler | 3f8175a | 2010-05-25 11:48:32 -0400 | [diff] [blame] | 198 | if (b == null) { |
| 199 | // out of memory? |
| 200 | return; |
| 201 | } |
| 202 | |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 203 | int[] loc = mCoordinatesTemp; |
| 204 | v.getLocationOnScreen(loc); |
| 205 | int screenX = loc[0]; |
| 206 | int screenY = loc[1]; |
| 207 | |
| 208 | startDrag(b, screenX, screenY, 0, 0, b.getWidth(), b.getHeight(), |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 209 | source, dragInfo, dragAction, dragRegion); |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 210 | |
| 211 | b.recycle(); |
| 212 | |
| 213 | if (dragAction == DRAG_ACTION_MOVE) { |
| 214 | v.setVisibility(View.GONE); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | /** |
| 219 | * Starts a drag. |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 220 | * |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 221 | * @param v The view that is being dragged |
| 222 | * @param bmp The bitmap that represents the view being dragged |
| 223 | * @param source An object representing where the drag originated |
| 224 | * @param dragInfo The data associated with the object that is being dragged |
| 225 | * @param dragAction The drag action: either {@link #DRAG_ACTION_MOVE} or |
| 226 | * {@link #DRAG_ACTION_COPY} |
| 227 | * @param dragRegion Coordinates within the bitmap b for the position of item being dragged. |
| 228 | * Makes dragging feel more precise, e.g. you can clip out a transparent border |
| 229 | */ |
| 230 | public void startDrag(View v, Bitmap bmp, DragSource source, Object dragInfo, int dragAction, |
| 231 | Rect dragRegion) { |
| 232 | mOriginator = v; |
| 233 | |
| 234 | int[] loc = mCoordinatesTemp; |
| 235 | v.getLocationOnScreen(loc); |
| 236 | int screenX = loc[0]; |
| 237 | int screenY = loc[1]; |
| 238 | |
| 239 | startDrag(bmp, screenX, screenY, 0, 0, bmp.getWidth(), bmp.getHeight(), |
| 240 | source, dragInfo, dragAction, dragRegion); |
| 241 | |
| 242 | if (dragAction == DRAG_ACTION_MOVE) { |
| 243 | v.setVisibility(View.GONE); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | /** |
| 248 | * Starts a drag. |
| 249 | * |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 250 | * @param b The bitmap to display as the drag image. It will be re-scaled to the |
| 251 | * enlarged size. |
| 252 | * @param screenX The x position on screen of the left-top of the bitmap. |
| 253 | * @param screenY The y position on screen of the left-top of the bitmap. |
| 254 | * @param textureLeft The left edge of the region inside b to use. |
| 255 | * @param textureTop The top edge of the region inside b to use. |
| 256 | * @param textureWidth The width of the region inside b to use. |
| 257 | * @param textureHeight The height of the region inside b to use. |
| 258 | * @param source An object representing where the drag originated |
Romain Guy | ea3763c | 2010-01-11 18:02:04 -0800 | [diff] [blame] | 259 | * @param dragInfo The data associated with the object that is being dragged |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 260 | * @param dragAction The drag action: either {@link #DRAG_ACTION_MOVE} or |
| 261 | * {@link #DRAG_ACTION_COPY} |
| 262 | */ |
| 263 | public void startDrag(Bitmap b, int screenX, int screenY, |
| 264 | int textureLeft, int textureTop, int textureWidth, int textureHeight, |
| 265 | DragSource source, Object dragInfo, int dragAction) { |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 266 | startDrag(b, screenX, screenY, textureLeft, textureTop, textureWidth, textureHeight, |
| 267 | source, dragInfo, dragAction, null); |
| 268 | } |
| 269 | |
| 270 | /** |
| 271 | * Starts a drag. |
| 272 | * |
| 273 | * @param b The bitmap to display as the drag image. It will be re-scaled to the |
| 274 | * enlarged size. |
| 275 | * @param screenX The x position on screen of the left-top of the bitmap. |
| 276 | * @param screenY The y position on screen of the left-top of the bitmap. |
| 277 | * @param textureLeft The left edge of the region inside b to use. |
| 278 | * @param textureTop The top edge of the region inside b to use. |
| 279 | * @param textureWidth The width of the region inside b to use. |
| 280 | * @param textureHeight The height of the region inside b to use. |
| 281 | * @param source An object representing where the drag originated |
| 282 | * @param dragInfo The data associated with the object that is being dragged |
| 283 | * @param dragAction The drag action: either {@link #DRAG_ACTION_MOVE} or |
| 284 | * {@link #DRAG_ACTION_COPY} |
| 285 | * @param dragRegion Coordinates within the bitmap b for the position of item being dragged. |
| 286 | * Makes dragging feel more precise, e.g. you can clip out a transparent border |
| 287 | */ |
| 288 | public void startDrag(Bitmap b, int screenX, int screenY, |
| 289 | int textureLeft, int textureTop, int textureWidth, int textureHeight, |
| 290 | DragSource source, Object dragInfo, int dragAction, Rect dragRegion) { |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 291 | if (PROFILE_DRAWING_DURING_DRAG) { |
| 292 | android.os.Debug.startMethodTracing("Launcher"); |
| 293 | } |
| 294 | |
| 295 | // Hide soft keyboard, if visible |
| 296 | if (mInputMethodManager == null) { |
| 297 | mInputMethodManager = (InputMethodManager) |
| 298 | mContext.getSystemService(Context.INPUT_METHOD_SERVICE); |
| 299 | } |
| 300 | mInputMethodManager.hideSoftInputFromWindow(mWindowToken, 0); |
| 301 | |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 302 | for (DragListener listener : mListeners) { |
| 303 | listener.onDragStart(source, dragInfo, dragAction); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 304 | } |
| 305 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 306 | int registrationX = ((int)mMotionDownX) - screenX; |
| 307 | int registrationY = ((int)mMotionDownY) - screenY; |
| 308 | |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 309 | final int dragRegionLeft = dragRegion == null ? 0 : dragRegion.left; |
| 310 | final int dragRegionTop = dragRegion == null ? 0 : dragRegion.top; |
| 311 | mTouchOffsetX = mMotionDownX - screenX - dragRegionLeft; |
| 312 | mTouchOffsetY = mMotionDownY - screenY - dragRegionTop; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 313 | |
| 314 | mDragging = true; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 315 | mDragSource = source; |
| 316 | mDragInfo = dragInfo; |
| 317 | |
| 318 | mVibrator.vibrate(VIBRATE_DURATION); |
| 319 | |
Joe Onorato | 5162ea9 | 2009-09-03 09:39:42 -0700 | [diff] [blame] | 320 | DragView dragView = mDragView = new DragView(mContext, b, registrationX, registrationY, |
| 321 | textureLeft, textureTop, textureWidth, textureHeight); |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 322 | |
Patrick Dubroy | a669d79 | 2010-11-23 14:40:33 -0800 | [diff] [blame] | 323 | final DragSource dragSource = source; |
| 324 | dragView.setOnDrawRunnable(new Runnable() { |
| 325 | public void run() { |
| 326 | dragSource.onDragViewVisible(); |
| 327 | }; |
| 328 | }); |
| 329 | |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 330 | if (dragRegion != null) { |
| 331 | dragView.setDragRegion(dragRegionLeft, dragRegion.top, |
| 332 | dragRegion.right - dragRegionLeft, dragRegion.bottom - dragRegionTop); |
| 333 | } |
| 334 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 335 | dragView.show(mWindowToken, (int)mMotionDownX, (int)mMotionDownY); |
Patrick Dubroy | de7658b | 2010-09-27 11:15:43 -0700 | [diff] [blame] | 336 | |
| 337 | handleMoveEvent((int) mMotionDownX, (int) mMotionDownY); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | /** |
| 341 | * Draw the view into a bitmap. |
| 342 | */ |
Adam Cohen | 120980b | 2010-12-08 11:05:37 -0800 | [diff] [blame] | 343 | Bitmap getViewBitmap(View v) { |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 344 | v.clearFocus(); |
| 345 | v.setPressed(false); |
| 346 | |
| 347 | boolean willNotCache = v.willNotCacheDrawing(); |
| 348 | v.setWillNotCacheDrawing(false); |
| 349 | |
| 350 | // Reset the drawing cache background color to fully transparent |
| 351 | // for the duration of this operation |
| 352 | int color = v.getDrawingCacheBackgroundColor(); |
| 353 | v.setDrawingCacheBackgroundColor(0); |
Adam Cohen | 120980b | 2010-12-08 11:05:37 -0800 | [diff] [blame] | 354 | float alpha = v.getAlpha(); |
| 355 | v.setAlpha(1.0f); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 356 | |
| 357 | if (color != 0) { |
| 358 | v.destroyDrawingCache(); |
| 359 | } |
| 360 | v.buildDrawingCache(); |
| 361 | Bitmap cacheBitmap = v.getDrawingCache(); |
Daniel Sandler | 3f8175a | 2010-05-25 11:48:32 -0400 | [diff] [blame] | 362 | if (cacheBitmap == null) { |
| 363 | Log.e(TAG, "failed getViewBitmap(" + v + ")", new RuntimeException()); |
| 364 | return null; |
| 365 | } |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 366 | |
| 367 | Bitmap bitmap = Bitmap.createBitmap(cacheBitmap); |
| 368 | |
| 369 | // Restore the view |
| 370 | v.destroyDrawingCache(); |
Adam Cohen | 120980b | 2010-12-08 11:05:37 -0800 | [diff] [blame] | 371 | v.setAlpha(alpha); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 372 | v.setWillNotCacheDrawing(willNotCache); |
| 373 | v.setDrawingCacheBackgroundColor(color); |
| 374 | |
| 375 | return bitmap; |
| 376 | } |
| 377 | |
| 378 | /** |
| 379 | * Call this from a drag source view like this: |
| 380 | * |
| 381 | * <pre> |
| 382 | * @Override |
| 383 | * public boolean dispatchKeyEvent(KeyEvent event) { |
| 384 | * return mDragController.dispatchKeyEvent(this, event) |
| 385 | * || super.dispatchKeyEvent(event); |
| 386 | * </pre> |
| 387 | */ |
Romain Guy | ea3763c | 2010-01-11 18:02:04 -0800 | [diff] [blame] | 388 | @SuppressWarnings({"UnusedDeclaration"}) |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 389 | public boolean dispatchKeyEvent(KeyEvent event) { |
| 390 | return mDragging; |
| 391 | } |
| 392 | |
Joe Onorato | 24b6fd8 | 2009-11-12 13:47:09 -0800 | [diff] [blame] | 393 | /** |
| 394 | * Stop dragging without dropping. |
| 395 | */ |
| 396 | public void cancelDrag() { |
| 397 | endDrag(); |
| 398 | } |
| 399 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 400 | private void endDrag() { |
| 401 | if (mDragging) { |
| 402 | mDragging = false; |
| 403 | if (mOriginator != null) { |
| 404 | mOriginator.setVisibility(View.VISIBLE); |
| 405 | } |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 406 | for (DragListener listener : mListeners) { |
| 407 | listener.onDragEnd(); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 408 | } |
| 409 | if (mDragView != null) { |
| 410 | mDragView.remove(); |
| 411 | mDragView = null; |
| 412 | } |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 413 | } |
| 414 | } |
| 415 | |
| 416 | /** |
| 417 | * Call this from a drag source view. |
| 418 | */ |
| 419 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 420 | if (false) { |
Joe Onorato | a30ce8e | 2009-11-11 08:16:49 -0800 | [diff] [blame] | 421 | Log.d(Launcher.TAG, "DragController.onInterceptTouchEvent " + ev + " mDragging=" |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 422 | + mDragging); |
| 423 | } |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 424 | final int action = ev.getAction(); |
| 425 | |
Joe Onorato | 87467d3 | 2009-11-08 14:36:43 -0500 | [diff] [blame] | 426 | if (action == MotionEvent.ACTION_DOWN) { |
| 427 | recordScreenSize(); |
| 428 | } |
| 429 | |
Joe Onorato | e048e8a | 2009-09-25 10:39:17 -0700 | [diff] [blame] | 430 | final int screenX = clamp((int)ev.getRawX(), 0, mDisplayMetrics.widthPixels); |
| 431 | final int screenY = clamp((int)ev.getRawY(), 0, mDisplayMetrics.heightPixels); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 432 | |
| 433 | switch (action) { |
| 434 | case MotionEvent.ACTION_MOVE: |
| 435 | break; |
| 436 | |
| 437 | case MotionEvent.ACTION_DOWN: |
| 438 | // Remember location of down touch |
| 439 | mMotionDownX = screenX; |
| 440 | mMotionDownY = screenY; |
| 441 | mLastDropTarget = null; |
| 442 | break; |
| 443 | |
| 444 | case MotionEvent.ACTION_CANCEL: |
| 445 | case MotionEvent.ACTION_UP: |
| 446 | if (mDragging) { |
| 447 | drop(screenX, screenY); |
| 448 | } |
| 449 | endDrag(); |
| 450 | break; |
| 451 | } |
| 452 | |
| 453 | return mDragging; |
| 454 | } |
| 455 | |
| 456 | /** |
Romain Guy | ea3763c | 2010-01-11 18:02:04 -0800 | [diff] [blame] | 457 | * Sets the view that should handle move events. |
| 458 | */ |
| 459 | void setMoveTarget(View view) { |
| 460 | mMoveTarget = view; |
| 461 | } |
| 462 | |
| 463 | public boolean dispatchUnhandledMove(View focused, int direction) { |
| 464 | return mMoveTarget != null && mMoveTarget.dispatchUnhandledMove(focused, direction); |
| 465 | } |
| 466 | |
Patrick Dubroy | de7658b | 2010-09-27 11:15:43 -0700 | [diff] [blame] | 467 | private void handleMoveEvent(int x, int y) { |
| 468 | mDragView.move(x, y); |
| 469 | |
| 470 | // Drop on someone? |
| 471 | final int[] coordinates = mCoordinatesTemp; |
| 472 | DropTarget dropTarget = findDropTarget(x, y, coordinates); |
| 473 | if (dropTarget != null) { |
| 474 | DropTarget delegate = dropTarget.getDropTargetDelegate( |
| 475 | mDragSource, coordinates[0], coordinates[1], |
| 476 | (int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo); |
| 477 | if (delegate != null) { |
| 478 | dropTarget = delegate; |
| 479 | } |
| 480 | |
| 481 | if (mLastDropTarget != dropTarget) { |
| 482 | if (mLastDropTarget != null) { |
| 483 | mLastDropTarget.onDragExit(mDragSource, coordinates[0], coordinates[1], |
| 484 | (int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo); |
| 485 | } |
| 486 | dropTarget.onDragEnter(mDragSource, coordinates[0], coordinates[1], |
| 487 | (int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo); |
| 488 | } |
| 489 | dropTarget.onDragOver(mDragSource, coordinates[0], coordinates[1], |
| 490 | (int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo); |
| 491 | } else { |
| 492 | if (mLastDropTarget != null) { |
| 493 | mLastDropTarget.onDragExit(mDragSource, coordinates[0], coordinates[1], |
| 494 | (int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo); |
| 495 | } |
| 496 | } |
| 497 | mLastDropTarget = dropTarget; |
| 498 | |
| 499 | // Scroll, maybe, but not if we're in the delete region. |
| 500 | boolean inDeleteRegion = false; |
| 501 | if (mDeleteRegion != null) { |
| 502 | inDeleteRegion = mDeleteRegion.contains(x, y); |
| 503 | } |
Patrick Dubroy | a16fd5a | 2010-10-07 16:47:28 -0700 | [diff] [blame] | 504 | |
| 505 | // After a scroll, the touch point will still be in the scroll region. |
| 506 | // Rather than scrolling immediately, require a bit of twiddling to scroll again |
| 507 | final int slop = ViewConfiguration.get(mContext).getScaledWindowTouchSlop(); |
| 508 | mDistanceSinceScroll += |
| 509 | Math.sqrt(Math.pow(mLastTouch[0] - x, 2) + Math.pow(mLastTouch[1] - y, 2)); |
| 510 | mLastTouch[0] = x; |
| 511 | mLastTouch[1] = y; |
| 512 | |
Joe Onorato | 658db74 | 2010-09-29 11:40:39 -0700 | [diff] [blame] | 513 | if (!inDeleteRegion && x < mScrollZone) { |
Patrick Dubroy | a16fd5a | 2010-10-07 16:47:28 -0700 | [diff] [blame] | 514 | if (mScrollState == SCROLL_OUTSIDE_ZONE && mDistanceSinceScroll > slop) { |
Patrick Dubroy | de7658b | 2010-09-27 11:15:43 -0700 | [diff] [blame] | 515 | mScrollState = SCROLL_WAITING_IN_ZONE; |
| 516 | mScrollRunnable.setDirection(SCROLL_LEFT); |
| 517 | mHandler.postDelayed(mScrollRunnable, SCROLL_DELAY); |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 518 | mDragScroller.onEnterScrollArea(SCROLL_LEFT); |
Patrick Dubroy | de7658b | 2010-09-27 11:15:43 -0700 | [diff] [blame] | 519 | } |
Joe Onorato | 658db74 | 2010-09-29 11:40:39 -0700 | [diff] [blame] | 520 | } else if (!inDeleteRegion && x > mScrollView.getWidth() - mScrollZone) { |
Patrick Dubroy | a16fd5a | 2010-10-07 16:47:28 -0700 | [diff] [blame] | 521 | if (mScrollState == SCROLL_OUTSIDE_ZONE && mDistanceSinceScroll > slop) { |
Patrick Dubroy | de7658b | 2010-09-27 11:15:43 -0700 | [diff] [blame] | 522 | mScrollState = SCROLL_WAITING_IN_ZONE; |
| 523 | mScrollRunnable.setDirection(SCROLL_RIGHT); |
| 524 | mHandler.postDelayed(mScrollRunnable, SCROLL_DELAY); |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 525 | mDragScroller.onEnterScrollArea(SCROLL_RIGHT); |
Patrick Dubroy | de7658b | 2010-09-27 11:15:43 -0700 | [diff] [blame] | 526 | } |
| 527 | } else { |
| 528 | if (mScrollState == SCROLL_WAITING_IN_ZONE) { |
| 529 | mScrollState = SCROLL_OUTSIDE_ZONE; |
| 530 | mScrollRunnable.setDirection(SCROLL_RIGHT); |
| 531 | mHandler.removeCallbacks(mScrollRunnable); |
Patrick Dubroy | 1262e36 | 2010-10-06 15:49:50 -0700 | [diff] [blame] | 532 | mDragScroller.onExitScrollArea(); |
Patrick Dubroy | de7658b | 2010-09-27 11:15:43 -0700 | [diff] [blame] | 533 | } |
| 534 | } |
| 535 | } |
| 536 | |
Romain Guy | ea3763c | 2010-01-11 18:02:04 -0800 | [diff] [blame] | 537 | /** |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 538 | * Call this from a drag source view. |
| 539 | */ |
| 540 | public boolean onTouchEvent(MotionEvent ev) { |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 541 | if (!mDragging) { |
| 542 | return false; |
| 543 | } |
| 544 | |
| 545 | final int action = ev.getAction(); |
Joe Onorato | e048e8a | 2009-09-25 10:39:17 -0700 | [diff] [blame] | 546 | final int screenX = clamp((int)ev.getRawX(), 0, mDisplayMetrics.widthPixels); |
| 547 | final int screenY = clamp((int)ev.getRawY(), 0, mDisplayMetrics.heightPixels); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 548 | |
| 549 | switch (action) { |
| 550 | case MotionEvent.ACTION_DOWN: |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 551 | // Remember where the motion event started |
Joe Onorato | e048e8a | 2009-09-25 10:39:17 -0700 | [diff] [blame] | 552 | mMotionDownX = screenX; |
| 553 | mMotionDownY = screenY; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 554 | |
Joe Onorato | 658db74 | 2010-09-29 11:40:39 -0700 | [diff] [blame] | 555 | if ((screenX < mScrollZone) || (screenX > mScrollView.getWidth() - mScrollZone)) { |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 556 | mScrollState = SCROLL_WAITING_IN_ZONE; |
| 557 | mHandler.postDelayed(mScrollRunnable, SCROLL_DELAY); |
| 558 | } else { |
| 559 | mScrollState = SCROLL_OUTSIDE_ZONE; |
| 560 | } |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 561 | break; |
| 562 | case MotionEvent.ACTION_MOVE: |
Patrick Dubroy | de7658b | 2010-09-27 11:15:43 -0700 | [diff] [blame] | 563 | handleMoveEvent(screenX, screenY); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 564 | break; |
| 565 | case MotionEvent.ACTION_UP: |
| 566 | mHandler.removeCallbacks(mScrollRunnable); |
| 567 | if (mDragging) { |
Joe Onorato | e048e8a | 2009-09-25 10:39:17 -0700 | [diff] [blame] | 568 | drop(screenX, screenY); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 569 | } |
| 570 | endDrag(); |
| 571 | |
| 572 | break; |
| 573 | case MotionEvent.ACTION_CANCEL: |
Joe Onorato | 24b6fd8 | 2009-11-12 13:47:09 -0800 | [diff] [blame] | 574 | cancelDrag(); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | return true; |
| 578 | } |
| 579 | |
| 580 | private boolean drop(float x, float y) { |
| 581 | final int[] coordinates = mCoordinatesTemp; |
| 582 | DropTarget dropTarget = findDropTarget((int) x, (int) y, coordinates); |
| 583 | |
| 584 | if (dropTarget != null) { |
| 585 | dropTarget.onDragExit(mDragSource, coordinates[0], coordinates[1], |
| 586 | (int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo); |
| 587 | if (dropTarget.acceptDrop(mDragSource, coordinates[0], coordinates[1], |
| 588 | (int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo)) { |
| 589 | dropTarget.onDrop(mDragSource, coordinates[0], coordinates[1], |
| 590 | (int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo); |
| 591 | mDragSource.onDropCompleted((View) dropTarget, true); |
| 592 | return true; |
| 593 | } else { |
| 594 | mDragSource.onDropCompleted((View) dropTarget, false); |
| 595 | return true; |
| 596 | } |
Winson Chung | a34abf8 | 2010-11-12 12:10:35 -0800 | [diff] [blame] | 597 | } else { |
| 598 | mDragSource.onDropCompleted(null, false); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 599 | } |
| 600 | return false; |
| 601 | } |
| 602 | |
| 603 | private DropTarget findDropTarget(int x, int y, int[] dropCoordinates) { |
| 604 | final Rect r = mRectTemp; |
| 605 | |
| 606 | final ArrayList<DropTarget> dropTargets = mDropTargets; |
| 607 | final int count = dropTargets.size(); |
| 608 | for (int i=count-1; i>=0; i--) { |
Patrick Dubroy | 440c360 | 2010-07-13 17:50:32 -0700 | [diff] [blame] | 609 | DropTarget target = dropTargets.get(i); |
Michael Jurka | 0280c3b | 2010-09-17 15:00:07 -0700 | [diff] [blame] | 610 | if (!target.isDropEnabled()) |
| 611 | continue; |
| 612 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 613 | target.getHitRect(r); |
Patrick Dubroy | 440c360 | 2010-07-13 17:50:32 -0700 | [diff] [blame] | 614 | |
| 615 | // Convert the hit rect to screen coordinates |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 616 | target.getLocationOnScreen(dropCoordinates); |
| 617 | r.offset(dropCoordinates[0] - target.getLeft(), dropCoordinates[1] - target.getTop()); |
Patrick Dubroy | 440c360 | 2010-07-13 17:50:32 -0700 | [diff] [blame] | 618 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 619 | if (r.contains(x, y)) { |
Patrick Dubroy | 440c360 | 2010-07-13 17:50:32 -0700 | [diff] [blame] | 620 | DropTarget delegate = target.getDropTargetDelegate(mDragSource, |
| 621 | x, y, (int)mTouchOffsetX, (int)mTouchOffsetY, mDragView, mDragInfo); |
| 622 | if (delegate != null) { |
| 623 | target = delegate; |
| 624 | target.getLocationOnScreen(dropCoordinates); |
| 625 | } |
| 626 | |
| 627 | // Make dropCoordinates relative to the DropTarget |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 628 | dropCoordinates[0] = x - dropCoordinates[0]; |
| 629 | dropCoordinates[1] = y - dropCoordinates[1]; |
Patrick Dubroy | 440c360 | 2010-07-13 17:50:32 -0700 | [diff] [blame] | 630 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 631 | return target; |
| 632 | } |
| 633 | } |
| 634 | return null; |
| 635 | } |
| 636 | |
Joe Onorato | e048e8a | 2009-09-25 10:39:17 -0700 | [diff] [blame] | 637 | /** |
| 638 | * Get the screen size so we can clamp events to the screen size so even if |
| 639 | * you drag off the edge of the screen, we find something. |
| 640 | */ |
| 641 | private void recordScreenSize() { |
| 642 | ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE)) |
| 643 | .getDefaultDisplay().getMetrics(mDisplayMetrics); |
| 644 | } |
| 645 | |
| 646 | /** |
| 647 | * Clamp val to be >= min and < max. |
| 648 | */ |
| 649 | private static int clamp(int val, int min, int max) { |
| 650 | if (val < min) { |
| 651 | return min; |
| 652 | } else if (val >= max) { |
| 653 | return max - 1; |
| 654 | } else { |
| 655 | return val; |
| 656 | } |
| 657 | } |
| 658 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 659 | public void setDragScoller(DragScroller scroller) { |
| 660 | mDragScroller = scroller; |
| 661 | } |
| 662 | |
| 663 | public void setWindowToken(IBinder token) { |
| 664 | mWindowToken = token; |
| 665 | } |
| 666 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 667 | /** |
| 668 | * Sets the drag listner which will be notified when a drag starts or ends. |
| 669 | */ |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 670 | public void addDragListener(DragListener l) { |
| 671 | mListeners.add(l); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 672 | } |
| 673 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 674 | /** |
| 675 | * Remove a previously installed drag listener. |
| 676 | */ |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 677 | public void removeDragListener(DragListener l) { |
Patrick Dubroy | 4ed6278 | 2010-08-17 15:11:18 -0700 | [diff] [blame] | 678 | mListeners.remove(l); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | /** |
| 682 | * Add a DropTarget to the list of potential places to receive drop events. |
| 683 | */ |
| 684 | public void addDropTarget(DropTarget target) { |
| 685 | mDropTargets.add(target); |
| 686 | } |
| 687 | |
| 688 | /** |
| 689 | * Don't send drop events to <em>target</em> any more. |
| 690 | */ |
| 691 | public void removeDropTarget(DropTarget target) { |
| 692 | mDropTargets.remove(target); |
| 693 | } |
| 694 | |
| 695 | /** |
| 696 | * Set which view scrolls for touch events near the edge of the screen. |
| 697 | */ |
| 698 | public void setScrollView(View v) { |
| 699 | mScrollView = v; |
| 700 | } |
| 701 | |
| 702 | /** |
| 703 | * Specifies the delete region. We won't scroll on touch events over the delete region. |
| 704 | * |
| 705 | * @param region The rectangle in screen coordinates of the delete region. |
| 706 | */ |
| 707 | void setDeleteRegion(RectF region) { |
| 708 | mDeleteRegion = region; |
| 709 | } |
| 710 | |
| 711 | private class ScrollRunnable implements Runnable { |
| 712 | private int mDirection; |
| 713 | |
| 714 | ScrollRunnable() { |
| 715 | } |
| 716 | |
| 717 | public void run() { |
| 718 | if (mDragScroller != null) { |
| 719 | if (mDirection == SCROLL_LEFT) { |
| 720 | mDragScroller.scrollLeft(); |
| 721 | } else { |
| 722 | mDragScroller.scrollRight(); |
| 723 | } |
| 724 | mScrollState = SCROLL_OUTSIDE_ZONE; |
Patrick Dubroy | a16fd5a | 2010-10-07 16:47:28 -0700 | [diff] [blame] | 725 | mDistanceSinceScroll = 0; |
| 726 | mDragScroller.onExitScrollArea(); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 727 | } |
| 728 | } |
| 729 | |
| 730 | void setDirection(int direction) { |
| 731 | mDirection = direction; |
| 732 | } |
| 733 | } |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 734 | } |