Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [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 | |
| 17 | |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 18 | package com.android.launcher3; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 19 | |
Patrick Dubroy | a669d79 | 2010-11-23 14:40:33 -0800 | [diff] [blame] | 20 | import android.animation.ValueAnimator; |
| 21 | import android.animation.ValueAnimator.AnimatorUpdateListener; |
Patrick Dubroy | de7658b | 2010-09-27 11:15:43 -0700 | [diff] [blame] | 22 | import android.content.res.Resources; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 23 | import android.graphics.Bitmap; |
| 24 | import android.graphics.Canvas; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 25 | import android.graphics.Paint; |
Winson Chung | b8c69f3 | 2011-10-19 21:36:08 -0700 | [diff] [blame] | 26 | import android.graphics.Point; |
Winson Chung | 61967cb | 2012-02-28 18:11:33 -0800 | [diff] [blame] | 27 | import android.graphics.PorterDuff; |
| 28 | import android.graphics.PorterDuffColorFilter; |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 29 | import android.graphics.Rect; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 30 | import android.view.View; |
Patrick Dubroy | a669d79 | 2010-11-23 14:40:33 -0800 | [diff] [blame] | 31 | import android.view.animation.DecelerateInterpolator; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 32 | |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 33 | import com.android.launcher3.R; |
Adam Cohen | 120980b | 2010-12-08 11:05:37 -0800 | [diff] [blame] | 34 | |
Patrick Dubroy | a669d79 | 2010-11-23 14:40:33 -0800 | [diff] [blame] | 35 | public class DragView extends View { |
Winson Chung | 867ca62 | 2012-02-21 15:48:35 -0800 | [diff] [blame] | 36 | private static float sDragAlpha = 1f; |
Winson Chung | 7bd1bbb | 2012-02-13 18:29:29 -0800 | [diff] [blame] | 37 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 38 | private Bitmap mBitmap; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 39 | private Bitmap mCrossFadeBitmap; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 40 | private Paint mPaint; |
| 41 | private int mRegistrationX; |
| 42 | private int mRegistrationY; |
| 43 | |
Winson Chung | b8c69f3 | 2011-10-19 21:36:08 -0700 | [diff] [blame] | 44 | private Point mDragVisualizeOffset = null; |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 45 | private Rect mDragRegion = null; |
Adam Cohen | 8dfcba4 | 2011-07-07 16:38:18 -0700 | [diff] [blame] | 46 | private DragLayer mDragLayer = null; |
Adam Cohen | fc53cd2 | 2011-07-20 15:45:11 -0700 | [diff] [blame] | 47 | private boolean mHasDrawn = false; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 48 | private float mCrossFadeProgress = 0f; |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 49 | |
Patrick Dubroy | a669d79 | 2010-11-23 14:40:33 -0800 | [diff] [blame] | 50 | ValueAnimator mAnim; |
Patrick Dubroy | a669d79 | 2010-11-23 14:40:33 -0800 | [diff] [blame] | 51 | private float mOffsetX = 0.0f; |
| 52 | private float mOffsetY = 0.0f; |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 53 | private float mInitialScale = 1f; |
Winson Chung | eeb5bbc | 2013-11-13 15:47:05 -0800 | [diff] [blame^] | 54 | // The intrinsic icon scale factor is the scale factor for a drag icon over the workspace |
| 55 | // size. This is ignored for non-icons. |
| 56 | private float mIntrinsicIconScale = 1f; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 57 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 58 | /** |
| 59 | * Construct the drag view. |
| 60 | * <p> |
| 61 | * The registration point is the point inside our view that the touch events should |
| 62 | * be centered upon. |
| 63 | * |
Adam Cohen | 8dfcba4 | 2011-07-07 16:38:18 -0700 | [diff] [blame] | 64 | * @param launcher The Launcher instance |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 65 | * @param bitmap The view that we're dragging around. We scale it up when we draw it. |
| 66 | * @param registrationX The x coordinate of the registration point. |
| 67 | * @param registrationY The y coordinate of the registration point. |
| 68 | */ |
Adam Cohen | 8dfcba4 | 2011-07-07 16:38:18 -0700 | [diff] [blame] | 69 | public DragView(Launcher launcher, Bitmap bitmap, int registrationX, int registrationY, |
Winson Chung | 72d5984 | 2012-02-22 13:51:36 -0800 | [diff] [blame] | 70 | int left, int top, int width, int height, final float initialScale) { |
Adam Cohen | 8dfcba4 | 2011-07-07 16:38:18 -0700 | [diff] [blame] | 71 | super(launcher); |
| 72 | mDragLayer = launcher.getDragLayer(); |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 73 | mInitialScale = initialScale; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 74 | |
Patrick Dubroy | de7658b | 2010-09-27 11:15:43 -0700 | [diff] [blame] | 75 | final Resources res = getResources(); |
Winson Chung | 7bd1bbb | 2012-02-13 18:29:29 -0800 | [diff] [blame] | 76 | final float offsetX = res.getDimensionPixelSize(R.dimen.dragViewOffsetX); |
| 77 | final float offsetY = res.getDimensionPixelSize(R.dimen.dragViewOffsetY); |
| 78 | final float scaleDps = res.getDimensionPixelSize(R.dimen.dragViewScale); |
| 79 | final float scale = (width + scaleDps) / width; |
Patrick Dubroy | a669d79 | 2010-11-23 14:40:33 -0800 | [diff] [blame] | 80 | |
Adam Cohen | 307fe23 | 2012-08-16 17:55:58 -0700 | [diff] [blame] | 81 | // Set the initial scale to avoid any jumps |
| 82 | setScaleX(initialScale); |
| 83 | setScaleY(initialScale); |
| 84 | |
Patrick Dubroy | a669d79 | 2010-11-23 14:40:33 -0800 | [diff] [blame] | 85 | // Animate the view into the correct position |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 86 | mAnim = LauncherAnimUtils.ofFloat(this, 0f, 1f); |
Winson Chung | 7bd1bbb | 2012-02-13 18:29:29 -0800 | [diff] [blame] | 87 | mAnim.setDuration(150); |
Patrick Dubroy | a669d79 | 2010-11-23 14:40:33 -0800 | [diff] [blame] | 88 | mAnim.addUpdateListener(new AnimatorUpdateListener() { |
| 89 | @Override |
| 90 | public void onAnimationUpdate(ValueAnimator animation) { |
| 91 | final float value = (Float) animation.getAnimatedValue(); |
| 92 | |
| 93 | final int deltaX = (int) ((value * offsetX) - mOffsetX); |
| 94 | final int deltaY = (int) ((value * offsetY) - mOffsetY); |
| 95 | |
| 96 | mOffsetX += deltaX; |
| 97 | mOffsetY += deltaY; |
Winson Chung | 72d5984 | 2012-02-22 13:51:36 -0800 | [diff] [blame] | 98 | setScaleX(initialScale + (value * (scale - initialScale))); |
| 99 | setScaleY(initialScale + (value * (scale - initialScale))); |
Winson Chung | 867ca62 | 2012-02-21 15:48:35 -0800 | [diff] [blame] | 100 | if (sDragAlpha != 1f) { |
| 101 | setAlpha(sDragAlpha * value + (1f - value)); |
| 102 | } |
Patrick Dubroy | a669d79 | 2010-11-23 14:40:33 -0800 | [diff] [blame] | 103 | |
| 104 | if (getParent() == null) { |
| 105 | animation.cancel(); |
| 106 | } else { |
Winson Chung | 7bd1bbb | 2012-02-13 18:29:29 -0800 | [diff] [blame] | 107 | setTranslationX(getTranslationX() + deltaX); |
| 108 | setTranslationY(getTranslationY() + deltaY); |
Patrick Dubroy | a669d79 | 2010-11-23 14:40:33 -0800 | [diff] [blame] | 109 | } |
| 110 | } |
| 111 | }); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 112 | |
Winson Chung | 7bd1bbb | 2012-02-13 18:29:29 -0800 | [diff] [blame] | 113 | mBitmap = Bitmap.createBitmap(bitmap, left, top, width, height); |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 114 | setDragRegion(new Rect(0, 0, width, height)); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 115 | |
| 116 | // The point in our scaled bitmap that the touch events are located |
Patrick Dubroy | a669d79 | 2010-11-23 14:40:33 -0800 | [diff] [blame] | 117 | mRegistrationX = registrationX; |
| 118 | mRegistrationY = registrationY; |
Patrick Dubroy | 62bbb3c | 2011-01-17 15:29:27 -0800 | [diff] [blame] | 119 | |
| 120 | // Force a measure, because Workspace uses getMeasuredHeight() before the layout pass |
| 121 | int ms = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); |
| 122 | measure(ms, ms); |
Michael Jurka | 6cfafb9 | 2012-02-23 18:25:43 -0800 | [diff] [blame] | 123 | mPaint = new Paint(Paint.FILTER_BITMAP_FLAG); |
Patrick Dubroy | 62bbb3c | 2011-01-17 15:29:27 -0800 | [diff] [blame] | 124 | } |
| 125 | |
Winson Chung | eeb5bbc | 2013-11-13 15:47:05 -0800 | [diff] [blame^] | 126 | /** Sets the scale of the view over the normal workspace icon size. */ |
| 127 | public void setIntrinsicIconScaleFactor(float scale) { |
| 128 | mIntrinsicIconScale = scale; |
| 129 | } |
| 130 | |
| 131 | public float getIntrinsicIconScaleFactor() { |
| 132 | return mIntrinsicIconScale; |
| 133 | } |
| 134 | |
Patrick Dubroy | 62bbb3c | 2011-01-17 15:29:27 -0800 | [diff] [blame] | 135 | public float getOffsetY() { |
| 136 | return mOffsetY; |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 137 | } |
| 138 | |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 139 | public int getDragRegionLeft() { |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 140 | return mDragRegion.left; |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | public int getDragRegionTop() { |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 144 | return mDragRegion.top; |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | public int getDragRegionWidth() { |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 148 | return mDragRegion.width(); |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | public int getDragRegionHeight() { |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 152 | return mDragRegion.height(); |
| 153 | } |
| 154 | |
Winson Chung | b8c69f3 | 2011-10-19 21:36:08 -0700 | [diff] [blame] | 155 | public void setDragVisualizeOffset(Point p) { |
| 156 | mDragVisualizeOffset = p; |
| 157 | } |
| 158 | |
| 159 | public Point getDragVisualizeOffset() { |
| 160 | return mDragVisualizeOffset; |
| 161 | } |
| 162 | |
Adam Cohen | e3e27a8 | 2011-04-15 12:07:39 -0700 | [diff] [blame] | 163 | public void setDragRegion(Rect r) { |
| 164 | mDragRegion = r; |
| 165 | } |
| 166 | |
| 167 | public Rect getDragRegion() { |
| 168 | return mDragRegion; |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 171 | public float getInitialScale() { |
| 172 | return mInitialScale; |
| 173 | } |
| 174 | |
| 175 | public void updateInitialScaleToCurrentScale() { |
| 176 | mInitialScale = getScaleX(); |
| 177 | } |
| 178 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 179 | @Override |
| 180 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
Joe Onorato | eebd924 | 2009-11-04 13:48:32 -0500 | [diff] [blame] | 181 | setMeasuredDimension(mBitmap.getWidth(), mBitmap.getHeight()); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | @Override |
| 185 | protected void onDraw(Canvas canvas) { |
Michael Jurka | 3a9fced | 2012-04-13 14:44:29 -0700 | [diff] [blame] | 186 | @SuppressWarnings("all") // suppress dead code warning |
| 187 | final boolean debug = false; |
| 188 | if (debug) { |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 189 | Paint p = new Paint(); |
| 190 | p.setStyle(Paint.Style.FILL); |
Winson Chung | eecf02d | 2012-03-02 17:14:58 -0800 | [diff] [blame] | 191 | p.setColor(0x66ffffff); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 192 | canvas.drawRect(0, 0, getWidth(), getHeight(), p); |
| 193 | } |
Patrick Dubroy | a669d79 | 2010-11-23 14:40:33 -0800 | [diff] [blame] | 194 | |
Adam Cohen | fc53cd2 | 2011-07-20 15:45:11 -0700 | [diff] [blame] | 195 | mHasDrawn = true; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 196 | boolean crossFade = mCrossFadeProgress > 0 && mCrossFadeBitmap != null; |
| 197 | if (crossFade) { |
| 198 | int alpha = crossFade ? (int) (255 * (1 - mCrossFadeProgress)) : 255; |
| 199 | mPaint.setAlpha(alpha); |
| 200 | } |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 201 | canvas.drawBitmap(mBitmap, 0.0f, 0.0f, mPaint); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 202 | if (crossFade) { |
| 203 | mPaint.setAlpha((int) (255 * mCrossFadeProgress)); |
| 204 | canvas.save(); |
| 205 | float sX = (mBitmap.getWidth() * 1.0f) / mCrossFadeBitmap.getWidth(); |
| 206 | float sY = (mBitmap.getHeight() * 1.0f) / mCrossFadeBitmap.getHeight(); |
| 207 | canvas.scale(sX, sY); |
| 208 | canvas.drawBitmap(mCrossFadeBitmap, 0.0f, 0.0f, mPaint); |
| 209 | canvas.restore(); |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | public void setCrossFadeBitmap(Bitmap crossFadeBitmap) { |
| 214 | mCrossFadeBitmap = crossFadeBitmap; |
| 215 | } |
| 216 | |
| 217 | public void crossFade(int duration) { |
Michael Jurka | f1ad608 | 2013-03-13 12:55:46 +0100 | [diff] [blame] | 218 | ValueAnimator va = LauncherAnimUtils.ofFloat(this, 0f, 1f); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 219 | va.setDuration(duration); |
| 220 | va.setInterpolator(new DecelerateInterpolator(1.5f)); |
| 221 | va.addUpdateListener(new AnimatorUpdateListener() { |
| 222 | @Override |
| 223 | public void onAnimationUpdate(ValueAnimator animation) { |
| 224 | mCrossFadeProgress = animation.getAnimatedFraction(); |
| 225 | } |
| 226 | }); |
| 227 | va.start(); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 228 | } |
| 229 | |
Winson Chung | 61967cb | 2012-02-28 18:11:33 -0800 | [diff] [blame] | 230 | public void setColor(int color) { |
Michael Jurka | 6cfafb9 | 2012-02-23 18:25:43 -0800 | [diff] [blame] | 231 | if (mPaint == null) { |
| 232 | mPaint = new Paint(Paint.FILTER_BITMAP_FLAG); |
| 233 | } |
Winson Chung | 61967cb | 2012-02-28 18:11:33 -0800 | [diff] [blame] | 234 | if (color != 0) { |
| 235 | mPaint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP)); |
| 236 | } else { |
| 237 | mPaint.setColorFilter(null); |
| 238 | } |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 239 | invalidate(); |
| 240 | } |
| 241 | |
Adam Cohen | fc53cd2 | 2011-07-20 15:45:11 -0700 | [diff] [blame] | 242 | public boolean hasDrawn() { |
| 243 | return mHasDrawn; |
| 244 | } |
| 245 | |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -0700 | [diff] [blame] | 246 | @Override |
| 247 | public void setAlpha(float alpha) { |
| 248 | super.setAlpha(alpha); |
Adam Cohen | 3e8f811 | 2011-07-02 18:03:00 -0700 | [diff] [blame] | 249 | mPaint.setAlpha((int) (255 * alpha)); |
| 250 | invalidate(); |
| 251 | } |
| 252 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 253 | /** |
| 254 | * Create a window containing this view and show it. |
| 255 | * |
| 256 | * @param windowToken obtained from v.getWindowToken() from one of your views |
Adam Cohen | 8dfcba4 | 2011-07-07 16:38:18 -0700 | [diff] [blame] | 257 | * @param touchX the x coordinate the user touched in DragLayer coordinates |
| 258 | * @param touchY the y coordinate the user touched in DragLayer coordinates |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 259 | */ |
Adam Cohen | 8dfcba4 | 2011-07-07 16:38:18 -0700 | [diff] [blame] | 260 | public void show(int touchX, int touchY) { |
| 261 | mDragLayer.addView(this); |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 262 | |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 263 | // Start the pick-up animation |
Adam Cohen | 8dfcba4 | 2011-07-07 16:38:18 -0700 | [diff] [blame] | 264 | DragLayer.LayoutParams lp = new DragLayer.LayoutParams(0, 0); |
| 265 | lp.width = mBitmap.getWidth(); |
| 266 | lp.height = mBitmap.getHeight(); |
Adam Cohen | 8dfcba4 | 2011-07-07 16:38:18 -0700 | [diff] [blame] | 267 | lp.customPosition = true; |
| 268 | setLayoutParams(lp); |
Winson Chung | 7bd1bbb | 2012-02-13 18:29:29 -0800 | [diff] [blame] | 269 | setTranslationX(touchX - mRegistrationX); |
| 270 | setTranslationY(touchY - mRegistrationY); |
Michael Jurka | ca99383 | 2012-06-29 15:17:04 -0700 | [diff] [blame] | 271 | // Post the animation to skip other expensive work happening on the first frame |
| 272 | post(new Runnable() { |
| 273 | public void run() { |
| 274 | mAnim.start(); |
| 275 | } |
| 276 | }); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 277 | } |
Adam Cohen | 716b51e | 2011-06-30 12:09:54 -0700 | [diff] [blame] | 278 | |
Winson Chung | 7bd1bbb | 2012-02-13 18:29:29 -0800 | [diff] [blame] | 279 | public void cancelAnimation() { |
| 280 | if (mAnim != null && mAnim.isRunning()) { |
| 281 | mAnim.cancel(); |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | public void resetLayoutParams() { |
| 286 | mOffsetX = mOffsetY = 0; |
| 287 | requestLayout(); |
| 288 | } |
| 289 | |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 290 | /** |
| 291 | * Move the window containing this view. |
| 292 | * |
Adam Cohen | 8dfcba4 | 2011-07-07 16:38:18 -0700 | [diff] [blame] | 293 | * @param touchX the x coordinate the user touched in DragLayer coordinates |
| 294 | * @param touchY the y coordinate the user touched in DragLayer coordinates |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 295 | */ |
| 296 | void move(int touchX, int touchY) { |
Winson Chung | 7bd1bbb | 2012-02-13 18:29:29 -0800 | [diff] [blame] | 297 | setTranslationX(touchX - mRegistrationX + (int) mOffsetX); |
| 298 | setTranslationY(touchY - mRegistrationY + (int) mOffsetY); |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | void remove() { |
Winson Chung | 7bd1bbb | 2012-02-13 18:29:29 -0800 | [diff] [blame] | 302 | if (getParent() != null) { |
| 303 | mDragLayer.removeView(DragView.this); |
| 304 | } |
Patrick Dubroy | 6f13342 | 2011-02-24 12:16:12 -0800 | [diff] [blame] | 305 | } |
Joe Onorato | 00acb12 | 2009-08-04 16:04:30 -0400 | [diff] [blame] | 306 | } |
| 307 | |