blob: 6ac9fe213f6c8007687340cae804d33d9459c3a5 [file] [log] [blame]
Michael Jurka01f0ed42010-08-20 00:41:17 -07001
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002/*
3 * Copyright (C) 2008 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
Joe Onoratoa5902522009-07-30 13:37:37 -070018package com.android.launcher2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080019
Gilles Debunnedd6c9922010-10-25 11:23:41 -070020import android.animation.Animator;
Michael Jurka8edd75c2010-12-17 20:15:06 -080021import android.animation.AnimatorListenerAdapter;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070022import android.animation.AnimatorSet;
Adam Cohen2801caf2011-05-13 20:57:39 -070023import android.animation.ObjectAnimator;
24import android.animation.PropertyValuesHolder;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070025import android.animation.ValueAnimator;
Michael Jurka946ad472010-07-09 18:05:18 -070026import android.app.Activity;
Brett Chabot2a9e2282011-08-23 15:03:13 -070027import android.app.ActivityManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080028import android.app.AlertDialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080029import android.app.Dialog;
30import android.app.SearchManager;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080031import android.appwidget.AppWidgetHostView;
Michael Jurkaaf442092010-06-10 17:01:57 -070032import android.appwidget.AppWidgetManager;
33import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080034import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080035import android.content.BroadcastReceiver;
Winson Chung68846fd2010-10-29 11:00:27 -070036import android.content.ClipData;
37import android.content.ClipDescription;
Michael Jurkae326f182011-11-21 14:05:46 -080038import android.content.ComponentCallbacks2;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040039import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080040import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041import android.content.Context;
42import android.content.DialogInterface;
43import android.content.Intent;
Winson Chungf0ea4d32011-06-06 14:27:16 -070044import android.content.IntentFilter;
Winson Chung82f55532011-08-09 14:14:23 -070045import android.content.SharedPreferences;
Winson Chungaafa03c2010-06-11 17:34:16 -070046import android.content.pm.ActivityInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080047import android.content.pm.PackageManager;
Adam Cohen716b51e2011-06-30 12:09:54 -070048import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080049import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070050import android.content.res.Resources;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080051import android.database.ContentObserver;
Michael Jurkaaf442092010-06-10 17:01:57 -070052import android.graphics.Rect;
Michael Jurkaaf442092010-06-10 17:01:57 -070053import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040054import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070055import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080056import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020057import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080058import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070059import android.os.Message;
Daniel Sandler843e8602010-06-07 14:59:01 -040060import android.os.SystemClock;
Joe Onoratobe386092009-11-17 17:32:16 -080061import android.os.SystemProperties;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070062import android.provider.Settings;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080063import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080064import android.text.Selection;
65import android.text.SpannableStringBuilder;
66import android.text.TextUtils;
67import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070068import android.util.Log;
Winson Chung400438b2011-01-16 17:53:48 -080069import android.view.Display;
Joe Onorato0d44e942009-11-16 18:20:51 -080070import android.view.HapticFeedbackConstants;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080071import android.view.KeyEvent;
72import android.view.LayoutInflater;
73import android.view.Menu;
74import android.view.MenuItem;
Michael Jurka0e260592010-06-30 17:07:39 -070075import android.view.MotionEvent;
Winson Chung400438b2011-01-16 17:53:48 -080076import android.view.Surface;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080077import android.view.View;
Adam Cohen0cf2a7c2011-11-08 15:07:01 -080078import android.view.View.OnLongClickListener;
Winson Chung82f55532011-08-09 14:14:23 -070079import android.view.ViewGroup;
Michael Jurkab737ee62011-11-15 15:57:22 -080080import android.view.ViewTreeObserver;
Michael Jurka2a4b1a82011-12-07 14:00:02 -080081import android.view.ViewTreeObserver.OnGlobalLayoutListener;
Dianne Hackbornbb003a52011-08-30 14:40:07 -070082import android.view.WindowManager;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -080083import android.view.accessibility.AccessibilityEvent;
Adam Cohencff6af82011-09-13 14:51:53 -070084import android.view.animation.AccelerateDecelerateInterpolator;
Winson Chung7a74ac92011-09-20 17:43:51 -070085import android.view.animation.AccelerateInterpolator;
Adam Cohenf16e5712011-01-13 13:31:45 -080086import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080087import android.view.inputmethod.InputMethodManager;
Adam Cohended9f8d2010-11-03 13:25:16 -070088import android.widget.Advanceable;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080089import android.widget.EditText;
Michael Jurkaaf442092010-06-10 17:01:57 -070090import android.widget.ImageView;
Winson Chung68846fd2010-10-29 11:00:27 -070091import android.widget.TextView;
92import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070093
Adam Cohendf2cc412011-04-27 16:56:57 -070094import com.android.common.Search;
95import com.android.launcher.R;
Adam Cohen558baaf2011-08-15 15:22:57 -070096import com.android.launcher2.DropTarget.DragObject;
Romain Guyedcce092010-03-04 13:03:17 -080097
Adam Cohenc0dcf592011-06-01 15:30:43 -070098import java.io.DataInputStream;
99import java.io.DataOutputStream;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700100import java.io.FileDescriptor;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700101import java.io.FileNotFoundException;
102import java.io.IOException;
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700103import java.io.PrintWriter;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700104import java.util.ArrayList;
105import java.util.HashMap;
Adam Cohenc0dcf592011-06-01 15:30:43 -0700106
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800107/**
108 * Default launcher application.
109 */
Michael Jurka946ad472010-07-09 18:05:18 -0700110public final class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700111 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
112 AllAppsView.Watcher, View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800113 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700114 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800115
Joe Onorato9c1289c2009-08-17 11:03:03 -0400116 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400117 static final boolean DEBUG_WIDGETS = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700118
Winson Chung70d72102011-08-12 11:24:35 -0700119 private static final int MENU_GROUP_WALLPAPER = 1;
120 private static final int MENU_WALLPAPER_SETTINGS = Menu.FIRST + 1;
121 private static final int MENU_MANAGE_APPS = MENU_WALLPAPER_SETTINGS + 1;
Winson Chung236d4312011-08-22 15:12:27 -0700122 private static final int MENU_SYSTEM_SETTINGS = MENU_MANAGE_APPS + 1;
123 private static final int MENU_HELP = MENU_SYSTEM_SETTINGS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800124
125 private static final int REQUEST_CREATE_SHORTCUT = 1;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700126 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800127 private static final int REQUEST_PICK_APPLICATION = 6;
128 private static final int REQUEST_PICK_SHORTCUT = 7;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700129 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700130 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800131
132 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
133
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800134 static final int SCREEN_COUNT = 5;
135 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800136
Joe Onorato7c312c12009-08-13 21:36:53 -0700137 static final int DIALOG_CREATE_SHORTCUT = 1;
138 static final int DIALOG_RENAME_FOLDER = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800139
Romain Guy98d01652009-06-30 16:21:04 -0700140 private static final String PREFERENCES = "launcher.preferences";
Adam Cohen23a4d302011-12-01 17:26:44 -0800141 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher.force_enable_rotation";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800142
143 // Type: int
144 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700145 // Type: int
146 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800147 // Type: int
Winson Chung3d503fb2011-07-13 17:25:49 -0700148 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
149 // Type: int
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800150 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
151 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700152 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800153 // Type: int
Adam Cohenfbba09b2011-07-18 21:43:05 -0700154 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800155 // Type: boolean
156 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
157 // Type: long
158 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
159
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700160 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
161
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700162 /** The different states that Launcher can be in. */
Winson Chungf0ea4d32011-06-06 14:27:16 -0700163 private enum State { WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700164 private State mState = State.WORKSPACE;
165 private AnimatorSet mStateAnimation;
Michael Jurkab737ee62011-11-15 15:57:22 -0800166 private AnimatorSet mDividerAnimator;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700167
Joe Onorato9c1289c2009-08-17 11:03:03 -0400168 static final int APPWIDGET_HOST_ID = 1024;
Winson Chung557d6ed2011-07-08 15:34:52 -0700169 private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
170 private static final int EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT = 600;
Winson Chung7a74ac92011-09-20 17:43:51 -0700171 private static final int SHOW_CLING_DURATION = 550;
Winson Chung7d7541e2011-09-16 20:14:36 -0700172 private static final int DISMISS_CLING_DURATION = 250;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800173
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800174 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800175 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800176
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800177 private final BroadcastReceiver mCloseSystemDialogsReceiver
178 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800179 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
180
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800181 private LayoutInflater mInflater;
182
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800183 private Workspace mWorkspace;
Michael Jurkab737ee62011-11-15 15:57:22 -0800184 private View mQsbDivider;
185 private View mDockDivider;
186 private DragLayer mDragLayer;
187 private DragController mDragController;
Romain Guycbb89e42009-06-08 15:52:54 -0700188
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700189 private AppWidgetManager mAppWidgetManager;
190 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700191
Michael Jurkac9d95c52011-08-29 14:03:34 -0700192 private ItemInfo mPendingAddInfo = new ItemInfo();
Michael Jurka0280c3b2010-09-17 15:00:07 -0700193 private int[] mTmpAddItemCellCoordinates = new int[2];
194
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800195 private FolderInfo mFolderInfo;
196
Winson Chung3d503fb2011-07-13 17:25:49 -0700197 private Hotseat mHotseat;
Michael Jurka838a4ca2011-02-07 13:33:06 -0800198 private View mAllAppsButton;
Winson Chung3d503fb2011-07-13 17:25:49 -0700199
Winson Chungc51db6a2011-10-05 11:44:49 -0700200 private SearchDropTargetBar mSearchDropTargetBar;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700201 private AppsCustomizeTabHost mAppsCustomizeTabHost;
202 private AppsCustomizePagedView mAppsCustomizeContent;
203 private boolean mAutoAdvanceRunning = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800204
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800205 private Bundle mSavedState;
206
207 private SpannableStringBuilder mDefaultKeySsb = null;
208
Joe Onorato9c1289c2009-08-17 11:03:03 -0400209 private boolean mWorkspaceLoading = true;
210
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800211 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800212 private boolean mRestoring;
213 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700214 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800215
216 private Bundle mSavedInstanceState;
217
Joe Onorato9c1289c2009-08-17 11:03:03 -0400218 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800219 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800220 private boolean mUserPresent = true;
221 private boolean mVisible = false;
222 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400223
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700224 private static LocaleConfiguration sLocaleConfiguration = null;
225
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700226 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700227
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700228 private Intent mAppMarketIntent = null;
229
Adam Cohended9f8d2010-11-03 13:25:16 -0700230 // Related to the auto-advancing of widgets
231 private final int ADVANCE_MSG = 1;
232 private final int mAdvanceInterval = 20000;
233 private final int mAdvanceStagger = 250;
234 private long mAutoAdvanceSentTime;
235 private long mAutoAdvanceTimeLeft = -1;
236 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
237 new HashMap<View, AppWidgetProviderInfo>();
238
Winson Chung400438b2011-01-16 17:53:48 -0800239 // Determines how long to wait after a rotation before restoring the screen orientation to
240 // match the sensor state.
241 private final int mRestoreScreenOrientationDelay = 500;
242
Michael Jurka4ef207b2010-11-29 17:05:45 -0800243 // External icons saved in case of resource changes, orientation, etc.
Winson Chungdff8ebb2011-09-08 17:25:31 -0700244 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
245 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
246 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
Michael Jurka4ef207b2010-11-29 17:05:45 -0800247
Adam Cohen16d7ffc2011-10-05 17:49:14 -0700248 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
249
Adam Cohen2801caf2011-05-13 20:57:39 -0700250
Michael Jurkaddd62e92011-02-16 17:49:14 -0800251 private BubbleTextView mWaitingForResume;
252
Michael Jurkac1f5d262011-09-30 19:32:27 -0700253 private Runnable mBuildLayersRunnable = new Runnable() {
254 public void run() {
Michael Jurka9d906c72011-10-14 06:25:36 -0700255 if (mWorkspace != null) {
256 mWorkspace.buildPageHardwareLayers();
257 }
Michael Jurkac1f5d262011-09-30 19:32:27 -0700258 }
259 };
260
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800261 private static ArrayList<PendingAddArguments> sPendingAddList
262 = new ArrayList<PendingAddArguments>();
263
264 private static class PendingAddArguments {
265 int requestCode;
266 Intent intent;
Winson Chung3d503fb2011-07-13 17:25:49 -0700267 long container;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800268 int screen;
269 int cellX;
270 int cellY;
271 }
272
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800273 @Override
274 protected void onCreate(Bundle savedInstanceState) {
275 super.onCreate(savedInstanceState);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800276 LauncherApplication app = ((LauncherApplication)getApplication());
277 mModel = app.setLauncher(this);
278 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400279 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800280 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700281
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700282 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700283 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
284 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700285
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800286 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200287 android.os.Debug.startMethodTracing(
288 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800289 }
290
291 checkForLocaleChange();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800292 setContentView(R.layout.launcher);
293 setupViews();
Winson Chung7d7541e2011-09-16 20:14:36 -0700294 showFirstRunWorkspaceCling();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800295
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800296 registerContentObservers();
297
Joe Onorato7c312c12009-08-13 21:36:53 -0700298 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700299
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800300 mSavedState = savedInstanceState;
301 restoreState(mSavedState);
302
Winson Chunga12a2502010-12-20 14:41:35 -0800303 // Update customization drawer _after_ restoring the states
Winson Chung785d2eb2011-04-14 16:08:02 -0700304 if (mAppsCustomizeContent != null) {
305 mAppsCustomizeContent.onPackagesUpdated();
306 }
Winson Chunga12a2502010-12-20 14:41:35 -0800307
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800308 if (PROFILE_STARTUP) {
309 android.os.Debug.stopMethodTracing();
310 }
311
312 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400313 mModel.startLoader(this, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800314 }
315
Michael Jurkac57b7a82011-08-09 22:02:20 -0700316 if (!mModel.isAllAppsLoaded()) {
317 ViewGroup appsCustomizeContentParent = (ViewGroup) mAppsCustomizeContent.getParent();
318 mInflater.inflate(R.layout.apps_customize_progressbar, appsCustomizeContentParent);
319 }
320
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800321 // For handling default keys
322 mDefaultKeySsb = new SpannableStringBuilder();
323 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800324
325 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
326 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800327
Winson Chungc51db6a2011-10-05 11:44:49 -0700328 boolean searchVisible = false;
329 boolean voiceVisible = false;
Michael Jurka4ef207b2010-11-29 17:05:45 -0800330 // If we have a saved version of these external icons, we load them up immediately
Winson Chungdff8ebb2011-09-08 17:25:31 -0700331 int coi = getCurrentOrientationIndexForGlobalIcons();
332 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null ||
333 sAppMarketIcon[coi] == null) {
Winson Chungc51db6a2011-10-05 11:44:49 -0700334 updateAppMarketIcon();
335 searchVisible = updateGlobalSearchIcon();
336 voiceVisible = updateVoiceSearchIcon(searchVisible);
Winson Chungf0ea4d32011-06-06 14:27:16 -0700337 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700338 if (sGlobalSearchIcon[coi] != null) {
339 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700340 searchVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700341 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700342 if (sVoiceSearchIcon[coi] != null) {
343 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
Winson Chungc51db6a2011-10-05 11:44:49 -0700344 voiceVisible = true;
Winson Chungf0ea4d32011-06-06 14:27:16 -0700345 }
Winson Chungdff8ebb2011-09-08 17:25:31 -0700346 if (sAppMarketIcon[coi] != null) {
347 updateAppMarketIcon(sAppMarketIcon[coi]);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800348 }
Winson Chungc51db6a2011-10-05 11:44:49 -0700349 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
Adam Cohen446e9402011-09-15 18:21:21 -0700350
Adam Cohen23a4d302011-12-01 17:26:44 -0800351 final String forceEnableRotation =
352 SystemProperties.get(FORCE_ENABLE_ROTATION_PROPERTY, "false");
353
Adam Cohen446e9402011-09-15 18:21:21 -0700354 // On large interfaces, we want the screen to auto-rotate based on the current orientation
Adam Cohen23a4d302011-12-01 17:26:44 -0800355 if (LauncherApplication.isScreenLarge() || "true".equalsIgnoreCase(forceEnableRotation)) {
Adam Cohen446e9402011-09-15 18:21:21 -0700356 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
357 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800358 }
Romain Guycbb89e42009-06-08 15:52:54 -0700359
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800360 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700361 if (sLocaleConfiguration == null) {
362 new AsyncTask<Void, Void, LocaleConfiguration>() {
363 @Override
364 protected LocaleConfiguration doInBackground(Void... unused) {
365 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
366 readConfiguration(Launcher.this, localeConfiguration);
367 return localeConfiguration;
368 }
369
370 @Override
371 protected void onPostExecute(LocaleConfiguration result) {
372 sLocaleConfiguration = result;
373 checkForLocaleChange(); // recursive, but now with a locale configuration
374 }
375 }.execute();
376 return;
377 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700378
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800379 final Configuration configuration = getResources().getConfiguration();
380
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700381 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800382 final String locale = configuration.locale.toString();
383
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700384 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800385 final int mcc = configuration.mcc;
386
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700387 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800388 final int mnc = configuration.mnc;
389
Romain Guy84f296c2009-11-04 15:00:44 -0800390 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800391
Romain Guy84f296c2009-11-04 15:00:44 -0800392 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700393 sLocaleConfiguration.locale = locale;
394 sLocaleConfiguration.mcc = mcc;
395 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700396
Joe Onorato0589f0f2010-02-08 13:44:00 -0800397 mIconCache.flush();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700398
399 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
400 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700401 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700402 public void run() {
403 writeConfiguration(Launcher.this, localeConfiguration);
404 }
405 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700406 }
407 }
408
409 private static class LocaleConfiguration {
410 public String locale;
411 public int mcc = -1;
412 public int mnc = -1;
413 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700414
Romain Guy98d01652009-06-30 16:21:04 -0700415 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
416 DataInputStream in = null;
417 try {
418 in = new DataInputStream(context.openFileInput(PREFERENCES));
419 configuration.locale = in.readUTF();
420 configuration.mcc = in.readInt();
421 configuration.mnc = in.readInt();
422 } catch (FileNotFoundException e) {
423 // Ignore
424 } catch (IOException e) {
425 // Ignore
426 } finally {
427 if (in != null) {
428 try {
429 in.close();
430 } catch (IOException e) {
431 // Ignore
432 }
433 }
434 }
435 }
436
437 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
438 DataOutputStream out = null;
439 try {
440 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
441 out.writeUTF(configuration.locale);
442 out.writeInt(configuration.mcc);
443 out.writeInt(configuration.mnc);
444 out.flush();
445 } catch (FileNotFoundException e) {
446 // Ignore
447 } catch (IOException e) {
448 //noinspection ResultOfMethodCallIgnored
449 context.getFileStreamPath(PREFERENCES).delete();
450 } finally {
451 if (out != null) {
452 try {
453 out.close();
454 } catch (IOException e) {
455 // Ignore
456 }
457 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800458 }
459 }
460
Adam Cohen716b51e2011-06-30 12:09:54 -0700461 public DragLayer getDragLayer() {
462 return mDragLayer;
463 }
464
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800465 static int getScreen() {
466 synchronized (sLock) {
467 return sScreen;
468 }
469 }
470
471 static void setScreen(int screen) {
472 synchronized (sLock) {
473 sScreen = screen;
474 }
475 }
476
Winson Chung557d6ed2011-07-08 15:34:52 -0700477 /**
478 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
479 * a configuration step, this allows the proper animations to run after other transitions.
480 */
481 private boolean completeAdd(PendingAddArguments args) {
Winson Chungb8472bb2011-08-05 13:49:21 -0700482 boolean result = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800483 switch (args.requestCode) {
484 case REQUEST_PICK_APPLICATION:
Winson Chung3d503fb2011-07-13 17:25:49 -0700485 completeAddApplication(args.intent, args.container, args.screen, args.cellX,
486 args.cellY);
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800487 break;
488 case REQUEST_PICK_SHORTCUT:
489 processShortcut(args.intent);
490 break;
491 case REQUEST_CREATE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -0700492 completeAddShortcut(args.intent, args.container, args.screen, args.cellX,
493 args.cellY);
Winson Chungb8472bb2011-08-05 13:49:21 -0700494 result = true;
495 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800496 case REQUEST_PICK_APPWIDGET:
497 addAppWidgetFromPick(args.intent);
498 break;
499 case REQUEST_CREATE_APPWIDGET:
500 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Winson Chung3d503fb2011-07-13 17:25:49 -0700501 completeAddAppWidget(appWidgetId, args.container, args.screen);
Winson Chungb8472bb2011-08-05 13:49:21 -0700502 result = true;
503 break;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800504 case REQUEST_PICK_WALLPAPER:
505 // We just wanted the activity result here so we can clear mWaitingForResult
506 break;
507 }
Winson Chungb8472bb2011-08-05 13:49:21 -0700508 // In any situation where we have a multi-step drop, we should reset the add info only after
509 // we complete the drop
510 resetAddInfo();
511 return result;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800512 }
513
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800514 @Override
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800515 protected void onActivityResult(final int requestCode, int resultCode, final Intent data) {
Winson Chung557d6ed2011-07-08 15:34:52 -0700516 boolean delayExitSpringLoadedMode = false;
Romain Guyaad5ef42009-06-10 02:48:37 -0700517 mWaitingForResult = false;
518
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800519 // The pattern used here is that a user PICKs a specific application,
520 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700521
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800522 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
523 // launch over to the Music app to actually CREATE_SHORTCUT.
Winson Chungc7da5552011-08-10 15:28:45 -0700524 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800525 final PendingAddArguments args = new PendingAddArguments();
526 args.requestCode = requestCode;
527 args.intent = data;
Winson Chung3d503fb2011-07-13 17:25:49 -0700528 args.container = mPendingAddInfo.container;
529 args.screen = mPendingAddInfo.screen;
530 args.cellX = mPendingAddInfo.cellX;
531 args.cellY = mPendingAddInfo.cellY;
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800532
533 // If the loader is still running, defer the add until it is done.
534 if (isWorkspaceLocked()) {
535 sPendingAddList.add(args);
536 } else {
Winson Chung557d6ed2011-07-08 15:34:52 -0700537 delayExitSpringLoadedMode = completeAdd(args);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800538 }
Romain Guy18042c82009-11-06 11:44:55 -0800539 } else if ((requestCode == REQUEST_PICK_APPWIDGET ||
Winson Chung557d6ed2011-07-08 15:34:52 -0700540 requestCode == REQUEST_CREATE_APPWIDGET) && resultCode == RESULT_CANCELED) {
541 if (data != null) {
542 // Clean up the appWidgetId if we canceled
543 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
544 if (appWidgetId != -1) {
545 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
546 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800547 }
548 }
Winson Chung557d6ed2011-07-08 15:34:52 -0700549
550 // Exit spring loaded mode if necessary after cancelling the configuration of a widget
Winson Chung6a3fd3f2011-08-02 14:03:26 -0700551 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800552 }
553
554 @Override
555 protected void onResume() {
556 super.onResume();
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800557 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700558 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400559 mWorkspaceLoading = true;
560 mModel.startLoader(this, true);
561 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700562 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800563 }
Winson Chunge4e50662012-01-23 14:45:13 -0800564
565 // Reset the pressed state of icons that were locked in the press state while activities
566 // were launching
Michael Jurkaddd62e92011-02-16 17:49:14 -0800567 if (mWaitingForResume != null) {
Winson Chunge4e50662012-01-23 14:45:13 -0800568 // Resets the previous workspace icon press state
Michael Jurkaddd62e92011-02-16 17:49:14 -0800569 mWaitingForResume.setStayPressed(false);
570 }
Winson Chunge4e50662012-01-23 14:45:13 -0800571 if (mAppsCustomizeContent != null) {
572 // Resets the previous all apps icon press state
573 mAppsCustomizeContent.resetDrawableState();
574 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700575 // When we resume Launcher, a different Activity might be responsible for the app
576 // market intent, so refresh the icon
577 updateAppMarketIcon();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800578 }
579
580 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700581 protected void onPause() {
582 super.onPause();
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700583 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800584 mDragController.cancelDrag();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700585 }
Romain Guycbb89e42009-06-08 15:52:54 -0700586
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700587 @Override
588 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400589 // Flag the loader to stop early before switching
590 mModel.stopLoader();
Winson Chung785d2eb2011-04-14 16:08:02 -0700591 if (mAppsCustomizeContent != null) {
592 mAppsCustomizeContent.surrender();
593 }
Romain Guy13c2e7b2010-03-10 19:45:00 -0800594 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700595 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700596
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800597 // We can't hide the IME if it was forced open. So don't bother
598 /*
599 @Override
600 public void onWindowFocusChanged(boolean hasFocus) {
601 super.onWindowFocusChanged(hasFocus);
602
603 if (hasFocus) {
604 final InputMethodManager inputManager = (InputMethodManager)
605 getSystemService(Context.INPUT_METHOD_SERVICE);
606 WindowManager.LayoutParams lp = getWindow().getAttributes();
607 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
608 android.os.Handler()) {
609 protected void onReceiveResult(int resultCode, Bundle resultData) {
610 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
611 }
612 });
613 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
614 }
615 }
616 */
617
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800618 private boolean acceptFilter() {
619 final InputMethodManager inputManager = (InputMethodManager)
620 getSystemService(Context.INPUT_METHOD_SERVICE);
621 return !inputManager.isFullscreenMode();
622 }
623
624 @Override
625 public boolean onKeyDown(int keyCode, KeyEvent event) {
Winson Chung97d85d22011-04-13 11:27:36 -0700626 final int uniChar = event.getUnicodeChar();
627 final boolean handled = super.onKeyDown(keyCode, event);
628 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
629 if (!handled && acceptFilter() && isKeyNotWhitespace) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800630 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
631 keyCode, event);
632 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700633 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700634 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700635 // showSearchDialog()
636 // If there are multiple keystrokes before the search dialog takes focus,
637 // onSearchRequested() will be called for every keystroke,
638 // but it is idempotent, so it's fine.
639 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800640 }
641 }
642
Joe Onorato8a9625e2010-01-28 15:55:35 -0800643 // Eat the long press event so the keyboard doesn't come up.
644 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
645 return true;
646 }
647
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800648 return handled;
649 }
650
Karl Rosaen138a0412009-04-23 19:00:21 -0700651 private String getTypedText() {
652 return mDefaultKeySsb.toString();
653 }
654
655 private void clearTypedText() {
656 mDefaultKeySsb.clear();
657 mDefaultKeySsb.clearSpans();
658 Selection.setSelection(mDefaultKeySsb, 0);
659 }
660
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800661 /**
Michael Jurka883f55b2010-10-21 15:47:14 -0700662 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
663 * State
664 */
665 private static State intToState(int stateOrdinal) {
666 State state = State.WORKSPACE;
667 final State[] stateValues = State.values();
668 for (int i = 0; i < stateValues.length; i++) {
669 if (stateValues[i].ordinal() == stateOrdinal) {
670 state = stateValues[i];
671 break;
672 }
673 }
674 return state;
675 }
676
677 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800678 * Restores the previous state, if it exists.
679 *
680 * @param savedState The previous state.
681 */
682 private void restoreState(Bundle savedState) {
683 if (savedState == null) {
684 return;
685 }
686
Michael Jurka883f55b2010-10-21 15:47:14 -0700687 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
Winson Chungf0ea4d32011-06-06 14:27:16 -0700688 if (state == State.APPS_CUSTOMIZE) {
Joe Onorato3a8820b2009-11-10 15:06:42 -0800689 showAllApps(false);
690 }
691
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800692 final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
693 if (currentScreen > -1) {
Michael Jurka0142d492010-08-25 17:46:15 -0700694 mWorkspace.setCurrentPage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800695 }
696
Winson Chung3d503fb2011-07-13 17:25:49 -0700697 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
698 final int pendingAddScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700699
Winson Chung3d503fb2011-07-13 17:25:49 -0700700 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
701 mPendingAddInfo.container = pendingAddContainer;
702 mPendingAddInfo.screen = pendingAddScreen;
703 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
704 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800705 mRestoring = true;
706 }
707
708 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
709 if (renameFolder) {
710 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700711 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800712 mRestoring = true;
713 }
Winson Chunga12a2502010-12-20 14:41:35 -0800714
Winson Chung785d2eb2011-04-14 16:08:02 -0700715
716 // Restore the AppsCustomize tab
717 if (mAppsCustomizeTabHost != null) {
718 String curTab = savedState.getString("apps_customize_currentTab");
719 if (curTab != null) {
Winson Chungf0ea4d32011-06-06 14:27:16 -0700720 // We set this directly so that there is no delay before the tab is set
Winson Chung785d2eb2011-04-14 16:08:02 -0700721 mAppsCustomizeContent.setContentType(
722 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
723 mAppsCustomizeTabHost.setCurrentTabByTag(curTab);
Winson Chungf314b0e2011-08-16 11:54:27 -0700724 mAppsCustomizeContent.loadAssociatedPages(
725 mAppsCustomizeContent.getCurrentPage());
Winson Chung785d2eb2011-04-14 16:08:02 -0700726 }
727
Winson Chung5afbf7b2011-07-25 11:53:08 -0700728 int currentIndex = savedState.getInt("apps_customize_currentIndex");
729 mAppsCustomizeContent.restorePageForIndex(currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -0700730 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800731 }
732
733 /**
734 * Finds all the views we need and configure them properly.
735 */
736 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700737 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -0400738
Winson Chung4c98d922011-05-31 16:50:48 -0700739 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
740 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
Michael Jurkab737ee62011-11-15 15:57:22 -0800741 mQsbDivider = (ImageView) findViewById(R.id.qsb_divider);
742 mDockDivider = (ImageView) findViewById(R.id.dock_divider);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800743
Winson Chung4c98d922011-05-31 16:50:48 -0700744 // Setup the drag layer
745 mDragLayer.setup(this, dragController);
746
Winson Chung3d503fb2011-07-13 17:25:49 -0700747 // Setup the hotseat
748 mHotseat = (Hotseat) findViewById(R.id.hotseat);
749 if (mHotseat != null) {
750 mHotseat.setup(this);
751 }
752
Winson Chung4c98d922011-05-31 16:50:48 -0700753 // Setup the workspace
754 mWorkspace.setHapticFeedbackEnabled(false);
755 mWorkspace.setOnLongClickListener(this);
Adam Cohencff6af82011-09-13 14:51:53 -0700756 mWorkspace.setup(dragController);
Michael Jurkad74c9842011-07-10 12:44:21 -0700757 dragController.addDragListener(mWorkspace);
Winson Chung4c98d922011-05-31 16:50:48 -0700758
Winson Chungf0ea4d32011-06-06 14:27:16 -0700759 // Get the search/delete bar
Winson Chungc51db6a2011-10-05 11:44:49 -0700760 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700761
Winson Chungf0ea4d32011-06-06 14:27:16 -0700762 // Setup AppsCustomize
763 mAppsCustomizeTabHost = (AppsCustomizeTabHost)
764 findViewById(R.id.apps_customize_pane);
765 mAppsCustomizeContent = (AppsCustomizePagedView)
766 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
767 mAppsCustomizeContent.setup(this, dragController);
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400768
Michael Jurka5130e402011-10-13 04:55:35 -0700769 // Get the all apps button
770 mAllAppsButton = findViewById(R.id.all_apps_button);
771 if (mAllAppsButton != null) {
772 mAllAppsButton.setOnTouchListener(new View.OnTouchListener() {
773 @Override
774 public boolean onTouch(View v, MotionEvent event) {
775 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
776 onTouchDownAllAppsButton(v);
777 }
778 return false;
779 }
780 });
781 }
Winson Chung3d503fb2011-07-13 17:25:49 -0700782 // Setup the drag controller (drop targets have to be added in reverse order in priority)
Winson Chung4c98d922011-05-31 16:50:48 -0700783 dragController.setDragScoller(mWorkspace);
784 dragController.setScrollView(mDragLayer);
785 dragController.setMoveTarget(mWorkspace);
786 dragController.addDropTarget(mWorkspace);
Winson Chungc51db6a2011-10-05 11:44:49 -0700787 if (mSearchDropTargetBar != null) {
788 mSearchDropTargetBar.setup(this, dragController);
Michael Jurkae0f5a612011-02-07 16:45:41 -0800789 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800790 }
791
792 /**
793 * Creates a view representing a shortcut.
794 *
795 * @param info The data structure describing the shortcut.
796 *
797 * @return A View inflated from R.layout.application.
798 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800799 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800800 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -0700801 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800802 }
803
804 /**
805 * Creates a view representing a shortcut inflated from the specified resource.
806 *
807 * @param layoutResId The id of the XML layout used to create the shortcut.
808 * @param parent The group the shortcut belongs to.
809 * @param info The data structure describing the shortcut.
810 *
811 * @return A View inflated from layoutResId.
812 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800813 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -0800814 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
815 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800816 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800817 return favorite;
818 }
819
820 /**
821 * Add an application shortcut to the workspace.
822 *
823 * @param data The intent describing the application.
824 * @param cellInfo The position on screen where to create the shortcut.
825 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700826 void completeAddApplication(Intent data, long container, int screen, int cellX, int cellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700827 final int[] cellXY = mTmpAddItemCellCoordinates;
Winson Chung3d503fb2011-07-13 17:25:49 -0700828 final CellLayout layout = getCellLayout(container, screen);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700829
Adam Cohenfbba09b2011-07-18 21:43:05 -0700830 // First we check if we already know the exact location where we want to add this item.
831 if (cellX >= 0 && cellY >= 0) {
832 cellXY[0] = cellX;
833 cellXY[1] = cellY;
834 } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700835 showOutOfSpaceMessage();
836 return;
837 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800838
Patrick Dubroy002cbf42011-03-03 16:36:21 -0800839 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800840
Romain Guy73b979d2009-06-09 12:57:21 -0700841 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -0800842 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800843 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800844 info.container = ItemInfo.NO_ID;
Winson Chung3d503fb2011-07-13 17:25:49 -0700845 mWorkspace.addApplicationShortcut(info, layout, container, screen, cellXY[0], cellXY[1],
Adam Cohenfbba09b2011-07-18 21:43:05 -0700846 isWorkspaceLocked(), cellX, cellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800847 } else {
848 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800849 }
850 }
Romain Guycbb89e42009-06-08 15:52:54 -0700851
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800852 /**
853 * Add a shortcut to the workspace.
854 *
855 * @param data The intent describing the shortcut.
856 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800857 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700858 private void completeAddShortcut(Intent data, long container, int screen, int cellX,
859 int cellY) {
860 int[] cellXY = mTmpAddItemCellCoordinates;
861 int[] touchXY = mPendingAddInfo.dropPos;
862 CellLayout layout = getCellLayout(container, screen);
Romain Guycbb89e42009-06-08 15:52:54 -0700863
Michael Jurkad3ef3062010-11-23 16:23:58 -0800864 boolean foundCellSpan = false;
Adam Cohenfbba09b2011-07-18 21:43:05 -0700865
Adam Cohen558baaf2011-08-15 15:22:57 -0700866 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
Adam Cohend9198822011-11-22 16:42:47 -0800867 if (info == null) {
868 return;
869 }
Adam Cohen558baaf2011-08-15 15:22:57 -0700870 final View view = createShortcut(info);
871
Adam Cohenfbba09b2011-07-18 21:43:05 -0700872 // First we check if we already know the exact location where we want to add this item.
873 if (cellX >= 0 && cellY >= 0) {
874 cellXY[0] = cellX;
875 cellXY[1] = cellY;
876 foundCellSpan = true;
Adam Cohen558baaf2011-08-15 15:22:57 -0700877
878 // If appropriate, either create a folder or add to an existing folder
879 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY,
880 true, null,null)) {
881 return;
882 }
883 DragObject dragObject = new DragObject();
884 dragObject.dragInfo = info;
885 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, dragObject, true)) {
886 return;
887 }
Adam Cohenfbba09b2011-07-18 21:43:05 -0700888 } else if (touchXY != null) {
Michael Jurkad3ef3062010-11-23 16:23:58 -0800889 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -0700890 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -0800891 foundCellSpan = (result != null);
892 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -0700893 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
Michael Jurkad3ef3062010-11-23 16:23:58 -0800894 }
895
896 if (!foundCellSpan) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700897 showOutOfSpaceMessage();
898 return;
899 }
900
Adam Cohen558baaf2011-08-15 15:22:57 -0700901 LauncherModel.addItemToDatabase(this, info, container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800902
903 if (!mRestoring) {
Winson Chung3d503fb2011-07-13 17:25:49 -0700904 mWorkspace.addInScreen(view, container, screen, cellXY[0], cellXY[1], 1, 1,
905 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800906 }
907 }
908
Adam Cohenf814aa02011-09-01 13:48:05 -0700909 int[] getSpanForWidget(ComponentName component, int minWidth, int minHeight, int[] spanXY) {
910 if (spanXY == null) {
911 spanXY = new int[2];
912 }
913
Adam Cohen0cf2a7c2011-11-08 15:07:01 -0800914 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(this, component, null);
Adam Cohenf814aa02011-09-01 13:48:05 -0700915 // We want to account for the extra amount of padding that we are adding to the widget
916 // to ensure that it gets the full amount of space that it has requested
917 int requiredWidth = minWidth + padding.left + padding.right;
918 int requiredHeight = minHeight + padding.top + padding.bottom;
919 return CellLayout.rectToCell(getResources(), requiredWidth, requiredHeight, null);
920 }
921
922 int[] getSpanForWidget(AppWidgetProviderInfo info, int[] spanXY) {
923 return getSpanForWidget(info.provider, info.minWidth, info.minHeight, spanXY);
924 }
925
Adam Cohencbf47e32011-09-16 17:32:37 -0700926 int[] getMinResizeSpanForWidget(AppWidgetProviderInfo info, int[] spanXY) {
927 return getSpanForWidget(info.provider, info.minResizeWidth, info.minResizeHeight, spanXY);
928 }
929
Adam Cohenf814aa02011-09-01 13:48:05 -0700930 int[] getSpanForWidget(PendingAddWidgetInfo info, int[] spanXY) {
931 return getSpanForWidget(info.componentName, info.minWidth, info.minHeight, spanXY);
932 }
933
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800934 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700935 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800936 *
Romain Guy5bbc91b2010-08-18 11:38:46 -0700937 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700938 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800939 */
Winson Chung3d503fb2011-07-13 17:25:49 -0700940 private void completeAddAppWidget(final int appWidgetId, long container, int screen) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700941 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Romain Guycbb89e42009-06-08 15:52:54 -0700942
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700943 // Calculate the grid spans needed to fit this widget
Winson Chung3d503fb2011-07-13 17:25:49 -0700944 CellLayout layout = getCellLayout(container, screen);
Adam Cohen09353862011-07-14 16:10:03 -0700945
Adam Cohenf814aa02011-09-01 13:48:05 -0700946 int[] spanXY = getSpanForWidget(appWidgetInfo, null);
Romain Guycbb89e42009-06-08 15:52:54 -0700947
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800948 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -0700949 // We have saved the position to which the widget was dragged-- this really only matters
950 // if we are placing widgets on a "spring-loaded" screen
Winson Chung3d503fb2011-07-13 17:25:49 -0700951 int[] cellXY = mTmpAddItemCellCoordinates;
952 int[] touchXY = mPendingAddInfo.dropPos;
Michael Jurka0280c3b2010-09-17 15:00:07 -0700953 boolean foundCellSpan = false;
Winson Chung3d503fb2011-07-13 17:25:49 -0700954 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
955 cellXY[0] = mPendingAddInfo.cellX;
956 cellXY[1] = mPendingAddInfo.cellY;
Adam Cohenfbba09b2011-07-18 21:43:05 -0700957 foundCellSpan = true;
958 } else if (touchXY != null) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700959 // when dragging and dropping, just find the closest free spot
Winson Chung3d503fb2011-07-13 17:25:49 -0700960 int[] result = layout.findNearestVacantArea(
Michael Jurka0280c3b2010-09-17 15:00:07 -0700961 touchXY[0], touchXY[1], spanXY[0], spanXY[1], cellXY);
Michael Jurkad3ef3062010-11-23 16:23:58 -0800962 foundCellSpan = (result != null);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700963 } else {
Adam Cohenfbba09b2011-07-18 21:43:05 -0700964 foundCellSpan = layout.findCellForSpan(cellXY, spanXY[0], spanXY[1]);
Michael Jurkaa63c4522010-08-19 13:52:27 -0700965 }
966
Michael Jurka0280c3b2010-09-17 15:00:07 -0700967 if (!foundCellSpan) {
Winson Chungf7640c82011-02-28 13:47:29 -0800968 if (appWidgetId != -1) {
969 // Deleting an app widget ID is a void call but writes to disk before returning
970 // to the caller...
Winson Chungf7640c82011-02-28 13:47:29 -0800971 new Thread("deleteAppWidgetId") {
972 public void run() {
973 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
974 }
975 }.start();
976 }
Michael Jurka0280c3b2010-09-17 15:00:07 -0700977 showOutOfSpaceMessage();
Romain Guy18042c82009-11-06 11:44:55 -0800978 return;
979 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800980
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700981 // Build Launcher-specific widget info and save to database
Michael Jurkac9d95c52011-08-29 14:03:34 -0700982 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700983 launcherInfo.spanX = spanXY[0];
984 launcherInfo.spanY = spanXY[1];
Romain Guycbb89e42009-06-08 15:52:54 -0700985
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800986 LauncherModel.addItemToDatabase(this, launcherInfo,
Winson Chung3d503fb2011-07-13 17:25:49 -0700987 container, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800988
989 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800990 // Perform actual inflation because we're live
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700991 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -0700992
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700993 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800994 launcherInfo.hostView.setTag(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -0700995
Winson Chung3d503fb2011-07-13 17:25:49 -0700996 mWorkspace.addInScreen(launcherInfo.hostView, container, screen, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -0400997 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -0700998
999 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001000 }
1001 }
Romain Guycbb89e42009-06-08 15:52:54 -07001002
Adam Cohended9f8d2010-11-03 13:25:16 -07001003 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1004 @Override
1005 public void onReceive(Context context, Intent intent) {
1006 final String action = intent.getAction();
1007 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1008 mUserPresent = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001009 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001010 updateRunning();
Winson Chung337cd9d2011-03-30 10:39:30 -07001011
Winson Chungc100e8e2011-08-09 16:02:43 -07001012 // Reset AllApps to its initial state only if we are not in the middle of
Winson Chungb8472bb2011-08-05 13:49:21 -07001013 // processing a multi-step drop
Winson Chungc100e8e2011-08-09 16:02:43 -07001014 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
1015 mAppsCustomizeTabHost.reset();
1016 showWorkspace(false);
Winson Chung785d2eb2011-04-14 16:08:02 -07001017 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001018 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1019 mUserPresent = true;
1020 updateRunning();
1021 }
1022 }
1023 };
1024
1025 @Override
1026 public void onAttachedToWindow() {
1027 super.onAttachedToWindow();
1028
1029 // Listen for broadcasts related to user-presence
1030 final IntentFilter filter = new IntentFilter();
1031 filter.addAction(Intent.ACTION_SCREEN_OFF);
1032 filter.addAction(Intent.ACTION_USER_PRESENT);
1033 registerReceiver(mReceiver, filter);
1034
Adam Cohend113e0c2010-11-11 10:48:05 -08001035 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001036 mVisible = true;
1037 }
1038
1039 @Override
1040 public void onDetachedFromWindow() {
1041 super.onDetachedFromWindow();
1042 mVisible = false;
Adam Cohenbec6ac52011-07-19 20:50:27 -07001043 mDragLayer.clearAllResizeFrames();
Adam Cohended9f8d2010-11-03 13:25:16 -07001044
Adam Cohend113e0c2010-11-11 10:48:05 -08001045 if (mAttached) {
1046 unregisterReceiver(mReceiver);
1047 mAttached = false;
1048 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001049 updateRunning();
1050 }
1051
1052 public void onWindowVisibilityChanged(int visibility) {
1053 mVisible = visibility == View.VISIBLE;
1054 updateRunning();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001055 // The following code used to be in onResume, but it turns out onResume is called when
1056 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1057 // is a more appropriate event to handle
1058 if (mVisible) {
1059 mAppsCustomizeTabHost.onWindowVisible();
1060 if (!mWorkspaceLoading) {
1061 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08001062 // We want to let Launcher draw itself at least once before we force it to build
1063 // layers on all the workspace pages, so that transitioning to Launcher from other
1064 // apps is nice and speedy. Usually the first call to preDraw doesn't correspond to
1065 // a true draw so we wait until the second preDraw call to be safe
1066 observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
1067 boolean mFirstTime = true;
1068 public boolean onPreDraw() {
1069 if (mFirstTime) {
1070 mFirstTime = false;
1071 } else {
1072 //workspace.post(mBuildLayersRunnable);
1073 observer.removeOnPreDrawListener(this);
1074 }
1075 return true;
1076 }
1077 });
1078 }
1079 clearTypedText();
1080 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001081 }
1082
1083 private void sendAdvanceMessage(long delay) {
1084 mHandler.removeMessages(ADVANCE_MSG);
1085 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1086 mHandler.sendMessageDelayed(msg, delay);
1087 mAutoAdvanceSentTime = System.currentTimeMillis();
1088 }
1089
1090 private void updateRunning() {
1091 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1092 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1093 mAutoAdvanceRunning = autoAdvanceRunning;
1094 if (autoAdvanceRunning) {
1095 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1096 sendAdvanceMessage(delay);
1097 } else {
1098 if (!mWidgetsToAdvance.isEmpty()) {
1099 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1100 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1101 }
1102 mHandler.removeMessages(ADVANCE_MSG);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001103 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
Adam Cohended9f8d2010-11-03 13:25:16 -07001104 }
1105 }
1106 }
1107
1108 private final Handler mHandler = new Handler() {
1109 @Override
1110 public void handleMessage(Message msg) {
1111 if (msg.what == ADVANCE_MSG) {
1112 int i = 0;
1113 for (View key: mWidgetsToAdvance.keySet()) {
1114 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1115 final int delay = mAdvanceStagger * i;
1116 if (v instanceof Advanceable) {
1117 postDelayed(new Runnable() {
1118 public void run() {
1119 ((Advanceable) v).advance();
1120 }
1121 }, delay);
1122 }
1123 i++;
1124 }
1125 sendAdvanceMessage(mAdvanceInterval);
1126 }
1127 }
1128 };
1129
1130 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
Adam Cohen292c0252011-07-18 13:55:17 -07001131 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
Adam Cohended9f8d2010-11-03 13:25:16 -07001132 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1133 if (v instanceof Advanceable) {
1134 mWidgetsToAdvance.put(hostView, appWidgetInfo);
Adam Cohen2ddf13e2011-01-19 21:26:33 -08001135 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
Adam Cohended9f8d2010-11-03 13:25:16 -07001136 updateRunning();
1137 }
1138 }
1139
1140 void removeWidgetToAutoAdvance(View hostView) {
1141 if (mWidgetsToAdvance.containsKey(hostView)) {
1142 mWidgetsToAdvance.remove(hostView);
1143 updateRunning();
1144 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001145 }
1146
Joe Onorato9c1289c2009-08-17 11:03:03 -04001147 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
Adam Cohended9f8d2010-11-03 13:25:16 -07001148 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001149 launcherInfo.hostView = null;
1150 }
1151
Adam Cohended9f8d2010-11-03 13:25:16 -07001152 void showOutOfSpaceMessage() {
1153 Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show();
1154 }
1155
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001156 public LauncherAppWidgetHost getAppWidgetHost() {
1157 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001158 }
Romain Guycbb89e42009-06-08 15:52:54 -07001159
Winson Chunga9abd0e2010-10-27 17:18:37 -07001160 public LauncherModel getModel() {
1161 return mModel;
1162 }
1163
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001164 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001165 getWindow().closeAllPanels();
1166
Winson Chung87acb482011-08-23 17:28:05 -07001167 /**
1168 * We should remove this code when we remove all the dialog code.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001169 try {
1170 dismissDialog(DIALOG_CREATE_SHORTCUT);
1171 // Unlock the workspace if the dialog was showing
1172 } catch (Exception e) {
1173 // An exception is thrown if the dialog is not visible, which is fine
1174 }
1175
1176 try {
1177 dismissDialog(DIALOG_RENAME_FOLDER);
1178 // Unlock the workspace if the dialog was showing
1179 } catch (Exception e) {
1180 // An exception is thrown if the dialog is not visible, which is fine
1181 }
Winson Chung87acb482011-08-23 17:28:05 -07001182 */
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001183
1184 // Whatever we were doing is hereby canceled.
1185 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001186 }
1187
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001188 @Override
1189 protected void onNewIntent(Intent intent) {
1190 super.onNewIntent(intent);
1191
1192 // Close the menu
1193 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001194 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001195 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001196
Joe Onorato14f122b2009-11-19 14:06:36 -08001197 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1198 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001199
Adam Cohenac56cff2011-09-28 20:45:37 -07001200 Folder openFolder = mWorkspace.getOpenFolder();
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001201 // In all these cases, only animate if we're already on home
Patrick Dubroy758a9232011-03-03 19:54:56 -08001202 mWorkspace.exitWidgetResizeMode();
Adam Cohenac56cff2011-09-28 20:45:37 -07001203 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1204 openFolder == null) {
Patrick Dubroy6ec2e182011-02-23 13:31:16 -08001205 mWorkspace.moveToDefaultScreen(true);
Joe Onorato3a8820b2009-11-10 15:06:42 -08001206 }
Adam Cohenac56cff2011-09-28 20:45:37 -07001207
1208 closeFolder();
Winson Chungde1af762011-07-21 16:44:07 -07001209 exitSpringLoadedDragMode();
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001210 showWorkspace(alreadyOnHome);
Romain Guy1dd3a072009-07-16 13:21:01 -07001211
Joe Onorato3a8820b2009-11-10 15:06:42 -08001212 final View v = getWindow().peekDecorView();
1213 if (v != null && v.getWindowToken() != null) {
1214 InputMethodManager imm = (InputMethodManager)getSystemService(
1215 INPUT_METHOD_SERVICE);
1216 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001217 }
Winson Chung337cd9d2011-03-30 10:39:30 -07001218
Michael Jurka35aa14d2011-07-07 17:01:08 -07001219 // Reset AllApps to its initial state
Adam Cohenb64d36e2011-10-17 21:48:02 -07001220 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
Winson Chungc100e8e2011-08-09 16:02:43 -07001221 mAppsCustomizeTabHost.reset();
Winson Chung785d2eb2011-04-14 16:08:02 -07001222 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001223 }
1224 }
1225
1226 @Override
1227 protected void onRestoreInstanceState(Bundle savedInstanceState) {
1228 // Do not call super here
1229 mSavedInstanceState = savedInstanceState;
1230 }
1231
1232 @Override
1233 protected void onSaveInstanceState(Bundle outState) {
Michael Jurka0142d492010-08-25 17:46:15 -07001234 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage());
Adam Cohen95bb8002011-07-03 23:40:28 -07001235 super.onSaveInstanceState(outState);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001236
Michael Jurka883f55b2010-10-21 15:47:14 -07001237 outState.putInt(RUNTIME_STATE, mState.ordinal());
Adam Cohen51e95032011-07-11 14:44:19 -07001238 // We close any open folder since it will not be re-opened, and we need to make sure
1239 // this state is reflected.
1240 closeFolder();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001241
Winson Chung3d503fb2011-07-13 17:25:49 -07001242 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screen > -1 &&
1243 mWaitingForResult) {
1244 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
1245 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screen);
1246 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
1247 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001248 }
1249
1250 if (mFolderInfo != null && mWaitingForResult) {
1251 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1252 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1253 }
Michael Jurka946ad472010-07-09 18:05:18 -07001254
Winson Chung785d2eb2011-04-14 16:08:02 -07001255 // Save the current AppsCustomize tab
1256 if (mAppsCustomizeTabHost != null) {
1257 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
1258 if (currentTabTag != null) {
1259 outState.putString("apps_customize_currentTab", currentTabTag);
1260 }
Winson Chung5afbf7b2011-07-25 11:53:08 -07001261 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
1262 outState.putInt("apps_customize_currentIndex", currentIndex);
Winson Chung785d2eb2011-04-14 16:08:02 -07001263 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001264 }
1265
1266 @Override
1267 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001268 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001269
Winson Chunge7a03942011-08-05 15:05:12 -07001270 // Remove all pending runnables
1271 mHandler.removeMessages(ADVANCE_MSG);
1272 mHandler.removeMessages(0);
Michael Jurka9d906c72011-10-14 06:25:36 -07001273 mWorkspace.removeCallbacks(mBuildLayersRunnable);
Winson Chunge7a03942011-08-05 15:05:12 -07001274
Winson Chungcd2b0142011-06-08 16:02:26 -07001275 // Stop callbacks from LauncherModel
1276 LauncherApplication app = ((LauncherApplication) getApplication());
1277 mModel.stopLoader();
1278 app.setLauncher(null);
1279
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001280 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001281 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001282 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001283 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001284 }
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001285 mAppWidgetHost = null;
1286
1287 mWidgetsToAdvance.clear();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001288
1289 TextKeyListener.getInstance().release();
1290
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001291
Winson Chung3d503fb2011-07-13 17:25:49 -07001292 unbindWorkspaceAndHotseatItems();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001293
1294 getContentResolver().unregisterContentObserver(mWidgetObserver);
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001295 unregisterReceiver(mCloseSystemDialogsReceiver);
Patrick Dubroy2313eff2011-01-11 20:01:31 -08001296
1297 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
1298 mWorkspace.removeAllViews();
1299 mWorkspace = null;
1300 mDragController = null;
Patrick Dubroy60b7c532011-01-16 17:19:32 -08001301
1302 ValueAnimator.clearAllAnimations();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001303 }
1304
Adam Cohena9cf38f2011-05-02 15:36:58 -07001305 public DragController getDragController() {
1306 return mDragController;
1307 }
1308
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001309 @Override
1310 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001311 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001312 super.startActivityForResult(intent, requestCode);
1313 }
1314
Winson Chung70d72102011-08-12 11:24:35 -07001315 /**
1316 * Indicates that we want global search for this activity by setting the globalSearch
1317 * argument for {@link #startSearch} to true.
1318 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001319 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001320 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001321 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001322
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001323 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001324
Karl Rosaen138a0412009-04-23 19:00:21 -07001325 if (initialQuery == null) {
1326 // Use any text typed in the launcher as the initial query
1327 initialQuery = getTypedText();
Karl Rosaen138a0412009-04-23 19:00:21 -07001328 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001329 if (appSearchData == null) {
1330 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +00001331 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001332 }
Mathew Inwoodcf7f63b2011-10-13 11:31:38 +01001333 Rect sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
Romain Guycbb89e42009-06-08 15:52:54 -07001334
Karl Rosaen138a0412009-04-23 19:00:21 -07001335 final SearchManager searchManager =
1336 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Karl Rosaen138a0412009-04-23 19:00:21 -07001337 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Mathew Inwoodcf7f63b2011-10-13 11:31:38 +01001338 appSearchData, globalSearch, sourceBounds);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001339 }
1340
Winson Chung70d72102011-08-12 11:24:35 -07001341 @Override
1342 public boolean onCreateOptionsMenu(Menu menu) {
1343 if (isWorkspaceLocked()) {
1344 return false;
1345 }
1346
1347 super.onCreateOptionsMenu(menu);
Winson Chungdff8ebb2011-09-08 17:25:31 -07001348
1349 Intent manageApps = new Intent(Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS);
1350 manageApps.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1351 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Winson Chung236d4312011-08-22 15:12:27 -07001352 Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
1353 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1354 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Michael Jurkab964f9c2011-09-27 22:10:05 -07001355 String helpUrl = getString(R.string.help_url);
1356 Intent help = new Intent(Intent.ACTION_VIEW, Uri.parse(helpUrl));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001357 help.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1358 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
1359
Winson Chung70d72102011-08-12 11:24:35 -07001360 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
1361 .setIcon(android.R.drawable.ic_menu_gallery)
1362 .setAlphabeticShortcut('W');
1363 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1364 .setIcon(android.R.drawable.ic_menu_manage)
Winson Chungdff8ebb2011-09-08 17:25:31 -07001365 .setIntent(manageApps)
Winson Chung70d72102011-08-12 11:24:35 -07001366 .setAlphabeticShortcut('M');
Winson Chung236d4312011-08-22 15:12:27 -07001367 menu.add(0, MENU_SYSTEM_SETTINGS, 0, R.string.menu_settings)
1368 .setIcon(android.R.drawable.ic_menu_preferences)
1369 .setIntent(settings)
1370 .setAlphabeticShortcut('P');
Michael Jurkab964f9c2011-09-27 22:10:05 -07001371 if (!helpUrl.isEmpty()) {
1372 menu.add(0, MENU_HELP, 0, R.string.menu_help)
1373 .setIcon(android.R.drawable.ic_menu_help)
1374 .setIntent(help)
1375 .setAlphabeticShortcut('H');
1376 }
Winson Chung70d72102011-08-12 11:24:35 -07001377 return true;
1378 }
1379
1380 @Override
1381 public boolean onPrepareOptionsMenu(Menu menu) {
1382 super.onPrepareOptionsMenu(menu);
1383
1384 if (mAppsCustomizeTabHost.isTransitioning()) {
1385 return false;
1386 }
1387 boolean allAppsVisible = (mAppsCustomizeTabHost.getVisibility() == View.VISIBLE);
1388 menu.setGroupVisible(MENU_GROUP_WALLPAPER, !allAppsVisible);
1389
1390 return true;
1391 }
1392
1393 @Override
1394 public boolean onOptionsItemSelected(MenuItem item) {
1395 switch (item.getItemId()) {
1396 case MENU_WALLPAPER_SETTINGS:
1397 startWallpaper();
1398 return true;
Winson Chung70d72102011-08-12 11:24:35 -07001399 }
1400
1401 return super.onOptionsItemSelected(item);
1402 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001403
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001404 @Override
1405 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001406 startSearch(null, false, null, true);
Amith Yamasania135ba82011-08-09 17:42:01 -07001407 // Use a custom animation for launching search
1408 overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast);
Karl Rosaen138a0412009-04-23 19:00:21 -07001409 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001410 }
1411
Joe Onorato9c1289c2009-08-17 11:03:03 -04001412 public boolean isWorkspaceLocked() {
1413 return mWorkspaceLoading || mWaitingForResult;
1414 }
1415
Michael Jurka0280c3b2010-09-17 15:00:07 -07001416 private void resetAddInfo() {
Winson Chung3d503fb2011-07-13 17:25:49 -07001417 mPendingAddInfo.container = ItemInfo.NO_ID;
1418 mPendingAddInfo.screen = -1;
1419 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
1420 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
1421 mPendingAddInfo.dropPos = null;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001422 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001423
Michael Jurkaaf442092010-06-10 17:01:57 -07001424 void addAppWidgetFromPick(Intent data) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001425 // TODO: catch bad widget exception when sent
1426 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurkaaf442092010-06-10 17:01:57 -07001427 // TODO: Is this log message meaningful?
1428 if (LOGD) Log.d(TAG, "dumping extras content=" + data.getExtras());
Winson Chung55cef262010-10-28 14:14:18 -07001429 addAppWidgetImpl(appWidgetId, null);
Michael Jurkaaf442092010-06-10 17:01:57 -07001430 }
1431
Winson Chung55cef262010-10-28 14:14:18 -07001432 void addAppWidgetImpl(int appWidgetId, PendingAddWidgetInfo info) {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001433 AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001434
Bjorn Bringert7984c942009-12-09 15:38:25 +00001435 if (appWidget.configure != null) {
1436 // Launch over to configure widget, if needed
1437 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
1438 intent.setComponent(appWidget.configure);
1439 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Winson Chung55cef262010-10-28 14:14:18 -07001440 if (info != null) {
Winson Chung68846fd2010-10-29 11:00:27 -07001441 if (info.mimeType != null && !info.mimeType.isEmpty()) {
1442 intent.putExtra(
1443 InstallWidgetReceiver.EXTRA_APPWIDGET_CONFIGURATION_DATA_MIME_TYPE,
1444 info.mimeType);
1445
1446 final String mimeType = info.mimeType;
1447 final ClipData clipData = (ClipData) info.configurationData;
1448 final ClipDescription clipDesc = clipData.getDescription();
1449 for (int i = 0; i < clipDesc.getMimeTypeCount(); ++i) {
1450 if (clipDesc.getMimeType(i).equals(mimeType)) {
Dianne Hackborn0d5aad72011-01-17 15:28:58 -08001451 final ClipData.Item item = clipData.getItemAt(i);
Winson Chung68846fd2010-10-29 11:00:27 -07001452 final CharSequence stringData = item.getText();
1453 final Uri uriData = item.getUri();
1454 final Intent intentData = item.getIntent();
1455 final String key =
1456 InstallWidgetReceiver.EXTRA_APPWIDGET_CONFIGURATION_DATA;
1457 if (uriData != null) {
1458 intent.putExtra(key, uriData);
1459 } else if (intentData != null) {
1460 intent.putExtra(key, intentData);
1461 } else if (stringData != null) {
1462 intent.putExtra(key, stringData);
1463 }
1464 break;
1465 }
1466 }
1467 }
Winson Chung55cef262010-10-28 14:14:18 -07001468 }
Bjorn Bringert7984c942009-12-09 15:38:25 +00001469
Romain Guy8e633c52010-03-04 12:51:36 -08001470 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001471 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001472 // Otherwise just add it
Winson Chung3d503fb2011-07-13 17:25:49 -07001473 completeAddAppWidget(appWidgetId, info.container, info.screen);
Winson Chung557d6ed2011-07-08 15:34:52 -07001474
1475 // Exit spring loaded mode if necessary after adding the widget
Winson Chung6a3fd3f2011-08-02 14:03:26 -07001476 exitSpringLoadedDragModeDelayed(true, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001477 }
1478 }
Romain Guycbb89e42009-06-08 15:52:54 -07001479
Adam Cohenfbba09b2011-07-18 21:43:05 -07001480 /**
1481 * Process a shortcut drop.
1482 *
1483 * @param componentName The name of the component
1484 * @param screen The screen where it should be added
1485 * @param cell The cell it should be added to, optional
1486 * @param position The location on the screen where it was dropped, optional
1487 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001488 void processShortcutFromDrop(ComponentName componentName, long container, int screen,
1489 int[] cell, int[] loc) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001490 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001491 mPendingAddInfo.container = container;
1492 mPendingAddInfo.screen = screen;
1493 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001494
1495 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001496 mPendingAddInfo.cellX = cell[0];
1497 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001498 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001499
1500 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1501 createShortcutIntent.setComponent(componentName);
1502 processShortcut(createShortcutIntent);
1503 }
1504
Adam Cohenfbba09b2011-07-18 21:43:05 -07001505 /**
1506 * Process a widget drop.
1507 *
1508 * @param info The PendingAppWidgetInfo of the widget being added.
1509 * @param screen The screen where it should be added
1510 * @param cell The cell it should be added to, optional
1511 * @param position The location on the screen where it was dropped, optional
1512 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001513 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, int screen,
1514 int[] cell, int[] loc) {
Adam Cohenfbba09b2011-07-18 21:43:05 -07001515 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07001516 mPendingAddInfo.container = info.container = container;
1517 mPendingAddInfo.screen = info.screen = screen;
1518 mPendingAddInfo.dropPos = loc;
Adam Cohenfbba09b2011-07-18 21:43:05 -07001519 if (cell != null) {
Winson Chung3d503fb2011-07-13 17:25:49 -07001520 mPendingAddInfo.cellX = cell[0];
1521 mPendingAddInfo.cellY = cell[1];
Adam Cohenfbba09b2011-07-18 21:43:05 -07001522 }
1523
1524 int appWidgetId = getAppWidgetHost().allocateAppWidgetId();
1525 AppWidgetManager.getInstance(this).bindAppWidgetId(appWidgetId, info.componentName);
1526 addAppWidgetImpl(appWidgetId, info);
1527 }
1528
Joe Onoratodeb98af2010-02-19 14:59:39 -08001529 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001530 // Handle case where user selected "Applications"
1531 String applicationName = getResources().getString(R.string.group_applications);
1532 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001533
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001534 if (applicationName != null && applicationName.equals(shortcutName)) {
1535 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1536 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001537
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001538 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1539 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07001540 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Joe Onorato4a79a042010-09-24 16:17:21 -07001541 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001542 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001543 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001544 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001545 }
1546
Winson Chung24ab2f12010-09-16 14:10:47 -07001547 void processWallpaper(Intent intent) {
1548 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1549 }
1550
Winson Chung3d503fb2011-07-13 17:25:49 -07001551 FolderIcon addFolder(CellLayout layout, long container, final int screen, int cellX,
1552 int cellY) {
Michael Jurkac9d95c52011-08-29 14:03:34 -07001553 final FolderInfo folderInfo = new FolderInfo();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001554 folderInfo.title = getText(R.string.folder_name);
1555
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001556 // Update the model
Winson Chung3d503fb2011-07-13 17:25:49 -07001557 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screen, cellX, cellY,
1558 false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001559 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001560
1561 // Create the view
Winson Chung3d503fb2011-07-13 17:25:49 -07001562 FolderIcon newFolder =
1563 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
1564 mWorkspace.addInScreen(newFolder, container, screen, cellX, cellY, 1, 1,
1565 isWorkspaceLocked());
Adam Cohendf035382011-04-11 17:22:04 -07001566 return newFolder;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001567 }
Romain Guycbb89e42009-06-08 15:52:54 -07001568
Joe Onorato9c1289c2009-08-17 11:03:03 -04001569 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001570 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001571 }
1572
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001573 private void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001574 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001575 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001576 Intent chooser = Intent.createChooser(pickWallpaper,
1577 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001578 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1579 // Removed in Eclair MR1
1580// WallpaperManager wm = (WallpaperManager)
1581// getSystemService(Context.WALLPAPER_SERVICE);
1582// WallpaperInfo wi = wm.getWallpaperInfo();
1583// if (wi != null && wi.getSettingsActivity() != null) {
1584// LabeledIntent li = new LabeledIntent(getPackageName(),
1585// R.string.configure_wallpaper, 0);
1586// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1587// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1588// }
Mike Clerona0618e42009-10-22 13:55:21 -07001589 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001590 }
1591
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001592 /**
1593 * Registers various content observers. The current implementation registers
1594 * only a favorites observer to keep track of the favorites applications.
1595 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001596 private void registerContentObservers() {
1597 ContentResolver resolver = getContentResolver();
1598 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1599 true, mWidgetObserver);
1600 }
1601
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001602 @Override
1603 public boolean dispatchKeyEvent(KeyEvent event) {
1604 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1605 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001606 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001607 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001608 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jason Samseb5615d2009-11-30 11:50:10 -08001609 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
Joe Onoratobe386092009-11-17 17:32:16 -08001610 dumpState();
1611 return true;
1612 }
1613 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001614 }
1615 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1616 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001617 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001618 return true;
1619 }
1620 }
1621
1622 return super.dispatchKeyEvent(event);
1623 }
1624
Joe Onorato88ec0992009-11-19 13:16:06 -08001625 @Override
1626 public void onBackPressed() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07001627 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001628 showWorkspace(true);
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001629 } else if (mWorkspace.getOpenFolder() != null) {
Adam Cohen76fc0852011-06-17 13:26:23 -07001630 Folder openFolder = mWorkspace.getOpenFolder();
1631 if (openFolder.isEditingName()) {
1632 openFolder.dismissEditingName();
1633 } else {
1634 closeFolder();
1635 }
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001636 } else {
Patrick Dubroy758a9232011-03-03 19:54:56 -08001637 mWorkspace.exitWidgetResizeMode();
1638
Patrick Dubroy94f78a52011-02-28 17:39:16 -08001639 // Back button is a no-op here, but give at least some feedback for the button press
1640 mWorkspace.showOutlinesTemporarily();
Michael Jurkaaf442092010-06-10 17:01:57 -07001641 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001642 }
1643
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001644 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001645 * Re-listen when widgets are reset.
1646 */
1647 private void onAppWidgetReset() {
Michael Jurkabbbad6b2011-02-07 13:04:09 -08001648 if (mAppWidgetHost != null) {
1649 mAppWidgetHost.startListening();
1650 }
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001651 }
1652
1653 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001654 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1655 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001656 */
Winson Chung3d503fb2011-07-13 17:25:49 -07001657 private void unbindWorkspaceAndHotseatItems() {
Winson Chung603bcb92011-09-02 11:45:39 -07001658 if (mModel != null) {
1659 mModel.unbindWorkspaceItems();
1660 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001661 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001662
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001663 /**
1664 * Launches the intent referred by the clicked shortcut.
1665 *
1666 * @param v The view representing the clicked shortcut.
1667 */
1668 public void onClick(View v) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001669 // Make sure that rogue clicks don't get through while allapps is launching, or after the
1670 // view has detached (it's possible for this to happen if the view is removed mid touch).
1671 if (v.getWindowToken() == null) {
1672 return;
1673 }
1674
1675 if (mWorkspace.isSwitchingState()) {
1676 return;
1677 }
Adam Cohen2f84ef22011-07-26 17:16:44 -07001678
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001679 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001680 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001681 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08001682 final Intent intent = ((ShortcutInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001683 int[] pos = new int[2];
1684 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08001685 intent.setSourceBounds(new Rect(pos[0], pos[1],
1686 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Michael Jurkaddd62e92011-02-16 17:49:14 -08001687 boolean success = startActivitySafely(intent, tag);
1688
1689 if (success && v instanceof BubbleTextView) {
1690 mWaitingForResume = (BubbleTextView) v;
1691 mWaitingForResume.setStayPressed(true);
1692 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001693 } else if (tag instanceof FolderInfo) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07001694 if (v instanceof FolderIcon) {
1695 FolderIcon fi = (FolderIcon) v;
1696 handleFolderClick(fi);
1697 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07001698 } else if (v == mAllAppsButton) {
1699 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001700 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001701 } else {
Michael Jurka2a552322011-10-11 15:22:05 -07001702 onClickAllAppsButton(v);
Joe Onorato7404ee42009-07-31 11:54:44 -07001703 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001704 }
1705 }
1706
Michael Jurka0e260592010-06-30 17:07:39 -07001707 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07001708 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001709 // clicking anywhere on the workspace causes the customization drawer to slide down
1710 showWorkspace(true);
Michael Jurka0e260592010-06-30 17:07:39 -07001711 return false;
1712 }
1713
Michael Jurkaaf442092010-06-10 17:01:57 -07001714 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001715 * Event handler for the search button
1716 *
1717 * @param v The view that was clicked.
1718 */
1719 public void onClickSearchButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08001720 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
1721
Amith Yamasania135ba82011-08-09 17:42:01 -07001722 onSearchRequested();
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001723 }
1724
1725 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001726 * Event handler for the voice button
1727 *
1728 * @param v The view that was clicked.
1729 */
1730 public void onClickVoiceButton(View v) {
Winson Chungbb185bd2011-11-21 12:31:42 -08001731 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001732
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001733 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
Winson Chungdff8ebb2011-09-08 17:25:31 -07001734 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001735 startActivity(intent);
1736 }
1737
1738 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001739 * Event handler for the "grid" button that appears on the home screen, which
1740 * enters all apps mode.
1741 *
1742 * @param v The view that was clicked.
1743 */
1744 public void onClickAllAppsButton(View v) {
Michael Jurka5130e402011-10-13 04:55:35 -07001745 showAllApps(true);
1746 }
1747
1748 public void onTouchDownAllAppsButton(View v) {
Michael Jurka2a552322011-10-11 15:22:05 -07001749 // Provide the same haptic feedback that the system offers for virtual keys.
1750 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001751 }
1752
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001753 public void onClickAppMarketButton(View v) {
1754 if (mAppMarketIntent != null) {
1755 startActivitySafely(mAppMarketIntent, "app market");
1756 }
1757 }
1758
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001759 void startApplicationDetailsActivity(ComponentName componentName) {
1760 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001761 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
1762 Uri.fromParts("package", packageName, null));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001763 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001764 startActivity(intent);
1765 }
1766
Patrick Dubroy5539af72010-09-07 15:22:01 -07001767 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
1768 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
1769 // System applications cannot be installed. For now, show a toast explaining that.
1770 // We may give them the option of disabling apps this way.
1771 int messageId = R.string.uninstall_system_app_text;
1772 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
1773 } else {
1774 String packageName = appInfo.componentName.getPackageName();
1775 String className = appInfo.componentName.getClassName();
1776 Intent intent = new Intent(
1777 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
Winson Chungdff8ebb2011-09-08 17:25:31 -07001778 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
1779 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Patrick Dubroy5539af72010-09-07 15:22:01 -07001780 startActivity(intent);
1781 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001782 }
1783
Michael Jurkaddd62e92011-02-16 17:49:14 -08001784 boolean startActivitySafely(Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001785 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1786 try {
1787 startActivity(intent);
Michael Jurkaddd62e92011-02-16 17:49:14 -08001788 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001789 } catch (ActivityNotFoundException e) {
1790 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Daniel Sandlerc9b18772010-04-22 14:37:59 -04001791 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001792 } catch (SecurityException e) {
1793 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001794 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001795 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07001796 "or use the exported attribute for this activity. "
1797 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001798 }
Michael Jurkaddd62e92011-02-16 17:49:14 -08001799 return false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001800 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001801
Romain Guy8e633c52010-03-04 12:51:36 -08001802 void startActivityForResultSafely(Intent intent, int requestCode) {
1803 try {
1804 startActivityForResult(intent, requestCode);
1805 } catch (ActivityNotFoundException e) {
1806 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1807 } catch (SecurityException e) {
1808 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1809 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
1810 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
1811 "or use the exported attribute for this activity.", e);
1812 }
1813 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001814
Adam Cohena9cf38f2011-05-02 15:36:58 -07001815 private void handleFolderClick(FolderIcon folderIcon) {
1816 final FolderInfo info = folderIcon.mInfo;
Adam Cohen3c81a382011-08-31 22:25:51 -07001817 Folder openFolder = mWorkspace.getFolderForTag(info);
1818
1819 // If the folder info reports that the associated folder is open, then verify that
1820 // it is actually opened. There have been a few instances where this gets out of sync.
1821 if (info.opened && openFolder == null) {
1822 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
1823 + info.screen + " (" + info.cellX + ", " + info.cellY + ")");
1824 info.opened = false;
1825 }
1826
Adam Cohena9cf38f2011-05-02 15:36:58 -07001827 if (!info.opened) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001828 // Close any open folder
1829 closeFolder();
1830 // Open the requested folder
Adam Cohena9cf38f2011-05-02 15:36:58 -07001831 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001832 } else {
1833 // Find the open folder...
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001834 int folderScreen;
1835 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07001836 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001837 // .. and close it
1838 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07001839 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001840 // Close any folder open on the current screen
1841 closeFolder();
1842 // Pull the folder onto this screen
Adam Cohena9cf38f2011-05-02 15:36:58 -07001843 openFolder(folderIcon);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001844 }
1845 }
1846 }
1847 }
1848
Adam Cohen2801caf2011-05-13 20:57:39 -07001849 private void growAndFadeOutFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001850 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07001851 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
1852 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
1853 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
1854
Adam Cohenc51934b2011-07-26 21:07:43 -07001855 FolderInfo info = (FolderInfo) fi.getTag();
1856 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1857 CellLayout cl = (CellLayout) fi.getParent().getParent();
Winson Chunge50adee2011-08-11 16:12:00 -07001858 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
1859 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
Adam Cohenc51934b2011-07-26 21:07:43 -07001860 }
1861
Adam Cohen2801caf2011-05-13 20:57:39 -07001862 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY);
1863 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
1864 oa.start();
1865 }
1866
1867 private void shrinkAndFadeInFolderIcon(FolderIcon fi) {
Adam Cohen9932a9b2011-08-02 22:14:07 -07001868 if (fi == null) return;
Adam Cohen2801caf2011-05-13 20:57:39 -07001869 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
1870 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
1871 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
1872
Adam Cohenc51934b2011-07-26 21:07:43 -07001873 FolderInfo info = (FolderInfo) fi.getTag();
1874 CellLayout cl = null;
1875 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1876 cl = (CellLayout) fi.getParent().getParent();
1877 }
1878
1879 final CellLayout layout = cl;
Adam Cohen2801caf2011-05-13 20:57:39 -07001880 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY);
1881 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
Adam Cohenc51934b2011-07-26 21:07:43 -07001882 oa.addListener(new AnimatorListenerAdapter() {
1883 @Override
1884 public void onAnimationEnd(Animator animation) {
1885 if (layout != null) {
1886 layout.clearFolderLeaveBehind();
1887 }
1888 }
1889 });
Adam Cohen2801caf2011-05-13 20:57:39 -07001890 oa.start();
1891 }
1892
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001893 /**
Michael Jurka774bd372010-10-22 13:40:50 -07001894 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001895 * is animated relative to the specified View. If the View is null, no animation
1896 * is played.
1897 *
1898 * @param folderInfo The FolderInfo describing the folder to open.
1899 */
Adam Cohena9cf38f2011-05-02 15:36:58 -07001900 public void openFolder(FolderIcon folderIcon) {
1901 Folder folder = folderIcon.mFolder;
1902 FolderInfo info = folder.mInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001903
Adam Cohen2801caf2011-05-13 20:57:39 -07001904 growAndFadeOutFolderIcon(folderIcon);
Adam Cohena9cf38f2011-05-02 15:36:58 -07001905 info.opened = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001906
Adam Cohen4554ee12011-08-03 16:13:21 -07001907 // Just verify that the folder hasn't already been added to the DragLayer.
1908 // There was a one-off crash where the folder had a parent already.
1909 if (folder.getParent() == null) {
1910 mDragLayer.addView(folder);
1911 mDragController.addDropTarget((DropTarget) folder);
1912 } else {
1913 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
1914 folder.getParent() + ").");
1915 }
Adam Cohena9cf38f2011-05-02 15:36:58 -07001916 folder.animateOpen();
Adam Cohen4554ee12011-08-03 16:13:21 -07001917 }
1918
1919 public void closeFolder() {
1920 Folder folder = mWorkspace.getOpenFolder();
1921 if (folder != null) {
Adam Cohenac56cff2011-09-28 20:45:37 -07001922 if (folder.isEditingName()) {
1923 folder.dismissEditingName();
1924 }
Adam Cohen4554ee12011-08-03 16:13:21 -07001925 closeFolder(folder);
Winson Chung7d7541e2011-09-16 20:14:36 -07001926
1927 // Dismiss the folder cling
1928 dismissFolderCling(null);
Adam Cohen4554ee12011-08-03 16:13:21 -07001929 }
1930 }
1931
1932 void closeFolder(Folder folder) {
1933 folder.getInfo().opened = false;
1934
1935 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
1936 if (parent != null) {
1937 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
1938 shrinkAndFadeInFolderIcon(fi);
1939 }
1940 folder.animateClosed();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001941 }
1942
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001943 public boolean onLongClick(View v) {
Patrick Dubroye708c522011-03-01 16:03:43 -08001944 if (mState != State.WORKSPACE) {
1945 return false;
1946 }
1947
Joe Onorato9c1289c2009-08-17 11:03:03 -04001948 if (isWorkspaceLocked()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001949 return false;
1950 }
1951
1952 if (!(v instanceof CellLayout)) {
Michael Jurka8c920dd2011-01-20 14:16:56 -08001953 v = (View) v.getParent().getParent();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001954 }
1955
Michael Jurka0280c3b2010-09-17 15:00:07 -07001956 resetAddInfo();
1957 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001958 // This happens when long clicking an item with the dpad/trackball
Adam Cohenfaea1f82011-07-21 16:23:57 -07001959 if (longClickCellInfo == null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001960 return true;
1961 }
1962
Winson Chung3d503fb2011-07-13 17:25:49 -07001963 // The hotseat touch handling does not go through Workspace, and we always allow long press
1964 // on hotseat items.
Michael Jurka0280c3b2010-09-17 15:00:07 -07001965 final View itemUnderLongClick = longClickCellInfo.cell;
Winson Chung3d503fb2011-07-13 17:25:49 -07001966 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
1967 if (allowLongPress && !mDragController.isDragging()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001968 if (itemUnderLongClick == null) {
1969 // User long pressed on empty space
Michael Jurka0280c3b2010-09-17 15:00:07 -07001970 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1971 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Winson Chung6a3fd3f2011-08-02 14:03:26 -07001972 startWallpaper();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001973 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001974 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001975 // User long pressed on an item
Michael Jurka0280c3b2010-09-17 15:00:07 -07001976 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001977 }
1978 }
1979 }
1980 return true;
1981 }
1982
Winson Chung3d503fb2011-07-13 17:25:49 -07001983 boolean isHotseatLayout(View layout) {
1984 return mHotseat != null && layout != null &&
1985 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
1986 }
1987 Hotseat getHotseat() {
1988 return mHotseat;
Romain Guy1fbc1c82009-11-09 20:43:08 -08001989 }
Adam Cohenebea84d2011-11-09 17:20:41 -08001990 SearchDropTargetBar getSearchBar() {
1991 return mSearchDropTargetBar;
1992 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08001993
Winson Chung3d503fb2011-07-13 17:25:49 -07001994 /**
1995 * Returns the CellLayout of the specified container at the specified screen.
1996 */
1997 CellLayout getCellLayout(long container, int screen) {
1998 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
1999 if (mHotseat != null) {
2000 return mHotseat.getLayout();
2001 } else {
2002 return null;
Romain Guye6b8e2f2009-11-10 11:56:55 -08002003 }
Winson Chung3d503fb2011-07-13 17:25:49 -07002004 } else {
2005 return (CellLayout) mWorkspace.getChildAt(screen);
Romain Guya6abce82009-11-10 02:54:41 -08002006 }
2007 }
2008
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002009 Workspace getWorkspace() {
2010 return mWorkspace;
2011 }
2012
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002013 @Override
2014 protected Dialog onCreateDialog(int id) {
2015 switch (id) {
2016 case DIALOG_CREATE_SHORTCUT:
2017 return new CreateShortcut().createDialog();
2018 case DIALOG_RENAME_FOLDER:
2019 return new RenameFolder().createDialog();
2020 }
2021
2022 return super.onCreateDialog(id);
2023 }
2024
2025 @Override
2026 protected void onPrepareDialog(int id, Dialog dialog) {
2027 switch (id) {
2028 case DIALOG_CREATE_SHORTCUT:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002029 break;
2030 case DIALOG_RENAME_FOLDER:
Romain Guy7b4ef332009-07-14 13:58:08 -07002031 if (mFolderInfo != null) {
2032 EditText input = (EditText) dialog.findViewById(R.id.folder_name);
2033 final CharSequence text = mFolderInfo.title;
2034 input.setText(text);
2035 input.setSelection(0, text.length());
2036 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002037 break;
2038 }
2039 }
2040
2041 void showRenameDialog(FolderInfo info) {
2042 mFolderInfo = info;
2043 mWaitingForResult = true;
2044 showDialog(DIALOG_RENAME_FOLDER);
2045 }
2046
Adam Cohenfbba09b2011-07-18 21:43:05 -07002047 private void showAddDialog() {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002048 resetAddInfo();
Winson Chung3d503fb2011-07-13 17:25:49 -07002049 mPendingAddInfo.container = LauncherSettings.Favorites.CONTAINER_DESKTOP;
2050 mPendingAddInfo.screen = mWorkspace.getCurrentPage();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002051 mWaitingForResult = true;
2052 showDialog(DIALOG_CREATE_SHORTCUT);
2053 }
2054
2055 private class RenameFolder {
2056 private EditText mInput;
2057
2058 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002059 final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null);
2060 mInput = (EditText) layout.findViewById(R.id.folder_name);
2061
2062 AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
2063 builder.setIcon(0);
2064 builder.setTitle(getString(R.string.rename_folder_title));
2065 builder.setCancelable(true);
2066 builder.setOnCancelListener(new Dialog.OnCancelListener() {
2067 public void onCancel(DialogInterface dialog) {
2068 cleanup();
2069 }
2070 });
2071 builder.setNegativeButton(getString(R.string.cancel_action),
2072 new Dialog.OnClickListener() {
2073 public void onClick(DialogInterface dialog, int which) {
2074 cleanup();
2075 }
2076 }
2077 );
2078 builder.setPositiveButton(getString(R.string.rename_action),
2079 new Dialog.OnClickListener() {
2080 public void onClick(DialogInterface dialog, int which) {
2081 changeFolderName();
2082 }
2083 }
2084 );
2085 builder.setView(layout);
Romain Guy7b4ef332009-07-14 13:58:08 -07002086
2087 final AlertDialog dialog = builder.create();
2088 dialog.setOnShowListener(new DialogInterface.OnShowListener() {
2089 public void onShow(DialogInterface dialog) {
Joe Onorato7018d8e2010-04-13 20:25:47 -07002090 mWaitingForResult = true;
Joe Onoratod753b422009-11-08 13:31:11 -05002091 mInput.requestFocus();
2092 InputMethodManager inputManager = (InputMethodManager)
2093 getSystemService(Context.INPUT_METHOD_SERVICE);
2094 inputManager.showSoftInput(mInput, 0);
Romain Guy7b4ef332009-07-14 13:58:08 -07002095 }
2096 });
2097
2098 return dialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002099 }
2100
2101 private void changeFolderName() {
2102 final String name = mInput.getText().toString();
2103 if (!TextUtils.isEmpty(name)) {
2104 // Make sure we have the right folder info
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002105 mFolderInfo = sFolders.get(mFolderInfo.id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002106 mFolderInfo.title = name;
2107 LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo);
2108
Joe Onorato9c1289c2009-08-17 11:03:03 -04002109 if (mWorkspaceLoading) {
Joe Onorato7c312c12009-08-13 21:36:53 -07002110 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002111 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002112 } else {
2113 final FolderIcon folderIcon = (FolderIcon)
2114 mWorkspace.getViewForTag(mFolderInfo);
2115 if (folderIcon != null) {
Adam Cohena9cf38f2011-05-02 15:36:58 -07002116 // TODO: At some point we'll probably want some version of setting
2117 // the text for a folder icon.
2118 //folderIcon.setText(name);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002119 getWorkspace().requestLayout();
2120 } else {
Joe Onorato7c312c12009-08-13 21:36:53 -07002121 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002122 mWorkspaceLoading = true;
2123 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002124 }
2125 }
2126 }
2127 cleanup();
2128 }
2129
2130 private void cleanup() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002131 dismissDialog(DIALOG_RENAME_FOLDER);
2132 mWaitingForResult = false;
2133 mFolderInfo = null;
2134 }
2135 }
2136
Daniel Sandler843e8602010-06-07 14:59:01 -04002137 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
2138 public boolean isAllAppsVisible() {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002139 return (mState == State.APPS_CUSTOMIZE);
Joe Onoratofb0ca672009-09-14 17:55:46 -04002140 }
2141
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002142 // AllAppsView.Watcher
2143 public void zoomed(float zoom) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002144 if (zoom == 1.0f) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002145 mWorkspace.setVisibility(View.GONE);
2146 }
2147 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002148
2149 /**
2150 * Helper method for the cameraZoomIn/cameraZoomOut animations
2151 * @param view The view being animated
Winson Chungf0ea4d32011-06-06 14:27:16 -07002152 * @param state The state that we are moving in or out of (eg. APPS_CUSTOMIZE)
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002153 * @param scaleFactor The scale factor used for the zoom
2154 */
Michael Jurkab3e22d92011-10-31 15:58:33 -07002155 private void setPivotsForZoom(View view, float scaleFactor) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002156 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen7777d962011-08-18 18:58:38 -07002157 view.setPivotY(view.getHeight() / 2.0f);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002158 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002159
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002160 void updateWallpaperVisibility(boolean visible) {
2161 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
2162 int curflags = getWindow().getAttributes().flags
2163 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2164 if (wpflags != curflags) {
2165 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
2166 }
2167 }
2168
Michael Jurka9433fa72012-01-19 08:50:41 -08002169 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
2170 if (v instanceof LauncherTransitionable) {
2171 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
2172 }
2173 }
2174
2175 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
2176 if (v instanceof LauncherTransitionable) {
2177 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
2178 }
2179 }
2180
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002181 /**
Michael Jurkab3e22d92011-10-31 15:58:33 -07002182 * Things to test when changing the following seven functions.
2183 * - Home from workspace
2184 * - from center screen
2185 * - from other screens
2186 * - Home from all apps
2187 * - from center screen
2188 * - from other screens
2189 * - Back from all apps
2190 * - from center screen
2191 * - from other screens
2192 * - Launch app from workspace and quit
2193 * - with back
2194 * - with home
2195 * - Launch app from all apps and quit
2196 * - with back
2197 * - with home
2198 * - Go to a screen that's not the default, then all
2199 * apps, and launch and app, and go back
2200 * - with back
2201 * -with home
2202 * - On workspace, long press power and go back
2203 * - with back
2204 * - with home
2205 * - On all apps, long press power and go back
2206 * - with back
2207 * - with home
2208 * - On workspace, power off
2209 * - On all apps, power off
2210 * - Launch an app and turn off the screen while in that app
2211 * - Go back with home key
2212 * - Go back with back key TODO: make this not go to workspace
2213 * - From all apps
2214 * - From workspace
2215 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2216 * - From all apps
2217 * - From the center workspace
2218 * - From another workspace
2219 */
2220
2221 /**
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002222 * Zoom the camera out from the workspace to reveal 'toView'.
2223 * Assumes that the view to show is anchored at either the very top or very bottom
2224 * of the screen.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002225 */
Michael Jurka9433fa72012-01-19 08:50:41 -08002226 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002227 if (mStateAnimation != null) {
2228 mStateAnimation.cancel();
2229 mStateAnimation = null;
2230 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002231 final Resources res = getResources();
Winson Chung7d7541e2011-09-16 20:14:36 -07002232 final Launcher instance = this;
Adam Cohenf16e5712011-01-13 13:31:45 -08002233
Winson Chungf0ea4d32011-06-06 14:27:16 -07002234 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
2235 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
2236 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
Michael Jurka9433fa72012-01-19 08:50:41 -08002237 final View fromView = mWorkspace;
Winson Chungf0ea4d32011-06-06 14:27:16 -07002238 final View toView = mAppsCustomizeTabHost;
Adam Cohencff6af82011-09-13 14:51:53 -07002239 final int startDelay =
2240 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002241
Michael Jurkab3e22d92011-10-31 15:58:33 -07002242 setPivotsForZoom(toView, scale);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002243
Michael Jurkad74c9842011-07-10 12:44:21 -07002244 // Shrink workspaces away if going to AppsCustomize from workspace
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002245 Animator workspaceAnim =
2246 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002247
2248 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002249 toView.setScaleX(scale);
2250 toView.setScaleY(scale);
2251 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView);
2252 scaleAnim.
2253 scaleX(1f).scaleY(1f).
2254 setDuration(duration).
2255 setInterpolator(new Workspace.ZoomOutInterpolator());
Adam Cohen61033d32010-11-15 18:29:44 -08002256
Winson Chungf0ea4d32011-06-06 14:27:16 -07002257 toView.setVisibility(View.VISIBLE);
Adam Cohenc00f0b92011-12-06 19:45:06 -08002258 toView.setAlpha(0f);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002259 final ObjectAnimator alphaAnim = ObjectAnimator
2260 .ofFloat(toView, "alpha", 0f, 1f)
2261 .setDuration(fadeDuration);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002262 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
Adam Cohenf16e5712011-01-13 13:31:45 -08002263
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002264 // toView should appear right at the end of the workspace shrink
2265 // animation
2266 mStateAnimation = new AnimatorSet();
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002267 mStateAnimation.play(scaleAnim).after(startDelay);
Michael Jurka7407d2a2011-12-12 21:48:38 -08002268 mStateAnimation.play(alphaAnim).after(startDelay);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002269
2270 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Adam Cohenf4ddea32011-09-12 13:46:42 -07002271 boolean animationCancelled = false;
2272
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002273 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002274 public void onAnimationStart(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002275 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002276 // Prepare the position
2277 toView.setTranslationX(0.0f);
2278 toView.setTranslationY(0.0f);
2279 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002280 toView.bringToFront();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002281 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002282 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002283 public void onAnimationEnd(Animator animation) {
Michael Jurka9433fa72012-01-19 08:50:41 -08002284 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2285 dispatchOnLauncherTransitionEnd(toView, animated, false);
Winson Chung32174c82011-07-19 15:47:55 -07002286
2287 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2288 // Hide the workspace scrollbar
2289 mWorkspace.hideScrollingIndicator(true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002290 hideDockDivider();
Winson Chung32174c82011-07-19 15:47:55 -07002291 }
Adam Cohenf4ddea32011-09-12 13:46:42 -07002292 if (!animationCancelled) {
2293 updateWallpaperVisibility(false);
2294 }
2295 }
2296
Adam Cohencff6af82011-09-13 14:51:53 -07002297 @Override
Adam Cohenf4ddea32011-09-12 13:46:42 -07002298 public void onAnimationCancel(Animator animation) {
2299 animationCancelled = true;
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002300 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002301 });
2302
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002303 if (workspaceAnim != null) {
2304 mStateAnimation.play(workspaceAnim);
2305 }
Michael Jurka1899a362011-11-03 13:50:45 -07002306
2307 boolean delayAnim = false;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002308 final ViewTreeObserver observer;
2309
Michael Jurka9433fa72012-01-19 08:50:41 -08002310 dispatchOnLauncherTransitionStart(fromView, animated, false);
2311 dispatchOnLauncherTransitionStart(toView, animated, false);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002312
2313 // If any of the objects being animated haven't been measured/laid out
2314 // yet, delay the animation until we get a layout pass
Michael Jurka9433fa72012-01-19 08:50:41 -08002315 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) ||
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002316 (mWorkspace.getMeasuredWidth() == 0) ||
2317 (toView.getMeasuredWidth() == 0)) {
2318 observer = mWorkspace.getViewTreeObserver();
2319 delayAnim = true;
2320 } else {
2321 observer = null;
Michael Jurka1899a362011-11-03 13:50:45 -07002322 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002323
2324 if (delayAnim) {
Michael Jurka49779a12012-01-16 04:10:08 -08002325 final AnimatorSet stateAnimation = mStateAnimation;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002326 final OnGlobalLayoutListener delayedStart = new OnGlobalLayoutListener() {
2327 public void onGlobalLayout() {
2328 mWorkspace.post(new Runnable() {
2329 public void run() {
Michael Jurka49779a12012-01-16 04:10:08 -08002330 // Check that mStateAnimation hasn't changed while
2331 // we waited for a layout pass
2332 if (mStateAnimation == stateAnimation) {
2333 // Need to update pivots for zoom if layout changed
2334 setPivotsForZoom(toView, scale);
2335 mStateAnimation.start();
2336 }
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002337 }
2338 });
2339 observer.removeGlobalOnLayoutListener(this);
2340 }
2341 };
2342 observer.addOnGlobalLayoutListener(delayedStart);
2343 } else {
2344 setPivotsForZoom(toView, scale);
Michael Jurka1899a362011-11-03 13:50:45 -07002345 mStateAnimation.start();
2346 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002347 } else {
2348 toView.setTranslationX(0.0f);
2349 toView.setTranslationY(0.0f);
2350 toView.setScaleX(1.0f);
2351 toView.setScaleY(1.0f);
2352 toView.setVisibility(View.VISIBLE);
Winson Chung785d2eb2011-04-14 16:08:02 -07002353 toView.bringToFront();
Winson Chung3ac74c52011-06-30 17:39:37 -07002354
Michael Jurka9433fa72012-01-19 08:50:41 -08002355 if (!springLoaded && !LauncherApplication.isScreenLarge()) {
2356 // Hide the workspace scrollbar
2357 mWorkspace.hideScrollingIndicator(true);
2358 hideDockDivider();
Michael Jurkaabded662011-03-04 12:06:57 -08002359 }
Michael Jurka9433fa72012-01-19 08:50:41 -08002360 dispatchOnLauncherTransitionStart(fromView, animated, false);
2361 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2362 dispatchOnLauncherTransitionStart(toView, animated, false);
2363 dispatchOnLauncherTransitionEnd(toView, animated, false);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002364 updateWallpaperVisibility(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002365 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002366 }
2367
2368 /**
2369 * Zoom the camera back into the workspace, hiding 'fromView'.
Michael Jurkab3e22d92011-10-31 15:58:33 -07002370 * This is the opposite of showAppsCustomizeHelper.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002371 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002372 */
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002373 private void hideAppsCustomizeHelper(
Michael Jurka9433fa72012-01-19 08:50:41 -08002374 State toState, final boolean animated, final boolean springLoaded) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002375 if (mStateAnimation != null) {
2376 mStateAnimation.cancel();
2377 mStateAnimation = null;
2378 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002379 Resources res = getResources();
Adam Cohenf16e5712011-01-13 13:31:45 -08002380
Winson Chungf0ea4d32011-06-06 14:27:16 -07002381 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
Michael Jurka159b4cc2012-01-17 03:00:35 -08002382 final int fadeOutDuration =
2383 res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002384 final float scaleFactor = (float)
2385 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
2386 final View fromView = mAppsCustomizeTabHost;
Michael Jurka9433fa72012-01-19 08:50:41 -08002387 final View toView = mWorkspace;
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002388 Animator workspaceAnim = null;
2389
2390 if (toState == State.WORKSPACE) {
2391 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger);
2392 workspaceAnim = mWorkspace.getChangeStateAnimation(
2393 Workspace.State.NORMAL, animated, stagger);
2394 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
2395 workspaceAnim = mWorkspace.getChangeStateAnimation(
2396 Workspace.State.SPRING_LOADED, animated);
2397 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002398
Michael Jurkab3e22d92011-10-31 15:58:33 -07002399 setPivotsForZoom(fromView, scaleFactor);
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002400 updateWallpaperVisibility(true);
Winson Chung4afe9b32011-07-27 17:46:20 -07002401 showHotseat(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002402 if (animated) {
Michael Jurka742574b2011-02-02 23:51:01 -08002403 final float oldScaleX = fromView.getScaleX();
2404 final float oldScaleY = fromView.getScaleY();
2405
Michael Jurka159b4cc2012-01-17 03:00:35 -08002406 final LauncherViewPropertyAnimator scaleAnim =
2407 new LauncherViewPropertyAnimator(fromView);
2408 scaleAnim.
2409 scaleX(scaleFactor).scaleY(scaleFactor).
2410 setDuration(duration).
2411 setInterpolator(new Workspace.ZoomInInterpolator());
2412
2413 final ObjectAnimator alphaAnim = ObjectAnimator
2414 .ofFloat(fromView, "alpha", 1f, 0f)
2415 .setDuration(fadeOutDuration);
Adam Cohencff6af82011-09-13 14:51:53 -07002416 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator());
Michael Jurka159b4cc2012-01-17 03:00:35 -08002417
Michael Jurka9433fa72012-01-19 08:50:41 -08002418 mStateAnimation = new AnimatorSet();
2419
2420 dispatchOnLauncherTransitionStart(fromView, animated, true);
2421 dispatchOnLauncherTransitionStart(toView, animated, true);
2422
2423 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002424 @Override
Michael Jurka8edd75c2010-12-17 20:15:06 -08002425 public void onAnimationEnd(Animator animation) {
Dianne Hackbornbb003a52011-08-30 14:40:07 -07002426 updateWallpaperVisibility(true);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002427 fromView.setVisibility(View.GONE);
Michael Jurka9433fa72012-01-19 08:50:41 -08002428 dispatchOnLauncherTransitionEnd(fromView, animated, true);
2429 dispatchOnLauncherTransitionEnd(toView, animated, true);
Michael Jurka430e8a52011-08-08 15:52:14 -07002430 mWorkspace.hideScrollingIndicator(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002431 }
2432 });
2433
Winson Chungf0ea4d32011-06-06 14:27:16 -07002434 mStateAnimation.playTogether(scaleAnim, alphaAnim);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002435 if (workspaceAnim != null) {
2436 mStateAnimation.play(workspaceAnim);
2437 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002438 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002439 } else {
2440 fromView.setVisibility(View.GONE);
Michael Jurka9433fa72012-01-19 08:50:41 -08002441 dispatchOnLauncherTransitionStart(fromView, animated, false);
2442 dispatchOnLauncherTransitionEnd(fromView, animated, false);
2443 dispatchOnLauncherTransitionStart(toView, animated, false);
2444 dispatchOnLauncherTransitionEnd(toView, animated, false);
Michael Jurkab737ee62011-11-15 15:57:22 -08002445 mWorkspace.hideScrollingIndicator(false);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002446 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002447 }
2448
Michael Jurkae326f182011-11-21 14:05:46 -08002449 @Override
2450 public void onTrimMemory(int level) {
2451 super.onTrimMemory(level);
2452 if (level == ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
2453 mAppsCustomizeTabHost.onTrimMemory();
2454 }
2455 }
2456
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002457 void showWorkspace(boolean animated) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002458 if (mState != State.WORKSPACE) {
2459 mWorkspace.setVisibility(View.VISIBLE);
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002460 hideAppsCustomizeHelper(State.WORKSPACE, animated, false);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002461
2462 // Show the search bar and hotseat
2463 mSearchDropTargetBar.showSearchBar(animated);
Michael Jurkab737ee62011-11-15 15:57:22 -08002464 // We only need to animate in the dock divider if we're going from spring loaded mode
2465 showDockDivider(animated && mState == State.APPS_CUSTOMIZE_SPRING_LOADED);
Michael Jurkab3e22d92011-10-31 15:58:33 -07002466
2467 // Set focus to the AppsCustomize button
2468 if (mAllAppsButton != null) {
2469 mAllAppsButton.requestFocus();
2470 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002471 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07002472
Michael Jurkab737ee62011-11-15 15:57:22 -08002473 mWorkspace.flashScrollingIndicator(animated);
Adam Cohen7777d962011-08-18 18:58:38 -07002474
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002475 // Change the state *after* we've called all the transition code
2476 mState = State.WORKSPACE;
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002477
Winson Chung5fb63472011-02-02 17:03:37 -08002478 // Resume the auto-advance of widgets
2479 mUserPresent = true;
2480 updateRunning();
2481
Svetoslav Ganov815ba2d2011-01-07 14:55:17 -08002482 // send an accessibility event to announce the context change
2483 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
Joe Onorato00acb122009-08-04 16:04:30 -04002484 }
2485
Michael Jurkab3e22d92011-10-31 15:58:33 -07002486 void showAllApps(boolean animated) {
2487 if (mState != State.WORKSPACE) return;
2488
2489 showAppsCustomizeHelper(animated, false);
2490 mAppsCustomizeTabHost.requestFocus();
2491
2492 // Hide the search bar and hotseat
2493 mSearchDropTargetBar.hideSearchBar(animated);
2494
2495 // Change the state *after* we've called all the transition code
2496 mState = State.APPS_CUSTOMIZE;
2497
2498 // Pause the auto-advance of widgets until we are out of AllApps
2499 mUserPresent = false;
2500 updateRunning();
2501 closeFolder();
2502
2503 // Send an accessibility event to announce the context change
2504 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
2505 }
2506
Adam Cohen7777d962011-08-18 18:58:38 -07002507 void enterSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002508 if (mState == State.APPS_CUSTOMIZE) {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08002509 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true);
Michael Jurkab737ee62011-11-15 15:57:22 -08002510 hideDockDivider();
Winson Chungc07918d2011-07-01 15:35:26 -07002511 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
Winson Chungb26f3d62011-06-02 10:49:29 -07002512 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002513 }
Adam Cohen7777d962011-08-18 18:58:38 -07002514
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002515 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay) {
Winson Chung09bfc452011-09-09 11:30:20 -07002516 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
2517
Winson Chunge7a03942011-08-05 15:05:12 -07002518 mHandler.postDelayed(new Runnable() {
Winson Chung557d6ed2011-07-08 15:34:52 -07002519 @Override
2520 public void run() {
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002521 if (successfulDrop) {
Michael Jurka7bdb25a2011-08-03 15:16:44 -07002522 // Before we show workspace, hide all apps again because
2523 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
2524 // clean up our state transition functions
2525 mAppsCustomizeTabHost.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002526 mSearchDropTargetBar.showSearchBar(true);
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002527 showWorkspace(true);
Adam Cohen7777d962011-08-18 18:58:38 -07002528 } else {
2529 exitSpringLoadedDragMode();
Winson Chung6a3fd3f2011-08-02 14:03:26 -07002530 }
Winson Chung557d6ed2011-07-08 15:34:52 -07002531 }
2532 }, (extendedDelay ?
2533 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT :
2534 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT));
2535 }
Michael Jurkab3e22d92011-10-31 15:58:33 -07002536
Michael Jurkad3ef3062010-11-23 16:23:58 -08002537 void exitSpringLoadedDragMode() {
Winson Chungb26f3d62011-06-02 10:49:29 -07002538 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
Michael Jurkab3e22d92011-10-31 15:58:33 -07002539 final boolean animated = true;
2540 final boolean springLoaded = true;
2541 showAppsCustomizeHelper(animated, springLoaded);
Winson Chungb26f3d62011-06-02 10:49:29 -07002542 mState = State.APPS_CUSTOMIZE;
Winson Chungf0ea4d32011-06-06 14:27:16 -07002543 }
2544 // Otherwise, we are not in spring loaded mode, so don't do anything.
2545 }
2546
Michael Jurkab737ee62011-11-15 15:57:22 -08002547 void hideDockDivider() {
2548 if (mQsbDivider != null && mDockDivider != null) {
2549 mQsbDivider.setVisibility(View.INVISIBLE);
2550 mDockDivider.setVisibility(View.INVISIBLE);
2551 }
2552 }
2553
2554 void showDockDivider(boolean animated) {
2555 if (mQsbDivider != null && mDockDivider != null) {
2556 mQsbDivider.setVisibility(View.VISIBLE);
2557 mDockDivider.setVisibility(View.VISIBLE);
2558 if (mDividerAnimator != null) {
2559 mDividerAnimator.cancel();
2560 mQsbDivider.setAlpha(1f);
2561 mDockDivider.setAlpha(1f);
2562 mDividerAnimator = null;
2563 }
2564 if (animated) {
2565 mDividerAnimator = new AnimatorSet();
2566 mDividerAnimator.playTogether(ObjectAnimator.ofFloat(mQsbDivider, "alpha", 1f),
2567 ObjectAnimator.ofFloat(mDockDivider, "alpha", 1f));
2568 mDividerAnimator.setDuration(mSearchDropTargetBar.getTransitionInDuration());
2569 mDividerAnimator.start();
2570 }
2571 }
2572 }
2573
Michael Jurkab3e22d92011-10-31 15:58:33 -07002574 void lockAllApps() {
2575 // TODO
2576 }
2577
2578 void unlockAllApps() {
2579 // TODO
2580 }
2581
Adam Cohenfc53cd22011-07-20 15:45:11 -07002582 public boolean isAllAppsCustomizeOpen() {
2583 return mState == State.APPS_CUSTOMIZE;
2584 }
2585
Winson Chungf0ea4d32011-06-06 14:27:16 -07002586 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002587 * Shows the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002588 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002589 void showHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002590 if (!LauncherApplication.isScreenLarge()) {
2591 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002592 if (mHotseat.getAlpha() != 1f) {
2593 int duration = mSearchDropTargetBar.getTransitionInDuration();
2594 mHotseat.animate().alpha(1f).setDuration(duration);
2595 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002596 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002597 mHotseat.setAlpha(1f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002598 }
2599 }
2600 }
2601
2602 /**
Winson Chung3d503fb2011-07-13 17:25:49 -07002603 * Hides the hotseat area.
Winson Chungf0ea4d32011-06-06 14:27:16 -07002604 */
Winson Chung3d503fb2011-07-13 17:25:49 -07002605 void hideHotseat(boolean animated) {
Winson Chungf0ea4d32011-06-06 14:27:16 -07002606 if (!LauncherApplication.isScreenLarge()) {
2607 if (animated) {
Michael Jurka7407d2a2011-12-12 21:48:38 -08002608 if (mHotseat.getAlpha() != 0f) {
2609 int duration = mSearchDropTargetBar.getTransitionOutDuration();
2610 mHotseat.animate().alpha(0f).setDuration(duration);
2611 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07002612 } else {
Winson Chung3d503fb2011-07-13 17:25:49 -07002613 mHotseat.setAlpha(0f);
Winson Chungf0ea4d32011-06-06 14:27:16 -07002614 }
Winson Chungb26f3d62011-06-02 10:49:29 -07002615 }
Michael Jurkad3ef3062010-11-23 16:23:58 -08002616 }
2617
Patrick Dubroy5f445422011-02-18 14:35:21 -08002618 /**
2619 * Add an item from all apps or customize onto the given workspace screen.
2620 * If layout is null, add to the current screen.
2621 */
2622 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002623 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
2624 showOutOfSpaceMessage();
Michael Jurka213d9632010-07-28 11:29:25 -07002625 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002626 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002627
Winson Chungdff8ebb2011-09-08 17:25:31 -07002628 /** Maps the current orientation to an index for referencing orientation correct global icons */
2629 private int getCurrentOrientationIndexForGlobalIcons() {
2630 // default - 0, landscape - 1
2631 switch (getResources().getConfiguration().orientation) {
2632 case Configuration.ORIENTATION_LANDSCAPE:
2633 return 1;
2634 default:
2635 return 0;
2636 }
2637 }
2638
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002639 private Drawable getExternalPackageToolbarIcon(ComponentName activityName) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07002640 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002641 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07002642 // Look for the toolbar icon specified in the activity meta-data
2643 Bundle metaData = packageManager.getActivityInfo(
2644 activityName, PackageManager.GET_META_DATA).metaData;
2645 if (metaData != null) {
2646 int iconResId = metaData.getInt(TOOLBAR_ICON_METADATA_NAME);
2647 if (iconResId != 0) {
2648 Resources res = packageManager.getResourcesForActivity(activityName);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002649 return res.getDrawable(iconResId);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002650 }
2651 }
2652 } catch (NameNotFoundException e) {
Michael Jurkab6052a92011-07-12 17:02:45 -07002653 // This can happen if the activity defines an invalid drawable
2654 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
2655 " not found", e);
Mathew Inwood70d51022011-07-12 13:41:41 +01002656 } catch (Resources.NotFoundException nfe) {
2657 // This can happen if the activity defines an invalid drawable
2658 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
2659 nfe);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002660 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002661 return null;
2662 }
2663
2664 // if successful in getting icon, return it; otherwise, set button to use default drawable
2665 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
2666 int buttonId, ComponentName activityName, int fallbackDrawableId) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002667 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName);
Winson Chung128bbcd2011-08-31 16:58:52 -07002668 Resources r = getResources();
2669 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
2670 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002671
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002672 TextView button = (TextView) findViewById(buttonId);
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002673 // If we were unable to find the icon via the meta-data, use a generic one
2674 if (toolbarIcon == null) {
Winson Chung128bbcd2011-08-31 16:58:52 -07002675 toolbarIcon = r.getDrawable(fallbackDrawableId);
2676 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002677 if (button != null) {
2678 button.setCompoundDrawables(toolbarIcon, null, null, null);
2679 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002680 return null;
2681 } else {
Winson Chung128bbcd2011-08-31 16:58:52 -07002682 toolbarIcon.setBounds(0, 0, w, h);
Michael Jurka4da7a3e2011-10-28 15:04:35 -07002683 if (button != null) {
2684 button.setCompoundDrawables(toolbarIcon, null, null, null);
2685 }
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002686 return toolbarIcon.getConstantState();
2687 }
2688 }
2689
2690 // if successful in getting icon, return it; otherwise, set button to use default drawable
2691 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
2692 int buttonId, ComponentName activityName, int fallbackDrawableId) {
2693 ImageView button = (ImageView) findViewById(buttonId);
2694 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName);
2695
Michael Jurka19e0fc52011-07-22 18:00:21 -07002696 if (button != null) {
2697 // If we were unable to find the icon via the meta-data, use a
2698 // generic one
2699 if (toolbarIcon == null) {
2700 button.setImageResource(fallbackDrawableId);
2701 } else {
2702 button.setImageDrawable(toolbarIcon);
2703 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002704 }
Michael Jurka19e0fc52011-07-22 18:00:21 -07002705
2706 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
2707
Michael Jurka0423dcf2010-10-05 14:56:18 -07002708 }
2709
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002710 private void updateTextButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
2711 TextView button = (TextView) findViewById(buttonId);
2712 button.setCompoundDrawables(d.newDrawable(getResources()), null, null, null);
2713 }
2714
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002715 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002716 ImageView button = (ImageView) findViewById(buttonId);
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002717 button.setImageDrawable(d.newDrawable(getResources()));
Michael Jurka4ef207b2010-11-29 17:05:45 -08002718 }
2719
Winson Chungbb185bd2011-11-21 12:31:42 -08002720 private void invalidatePressedFocusedStates(View container, View button) {
2721 if (container instanceof HolographicLinearLayout) {
2722 HolographicLinearLayout layout = (HolographicLinearLayout) container;
2723 layout.invalidatePressedFocusedStates();
2724 } else if (button instanceof HolographicImageView) {
2725 HolographicImageView view = (HolographicImageView) button;
2726 view.invalidatePressedFocusedStates();
2727 }
2728 }
2729
Winson Chungc51db6a2011-10-05 11:44:49 -07002730 private boolean updateGlobalSearchIcon() {
2731 final View searchButtonContainer = findViewById(R.id.search_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07002732 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
2733 final View searchDivider = findViewById(R.id.search_divider);
Winson Chungc51db6a2011-10-05 11:44:49 -07002734 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002735 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07002736
Winson Chung1cad91e2011-05-25 17:41:01 -07002737 final SearchManager searchManager =
2738 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2739 ComponentName activityName = searchManager.getGlobalSearchActivity();
2740 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002741 int coi = getCurrentOrientationIndexForGlobalIcons();
2742 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Winson Chungc7aef8c2011-09-15 18:53:04 -07002743 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo);
Winson Chung649723c2011-07-06 20:41:23 -07002744 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002745 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
2746 searchButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08002747 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07002748 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07002749 } else {
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002750 // We disable both search and voice search when there is no global search provider
Winson Chung649723c2011-07-06 20:41:23 -07002751 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002752 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
2753 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
2754 searchButton.setVisibility(View.GONE);
Winson Chungcbf7c4d2011-08-23 11:58:54 -07002755 voiceButton.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002756 return false;
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002757 }
2758 }
2759
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002760 private void updateGlobalSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002761 final View searchButtonContainer = findViewById(R.id.search_button_container);
2762 final View searchButton = (ImageView) findViewById(R.id.search_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002763 updateButtonWithDrawable(R.id.search_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08002764 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002765 }
2766
Winson Chungc51db6a2011-10-05 11:44:49 -07002767 private boolean updateVoiceSearchIcon(boolean searchVisible) {
Winson Chung1cad91e2011-05-25 17:41:01 -07002768 final View searchDivider = findViewById(R.id.search_divider);
Winson Chungc51db6a2011-10-05 11:44:49 -07002769 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
Winson Chung1cad91e2011-05-25 17:41:01 -07002770 final View voiceButton = findViewById(R.id.voice_button);
Winson Chung97d85d22011-04-13 11:27:36 -07002771
Winson Chungc51db6a2011-10-05 11:44:49 -07002772 // We only show/update the voice search icon if the search icon is enabled as well
Winson Chung1cad91e2011-05-25 17:41:01 -07002773 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2774 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chungc51db6a2011-10-05 11:44:49 -07002775 if (searchVisible && activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002776 int coi = getCurrentOrientationIndexForGlobalIcons();
2777 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
Winson Chungc7aef8c2011-09-15 18:53:04 -07002778 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo);
Winson Chung649723c2011-07-06 20:41:23 -07002779 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002780 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002781 voiceButton.setVisibility(View.VISIBLE);
Winson Chungbb185bd2011-11-21 12:31:42 -08002782 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Winson Chungc51db6a2011-10-05 11:44:49 -07002783 return true;
Winson Chung1cad91e2011-05-25 17:41:01 -07002784 } else {
Winson Chung649723c2011-07-06 20:41:23 -07002785 if (searchDivider != null) searchDivider.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002786 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
Winson Chung1cad91e2011-05-25 17:41:01 -07002787 voiceButton.setVisibility(View.GONE);
Winson Chungc51db6a2011-10-05 11:44:49 -07002788 return false;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002789 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002790 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002791
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002792 private void updateVoiceSearchIcon(Drawable.ConstantState d) {
Winson Chungbb185bd2011-11-21 12:31:42 -08002793 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
2794 final View voiceButton = findViewById(R.id.voice_button);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002795 updateButtonWithDrawable(R.id.voice_button, d);
Winson Chungbb185bd2011-11-21 12:31:42 -08002796 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002797 }
2798
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002799 /**
Winson Chungeb66b142011-06-16 13:14:22 -07002800 * Sets the app market icon
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002801 */
2802 private void updateAppMarketIcon() {
Winson Chung785d2eb2011-04-14 16:08:02 -07002803 final View marketButton = findViewById(R.id.market_button);
2804 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
2805 // Find the app market activity by resolving an intent.
2806 // (If multiple app markets are installed, it will return the ResolverActivity.)
2807 ComponentName activityName = intent.resolveActivity(getPackageManager());
Winson Chung6a26e5b2011-05-26 14:36:06 -07002808 if (activityName != null) {
Winson Chungdff8ebb2011-09-08 17:25:31 -07002809 int coi = getCurrentOrientationIndexForGlobalIcons();
Winson Chung785d2eb2011-04-14 16:08:02 -07002810 mAppMarketIntent = intent;
Winson Chungdff8ebb2011-09-08 17:25:31 -07002811 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity(
Winson Chung967289b2011-06-30 18:09:30 -07002812 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo);
Winson Chung785d2eb2011-04-14 16:08:02 -07002813 marketButton.setVisibility(View.VISIBLE);
2814 } else {
2815 // We should hide and disable the view so that we don't try and restore the visibility
2816 // of it when we swap between drag & normal states from IconDropTarget subclasses.
2817 marketButton.setVisibility(View.GONE);
2818 marketButton.setEnabled(false);
Michael Jurka0423dcf2010-10-05 14:56:18 -07002819 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002820 }
2821
Michael Jurkae7bf83b2010-12-14 18:02:21 -08002822 private void updateAppMarketIcon(Drawable.ConstantState d) {
Winson Chungfbb3d9b2011-03-01 12:43:02 -08002823 updateTextButtonWithDrawable(R.id.market_button, d);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002824 }
2825
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002826 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002827 * Displays the shortcut creation dialog and launches, if necessary, the
2828 * appropriate activity.
2829 */
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002830 private class CreateShortcut implements DialogInterface.OnClickListener,
Romain Guy7b4ef332009-07-14 13:58:08 -07002831 DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
2832 DialogInterface.OnShowListener {
2833
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002834 private AddAdapter mAdapter;
Romain Guy9ffb5432009-03-24 21:04:15 -07002835
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002836 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002837 mAdapter = new AddAdapter(Launcher.this);
Romain Guycbb89e42009-06-08 15:52:54 -07002838
Winson Chung55b65502011-05-26 12:03:43 -07002839 final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this,
2840 AlertDialog.THEME_HOLO_DARK);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002841 builder.setAdapter(mAdapter, this);
Romain Guycbb89e42009-06-08 15:52:54 -07002842
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002843 AlertDialog dialog = builder.create();
2844 dialog.setOnCancelListener(this);
Romain Guycbb89e42009-06-08 15:52:54 -07002845 dialog.setOnDismissListener(this);
Romain Guy7b4ef332009-07-14 13:58:08 -07002846 dialog.setOnShowListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002847
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002848 return dialog;
2849 }
2850
2851 public void onCancel(DialogInterface dialog) {
2852 mWaitingForResult = false;
2853 cleanup();
2854 }
2855
Romain Guycbb89e42009-06-08 15:52:54 -07002856 public void onDismiss(DialogInterface dialog) {
Winson Chung55b65502011-05-26 12:03:43 -07002857 mWaitingForResult = false;
2858 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002859 }
2860
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002861 private void cleanup() {
Joe Onoratocc19a532009-11-19 14:19:17 -08002862 try {
2863 dismissDialog(DIALOG_CREATE_SHORTCUT);
2864 } catch (Exception e) {
2865 // An exception is thrown if the dialog is not visible, which is fine
2866 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002867 }
2868
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002869 /**
2870 * Handle the action clicked in the "Add to home" dialog.
2871 */
2872 public void onClick(DialogInterface dialog, int which) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002873 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002874
Winson Chung55b65502011-05-26 12:03:43 -07002875 AddAdapter.ListItem item = (AddAdapter.ListItem) mAdapter.getItem(which);
2876 switch (item.actionTag) {
Winson Chung55b65502011-05-26 12:03:43 -07002877 case AddAdapter.ITEM_APPLICATION: {
2878 if (mAppsCustomizeTabHost != null) {
2879 mAppsCustomizeTabHost.selectAppsTab();
2880 }
2881 showAllApps(true);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002882 break;
2883 }
Winson Chung55b65502011-05-26 12:03:43 -07002884 case AddAdapter.ITEM_APPWIDGET: {
2885 if (mAppsCustomizeTabHost != null) {
2886 mAppsCustomizeTabHost.selectWidgetsTab();
2887 }
2888 showAllApps(true);
2889 break;
2890 }
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002891 case AddAdapter.ITEM_WALLPAPER: {
2892 startWallpaper();
2893 break;
2894 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002895 }
2896 }
Romain Guy7b4ef332009-07-14 13:58:08 -07002897
2898 public void onShow(DialogInterface dialog) {
Winson Chungaafa03c2010-06-11 17:34:16 -07002899 mWaitingForResult = true;
Romain Guy7b4ef332009-07-14 13:58:08 -07002900 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002901 }
2902
2903 /**
Winson Chungb8472bb2011-08-05 13:49:21 -07002904 * Receives notifications when system dialogs are to be closed.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002905 */
2906 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
2907 @Override
2908 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002909 closeSystemDialogs();
2910 }
2911 }
2912
2913 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002914 * Receives notifications whenever the appwidgets are reset.
2915 */
2916 private class AppWidgetResetObserver extends ContentObserver {
2917 public AppWidgetResetObserver() {
2918 super(new Handler());
2919 }
2920
2921 @Override
2922 public void onChange(boolean selfChange) {
2923 onAppWidgetReset();
2924 }
2925 }
2926
2927 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002928 * If the activity is currently paused, signal that we need to re-run the loader
2929 * in onResume.
2930 *
2931 * This needs to be called from incoming places where resources might have been loaded
2932 * while we are paused. That is becaues the Configuration might be wrong
2933 * when we're not running, and if it comes back to what it was when we
2934 * were paused, we are not restarted.
2935 *
2936 * Implementation of the method from LauncherModel.Callbacks.
2937 *
2938 * @return true if we are currently paused. The caller might be able to
2939 * skip some work in that case since we will come back again.
2940 */
2941 public boolean setLoadOnResume() {
2942 if (mPaused) {
2943 Log.i(TAG, "setLoadOnResume");
2944 mOnResumeNeedsLoad = true;
2945 return true;
2946 } else {
2947 return false;
2948 }
2949 }
2950
2951 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002952 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002953 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002954 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07002955 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002956 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07002957 } else {
2958 return SCREEN_COUNT / 2;
2959 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002960 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002961
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002962
Joe Onorato9c1289c2009-08-17 11:03:03 -04002963 /**
2964 * Refreshes the shortcuts shown on the workspace.
2965 *
2966 * Implementation of the method from LauncherModel.Callbacks.
2967 */
2968 public void startBinding() {
2969 final Workspace workspace = mWorkspace;
Adam Cohendf035382011-04-11 17:22:04 -07002970
2971 mWorkspace.clearDropTargets();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002972 int count = workspace.getChildCount();
2973 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04002974 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Winson Chung7a25a9e2011-01-30 13:33:56 -08002975 final CellLayout layoutParent = (CellLayout) workspace.getChildAt(i);
2976 layoutParent.removeAllViewsInLayout();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002977 }
Michael Jurka05bf6442011-11-30 20:28:53 -08002978 mWidgetsToAdvance.clear();
Winson Chung3d503fb2011-07-13 17:25:49 -07002979 if (mHotseat != null) {
2980 mHotseat.resetLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002981 }
2982 }
2983
2984 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002985 * Bind the items start-end from the list.
2986 *
2987 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002988 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002989 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07002990 setLoadOnResume();
2991
Joe Onorato9c1289c2009-08-17 11:03:03 -04002992 final Workspace workspace = mWorkspace;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002993 for (int i=start; i<end; i++) {
2994 final ItemInfo item = shortcuts.get(i);
Winson Chung4d279d92011-07-21 11:46:32 -07002995
2996 // Short circuit if we are loading dock items for a configuration which has no dock
2997 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
2998 mHotseat == null) {
2999 continue;
3000 }
3001
Joe Onorato9c1289c2009-08-17 11:03:03 -04003002 switch (item.itemType) {
3003 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3004 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Winson Chung3d503fb2011-07-13 17:25:49 -07003005 View shortcut = createShortcut((ShortcutInfo)item);
3006 workspace.addInScreen(shortcut, item.container, item.screen, item.cellX,
3007 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003008 break;
Adam Cohendf2cc412011-04-27 16:56:57 -07003009 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
Winson Chung3d503fb2011-07-13 17:25:49 -07003010 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003011 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Adam Cohendf2cc412011-04-27 16:56:57 -07003012 (FolderInfo) item, mIconCache);
Winson Chung3d503fb2011-07-13 17:25:49 -07003013 workspace.addInScreen(newFolder, item.container, item.screen, item.cellX,
3014 item.cellY, 1, 1, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003015 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003016 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003017 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003018 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003019 }
3020
Joe Onorato9c1289c2009-08-17 11:03:03 -04003021 /**
3022 * Implementation of the method from LauncherModel.Callbacks.
3023 */
Joe Onoratoad72e172009-11-06 16:25:04 -05003024 public void bindFolders(HashMap<Long, FolderInfo> folders) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003025 setLoadOnResume();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003026 sFolders.clear();
3027 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003028 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003029
3030 /**
3031 * Add the views for a widget to the workspace.
3032 *
3033 * Implementation of the method from LauncherModel.Callbacks.
3034 */
3035 public void bindAppWidget(LauncherAppWidgetInfo item) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003036 setLoadOnResume();
3037
Daniel Sandler843e8602010-06-07 14:59:01 -04003038 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3039 if (DEBUG_WIDGETS) {
3040 Log.d(TAG, "bindAppWidget: " + item);
3041 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003042 final Workspace workspace = mWorkspace;
3043
3044 final int appWidgetId = item.appWidgetId;
3045 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003046 if (DEBUG_WIDGETS) {
3047 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3048 }
3049
Joe Onorato9c1289c2009-08-17 11:03:03 -04003050 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3051
Joe Onorato9c1289c2009-08-17 11:03:03 -04003052 item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
3053 item.hostView.setTag(item);
3054
Winson Chung3d503fb2011-07-13 17:25:49 -07003055 workspace.addInScreen(item.hostView, item.container, item.screen, item.cellX,
Joe Onorato9c1289c2009-08-17 11:03:03 -04003056 item.cellY, item.spanX, item.spanY, false);
3057
Adam Cohended9f8d2010-11-03 13:25:16 -07003058 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3059
Joe Onorato9c1289c2009-08-17 11:03:03 -04003060 workspace.requestLayout();
3061
Daniel Sandler843e8602010-06-07 14:59:01 -04003062 if (DEBUG_WIDGETS) {
3063 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3064 + (SystemClock.uptimeMillis()-start) + "ms");
3065 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003066 }
3067
3068 /**
3069 * Callback saying that there aren't any more items to bind.
3070 *
3071 * Implementation of the method from LauncherModel.Callbacks.
3072 */
3073 public void finishBindingItems() {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003074 setLoadOnResume();
3075
Joe Onorato9c1289c2009-08-17 11:03:03 -04003076 if (mSavedState != null) {
3077 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003078 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003079 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003080 mSavedState = null;
3081 }
3082
3083 if (mSavedInstanceState != null) {
3084 super.onRestoreInstanceState(mSavedInstanceState);
3085 mSavedInstanceState = null;
3086 }
3087
Joe Onorato9c1289c2009-08-17 11:03:03 -04003088 mWorkspaceLoading = false;
Patrick Dubroy002cbf42011-03-03 16:36:21 -08003089
3090 // If we received the result of any pending adds while the loader was running (e.g. the
3091 // widget configuration forced an orientation change), process them now.
3092 for (int i = 0; i < sPendingAddList.size(); i++) {
3093 completeAdd(sPendingAddList.get(i));
3094 }
3095 sPendingAddList.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003096
Winson Chungc51db6a2011-10-05 11:44:49 -07003097 // Update the market app icon as necessary (the other icons will be managed in response to
3098 // package changes in bindSearchablesChanged()
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003099 updateAppMarketIcon();
Michael Jurkac1f5d262011-09-30 19:32:27 -07003100
3101 mWorkspace.post(mBuildLayersRunnable);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003102 }
3103
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003104 @Override
3105 public void bindSearchablesChanged() {
Winson Chungc51db6a2011-10-05 11:44:49 -07003106 boolean searchVisible = updateGlobalSearchIcon();
3107 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
3108 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
Narayan Kamathcb1a4772011-06-28 13:46:59 +01003109 }
3110
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003111 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003112 * Add the icons for all apps.
3113 *
3114 * Implementation of the method from LauncherModel.Callbacks.
3115 */
Michael Jurkac57b7a82011-08-09 22:02:20 -07003116 public void bindAllApplications(final ArrayList<ApplicationInfo> apps) {
3117 // Remove the progress bar entirely; we could also make it GONE
3118 // but better to remove it since we know it's not going to be used
3119 View progressBar = mAppsCustomizeTabHost.
3120 findViewById(R.id.apps_customize_progress_bar);
3121 if (progressBar != null) {
3122 ((ViewGroup)progressBar.getParent()).removeView(progressBar);
Winson Chung785d2eb2011-04-14 16:08:02 -07003123 }
Michael Jurkac57b7a82011-08-09 22:02:20 -07003124 // We just post the call to setApps so the user sees the progress bar
3125 // disappear-- otherwise, it just looks like the progress bar froze
3126 // which doesn't look great
3127 mAppsCustomizeTabHost.post(new Runnable() {
3128 public void run() {
3129 if (mAppsCustomizeContent != null) {
3130 mAppsCustomizeContent.setApps(apps);
3131 }
3132 }
3133 });
Joe Onorato9c1289c2009-08-17 11:03:03 -04003134 }
3135
3136 /**
3137 * A package was installed.
3138 *
3139 * Implementation of the method from LauncherModel.Callbacks.
3140 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003141 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003142 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003143 removeDialog(DIALOG_CREATE_SHORTCUT);
Winson Chungf0ea4d32011-06-06 14:27:16 -07003144
Winson Chung785d2eb2011-04-14 16:08:02 -07003145 if (mAppsCustomizeContent != null) {
3146 mAppsCustomizeContent.addApps(apps);
3147 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003148 }
3149
3150 /**
3151 * A package was updated.
3152 *
3153 * Implementation of the method from LauncherModel.Callbacks.
3154 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003155 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003156 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003157 removeDialog(DIALOG_CREATE_SHORTCUT);
Patrick Dubroyf5afda72011-02-28 12:04:18 -08003158 if (mWorkspace != null) {
3159 mWorkspace.updateShortcuts(apps);
3160 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003161
Winson Chung785d2eb2011-04-14 16:08:02 -07003162 if (mAppsCustomizeContent != null) {
3163 mAppsCustomizeContent.updateApps(apps);
3164 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003165 }
3166
3167 /**
3168 * A package was uninstalled.
3169 *
3170 * Implementation of the method from LauncherModel.Callbacks.
3171 */
Joe Onorato36115782010-06-17 13:28:48 -04003172 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003173 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato36115782010-06-17 13:28:48 -04003174 if (permanent) {
3175 mWorkspace.removeItems(apps);
3176 }
Winson Chungf0ea4d32011-06-06 14:27:16 -07003177
Winson Chung785d2eb2011-04-14 16:08:02 -07003178 if (mAppsCustomizeContent != null) {
3179 mAppsCustomizeContent.removeApps(apps);
3180 }
Winson Chunga1820962011-10-03 16:31:06 -07003181
3182 // Notify the drag controller
3183 mDragController.onAppsRemoved(apps, this);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003184 }
Joe Onoratobe386092009-11-17 17:32:16 -08003185
3186 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003187 * A number of packages were updated.
3188 */
3189 public void bindPackagesUpdated() {
Winson Chung785d2eb2011-04-14 16:08:02 -07003190 if (mAppsCustomizeContent != null) {
3191 mAppsCustomizeContent.onPackagesUpdated();
3192 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003193 }
3194
Winson Chung400438b2011-01-16 17:53:48 -08003195 private int mapConfigurationOriActivityInfoOri(int configOri) {
3196 final Display d = getWindowManager().getDefaultDisplay();
3197 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
3198 switch (d.getRotation()) {
3199 case Surface.ROTATION_0:
3200 case Surface.ROTATION_180:
3201 // We are currently in the same basic orientation as the natural orientation
3202 naturalOri = configOri;
3203 break;
3204 case Surface.ROTATION_90:
3205 case Surface.ROTATION_270:
3206 // We are currently in the other basic orientation to the natural orientation
3207 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
3208 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
3209 break;
3210 }
3211
3212 int[] oriMap = {
3213 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
3214 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
3215 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
3216 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
3217 };
3218 // Since the map starts at portrait, we need to offset if this device's natural orientation
3219 // is landscape.
3220 int indexOffset = 0;
3221 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
3222 indexOffset = 1;
3223 }
3224 return oriMap[(d.getRotation() + indexOffset) % 4];
3225 }
Adam Cohen446e9402011-09-15 18:21:21 -07003226
3227 public void lockScreenOrientationOnLargeUI() {
3228 if (LauncherApplication.isScreenLarge()) {
3229 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
3230 .getConfiguration().orientation));
3231 }
Winson Chung400438b2011-01-16 17:53:48 -08003232 }
Adam Cohen446e9402011-09-15 18:21:21 -07003233 public void unlockScreenOrientationOnLargeUI() {
3234 if (LauncherApplication.isScreenLarge()) {
3235 mHandler.postDelayed(new Runnable() {
3236 public void run() {
3237 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
3238 }
3239 }, mRestoreScreenOrientationDelay);
3240 }
Winson Chung400438b2011-01-16 17:53:48 -08003241 }
3242
Winson Chung82f55532011-08-09 14:14:23 -07003243 /* Cling related */
Winson Chung7d7541e2011-09-16 20:14:36 -07003244 private static final String PREFS_KEY = "com.android.launcher2.prefs";
3245 private boolean isClingsEnabled() {
Brett Chabot2a9e2282011-08-23 15:03:13 -07003246 // disable clings when running in a test harness
Winson Chung7d7541e2011-09-16 20:14:36 -07003247 if(ActivityManager.isRunningInTestHarness()) return false;
Brett Chabot2a9e2282011-08-23 15:03:13 -07003248
Winson Chung7d7541e2011-09-16 20:14:36 -07003249 return true;
Winson Chung82f55532011-08-09 14:14:23 -07003250 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003251 private Cling initCling(int clingId, int[] positionData, boolean animate, int delay) {
3252 Cling cling = (Cling) findViewById(clingId);
3253 if (cling != null) {
3254 cling.init(this, positionData);
3255 cling.setVisibility(View.VISIBLE);
3256 cling.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3257 if (animate) {
3258 cling.buildLayer();
3259 cling.setAlpha(0f);
3260 cling.animate()
3261 .alpha(1f)
Winson Chung7a74ac92011-09-20 17:43:51 -07003262 .setInterpolator(new AccelerateInterpolator())
Winson Chung7d7541e2011-09-16 20:14:36 -07003263 .setDuration(SHOW_CLING_DURATION)
3264 .setStartDelay(delay)
3265 .start();
3266 } else {
3267 cling.setAlpha(1f);
3268 }
3269 }
3270 return cling;
3271 }
3272 private void dismissCling(final Cling cling, final String flag, int duration) {
Winson Chung82f55532011-08-09 14:14:23 -07003273 if (cling != null) {
3274 ObjectAnimator anim = ObjectAnimator.ofFloat(cling, "alpha", 0f);
Winson Chung7d7541e2011-09-16 20:14:36 -07003275 anim.setDuration(duration);
Winson Chung82f55532011-08-09 14:14:23 -07003276 anim.addListener(new AnimatorListenerAdapter() {
3277 public void onAnimationEnd(Animator animation) {
3278 cling.setVisibility(View.GONE);
3279 cling.cleanup();
3280 SharedPreferences prefs =
3281 getSharedPreferences("com.android.launcher2.prefs", Context.MODE_PRIVATE);
3282 SharedPreferences.Editor editor = prefs.edit();
3283 editor.putBoolean(flag, true);
3284 editor.commit();
3285 };
3286 });
3287 anim.start();
3288 }
3289 }
Winson Chung9d9d74f2011-09-19 11:49:12 -07003290 private void removeCling(int id) {
3291 final View cling = findViewById(id);
3292 if (cling != null) {
3293 final ViewGroup parent = (ViewGroup) cling.getParent();
3294 parent.post(new Runnable() {
3295 @Override
3296 public void run() {
3297 parent.removeView(cling);
3298 }
3299 });
3300 }
3301 }
Winson Chung7d7541e2011-09-16 20:14:36 -07003302 public void showFirstRunWorkspaceCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003303 // Enable the clings only if they have not been dismissed before
3304 SharedPreferences prefs =
3305 getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003306 if (isClingsEnabled() && !prefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003307 initCling(R.id.workspace_cling, null, false, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003308 } else {
3309 removeCling(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003310 }
3311 }
3312 public void showFirstRunAllAppsCling(int[] position) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003313 // Enable the clings only if they have not been dismissed before
3314 SharedPreferences prefs =
3315 getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003316 if (isClingsEnabled() && !prefs.getBoolean(Cling.ALLAPPS_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003317 initCling(R.id.all_apps_cling, position, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003318 } else {
3319 removeCling(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003320 }
3321 }
3322 public Cling showFirstRunFoldersCling() {
Winson Chung7d7541e2011-09-16 20:14:36 -07003323 // Enable the clings only if they have not been dismissed before
3324 SharedPreferences prefs =
3325 getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE);
3326 Cling cling = null;
Winson Chung9d9d74f2011-09-19 11:49:12 -07003327 if (isClingsEnabled() && !prefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) {
Winson Chung7d7541e2011-09-16 20:14:36 -07003328 cling = initCling(R.id.folder_cling, null, true, 0);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003329 } else {
3330 removeCling(R.id.folder_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003331 }
3332 return cling;
3333 }
3334 public boolean isFolderClingVisible() {
3335 Cling cling = (Cling) findViewById(R.id.folder_cling);
Winson Chung9d9d74f2011-09-19 11:49:12 -07003336 if (cling != null) {
3337 return cling.getVisibility() == View.VISIBLE;
3338 }
3339 return false;
Winson Chung7d7541e2011-09-16 20:14:36 -07003340 }
Winson Chung82f55532011-08-09 14:14:23 -07003341 public void dismissWorkspaceCling(View v) {
3342 Cling cling = (Cling) findViewById(R.id.workspace_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003343 dismissCling(cling, Cling.WORKSPACE_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07003344 }
3345 public void dismissAllAppsCling(View v) {
3346 Cling cling = (Cling) findViewById(R.id.all_apps_cling);
Winson Chung7d7541e2011-09-16 20:14:36 -07003347 dismissCling(cling, Cling.ALLAPPS_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
3348 }
3349 public void dismissFolderCling(View v) {
3350 Cling cling = (Cling) findViewById(R.id.folder_cling);
3351 dismissCling(cling, Cling.FOLDER_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION);
Winson Chung82f55532011-08-09 14:14:23 -07003352 }
3353
Winson Chung80baf5a2010-08-09 16:03:15 -07003354 /**
Joe Onoratobe386092009-11-17 17:32:16 -08003355 * Prints out out state for debugging.
3356 */
3357 public void dumpState() {
3358 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08003359 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08003360 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
3361 Log.d(TAG, "mRestoring=" + mRestoring);
3362 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
3363 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003364 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08003365 mModel.dumpState();
Winson Chungf0ea4d32011-06-06 14:27:16 -07003366
Winson Chung785d2eb2011-04-14 16:08:02 -07003367 if (mAppsCustomizeContent != null) {
3368 mAppsCustomizeContent.dumpState();
3369 }
Joe Onoratobe386092009-11-17 17:32:16 -08003370 Log.d(TAG, "END launcher2 dump state");
3371 }
Adam Cohen16d7ffc2011-10-05 17:49:14 -07003372
3373 @Override
3374 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
3375 super.dump(prefix, fd, writer, args);
3376 writer.println(" ");
3377 writer.println("Debug logs: ");
3378 for (int i = 0; i < sDumpLogs.size(); i++) {
3379 writer.println(" " + sDumpLogs.get(i));
3380 }
3381 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003382}
Michael Jurka2763be32011-02-24 11:19:57 -08003383
Michael Jurkaabded662011-03-04 12:06:57 -08003384interface LauncherTransitionable {
Michael Jurka2a4b1a82011-12-07 14:00:02 -08003385 View getContent();
Michael Jurka9433fa72012-01-19 08:50:41 -08003386 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
3387 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
Michael Jurka2763be32011-02-24 11:19:57 -08003388}