blob: 0fb87bacc97214bb1d640a8aed2e762a3914f45c [file] [log] [blame]
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Joe Onoratoa5902522009-07-30 13:37:37 -070017package com.android.launcher2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
Michael Jurka3c4c20f2010-10-28 15:36:06 -070019import com.android.launcher.R;
Winson Chungaafa03c2010-06-11 17:34:16 -070020
Joe Onorato4be866d2010-10-10 11:26:02 -070021import android.animation.Animator;
22import android.animation.AnimatorListenerAdapter;
Michael Jurka18014792010-10-14 09:01:34 -070023import android.animation.AnimatorSet;
24import android.animation.ObjectAnimator;
Chet Haase00397b12010-10-07 11:13:10 -070025import android.animation.TimeInterpolator;
Patrick Dubroyde7658b2010-09-27 11:15:43 -070026import android.animation.ValueAnimator;
27import android.animation.ValueAnimator.AnimatorUpdateListener;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080028import android.content.Context;
Joe Onorato79e56262009-09-21 15:23:04 -040029import android.content.res.Resources;
Winson Chungaafa03c2010-06-11 17:34:16 -070030import android.content.res.TypedArray;
Joe Onorato4be866d2010-10-10 11:26:02 -070031import android.graphics.Bitmap;
Winson Chungaafa03c2010-06-11 17:34:16 -070032import android.graphics.Canvas;
Joe Onorato4be866d2010-10-10 11:26:02 -070033import android.graphics.Paint;
Patrick Dubroyde7658b2010-09-27 11:15:43 -070034import android.graphics.Point;
35import android.graphics.PointF;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080036import android.graphics.Rect;
37import android.graphics.RectF;
Michael Jurka18014792010-10-14 09:01:34 -070038import android.graphics.Region;
Patrick Dubroy6569f2c2010-07-12 14:25:18 -070039import android.graphics.drawable.Drawable;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080040import android.util.AttributeSet;
Joe Onorato4be866d2010-10-10 11:26:02 -070041import android.util.Log;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080042import android.view.ContextMenu;
43import android.view.MotionEvent;
44import android.view.View;
45import android.view.ViewDebug;
46import android.view.ViewGroup;
Winson Chungaafa03c2010-06-11 17:34:16 -070047import android.view.animation.Animation;
Winson Chung150fbab2010-09-29 17:14:26 -070048import android.view.animation.DecelerateInterpolator;
Winson Chungaafa03c2010-06-11 17:34:16 -070049import android.view.animation.LayoutAnimationController;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080050
Michael Jurka3c4c20f2010-10-28 15:36:06 -070051import java.util.Arrays;
Patrick Dubroy8e58e912010-10-14 13:21:48 -070052
Michael Jurkabdb5c532011-02-01 15:05:06 -080053public class CellLayout extends ViewGroup {
Winson Chungaafa03c2010-06-11 17:34:16 -070054 static final String TAG = "CellLayout";
55
The Android Open Source Project31dd5032009-03-03 19:32:27 -080056 private int mCellWidth;
57 private int mCellHeight;
Winson Chungaafa03c2010-06-11 17:34:16 -070058
Winson Chungaafa03c2010-06-11 17:34:16 -070059 private int mLeftPadding;
60 private int mRightPadding;
61 private int mTopPadding;
62 private int mBottomPadding;
63
Adam Cohend22015c2010-07-26 22:02:18 -070064 private int mCountX;
65 private int mCountY;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080066
67 private int mWidthGap;
68 private int mHeightGap;
69
70 private final Rect mRect = new Rect();
71 private final CellInfo mCellInfo = new CellInfo();
Winson Chungaafa03c2010-06-11 17:34:16 -070072
Patrick Dubroyde7658b2010-09-27 11:15:43 -070073 // These are temporary variables to prevent having to allocate a new object just to
74 // return an (x, y) value from helper functions. Do NOT use them to maintain other state.
Patrick Dubroy6569f2c2010-07-12 14:25:18 -070075 private final int[] mTmpCellXY = new int[2];
Patrick Dubroyde7658b2010-09-27 11:15:43 -070076 private final int[] mTmpPoint = new int[2];
77 private final PointF mTmpPointF = new PointF();
Patrick Dubroy6569f2c2010-07-12 14:25:18 -070078
The Android Open Source Project31dd5032009-03-03 19:32:27 -080079 boolean[][] mOccupied;
80
Michael Jurkadee05892010-07-27 10:01:56 -070081 private OnTouchListener mInterceptTouchListener;
82
Michael Jurka5f1c5092010-09-03 14:15:02 -070083 private float mBackgroundAlpha;
Adam Cohen1b0aaac2010-10-28 11:11:18 -070084 private float mBackgroundAlphaMultiplier = 1.0f;
Adam Cohenf34bab52010-09-30 14:11:56 -070085
Michael Jurka33945b22010-12-21 18:19:38 -080086 private Drawable mNormalBackground;
Michael Jurka33945b22010-12-21 18:19:38 -080087 private Drawable mActiveBackground;
88 private Drawable mActiveGlowBackground;
89 private Drawable mNormalBackgroundMini;
90 private Drawable mNormalGlowBackgroundMini;
91 private Drawable mActiveBackgroundMini;
92 private Drawable mActiveGlowBackgroundMini;
Michael Jurka18014792010-10-14 09:01:34 -070093 private Rect mBackgroundRect;
Michael Jurka33945b22010-12-21 18:19:38 -080094 private Rect mGlowBackgroundRect;
95 private float mGlowBackgroundScale;
96 private float mGlowBackgroundAlpha;
Patrick Dubroy1262e362010-10-06 15:49:50 -070097
Michael Jurka33945b22010-12-21 18:19:38 -080098 private boolean mAcceptsDrops = false;
99 // If we're actively dragging something over this screen, mIsDragOverlapping is true
100 private boolean mIsDragOverlapping = false;
101 private boolean mIsDragOccuring = false;
102 private boolean mIsDefaultDropTarget = false;
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700103 private final Point mDragCenter = new Point();
Patrick Dubroy6569f2c2010-07-12 14:25:18 -0700104
Winson Chung150fbab2010-09-29 17:14:26 -0700105 // These arrays are used to implement the drag visualization on x-large screens.
Joe Onorato4be866d2010-10-10 11:26:02 -0700106 // They are used as circular arrays, indexed by mDragOutlineCurrent.
107 private Point[] mDragOutlines = new Point[8];
Chet Haase472b2812010-10-14 07:02:04 -0700108 private float[] mDragOutlineAlphas = new float[mDragOutlines.length];
Joe Onorato4be866d2010-10-10 11:26:02 -0700109 private InterruptibleInOutAnimator[] mDragOutlineAnims =
110 new InterruptibleInOutAnimator[mDragOutlines.length];
Winson Chung150fbab2010-09-29 17:14:26 -0700111
112 // Used as an index into the above 3 arrays; indicates which is the most current value.
Joe Onorato4be866d2010-10-10 11:26:02 -0700113 private int mDragOutlineCurrent = 0;
Patrick Dubroy8e58e912010-10-14 13:21:48 -0700114 private final Paint mDragOutlinePaint = new Paint();
Winson Chung150fbab2010-09-29 17:14:26 -0700115
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700116 private Drawable mCrosshairsDrawable = null;
Patrick Dubroy49250ad2010-10-08 15:33:52 -0700117 private InterruptibleInOutAnimator mCrosshairsAnimator = null;
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700118 private float mCrosshairsVisibility = 0.0f;
119
Patrick Dubroy6569f2c2010-07-12 14:25:18 -0700120 // When a drag operation is in progress, holds the nearest cell to the touch point
121 private final int[] mDragCell = new int[2];
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800122
Joe Onorato4be866d2010-10-10 11:26:02 -0700123 private boolean mDragging = false;
124
Patrick Dubroyce34a972010-10-19 10:34:32 -0700125 private TimeInterpolator mEaseOutInterpolator;
Michael Jurka8c920dd2011-01-20 14:16:56 -0800126 private CellLayoutChildren mChildren;
Patrick Dubroyce34a972010-10-19 10:34:32 -0700127
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800128 public CellLayout(Context context) {
129 this(context, null);
130 }
131
132 public CellLayout(Context context, AttributeSet attrs) {
133 this(context, attrs, 0);
134 }
135
136 public CellLayout(Context context, AttributeSet attrs, int defStyle) {
137 super(context, attrs, defStyle);
Patrick Dubroy6569f2c2010-07-12 14:25:18 -0700138
139 // A ViewGroup usually does not draw, but CellLayout needs to draw a rectangle to show
140 // the user where a dragged item will land when dropped.
141 setWillNotDraw(false);
Michael Jurkaa63c4522010-08-19 13:52:27 -0700142
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800143 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CellLayout, defStyle, 0);
144
145 mCellWidth = a.getDimensionPixelSize(R.styleable.CellLayout_cellWidth, 10);
146 mCellHeight = a.getDimensionPixelSize(R.styleable.CellLayout_cellHeight, 10);
Winson Chungece7f5b2010-10-22 14:54:12 -0700147 mWidthGap = a.getDimensionPixelSize(R.styleable.CellLayout_widthGap, -1);
148 mHeightGap = a.getDimensionPixelSize(R.styleable.CellLayout_heightGap, -1);
Winson Chungaafa03c2010-06-11 17:34:16 -0700149
Adam Cohend22015c2010-07-26 22:02:18 -0700150 mLeftPadding =
151 a.getDimensionPixelSize(R.styleable.CellLayout_xAxisStartPadding, 10);
152 mRightPadding =
153 a.getDimensionPixelSize(R.styleable.CellLayout_xAxisEndPadding, 10);
154 mTopPadding =
155 a.getDimensionPixelSize(R.styleable.CellLayout_yAxisStartPadding, 10);
156 mBottomPadding =
157 a.getDimensionPixelSize(R.styleable.CellLayout_yAxisEndPadding, 10);
Winson Chungaafa03c2010-06-11 17:34:16 -0700158
Adam Cohend22015c2010-07-26 22:02:18 -0700159 mCountX = LauncherModel.getCellCountX();
160 mCountY = LauncherModel.getCellCountY();
Michael Jurka0280c3b2010-09-17 15:00:07 -0700161 mOccupied = new boolean[mCountX][mCountY];
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800162
163 a.recycle();
164
165 setAlwaysDrawnWithCacheEnabled(false);
166
Patrick Dubroy046e7eb2010-10-06 12:14:43 -0700167 final Resources res = getResources();
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700168
Patrick Dubroy046e7eb2010-10-06 12:14:43 -0700169 if (LauncherApplication.isScreenXLarge()) {
Michael Jurka33945b22010-12-21 18:19:38 -0800170 mNormalBackground = res.getDrawable(R.drawable.homescreen_large_blue);
Michael Jurka33945b22010-12-21 18:19:38 -0800171 mActiveBackground = res.getDrawable(R.drawable.homescreen_large_green);
172 mActiveGlowBackground = res.getDrawable(R.drawable.homescreen_large_green_strong);
173
174 mNormalBackgroundMini = res.getDrawable(R.drawable.homescreen_small_blue);
175 mNormalGlowBackgroundMini = res.getDrawable(R.drawable.homescreen_small_blue_strong);
176 mActiveBackgroundMini = res.getDrawable(R.drawable.homescreen_small_green);
177 mActiveGlowBackgroundMini = res.getDrawable(R.drawable.homescreen_small_green_strong);
178
179 mNormalBackground.setFilterBitmap(true);
Michael Jurka33945b22010-12-21 18:19:38 -0800180 mActiveBackground.setFilterBitmap(true);
181 mActiveGlowBackground.setFilterBitmap(true);
182 mNormalBackgroundMini.setFilterBitmap(true);
183 mNormalGlowBackgroundMini.setFilterBitmap(true);
184 mActiveBackgroundMini.setFilterBitmap(true);
185 mActiveGlowBackgroundMini.setFilterBitmap(true);
Patrick Dubroy046e7eb2010-10-06 12:14:43 -0700186 }
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700187
Patrick Dubroy046e7eb2010-10-06 12:14:43 -0700188 // Initialize the data structures used for the drag visualization.
Winson Chung150fbab2010-09-29 17:14:26 -0700189
Patrick Dubroy046e7eb2010-10-06 12:14:43 -0700190 mCrosshairsDrawable = res.getDrawable(R.drawable.gardening_crosshairs);
Patrick Dubroyce34a972010-10-19 10:34:32 -0700191 mEaseOutInterpolator = new DecelerateInterpolator(2.5f); // Quint ease out
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700192
Patrick Dubroy046e7eb2010-10-06 12:14:43 -0700193 // Set up the animation for fading the crosshairs in and out
194 int animDuration = res.getInteger(R.integer.config_crosshairsFadeInTime);
Patrick Dubroy49250ad2010-10-08 15:33:52 -0700195 mCrosshairsAnimator = new InterruptibleInOutAnimator(animDuration, 0.0f, 1.0f);
Chet Haase472b2812010-10-14 07:02:04 -0700196 mCrosshairsAnimator.getAnimator().addUpdateListener(new AnimatorUpdateListener() {
Patrick Dubroy046e7eb2010-10-06 12:14:43 -0700197 public void onAnimationUpdate(ValueAnimator animation) {
198 mCrosshairsVisibility = ((Float) animation.getAnimatedValue()).floatValue();
Patrick Dubroy8e58e912010-10-14 13:21:48 -0700199 invalidate();
Patrick Dubroy046e7eb2010-10-06 12:14:43 -0700200 }
201 });
Patrick Dubroyce34a972010-10-19 10:34:32 -0700202 mCrosshairsAnimator.getAnimator().setInterpolator(mEaseOutInterpolator);
Patrick Dubroy046e7eb2010-10-06 12:14:43 -0700203
Joe Onorato4be866d2010-10-10 11:26:02 -0700204 for (int i = 0; i < mDragOutlines.length; i++) {
205 mDragOutlines[i] = new Point(-1, -1);
Patrick Dubroy046e7eb2010-10-06 12:14:43 -0700206 }
207
208 // When dragging things around the home screens, we show a green outline of
209 // where the item will land. The outlines gradually fade out, leaving a trail
210 // behind the drag path.
211 // Set up all the animations that are used to implement this fading.
212 final int duration = res.getInteger(R.integer.config_dragOutlineFadeTime);
Chet Haase472b2812010-10-14 07:02:04 -0700213 final float fromAlphaValue = 0;
214 final float toAlphaValue = (float)res.getInteger(R.integer.config_dragOutlineMaxAlpha);
Joe Onorato4be866d2010-10-10 11:26:02 -0700215
Patrick Dubroy8e58e912010-10-14 13:21:48 -0700216 Arrays.fill(mDragOutlineAlphas, fromAlphaValue);
Joe Onorato4be866d2010-10-10 11:26:02 -0700217
218 for (int i = 0; i < mDragOutlineAnims.length; i++) {
Patrick Dubroy046e7eb2010-10-06 12:14:43 -0700219 final InterruptibleInOutAnimator anim =
220 new InterruptibleInOutAnimator(duration, fromAlphaValue, toAlphaValue);
Patrick Dubroyce34a972010-10-19 10:34:32 -0700221 anim.getAnimator().setInterpolator(mEaseOutInterpolator);
Patrick Dubroy046e7eb2010-10-06 12:14:43 -0700222 final int thisIndex = i;
Chet Haase472b2812010-10-14 07:02:04 -0700223 anim.getAnimator().addUpdateListener(new AnimatorUpdateListener() {
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700224 public void onAnimationUpdate(ValueAnimator animation) {
Joe Onorato4be866d2010-10-10 11:26:02 -0700225 final Bitmap outline = (Bitmap)anim.getTag();
226
227 // If an animation is started and then stopped very quickly, we can still
228 // get spurious updates we've cleared the tag. Guard against this.
229 if (outline == null) {
Patrick Dubroyfe6bd872010-10-13 17:32:10 -0700230 if (false) {
231 Object val = animation.getAnimatedValue();
232 Log.d(TAG, "anim " + thisIndex + " update: " + val +
233 ", isStopped " + anim.isStopped());
234 }
Joe Onorato4be866d2010-10-10 11:26:02 -0700235 // Try to prevent it from continuing to run
236 animation.cancel();
237 } else {
Chet Haase472b2812010-10-14 07:02:04 -0700238 mDragOutlineAlphas[thisIndex] = (Float) animation.getAnimatedValue();
Joe Onorato4be866d2010-10-10 11:26:02 -0700239 final int left = mDragOutlines[thisIndex].x;
240 final int top = mDragOutlines[thisIndex].y;
241 CellLayout.this.invalidate(left, top,
242 left + outline.getWidth(), top + outline.getHeight());
243 }
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700244 }
245 });
Joe Onorato4be866d2010-10-10 11:26:02 -0700246 // The animation holds a reference to the drag outline bitmap as long is it's
247 // running. This way the bitmap can be GCed when the animations are complete.
Chet Haase472b2812010-10-14 07:02:04 -0700248 anim.getAnimator().addListener(new AnimatorListenerAdapter() {
Michael Jurka3c4c20f2010-10-28 15:36:06 -0700249 @Override
Joe Onorato4be866d2010-10-10 11:26:02 -0700250 public void onAnimationEnd(Animator animation) {
Chet Haase472b2812010-10-14 07:02:04 -0700251 if ((Float) ((ValueAnimator) animation).getAnimatedValue() == 0f) {
Joe Onorato4be866d2010-10-10 11:26:02 -0700252 anim.setTag(null);
253 }
254 }
255 });
256 mDragOutlineAnims[i] = anim;
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700257 }
Patrick Dubroyce34a972010-10-19 10:34:32 -0700258
Michael Jurka18014792010-10-14 09:01:34 -0700259 mBackgroundRect = new Rect();
Michael Jurka33945b22010-12-21 18:19:38 -0800260 mGlowBackgroundRect = new Rect();
Michael Jurka18014792010-10-14 09:01:34 -0700261 setHoverScale(1.0f);
262 setHoverAlpha(1.0f);
Michael Jurkabea15192010-11-17 12:33:46 -0800263
Michael Jurka8c920dd2011-01-20 14:16:56 -0800264 mChildren = new CellLayoutChildren(context);
265 mChildren.setCellDimensions(
266 mCellWidth, mCellHeight, mLeftPadding, mTopPadding, mWidthGap, mHeightGap);
267 addView(mChildren);
Michael Jurka18014792010-10-14 09:01:34 -0700268 }
269
Winson Chung6e314082011-01-27 16:46:51 -0800270 public CellLayoutChildren getChildrenLayout() {
271 if (getChildCount() > 0) {
272 return (CellLayoutChildren) getChildAt(0);
273 }
274 return null;
275 }
276
Michael Jurka33945b22010-12-21 18:19:38 -0800277 public void setIsDefaultDropTarget(boolean isDefaultDropTarget) {
278 if (mIsDefaultDropTarget != isDefaultDropTarget) {
279 mIsDefaultDropTarget = isDefaultDropTarget;
280 invalidate();
281 }
282 }
283
Michael Jurka33945b22010-12-21 18:19:38 -0800284 void setIsDragOccuring(boolean isDragOccuring) {
285 if (mIsDragOccuring != isDragOccuring) {
286 mIsDragOccuring = isDragOccuring;
287 invalidate();
288 }
289 }
290
291 void setIsDragOverlapping(boolean isDragOverlapping) {
292 if (mIsDragOverlapping != isDragOverlapping) {
293 mIsDragOverlapping = isDragOverlapping;
294 invalidate();
295 }
296 }
297
298 boolean getIsDragOverlapping() {
299 return mIsDragOverlapping;
300 }
301
302 private void updateGlowRect() {
303 float marginFraction = (mGlowBackgroundScale - 1.0f) / 2.0f;
Michael Jurka18014792010-10-14 09:01:34 -0700304 int marginX = (int) (marginFraction * (mBackgroundRect.right - mBackgroundRect.left));
305 int marginY = (int) (marginFraction * (mBackgroundRect.bottom - mBackgroundRect.top));
Michael Jurka33945b22010-12-21 18:19:38 -0800306 mGlowBackgroundRect.set(mBackgroundRect.left - marginX, mBackgroundRect.top - marginY,
Michael Jurka18014792010-10-14 09:01:34 -0700307 mBackgroundRect.right + marginX, mBackgroundRect.bottom + marginY);
308 invalidate();
309 }
310
311 public void setHoverScale(float scaleFactor) {
Michael Jurka33945b22010-12-21 18:19:38 -0800312 if (scaleFactor != mGlowBackgroundScale) {
313 mGlowBackgroundScale = scaleFactor;
314 updateGlowRect();
Michael Jurka8deb1e62011-01-25 16:27:43 -0800315 if (getParent() != null) {
316 ((View) getParent()).invalidate();
317 }
Michael Jurka18014792010-10-14 09:01:34 -0700318 }
319 }
320
321 public float getHoverScale() {
Michael Jurka33945b22010-12-21 18:19:38 -0800322 return mGlowBackgroundScale;
Michael Jurka18014792010-10-14 09:01:34 -0700323 }
324
325 public float getHoverAlpha() {
Michael Jurka33945b22010-12-21 18:19:38 -0800326 return mGlowBackgroundAlpha;
Michael Jurka18014792010-10-14 09:01:34 -0700327 }
328
329 public void setHoverAlpha(float alpha) {
Michael Jurka33945b22010-12-21 18:19:38 -0800330 mGlowBackgroundAlpha = alpha;
Michael Jurka18014792010-10-14 09:01:34 -0700331 invalidate();
332 }
333
334 void animateDrop() {
335 if (LauncherApplication.isScreenXLarge()) {
336 Resources res = getResources();
337 float onDropScale = res.getInteger(R.integer.config_screenOnDropScalePercent) / 100.0f;
338 ObjectAnimator scaleUp = ObjectAnimator.ofFloat(this, "hoverScale", onDropScale);
339 scaleUp.setDuration(res.getInteger(R.integer.config_screenOnDropScaleUpDuration));
340 ObjectAnimator scaleDown = ObjectAnimator.ofFloat(this, "hoverScale", 1.0f);
341 scaleDown.setDuration(res.getInteger(R.integer.config_screenOnDropScaleDownDuration));
342 ObjectAnimator alphaFadeOut = ObjectAnimator.ofFloat(this, "hoverAlpha", 0.0f);
343
344 alphaFadeOut.setStartDelay(res.getInteger(R.integer.config_screenOnDropAlphaFadeDelay));
345 alphaFadeOut.setDuration(res.getInteger(R.integer.config_screenOnDropAlphaFadeDelay));
346
347 AnimatorSet bouncer = new AnimatorSet();
348 bouncer.play(scaleUp).before(scaleDown);
349 bouncer.play(scaleUp).with(alphaFadeOut);
Michael Jurka8edd75c2010-12-17 20:15:06 -0800350 bouncer.addListener(new AnimatorListenerAdapter() {
Michael Jurka3c4c20f2010-10-28 15:36:06 -0700351 @Override
Michael Jurka18014792010-10-14 09:01:34 -0700352 public void onAnimationStart(Animator animation) {
Michael Jurka33945b22010-12-21 18:19:38 -0800353 setIsDragOverlapping(true);
Michael Jurka18014792010-10-14 09:01:34 -0700354 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -0700355 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -0800356 public void onAnimationEnd(Animator animation) {
Michael Jurka33945b22010-12-21 18:19:38 -0800357 setIsDragOverlapping(false);
Michael Jurka18014792010-10-14 09:01:34 -0700358 setHoverScale(1.0f);
359 setHoverAlpha(1.0f);
360 }
361 });
362 bouncer.start();
363 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800364 }
365
Jeff Sharkey83f111d2009-04-20 21:03:13 -0700366 @Override
Patrick Dubroy1262e362010-10-06 15:49:50 -0700367 protected void onDraw(Canvas canvas) {
Michael Jurka3e7c7632010-10-02 16:01:03 -0700368 // When we're large, we are either drawn in a "hover" state (ie when dragging an item to
369 // a neighboring page) or with just a normal background (if backgroundAlpha > 0.0f)
370 // When we're small, we are either drawn normally or in the "accepts drops" state (during
371 // a drag). However, we also drag the mini hover background *over* one of those two
372 // backgrounds
Winson Chung26cbf3a2011-01-06 16:25:55 -0800373 if (LauncherApplication.isScreenXLarge() && mBackgroundAlpha > 0.0f) {
Adam Cohenf34bab52010-09-30 14:11:56 -0700374 Drawable bg;
Michael Jurka33945b22010-12-21 18:19:38 -0800375 boolean mini = getScaleX() < 0.5f;
376
377 if (mIsDragOverlapping) {
378 // In the mini case, we draw the active_glow bg *over* the active background
379 bg = mini ? mActiveBackgroundMini : mActiveGlowBackground;
380 } else if (mIsDragOccuring && mAcceptsDrops) {
381 bg = mini ? mActiveBackgroundMini : mActiveBackground;
Adam Cohen3af863b2011-01-25 12:16:51 -0800382 } else if (mIsDefaultDropTarget && mini) {
383 bg = mNormalGlowBackgroundMini;
Adam Cohenf34bab52010-09-30 14:11:56 -0700384 } else {
Michael Jurka33945b22010-12-21 18:19:38 -0800385 bg = mini ? mNormalBackgroundMini : mNormalBackground;
Adam Cohenf34bab52010-09-30 14:11:56 -0700386 }
Michael Jurka33945b22010-12-21 18:19:38 -0800387
388 bg.setAlpha((int) (mBackgroundAlpha * mBackgroundAlphaMultiplier * 255));
389 bg.setBounds(mBackgroundRect);
390 bg.draw(canvas);
391
392 if (mini && mIsDragOverlapping) {
Michael Jurka18014792010-10-14 09:01:34 -0700393 boolean modifiedClipRect = false;
Michael Jurka33945b22010-12-21 18:19:38 -0800394 if (mGlowBackgroundScale > 1.0f) {
Michael Jurka18014792010-10-14 09:01:34 -0700395 // If the hover background's scale is greater than 1, we'll be drawing outside
396 // the bounds of this CellLayout. Get around that by temporarily increasing the
397 // size of the clip rect
Michael Jurka33945b22010-12-21 18:19:38 -0800398 float marginFraction = (mGlowBackgroundScale - 1.0f) / 2.0f;
Michael Jurka18014792010-10-14 09:01:34 -0700399 Rect clipRect = canvas.getClipBounds();
400 int marginX = (int) (marginFraction * (clipRect.right - clipRect.left));
401 int marginY = (int) (marginFraction * (clipRect.bottom - clipRect.top));
402 canvas.save(Canvas.CLIP_SAVE_FLAG);
403 canvas.clipRect(-marginX, -marginY,
404 getWidth() + marginX, getHeight() + marginY, Region.Op.REPLACE);
405 modifiedClipRect = true;
406 }
407
Michael Jurka33945b22010-12-21 18:19:38 -0800408 mActiveGlowBackgroundMini.setAlpha(
409 (int) (mBackgroundAlpha * mGlowBackgroundAlpha * 255));
410 mActiveGlowBackgroundMini.setBounds(mGlowBackgroundRect);
411 mActiveGlowBackgroundMini.draw(canvas);
Michael Jurka18014792010-10-14 09:01:34 -0700412 if (modifiedClipRect) {
413 canvas.restore();
414 }
Michael Jurka3e7c7632010-10-02 16:01:03 -0700415 }
Michael Jurkaa63c4522010-08-19 13:52:27 -0700416 }
Romain Guya6abce82009-11-10 02:54:41 -0800417
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700418 if (mCrosshairsVisibility > 0.0f) {
419 final int countX = mCountX;
420 final int countY = mCountY;
421
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700422 final float MAX_ALPHA = 0.4f;
423 final int MAX_VISIBLE_DISTANCE = 600;
424 final float DISTANCE_MULTIPLIER = 0.002f;
425
426 final Drawable d = mCrosshairsDrawable;
427 final int width = d.getIntrinsicWidth();
428 final int height = d.getIntrinsicHeight();
429
430 int x = getLeftPadding() - (mWidthGap / 2) - (width / 2);
431 for (int col = 0; col <= countX; col++) {
432 int y = getTopPadding() - (mHeightGap / 2) - (height / 2);
433 for (int row = 0; row <= countY; row++) {
434 mTmpPointF.set(x - mDragCenter.x, y - mDragCenter.y);
435 float dist = mTmpPointF.length();
436 // Crosshairs further from the drag point are more faint
437 float alpha = Math.min(MAX_ALPHA,
438 DISTANCE_MULTIPLIER * (MAX_VISIBLE_DISTANCE - dist));
439 if (alpha > 0.0f) {
440 d.setBounds(x, y, x + width, y + height);
441 d.setAlpha((int) (alpha * 255 * mCrosshairsVisibility));
442 d.draw(canvas);
443 }
444 y += mCellHeight + mHeightGap;
445 }
446 x += mCellWidth + mWidthGap;
447 }
Joe Onorato4be866d2010-10-10 11:26:02 -0700448 }
Winson Chung150fbab2010-09-29 17:14:26 -0700449
Patrick Dubroy8e58e912010-10-14 13:21:48 -0700450 final Paint paint = mDragOutlinePaint;
Joe Onorato4be866d2010-10-10 11:26:02 -0700451 for (int i = 0; i < mDragOutlines.length; i++) {
Chet Haase472b2812010-10-14 07:02:04 -0700452 final float alpha = mDragOutlineAlphas[i];
Joe Onorato4be866d2010-10-10 11:26:02 -0700453 if (alpha > 0) {
454 final Point p = mDragOutlines[i];
455 final Bitmap b = (Bitmap) mDragOutlineAnims[i].getTag();
Chet Haase472b2812010-10-14 07:02:04 -0700456 paint.setAlpha((int)(alpha + .5f));
Joe Onorato4be866d2010-10-10 11:26:02 -0700457 canvas.drawBitmap(b, p.x, p.y, paint);
Winson Chung150fbab2010-09-29 17:14:26 -0700458 }
Patrick Dubroy6569f2c2010-07-12 14:25:18 -0700459 }
460 }
461
462 @Override
Jeff Sharkey83f111d2009-04-20 21:03:13 -0700463 public void cancelLongPress() {
464 super.cancelLongPress();
465
466 // Cancel long press for all children
467 final int count = getChildCount();
468 for (int i = 0; i < count; i++) {
469 final View child = getChildAt(i);
470 child.cancelLongPress();
471 }
472 }
473
Michael Jurkadee05892010-07-27 10:01:56 -0700474 public void setOnInterceptTouchListener(View.OnTouchListener listener) {
475 mInterceptTouchListener = listener;
476 }
477
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800478 int getCountX() {
Adam Cohend22015c2010-07-26 22:02:18 -0700479 return mCountX;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800480 }
481
482 int getCountY() {
Adam Cohend22015c2010-07-26 22:02:18 -0700483 return mCountY;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800484 }
485
Michael Jurkaf3ca3ab2010-10-20 17:08:24 -0700486 public boolean addViewToCellLayout(
487 View child, int index, int childId, LayoutParams params, boolean markCells) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700488 final LayoutParams lp = params;
489
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800490 // Generate an id for each view, this assumes we have at most 256x256 cells
491 // per workspace screen
Adam Cohend22015c2010-07-26 22:02:18 -0700492 if (lp.cellX >= 0 && lp.cellX <= mCountX - 1 && lp.cellY >= 0 && lp.cellY <= mCountY - 1) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700493 // If the horizontal or vertical span is set to -1, it is taken to
494 // mean that it spans the extent of the CellLayout
Adam Cohend22015c2010-07-26 22:02:18 -0700495 if (lp.cellHSpan < 0) lp.cellHSpan = mCountX;
496 if (lp.cellVSpan < 0) lp.cellVSpan = mCountY;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800497
Winson Chungaafa03c2010-06-11 17:34:16 -0700498 child.setId(childId);
499
Michael Jurka8c920dd2011-01-20 14:16:56 -0800500 mChildren.addView(child, index, lp);
Michael Jurkadee05892010-07-27 10:01:56 -0700501
Michael Jurkaf3ca3ab2010-10-20 17:08:24 -0700502 if (markCells) markCellsAsOccupiedForView(child);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700503
Winson Chungaafa03c2010-06-11 17:34:16 -0700504 return true;
505 }
506 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800507 }
Michael Jurka3e7c7632010-10-02 16:01:03 -0700508
Michael Jurkabea15192010-11-17 12:33:46 -0800509 public void setAcceptsDrops(boolean acceptsDrops) {
510 if (mAcceptsDrops != acceptsDrops) {
511 mAcceptsDrops = acceptsDrops;
512 invalidate();
513 }
514 }
515
Michael Jurka3e7c7632010-10-02 16:01:03 -0700516 public boolean getAcceptsDrops() {
517 return mAcceptsDrops;
518 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800519
520 @Override
Michael Jurka0280c3b2010-09-17 15:00:07 -0700521 public void removeAllViews() {
522 clearOccupiedCells();
Michael Jurka8c920dd2011-01-20 14:16:56 -0800523 mChildren.removeAllViews();
Michael Jurka0280c3b2010-09-17 15:00:07 -0700524 }
525
526 @Override
527 public void removeAllViewsInLayout() {
528 clearOccupiedCells();
Michael Jurka8c920dd2011-01-20 14:16:56 -0800529 mChildren.removeAllViewsInLayout();
Michael Jurka0280c3b2010-09-17 15:00:07 -0700530 }
531
Michael Jurkaf3ca3ab2010-10-20 17:08:24 -0700532 public void removeViewWithoutMarkingCells(View view) {
Michael Jurkacf6125c2011-01-28 15:20:01 -0800533 mChildren.removeView(view);
Michael Jurkaf3ca3ab2010-10-20 17:08:24 -0700534 }
535
Michael Jurka0280c3b2010-09-17 15:00:07 -0700536 @Override
537 public void removeView(View view) {
538 markCellsAsUnoccupiedForView(view);
Michael Jurka8c920dd2011-01-20 14:16:56 -0800539 mChildren.removeView(view);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700540 }
541
542 @Override
543 public void removeViewAt(int index) {
Michael Jurka8c920dd2011-01-20 14:16:56 -0800544 markCellsAsUnoccupiedForView(mChildren.getChildAt(index));
545 mChildren.removeViewAt(index);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700546 }
547
548 @Override
549 public void removeViewInLayout(View view) {
550 markCellsAsUnoccupiedForView(view);
Michael Jurka8c920dd2011-01-20 14:16:56 -0800551 mChildren.removeViewInLayout(view);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700552 }
553
554 @Override
555 public void removeViews(int start, int count) {
556 for (int i = start; i < start + count; i++) {
Michael Jurka8c920dd2011-01-20 14:16:56 -0800557 markCellsAsUnoccupiedForView(mChildren.getChildAt(i));
Michael Jurka0280c3b2010-09-17 15:00:07 -0700558 }
Michael Jurka8c920dd2011-01-20 14:16:56 -0800559 mChildren.removeViews(start, count);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700560 }
561
562 @Override
563 public void removeViewsInLayout(int start, int count) {
564 for (int i = start; i < start + count; i++) {
Michael Jurka8c920dd2011-01-20 14:16:56 -0800565 markCellsAsUnoccupiedForView(mChildren.getChildAt(i));
Michael Jurka0280c3b2010-09-17 15:00:07 -0700566 }
Michael Jurka8c920dd2011-01-20 14:16:56 -0800567 mChildren.removeViewsInLayout(start, count);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700568 }
569
Michael Jurka8c920dd2011-01-20 14:16:56 -0800570 public void drawChildren(Canvas canvas) {
571 mChildren.draw(canvas);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800572 }
573
574 @Override
575 protected void onAttachedToWindow() {
576 super.onAttachedToWindow();
577 mCellInfo.screen = ((ViewGroup) getParent()).indexOfChild(this);
578 }
579
Michael Jurkaaf442092010-06-10 17:01:57 -0700580 public void setTagToCellInfoForPoint(int touchX, int touchY) {
581 final CellInfo cellInfo = mCellInfo;
582 final Rect frame = mRect;
583 final int x = touchX + mScrollX;
584 final int y = touchY + mScrollY;
Michael Jurka8c920dd2011-01-20 14:16:56 -0800585 final int count = mChildren.getChildCount();
Michael Jurkaaf442092010-06-10 17:01:57 -0700586
587 boolean found = false;
588 for (int i = count - 1; i >= 0; i--) {
Michael Jurka8c920dd2011-01-20 14:16:56 -0800589 final View child = mChildren.getChildAt(i);
Adam Cohend4844c32011-02-18 19:25:06 -0800590 final LayoutParams lp = (LayoutParams) child.getLayoutParams();
Michael Jurkaaf442092010-06-10 17:01:57 -0700591
Adam Cohen1b607ed2011-03-03 17:26:50 -0800592 if ((child.getVisibility() == VISIBLE || child.getAnimation() != null) &&
593 lp.isLockedToGrid) {
Michael Jurkaaf442092010-06-10 17:01:57 -0700594 child.getHitRect(frame);
595 if (frame.contains(x, y)) {
Michael Jurkaaf442092010-06-10 17:01:57 -0700596 cellInfo.cell = child;
597 cellInfo.cellX = lp.cellX;
598 cellInfo.cellY = lp.cellY;
599 cellInfo.spanX = lp.cellHSpan;
600 cellInfo.spanY = lp.cellVSpan;
601 cellInfo.valid = true;
602 found = true;
Michael Jurkaaf442092010-06-10 17:01:57 -0700603 break;
604 }
605 }
606 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700607
Michael Jurkaaf442092010-06-10 17:01:57 -0700608 if (!found) {
Patrick Dubroy6569f2c2010-07-12 14:25:18 -0700609 final int cellXY[] = mTmpCellXY;
Michael Jurkaaf442092010-06-10 17:01:57 -0700610 pointToCellExact(x, y, cellXY);
611
Michael Jurkaaf442092010-06-10 17:01:57 -0700612 cellInfo.cell = null;
613 cellInfo.cellX = cellXY[0];
614 cellInfo.cellY = cellXY[1];
615 cellInfo.spanX = 1;
616 cellInfo.spanY = 1;
Michael Jurka0280c3b2010-09-17 15:00:07 -0700617 cellInfo.valid = cellXY[0] >= 0 && cellXY[1] >= 0 && cellXY[0] < mCountX &&
618 cellXY[1] < mCountY && !mOccupied[cellXY[0]][cellXY[1]];
Michael Jurkaaf442092010-06-10 17:01:57 -0700619 }
620 setTag(cellInfo);
621 }
622
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800623 @Override
624 public boolean onInterceptTouchEvent(MotionEvent ev) {
Michael Jurkadee05892010-07-27 10:01:56 -0700625 if (mInterceptTouchListener != null && mInterceptTouchListener.onTouch(this, ev)) {
626 return true;
627 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800628 final int action = ev.getAction();
629 final CellInfo cellInfo = mCellInfo;
630
631 if (action == MotionEvent.ACTION_DOWN) {
Michael Jurkaaf442092010-06-10 17:01:57 -0700632 setTagToCellInfoForPoint((int) ev.getX(), (int) ev.getY());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800633 } else if (action == MotionEvent.ACTION_UP) {
634 cellInfo.cell = null;
635 cellInfo.cellX = -1;
636 cellInfo.cellY = -1;
637 cellInfo.spanX = 0;
638 cellInfo.spanY = 0;
639 cellInfo.valid = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800640 setTag(cellInfo);
641 }
642
643 return false;
644 }
645
646 @Override
647 public CellInfo getTag() {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700648 return (CellInfo) super.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800649 }
650
Patrick Dubroy6569f2c2010-07-12 14:25:18 -0700651 /**
Winson Chungaafa03c2010-06-11 17:34:16 -0700652 * Given a point, return the cell that strictly encloses that point
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800653 * @param x X coordinate of the point
654 * @param y Y coordinate of the point
655 * @param result Array of 2 ints to hold the x and y coordinate of the cell
656 */
657 void pointToCellExact(int x, int y, int[] result) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700658 final int hStartPadding = getLeftPadding();
659 final int vStartPadding = getTopPadding();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800660
661 result[0] = (x - hStartPadding) / (mCellWidth + mWidthGap);
662 result[1] = (y - vStartPadding) / (mCellHeight + mHeightGap);
663
Adam Cohend22015c2010-07-26 22:02:18 -0700664 final int xAxis = mCountX;
665 final int yAxis = mCountY;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800666
667 if (result[0] < 0) result[0] = 0;
668 if (result[0] >= xAxis) result[0] = xAxis - 1;
669 if (result[1] < 0) result[1] = 0;
670 if (result[1] >= yAxis) result[1] = yAxis - 1;
671 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700672
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800673 /**
674 * Given a point, return the cell that most closely encloses that point
675 * @param x X coordinate of the point
676 * @param y Y coordinate of the point
677 * @param result Array of 2 ints to hold the x and y coordinate of the cell
678 */
679 void pointToCellRounded(int x, int y, int[] result) {
680 pointToCellExact(x + (mCellWidth / 2), y + (mCellHeight / 2), result);
681 }
682
683 /**
684 * Given a cell coordinate, return the point that represents the upper left corner of that cell
Winson Chungaafa03c2010-06-11 17:34:16 -0700685 *
686 * @param cellX X coordinate of the cell
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800687 * @param cellY Y coordinate of the cell
Winson Chungaafa03c2010-06-11 17:34:16 -0700688 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800689 * @param result Array of 2 ints to hold the x and y coordinate of the point
690 */
691 void cellToPoint(int cellX, int cellY, int[] result) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700692 final int hStartPadding = getLeftPadding();
693 final int vStartPadding = getTopPadding();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800694
695 result[0] = hStartPadding + cellX * (mCellWidth + mWidthGap);
696 result[1] = vStartPadding + cellY * (mCellHeight + mHeightGap);
697 }
698
Romain Guy84f296c2009-11-04 15:00:44 -0800699 int getCellWidth() {
700 return mCellWidth;
701 }
702
703 int getCellHeight() {
704 return mCellHeight;
705 }
706
Adam Cohend4844c32011-02-18 19:25:06 -0800707 int getWidthGap() {
708 return mWidthGap;
709 }
710
711 int getHeightGap() {
712 return mHeightGap;
713 }
714
Romain Guy1a304a12009-11-10 00:02:32 -0800715 int getLeftPadding() {
Winson Chungaafa03c2010-06-11 17:34:16 -0700716 return mLeftPadding;
Romain Guy1a304a12009-11-10 00:02:32 -0800717 }
718
719 int getTopPadding() {
Winson Chungaafa03c2010-06-11 17:34:16 -0700720 return mTopPadding;
Romain Guy1a304a12009-11-10 00:02:32 -0800721 }
722
723 int getRightPadding() {
Winson Chungaafa03c2010-06-11 17:34:16 -0700724 return mRightPadding;
Romain Guy1a304a12009-11-10 00:02:32 -0800725 }
726
727 int getBottomPadding() {
Winson Chungaafa03c2010-06-11 17:34:16 -0700728 return mBottomPadding;
Romain Guy1a304a12009-11-10 00:02:32 -0800729 }
730
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800731 @Override
732 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
733 // TODO: currently ignoring padding
Winson Chungaafa03c2010-06-11 17:34:16 -0700734
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800735 int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec);
Winson Chungaafa03c2010-06-11 17:34:16 -0700736 int widthSpecSize = MeasureSpec.getSize(widthMeasureSpec);
737
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800738 int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec);
739 int heightSpecSize = MeasureSpec.getSize(heightMeasureSpec);
Winson Chungaafa03c2010-06-11 17:34:16 -0700740
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800741 if (widthSpecMode == MeasureSpec.UNSPECIFIED || heightSpecMode == MeasureSpec.UNSPECIFIED) {
742 throw new RuntimeException("CellLayout cannot have UNSPECIFIED dimensions");
743 }
744
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800745 final int cellWidth = mCellWidth;
746 final int cellHeight = mCellHeight;
747
Adam Cohend22015c2010-07-26 22:02:18 -0700748 int numWidthGaps = mCountX - 1;
749 int numHeightGaps = mCountY - 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800750
Winson Chungece7f5b2010-10-22 14:54:12 -0700751 if (mWidthGap < 0 || mHeightGap < 0) {
752 int vSpaceLeft = heightSpecSize - mTopPadding - mBottomPadding - (cellHeight * mCountY);
753 mHeightGap = vSpaceLeft / numHeightGaps;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800754
Winson Chungece7f5b2010-10-22 14:54:12 -0700755 int hSpaceLeft = widthSpecSize - mLeftPadding - mRightPadding - (cellWidth * mCountX);
756 mWidthGap = hSpaceLeft / numWidthGaps;
Winson Chungaafa03c2010-06-11 17:34:16 -0700757
Winson Chungece7f5b2010-10-22 14:54:12 -0700758 // center it around the min gaps
759 int minGap = Math.min(mWidthGap, mHeightGap);
760 mWidthGap = mHeightGap = minGap;
761 }
Michael Jurka5f1c5092010-09-03 14:15:02 -0700762
Michael Jurka8c920dd2011-01-20 14:16:56 -0800763 // Initial values correspond to widthSpecMode == MeasureSpec.EXACTLY
764 int newWidth = widthSpecSize;
765 int newHeight = heightSpecSize;
Michael Jurka5f1c5092010-09-03 14:15:02 -0700766 if (widthSpecMode == MeasureSpec.AT_MOST) {
Michael Jurka8c920dd2011-01-20 14:16:56 -0800767 newWidth = mLeftPadding + mRightPadding + (mCountX * cellWidth) +
Winson Chungece7f5b2010-10-22 14:54:12 -0700768 ((mCountX - 1) * mWidthGap);
Michael Jurka8c920dd2011-01-20 14:16:56 -0800769 newHeight = mTopPadding + mBottomPadding + (mCountY * cellHeight) +
Winson Chungece7f5b2010-10-22 14:54:12 -0700770 ((mCountY - 1) * mHeightGap);
Michael Jurka5f1c5092010-09-03 14:15:02 -0700771 setMeasuredDimension(newWidth, newHeight);
Michael Jurka5f1c5092010-09-03 14:15:02 -0700772 }
Michael Jurka8c920dd2011-01-20 14:16:56 -0800773
774 int count = getChildCount();
775 for (int i = 0; i < count; i++) {
776 View child = getChildAt(i);
777 int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(newWidth, MeasureSpec.EXACTLY);
778 int childheightMeasureSpec = MeasureSpec.makeMeasureSpec(newHeight,
779 MeasureSpec.EXACTLY);
780 child.measure(childWidthMeasureSpec, childheightMeasureSpec);
781 }
782 setMeasuredDimension(newWidth, newHeight);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800783 }
784
785 @Override
Michael Jurka28750fb2010-09-24 17:43:49 -0700786 protected void onLayout(boolean changed, int l, int t, int r, int b) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800787 int count = getChildCount();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800788 for (int i = 0; i < count; i++) {
Michael Jurka8c920dd2011-01-20 14:16:56 -0800789 View child = getChildAt(i);
790 child.layout(0, 0, r - l, b - t);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800791 }
792 }
793
794 @Override
Michael Jurkadee05892010-07-27 10:01:56 -0700795 protected void onSizeChanged(int w, int h, int oldw, int oldh) {
796 super.onSizeChanged(w, h, oldw, oldh);
Michael Jurka18014792010-10-14 09:01:34 -0700797 mBackgroundRect.set(0, 0, w, h);
Michael Jurka33945b22010-12-21 18:19:38 -0800798 updateGlowRect();
Michael Jurkadee05892010-07-27 10:01:56 -0700799 }
800
801 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800802 protected void setChildrenDrawingCacheEnabled(boolean enabled) {
Michael Jurka8c920dd2011-01-20 14:16:56 -0800803 mChildren.setChildrenDrawingCacheEnabled(enabled);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800804 }
805
806 @Override
807 protected void setChildrenDrawnWithCacheEnabled(boolean enabled) {
Michael Jurka8c920dd2011-01-20 14:16:56 -0800808 mChildren.setChildrenDrawnWithCacheEnabled(enabled);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800809 }
810
Michael Jurka5f1c5092010-09-03 14:15:02 -0700811 public float getBackgroundAlpha() {
812 return mBackgroundAlpha;
Michael Jurkadee05892010-07-27 10:01:56 -0700813 }
814
Michael Jurka742574b2011-02-02 23:51:01 -0800815 public void setFastBackgroundAlpha(float alpha) {
816 mBackgroundAlpha = alpha;
817 }
818
Adam Cohen1b0aaac2010-10-28 11:11:18 -0700819 public void setBackgroundAlphaMultiplier(float multiplier) {
820 mBackgroundAlphaMultiplier = multiplier;
821 }
822
Adam Cohenddb82192010-11-10 16:32:54 -0800823 public float getBackgroundAlphaMultiplier() {
824 return mBackgroundAlphaMultiplier;
825 }
826
Michael Jurka5f1c5092010-09-03 14:15:02 -0700827 public void setBackgroundAlpha(float alpha) {
828 mBackgroundAlpha = alpha;
Michael Jurka0142d492010-08-25 17:46:15 -0700829 invalidate();
Michael Jurkadee05892010-07-27 10:01:56 -0700830 }
831
Michael Jurka5f1c5092010-09-03 14:15:02 -0700832 // Need to return true to let the view system know we know how to handle alpha-- this is
833 // because when our children have an alpha of 0.0f, they are still rendering their "dimmed"
834 // versions
835 @Override
836 protected boolean onSetAlpha(int alpha) {
837 return true;
838 }
839
840 public void setAlpha(float alpha) {
841 setChildrenAlpha(alpha);
842 super.setAlpha(alpha);
843 }
844
Michael Jurka742574b2011-02-02 23:51:01 -0800845 public void setFastAlpha(float alpha) {
846 setFastChildrenAlpha(alpha);
847 super.setFastAlpha(alpha);
848 }
849
Michael Jurkadee05892010-07-27 10:01:56 -0700850 private void setChildrenAlpha(float alpha) {
Michael Jurka0142d492010-08-25 17:46:15 -0700851 final int childCount = getChildCount();
852 for (int i = 0; i < childCount; i++) {
Michael Jurkadee05892010-07-27 10:01:56 -0700853 getChildAt(i).setAlpha(alpha);
854 }
855 }
856
Michael Jurka742574b2011-02-02 23:51:01 -0800857 private void setFastChildrenAlpha(float alpha) {
858 final int childCount = getChildCount();
859 for (int i = 0; i < childCount; i++) {
860 getChildAt(i).setFastAlpha(alpha);
861 }
862 }
863
Patrick Dubroy440c3602010-07-13 17:50:32 -0700864 public View getChildAt(int x, int y) {
Michael Jurka8c920dd2011-01-20 14:16:56 -0800865 return mChildren.getChildAt(x, y);
Patrick Dubroy440c3602010-07-13 17:50:32 -0700866 }
867
Patrick Dubroy6569f2c2010-07-12 14:25:18 -0700868 /**
869 * Estimate where the top left cell of the dragged item will land if it is dropped.
870 *
871 * @param originX The X value of the top left corner of the item
872 * @param originY The Y value of the top left corner of the item
873 * @param spanX The number of horizontal cells that the item spans
874 * @param spanY The number of vertical cells that the item spans
875 * @param result The estimated drop cell X and Y.
876 */
877 void estimateDropCell(int originX, int originY, int spanX, int spanY, int[] result) {
Adam Cohend22015c2010-07-26 22:02:18 -0700878 final int countX = mCountX;
879 final int countY = mCountY;
Patrick Dubroy6569f2c2010-07-12 14:25:18 -0700880
Michael Jurkaa63c4522010-08-19 13:52:27 -0700881 // pointToCellRounded takes the top left of a cell but will pad that with
882 // cellWidth/2 and cellHeight/2 when finding the matching cell
883 pointToCellRounded(originX, originY, result);
Patrick Dubroy6569f2c2010-07-12 14:25:18 -0700884
885 // If the item isn't fully on this screen, snap to the edges
886 int rightOverhang = result[0] + spanX - countX;
887 if (rightOverhang > 0) {
888 result[0] -= rightOverhang; // Snap to right
889 }
890 result[0] = Math.max(0, result[0]); // Snap to left
891 int bottomOverhang = result[1] + spanY - countY;
892 if (bottomOverhang > 0) {
893 result[1] -= bottomOverhang; // Snap to bottom
894 }
895 result[1] = Math.max(0, result[1]); // Snap to top
896 }
897
Joe Onorato4be866d2010-10-10 11:26:02 -0700898 void visualizeDropLocation(
899 View v, Bitmap dragOutline, int originX, int originY, int spanX, int spanY) {
900
Patrick Dubroy08ae2ec2010-10-14 23:54:22 -0700901 final int oldDragCellX = mDragCell[0];
902 final int oldDragCellY = mDragCell[1];
Joe Onorato4be866d2010-10-10 11:26:02 -0700903 final int[] nearest = findNearestVacantArea(originX, originY, spanX, spanY, v, mDragCell);
Winson Chunga9abd0e2010-10-27 17:18:37 -0700904 if (v != null) {
905 mDragCenter.set(originX + (v.getWidth() / 2), originY + (v.getHeight() / 2));
906 } else {
907 mDragCenter.set(originX, originY);
908 }
Patrick Dubroy6569f2c2010-07-12 14:25:18 -0700909
Patrick Dubroy08ae2ec2010-10-14 23:54:22 -0700910 if (nearest != null && (nearest[0] != oldDragCellX || nearest[1] != oldDragCellY)) {
Patrick Dubroy6569f2c2010-07-12 14:25:18 -0700911 // Find the top left corner of the rect the object will occupy
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700912 final int[] topLeft = mTmpPoint;
913 cellToPoint(nearest[0], nearest[1], topLeft);
914
Joe Onorato4be866d2010-10-10 11:26:02 -0700915 int left = topLeft[0];
916 int top = topLeft[1];
Patrick Dubroy6569f2c2010-07-12 14:25:18 -0700917
Winson Chunga9abd0e2010-10-27 17:18:37 -0700918 if (v != null) {
919 if (v.getParent() instanceof CellLayout) {
920 LayoutParams lp = (LayoutParams) v.getLayoutParams();
921 left += lp.leftMargin;
922 top += lp.topMargin;
923 }
Winson Chung150fbab2010-09-29 17:14:26 -0700924
Winson Chunga9abd0e2010-10-27 17:18:37 -0700925 // Offsets due to the size difference between the View and the dragOutline
926 left += (v.getWidth() - dragOutline.getWidth()) / 2;
927 top += (v.getHeight() - dragOutline.getHeight()) / 2;
928 }
Winson Chung150fbab2010-09-29 17:14:26 -0700929
Joe Onorato4be866d2010-10-10 11:26:02 -0700930 final int oldIndex = mDragOutlineCurrent;
Patrick Dubroy08ae2ec2010-10-14 23:54:22 -0700931 mDragOutlineAnims[oldIndex].animateOut();
932 mDragOutlineCurrent = (oldIndex + 1) % mDragOutlines.length;
Winson Chung150fbab2010-09-29 17:14:26 -0700933
Patrick Dubroy08ae2ec2010-10-14 23:54:22 -0700934 mDragOutlines[mDragOutlineCurrent].set(left, top);
935 mDragOutlineAnims[mDragOutlineCurrent].setTag(dragOutline);
936 mDragOutlineAnims[mDragOutlineCurrent].animateIn();
Patrick Dubroy6569f2c2010-07-12 14:25:18 -0700937 }
Patrick Dubroy49250ad2010-10-08 15:33:52 -0700938
939 // If we are drawing crosshairs, the entire CellLayout needs to be invalidated
940 if (mCrosshairsDrawable != null) {
941 invalidate();
942 }
Patrick Dubroy6569f2c2010-07-12 14:25:18 -0700943 }
944
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800945 /**
Jeff Sharkey70864282009-04-07 21:08:40 -0700946 * Find a vacant area that will fit the given bounds nearest the requested
947 * cell location. Uses Euclidean distance to score multiple vacant areas.
Winson Chungaafa03c2010-06-11 17:34:16 -0700948 *
Romain Guy51afc022009-05-04 18:03:43 -0700949 * @param pixelX The X location at which you want to search for a vacant area.
950 * @param pixelY The Y location at which you want to search for a vacant area.
Jeff Sharkey70864282009-04-07 21:08:40 -0700951 * @param spanX Horizontal span of the object.
952 * @param spanY Vertical span of the object.
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700953 * @param result Array in which to place the result, or null (in which case a new array will
954 * be allocated)
Jeff Sharkey70864282009-04-07 21:08:40 -0700955 * @return The X, Y cell of a vacant area that can contain this object,
956 * nearest the requested location.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800957 */
Michael Jurka6a1435d2010-09-27 17:35:12 -0700958 int[] findNearestVacantArea(
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700959 int pixelX, int pixelY, int spanX, int spanY, int[] result) {
960 return findNearestVacantArea(pixelX, pixelY, spanX, spanY, null, result);
Michael Jurka6a1435d2010-09-27 17:35:12 -0700961 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700962
Michael Jurka6a1435d2010-09-27 17:35:12 -0700963 /**
964 * Find a vacant area that will fit the given bounds nearest the requested
965 * cell location. Uses Euclidean distance to score multiple vacant areas.
966 *
967 * @param pixelX The X location at which you want to search for a vacant area.
968 * @param pixelY The Y location at which you want to search for a vacant area.
969 * @param spanX Horizontal span of the object.
970 * @param spanY Vertical span of the object.
Michael Jurka6a1435d2010-09-27 17:35:12 -0700971 * @param ignoreView Considers space occupied by this view as unoccupied
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700972 * @param result Previously returned value to possibly recycle.
Michael Jurka6a1435d2010-09-27 17:35:12 -0700973 * @return The X, Y cell of a vacant area that can contain this object,
974 * nearest the requested location.
975 */
976 int[] findNearestVacantArea(
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700977 int pixelX, int pixelY, int spanX, int spanY, View ignoreView, int[] result) {
Michael Jurkac6ee42e2010-09-30 12:04:50 -0700978 // mark space take by ignoreView as available (method checks if ignoreView is null)
979 markCellsAsUnoccupiedForView(ignoreView);
980
Jeff Sharkey70864282009-04-07 21:08:40 -0700981 // Keep track of best-scoring drop area
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700982 final int[] bestXY = result != null ? result : new int[2];
Jeff Sharkey70864282009-04-07 21:08:40 -0700983 double bestDistance = Double.MAX_VALUE;
Winson Chungaafa03c2010-06-11 17:34:16 -0700984
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700985 final int countX = mCountX;
986 final int countY = mCountY;
987 final boolean[][] occupied = mOccupied;
988
Winson Chungbbc60d82010-11-11 16:34:41 -0800989 for (int y = 0; y < countY - (spanY - 1); y++) {
Michael Jurkac28de512010-08-13 11:27:44 -0700990 inner:
Winson Chungbbc60d82010-11-11 16:34:41 -0800991 for (int x = 0; x < countX - (spanX - 1); x++) {
Michael Jurkac28de512010-08-13 11:27:44 -0700992 for (int i = 0; i < spanX; i++) {
993 for (int j = 0; j < spanY; j++) {
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700994 if (occupied[x + i][y + j]) {
Winson Chungbbc60d82010-11-11 16:34:41 -0800995 // small optimization: we can skip to after the column we just found
Michael Jurkac28de512010-08-13 11:27:44 -0700996 // an occupied cell
Winson Chungbbc60d82010-11-11 16:34:41 -0800997 x += i;
Michael Jurkac28de512010-08-13 11:27:44 -0700998 continue inner;
999 }
1000 }
1001 }
1002 final int[] cellXY = mTmpCellXY;
1003 cellToPoint(x, y, cellXY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001004
Michael Jurkac28de512010-08-13 11:27:44 -07001005 double distance = Math.sqrt(Math.pow(cellXY[0] - pixelX, 2)
1006 + Math.pow(cellXY[1] - pixelY, 2));
1007 if (distance <= bestDistance) {
1008 bestDistance = distance;
1009 bestXY[0] = x;
1010 bestXY[1] = y;
1011 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001012 }
1013 }
Michael Jurkac6ee42e2010-09-30 12:04:50 -07001014 // re-mark space taken by ignoreView as occupied
1015 markCellsAsOccupiedForView(ignoreView);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001016
Winson Chungaafa03c2010-06-11 17:34:16 -07001017 // Return null if no suitable location found
Jeff Sharkey70864282009-04-07 21:08:40 -07001018 if (bestDistance < Double.MAX_VALUE) {
1019 return bestXY;
1020 } else {
1021 return null;
1022 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001023 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001024
Michael Jurka0280c3b2010-09-17 15:00:07 -07001025 boolean existsEmptyCell() {
1026 return findCellForSpan(null, 1, 1);
1027 }
1028
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001029 /**
Michael Jurka0280c3b2010-09-17 15:00:07 -07001030 * Finds the upper-left coordinate of the first rectangle in the grid that can
1031 * hold a cell of the specified dimensions. If intersectX and intersectY are not -1,
1032 * then this method will only return coordinates for rectangles that contain the cell
1033 * (intersectX, intersectY)
1034 *
1035 * @param cellXY The array that will contain the position of a vacant cell if such a cell
1036 * can be found.
1037 * @param spanX The horizontal span of the cell we want to find.
1038 * @param spanY The vertical span of the cell we want to find.
1039 *
1040 * @return True if a vacant cell of the specified dimension was found, false otherwise.
Patrick Dubroy6569f2c2010-07-12 14:25:18 -07001041 */
Michael Jurka0280c3b2010-09-17 15:00:07 -07001042 boolean findCellForSpan(int[] cellXY, int spanX, int spanY) {
1043 return findCellForSpanThatIntersectsIgnoring(cellXY, spanX, spanY, -1, -1, null);
1044 }
1045
1046 /**
1047 * Like above, but ignores any cells occupied by the item "ignoreView"
1048 *
1049 * @param cellXY The array that will contain the position of a vacant cell if such a cell
1050 * can be found.
1051 * @param spanX The horizontal span of the cell we want to find.
1052 * @param spanY The vertical span of the cell we want to find.
1053 * @param ignoreView The home screen item we should treat as not occupying any space
1054 * @return
1055 */
1056 boolean findCellForSpanIgnoring(int[] cellXY, int spanX, int spanY, View ignoreView) {
1057 return findCellForSpanThatIntersectsIgnoring(cellXY, spanX, spanY, -1, -1, ignoreView);
1058 }
1059
1060 /**
1061 * Like above, but if intersectX and intersectY are not -1, then this method will try to
1062 * return coordinates for rectangles that contain the cell [intersectX, intersectY]
1063 *
1064 * @param spanX The horizontal span of the cell we want to find.
1065 * @param spanY The vertical span of the cell we want to find.
1066 * @param ignoreView The home screen item we should treat as not occupying any space
1067 * @param intersectX The X coordinate of the cell that we should try to overlap
1068 * @param intersectX The Y coordinate of the cell that we should try to overlap
1069 *
1070 * @return True if a vacant cell of the specified dimension was found, false otherwise.
1071 */
1072 boolean findCellForSpanThatIntersects(int[] cellXY, int spanX, int spanY,
1073 int intersectX, int intersectY) {
1074 return findCellForSpanThatIntersectsIgnoring(
1075 cellXY, spanX, spanY, intersectX, intersectY, null);
1076 }
1077
1078 /**
1079 * The superset of the above two methods
1080 */
1081 boolean findCellForSpanThatIntersectsIgnoring(int[] cellXY, int spanX, int spanY,
1082 int intersectX, int intersectY, View ignoreView) {
Michael Jurkac6ee42e2010-09-30 12:04:50 -07001083 // mark space take by ignoreView as available (method checks if ignoreView is null)
1084 markCellsAsUnoccupiedForView(ignoreView);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001085
Michael Jurka28750fb2010-09-24 17:43:49 -07001086 boolean foundCell = false;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001087 while (true) {
1088 int startX = 0;
1089 if (intersectX >= 0) {
1090 startX = Math.max(startX, intersectX - (spanX - 1));
1091 }
1092 int endX = mCountX - (spanX - 1);
1093 if (intersectX >= 0) {
1094 endX = Math.min(endX, intersectX + (spanX - 1) + (spanX == 1 ? 1 : 0));
1095 }
1096 int startY = 0;
1097 if (intersectY >= 0) {
1098 startY = Math.max(startY, intersectY - (spanY - 1));
1099 }
1100 int endY = mCountY - (spanY - 1);
1101 if (intersectY >= 0) {
1102 endY = Math.min(endY, intersectY + (spanY - 1) + (spanY == 1 ? 1 : 0));
1103 }
1104
Winson Chungbbc60d82010-11-11 16:34:41 -08001105 for (int y = startY; y < endY && !foundCell; y++) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001106 inner:
Winson Chungbbc60d82010-11-11 16:34:41 -08001107 for (int x = startX; x < endX; x++) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001108 for (int i = 0; i < spanX; i++) {
1109 for (int j = 0; j < spanY; j++) {
1110 if (mOccupied[x + i][y + j]) {
Winson Chungbbc60d82010-11-11 16:34:41 -08001111 // small optimization: we can skip to after the column we just found
Michael Jurka0280c3b2010-09-17 15:00:07 -07001112 // an occupied cell
Winson Chungbbc60d82010-11-11 16:34:41 -08001113 x += i;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001114 continue inner;
1115 }
1116 }
1117 }
1118 if (cellXY != null) {
1119 cellXY[0] = x;
1120 cellXY[1] = y;
1121 }
Michael Jurka28750fb2010-09-24 17:43:49 -07001122 foundCell = true;
1123 break;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001124 }
1125 }
1126 if (intersectX == -1 && intersectY == -1) {
1127 break;
1128 } else {
1129 // if we failed to find anything, try again but without any requirements of
1130 // intersecting
1131 intersectX = -1;
1132 intersectY = -1;
1133 continue;
1134 }
1135 }
1136
Michael Jurkac6ee42e2010-09-30 12:04:50 -07001137 // re-mark space taken by ignoreView as occupied
1138 markCellsAsOccupiedForView(ignoreView);
Michael Jurka28750fb2010-09-24 17:43:49 -07001139 return foundCell;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001140 }
1141
1142 /**
1143 * Called when drag has left this CellLayout or has been completed (successfully or not)
1144 */
1145 void onDragExit() {
Joe Onorato4be866d2010-10-10 11:26:02 -07001146 // This can actually be called when we aren't in a drag, e.g. when adding a new
1147 // item to this layout via the customize drawer.
1148 // Guard against that case.
1149 if (mDragging) {
1150 mDragging = false;
Patrick Dubroy6569f2c2010-07-12 14:25:18 -07001151
Joe Onorato4be866d2010-10-10 11:26:02 -07001152 // Fade out the drag indicators
1153 if (mCrosshairsAnimator != null) {
1154 mCrosshairsAnimator.animateOut();
1155 }
Patrick Dubroyde7658b2010-09-27 11:15:43 -07001156 }
Patrick Dubroy08ae2ec2010-10-14 23:54:22 -07001157
1158 // Invalidate the drag data
1159 mDragCell[0] = -1;
1160 mDragCell[1] = -1;
1161 mDragOutlineAnims[mDragOutlineCurrent].animateOut();
1162 mDragOutlineCurrent = (mDragOutlineCurrent + 1) % mDragOutlineAnims.length;
1163
Michael Jurka33945b22010-12-21 18:19:38 -08001164 setIsDragOverlapping(false);
Patrick Dubroy6569f2c2010-07-12 14:25:18 -07001165 }
1166
1167 /**
Winson Chungaafa03c2010-06-11 17:34:16 -07001168 * Mark a child as having been dropped.
Patrick Dubroyde7658b2010-09-27 11:15:43 -07001169 * At the beginning of the drag operation, the child may have been on another
Patrick Dubroyce34a972010-10-19 10:34:32 -07001170 * screen, but it is re-parented before this method is called.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001171 *
1172 * @param child The child that is being dropped
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001173 */
Michael Jurkad3ef3062010-11-23 16:23:58 -08001174 void onDropChild(View child, boolean animate) {
Romain Guyd94533d2009-08-17 10:01:15 -07001175 if (child != null) {
1176 LayoutParams lp = (LayoutParams) child.getLayoutParams();
Romain Guyd94533d2009-08-17 10:01:15 -07001177 lp.isDragging = false;
Romain Guy84f296c2009-11-04 15:00:44 -08001178 lp.dropped = true;
Michael Jurkad3ef3062010-11-23 16:23:58 -08001179 lp.animateDrop = animate;
Patrick Dubroye3887cc2011-01-20 10:43:40 -08001180 child.setVisibility(animate ? View.INVISIBLE : View.VISIBLE);
Romain Guyd94533d2009-08-17 10:01:15 -07001181 child.requestLayout();
Romain Guyd94533d2009-08-17 10:01:15 -07001182 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001183 }
1184
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001185 /**
1186 * Start dragging the specified child
Winson Chungaafa03c2010-06-11 17:34:16 -07001187 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001188 * @param child The child that is being dragged
1189 */
1190 void onDragChild(View child) {
1191 LayoutParams lp = (LayoutParams) child.getLayoutParams();
1192 lp.isDragging = true;
Patrick Dubroyde7658b2010-09-27 11:15:43 -07001193 }
1194
1195 /**
1196 * A drag event has begun over this layout.
1197 * It may have begun over this layout (in which case onDragChild is called first),
1198 * or it may have begun on another layout.
1199 */
Winson Chunga9abd0e2010-10-27 17:18:37 -07001200 void onDragEnter() {
Patrick Dubroyfe6bd872010-10-13 17:32:10 -07001201 if (!mDragging) {
Patrick Dubroyfe6bd872010-10-13 17:32:10 -07001202 // Fade in the drag indicators
1203 if (mCrosshairsAnimator != null) {
1204 mCrosshairsAnimator.animateIn();
1205 }
Joe Onorato4be866d2010-10-10 11:26:02 -07001206 }
1207 mDragging = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001208 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001209
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001210 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001211 * Computes a bounding rectangle for a range of cells
Winson Chungaafa03c2010-06-11 17:34:16 -07001212 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001213 * @param cellX X coordinate of upper left corner expressed as a cell position
1214 * @param cellY Y coordinate of upper left corner expressed as a cell position
Winson Chungaafa03c2010-06-11 17:34:16 -07001215 * @param cellHSpan Width in cells
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001216 * @param cellVSpan Height in cells
Patrick Dubroy6569f2c2010-07-12 14:25:18 -07001217 * @param resultRect Rect into which to put the results
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001218 */
Patrick Dubroy6569f2c2010-07-12 14:25:18 -07001219 public void cellToRect(int cellX, int cellY, int cellHSpan, int cellVSpan, RectF resultRect) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001220 final int cellWidth = mCellWidth;
1221 final int cellHeight = mCellHeight;
1222 final int widthGap = mWidthGap;
1223 final int heightGap = mHeightGap;
Winson Chungaafa03c2010-06-11 17:34:16 -07001224
1225 final int hStartPadding = getLeftPadding();
1226 final int vStartPadding = getTopPadding();
1227
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001228 int width = cellHSpan * cellWidth + ((cellHSpan - 1) * widthGap);
1229 int height = cellVSpan * cellHeight + ((cellVSpan - 1) * heightGap);
1230
1231 int x = hStartPadding + cellX * (cellWidth + widthGap);
1232 int y = vStartPadding + cellY * (cellHeight + heightGap);
Winson Chungaafa03c2010-06-11 17:34:16 -07001233
Patrick Dubroy6569f2c2010-07-12 14:25:18 -07001234 resultRect.set(x, y, x + width, y + height);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001235 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001236
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001237 /**
Winson Chungaafa03c2010-06-11 17:34:16 -07001238 * Computes the required horizontal and vertical cell spans to always
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001239 * fit the given rectangle.
Winson Chungaafa03c2010-06-11 17:34:16 -07001240 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001241 * @param width Width in pixels
1242 * @param height Height in pixels
Patrick Dubroy8f86ddc2010-07-16 13:55:32 -07001243 * @param result An array of length 2 in which to store the result (may be null).
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001244 */
Patrick Dubroy8f86ddc2010-07-16 13:55:32 -07001245 public int[] rectToCell(int width, int height, int[] result) {
Michael Jurka9987a5c2010-10-08 16:58:12 -07001246 return rectToCell(getResources(), width, height, result);
1247 }
1248
1249 public static int[] rectToCell(Resources resources, int width, int height, int[] result) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001250 // Always assume we're working with the smallest span to make sure we
1251 // reserve enough space in both orientations.
Joe Onorato79e56262009-09-21 15:23:04 -04001252 int actualWidth = resources.getDimensionPixelSize(R.dimen.workspace_cell_width);
1253 int actualHeight = resources.getDimensionPixelSize(R.dimen.workspace_cell_height);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001254 int smallerSize = Math.min(actualWidth, actualHeight);
Joe Onorato79e56262009-09-21 15:23:04 -04001255
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001256 // Always round up to next largest cell
1257 int spanX = (width + smallerSize) / smallerSize;
1258 int spanY = (height + smallerSize) / smallerSize;
Joe Onorato79e56262009-09-21 15:23:04 -04001259
Patrick Dubroy8f86ddc2010-07-16 13:55:32 -07001260 if (result == null) {
1261 return new int[] { spanX, spanY };
1262 }
1263 result[0] = spanX;
1264 result[1] = spanY;
1265 return result;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001266 }
1267
Michael Jurkaf12c75c2011-01-25 22:41:40 -08001268 public int[] cellSpansToSize(int hSpans, int vSpans) {
1269 int[] size = new int[2];
1270 size[0] = hSpans * mCellWidth + (hSpans - 1) * mWidthGap;
1271 size[1] = vSpans * mCellHeight + (vSpans - 1) * mHeightGap;
1272 return size;
1273 }
1274
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001275 /**
Patrick Dubroy047379a2010-12-19 22:02:04 -08001276 * Calculate the grid spans needed to fit given item
1277 */
1278 public void calculateSpans(ItemInfo info) {
1279 final int minWidth;
1280 final int minHeight;
1281
1282 if (info instanceof LauncherAppWidgetInfo) {
1283 minWidth = ((LauncherAppWidgetInfo) info).minWidth;
1284 minHeight = ((LauncherAppWidgetInfo) info).minHeight;
1285 } else if (info instanceof PendingAddWidgetInfo) {
1286 minWidth = ((PendingAddWidgetInfo) info).minWidth;
1287 minHeight = ((PendingAddWidgetInfo) info).minHeight;
1288 } else {
1289 // It's not a widget, so it must be 1x1
1290 info.spanX = info.spanY = 1;
1291 return;
1292 }
1293 int[] spans = rectToCell(minWidth, minHeight, null);
1294 info.spanX = spans[0];
1295 info.spanY = spans[1];
1296 }
1297
1298 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001299 * Find the first vacant cell, if there is one.
1300 *
1301 * @param vacant Holds the x and y coordinate of the vacant cell
1302 * @param spanX Horizontal cell span.
1303 * @param spanY Vertical cell span.
Winson Chungaafa03c2010-06-11 17:34:16 -07001304 *
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001305 * @return True if a vacant cell was found
1306 */
1307 public boolean getVacantCell(int[] vacant, int spanX, int spanY) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001308
Michael Jurka0280c3b2010-09-17 15:00:07 -07001309 return findVacantCell(vacant, spanX, spanY, mCountX, mCountY, mOccupied);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001310 }
1311
1312 static boolean findVacantCell(int[] vacant, int spanX, int spanY,
1313 int xCount, int yCount, boolean[][] occupied) {
1314
1315 for (int x = 0; x < xCount; x++) {
1316 for (int y = 0; y < yCount; y++) {
1317 boolean available = !occupied[x][y];
1318out: for (int i = x; i < x + spanX - 1 && x < xCount; i++) {
1319 for (int j = y; j < y + spanY - 1 && y < yCount; j++) {
1320 available = available && !occupied[i][j];
1321 if (!available) break out;
1322 }
1323 }
1324
1325 if (available) {
1326 vacant[0] = x;
1327 vacant[1] = y;
1328 return true;
1329 }
1330 }
1331 }
1332
1333 return false;
1334 }
1335
Michael Jurka0280c3b2010-09-17 15:00:07 -07001336 private void clearOccupiedCells() {
1337 for (int x = 0; x < mCountX; x++) {
1338 for (int y = 0; y < mCountY; y++) {
1339 mOccupied[x][y] = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001340 }
1341 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001342 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001343
Adam Cohen1b607ed2011-03-03 17:26:50 -08001344 /**
1345 * Given a view, determines how much that view can be expanded in all directions, in terms of
1346 * whether or not there are other items occupying adjacent cells. Used by the
1347 * AppWidgetResizeFrame to determine how the widget can be resized.
1348 */
Adam Cohend4844c32011-02-18 19:25:06 -08001349 public void getExpandabilityArrayForView(View view, int[] expandability) {
Adam Cohen1b607ed2011-03-03 17:26:50 -08001350 final LayoutParams lp = (LayoutParams) view.getLayoutParams();
Adam Cohend4844c32011-02-18 19:25:06 -08001351 boolean flag;
1352
Adam Cohen1b607ed2011-03-03 17:26:50 -08001353 expandability[AppWidgetResizeFrame.LEFT] = 0;
Adam Cohend4844c32011-02-18 19:25:06 -08001354 for (int x = lp.cellX - 1; x >= 0; x--) {
1355 flag = false;
1356 for (int y = lp.cellY; y < lp.cellY + lp.cellVSpan; y++) {
1357 if (mOccupied[x][y]) flag = true;
1358 }
1359 if (flag) break;
Adam Cohen1b607ed2011-03-03 17:26:50 -08001360 expandability[AppWidgetResizeFrame.LEFT]++;
Adam Cohend4844c32011-02-18 19:25:06 -08001361 }
1362
Adam Cohen1b607ed2011-03-03 17:26:50 -08001363 expandability[AppWidgetResizeFrame.TOP] = 0;
Adam Cohend4844c32011-02-18 19:25:06 -08001364 for (int y = lp.cellY - 1; y >= 0; y--) {
1365 flag = false;
1366 for (int x = lp.cellX; x < lp.cellX + lp.cellHSpan; x++) {
1367 if (mOccupied[x][y]) flag = true;
1368 }
1369 if (flag) break;
Adam Cohen1b607ed2011-03-03 17:26:50 -08001370 expandability[AppWidgetResizeFrame.TOP]++;
1371 }
Adam Cohend4844c32011-02-18 19:25:06 -08001372
Adam Cohen1b607ed2011-03-03 17:26:50 -08001373 expandability[AppWidgetResizeFrame.RIGHT] = 0;
Adam Cohend4844c32011-02-18 19:25:06 -08001374 for (int x = lp.cellX + lp.cellHSpan; x < mCountX; x++) {
1375 flag = false;
1376 for (int y = lp.cellY; y < lp.cellY + lp.cellVSpan; y++) {
1377 if (mOccupied[x][y]) flag = true;
1378 }
1379 if (flag) break;
Adam Cohen1b607ed2011-03-03 17:26:50 -08001380 expandability[AppWidgetResizeFrame.RIGHT]++;
1381 }
Adam Cohend4844c32011-02-18 19:25:06 -08001382
Adam Cohen1b607ed2011-03-03 17:26:50 -08001383 expandability[AppWidgetResizeFrame.BOTTOM] = 0;
Adam Cohend4844c32011-02-18 19:25:06 -08001384 for (int y = lp.cellY + lp.cellVSpan; y < mCountY; y++) {
1385 flag = false;
1386 for (int x = lp.cellX; x < lp.cellX + lp.cellHSpan; x++) {
1387 if (mOccupied[x][y]) flag = true;
1388 }
1389 if (flag) break;
Adam Cohen1b607ed2011-03-03 17:26:50 -08001390 expandability[AppWidgetResizeFrame.BOTTOM]++;
1391 }
Adam Cohend4844c32011-02-18 19:25:06 -08001392 }
1393
Michael Jurka0280c3b2010-09-17 15:00:07 -07001394 public void onMove(View view, int newCellX, int newCellY) {
1395 LayoutParams lp = (LayoutParams) view.getLayoutParams();
1396 markCellsAsUnoccupiedForView(view);
1397 markCellsForView(newCellX, newCellY, lp.cellHSpan, lp.cellVSpan, true);
1398 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001399
Adam Cohend4844c32011-02-18 19:25:06 -08001400 public void markCellsAsOccupiedForView(View view) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08001401 if (view == null || view.getParent() != mChildren) return;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001402 LayoutParams lp = (LayoutParams) view.getLayoutParams();
1403 markCellsForView(lp.cellX, lp.cellY, lp.cellHSpan, lp.cellVSpan, true);
1404 }
1405
Adam Cohend4844c32011-02-18 19:25:06 -08001406 public void markCellsAsUnoccupiedForView(View view) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08001407 if (view == null || view.getParent() != mChildren) return;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001408 LayoutParams lp = (LayoutParams) view.getLayoutParams();
1409 markCellsForView(lp.cellX, lp.cellY, lp.cellHSpan, lp.cellVSpan, false);
1410 }
1411
1412 private void markCellsForView(int cellX, int cellY, int spanX, int spanY, boolean value) {
1413 for (int x = cellX; x < cellX + spanX && x < mCountX; x++) {
1414 for (int y = cellY; y < cellY + spanY && y < mCountY; y++) {
1415 mOccupied[x][y] = value;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001416 }
1417 }
1418 }
1419
1420 @Override
1421 public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) {
1422 return new CellLayout.LayoutParams(getContext(), attrs);
1423 }
1424
1425 @Override
1426 protected boolean checkLayoutParams(ViewGroup.LayoutParams p) {
1427 return p instanceof CellLayout.LayoutParams;
1428 }
1429
1430 @Override
1431 protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) {
1432 return new CellLayout.LayoutParams(p);
1433 }
1434
Winson Chungaafa03c2010-06-11 17:34:16 -07001435 public static class CellLayoutAnimationController extends LayoutAnimationController {
1436 public CellLayoutAnimationController(Animation animation, float delay) {
1437 super(animation, delay);
1438 }
1439
1440 @Override
1441 protected long getDelayForView(View view) {
1442 return (int) (Math.random() * 150);
1443 }
1444 }
1445
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001446 public static class LayoutParams extends ViewGroup.MarginLayoutParams {
1447 /**
1448 * Horizontal location of the item in the grid.
1449 */
1450 @ViewDebug.ExportedProperty
1451 public int cellX;
1452
1453 /**
1454 * Vertical location of the item in the grid.
1455 */
1456 @ViewDebug.ExportedProperty
1457 public int cellY;
1458
1459 /**
1460 * Number of cells spanned horizontally by the item.
1461 */
1462 @ViewDebug.ExportedProperty
1463 public int cellHSpan;
1464
1465 /**
1466 * Number of cells spanned vertically by the item.
1467 */
1468 @ViewDebug.ExportedProperty
1469 public int cellVSpan;
Winson Chungaafa03c2010-06-11 17:34:16 -07001470
Adam Cohen1b607ed2011-03-03 17:26:50 -08001471 /**
1472 * Indicates whether the item will set its x, y, width and height parameters freely,
1473 * or whether these will be computed based on cellX, cellY, cellHSpan and cellVSpan.
1474 */
Adam Cohend4844c32011-02-18 19:25:06 -08001475 public boolean isLockedToGrid = true;
1476
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001477 /**
1478 * Is this item currently being dragged
1479 */
1480 public boolean isDragging;
1481
1482 // X coordinate of the view in the layout.
1483 @ViewDebug.ExportedProperty
1484 int x;
1485 // Y coordinate of the view in the layout.
1486 @ViewDebug.ExportedProperty
1487 int y;
1488
Patrick Dubroyce34a972010-10-19 10:34:32 -07001489 /**
1490 * The old X coordinate of this item, relative to its current parent.
1491 * Used to animate the item into its new position.
1492 */
1493 int oldX;
1494
1495 /**
1496 * The old Y coordinate of this item, relative to its current parent.
1497 * Used to animate the item into its new position.
1498 */
1499 int oldY;
1500
Romain Guy84f296c2009-11-04 15:00:44 -08001501 boolean dropped;
Romain Guyfcb9e712009-10-02 16:06:52 -07001502
Michael Jurkad3ef3062010-11-23 16:23:58 -08001503 boolean animateDrop;
1504
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001505 public LayoutParams(Context c, AttributeSet attrs) {
1506 super(c, attrs);
1507 cellHSpan = 1;
1508 cellVSpan = 1;
1509 }
1510
1511 public LayoutParams(ViewGroup.LayoutParams source) {
1512 super(source);
1513 cellHSpan = 1;
1514 cellVSpan = 1;
1515 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001516
1517 public LayoutParams(LayoutParams source) {
1518 super(source);
1519 this.cellX = source.cellX;
1520 this.cellY = source.cellY;
1521 this.cellHSpan = source.cellHSpan;
1522 this.cellVSpan = source.cellVSpan;
1523 }
1524
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001525 public LayoutParams(int cellX, int cellY, int cellHSpan, int cellVSpan) {
Romain Guy8f19cdd2010-01-08 15:07:00 -08001526 super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001527 this.cellX = cellX;
1528 this.cellY = cellY;
1529 this.cellHSpan = cellHSpan;
1530 this.cellVSpan = cellVSpan;
1531 }
1532
1533 public void setup(int cellWidth, int cellHeight, int widthGap, int heightGap,
1534 int hStartPadding, int vStartPadding) {
Adam Cohend4844c32011-02-18 19:25:06 -08001535 if (isLockedToGrid) {
1536 final int myCellHSpan = cellHSpan;
1537 final int myCellVSpan = cellVSpan;
1538 final int myCellX = cellX;
1539 final int myCellY = cellY;
Adam Cohen1b607ed2011-03-03 17:26:50 -08001540
Adam Cohend4844c32011-02-18 19:25:06 -08001541 width = myCellHSpan * cellWidth + ((myCellHSpan - 1) * widthGap) -
1542 leftMargin - rightMargin;
1543 height = myCellVSpan * cellHeight + ((myCellVSpan - 1) * heightGap) -
1544 topMargin - bottomMargin;
Adam Cohend4844c32011-02-18 19:25:06 -08001545 x = hStartPadding + myCellX * (cellWidth + widthGap) + leftMargin;
1546 y = vStartPadding + myCellY * (cellHeight + heightGap) + topMargin;
1547 }
1548 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001549
Adam Cohend4844c32011-02-18 19:25:06 -08001550 public void setWidth(int width) {
1551 this.width = width;
1552 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001553
Adam Cohend4844c32011-02-18 19:25:06 -08001554 public int getWidth() {
1555 return width;
1556 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001557
Adam Cohend4844c32011-02-18 19:25:06 -08001558 public void setHeight(int height) {
1559 this.height = height;
1560 }
1561
1562 public int getHeight() {
1563 return height;
1564 }
1565
1566 public void setX(int x) {
1567 this.x = x;
1568 }
1569
1570 public int getX() {
1571 return x;
1572 }
1573
1574 public void setY(int y) {
1575 this.y = y;
1576 }
1577
1578 public int getY() {
1579 return y;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001580 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001581
1582 public String toString() {
1583 return "(" + this.cellX + ", " + this.cellY + ")";
1584 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001585 }
1586
Michael Jurka0280c3b2010-09-17 15:00:07 -07001587 // This class stores info for two purposes:
1588 // 1. When dragging items (mDragInfo in Workspace), we store the View, its cellX & cellY,
1589 // its spanX, spanY, and the screen it is on
1590 // 2. When long clicking on an empty cell in a CellLayout, we save information about the
1591 // cellX and cellY coordinates and which page was clicked. We then set this as a tag on
1592 // the CellLayout that was long clicked
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001593 static final class CellInfo implements ContextMenu.ContextMenuInfo {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001594 View cell;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001595 int cellX = -1;
1596 int cellY = -1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001597 int spanX;
1598 int spanY;
1599 int screen;
1600 boolean valid;
1601
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001602 @Override
1603 public String toString() {
Winson Chungaafa03c2010-06-11 17:34:16 -07001604 return "Cell[view=" + (cell == null ? "null" : cell.getClass())
1605 + ", x=" + cellX + ", y=" + cellY + "]";
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001606 }
1607 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001608}