blob: d9bff5e19a9f10dd0aa81993cf032875e853b2d5 [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 Jurkaaf442092010-06-10 17:01:57 -070019import com.android.launcher.R;
Adam Powell495f2892010-04-16 16:40:55 -070020
Michael Jurka0280c3b2010-09-17 15:00:07 -070021import android.animation.Animator;
Patrick Dubroyde7658b2010-09-27 11:15:43 -070022import android.animation.Animator.AnimatorListener;
Chet Haaseb1254a62010-09-07 13:35:00 -070023import android.animation.AnimatorSet;
Michael Jurka0280c3b2010-09-17 15:00:07 -070024import android.animation.ObjectAnimator;
25import android.animation.PropertyValuesHolder;
Dianne Hackborn8f573952009-08-10 23:21:09 -070026import android.app.WallpaperManager;
Romain Guy629de3e2010-01-13 12:20:59 -080027import android.appwidget.AppWidgetManager;
28import android.appwidget.AppWidgetProviderInfo;
Adam Powell495f2892010-04-16 16:40:55 -070029import android.content.ComponentName;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080030import android.content.Context;
31import android.content.Intent;
Adam Powell495f2892010-04-16 16:40:55 -070032import android.content.pm.PackageManager;
Romain Guy5c16f3e2010-01-12 17:24:58 -080033import android.content.pm.ProviderInfo;
Patrick Dubroy7247f632010-08-04 16:02:59 -070034import android.content.res.Resources;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080035import android.content.res.TypedArray;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080036import android.graphics.Canvas;
Michael Jurkaa63c4522010-08-19 13:52:27 -070037import android.graphics.Matrix;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080038import android.graphics.Rect;
The Android Open Source Projectf96811c2009-03-18 17:39:48 -070039import android.graphics.drawable.Drawable;
Romain Guy5c16f3e2010-01-12 17:24:58 -080040import android.net.Uri;
Joe Onorato956091b2010-02-19 12:47:40 -080041import android.os.IBinder;
Adam Powell495f2892010-04-16 16:40:55 -070042import android.os.Parcelable;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080043import android.util.AttributeSet;
Daniel Sandler291ad122010-05-24 16:03:53 -040044import android.util.Log;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080045import android.view.MotionEvent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080046import android.view.View;
The Android Open Source Projectf96811c2009-03-18 17:39:48 -070047import android.widget.TextView;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080048
Michael Jurkaaf442092010-06-10 17:01:57 -070049import java.util.ArrayList;
50import java.util.HashSet;
Romain Guyedcce092010-03-04 13:03:17 -080051
The Android Open Source Project31dd5032009-03-03 19:32:27 -080052/**
Michael Jurka0142d492010-08-25 17:46:15 -070053 * The workspace is a wide area with a wallpaper and a finite number of pages.
54 * Each page contains a number of icons, folders or widgets the user can
Winson Chungaafa03c2010-06-11 17:34:16 -070055 * interact with. A workspace is meant to be used with a fixed width only.
The Android Open Source Project31dd5032009-03-03 19:32:27 -080056 */
Michael Jurka0142d492010-08-25 17:46:15 -070057public class Workspace extends SmoothPagedView
Michael Jurkadee05892010-07-27 10:01:56 -070058 implements DropTarget, DragSource, DragScroller, View.OnTouchListener {
Romain Guye47f55c2009-11-11 19:21:22 -080059 @SuppressWarnings({"UnusedDeclaration"})
Joe Onorato3a8820b2009-11-10 15:06:42 -080060 private static final String TAG = "Launcher.Workspace";
Michael Jurka0142d492010-08-25 17:46:15 -070061
Michael Jurkadee05892010-07-27 10:01:56 -070062 // This is how much the workspace shrinks when we enter all apps or
63 // customization mode
64 private static final float SHRINK_FACTOR = 0.16f;
Adam Cohena985e592010-09-09 11:23:48 -070065
Adam Cohenf34bab52010-09-30 14:11:56 -070066 // Y rotation to apply to the workspace screens
67 private static final float WORKSPACE_ROTATION = 12.5f;
Adam Cohena985e592010-09-09 11:23:48 -070068
69 // These are extra scale factors to apply to the mini home screens
70 // so as to achieve the desired transform
71 private static final float EXTRA_SCALE_FACTOR_0 = 0.97f;
72 private static final float EXTRA_SCALE_FACTOR_1 = 1.0f;
Adam Cohene54cec82010-09-13 18:19:55 -070073 private static final float EXTRA_SCALE_FACTOR_2 = 1.08f;
Adam Cohena985e592010-09-09 11:23:48 -070074
Adam Cohenf34bab52010-09-30 14:11:56 -070075 private static final int BACKGROUND_FADE_OUT_DELAY = 300;
76 private static final int BACKGROUND_FADE_OUT_DURATION = 300;
77 private static final int BACKGROUND_FADE_IN_DURATION = 100;
78
Adam Cohenf34bab52010-09-30 14:11:56 -070079 // These animators are used to fade the
80 private ObjectAnimator<Float> mBackgroundFadeIn;
81 private ObjectAnimator<Float> mBackgroundFadeOut;
82 private float mBackgroundAlpha = 0;
83
Michael Jurka0142d492010-08-25 17:46:15 -070084 private enum ShrinkPosition { SHRINK_TO_TOP, SHRINK_TO_MIDDLE, SHRINK_TO_BOTTOM };
The Android Open Source Project31dd5032009-03-03 19:32:27 -080085
Dianne Hackborn8f573952009-08-10 23:21:09 -070086 private final WallpaperManager mWallpaperManager;
Winson Chungaafa03c2010-06-11 17:34:16 -070087
Michael Jurka0142d492010-08-25 17:46:15 -070088 private int mDefaultPage;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080089
Michael Jurka79212d82010-07-30 16:36:20 -070090 private boolean mWaitingToShrinkToBottom = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080091
The Android Open Source Project31dd5032009-03-03 19:32:27 -080092 /**
93 * CellInfo for the cell that is currently being dragged
94 */
95 private CellLayout.CellInfo mDragInfo;
Winson Chungaafa03c2010-06-11 17:34:16 -070096
Jeff Sharkey70864282009-04-07 21:08:40 -070097 /**
98 * Target drop area calculated during last acceptDrop call.
99 */
100 private int[] mTargetCell = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800101
Patrick Dubroy6569f2c2010-07-12 14:25:18 -0700102 /**
103 * The CellLayout that is currently being dragged over
104 */
105 private CellLayout mDragTargetLayout = null;
106
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800107 private Launcher mLauncher;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800108 private IconCache mIconCache;
Joe Onorato00acb122009-08-04 16:04:30 -0400109 private DragController mDragController;
Winson Chungaafa03c2010-06-11 17:34:16 -0700110
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800111 private int[] mTempCell = new int[2];
Jeff Sharkey70864282009-04-07 21:08:40 -0700112 private int[] mTempEstimate = new int[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -0700113 private float[] mTempOriginXY = new float[2];
Michael Jurkaa63c4522010-08-19 13:52:27 -0700114 private float[] mTempDragCoordinates = new float[2];
115 private float[] mTempDragBottomRightCoordinates = new float[2];
Michael Jurka0280c3b2010-09-17 15:00:07 -0700116 private Matrix mTempInverseMatrix = new Matrix();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800117
Adam Cohend22015c2010-07-26 22:02:18 -0700118 private static final int DEFAULT_CELL_COUNT_X = 4;
119 private static final int DEFAULT_CELL_COUNT_Y = 4;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800120
Romain Guy8a73c512009-11-09 19:19:59 -0800121 private Drawable mPreviousIndicator;
122 private Drawable mNextIndicator;
Winson Chungaafa03c2010-06-11 17:34:16 -0700123
Patrick Dubroy1262e362010-10-06 15:49:50 -0700124 // State variable that indicates whether the pages are small (ie when you're
Michael Jurkadee05892010-07-27 10:01:56 -0700125 // in all apps or customize mode)
126 private boolean mIsSmall;
Patrick Dubroy1262e362010-10-06 15:49:50 -0700127
Chet Haaseb1254a62010-09-07 13:35:00 -0700128 private AnimatorListener mUnshrinkAnimationListener;
Michael Jurkadee05892010-07-27 10:01:56 -0700129
Patrick Dubroy1262e362010-10-06 15:49:50 -0700130 private boolean mInScrollArea = false;
131
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800132 /**
133 * Used to inflate the Workspace from XML.
134 *
135 * @param context The application's context.
Michael Jurka0142d492010-08-25 17:46:15 -0700136 * @param attrs The attributes set containing the Workspace's customization values.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800137 */
138 public Workspace(Context context, AttributeSet attrs) {
139 this(context, attrs, 0);
140 }
141
142 /**
143 * Used to inflate the Workspace from XML.
144 *
145 * @param context The application's context.
Michael Jurka0142d492010-08-25 17:46:15 -0700146 * @param attrs The attributes set containing the Workspace's customization values.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800147 * @param defStyle Unused.
148 */
149 public Workspace(Context context, AttributeSet attrs, int defStyle) {
150 super(context, attrs, defStyle);
Michael Jurka0142d492010-08-25 17:46:15 -0700151 mContentIsRefreshable = false;
Michael Jurka5f1c5092010-09-03 14:15:02 -0700152
153 if (!LauncherApplication.isScreenXLarge()) {
154 mFadeInAdjacentScreens = false;
155 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800156
Dianne Hackborn8f573952009-08-10 23:21:09 -0700157 mWallpaperManager = WallpaperManager.getInstance(context);
Winson Chungaafa03c2010-06-11 17:34:16 -0700158
159 TypedArray a = context.obtainStyledAttributes(attrs,
160 R.styleable.Workspace, defStyle, 0);
Adam Cohend22015c2010-07-26 22:02:18 -0700161 int cellCountX = a.getInt(R.styleable.Workspace_cellCountX, DEFAULT_CELL_COUNT_X);
162 int cellCountY = a.getInt(R.styleable.Workspace_cellCountY, DEFAULT_CELL_COUNT_Y);
Michael Jurka0142d492010-08-25 17:46:15 -0700163 mDefaultPage = a.getInt(R.styleable.Workspace_defaultScreen, 1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800164 a.recycle();
165
Adam Cohend22015c2010-07-26 22:02:18 -0700166 LauncherModel.updateWorkspaceLayoutCells(cellCountX, cellCountY);
Joe Onorato0d44e942009-11-16 18:20:51 -0800167 setHapticFeedbackEnabled(false);
Michael Jurka0142d492010-08-25 17:46:15 -0700168
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800169 initWorkspace();
170 }
171
172 /**
173 * Initializes various states for this workspace.
174 */
Michael Jurka0142d492010-08-25 17:46:15 -0700175 protected void initWorkspace() {
Joe Onorato0589f0f2010-02-08 13:44:00 -0800176 Context context = getContext();
Michael Jurka0142d492010-08-25 17:46:15 -0700177 mCurrentPage = mDefaultPage;
178 Launcher.setScreen(mCurrentPage);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800179 LauncherApplication app = (LauncherApplication)context.getApplicationContext();
180 mIconCache = app.getIconCache();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800181
Chet Haaseb1254a62010-09-07 13:35:00 -0700182 mUnshrinkAnimationListener = new AnimatorListener() {
183 public void onAnimationStart(Animator animation) {}
184 public void onAnimationEnd(Animator animation) {
Michael Jurkadee05892010-07-27 10:01:56 -0700185 mIsSmall = false;
186 }
Chet Haaseb1254a62010-09-07 13:35:00 -0700187 public void onAnimationCancel(Animator animation) {}
188 public void onAnimationRepeat(Animator animation) {}
Michael Jurkadee05892010-07-27 10:01:56 -0700189 };
Michael Jurka0142d492010-08-25 17:46:15 -0700190
191 mSnapVelocity = 600;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800192 }
193
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800194 @Override
Adam Cohenf34bab52010-09-30 14:11:56 -0700195 protected int getScrollMode() {
196 if (LauncherApplication.isScreenXLarge()) {
197 return SmoothPagedView.QUINTIC_MODE;
198 } else {
199 return SmoothPagedView.OVERSHOOT_MODE;
200 }
201 }
202
203 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800204 public void addView(View child, int index, LayoutParams params) {
205 if (!(child instanceof CellLayout)) {
206 throw new IllegalArgumentException("A Workspace can only have CellLayout children.");
207 }
208 super.addView(child, index, params);
209 }
210
211 @Override
212 public void addView(View child) {
213 if (!(child instanceof CellLayout)) {
214 throw new IllegalArgumentException("A Workspace can only have CellLayout children.");
215 }
216 super.addView(child);
217 }
218
219 @Override
220 public void addView(View child, int index) {
221 if (!(child instanceof CellLayout)) {
222 throw new IllegalArgumentException("A Workspace can only have CellLayout children.");
223 }
224 super.addView(child, index);
225 }
226
227 @Override
228 public void addView(View child, int width, int height) {
229 if (!(child instanceof CellLayout)) {
230 throw new IllegalArgumentException("A Workspace can only have CellLayout children.");
231 }
232 super.addView(child, width, height);
233 }
234
235 @Override
236 public void addView(View child, LayoutParams params) {
237 if (!(child instanceof CellLayout)) {
238 throw new IllegalArgumentException("A Workspace can only have CellLayout children.");
239 }
240 super.addView(child, params);
241 }
242
243 /**
244 * @return The open folder on the current screen, or null if there is none
245 */
246 Folder getOpenFolder() {
Michael Jurka0142d492010-08-25 17:46:15 -0700247 CellLayout currentPage = (CellLayout) getChildAt(mCurrentPage);
248 int count = currentPage.getChildCount();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800249 for (int i = 0; i < count; i++) {
Michael Jurka0142d492010-08-25 17:46:15 -0700250 View child = currentPage.getChildAt(i);
Winson Chungaafa03c2010-06-11 17:34:16 -0700251 if (child instanceof Folder) {
252 Folder folder = (Folder) child;
253 if (folder.getInfo().opened)
254 return folder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800255 }
256 }
257 return null;
258 }
259
260 ArrayList<Folder> getOpenFolders() {
Michael Jurkadee05892010-07-27 10:01:56 -0700261 final int screenCount = getChildCount();
262 ArrayList<Folder> folders = new ArrayList<Folder>(screenCount);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800263
Michael Jurkadee05892010-07-27 10:01:56 -0700264 for (int screen = 0; screen < screenCount; screen++) {
Michael Jurka0142d492010-08-25 17:46:15 -0700265 CellLayout currentPage = (CellLayout) getChildAt(screen);
266 int count = currentPage.getChildCount();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800267 for (int i = 0; i < count; i++) {
Michael Jurka0142d492010-08-25 17:46:15 -0700268 View child = currentPage.getChildAt(i);
Winson Chungaafa03c2010-06-11 17:34:16 -0700269 if (child instanceof Folder) {
270 Folder folder = (Folder) child;
271 if (folder.getInfo().opened)
272 folders.add(folder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800273 break;
274 }
275 }
276 }
277
278 return folders;
279 }
280
Michael Jurka0142d492010-08-25 17:46:15 -0700281 boolean isDefaultPageShowing() {
282 return mCurrentPage == mDefaultPage;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800283 }
284
285 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800286 * Sets the current screen.
287 *
Michael Jurka0142d492010-08-25 17:46:15 -0700288 * @param currentPage
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800289 */
Michael Jurka0142d492010-08-25 17:46:15 -0700290 @Override
291 void setCurrentPage(int currentPage) {
292 super.setCurrentPage(currentPage);
293 updateWallpaperOffset(mScrollX);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800294 }
295
296 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800297 * Adds the specified child in the specified screen. The position and dimension of
298 * the child are defined by x, y, spanX and spanY.
299 *
300 * @param child The child to add in one of the workspace's screens.
301 * @param screen The screen in which to add the child.
302 * @param x The X position of the child in the screen's grid.
303 * @param y The Y position of the child in the screen's grid.
304 * @param spanX The number of cells spanned horizontally by the child.
305 * @param spanY The number of cells spanned vertically by the child.
306 */
307 void addInScreen(View child, int screen, int x, int y, int spanX, int spanY) {
308 addInScreen(child, screen, x, y, spanX, spanY, false);
309 }
310
Winson Chungaafa03c2010-06-11 17:34:16 -0700311 void addInFullScreen(View child, int screen) {
312 addInScreen(child, screen, 0, 0, -1, -1);
313 }
314
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800315 /**
316 * Adds the specified child in the specified screen. The position and dimension of
317 * the child are defined by x, y, spanX and spanY.
318 *
319 * @param child The child to add in one of the workspace's screens.
320 * @param screen The screen in which to add the child.
321 * @param x The X position of the child in the screen's grid.
322 * @param y The Y position of the child in the screen's grid.
323 * @param spanX The number of cells spanned horizontally by the child.
324 * @param spanY The number of cells spanned vertically by the child.
325 * @param insert When true, the child is inserted at the beginning of the children list.
326 */
327 void addInScreen(View child, int screen, int x, int y, int spanX, int spanY, boolean insert) {
328 if (screen < 0 || screen >= getChildCount()) {
Daniel Sandler291ad122010-05-24 16:03:53 -0400329 Log.e(TAG, "The screen must be >= 0 and < " + getChildCount()
330 + " (was " + screen + "); skipping child");
331 return;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800332 }
333
334 final CellLayout group = (CellLayout) getChildAt(screen);
335 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
336 if (lp == null) {
337 lp = new CellLayout.LayoutParams(x, y, spanX, spanY);
338 } else {
339 lp.cellX = x;
340 lp.cellY = y;
341 lp.cellHSpan = spanX;
342 lp.cellVSpan = spanY;
343 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700344
Patrick Dubroy6569f2c2010-07-12 14:25:18 -0700345 // Get the canonical child id to uniquely represent this view in this screen
Michael Jurka845ba3b2010-09-28 17:09:46 -0700346 int childId = LauncherModel.getCellLayoutChildId(-1, screen, x, y, spanX, spanY);
Winson Chungaafa03c2010-06-11 17:34:16 -0700347 if (!group.addViewToCellLayout(child, insert ? 0 : -1, childId, lp)) {
348 // TODO: This branch occurs when the workspace is adding views
349 // outside of the defined grid
Patrick Dubroy6569f2c2010-07-12 14:25:18 -0700350 // maybe we should be deleting these items from the LauncherModel?
Winson Chungaafa03c2010-06-11 17:34:16 -0700351 Log.w(TAG, "Failed to add to item at (" + lp.cellX + "," + lp.cellY + ") to CellLayout");
352 }
353
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800354 if (!(child instanceof Folder)) {
Joe Onorato0d44e942009-11-16 18:20:51 -0800355 child.setHapticFeedbackEnabled(false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800356 child.setOnLongClickListener(mLongClickListener);
357 }
Joe Onorato00acb122009-08-04 16:04:30 -0400358 if (child instanceof DropTarget) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700359 mDragController.addDropTarget((DropTarget) child);
Joe Onorato00acb122009-08-04 16:04:30 -0400360 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800361 }
362
Michael Jurkadee05892010-07-27 10:01:56 -0700363 public boolean onTouch(View v, MotionEvent event) {
364 // this is an intercepted event being forwarded from a cell layout
365 if (mIsSmall) {
Patrick Dubroy2b9ff372010-09-07 17:49:27 -0700366 mLauncher.onWorkspaceClick((CellLayout) v);
Michael Jurka96226222010-08-20 00:54:40 -0700367 return true;
Michael Jurkadee05892010-07-27 10:01:56 -0700368 }
369 return false;
Michael Jurka0e260592010-06-30 17:07:39 -0700370 }
371
Michael Jurka5f1c5092010-09-03 14:15:02 -0700372 @Override
373 public boolean dispatchUnhandledMove(View focused, int direction) {
374 if (mIsSmall) {
375 // when the home screens are shrunken, shouldn't allow side-scrolling
376 return false;
377 }
378 return super.dispatchUnhandledMove(focused, direction);
379 }
380
381 @Override
382 public boolean onInterceptTouchEvent(MotionEvent ev) {
383 if (mIsSmall) {
384 // when the home screens are shrunken, shouldn't allow side-scrolling
385 return false;
386 }
387 return super.onInterceptTouchEvent(ev);
388 }
389
Patrick Dubroy1262e362010-10-06 15:49:50 -0700390 protected void onPageBeginMoving() {
Michael Jurka0142d492010-08-25 17:46:15 -0700391 if (mNextPage != INVALID_PAGE) {
392 // we're snapping to a particular screen
Michael Jurka16fed412010-10-01 16:12:03 -0700393 enableChildrenCache(mCurrentPage, mNextPage);
Michael Jurka0142d492010-08-25 17:46:15 -0700394 } else {
395 // this is when user is actively dragging a particular screen, they might
396 // swipe it either left or right (but we won't advance by more than one screen)
Michael Jurka16fed412010-10-01 16:12:03 -0700397 enableChildrenCache(mCurrentPage - 1, mCurrentPage + 1);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800398 }
Adam Cohenf34bab52010-09-30 14:11:56 -0700399 showOutlines();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800400 }
401
Patrick Dubroy1262e362010-10-06 15:49:50 -0700402 protected void onPageEndMoving() {
Michael Jurka16fed412010-10-01 16:12:03 -0700403 clearChildrenCache();
Patrick Dubroy1262e362010-10-06 15:49:50 -0700404
405 // Hide the outlines, as long as we're not dragging
406 if (!mDragController.dragging()) {
407 hideOutlines();
408 }
Michael Jurka0142d492010-08-25 17:46:15 -0700409 }
410
411 @Override
412 protected void notifyPageSwitchListener() {
413 super.notifyPageSwitchListener();
414
415 if (mPreviousIndicator != null) {
416 // if we know the next page, we show the indication for it right away; it looks
417 // weird if the indicators are lagging
418 int page = mNextPage;
419 if (page == INVALID_PAGE) {
420 page = mCurrentPage;
421 }
422 mPreviousIndicator.setLevel(page);
423 mNextIndicator.setLevel(page);
424 }
425 Launcher.setScreen(mCurrentPage);
426 };
427
Dianne Hackborn8f573952009-08-10 23:21:09 -0700428 private void updateWallpaperOffset() {
Romain Guy798300c2009-08-11 14:43:29 -0700429 updateWallpaperOffset(getChildAt(getChildCount() - 1).getRight() - (mRight - mLeft));
430 }
431
432 private void updateWallpaperOffset(int scrollRange) {
Winson Chung86f77532010-08-24 11:08:22 -0700433 final boolean isStaticWallpaper = (mWallpaperManager != null) &&
434 (mWallpaperManager.getWallpaperInfo() == null);
435 if (LauncherApplication.isScreenXLarge() && !isStaticWallpaper) {
436 IBinder token = getWindowToken();
437 if (token != null) {
438 mWallpaperManager.setWallpaperOffsetSteps(1.0f / (getChildCount() - 1), 0 );
439 mWallpaperManager.setWallpaperOffsets(getWindowToken(),
440 Math.max(0.f, Math.min(mScrollX/(float)scrollRange, 1.f)), 0);
441 }
Joe Onorato956091b2010-02-19 12:47:40 -0800442 }
Dianne Hackborn8f573952009-08-10 23:21:09 -0700443 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700444
Adam Cohenf34bab52010-09-30 14:11:56 -0700445 private float getScaleXForRotation(float degrees) {
446 return (float) (1.0f / Math.cos(Math.PI * degrees / 180.0f));
447 }
448
449 public void showOutlines() {
450 if (mBackgroundFadeOut != null) mBackgroundFadeOut.cancel();
451 if (mBackgroundFadeIn != null) mBackgroundFadeIn.cancel();
452 mBackgroundFadeIn = new ObjectAnimator<Float>(BACKGROUND_FADE_IN_DURATION, this,
453 new PropertyValuesHolder<Float>("backgroundAlpha", 1.0f));
454 mBackgroundFadeIn.start();
455 }
456
457 public void hideOutlines() {
458 if (mBackgroundFadeIn != null) mBackgroundFadeIn.cancel();
459 if (mBackgroundFadeOut != null) mBackgroundFadeOut.cancel();
460 mBackgroundFadeOut = new ObjectAnimator<Float>(BACKGROUND_FADE_OUT_DURATION, this,
461 new PropertyValuesHolder<Float>("backgroundAlpha", 0.0f));
462 mBackgroundFadeOut.setStartDelay(BACKGROUND_FADE_OUT_DELAY);
463 mBackgroundFadeOut.start();
464 }
465
466 public void setBackgroundAlpha(float alpha) {
467 mBackgroundAlpha = alpha;
468 for (int i = 0; i < getChildCount(); i++) {
469 CellLayout cl = (CellLayout) getChildAt(i);
470 cl.setBackgroundAlpha(alpha);
471 }
472 }
473
474 public float getBackgroundAlpha() {
475 return mBackgroundAlpha;
476 }
477
478 @Override
479 protected void screenScrolled(int screenCenter) {
Adam Cohen9c4949e2010-10-05 12:27:22 -0700480 CellLayout cur = (CellLayout) getChildAt(mCurrentPage);
481 CellLayout toRight = (CellLayout) getChildAt(mCurrentPage + 1);
482 CellLayout toLeft = (CellLayout) getChildAt(mCurrentPage - 1);
Adam Cohenf34bab52010-09-30 14:11:56 -0700483
484 for (int i = 0; i < mCurrentPage - 1; i++) {
485 View v = getChildAt(i);
486 if (v != null) {
487 v.setRotationY(WORKSPACE_ROTATION);
488 v.setScaleX(getScaleXForRotation(WORKSPACE_ROTATION));
489 }
490 }
491 for (int i = mCurrentPage + 1; i < getChildCount(); i++) {
492 View v = getChildAt(i);
493 if (v != null) {
494 v.setRotationY(-WORKSPACE_ROTATION);
495 v.setScaleX(getScaleXForRotation(-WORKSPACE_ROTATION));
496 }
497 }
498
Adam Cohen9c4949e2010-10-05 12:27:22 -0700499 int halfScreenSize = getMeasuredWidth() / 2;
Adam Cohenf34bab52010-09-30 14:11:56 -0700500 int pageWidth = cur.getMeasuredWidth();
Adam Cohen9c4949e2010-10-05 12:27:22 -0700501 int delta = screenCenter - (getChildOffset(mCurrentPage) -
502 getRelativeChildOffset(mCurrentPage) + halfScreenSize);
Adam Cohenf34bab52010-09-30 14:11:56 -0700503
Adam Cohen9c4949e2010-10-05 12:27:22 -0700504 float scrollProgress = Math.abs(delta/(pageWidth*1.0f + mPageSpacing));
Patrick Dubroy1262e362010-10-06 15:49:50 -0700505 boolean scrollRight = (delta <= 0);
Adam Cohenf34bab52010-09-30 14:11:56 -0700506
507 float rotation;
508
Patrick Dubroy1262e362010-10-06 15:49:50 -0700509 if (scrollRight) {
Adam Cohenf34bab52010-09-30 14:11:56 -0700510 rotation = -scrollProgress * WORKSPACE_ROTATION;
511 cur.setRotationY(rotation);
512 cur.setScaleX(getScaleXForRotation(rotation));
Adam Cohen9c4949e2010-10-05 12:27:22 -0700513
Adam Cohenf34bab52010-09-30 14:11:56 -0700514 if (toLeft != null) {
515 rotation = WORKSPACE_ROTATION * (1 - scrollProgress);
516 toLeft.setRotationY(rotation);
517 toLeft.setScaleX(getScaleXForRotation(rotation));
518 }
519 if (toRight != null) {
520 toRight.setRotationY(-WORKSPACE_ROTATION);
521 toRight.setScaleX(getScaleXForRotation(WORKSPACE_ROTATION));
522 }
523 } else {
524 rotation = scrollProgress * WORKSPACE_ROTATION;
525 cur.setRotationY(rotation);
526 cur.setScaleX(getScaleXForRotation(rotation));
527
528 if (toRight != null) {
529 rotation = -WORKSPACE_ROTATION * (1 - scrollProgress);
530 toRight.setRotationY(rotation);
531 toRight.setScaleX(getScaleXForRotation(rotation));
532 }
533 if (toLeft != null) {
534 toLeft.setRotationY(WORKSPACE_ROTATION);
535 toLeft.setScaleX(getScaleXForRotation(WORKSPACE_ROTATION));
536 }
537 }
538 }
539
Joe Onorato00acb122009-08-04 16:04:30 -0400540 protected void onAttachedToWindow() {
541 super.onAttachedToWindow();
Joe Onorato956091b2010-02-19 12:47:40 -0800542 computeScroll();
Joe Onorato00acb122009-08-04 16:04:30 -0400543 mDragController.setWindowToken(getWindowToken());
544 }
545
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800546 @Override
Michael Jurka28750fb2010-09-24 17:43:49 -0700547 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
Michael Jurka0142d492010-08-25 17:46:15 -0700548 super.onLayout(changed, left, top, right, bottom);
Winson Chungaafa03c2010-06-11 17:34:16 -0700549
Michael Jurka79212d82010-07-30 16:36:20 -0700550 // if shrinkToBottom() is called on initialization, it has to be deferred
551 // until after the first call to onLayout so that it has the correct width
552 if (mWaitingToShrinkToBottom) {
553 shrinkToBottom(false);
554 mWaitingToShrinkToBottom = false;
555 }
556
Winson Chungaafa03c2010-06-11 17:34:16 -0700557 if (LauncherApplication.isInPlaceRotationEnabled()) {
558 // When the device is rotated, the scroll position of the current screen
559 // needs to be refreshed
Michael Jurka0142d492010-08-25 17:46:15 -0700560 setCurrentPage(getCurrentPage());
Winson Chungaafa03c2010-06-11 17:34:16 -0700561 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800562 }
563
564 @Override
Michael Jurka0142d492010-08-25 17:46:15 -0700565 protected void dispatchDraw(Canvas canvas) {
566 if (mIsSmall) {
567 // Draw all the workspaces if we're small
568 final int pageCount = getChildCount();
569 final long drawingTime = getDrawingTime();
570 for (int i = 0; i < pageCount; i++) {
571 final View page = (View) getChildAt(i);
572
Michael Jurka0142d492010-08-25 17:46:15 -0700573 drawChild(canvas, page, drawingTime);
574 }
575 } else {
576 super.dispatchDraw(canvas);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800577 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800578 }
579
580 @Override
581 protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {
Joe Onorato67886212009-09-14 19:05:05 -0400582 if (!mLauncher.isAllAppsVisible()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800583 final Folder openFolder = getOpenFolder();
584 if (openFolder != null) {
585 return openFolder.requestFocus(direction, previouslyFocusedRect);
586 } else {
Michael Jurka0142d492010-08-25 17:46:15 -0700587 return super.onRequestFocusInDescendants(direction, previouslyFocusedRect);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800588 }
589 }
590 return false;
591 }
592
593 @Override
Romain Guyc2e24c02009-06-01 16:11:41 -0700594 public void addFocusables(ArrayList<View> views, int direction, int focusableMode) {
Joe Onorato67886212009-09-14 19:05:05 -0400595 if (!mLauncher.isAllAppsVisible()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800596 final Folder openFolder = getOpenFolder();
Michael Jurka0142d492010-08-25 17:46:15 -0700597 if (openFolder != null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800598 openFolder.addFocusables(views, direction);
Michael Jurka0142d492010-08-25 17:46:15 -0700599 } else {
600 super.addFocusables(views, direction, focusableMode);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800601 }
602 }
603 }
604
605 @Override
Joe Onorato7bb17492009-09-24 17:51:01 -0700606 public boolean dispatchTouchEvent(MotionEvent ev) {
607 if (ev.getAction() == MotionEvent.ACTION_DOWN) {
Michael Jurka54dd7542010-07-30 14:47:52 -0700608 // (In XLarge mode, the workspace is shrunken below all apps, and responds to taps
609 // ie when you click on a mini-screen, it zooms back to that screen)
Joe Onorato6b4adbc2010-09-01 12:13:25 -0700610 if (!LauncherApplication.isScreenXLarge() && mLauncher.isAllAppsVisible()) {
Joe Onorato7bb17492009-09-24 17:51:01 -0700611 return false;
612 }
613 }
614 return super.dispatchTouchEvent(ev);
615 }
616
Michael Jurka0142d492010-08-25 17:46:15 -0700617 void enableChildrenCache(int fromPage, int toPage) {
618 if (fromPage > toPage) {
619 final int temp = fromPage;
620 fromPage = toPage;
621 toPage = temp;
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800622 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700623
Michael Jurkadee05892010-07-27 10:01:56 -0700624 final int screenCount = getChildCount();
Adam Powellfea5d022010-04-29 11:42:45 -0700625
Michael Jurka0142d492010-08-25 17:46:15 -0700626 fromPage = Math.max(fromPage, 0);
627 toPage = Math.min(toPage, screenCount - 1);
Adam Powellfea5d022010-04-29 11:42:45 -0700628
Michael Jurka0142d492010-08-25 17:46:15 -0700629 for (int i = fromPage; i <= toPage; i++) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800630 final CellLayout layout = (CellLayout) getChildAt(i);
631 layout.setChildrenDrawnWithCacheEnabled(true);
632 layout.setChildrenDrawingCacheEnabled(true);
633 }
634 }
635
636 void clearChildrenCache() {
Michael Jurkadee05892010-07-27 10:01:56 -0700637 final int screenCount = getChildCount();
638 for (int i = 0; i < screenCount; i++) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800639 final CellLayout layout = (CellLayout) getChildAt(i);
640 layout.setChildrenDrawnWithCacheEnabled(false);
641 }
642 }
643
644 @Override
645 public boolean onTouchEvent(MotionEvent ev) {
Joe Onorato2bc6b7c2009-10-01 14:08:30 -0700646 if (mLauncher.isAllAppsVisible()) {
647 // Cancel any scrolling that is in progress.
648 if (!mScroller.isFinished()) {
649 mScroller.abortAnimation();
650 }
Michael Jurka0142d492010-08-25 17:46:15 -0700651 snapToPage(mCurrentPage);
Joe Onorato7c312c12009-08-13 21:36:53 -0700652 return false; // We don't want the events. Let them fall through to the all apps view.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800653 }
654
Michael Jurka0142d492010-08-25 17:46:15 -0700655 return super.onTouchEvent(ev);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800656 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700657
Michael Jurka01f0ed42010-08-20 00:41:17 -0700658 public boolean isSmall() {
659 return mIsSmall;
660 }
661
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700662 void shrinkToTop(boolean animated) {
Michael Jurka0142d492010-08-25 17:46:15 -0700663 shrink(ShrinkPosition.SHRINK_TO_TOP, animated);
Michael Jurka01f0ed42010-08-20 00:41:17 -0700664 }
665
666 void shrinkToMiddle() {
Michael Jurka0142d492010-08-25 17:46:15 -0700667 shrink(ShrinkPosition.SHRINK_TO_MIDDLE, true);
Michael Jurka213d9632010-07-28 11:29:25 -0700668 }
669
670 void shrinkToBottom() {
Michael Jurka79212d82010-07-30 16:36:20 -0700671 shrinkToBottom(true);
672 }
673
674 void shrinkToBottom(boolean animated) {
675 if (mFirstLayout) {
676 // (mFirstLayout == "first layout has not happened yet")
677 // if we get a call to shrink() as part of our initialization (for example, if
678 // Launcher is started in All Apps mode) then we need to wait for a layout call
679 // to get our width so we can layout the mini-screen views correctly
680 mWaitingToShrinkToBottom = true;
681 } else {
Michael Jurka0142d492010-08-25 17:46:15 -0700682 shrink(ShrinkPosition.SHRINK_TO_BOTTOM, animated);
Michael Jurka79212d82010-07-30 16:36:20 -0700683 }
Michael Jurka213d9632010-07-28 11:29:25 -0700684 }
685
Adam Cohena985e592010-09-09 11:23:48 -0700686 private float getYScaleForScreen(int screen) {
687 int x = Math.abs(screen - 2);
688
689 // TODO: This should be generalized for use with arbitrary rotation angles.
690 switch(x) {
691 case 0: return EXTRA_SCALE_FACTOR_0;
692 case 1: return EXTRA_SCALE_FACTOR_1;
693 case 2: return EXTRA_SCALE_FACTOR_2;
694 }
695 return 1.0f;
696 }
697
Michael Jurkadee05892010-07-27 10:01:56 -0700698 // we use this to shrink the workspace for the all apps view and the customize view
Michael Jurka0142d492010-08-25 17:46:15 -0700699 private void shrink(ShrinkPosition shrinkPosition, boolean animated) {
Michael Jurkadee05892010-07-27 10:01:56 -0700700 mIsSmall = true;
Michael Jurka5f1c5092010-09-03 14:15:02 -0700701 // we intercept and reject all touch events when we're small, so be sure to reset the state
702 mTouchState = TOUCH_STATE_REST;
703 mActivePointerId = INVALID_POINTER;
704
Patrick Dubroy7247f632010-08-04 16:02:59 -0700705 final Resources res = getResources();
Michael Jurkadee05892010-07-27 10:01:56 -0700706 final int screenWidth = getWidth();
Michael Jurka213d9632010-07-28 11:29:25 -0700707 final int screenHeight = getHeight();
Michael Jurka0142d492010-08-25 17:46:15 -0700708
709 // Making the assumption that all pages have the same width as the 0th
710 final int pageWidth = getChildAt(0).getMeasuredWidth();
711 final int pageHeight = getChildAt(0).getMeasuredHeight();
712
713 final int scaledPageWidth = (int) (SHRINK_FACTOR * pageWidth);
714 final int scaledPageHeight = (int) (SHRINK_FACTOR * pageHeight);
Adam Cohena985e592010-09-09 11:23:48 -0700715 final float extraScaledSpacing = res.getDimension(R.dimen.smallScreenExtraSpacing);
Michael Jurkadee05892010-07-27 10:01:56 -0700716
717 final int screenCount = getChildCount();
Adam Cohena985e592010-09-09 11:23:48 -0700718 float totalWidth = screenCount * scaledPageWidth + (screenCount - 1) * extraScaledSpacing;
Michael Jurka213d9632010-07-28 11:29:25 -0700719
720 float newY = getResources().getDimension(R.dimen.smallScreenVerticalMargin);
Michael Jurka0142d492010-08-25 17:46:15 -0700721 if (shrinkPosition == ShrinkPosition.SHRINK_TO_BOTTOM) {
722 newY = screenHeight - newY - scaledPageHeight;
723 } else if (shrinkPosition == ShrinkPosition.SHRINK_TO_MIDDLE) {
724 newY = screenHeight / 2 - scaledPageHeight / 2;
Michael Jurka213d9632010-07-28 11:29:25 -0700725 }
Michael Jurkadee05892010-07-27 10:01:56 -0700726
727 // We animate all the screens to the centered position in workspace
728 // At the same time, the screens become greyed/dimmed
729
730 // newX is initialized to the left-most position of the centered screens
Michael Jurka0142d492010-08-25 17:46:15 -0700731 float newX = mScroller.getFinalX() + screenWidth / 2 - totalWidth / 2;
Adam Cohena985e592010-09-09 11:23:48 -0700732
733 // We are going to scale about the center of the view, so we need to adjust the positions
734 // of the views accordingly
735 newX -= (pageWidth - scaledPageWidth) / 2.0f;
736 newY -= (pageHeight - scaledPageHeight) / 2.0f;
Michael Jurkadee05892010-07-27 10:01:56 -0700737 for (int i = 0; i < screenCount; i++) {
738 CellLayout cl = (CellLayout) getChildAt(i);
Adam Cohena985e592010-09-09 11:23:48 -0700739
Adam Cohenf34bab52010-09-30 14:11:56 -0700740 float rotation = (-i + 2) * WORKSPACE_ROTATION;
Adam Cohena985e592010-09-09 11:23:48 -0700741 float rotationScaleX = (float) (1.0f / Math.cos(Math.PI * rotation / 180.0f));
742 float rotationScaleY = getYScaleForScreen(i);
743
Michael Jurka79212d82010-07-30 16:36:20 -0700744 if (animated) {
Patrick Dubroy7247f632010-08-04 16:02:59 -0700745 final int duration = res.getInteger(R.integer.config_workspaceShrinkTime);
Michael Jurka5f1c5092010-09-03 14:15:02 -0700746 new ObjectAnimator<Float>(duration, cl,
747 new PropertyValuesHolder<Float>("x", newX),
748 new PropertyValuesHolder<Float>("y", newY),
Adam Cohene54cec82010-09-13 18:19:55 -0700749 new PropertyValuesHolder<Float>("scaleX", SHRINK_FACTOR * rotationScaleX),
750 new PropertyValuesHolder<Float>("scaleY", SHRINK_FACTOR * rotationScaleY),
Michael Jurka5f1c5092010-09-03 14:15:02 -0700751 new PropertyValuesHolder<Float>("backgroundAlpha", 1.0f),
Michael Jurka16fed412010-10-01 16:12:03 -0700752 new PropertyValuesHolder<Float>("alpha", 1.0f),
Michael Jurka5f1c5092010-09-03 14:15:02 -0700753 new PropertyValuesHolder<Float>("rotationY", rotation)).start();
Michael Jurka79212d82010-07-30 16:36:20 -0700754 } else {
755 cl.setX((int)newX);
756 cl.setY((int)newY);
Adam Cohenf34bab52010-09-30 14:11:56 -0700757 cl.setScaleX(SHRINK_FACTOR * rotationScaleX);
758 cl.setScaleY(SHRINK_FACTOR * rotationScaleY);
Michael Jurka5f1c5092010-09-03 14:15:02 -0700759 cl.setBackgroundAlpha(1.0f);
760 cl.setAlpha(0.0f);
Adam Cohena985e592010-09-09 11:23:48 -0700761 cl.setRotationY(rotation);
Michael Jurka79212d82010-07-30 16:36:20 -0700762 }
Michael Jurkadee05892010-07-27 10:01:56 -0700763 // increment newX for the next screen
Adam Cohena985e592010-09-09 11:23:48 -0700764 newX += scaledPageWidth + extraScaledSpacing;
Michael Jurkadee05892010-07-27 10:01:56 -0700765 cl.setOnInterceptTouchListener(this);
766 }
767 setChildrenDrawnWithCacheEnabled(true);
Michael Jurkadee05892010-07-27 10:01:56 -0700768 }
769
770 // We call this when we trigger an unshrink by clicking on the CellLayout cl
Patrick Dubroy2b9ff372010-09-07 17:49:27 -0700771 public void unshrink(CellLayout clThatWasClicked) {
Michael Jurka0142d492010-08-25 17:46:15 -0700772 int newCurrentPage = mCurrentPage;
Michael Jurka4cb37242010-08-09 21:05:32 -0700773 final int screenCount = getChildCount();
774 for (int i = 0; i < screenCount; i++) {
775 if (getChildAt(i) == clThatWasClicked) {
Michael Jurka0142d492010-08-25 17:46:15 -0700776 newCurrentPage = i;
Michael Jurkadee05892010-07-27 10:01:56 -0700777 }
Michael Jurka4cb37242010-08-09 21:05:32 -0700778 }
Michael Jurka0142d492010-08-25 17:46:15 -0700779 unshrink(newCurrentPage);
Michael Jurka4cb37242010-08-09 21:05:32 -0700780 }
781
Michael Jurka0142d492010-08-25 17:46:15 -0700782 private void unshrink(int newCurrentPage) {
Michael Jurka4cb37242010-08-09 21:05:32 -0700783 if (mIsSmall) {
Michael Jurka5f1c5092010-09-03 14:15:02 -0700784 int newX = getChildOffset(newCurrentPage) - getRelativeChildOffset(newCurrentPage);
785 int delta = newX - mScrollX;
Michael Jurka4cb37242010-08-09 21:05:32 -0700786
787 final int screenCount = getChildCount();
Michael Jurkab0f28bd2010-07-30 11:58:59 -0700788 for (int i = 0; i < screenCount; i++) {
789 CellLayout cl = (CellLayout) getChildAt(i);
790 cl.setX(cl.getX() + delta);
791 }
Michael Jurka0142d492010-08-25 17:46:15 -0700792 snapToPage(newCurrentPage);
Michael Jurkab0f28bd2010-07-30 11:58:59 -0700793 unshrink();
Michael Jurka0142d492010-08-25 17:46:15 -0700794
795 setCurrentPage(newCurrentPage);
Michael Jurkab0f28bd2010-07-30 11:58:59 -0700796 }
Michael Jurkadee05892010-07-27 10:01:56 -0700797 }
798
Michael Jurka4cb37242010-08-09 21:05:32 -0700799 void unshrink() {
800 unshrink(true);
801 }
802
803 void unshrink(boolean animated) {
Michael Jurkab0f28bd2010-07-30 11:58:59 -0700804 if (mIsSmall) {
Chet Haaseb1254a62010-09-07 13:35:00 -0700805 AnimatorSet s = new AnimatorSet();
Michael Jurkab0f28bd2010-07-30 11:58:59 -0700806 final int screenCount = getChildCount();
Michael Jurka4cb37242010-08-09 21:05:32 -0700807
808 final int duration = getResources().getInteger(R.integer.config_workspaceUnshrinkTime);
Michael Jurkab0f28bd2010-07-30 11:58:59 -0700809 for (int i = 0; i < screenCount; i++) {
Patrick Dubroy7247f632010-08-04 16:02:59 -0700810 final CellLayout cl = (CellLayout)getChildAt(i);
Michael Jurka5f1c5092010-09-03 14:15:02 -0700811 float finalAlphaValue = (i == mCurrentPage) ? 1.0f : 0.0f;
Adam Cohenf34bab52010-09-30 14:11:56 -0700812 float rotation = 0.0f;
813
814 if (i < mCurrentPage) {
815 rotation = WORKSPACE_ROTATION;
816 } else if (i > mCurrentPage) {
817 rotation = -WORKSPACE_ROTATION;
818 }
819
Michael Jurka4cb37242010-08-09 21:05:32 -0700820 if (animated) {
821 s.playTogether(
Chet Haaseb1254a62010-09-07 13:35:00 -0700822 new ObjectAnimator<Float>(duration, cl, "translationX", 0.0f),
823 new ObjectAnimator<Float>(duration, cl, "translationY", 0.0f),
824 new ObjectAnimator<Float>(duration, cl, "scaleX", 1.0f),
825 new ObjectAnimator<Float>(duration, cl, "scaleY", 1.0f),
Michael Jurka5f1c5092010-09-03 14:15:02 -0700826 new ObjectAnimator<Float>(duration, cl, "backgroundAlpha", 0.0f),
827 new ObjectAnimator<Float>(duration, cl, "alpha", finalAlphaValue),
Adam Cohenf34bab52010-09-30 14:11:56 -0700828 new ObjectAnimator<Float>(duration, cl, "rotationY", rotation));
Michael Jurka4cb37242010-08-09 21:05:32 -0700829 } else {
830 cl.setTranslationX(0.0f);
831 cl.setTranslationY(0.0f);
832 cl.setScaleX(1.0f);
833 cl.setScaleY(1.0f);
Michael Jurka5f1c5092010-09-03 14:15:02 -0700834 cl.setBackgroundAlpha(0.0f);
Adam Cohenf34bab52010-09-30 14:11:56 -0700835 cl.setAlpha(finalAlphaValue);
836 cl.setRotationY(rotation);
Michael Jurka4cb37242010-08-09 21:05:32 -0700837 }
Michael Jurkab0f28bd2010-07-30 11:58:59 -0700838 }
839 s.addListener(mUnshrinkAnimationListener);
840 s.start();
Michael Jurkadee05892010-07-27 10:01:56 -0700841 }
Michael Jurkadee05892010-07-27 10:01:56 -0700842 }
843
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800844 void startDrag(CellLayout.CellInfo cellInfo) {
845 View child = cellInfo.cell;
Winson Chungaafa03c2010-06-11 17:34:16 -0700846
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800847 // Make sure the drag was started by a long press as opposed to a long click.
Bjorn Bringert7984c942009-12-09 15:38:25 +0000848 if (!child.isInTouchMode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800849 return;
850 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700851
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800852 mDragInfo = cellInfo;
Michael Jurka0142d492010-08-25 17:46:15 -0700853 mDragInfo.screen = mCurrentPage;
Winson Chungaafa03c2010-06-11 17:34:16 -0700854
Michael Jurka0142d492010-08-25 17:46:15 -0700855 CellLayout current = ((CellLayout) getChildAt(mCurrentPage));
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800856
857 current.onDragChild(child);
Joe Onorato00acb122009-08-04 16:04:30 -0400858 mDragController.startDrag(child, this, child.getTag(), DragController.DRAG_ACTION_MOVE);
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700859 current.onDragEnter(child);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800860 invalidate();
861 }
862
Michael Jurka0280c3b2010-09-17 15:00:07 -0700863 void addApplicationShortcut(ShortcutInfo info, int screen, int cellX, int cellY,
864 boolean insertAtFirst, int intersectX, int intersectY) {
865 final CellLayout cellLayout = (CellLayout) getChildAt(screen);
866 View view = mLauncher.createShortcut(R.layout.application, cellLayout, (ShortcutInfo) info);
867
868 final int[] cellXY = new int[2];
869 cellLayout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectX, intersectY);
870 addInScreen(view, screen, cellXY[0], cellXY[1], 1, 1, insertAtFirst);
871 LauncherModel.addOrMoveItemInDatabase(mLauncher, info,
872 LauncherSettings.Favorites.CONTAINER_DESKTOP, screen,
873 cellXY[0], cellXY[1]);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800874 }
875
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800876
Joe Onorato00acb122009-08-04 16:04:30 -0400877 public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
878 DragView dragView, Object dragInfo) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700879 CellLayout cellLayout;
Michael Jurkaa63c4522010-08-19 13:52:27 -0700880 int originX = x - xOffset;
881 int originY = y - yOffset;
882 if (mIsSmall) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700883 cellLayout = findMatchingPageForDragOver(dragView, originX, originY);
Michael Jurkaa63c4522010-08-19 13:52:27 -0700884 if (cellLayout == null) {
885 // cancel the drag if we're not over a mini-screen at time of drop
886 // TODO: maybe add a nice fade here?
887 return;
888 }
Michael Jurka0280c3b2010-09-17 15:00:07 -0700889 // get originX and originY in the local coordinate system of the screen
890 mTempOriginXY[0] = originX;
891 mTempOriginXY[1] = originY;
892 mapPointGlobalToLocal(cellLayout, mTempOriginXY);
893 originX = (int)mTempOriginXY[0];
894 originY = (int)mTempOriginXY[1];
895 } else {
896 cellLayout = getCurrentDropLayout();
Michael Jurkaa63c4522010-08-19 13:52:27 -0700897 }
Michael Jurkac6ee42e2010-09-30 12:04:50 -0700898
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800899 if (source != this) {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700900 onDropExternal(originX, originY, dragInfo, cellLayout);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800901 } else {
902 // Move internally
903 if (mDragInfo != null) {
904 final View cell = mDragInfo.cell;
Michael Jurkaa63c4522010-08-19 13:52:27 -0700905
Michael Jurka6a1435d2010-09-27 17:35:12 -0700906 mTargetCell = findNearestVacantArea(originX, originY,
Winson Chungaafa03c2010-06-11 17:34:16 -0700907 mDragInfo.spanX, mDragInfo.spanY, cell, cellLayout,
908 mTargetCell);
Michael Jurkac6ee42e2010-09-30 12:04:50 -0700909
910 int screen = indexOfChild(cellLayout);
911 if (screen != mDragInfo.screen) {
912 final CellLayout originalCellLayout = (CellLayout) getChildAt(mDragInfo.screen);
913 originalCellLayout.removeView(cell);
914 addInScreen(cell, screen, mTargetCell[0], mTargetCell[1],
915 mDragInfo.spanX, mDragInfo.spanY);
916 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700917 cellLayout.onDropChild(cell);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800918
Winson Chungaafa03c2010-06-11 17:34:16 -0700919 // update the item's position after drop
Romain Guy84f296c2009-11-04 15:00:44 -0800920 final ItemInfo info = (ItemInfo) cell.getTag();
Michael Jurka0280c3b2010-09-17 15:00:07 -0700921 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) cell.getLayoutParams();
922 cellLayout.onMove(cell, mTargetCell[0], mTargetCell[1]);
Winson Chungaafa03c2010-06-11 17:34:16 -0700923 lp.cellX = mTargetCell[0];
924 lp.cellY = mTargetCell[1];
Michael Jurka60587ef2010-09-30 11:06:13 -0700925 cell.setId(LauncherModel.getCellLayoutChildId(-1, mDragInfo.screen,
Michael Jurka845ba3b2010-09-28 17:09:46 -0700926 mTargetCell[0], mTargetCell[1], mDragInfo.spanX, mDragInfo.spanY));
Winson Chungaafa03c2010-06-11 17:34:16 -0700927
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800928 LauncherModel.moveItemInDatabase(mLauncher, info,
Michael Jurkac6ee42e2010-09-30 12:04:50 -0700929 LauncherSettings.Favorites.CONTAINER_DESKTOP, screen,
Winson Chungaafa03c2010-06-11 17:34:16 -0700930 lp.cellX, lp.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800931 }
932 }
933 }
934
Winson Chungaafa03c2010-06-11 17:34:16 -0700935 public void onDragEnter(DragSource source, int x, int y, int xOffset,
936 int yOffset, DragView dragView, Object dragInfo) {
Patrick Dubroyde7658b2010-09-27 11:15:43 -0700937 getCurrentDropLayout().onDragEnter(dragView);
Patrick Dubroy1262e362010-10-06 15:49:50 -0700938 showOutlines();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800939 }
940
Patrick Dubroy440c3602010-07-13 17:50:32 -0700941 public DropTarget getDropTargetDelegate(DragSource source, int x, int y, int xOffset, int yOffset,
942 DragView dragView, Object dragInfo) {
943
Michael Jurka0280c3b2010-09-17 15:00:07 -0700944 if (mIsSmall) {
945 // If we're shrunken, don't let anyone drag on folders/etc that are on the mini-screens
946 return null;
947 }
Patrick Dubroy440c3602010-07-13 17:50:32 -0700948 // We may need to delegate the drag to a child view. If a 1x1 item
949 // would land in a cell occupied by a DragTarget (e.g. a Folder),
950 // then drag events should be handled by that child.
951
952 ItemInfo item = (ItemInfo)dragInfo;
953 CellLayout currentLayout = getCurrentDropLayout();
954
955 int dragPointX, dragPointY;
956 if (item.spanX == 1 && item.spanY == 1) {
957 // For a 1x1, calculate the drop cell exactly as in onDragOver
958 dragPointX = x - xOffset;
959 dragPointY = y - yOffset;
960 } else {
961 // Otherwise, use the exact drag coordinates
962 dragPointX = x;
963 dragPointY = y;
964 }
Michael Jurka0280c3b2010-09-17 15:00:07 -0700965 dragPointX += mScrollX - currentLayout.getLeft();
966 dragPointY += mScrollY - currentLayout.getTop();
Patrick Dubroy440c3602010-07-13 17:50:32 -0700967
968 // If we are dragging over a cell that contains a DropTarget that will
969 // accept the drop, delegate to that DropTarget.
970 final int[] cellXY = mTempCell;
971 currentLayout.estimateDropCell(dragPointX, dragPointY, item.spanX, item.spanY, cellXY);
972 View child = currentLayout.getChildAt(cellXY[0], cellXY[1]);
973 if (child instanceof DropTarget) {
974 DropTarget target = (DropTarget)child;
975 if (target.acceptDrop(source, x, y, xOffset, yOffset, dragView, dragInfo)) {
976 return target;
977 }
978 }
979 return null;
980 }
981
Michael Jurka0280c3b2010-09-17 15:00:07 -0700982 private void mapPointGlobalToLocal(View v, float[] xy) {
983 xy[0] = xy[0] + mScrollX - v.getLeft();
984 xy[1] = xy[1] + mScrollY - v.getTop();
985 v.getMatrix().invert(mTempInverseMatrix);
986 mTempInverseMatrix.mapPoints(xy);
987 }
988
Michael Jurkaa63c4522010-08-19 13:52:27 -0700989 // xy = upper left corner of item being dragged
990 // bottomRightXy = lower right corner of item being dragged
991 // This method will see which mini-screen is most overlapped by the item being dragged, and
992 // return it. It will also transform the parameters xy and bottomRightXy into the local
993 // coordinate space of the returned screen
Michael Jurka0280c3b2010-09-17 15:00:07 -0700994 private CellLayout findMatchingPageForDragOver(DragView dragView, int originX, int originY) {
995 float x = originX + dragView.getScaledDragRegionXOffset();
996 float y = originY + dragView.getScaledDragRegionYOffset();
997 float right = x + dragView.getScaledDragRegionWidth();
998 float bottom = y + dragView.getScaledDragRegionHeight();
Michael Jurkaa63c4522010-08-19 13:52:27 -0700999
1000 // We loop through all the screens (ie CellLayouts) and see which one overlaps the most
1001 // with the item being dragged.
1002 final int screenCount = getChildCount();
1003 CellLayout bestMatchingScreen = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001004 float smallestDistSoFar = Float.MAX_VALUE;
1005 final float[] xy = mTempDragCoordinates;
1006 final float[] bottomRightXy = mTempDragBottomRightCoordinates;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001007 for (int i = 0; i < screenCount; i++) {
1008 CellLayout cl = (CellLayout)getChildAt(i);
1009 // Transform the coordinates of the item being dragged to the CellLayout's coordinates
1010 float left = cl.getLeft();
1011 float top = cl.getTop();
1012 xy[0] = x + mScrollX - left;
1013 xy[1] = y + mScrollY - top;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001014
1015 bottomRightXy[0] = right + mScrollX - left;
1016 bottomRightXy[1] = bottom + mScrollY - top;
1017
Michael Jurka0280c3b2010-09-17 15:00:07 -07001018 cl.getMatrix().invert(mTempInverseMatrix);
1019 mTempInverseMatrix.mapPoints(xy);
1020 mTempInverseMatrix.mapPoints(bottomRightXy);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001021
1022 float dragRegionX = xy[0];
1023 float dragRegionY = xy[1];
1024 float dragRegionRight = bottomRightXy[0];
1025 float dragRegionBottom = bottomRightXy[1];
Michael Jurka0280c3b2010-09-17 15:00:07 -07001026 float dragRegionCenterX = (dragRegionX + dragRegionRight) / 2.0f;
1027 float dragRegionCenterY = (dragRegionY + dragRegionBottom) / 2.0f;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001028
1029 // Find the overlapping region
1030 float overlapLeft = Math.max(0f, dragRegionX);
1031 float overlapTop = Math.max(0f, dragRegionY);
1032 float overlapBottom = Math.min(cl.getHeight(), dragRegionBottom);
1033 float overlapRight = Math.min(cl.getWidth(), dragRegionRight);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001034 if (overlapRight >= 0 && overlapLeft <= cl.getWidth() &&
Michael Jurka0280c3b2010-09-17 15:00:07 -07001035 (overlapTop >= 0 && overlapBottom <= cl.getHeight())) {
1036 // Calculate the distance between the two centers
1037 float distX = dragRegionCenterX - cl.getWidth()/2;
1038 float distY = dragRegionCenterY - cl.getHeight()/2;
1039 float dist = distX * distX + distY * distY;
1040
Michael Jurkaa63c4522010-08-19 13:52:27 -07001041 float overlap = (overlapRight - overlapLeft) * (overlapBottom - overlapTop);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001042
1043 // Calculate the closest overlapping region
1044 if (overlap > 0 && dist < smallestDistSoFar) {
1045 smallestDistSoFar = dist;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001046 bestMatchingScreen = cl;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001047 }
1048 }
1049 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001050
1051 if (bestMatchingScreen != mDragTargetLayout) {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001052 if (mDragTargetLayout != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001053 mDragTargetLayout.onDragExit();
Michael Jurkaa63c4522010-08-19 13:52:27 -07001054 }
1055 mDragTargetLayout = bestMatchingScreen;
Patrick Dubroy1262e362010-10-06 15:49:50 -07001056 // TODO: Should we be calling mDragTargetLayout.onDragEnter() here?
Michael Jurkaa63c4522010-08-19 13:52:27 -07001057 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001058 return bestMatchingScreen;
1059 }
1060
Patrick Dubroy6569f2c2010-07-12 14:25:18 -07001061 public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
1062 DragView dragView, Object dragInfo) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001063 CellLayout currentLayout;
1064 int originX = x - xOffset;
1065 int originY = y - yOffset;
1066 if (mIsSmall) {
1067 currentLayout = findMatchingPageForDragOver(dragView, originX, originY);
1068
1069 if (currentLayout == null) {
1070 return;
1071 }
1072
1073 currentLayout.setHover(true);
1074 // get originX and originY in the local coordinate system of the screen
1075 mTempOriginXY[0] = originX;
1076 mTempOriginXY[1] = originY;
1077 mapPointGlobalToLocal(currentLayout, mTempOriginXY);
1078 originX = (int)mTempOriginXY[0];
1079 originY = (int)mTempOriginXY[1];
1080 } else {
1081 currentLayout = getCurrentDropLayout();
1082 }
Patrick Dubroy6569f2c2010-07-12 14:25:18 -07001083
Patrick Dubroy976ebec2010-08-04 20:03:37 -07001084 final ItemInfo item = (ItemInfo)dragInfo;
Patrick Dubroy6569f2c2010-07-12 14:25:18 -07001085
1086 if (dragInfo instanceof LauncherAppWidgetInfo) {
1087 LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo)dragInfo;
1088
1089 if (widgetInfo.spanX == -1) {
1090 // Calculate the grid spans needed to fit this widget
Patrick Dubroy8f86ddc2010-07-16 13:55:32 -07001091 int[] spans = currentLayout.rectToCell(widgetInfo.minWidth, widgetInfo.minHeight, null);
Patrick Dubroy6569f2c2010-07-12 14:25:18 -07001092 item.spanX = spans[0];
1093 item.spanY = spans[1];
1094 }
1095 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001096
1097 if (source != this) {
1098 // This is a hack to fix the point used to determine which cell an icon from the all
1099 // apps screen is over
1100 if (item != null && item.spanX == 1 && currentLayout != null) {
1101 int dragRegionLeft = (dragView.getWidth() - currentLayout.getCellWidth()) / 2;
1102
1103 originX += dragRegionLeft - dragView.getDragRegionLeft();
1104 if (dragView.getDragRegionWidth() != currentLayout.getCellWidth()) {
1105 dragView.setDragRegion(dragView.getDragRegionLeft(), dragView.getDragRegionTop(),
1106 currentLayout.getCellWidth(), dragView.getDragRegionHeight());
1107 }
1108 }
1109 }
Patrick Dubroy6569f2c2010-07-12 14:25:18 -07001110
Patrick Dubroy1262e362010-10-06 15:49:50 -07001111 // When touch is inside the scroll area, skip dragOver actions for the current screen
1112 if (!mInScrollArea) {
1113 if (currentLayout != mDragTargetLayout) {
1114 if (mDragTargetLayout != null) {
1115 mDragTargetLayout.onDragExit();
1116 }
1117 currentLayout.onDragEnter(dragView);
1118 mDragTargetLayout = currentLayout;
1119 }
1120
1121 // only visualize the drop locations for moving icons within the home screen on tablet
1122 // on phone, we also visualize icons dragged in from All Apps
1123 if ((!LauncherApplication.isScreenXLarge() || source == this)
1124 && mDragTargetLayout != null) {
1125 final View child = (mDragInfo == null) ? null : mDragInfo.cell;
1126 int localOriginX = originX - (mDragTargetLayout.getLeft() - mScrollX);
1127 int localOriginY = originY - (mDragTargetLayout.getTop() - mScrollY);
1128 mDragTargetLayout.visualizeDropLocation(
1129 child, localOriginX, localOriginY, item.spanX, item.spanY);
1130 }
Patrick Dubroy976ebec2010-08-04 20:03:37 -07001131 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001132 }
1133
Winson Chungaafa03c2010-06-11 17:34:16 -07001134 public void onDragExit(DragSource source, int x, int y, int xOffset,
1135 int yOffset, DragView dragView, Object dragInfo) {
Patrick Dubroy6569f2c2010-07-12 14:25:18 -07001136 if (mDragTargetLayout != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001137 mDragTargetLayout.onDragExit();
Patrick Dubroy6569f2c2010-07-12 14:25:18 -07001138 mDragTargetLayout = null;
1139 }
Patrick Dubroy1262e362010-10-06 15:49:50 -07001140 if (!mIsPageMoving) {
1141 hideOutlines();
1142 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001143 }
1144
Winson Chungaafa03c2010-06-11 17:34:16 -07001145 private void onDropExternal(int x, int y, Object dragInfo,
1146 CellLayout cellLayout) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001147 onDropExternal(x, y, dragInfo, cellLayout, false);
1148 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001149
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07001150 /**
1151 * Add the item specified by dragInfo to the given layout.
1152 * This is basically the equivalent of onDropExternal, except it's not initiated
1153 * by drag and drop.
1154 * @return true if successful
1155 */
1156 public boolean addExternalItemToScreen(Object dragInfo, View layout) {
1157 CellLayout cl = (CellLayout) layout;
1158 ItemInfo info = (ItemInfo) dragInfo;
1159
Michael Jurka0280c3b2010-09-17 15:00:07 -07001160 if (cl.findCellForSpan(mTempEstimate, info.spanX, info.spanY)) {
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07001161 onDropExternal(0, 0, dragInfo, cl, false);
1162 return true;
1163 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001164 mLauncher.showOutOfSpaceMessage();
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07001165 return false;
1166 }
1167
Michael Jurka0280c3b2010-09-17 15:00:07 -07001168 // Drag from somewhere else
Winson Chungaafa03c2010-06-11 17:34:16 -07001169 private void onDropExternal(int x, int y, Object dragInfo,
1170 CellLayout cellLayout, boolean insertAtFirst) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001171 int screen = indexOfChild(cellLayout);
1172 if (dragInfo instanceof PendingAddItemInfo) {
1173 PendingAddItemInfo info = (PendingAddItemInfo) dragInfo;
1174 // When dragging and dropping from customization tray, we deal with creating
1175 // widgets/shortcuts/folders in a slightly different way
1176 int[] touchXY = new int[2];
1177 touchXY[0] = x;
1178 touchXY[1] = y;
1179 switch (info.itemType) {
1180 case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
1181 mLauncher.addAppWidgetFromDrop(info.componentName, screen, touchXY);
1182 break;
1183 case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER:
1184 mLauncher.addLiveFolderFromDrop(info.componentName, screen, touchXY);
1185 break;
1186 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
1187 mLauncher.processShortcutFromDrop(info.componentName, screen, touchXY);
1188 break;
1189 default:
1190 throw new IllegalStateException("Unknown item type: " + info.itemType);
1191 }
1192 cellLayout.onDragExit();
1193 return;
1194 }
1195
1196 // This is for other drag/drop cases, like dragging from All Apps
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001197 ItemInfo info = (ItemInfo) dragInfo;
1198
Michael Jurkaaf442092010-06-10 17:01:57 -07001199 View view = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001200
1201 switch (info.itemType) {
1202 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
1203 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Joe Onoratoe48e7c12010-02-19 13:10:40 -08001204 if (info.container == NO_ID && info instanceof ApplicationInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001205 // Came from all apps -- make a copy
Winson Chungaafa03c2010-06-11 17:34:16 -07001206 info = new ShortcutInfo((ApplicationInfo) info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001207 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001208 view = mLauncher.createShortcut(R.layout.application, cellLayout,
1209 (ShortcutInfo) info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001210 break;
1211 case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER:
1212 view = FolderIcon.fromXml(R.layout.folder_icon, mLauncher,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001213 cellLayout, ((UserFolderInfo) info));
Michael Jurkaaf442092010-06-10 17:01:57 -07001214 break;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001215 default:
Michael Jurka0280c3b2010-09-17 15:00:07 -07001216 throw new IllegalStateException("Unknown item type: " + info.itemType);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001217 }
1218
Patrick Dubroy6569f2c2010-07-12 14:25:18 -07001219 // If the view is null, it has already been added.
1220 if (view == null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001221 cellLayout.onDragExit();
Patrick Dubroy6569f2c2010-07-12 14:25:18 -07001222 } else {
Michael Jurka7ded67c2010-09-28 13:57:39 -07001223 mTargetCell = findNearestVacantArea(x, y, 1, 1, null, cellLayout, mTargetCell);
Winson Chungaafa03c2010-06-11 17:34:16 -07001224 addInScreen(view, indexOfChild(cellLayout), mTargetCell[0],
1225 mTargetCell[1], info.spanX, info.spanY, insertAtFirst);
1226 cellLayout.onDropChild(view);
Patrick Dubroy6569f2c2010-07-12 14:25:18 -07001227 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) view.getLayoutParams();
Michael Jurkaaf442092010-06-10 17:01:57 -07001228
1229 LauncherModel.addOrMoveItemInDatabase(mLauncher, info,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001230 LauncherSettings.Favorites.CONTAINER_DESKTOP, screen,
Winson Chungaafa03c2010-06-11 17:34:16 -07001231 lp.cellX, lp.cellY);
Joe Onorato00acb122009-08-04 16:04:30 -04001232 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001233 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001234
Jeff Sharkey70864282009-04-07 21:08:40 -07001235 /**
1236 * Return the current {@link CellLayout}, correctly picking the destination
1237 * screen while a scroll is in progress.
1238 */
1239 private CellLayout getCurrentDropLayout() {
Michael Jurka0142d492010-08-25 17:46:15 -07001240 int index = mScroller.isFinished() ? mCurrentPage : mNextPage;
Jeff Sharkey70864282009-04-07 21:08:40 -07001241 return (CellLayout) getChildAt(index);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001242 }
1243
Jeff Sharkey70864282009-04-07 21:08:40 -07001244 /**
Michael Jurka0280c3b2010-09-17 15:00:07 -07001245 * Return the current CellInfo describing our current drag; this method exists
1246 * so that Launcher can sync this object with the correct info when the activity is created/
1247 * destroyed
1248 *
1249 */
1250 public CellLayout.CellInfo getDragInfo() {
1251 return mDragInfo;
1252 }
1253
1254 /**
Jeff Sharkey70864282009-04-07 21:08:40 -07001255 * {@inheritDoc}
1256 */
1257 public boolean acceptDrop(DragSource source, int x, int y,
Joe Onorato00acb122009-08-04 16:04:30 -04001258 int xOffset, int yOffset, DragView dragView, Object dragInfo) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001259 CellLayout layout;
1260 if (mIsSmall) {
1261 layout = findMatchingPageForDragOver(dragView, x - xOffset, y - yOffset);
1262 if (layout == null) {
1263 // cancel the drag if we're not over a mini-screen at time of drop
1264 return false;
1265 }
1266 } else {
1267 layout = getCurrentDropLayout();
1268 }
Michael Jurkac28de512010-08-13 11:27:44 -07001269 final CellLayout.CellInfo dragCellInfo = mDragInfo;
1270 final int spanX = dragCellInfo == null ? 1 : dragCellInfo.spanX;
1271 final int spanY = dragCellInfo == null ? 1 : dragCellInfo.spanY;
Romain Guy4c58c482009-05-12 17:35:41 -07001272
Michael Jurkac28de512010-08-13 11:27:44 -07001273 final View ignoreView = dragCellInfo == null ? null : dragCellInfo.cell;
Romain Guy4c58c482009-05-12 17:35:41 -07001274
Michael Jurka0280c3b2010-09-17 15:00:07 -07001275 if (layout.findCellForSpanIgnoring(null, spanX, spanY, ignoreView)) {
Michael Jurka0e260592010-06-30 17:07:39 -07001276 return true;
1277 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001278 mLauncher.showOutOfSpaceMessage();
Michael Jurka0e260592010-06-30 17:07:39 -07001279 return false;
1280 }
Jeff Sharkey70864282009-04-07 21:08:40 -07001281 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001282
Jeff Sharkey70864282009-04-07 21:08:40 -07001283 /**
Jeff Sharkey70864282009-04-07 21:08:40 -07001284 * Calculate the nearest cell where the given object would be dropped.
1285 */
Michael Jurka6a1435d2010-09-27 17:35:12 -07001286 private int[] findNearestVacantArea(int pixelX, int pixelY,
Jeff Sharkey70864282009-04-07 21:08:40 -07001287 int spanX, int spanY, View ignoreView, CellLayout layout, int[] recycle) {
Patrick Dubroy6569f2c2010-07-12 14:25:18 -07001288
Michael Jurka5f1c5092010-09-03 14:15:02 -07001289 int localPixelX = pixelX - (layout.getLeft() - mScrollX);
1290 int localPixelY = pixelY - (layout.getTop() - mScrollY);
Patrick Dubroy6569f2c2010-07-12 14:25:18 -07001291
Jeff Sharkey70864282009-04-07 21:08:40 -07001292 // Find the best target drop location
Michael Jurka0280c3b2010-09-17 15:00:07 -07001293 return layout.findNearestVacantArea(
Michael Jurkafc9f07d2010-09-30 13:22:31 -07001294 localPixelX, localPixelY, spanX, spanY, ignoreView, recycle);
Jeff Sharkey70864282009-04-07 21:08:40 -07001295 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001296
Patrick Dubroy8f86ddc2010-07-16 13:55:32 -07001297 /**
1298 * Estimate the size that a child with the given dimensions will take in the current screen.
1299 */
1300 void estimateChildSize(int minWidth, int minHeight, int[] result) {
Michael Jurka0142d492010-08-25 17:46:15 -07001301 ((CellLayout)getChildAt(mCurrentPage)).estimateChildSize(minWidth, minHeight, result);
Patrick Dubroy8f86ddc2010-07-16 13:55:32 -07001302 }
1303
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001304 void setLauncher(Launcher launcher) {
1305 mLauncher = launcher;
1306 }
1307
Joe Onorato00acb122009-08-04 16:04:30 -04001308 public void setDragController(DragController dragController) {
1309 mDragController = dragController;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001310 }
1311
1312 public void onDropCompleted(View target, boolean success) {
Winson Chungaafa03c2010-06-11 17:34:16 -07001313 if (success) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001314 if (target != this && mDragInfo != null) {
1315 final CellLayout cellLayout = (CellLayout) getChildAt(mDragInfo.screen);
1316 cellLayout.removeView(mDragInfo.cell);
Joe Onorato00acb122009-08-04 16:04:30 -04001317 if (mDragInfo.cell instanceof DropTarget) {
1318 mDragController.removeDropTarget((DropTarget)mDragInfo.cell);
1319 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001320 // final Object tag = mDragInfo.cell.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001321 }
1322 } else {
1323 if (mDragInfo != null) {
1324 final CellLayout cellLayout = (CellLayout) getChildAt(mDragInfo.screen);
1325 cellLayout.onDropAborted(mDragInfo.cell);
1326 }
1327 }
1328
1329 mDragInfo = null;
1330 }
1331
Michael Jurka0280c3b2010-09-17 15:00:07 -07001332 public boolean isDropEnabled() {
1333 return true;
1334 }
1335
Michael Jurka0142d492010-08-25 17:46:15 -07001336 @Override
1337 protected void onRestoreInstanceState(Parcelable state) {
1338 super.onRestoreInstanceState(state);
1339 Launcher.setScreen(mCurrentPage);
1340 }
1341
1342 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001343 public void scrollLeft() {
Michael Jurka7f0f4f32010-08-23 11:33:38 -07001344 if (!mIsSmall) {
Michael Jurka0142d492010-08-25 17:46:15 -07001345 super.scrollLeft();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001346 }
1347 }
1348
Michael Jurka0142d492010-08-25 17:46:15 -07001349 @Override
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001350 public void scrollRight() {
Michael Jurka7f0f4f32010-08-23 11:33:38 -07001351 if (!mIsSmall) {
Michael Jurka0142d492010-08-25 17:46:15 -07001352 super.scrollRight();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001353 }
1354 }
1355
Patrick Dubroy1262e362010-10-06 15:49:50 -07001356 @Override
1357 public void onEnterScrollArea(int direction) {
1358 mInScrollArea = true;
1359 final int screen = getCurrentPage() + ((direction == DragController.SCROLL_LEFT) ? -1 : 1);
1360 if (0 <= screen && screen < getChildCount()) {
1361 ((CellLayout) getChildAt(screen)).setHover(true);
1362 }
1363
1364 if (mDragTargetLayout != null) {
1365 mDragTargetLayout.onDragExit();
1366 mDragTargetLayout = null;
1367 }
1368 }
1369
1370 @Override
1371 public void onExitScrollArea() {
1372 mInScrollArea = false;
1373 final int childCount = getChildCount();
1374 for (int i = 0; i < childCount; i++) {
1375 ((CellLayout) getChildAt(i)).setHover(false);
1376 }
1377 }
1378
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001379 public Folder getFolderForTag(Object tag) {
Michael Jurkadee05892010-07-27 10:01:56 -07001380 final int screenCount = getChildCount();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001381 for (int screen = 0; screen < screenCount; screen++) {
1382 CellLayout currentScreen = ((CellLayout) getChildAt(screen));
1383 int count = currentScreen.getChildCount();
1384 for (int i = 0; i < count; i++) {
1385 View child = currentScreen.getChildAt(i);
1386 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
1387 if (lp.cellHSpan == 4 && lp.cellVSpan == 4 && child instanceof Folder) {
1388 Folder f = (Folder) child;
Winson Chungaafa03c2010-06-11 17:34:16 -07001389 if (f.getInfo() == tag && f.getInfo().opened) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001390 return f;
1391 }
1392 }
1393 }
1394 }
1395 return null;
1396 }
1397
1398 public View getViewForTag(Object tag) {
1399 int screenCount = getChildCount();
1400 for (int screen = 0; screen < screenCount; screen++) {
1401 CellLayout currentScreen = ((CellLayout) getChildAt(screen));
1402 int count = currentScreen.getChildCount();
1403 for (int i = 0; i < count; i++) {
1404 View child = currentScreen.getChildAt(i);
1405 if (child.getTag() == tag) {
1406 return child;
1407 }
1408 }
1409 }
1410 return null;
1411 }
1412
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001413
Joe Onorato64e6be72010-03-05 15:05:52 -05001414 void removeItems(final ArrayList<ApplicationInfo> apps) {
Michael Jurkadee05892010-07-27 10:01:56 -07001415 final int screenCount = getChildCount();
Romain Guy5c16f3e2010-01-12 17:24:58 -08001416 final PackageManager manager = getContext().getPackageManager();
Romain Guy629de3e2010-01-13 12:20:59 -08001417 final AppWidgetManager widgets = AppWidgetManager.getInstance(getContext());
Romain Guy574d20e2009-06-01 15:34:04 -07001418
Joe Onorato64e6be72010-03-05 15:05:52 -05001419 final HashSet<String> packageNames = new HashSet<String>();
1420 final int appCount = apps.size();
1421 for (int i = 0; i < appCount; i++) {
1422 packageNames.add(apps.get(i).componentName.getPackageName());
1423 }
1424
Michael Jurkadee05892010-07-27 10:01:56 -07001425 for (int i = 0; i < screenCount; i++) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001426 final CellLayout layout = (CellLayout) getChildAt(i);
Romain Guy574d20e2009-06-01 15:34:04 -07001427
Romain Guy629de3e2010-01-13 12:20:59 -08001428 // Avoid ANRs by treating each screen separately
1429 post(new Runnable() {
1430 public void run() {
1431 final ArrayList<View> childrenToRemove = new ArrayList<View>();
1432 childrenToRemove.clear();
Winson Chungaafa03c2010-06-11 17:34:16 -07001433
Romain Guy629de3e2010-01-13 12:20:59 -08001434 int childCount = layout.getChildCount();
1435 for (int j = 0; j < childCount; j++) {
1436 final View view = layout.getChildAt(j);
1437 Object tag = view.getTag();
Winson Chungaafa03c2010-06-11 17:34:16 -07001438
Joe Onorato0589f0f2010-02-08 13:44:00 -08001439 if (tag instanceof ShortcutInfo) {
1440 final ShortcutInfo info = (ShortcutInfo) tag;
Romain Guy629de3e2010-01-13 12:20:59 -08001441 final Intent intent = info.intent;
1442 final ComponentName name = intent.getComponent();
Winson Chungaafa03c2010-06-11 17:34:16 -07001443
Joe Onorato64e6be72010-03-05 15:05:52 -05001444 if (Intent.ACTION_MAIN.equals(intent.getAction()) && name != null) {
1445 for (String packageName: packageNames) {
1446 if (packageName.equals(name.getPackageName())) {
Joe Onorato64e6be72010-03-05 15:05:52 -05001447 LauncherModel.deleteItemFromDatabase(mLauncher, info);
1448 childrenToRemove.add(view);
1449 }
1450 }
Romain Guy629de3e2010-01-13 12:20:59 -08001451 }
1452 } else if (tag instanceof UserFolderInfo) {
1453 final UserFolderInfo info = (UserFolderInfo) tag;
Joe Onorato0589f0f2010-02-08 13:44:00 -08001454 final ArrayList<ShortcutInfo> contents = info.contents;
1455 final ArrayList<ShortcutInfo> toRemove = new ArrayList<ShortcutInfo>(1);
Romain Guy629de3e2010-01-13 12:20:59 -08001456 final int contentsCount = contents.size();
1457 boolean removedFromFolder = false;
Winson Chungaafa03c2010-06-11 17:34:16 -07001458
Romain Guy629de3e2010-01-13 12:20:59 -08001459 for (int k = 0; k < contentsCount; k++) {
Joe Onorato0589f0f2010-02-08 13:44:00 -08001460 final ShortcutInfo appInfo = contents.get(k);
Romain Guy629de3e2010-01-13 12:20:59 -08001461 final Intent intent = appInfo.intent;
1462 final ComponentName name = intent.getComponent();
Winson Chungaafa03c2010-06-11 17:34:16 -07001463
Joe Onorato64e6be72010-03-05 15:05:52 -05001464 if (Intent.ACTION_MAIN.equals(intent.getAction()) && name != null) {
1465 for (String packageName: packageNames) {
1466 if (packageName.equals(name.getPackageName())) {
1467 toRemove.add(appInfo);
Brad Fitzpatrick73013bf2010-09-14 12:15:32 -07001468 LauncherModel.deleteItemFromDatabase(mLauncher, appInfo);
Joe Onorato64e6be72010-03-05 15:05:52 -05001469 removedFromFolder = true;
1470 }
1471 }
Romain Guy629de3e2010-01-13 12:20:59 -08001472 }
1473 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001474
Romain Guy629de3e2010-01-13 12:20:59 -08001475 contents.removeAll(toRemove);
1476 if (removedFromFolder) {
1477 final Folder folder = getOpenFolder();
Winson Chungaafa03c2010-06-11 17:34:16 -07001478 if (folder != null)
1479 folder.notifyDataSetChanged();
Romain Guy629de3e2010-01-13 12:20:59 -08001480 }
1481 } else if (tag instanceof LiveFolderInfo) {
1482 final LiveFolderInfo info = (LiveFolderInfo) tag;
1483 final Uri uri = info.uri;
1484 final ProviderInfo providerInfo = manager.resolveContentProvider(
1485 uri.getAuthority(), 0);
Romain Guy574d20e2009-06-01 15:34:04 -07001486
Joe Onoratof11079b2010-04-15 11:47:28 -07001487 if (providerInfo != null) {
Joe Onorato64e6be72010-03-05 15:05:52 -05001488 for (String packageName: packageNames) {
1489 if (packageName.equals(providerInfo.packageName)) {
Joe Onorato64e6be72010-03-05 15:05:52 -05001490 LauncherModel.deleteItemFromDatabase(mLauncher, info);
Winson Chungaafa03c2010-06-11 17:34:16 -07001491 childrenToRemove.add(view);
Joe Onorato64e6be72010-03-05 15:05:52 -05001492 }
1493 }
Romain Guy629de3e2010-01-13 12:20:59 -08001494 }
1495 } else if (tag instanceof LauncherAppWidgetInfo) {
1496 final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) tag;
1497 final AppWidgetProviderInfo provider =
1498 widgets.getAppWidgetInfo(info.appWidgetId);
Daniel Sandlere1cc6c32010-05-07 11:49:29 -04001499 if (provider != null) {
Joe Onorato64e6be72010-03-05 15:05:52 -05001500 for (String packageName: packageNames) {
1501 if (packageName.equals(provider.provider.getPackageName())) {
Joe Onorato64e6be72010-03-05 15:05:52 -05001502 LauncherModel.deleteItemFromDatabase(mLauncher, info);
Winson Chungaafa03c2010-06-11 17:34:16 -07001503 childrenToRemove.add(view);
Joe Onorato64e6be72010-03-05 15:05:52 -05001504 }
1505 }
Romain Guy629de3e2010-01-13 12:20:59 -08001506 }
Romain Guy574d20e2009-06-01 15:34:04 -07001507 }
1508 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001509
Romain Guy629de3e2010-01-13 12:20:59 -08001510 childCount = childrenToRemove.size();
1511 for (int j = 0; j < childCount; j++) {
1512 View child = childrenToRemove.get(j);
1513 layout.removeViewInLayout(child);
1514 if (child instanceof DropTarget) {
1515 mDragController.removeDropTarget((DropTarget)child);
1516 }
Romain Guy574d20e2009-06-01 15:34:04 -07001517 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001518
Romain Guy629de3e2010-01-13 12:20:59 -08001519 if (childCount > 0) {
1520 layout.requestLayout();
1521 layout.invalidate();
Romain Guy5c16f3e2010-01-12 17:24:58 -08001522 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001523 }
Romain Guy629de3e2010-01-13 12:20:59 -08001524 });
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001525 }
1526 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001527
Joe Onorato64e6be72010-03-05 15:05:52 -05001528 void updateShortcuts(ArrayList<ApplicationInfo> apps) {
Michael Jurkadee05892010-07-27 10:01:56 -07001529 final int screenCount = getChildCount();
1530 for (int i = 0; i < screenCount; i++) {
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001531 final CellLayout layout = (CellLayout) getChildAt(i);
1532 int childCount = layout.getChildCount();
1533 for (int j = 0; j < childCount; j++) {
1534 final View view = layout.getChildAt(j);
1535 Object tag = view.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001536 if (tag instanceof ShortcutInfo) {
1537 ShortcutInfo info = (ShortcutInfo)tag;
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001538 // We need to check for ACTION_MAIN otherwise getComponent() might
1539 // return null for some shortcuts (for instance, for shortcuts to
1540 // web pages.)
1541 final Intent intent = info.intent;
1542 final ComponentName name = intent.getComponent();
1543 if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION &&
Joe Onorato64e6be72010-03-05 15:05:52 -05001544 Intent.ACTION_MAIN.equals(intent.getAction()) && name != null) {
1545 final int appCount = apps.size();
Winson Chungaafa03c2010-06-11 17:34:16 -07001546 for (int k = 0; k < appCount; k++) {
Joe Onorato64e6be72010-03-05 15:05:52 -05001547 ApplicationInfo app = apps.get(k);
1548 if (app.componentName.equals(name)) {
1549 info.setIcon(mIconCache.getIcon(info.intent));
1550 ((TextView)view).setCompoundDrawablesWithIntrinsicBounds(null,
1551 new FastBitmapDrawable(info.getIcon(mIconCache)),
1552 null, null);
1553 }
1554 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07001555 }
1556 }
1557 }
1558 }
1559 }
1560
Joe Onorato14f122b2009-11-19 14:06:36 -08001561 void moveToDefaultScreen(boolean animate) {
Joe Onoratoc45b1682010-01-11 18:48:40 -05001562 if (animate) {
Michael Jurka4cb37242010-08-09 21:05:32 -07001563 if (mIsSmall) {
Michael Jurka0142d492010-08-25 17:46:15 -07001564 unshrink(mDefaultPage);
Michael Jurka4cb37242010-08-09 21:05:32 -07001565 } else {
Michael Jurka0142d492010-08-25 17:46:15 -07001566 snapToPage(mDefaultPage);
Michael Jurka4cb37242010-08-09 21:05:32 -07001567 }
Joe Onoratoc45b1682010-01-11 18:48:40 -05001568 } else {
Michael Jurka0142d492010-08-25 17:46:15 -07001569 setCurrentPage(mDefaultPage);
Joe Onoratoc45b1682010-01-11 18:48:40 -05001570 }
Michael Jurka0142d492010-08-25 17:46:15 -07001571 getChildAt(mDefaultPage).requestFocus();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001572 }
1573
Romain Guy8a73c512009-11-09 19:19:59 -08001574 void setIndicators(Drawable previous, Drawable next) {
1575 mPreviousIndicator = previous;
1576 mNextIndicator = next;
Michael Jurka0142d492010-08-25 17:46:15 -07001577 previous.setLevel(mCurrentPage);
1578 next.setLevel(mCurrentPage);
Romain Guy8a73c512009-11-09 19:19:59 -08001579 }
1580
Michael Jurka0142d492010-08-25 17:46:15 -07001581 @Override
1582 public void syncPages() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001583 }
Michael Jurka0142d492010-08-25 17:46:15 -07001584
1585 @Override
1586 public void syncPageItems(int page) {
1587 }
1588
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001589}