blob: eacaef9080560e9aba84928e1da6dae16a89a62b [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
Winson Chung68846fd2010-10-29 11:00:27 -070020import java.io.DataInputStream;
21import java.io.DataOutputStream;
22import java.io.FileNotFoundException;
23import java.io.IOException;
24import java.util.ArrayList;
25import java.util.HashMap;
26import java.util.List;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070027
Gilles Debunnedd6c9922010-10-25 11:23:41 -070028import android.animation.Animator;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070029import android.animation.AnimatorSet;
Chet Haaseb1254a62010-09-07 13:35:00 -070030import android.animation.ObjectAnimator;
Patrick Dubroy07a0de42010-08-26 11:48:35 -070031import android.animation.PropertyValuesHolder;
Gilles Debunnedd6c9922010-10-25 11:23:41 -070032import android.animation.ValueAnimator;
Michael Jurka946ad472010-07-09 18:05:18 -070033import android.app.Activity;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080034import android.app.AlertDialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080035import android.app.Dialog;
36import android.app.SearchManager;
37import android.app.StatusBarManager;
Dianne Hackborn107f8392009-08-05 21:32:16 -070038import android.app.WallpaperManager;
Michael Jurkaaf442092010-06-10 17:01:57 -070039import android.appwidget.AppWidgetManager;
40import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080042import android.content.BroadcastReceiver;
Winson Chung68846fd2010-10-29 11:00:27 -070043import android.content.ClipData;
44import android.content.ClipDescription;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040045import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080046import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080047import android.content.Context;
48import android.content.DialogInterface;
49import android.content.Intent;
Winson Chung68846fd2010-10-29 11:00:27 -070050import android.content.IntentFilter;
Adam Cohended9f8d2010-11-03 13:25:16 -070051import android.content.Intent.ShortcutIconResource;
Winson Chungaafa03c2010-06-11 17:34:16 -070052import android.content.pm.ActivityInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080053import android.content.pm.PackageManager;
Winson Chung68846fd2010-10-29 11:00:27 -070054import android.content.pm.ResolveInfo;
Adam Cohended9f8d2010-11-03 13:25:16 -070055import android.content.pm.PackageManager.NameNotFoundException;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080056import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070057import android.content.res.Resources;
Daniel Sandlerab1ebd72010-04-27 16:57:25 -040058import android.content.res.TypedArray;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080059import android.database.ContentObserver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080060import android.graphics.Bitmap;
Romain Guya6abce82009-11-10 02:54:41 -080061import android.graphics.Canvas;
Michael Jurkaaf442092010-06-10 17:01:57 -070062import android.graphics.Rect;
Romain Guyff0c2e22009-11-10 12:09:59 -080063import android.graphics.drawable.ColorDrawable;
Michael Jurkaaf442092010-06-10 17:01:57 -070064import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040065import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070066import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080067import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020068import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080069import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070070import android.os.Message;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080071import android.os.Parcelable;
Daniel Sandler843e8602010-06-07 14:59:01 -040072import android.os.SystemClock;
Joe Onoratobe386092009-11-17 17:32:16 -080073import android.os.SystemProperties;
Karl Rosaen138a0412009-04-23 19:00:21 -070074import android.provider.LiveFolders;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070075import android.provider.Settings;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080076import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080077import android.text.Selection;
78import android.text.SpannableStringBuilder;
79import android.text.TextUtils;
80import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070081import android.util.Log;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080082import android.view.Display;
Joe Onorato0d44e942009-11-16 18:20:51 -080083import android.view.HapticFeedbackConstants;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080084import android.view.KeyEvent;
85import android.view.LayoutInflater;
86import android.view.Menu;
87import android.view.MenuItem;
Michael Jurka0e260592010-06-30 17:07:39 -070088import android.view.MotionEvent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080089import android.view.View;
90import android.view.ViewGroup;
Winson Chungaafa03c2010-06-11 17:34:16 -070091import android.view.WindowManager;
Adam Cohended9f8d2010-11-03 13:25:16 -070092import android.view.View.OnLongClickListener;
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -070093import android.view.animation.AccelerateInterpolator;
Patrick Dubroy7247f632010-08-04 16:02:59 -070094import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080095import android.view.inputmethod.InputMethodManager;
Adam Cohended9f8d2010-11-03 13:25:16 -070096import android.widget.Advanceable;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080097import android.widget.EditText;
Michael Jurkaaf442092010-06-10 17:01:57 -070098import android.widget.ImageView;
99import android.widget.LinearLayout;
100import android.widget.PopupWindow;
Michael Jurka0e260592010-06-30 17:07:39 -0700101import android.widget.TabHost;
Winson Chung49767ae2010-11-29 14:48:30 -0800102import android.widget.TabWidget;
Winson Chung68846fd2010-10-29 11:00:27 -0700103import android.widget.TextView;
104import android.widget.Toast;
Adam Cohended9f8d2010-11-03 13:25:16 -0700105import android.widget.TabHost.OnTabChangeListener;
106import android.widget.TabHost.TabContentFactory;
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700107
Winson Chung68846fd2010-10-29 11:00:27 -0700108import com.android.common.Search;
109import com.android.launcher.R;
Romain Guyedcce092010-03-04 13:03:17 -0800110
Adam Cohended9f8d2010-11-03 13:25:16 -0700111
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800112/**
113 * Default launcher application.
114 */
Michael Jurka946ad472010-07-09 18:05:18 -0700115public final class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700116 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
117 AllAppsView.Watcher, View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800118 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700119 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800120
Joe Onorato9c1289c2009-08-17 11:03:03 -0400121 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400122 static final boolean DEBUG_WIDGETS = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400123 static final boolean DEBUG_USER_INTERFACE = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700124
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800125 private static final int MENU_GROUP_ADD = 1;
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800126 private static final int MENU_GROUP_WALLPAPER = MENU_GROUP_ADD + 1;
127
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800128 private static final int MENU_ADD = Menu.FIRST + 1;
Winson Chung7ad01412010-09-27 11:33:03 -0700129 private static final int MENU_MANAGE_APPS = MENU_ADD + 1;
130 private static final int MENU_WALLPAPER_SETTINGS = MENU_MANAGE_APPS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800131 private static final int MENU_SEARCH = MENU_WALLPAPER_SETTINGS + 1;
132 private static final int MENU_NOTIFICATIONS = MENU_SEARCH + 1;
Romain Guy94dabf12009-07-21 10:55:43 -0700133 private static final int MENU_SETTINGS = MENU_NOTIFICATIONS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800134
135 private static final int REQUEST_CREATE_SHORTCUT = 1;
136 private static final int REQUEST_CREATE_LIVE_FOLDER = 4;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700137 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800138 private static final int REQUEST_PICK_APPLICATION = 6;
139 private static final int REQUEST_PICK_SHORTCUT = 7;
140 private static final int REQUEST_PICK_LIVE_FOLDER = 8;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700141 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700142 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800143
144 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
145
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800146 static final int SCREEN_COUNT = 5;
147 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800148
Joe Onorato7c312c12009-08-13 21:36:53 -0700149 static final int DIALOG_CREATE_SHORTCUT = 1;
150 static final int DIALOG_RENAME_FOLDER = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800151
Romain Guy98d01652009-06-30 16:21:04 -0700152 private static final String PREFERENCES = "launcher.preferences";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800153
154 // Type: int
155 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700156 // Type: int
157 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800158 // Type: long
159 private static final String RUNTIME_STATE_USER_FOLDERS = "launcher.user_folder";
160 // Type: int
161 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
162 // Type: int
163 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cellX";
164 // Type: int
165 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cellY";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800166 // Type: boolean
167 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
168 // Type: long
169 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
170
Winson Chung80baf5a2010-08-09 16:03:15 -0700171 // tags for the customization tabs
172 private static final String WIDGETS_TAG = "widgets";
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700173 private static final String APPLICATIONS_TAG = "applications";
Winson Chung80baf5a2010-08-09 16:03:15 -0700174 private static final String SHORTCUTS_TAG = "shortcuts";
175 private static final String WALLPAPERS_TAG = "wallpapers";
176
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700177 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
178
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700179 /** The different states that Launcher can be in. */
180 private enum State { WORKSPACE, ALL_APPS, CUSTOMIZE, OVERVIEW };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700181 private State mState = State.WORKSPACE;
182 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700183
Joe Onorato9c1289c2009-08-17 11:03:03 -0400184 static final int APPWIDGET_HOST_ID = 1024;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800185
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800186 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800187 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800188
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800189 private final BroadcastReceiver mCloseSystemDialogsReceiver
190 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800191 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
192
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800193 private LayoutInflater mInflater;
194
Joe Onorato00acb122009-08-04 16:04:30 -0400195 private DragController mDragController;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800196 private Workspace mWorkspace;
Romain Guycbb89e42009-06-08 15:52:54 -0700197
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700198 private AppWidgetManager mAppWidgetManager;
199 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700200
Michael Jurka0280c3b2010-09-17 15:00:07 -0700201 private int mAddScreen = -1;
202 private int mAddIntersectCellX = -1;
203 private int mAddIntersectCellY = -1;
204 private int[] mAddDropPosition;
205 private int[] mTmpAddItemCellCoordinates = new int[2];
206
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800207 private FolderInfo mFolderInfo;
208
Joe Onorato7c312c12009-08-13 21:36:53 -0700209 private DeleteZone mDeleteZone;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700210 private HandleView mHandleView;
Joe Onorato7c312c12009-08-13 21:36:53 -0700211 private AllAppsView mAllAppsGrid;
Michael Jurka0e260592010-06-30 17:07:39 -0700212 private TabHost mHomeCustomizationDrawer;
Adam Cohended9f8d2010-11-03 13:25:16 -0700213 private boolean mAutoAdvanceRunning = false;
Patrick Dubroy2b9ff372010-09-07 17:49:27 -0700214
215 private PagedView mAllAppsPagedView = null;
216 private CustomizePagedView mCustomizePagedView = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800217
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800218 private Bundle mSavedState;
219
220 private SpannableStringBuilder mDefaultKeySsb = null;
221
Joe Onorato9c1289c2009-08-17 11:03:03 -0400222 private boolean mWorkspaceLoading = true;
223
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800224 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800225 private boolean mRestoring;
226 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700227 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800228
229 private Bundle mSavedInstanceState;
230
Joe Onorato9c1289c2009-08-17 11:03:03 -0400231 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800232 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800233 private boolean mUserPresent = true;
234 private boolean mVisible = false;
235 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400236
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700237 private static LocaleConfiguration sLocaleConfiguration = null;
238
Romain Guy84f296c2009-11-04 15:00:44 -0800239 private ArrayList<ItemInfo> mDesktopItems = new ArrayList<ItemInfo>();
Adam Cohended9f8d2010-11-03 13:25:16 -0700240
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700241 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700242
Romain Guy1fbc1c82009-11-09 20:43:08 -0800243 private ImageView mPreviousView;
244 private ImageView mNextView;
Joe Onorato080d9b62009-11-02 12:01:11 -0500245
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400246 // Hotseats (quick-launch icons next to AllApps)
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400247 private String[] mHotseatConfig = null;
248 private Intent[] mHotseats = null;
249 private Drawable[] mHotseatIcons = null;
250 private CharSequence[] mHotseatLabels = null;
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400251
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700252 private Intent mAppMarketIntent = null;
253
Adam Cohended9f8d2010-11-03 13:25:16 -0700254 // Related to the auto-advancing of widgets
255 private final int ADVANCE_MSG = 1;
256 private final int mAdvanceInterval = 20000;
257 private final int mAdvanceStagger = 250;
258 private long mAutoAdvanceSentTime;
259 private long mAutoAdvanceTimeLeft = -1;
260 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
261 new HashMap<View, AppWidgetProviderInfo>();
262
Michael Jurka4ef207b2010-11-29 17:05:45 -0800263 // External icons saved in case of resource changes, orientation, etc.
264 private static Drawable sGlobalSearchIcon;
265 private static Drawable sVoiceSearchIcon;
266 private static Drawable sAppMarketIcon;
267
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800268 @Override
269 protected void onCreate(Bundle savedInstanceState) {
270 super.onCreate(savedInstanceState);
Romain Guyb1b69f52009-08-10 15:10:15 -0700271
Winson Chungaafa03c2010-06-11 17:34:16 -0700272 if (LauncherApplication.isInPlaceRotationEnabled()) {
273 // hide the status bar (temporary until we get the status bar design figured out)
274 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
275 this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
276 }
277
Joe Onorato0589f0f2010-02-08 13:44:00 -0800278 LauncherApplication app = ((LauncherApplication)getApplication());
279 mModel = app.setLauncher(this);
280 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400281 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800282 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700283
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700284 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700285 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
286 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700287
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800288 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200289 android.os.Debug.startMethodTracing(
290 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800291 }
292
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400293 loadHotseats();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800294 checkForLocaleChange();
295 setWallpaperDimension();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800296 setContentView(R.layout.launcher);
Michael Jurka946ad472010-07-09 18:05:18 -0700297 mHomeCustomizationDrawer = (TabHost) findViewById(com.android.internal.R.id.tabhost);
298 if (mHomeCustomizationDrawer != null) {
299 mHomeCustomizationDrawer.setup();
Winson Chungaafa03c2010-06-11 17:34:16 -0700300
Winson Chung80baf5a2010-08-09 16:03:15 -0700301 // share the same customization workspace across all the tabs
Winson Chunge3193b92010-09-10 11:44:42 -0700302 mCustomizePagedView = (CustomizePagedView) mInflater.inflate(
303 R.layout.customization_drawer, mHomeCustomizationDrawer, false);
Winson Chung80baf5a2010-08-09 16:03:15 -0700304 TabContentFactory contentFactory = new TabContentFactory() {
305 public View createTabContent(String tag) {
306 return mCustomizePagedView;
307 }
308 };
309
Winson Chung49767ae2010-11-29 14:48:30 -0800310
311 TextView tabView;
312 TabWidget tabWidget = (TabWidget)
313 mHomeCustomizationDrawer.findViewById(com.android.internal.R.id.tabs);
314
315 tabView = (TextView) mInflater.inflate(R.layout.tab_widget_indicator, tabWidget, false);
316 tabView.setText(getString(R.string.widgets_tab_label));
Winson Chung80baf5a2010-08-09 16:03:15 -0700317 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(WIDGETS_TAG)
Winson Chung49767ae2010-11-29 14:48:30 -0800318 .setIndicator(tabView).setContent(contentFactory));
319 tabView = (TextView) mInflater.inflate(R.layout.tab_widget_indicator, tabWidget, false);
320 tabView.setText(getString(R.string.applications_tab_label));
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700321 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(APPLICATIONS_TAG)
Winson Chung49767ae2010-11-29 14:48:30 -0800322 .setIndicator(tabView).setContent(contentFactory));
323 tabView = (TextView) mInflater.inflate(R.layout.tab_widget_indicator, tabWidget, false);
324 tabView.setText(getString(R.string.wallpapers_tab_label));
Winson Chung80baf5a2010-08-09 16:03:15 -0700325 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(WALLPAPERS_TAG)
Winson Chung49767ae2010-11-29 14:48:30 -0800326 .setIndicator(tabView).setContent(contentFactory));
327 tabView = (TextView) mInflater.inflate(R.layout.tab_widget_indicator, tabWidget, false);
328 tabView.setText(getString(R.string.shortcuts_tab_label));
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700329 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(SHORTCUTS_TAG)
Winson Chung49767ae2010-11-29 14:48:30 -0800330 .setIndicator(tabView).setContent(contentFactory));
Winson Chung80baf5a2010-08-09 16:03:15 -0700331 mHomeCustomizationDrawer.setOnTabChangedListener(new OnTabChangeListener() {
332 public void onTabChanged(String tabId) {
333 // animate the changing of the tab content by fading pages in and out
Winson Chungbbc60d82010-11-11 16:34:41 -0800334 final Resources res = getResources();
335 final int duration = res.getInteger(R.integer.config_tabTransitionTime);
Winson Chung80baf5a2010-08-09 16:03:15 -0700336 final float alpha = mCustomizePagedView.getAlpha();
Chet Haase472b2812010-10-14 07:02:04 -0700337 ValueAnimator alphaAnim = ObjectAnimator.ofFloat(mCustomizePagedView,
Winson Chung80baf5a2010-08-09 16:03:15 -0700338 "alpha", alpha, 0.0f);
Chet Haase472b2812010-10-14 07:02:04 -0700339 alphaAnim.setDuration(duration);
Michael Jurka3c4c20f2010-10-28 15:36:06 -0700340 alphaAnim.addListener(new LauncherAnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700341 @Override
Michael Jurka3c4c20f2010-10-28 15:36:06 -0700342 public void onAnimationEndOrCancel(Animator animation) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700343 String tag = mHomeCustomizationDrawer.getCurrentTabTag();
344 if (tag == WIDGETS_TAG) {
345 mCustomizePagedView.setCustomizationFilter(
346 CustomizePagedView.CustomizationType.WidgetCustomization);
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700347 } else if (tag == APPLICATIONS_TAG) {
348 mCustomizePagedView.setCustomizationFilter(
349 CustomizePagedView.CustomizationType.ApplicationCustomization);
Winson Chung80baf5a2010-08-09 16:03:15 -0700350 } else if (tag == WALLPAPERS_TAG) {
351 mCustomizePagedView.setCustomizationFilter(
352 CustomizePagedView.CustomizationType.WallpaperCustomization);
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700353 } else if (tag == SHORTCUTS_TAG) {
354 mCustomizePagedView.setCustomizationFilter(
355 CustomizePagedView.CustomizationType.ShortcutCustomization);
Winson Chung80baf5a2010-08-09 16:03:15 -0700356 }
357
358 final float alpha = mCustomizePagedView.getAlpha();
Chet Haase472b2812010-10-14 07:02:04 -0700359 ValueAnimator alphaAnim = ObjectAnimator.ofFloat(
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700360 mCustomizePagedView, "alpha", alpha, 1.0f);
Chet Haase472b2812010-10-14 07:02:04 -0700361 alphaAnim.setDuration(duration);
Winson Chung80baf5a2010-08-09 16:03:15 -0700362 alphaAnim.start();
363 }
364 });
365 alphaAnim.start();
366 }
367 });
Michael Jurka946ad472010-07-09 18:05:18 -0700368 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800369 setupViews();
370
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800371 registerContentObservers();
372
Joe Onorato7c312c12009-08-13 21:36:53 -0700373 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700374
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800375 mSavedState = savedInstanceState;
376 restoreState(mSavedState);
377
378 if (PROFILE_STARTUP) {
379 android.os.Debug.stopMethodTracing();
380 }
381
382 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400383 mModel.startLoader(this, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800384 }
385
386 // For handling default keys
387 mDefaultKeySsb = new SpannableStringBuilder();
388 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800389
390 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
391 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800392
393 // If we have a saved version of these external icons, we load them up immediately
394 if (LauncherApplication.isScreenXLarge()) {
395 if (sGlobalSearchIcon != null) {
396 updateGlobalSearchIcon(sGlobalSearchIcon);
397 }
398 if (sVoiceSearchIcon != null) {
399 updateVoiceSearchIcon(sVoiceSearchIcon);
400 }
401 if (sAppMarketIcon != null) {
402 updateAppMarketIcon(sAppMarketIcon);
403 }
404 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800405 }
Romain Guycbb89e42009-06-08 15:52:54 -0700406
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800407 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700408 if (sLocaleConfiguration == null) {
409 new AsyncTask<Void, Void, LocaleConfiguration>() {
410 @Override
411 protected LocaleConfiguration doInBackground(Void... unused) {
412 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
413 readConfiguration(Launcher.this, localeConfiguration);
414 return localeConfiguration;
415 }
416
417 @Override
418 protected void onPostExecute(LocaleConfiguration result) {
419 sLocaleConfiguration = result;
420 checkForLocaleChange(); // recursive, but now with a locale configuration
421 }
422 }.execute();
423 return;
424 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700425
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800426 final Configuration configuration = getResources().getConfiguration();
427
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700428 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800429 final String locale = configuration.locale.toString();
430
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700431 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800432 final int mcc = configuration.mcc;
433
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700434 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800435 final int mnc = configuration.mnc;
436
Romain Guy84f296c2009-11-04 15:00:44 -0800437 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800438
Romain Guy84f296c2009-11-04 15:00:44 -0800439 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700440 sLocaleConfiguration.locale = locale;
441 sLocaleConfiguration.mcc = mcc;
442 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700443
Joe Onorato0589f0f2010-02-08 13:44:00 -0800444 mIconCache.flush();
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400445 loadHotseats();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700446
447 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
448 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700449 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700450 public void run() {
451 writeConfiguration(Launcher.this, localeConfiguration);
452 }
453 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700454 }
455 }
456
457 private static class LocaleConfiguration {
458 public String locale;
459 public int mcc = -1;
460 public int mnc = -1;
461 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700462
Romain Guy98d01652009-06-30 16:21:04 -0700463 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
464 DataInputStream in = null;
465 try {
466 in = new DataInputStream(context.openFileInput(PREFERENCES));
467 configuration.locale = in.readUTF();
468 configuration.mcc = in.readInt();
469 configuration.mnc = in.readInt();
470 } catch (FileNotFoundException e) {
471 // Ignore
472 } catch (IOException e) {
473 // Ignore
474 } finally {
475 if (in != null) {
476 try {
477 in.close();
478 } catch (IOException e) {
479 // Ignore
480 }
481 }
482 }
483 }
484
485 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
486 DataOutputStream out = null;
487 try {
488 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
489 out.writeUTF(configuration.locale);
490 out.writeInt(configuration.mcc);
491 out.writeInt(configuration.mnc);
492 out.flush();
493 } catch (FileNotFoundException e) {
494 // Ignore
495 } catch (IOException e) {
496 //noinspection ResultOfMethodCallIgnored
497 context.getFileStreamPath(PREFERENCES).delete();
498 } finally {
499 if (out != null) {
500 try {
501 out.close();
502 } catch (IOException e) {
503 // Ignore
504 }
505 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800506 }
507 }
508
509 static int getScreen() {
510 synchronized (sLock) {
511 return sScreen;
512 }
513 }
514
515 static void setScreen(int screen) {
516 synchronized (sLock) {
517 sScreen = screen;
518 }
519 }
520
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800521 private void setWallpaperDimension() {
Dianne Hackborn107f8392009-08-05 21:32:16 -0700522 WallpaperManager wpm = (WallpaperManager)getSystemService(WALLPAPER_SERVICE);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800523
524 Display display = getWindowManager().getDefaultDisplay();
Romain Guy5bbc91b2010-08-18 11:38:46 -0700525 // TODO: Put back when we decide about scrolling the wallpaper
526 // boolean isPortrait = display.getWidth() < display.getHeight();
527 // final int width = isPortrait ? display.getWidth() : display.getHeight();
528 // final int height = isPortrait ? display.getHeight() : display.getWidth();
529 wpm.suggestDesiredDimensions(Math.max(display.getWidth(), display.getHeight()),
530 Math.max(display.getWidth(), display.getHeight()));
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800531 }
532
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400533 // Note: This doesn't do all the client-id magic that BrowserProvider does
534 // in Browser. (http://b/2425179)
535 private Uri getDefaultBrowserUri() {
536 String url = getString(R.string.default_browser_url);
537 if (url.indexOf("{CID}") != -1) {
538 url = url.replace("{CID}", "android-google");
539 }
540 return Uri.parse(url);
541 }
542
543 // Load the Intent templates from arrays.xml to populate the hotseats. For
544 // each Intent, if it resolves to a single app, use that as the launch
545 // intent & use that app's label as the contentDescription. Otherwise,
546 // retain the ResolveActivity so the user can pick an app.
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400547 private void loadHotseats() {
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400548 if (mHotseatConfig == null) {
549 mHotseatConfig = getResources().getStringArray(R.array.hotseats);
550 if (mHotseatConfig.length > 0) {
551 mHotseats = new Intent[mHotseatConfig.length];
552 mHotseatLabels = new CharSequence[mHotseatConfig.length];
553 mHotseatIcons = new Drawable[mHotseatConfig.length];
554 } else {
555 mHotseats = null;
556 mHotseatIcons = null;
557 mHotseatLabels = null;
558 }
559
560 TypedArray hotseatIconDrawables = getResources().obtainTypedArray(R.array.hotseat_icons);
561 for (int i=0; i<mHotseatConfig.length; i++) {
562 // load icon for this slot; currently unrelated to the actual activity
563 try {
564 mHotseatIcons[i] = hotseatIconDrawables.getDrawable(i);
565 } catch (ArrayIndexOutOfBoundsException ex) {
566 Log.w(TAG, "Missing hotseat_icons array item #" + i);
567 mHotseatIcons[i] = null;
568 }
569 }
570 hotseatIconDrawables.recycle();
571 }
572
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400573 PackageManager pm = getPackageManager();
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400574 for (int i=0; i<mHotseatConfig.length; i++) {
575 Intent intent = null;
576 if (mHotseatConfig[i].equals("*BROWSER*")) {
577 // magic value meaning "launch user's default web browser"
578 // replace it with a generic web request so we can see if there is indeed a default
579 String defaultUri = getString(R.string.default_browser_url);
580 intent = new Intent(
581 Intent.ACTION_VIEW,
582 ((defaultUri != null)
583 ? Uri.parse(defaultUri)
584 : getDefaultBrowserUri())
585 ).addCategory(Intent.CATEGORY_BROWSABLE);
586 // note: if the user launches this without a default set, she
587 // will always be taken to the default URL above; this is
588 // unavoidable as we must specify a valid URL in order for the
Winson Chungaafa03c2010-06-11 17:34:16 -0700589 // chooser to appear, and once the user selects something, that
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400590 // URL is unavoidably sent to the chosen app.
591 } else {
592 try {
593 intent = Intent.parseUri(mHotseatConfig[i], 0);
594 } catch (java.net.URISyntaxException ex) {
595 Log.w(TAG, "Invalid hotseat intent: " + mHotseatConfig[i]);
596 // bogus; leave intent=null
597 }
598 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700599
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400600 if (intent == null) {
601 mHotseats[i] = null;
602 mHotseatLabels[i] = getText(R.string.activity_not_found);
603 continue;
604 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400605
606 if (LOGD) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700607 Log.d(TAG, "loadHotseats: hotseat " + i
608 + " initial intent=["
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400609 + intent.toUri(Intent.URI_INTENT_SCHEME)
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400610 + "]");
611 }
612
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400613 ResolveInfo bestMatch = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
614 List<ResolveInfo> allMatches = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
Winson Chungaafa03c2010-06-11 17:34:16 -0700615 if (LOGD) {
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400616 Log.d(TAG, "Best match for intent: " + bestMatch);
617 Log.d(TAG, "All matches: ");
618 for (ResolveInfo ri : allMatches) {
619 Log.d(TAG, " --> " + ri);
620 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400621 }
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400622 // did this resolve to a single app, or the resolver?
623 if (allMatches.size() == 0 || bestMatch == null) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700624 // can't find any activity to handle this. let's leave the
625 // intent as-is and let Launcher show a toast when it fails
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400626 // to launch.
627 mHotseats[i] = intent;
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400628
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400629 // set accessibility text to "Not installed"
630 mHotseatLabels[i] = getText(R.string.activity_not_found);
631 } else {
632 boolean found = false;
633 for (ResolveInfo ri : allMatches) {
634 if (bestMatch.activityInfo.name.equals(ri.activityInfo.name)
635 && bestMatch.activityInfo.applicationInfo.packageName
636 .equals(ri.activityInfo.applicationInfo.packageName)) {
637 found = true;
638 break;
639 }
640 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700641
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400642 if (!found) {
643 if (LOGD) Log.d(TAG, "Multiple options, no default yet");
644 // the bestMatch is probably the ResolveActivity, meaning the
645 // user has not yet selected a default
646 // so: we'll keep the original intent for now
647 mHotseats[i] = intent;
648
649 // set the accessibility text to "Select shortcut"
650 mHotseatLabels[i] = getText(R.string.title_select_shortcut);
651 } else {
652 // we have an app!
653 // now reconstruct the intent to launch it through the front
654 // door
655 ComponentName com = new ComponentName(
656 bestMatch.activityInfo.applicationInfo.packageName,
657 bestMatch.activityInfo.name);
658 mHotseats[i] = new Intent(Intent.ACTION_MAIN).setComponent(com);
659
660 // load the app label for accessibility
661 mHotseatLabels[i] = bestMatch.activityInfo.loadLabel(pm);
662 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400663 }
664
665 if (LOGD) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700666 Log.d(TAG, "loadHotseats: hotseat " + i
667 + " final intent=["
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400668 + ((mHotseats[i] == null)
669 ? "null"
670 : mHotseats[i].toUri(Intent.URI_INTENT_SCHEME))
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400671 + "] label=[" + mHotseatLabels[i]
672 + "]"
673 );
674 }
675 }
676 }
677
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800678 @Override
679 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Romain Guyaad5ef42009-06-10 02:48:37 -0700680 mWaitingForResult = false;
681
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800682 // The pattern used here is that a user PICKs a specific application,
683 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700684
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800685 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
686 // launch over to the Music app to actually CREATE_SHORTCUT.
Romain Guycbb89e42009-06-08 15:52:54 -0700687
Michael Jurka0280c3b2010-09-17 15:00:07 -0700688 if (resultCode == RESULT_OK && mAddScreen != -1) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800689 switch (requestCode) {
690 case REQUEST_PICK_APPLICATION:
Michael Jurka28750fb2010-09-24 17:43:49 -0700691 completeAddApplication(
692 this, data, mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800693 break;
694 case REQUEST_PICK_SHORTCUT:
Joe Onoratodeb98af2010-02-19 14:59:39 -0800695 processShortcut(data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800696 break;
697 case REQUEST_CREATE_SHORTCUT:
Michael Jurka0280c3b2010-09-17 15:00:07 -0700698 completeAddShortcut(data, mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800699 break;
700 case REQUEST_PICK_LIVE_FOLDER:
701 addLiveFolder(data);
702 break;
703 case REQUEST_CREATE_LIVE_FOLDER:
Michael Jurka0280c3b2010-09-17 15:00:07 -0700704 completeAddLiveFolder(data, mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800705 break;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700706 case REQUEST_PICK_APPWIDGET:
Michael Jurkaaf442092010-06-10 17:01:57 -0700707 addAppWidgetFromPick(data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800708 break;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700709 case REQUEST_CREATE_APPWIDGET:
Michael Jurkaaf442092010-06-10 17:01:57 -0700710 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700711 completeAddAppWidget(appWidgetId, mAddScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800712 break;
Mike Clerona0618e42009-10-22 13:55:21 -0700713 case REQUEST_PICK_WALLPAPER:
714 // We just wanted the activity result here so we can clear mWaitingForResult
715 break;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800716 }
Romain Guy18042c82009-11-06 11:44:55 -0800717 } else if ((requestCode == REQUEST_PICK_APPWIDGET ||
718 requestCode == REQUEST_CREATE_APPWIDGET) && resultCode == RESULT_CANCELED &&
719 data != null) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700720 // Clean up the appWidgetId if we canceled
721 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
722 if (appWidgetId != -1) {
723 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800724 }
725 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800726 }
727
728 @Override
729 protected void onResume() {
730 super.onResume();
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800731 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700732 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400733 mWorkspaceLoading = true;
734 mModel.startLoader(this, true);
735 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700736 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800737 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700738 // When we resume Launcher, a different Activity might be responsible for the app
739 // market intent, so refresh the icon
740 updateAppMarketIcon();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800741 }
742
743 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700744 protected void onPause() {
745 super.onPause();
Michael Jurkaaf442092010-06-10 17:01:57 -0700746 // Some launcher layouts don't have a previous and next view
747 if (mPreviousView != null) {
748 dismissPreview(mPreviousView);
Patrick Dubroyab962b72010-07-26 12:10:10 -0700749 }
750 if (mNextView != null) {
Michael Jurkaaf442092010-06-10 17:01:57 -0700751 dismissPreview(mNextView);
752 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700753 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800754 mDragController.cancelDrag();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700755 }
Romain Guycbb89e42009-06-08 15:52:54 -0700756
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700757 @Override
758 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400759 // Flag the loader to stop early before switching
760 mModel.stopLoader();
Romain Guy13c2e7b2010-03-10 19:45:00 -0800761 mAllAppsGrid.surrender();
Romain Guy13c2e7b2010-03-10 19:45:00 -0800762 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700763 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700764
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800765 // We can't hide the IME if it was forced open. So don't bother
766 /*
767 @Override
768 public void onWindowFocusChanged(boolean hasFocus) {
769 super.onWindowFocusChanged(hasFocus);
770
771 if (hasFocus) {
772 final InputMethodManager inputManager = (InputMethodManager)
773 getSystemService(Context.INPUT_METHOD_SERVICE);
774 WindowManager.LayoutParams lp = getWindow().getAttributes();
775 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
776 android.os.Handler()) {
777 protected void onReceiveResult(int resultCode, Bundle resultData) {
778 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
779 }
780 });
781 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
782 }
783 }
784 */
785
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800786 private boolean acceptFilter() {
787 final InputMethodManager inputManager = (InputMethodManager)
788 getSystemService(Context.INPUT_METHOD_SERVICE);
789 return !inputManager.isFullscreenMode();
790 }
791
792 @Override
793 public boolean onKeyDown(int keyCode, KeyEvent event) {
794 boolean handled = super.onKeyDown(keyCode, event);
795 if (!handled && acceptFilter() && keyCode != KeyEvent.KEYCODE_ENTER) {
796 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
797 keyCode, event);
798 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700799 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700800 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700801 // showSearchDialog()
802 // If there are multiple keystrokes before the search dialog takes focus,
803 // onSearchRequested() will be called for every keystroke,
804 // but it is idempotent, so it's fine.
805 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800806 }
807 }
808
Joe Onorato8a9625e2010-01-28 15:55:35 -0800809 // Eat the long press event so the keyboard doesn't come up.
810 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
811 return true;
812 }
813
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800814 return handled;
815 }
816
Karl Rosaen138a0412009-04-23 19:00:21 -0700817 private String getTypedText() {
818 return mDefaultKeySsb.toString();
819 }
820
821 private void clearTypedText() {
822 mDefaultKeySsb.clear();
823 mDefaultKeySsb.clearSpans();
824 Selection.setSelection(mDefaultKeySsb, 0);
825 }
826
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800827 /**
Michael Jurka883f55b2010-10-21 15:47:14 -0700828 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
829 * State
830 */
831 private static State intToState(int stateOrdinal) {
832 State state = State.WORKSPACE;
833 final State[] stateValues = State.values();
834 for (int i = 0; i < stateValues.length; i++) {
835 if (stateValues[i].ordinal() == stateOrdinal) {
836 state = stateValues[i];
837 break;
838 }
839 }
840 return state;
841 }
842
843 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800844 * Restores the previous state, if it exists.
845 *
846 * @param savedState The previous state.
847 */
848 private void restoreState(Bundle savedState) {
849 if (savedState == null) {
850 return;
851 }
852
Michael Jurka883f55b2010-10-21 15:47:14 -0700853 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
854
855 if (state == State.ALL_APPS) {
Joe Onorato3a8820b2009-11-10 15:06:42 -0800856 showAllApps(false);
Michael Jurka883f55b2010-10-21 15:47:14 -0700857 } else if (state == State.CUSTOMIZE) {
858 showCustomizationDrawer(false);
Joe Onorato3a8820b2009-11-10 15:06:42 -0800859 }
860
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800861 final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
862 if (currentScreen > -1) {
Michael Jurka0142d492010-08-25 17:46:15 -0700863 mWorkspace.setCurrentPage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800864 }
865
866 final int addScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700867
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800868 if (addScreen > -1) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700869 mAddScreen = addScreen;
870 mAddIntersectCellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
871 mAddIntersectCellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800872 mRestoring = true;
873 }
874
875 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
876 if (renameFolder) {
877 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700878 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800879 mRestoring = true;
880 }
881 }
882
883 /**
884 * Finds all the views we need and configure them properly.
885 */
886 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700887 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -0400888
Romain Guyb1b69f52009-08-10 15:10:15 -0700889 DragLayer dragLayer = (DragLayer) findViewById(R.id.drag_layer);
Joe Onorato00acb122009-08-04 16:04:30 -0400890 dragLayer.setDragController(dragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800891
Joe Onorato7c312c12009-08-13 21:36:53 -0700892 mAllAppsGrid = (AllAppsView)dragLayer.findViewById(R.id.all_apps_view);
Joe Onorato6665c0f2009-09-02 15:27:24 -0700893 mAllAppsGrid.setLauncher(this);
Joe Onorato5162ea92009-09-03 09:39:42 -0700894 mAllAppsGrid.setDragController(dragController);
Romain Guyc16fea72010-03-12 17:17:56 -0800895 ((View) mAllAppsGrid).setWillNotDraw(false); // We don't want a hole punched in our window.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700896 // Manage focusability manually since this thing is always visible (in non-xlarge)
Winson Chungaafa03c2010-06-11 17:34:16 -0700897 ((View) mAllAppsGrid).setFocusable(false);
Joe Onorato7c312c12009-08-13 21:36:53 -0700898
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700899 if (LauncherApplication.isScreenXLarge()) {
900 // They need to be INVISIBLE initially so that they will be measured in the layout.
901 // Otherwise the animations are messed up when we show them for the first time.
902 ((View) mAllAppsGrid).setVisibility(View.INVISIBLE);
903 mHomeCustomizationDrawer.setVisibility(View.INVISIBLE);
904 }
905
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800906 mWorkspace = (Workspace) dragLayer.findViewById(R.id.workspace);
Adam Lesinski6b879f02010-11-04 16:15:23 -0700907
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800908 final Workspace workspace = mWorkspace;
Joe Onoratof0dde092010-02-16 18:25:23 -0500909 workspace.setHapticFeedbackEnabled(false);
Michael Jurka946ad472010-07-09 18:05:18 -0700910
Joe Onorato7c312c12009-08-13 21:36:53 -0700911 DeleteZone deleteZone = (DeleteZone) dragLayer.findViewById(R.id.delete_zone);
912 mDeleteZone = deleteZone;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800913
Michael Jurka2c3af5f2010-08-03 13:53:20 -0700914 View handleView = findViewById(R.id.all_apps_button);
915 if (handleView != null && handleView instanceof HandleView) {
916 // we don't use handle view in xlarge mode
Michael Jurka7ef4f752010-08-03 16:04:26 -0700917 mHandleView = (HandleView)handleView;
Michael Jurka2c3af5f2010-08-03 13:53:20 -0700918 mHandleView.setLauncher(this);
919 mHandleView.setOnClickListener(this);
920 mHandleView.setOnLongClickListener(this);
921 }
Romain Guy1fbc1c82009-11-09 20:43:08 -0800922
Winson Chung80baf5a2010-08-09 16:03:15 -0700923 if (mCustomizePagedView != null) {
924 mCustomizePagedView.setLauncher(this);
925 mCustomizePagedView.setDragController(dragController);
926 mCustomizePagedView.update();
Michael Jurkaaf442092010-06-10 17:01:57 -0700927 } else {
928 ImageView hotseatLeft = (ImageView) findViewById(R.id.hotseat_left);
929 hotseatLeft.setContentDescription(mHotseatLabels[0]);
930 hotseatLeft.setImageDrawable(mHotseatIcons[0]);
931 ImageView hotseatRight = (ImageView) findViewById(R.id.hotseat_right);
932 hotseatRight.setContentDescription(mHotseatLabels[1]);
933 hotseatRight.setImageDrawable(mHotseatIcons[1]);
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400934
Michael Jurkaaf442092010-06-10 17:01:57 -0700935 mPreviousView = (ImageView) dragLayer.findViewById(R.id.previous_screen);
936 mNextView = (ImageView) dragLayer.findViewById(R.id.next_screen);
Romain Guy1fbc1c82009-11-09 20:43:08 -0800937
Michael Jurkaaf442092010-06-10 17:01:57 -0700938 Drawable previous = mPreviousView.getDrawable();
939 Drawable next = mNextView.getDrawable();
940 mWorkspace.setIndicators(previous, next);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800941
Michael Jurkaaf442092010-06-10 17:01:57 -0700942 mPreviousView.setHapticFeedbackEnabled(false);
943 mPreviousView.setOnLongClickListener(this);
944 mNextView.setHapticFeedbackEnabled(false);
945 mNextView.setOnLongClickListener(this);
946 }
Romain Guy1fbc1c82009-11-09 20:43:08 -0800947
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800948 workspace.setOnLongClickListener(this);
Joe Onorato00acb122009-08-04 16:04:30 -0400949 workspace.setDragController(dragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800950 workspace.setLauncher(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800951
952 deleteZone.setLauncher(this);
Joe Onorato00acb122009-08-04 16:04:30 -0400953 deleteZone.setDragController(dragController);
Michael Jurka54f7ac32010-08-02 13:56:46 -0700954 int deleteZoneHandleId;
955 if (LauncherApplication.isScreenXLarge()) {
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700956 deleteZoneHandleId = R.id.all_apps_button;
Michael Jurka54f7ac32010-08-02 13:56:46 -0700957 } else {
958 deleteZoneHandleId = R.id.all_apps_button_cluster;
959 }
Michael Jurkaaf442092010-06-10 17:01:57 -0700960 deleteZone.setHandle(findViewById(deleteZoneHandleId));
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700961 dragController.addDragListener(deleteZone);
962
963 ApplicationInfoDropTarget infoButton = (ApplicationInfoDropTarget)findViewById(R.id.info_button);
964 if (infoButton != null) {
965 infoButton.setLauncher(this);
966 infoButton.setHandle(findViewById(R.id.configure_button));
967 infoButton.setDragColor(getResources().getColor(R.color.app_info_filter));
968 dragController.addDragListener(infoButton);
969 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800970
Joe Onorato00acb122009-08-04 16:04:30 -0400971 dragController.setDragScoller(workspace);
Joe Onorato00acb122009-08-04 16:04:30 -0400972 dragController.setScrollView(dragLayer);
Romain Guyea3763c2010-01-11 18:02:04 -0800973 dragController.setMoveTarget(workspace);
Jason Samsfd22dac2009-09-20 17:24:16 -0700974
Joe Onorato00acb122009-08-04 16:04:30 -0400975 // The order here is bottom to top.
976 dragController.addDropTarget(workspace);
977 dragController.addDropTarget(deleteZone);
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700978 if (infoButton != null) {
979 dragController.addDropTarget(infoButton);
980 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800981 }
982
Romain Guy8a73c512009-11-09 19:19:59 -0800983 @SuppressWarnings({"UnusedDeclaration"})
984 public void previousScreen(View v) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700985 if (mState != State.ALL_APPS) {
Joe Onorato61597bd2009-11-19 12:51:57 -0800986 mWorkspace.scrollLeft();
987 }
Romain Guy8a73c512009-11-09 19:19:59 -0800988 }
989
990 @SuppressWarnings({"UnusedDeclaration"})
991 public void nextScreen(View v) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700992 if (mState != State.ALL_APPS) {
Joe Onorato61597bd2009-11-19 12:51:57 -0800993 mWorkspace.scrollRight();
994 }
Romain Guy8a73c512009-11-09 19:19:59 -0800995 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400996
997 @SuppressWarnings({"UnusedDeclaration"})
998 public void launchHotSeat(View v) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700999 if (mState == State.ALL_APPS) return;
Daniel Sandler3e9454a2010-05-24 11:22:41 -04001000
Daniel Sandlerc9b18772010-04-22 14:37:59 -04001001 int index = -1;
1002 if (v.getId() == R.id.hotseat_left) {
1003 index = 0;
1004 } else if (v.getId() == R.id.hotseat_right) {
1005 index = 1;
1006 }
1007
Daniel Sandlerab1ebd72010-04-27 16:57:25 -04001008 // reload these every tap; you never know when they might change
1009 loadHotseats();
1010 if (index >= 0 && index < mHotseats.length && mHotseats[index] != null) {
1011 Intent intent = mHotseats[index];
Daniel Sandlerc9b18772010-04-22 14:37:59 -04001012 startActivitySafely(
1013 mHotseats[index],
1014 "hotseat"
1015 );
1016 }
1017 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001018
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001019 /**
1020 * Creates a view representing a shortcut.
1021 *
1022 * @param info The data structure describing the shortcut.
1023 *
1024 * @return A View inflated from R.layout.application.
1025 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001026 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001027 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001028 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001029 }
1030
1031 /**
1032 * Creates a view representing a shortcut inflated from the specified resource.
1033 *
1034 * @param layoutResId The id of the XML layout used to create the shortcut.
1035 * @param parent The group the shortcut belongs to.
1036 * @param info The data structure describing the shortcut.
1037 *
1038 * @return A View inflated from layoutResId.
1039 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001040 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001041 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1042 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001043 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001044 return favorite;
1045 }
1046
1047 /**
1048 * Add an application shortcut to the workspace.
1049 *
1050 * @param data The intent describing the application.
1051 * @param cellInfo The position on screen where to create the shortcut.
1052 */
Michael Jurka0280c3b2010-09-17 15:00:07 -07001053 void completeAddApplication(Context context, Intent data, int screen,
1054 int intersectCellX, int intersectCellY) {
1055 final int[] cellXY = mTmpAddItemCellCoordinates;
1056 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1057
1058 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1059 showOutOfSpaceMessage();
1060 return;
1061 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001062
Joe Onorato0589f0f2010-02-08 13:44:00 -08001063 final ShortcutInfo info = mModel.getShortcutInfo(context.getPackageManager(),
1064 data, context);
1065
Romain Guy73b979d2009-06-09 12:57:21 -07001066 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -08001067 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001068 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001069 info.container = ItemInfo.NO_ID;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001070 mWorkspace.addApplicationShortcut(info, screen, cellXY[0], cellXY[1],
1071 isWorkspaceLocked(), mAddIntersectCellX, mAddIntersectCellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001072 } else {
1073 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001074 }
1075 }
Romain Guycbb89e42009-06-08 15:52:54 -07001076
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001077 /**
1078 * Add a shortcut to the workspace.
1079 *
1080 * @param data The intent describing the shortcut.
1081 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001082 */
Michael Jurka0280c3b2010-09-17 15:00:07 -07001083 private void completeAddShortcut(Intent data, int screen,
1084 int intersectCellX, int intersectCellY) {
1085 final int[] cellXY = mTmpAddItemCellCoordinates;
1086 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
Romain Guycbb89e42009-06-08 15:52:54 -07001087
Michael Jurka0280c3b2010-09-17 15:00:07 -07001088 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1089 showOutOfSpaceMessage();
1090 return;
1091 }
1092
1093 final ShortcutInfo info = mModel.addShortcut(
1094 this, data, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001095
1096 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001097 final View view = createShortcut(info);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001098 mWorkspace.addInScreen(view, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001099 }
1100 }
1101
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001102 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001103 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001104 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001105 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001106 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001107 */
Michael Jurka0280c3b2010-09-17 15:00:07 -07001108 private void completeAddAppWidget(int appWidgetId, int screen) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001109 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Romain Guycbb89e42009-06-08 15:52:54 -07001110
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001111 // Calculate the grid spans needed to fit this widget
Michael Jurka0280c3b2010-09-17 15:00:07 -07001112 CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1113 int[] spanXY = layout.rectToCell(appWidgetInfo.minWidth, appWidgetInfo.minHeight, null);
Romain Guycbb89e42009-06-08 15:52:54 -07001114
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001115 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001116 // We have saved the position to which the widget was dragged-- this really only matters
1117 // if we are placing widgets on a "spring-loaded" screen
Michael Jurka0280c3b2010-09-17 15:00:07 -07001118 final int[] cellXY = mTmpAddItemCellCoordinates;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001119
1120 // For now, we don't save the coordinate where we dropped the icon because we're not
1121 // supporting spring-loaded mini-screens; however, leaving the ability to directly place
1122 // a widget on the home screen in case we want to add it in the future
Winson Chung55cef262010-10-28 14:14:18 -07001123 int[] touchXY = null;
Michael Jurka9c6de3d2010-11-23 16:23:58 -08001124 if (mAddDropPosition != null && mAddDropPosition[0] > -1 && mAddDropPosition[1] > -1) {
Winson Chung55cef262010-10-28 14:14:18 -07001125 touchXY = mAddDropPosition;
1126 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001127 boolean findNearestVacantAreaFailed = false;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001128 boolean foundCellSpan = false;
1129 if (touchXY != null) {
1130 // when dragging and dropping, just find the closest free spot
1131 CellLayout screenLayout = (CellLayout) mWorkspace.getChildAt(screen);
1132 int[] result = screenLayout.findNearestVacantArea(
1133 touchXY[0], touchXY[1], spanXY[0], spanXY[1], cellXY);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001134 findNearestVacantAreaFailed = (result == null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001135 foundCellSpan = !findNearestVacantAreaFailed;
1136 } else {
Michael Jurka9c6de3d2010-11-23 16:23:58 -08001137 // if we long pressed on an empty cell to bring up a menu,
1138 // make sure we intersect the empty cell
1139 // if mAddIntersectCellX/Y are -1 (e.g. we used menu -> add) then
1140 // findCellForSpanThatIntersects will just ignore them
1141 foundCellSpan = layout.findCellForSpanThatIntersects(cellXY, spanXY[0], spanXY[1],
1142 mAddIntersectCellX, mAddIntersectCellY);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001143 }
1144
Michael Jurka0280c3b2010-09-17 15:00:07 -07001145 if (!foundCellSpan) {
Romain Guy18042c82009-11-06 11:44:55 -08001146 if (appWidgetId != -1) mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001147 showOutOfSpaceMessage();
Romain Guy18042c82009-11-06 11:44:55 -08001148 return;
1149 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001150
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001151 // Build Launcher-specific widget info and save to database
1152 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001153 launcherInfo.spanX = spanXY[0];
1154 launcherInfo.spanY = spanXY[1];
Romain Guycbb89e42009-06-08 15:52:54 -07001155
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001156 LauncherModel.addItemToDatabase(this, launcherInfo,
1157 LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001158 screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001159
1160 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001161 mDesktopItems.add(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001162
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001163 // Perform actual inflation because we're live
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001164 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001165
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001166 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001167 launcherInfo.hostView.setTag(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001168
Michael Jurka0280c3b2010-09-17 15:00:07 -07001169 mWorkspace.addInScreen(launcherInfo.hostView, screen, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001170 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001171
1172 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001173 }
1174 }
Romain Guycbb89e42009-06-08 15:52:54 -07001175
Adam Cohended9f8d2010-11-03 13:25:16 -07001176 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1177 @Override
1178 public void onReceive(Context context, Intent intent) {
1179 final String action = intent.getAction();
1180 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1181 mUserPresent = false;
1182 updateRunning();
1183 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1184 mUserPresent = true;
1185 updateRunning();
1186 }
1187 }
1188 };
1189
1190 @Override
1191 public void onAttachedToWindow() {
1192 super.onAttachedToWindow();
1193
1194 // Listen for broadcasts related to user-presence
1195 final IntentFilter filter = new IntentFilter();
1196 filter.addAction(Intent.ACTION_SCREEN_OFF);
1197 filter.addAction(Intent.ACTION_USER_PRESENT);
1198 registerReceiver(mReceiver, filter);
1199
Adam Cohend113e0c2010-11-11 10:48:05 -08001200 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001201 mVisible = true;
1202 }
1203
1204 @Override
1205 public void onDetachedFromWindow() {
1206 super.onDetachedFromWindow();
1207 mVisible = false;
1208
Adam Cohend113e0c2010-11-11 10:48:05 -08001209 if (mAttached) {
1210 unregisterReceiver(mReceiver);
1211 mAttached = false;
1212 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001213 updateRunning();
1214 }
1215
1216 public void onWindowVisibilityChanged(int visibility) {
1217 mVisible = visibility == View.VISIBLE;
1218 updateRunning();
1219 }
1220
1221 private void sendAdvanceMessage(long delay) {
1222 mHandler.removeMessages(ADVANCE_MSG);
1223 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1224 mHandler.sendMessageDelayed(msg, delay);
1225 mAutoAdvanceSentTime = System.currentTimeMillis();
1226 }
1227
1228 private void updateRunning() {
1229 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1230 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1231 mAutoAdvanceRunning = autoAdvanceRunning;
1232 if (autoAdvanceRunning) {
1233 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1234 sendAdvanceMessage(delay);
1235 } else {
1236 if (!mWidgetsToAdvance.isEmpty()) {
1237 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1238 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1239 }
1240 mHandler.removeMessages(ADVANCE_MSG);
1241 }
1242 }
1243 }
1244
1245 private final Handler mHandler = new Handler() {
1246 @Override
1247 public void handleMessage(Message msg) {
1248 if (msg.what == ADVANCE_MSG) {
1249 int i = 0;
1250 for (View key: mWidgetsToAdvance.keySet()) {
1251 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1252 final int delay = mAdvanceStagger * i;
1253 if (v instanceof Advanceable) {
1254 postDelayed(new Runnable() {
1255 public void run() {
1256 ((Advanceable) v).advance();
1257 }
1258 }, delay);
1259 }
1260 i++;
1261 }
1262 sendAdvanceMessage(mAdvanceInterval);
1263 }
1264 }
1265 };
1266
1267 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
1268 if (appWidgetInfo.autoAdvanceViewId == -1) return;
1269 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1270 if (v instanceof Advanceable) {
1271 mWidgetsToAdvance.put(hostView, appWidgetInfo);
1272 ((Advanceable) v).willBeAdvancedByHost();
1273 updateRunning();
1274 }
1275 }
1276
1277 void removeWidgetToAutoAdvance(View hostView) {
1278 if (mWidgetsToAdvance.containsKey(hostView)) {
1279 mWidgetsToAdvance.remove(hostView);
1280 updateRunning();
1281 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001282 }
1283
Joe Onorato9c1289c2009-08-17 11:03:03 -04001284 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
1285 mDesktopItems.remove(launcherInfo);
Adam Cohended9f8d2010-11-03 13:25:16 -07001286 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001287 launcherInfo.hostView = null;
1288 }
1289
Adam Cohended9f8d2010-11-03 13:25:16 -07001290 void showOutOfSpaceMessage() {
1291 Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show();
1292 }
1293
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001294 public LauncherAppWidgetHost getAppWidgetHost() {
1295 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001296 }
Romain Guycbb89e42009-06-08 15:52:54 -07001297
Winson Chunga9abd0e2010-10-27 17:18:37 -07001298 public LauncherModel getModel() {
1299 return mModel;
1300 }
1301
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001302 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001303 getWindow().closeAllPanels();
1304
1305 try {
1306 dismissDialog(DIALOG_CREATE_SHORTCUT);
1307 // Unlock the workspace if the dialog was showing
1308 } catch (Exception e) {
1309 // An exception is thrown if the dialog is not visible, which is fine
1310 }
1311
1312 try {
1313 dismissDialog(DIALOG_RENAME_FOLDER);
1314 // Unlock the workspace if the dialog was showing
1315 } catch (Exception e) {
1316 // An exception is thrown if the dialog is not visible, which is fine
1317 }
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001318
1319 // Whatever we were doing is hereby canceled.
1320 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001321 }
1322
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001323 @Override
1324 protected void onNewIntent(Intent intent) {
1325 super.onNewIntent(intent);
1326
1327 // Close the menu
1328 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001329 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001330 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001331
Joe Onorato14f122b2009-11-19 14:06:36 -08001332 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1333 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001334
Michael Jurka4cb37242010-08-09 21:05:32 -07001335 // in all these cases, only animate if we're already on home
1336 if (LauncherApplication.isScreenXLarge()) {
Michael Jurka99229f62010-09-09 11:49:32 -07001337 mWorkspace.unshrink(alreadyOnHome);
1338 }
1339 if (!mWorkspace.isDefaultPageShowing()) {
Michael Jurka4cb37242010-08-09 21:05:32 -07001340 // on the phone, we don't animate the change to the workspace if all apps is visible
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001341 mWorkspace.moveToDefaultScreen(alreadyOnHome &&
1342 (LauncherApplication.isScreenXLarge() || mState != State.ALL_APPS));
Joe Onorato3a8820b2009-11-10 15:06:42 -08001343 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001344 showWorkspace(alreadyOnHome);
Romain Guy1dd3a072009-07-16 13:21:01 -07001345
Joe Onorato3a8820b2009-11-10 15:06:42 -08001346 final View v = getWindow().peekDecorView();
1347 if (v != null && v.getWindowToken() != null) {
1348 InputMethodManager imm = (InputMethodManager)getSystemService(
1349 INPUT_METHOD_SERVICE);
1350 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001351 }
1352 }
1353 }
1354
1355 @Override
1356 protected void onRestoreInstanceState(Bundle savedInstanceState) {
1357 // Do not call super here
1358 mSavedInstanceState = savedInstanceState;
Michael Jurka946ad472010-07-09 18:05:18 -07001359
1360 if (mHomeCustomizationDrawer != null) {
1361 String cur = savedInstanceState.getString("currentTab");
1362 if (cur != null) {
1363 mHomeCustomizationDrawer.setCurrentTabByTag(cur);
1364 }
1365 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001366 }
1367
1368 @Override
1369 protected void onSaveInstanceState(Bundle outState) {
Michael Jurka0142d492010-08-25 17:46:15 -07001370 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001371
1372 final ArrayList<Folder> folders = mWorkspace.getOpenFolders();
1373 if (folders.size() > 0) {
1374 final int count = folders.size();
1375 long[] ids = new long[count];
1376 for (int i = 0; i < count; i++) {
1377 final FolderInfo info = folders.get(i).getInfo();
1378 ids[i] = info.id;
1379 }
1380 outState.putLongArray(RUNTIME_STATE_USER_FOLDERS, ids);
1381 } else {
1382 super.onSaveInstanceState(outState);
1383 }
1384
Michael Jurka883f55b2010-10-21 15:47:14 -07001385 outState.putInt(RUNTIME_STATE, mState.ordinal());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001386
Michael Jurka0280c3b2010-09-17 15:00:07 -07001387 if (mAddScreen > -1 && mWaitingForResult) {
1388 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mAddScreen);
1389 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mAddIntersectCellX);
1390 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001391 }
1392
1393 if (mFolderInfo != null && mWaitingForResult) {
1394 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1395 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1396 }
Michael Jurka946ad472010-07-09 18:05:18 -07001397
1398 if (mHomeCustomizationDrawer != null) {
1399 String currentTabTag = mHomeCustomizationDrawer.getCurrentTabTag();
1400 if (currentTabTag != null) {
1401 outState.putString("currentTab", currentTabTag);
1402 }
1403 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001404 }
1405
1406 @Override
1407 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001408 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001409
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001410 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001411 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001412 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001413 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001414 }
1415
1416 TextKeyListener.getInstance().release();
1417
Joe Onorato9c1289c2009-08-17 11:03:03 -04001418 mModel.stopLoader();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001419
Joe Onorato9c1289c2009-08-17 11:03:03 -04001420 unbindDesktopItems();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001421
1422 getContentResolver().unregisterContentObserver(mWidgetObserver);
Winson Chungaafa03c2010-06-11 17:34:16 -07001423
Patrick Dubroyab962b72010-07-26 12:10:10 -07001424 // Some launcher layouts don't have a previous and next view
1425 if (mPreviousView != null) {
1426 dismissPreview(mPreviousView);
1427 }
1428 if (mNextView != null) {
1429 dismissPreview(mNextView);
1430 }
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001431
1432 unregisterReceiver(mCloseSystemDialogsReceiver);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001433 }
1434
1435 @Override
1436 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001437 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001438 super.startActivityForResult(intent, requestCode);
1439 }
1440
1441 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001442 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001443 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001444
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001445 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001446
Karl Rosaen138a0412009-04-23 19:00:21 -07001447 if (initialQuery == null) {
1448 // Use any text typed in the launcher as the initial query
1449 initialQuery = getTypedText();
1450 clearTypedText();
1451 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001452 if (appSearchData == null) {
1453 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +00001454 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001455 }
Romain Guycbb89e42009-06-08 15:52:54 -07001456
Karl Rosaen138a0412009-04-23 19:00:21 -07001457 final SearchManager searchManager =
1458 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Karl Rosaen138a0412009-04-23 19:00:21 -07001459 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Romain Guycbb89e42009-06-08 15:52:54 -07001460 appSearchData, globalSearch);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001461 }
1462
1463 @Override
1464 public boolean onCreateOptionsMenu(Menu menu) {
Patrick Dubroy5905bca2010-09-08 22:43:38 -07001465 if (isWorkspaceLocked()) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001466 return false;
1467 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001468
1469 super.onCreateOptionsMenu(menu);
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001470
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001471 menu.add(MENU_GROUP_ADD, MENU_ADD, 0, R.string.menu_add)
1472 .setIcon(android.R.drawable.ic_menu_add)
1473 .setAlphabeticShortcut('A');
Winson Chung7ad01412010-09-27 11:33:03 -07001474 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1475 .setIcon(android.R.drawable.ic_menu_manage)
1476 .setAlphabeticShortcut('M');
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001477 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001478 .setIcon(android.R.drawable.ic_menu_gallery)
1479 .setAlphabeticShortcut('W');
1480 menu.add(0, MENU_SEARCH, 0, R.string.menu_search)
1481 .setIcon(android.R.drawable.ic_search_category_default)
1482 .setAlphabeticShortcut(SearchManager.MENU_KEY);
1483 menu.add(0, MENU_NOTIFICATIONS, 0, R.string.menu_notifications)
1484 .setIcon(com.android.internal.R.drawable.ic_menu_notifications)
1485 .setAlphabeticShortcut('N');
1486
1487 final Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
Romain Guy5a941392009-04-28 15:18:25 -07001488 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
1489 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001490
1491 menu.add(0, MENU_SETTINGS, 0, R.string.menu_settings)
1492 .setIcon(android.R.drawable.ic_menu_preferences).setAlphabeticShortcut('P')
1493 .setIntent(settings);
1494
1495 return true;
1496 }
1497
1498 @Override
1499 public boolean onPrepareOptionsMenu(Menu menu) {
1500 super.onPrepareOptionsMenu(menu);
1501
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001502 // If all apps is animating, don't show the menu, because we don't know
1503 // which one to show.
Patrick Dubroyff5f0402010-07-26 15:23:26 -07001504 if (mAllAppsGrid.isAnimating()) {
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001505 return false;
1506 }
1507
1508 // Only show the add and wallpaper options when we're not in all apps.
Patrick Dubroyff5f0402010-07-26 15:23:26 -07001509 boolean visible = !mAllAppsGrid.isVisible();
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001510 menu.setGroupVisible(MENU_GROUP_ADD, visible);
1511 menu.setGroupVisible(MENU_GROUP_WALLPAPER, visible);
1512
1513 // Disable add if the workspace is full.
1514 if (visible) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001515 CellLayout layout = (CellLayout) mWorkspace.getChildAt(mWorkspace.getCurrentPage());
1516 menu.setGroupEnabled(MENU_GROUP_ADD, layout.existsEmptyCell());
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001517 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001518
1519 return true;
1520 }
1521
1522 @Override
1523 public boolean onOptionsItemSelected(MenuItem item) {
1524 switch (item.getItemId()) {
1525 case MENU_ADD:
1526 addItems();
1527 return true;
Winson Chung7ad01412010-09-27 11:33:03 -07001528 case MENU_MANAGE_APPS:
1529 manageApps();
1530 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001531 case MENU_WALLPAPER_SETTINGS:
1532 startWallpaper();
1533 return true;
1534 case MENU_SEARCH:
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001535 onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001536 return true;
1537 case MENU_NOTIFICATIONS:
1538 showNotifications();
1539 return true;
1540 }
1541
1542 return super.onOptionsItemSelected(item);
1543 }
Romain Guycbb89e42009-06-08 15:52:54 -07001544
Karl Rosaen138a0412009-04-23 19:00:21 -07001545 /**
1546 * Indicates that we want global search for this activity by setting the globalSearch
1547 * argument for {@link #startSearch} to true.
1548 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001549
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001550 @Override
1551 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001552 startSearch(null, false, null, true);
Karl Rosaen138a0412009-04-23 19:00:21 -07001553 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001554 }
1555
Joe Onorato9c1289c2009-08-17 11:03:03 -04001556 public boolean isWorkspaceLocked() {
1557 return mWorkspaceLoading || mWaitingForResult;
1558 }
1559
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001560 private void addItems() {
Patrick Dubroy558654c2010-07-23 16:48:11 -07001561 if (LauncherApplication.isScreenXLarge()) {
1562 // Animate the widget chooser up from the bottom of the screen
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001563 if (mState != State.CUSTOMIZE) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07001564 showCustomizationDrawer(true);
Patrick Dubroy558654c2010-07-23 16:48:11 -07001565 }
1566 } else {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001567 showWorkspace(true);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001568 showAddDialog(-1, -1);
Patrick Dubroy558654c2010-07-23 16:48:11 -07001569 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001570 }
1571
Michael Jurka0280c3b2010-09-17 15:00:07 -07001572 private void resetAddInfo() {
1573 mAddScreen = -1;
1574 mAddIntersectCellX = -1;
1575 mAddIntersectCellY = -1;
1576 mAddDropPosition = null;
1577 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001578
Winson Chung55cef262010-10-28 14:14:18 -07001579 void addAppWidgetFromDrop(PendingAddWidgetInfo info, int screen, int[] position) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001580 resetAddInfo();
1581 mAddScreen = screen;
1582
1583 // only set mAddDropPosition if we dropped on home screen in "spring-loaded" manner
1584 mAddDropPosition = position;
1585
Michael Jurkaaf442092010-06-10 17:01:57 -07001586 int appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Winson Chung55cef262010-10-28 14:14:18 -07001587 AppWidgetManager.getInstance(this).bindAppWidgetId(appWidgetId, info.componentName);
1588 addAppWidgetImpl(appWidgetId, info);
Michael Jurkaaf442092010-06-10 17:01:57 -07001589 }
1590
Winson Chung7ad01412010-09-27 11:33:03 -07001591 private void manageApps() {
1592 startActivity(new Intent(android.provider.Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS));
1593 }
1594
Michael Jurkaaf442092010-06-10 17:01:57 -07001595 void addAppWidgetFromPick(Intent data) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001596 // TODO: catch bad widget exception when sent
1597 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurkaaf442092010-06-10 17:01:57 -07001598 // TODO: Is this log message meaningful?
1599 if (LOGD) Log.d(TAG, "dumping extras content=" + data.getExtras());
Winson Chung55cef262010-10-28 14:14:18 -07001600 addAppWidgetImpl(appWidgetId, null);
Michael Jurkaaf442092010-06-10 17:01:57 -07001601 }
1602
Winson Chung55cef262010-10-28 14:14:18 -07001603 void addAppWidgetImpl(int appWidgetId, PendingAddWidgetInfo info) {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001604 AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001605
Bjorn Bringert7984c942009-12-09 15:38:25 +00001606 if (appWidget.configure != null) {
1607 // Launch over to configure widget, if needed
1608 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
1609 intent.setComponent(appWidget.configure);
1610 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Winson Chung55cef262010-10-28 14:14:18 -07001611 if (info != null) {
Winson Chung68846fd2010-10-29 11:00:27 -07001612 if (info.mimeType != null && !info.mimeType.isEmpty()) {
1613 intent.putExtra(
1614 InstallWidgetReceiver.EXTRA_APPWIDGET_CONFIGURATION_DATA_MIME_TYPE,
1615 info.mimeType);
1616
1617 final String mimeType = info.mimeType;
1618 final ClipData clipData = (ClipData) info.configurationData;
1619 final ClipDescription clipDesc = clipData.getDescription();
1620 for (int i = 0; i < clipDesc.getMimeTypeCount(); ++i) {
1621 if (clipDesc.getMimeType(i).equals(mimeType)) {
1622 final ClipData.Item item = clipData.getItem(i);
1623 final CharSequence stringData = item.getText();
1624 final Uri uriData = item.getUri();
1625 final Intent intentData = item.getIntent();
1626 final String key =
1627 InstallWidgetReceiver.EXTRA_APPWIDGET_CONFIGURATION_DATA;
1628 if (uriData != null) {
1629 intent.putExtra(key, uriData);
1630 } else if (intentData != null) {
1631 intent.putExtra(key, intentData);
1632 } else if (stringData != null) {
1633 intent.putExtra(key, stringData);
1634 }
1635 break;
1636 }
1637 }
1638 }
Winson Chung55cef262010-10-28 14:14:18 -07001639 }
Bjorn Bringert7984c942009-12-09 15:38:25 +00001640
Romain Guy8e633c52010-03-04 12:51:36 -08001641 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001642 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001643 // Otherwise just add it
Michael Jurka0280c3b2010-09-17 15:00:07 -07001644 completeAddAppWidget(appWidgetId, mAddScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001645 }
1646 }
Romain Guycbb89e42009-06-08 15:52:54 -07001647
Michael Jurka0280c3b2010-09-17 15:00:07 -07001648 void processShortcutFromDrop(ComponentName componentName, int screen, int[] position) {
1649 resetAddInfo();
1650 mAddScreen = screen;
1651 mAddDropPosition = position;
1652
1653 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1654 createShortcutIntent.setComponent(componentName);
1655 processShortcut(createShortcutIntent);
1656 }
1657
Joe Onoratodeb98af2010-02-19 14:59:39 -08001658 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001659 // Handle case where user selected "Applications"
1660 String applicationName = getResources().getString(R.string.group_applications);
1661 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001662
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001663 if (applicationName != null && applicationName.equals(shortcutName)) {
1664 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1665 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001666
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001667 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1668 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07001669 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Joe Onorato4a79a042010-09-24 16:17:21 -07001670 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001671 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001672 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001673 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001674 }
1675
Winson Chung24ab2f12010-09-16 14:10:47 -07001676 void processWallpaper(Intent intent) {
1677 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1678 }
1679
Michael Jurka0280c3b2010-09-17 15:00:07 -07001680 void addLiveFolderFromDrop(ComponentName componentName, int screen, int[] position) {
1681 resetAddInfo();
1682 mAddScreen = screen;
1683 mAddDropPosition = position;
1684
1685 Intent createFolderIntent = new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER);
1686 createFolderIntent.setComponent(componentName);
1687
1688 addLiveFolder(createFolderIntent);
1689 }
1690
1691 void addLiveFolder(Intent intent) { // YYY add screen intersect etc. parameters here
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001692 // Handle case where user selected "Folder"
Jeffrey Sharkeyc4bbd0a2009-03-24 22:47:52 -07001693 String folderName = getResources().getString(R.string.group_folder);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001694 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001695
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001696 if (folderName != null && folderName.equals(shortcutName)) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001697 addFolder(mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001698 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001699 startActivityForResultSafely(intent, REQUEST_CREATE_LIVE_FOLDER);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001700 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001701 }
1702
Michael Jurka0280c3b2010-09-17 15:00:07 -07001703 void addFolder(int screen, int intersectCellX, int intersectCellY) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001704 UserFolderInfo folderInfo = new UserFolderInfo();
1705 folderInfo.title = getText(R.string.folder_name);
1706
Michael Jurka0280c3b2010-09-17 15:00:07 -07001707 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1708 final int[] cellXY = mTmpAddItemCellCoordinates;
1709 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1710 showOutOfSpaceMessage();
1711 return;
1712 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001713
1714 // Update the model
Joe Onorato9c1289c2009-08-17 11:03:03 -04001715 LauncherModel.addItemToDatabase(this, folderInfo,
1716 LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001717 screen, cellXY[0], cellXY[1], false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001718 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001719
1720 // Create the view
1721 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurkac9a96192010-11-01 11:52:08 -07001722 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()),
1723 folderInfo, mIconCache);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001724 mWorkspace.addInScreen(newFolder, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001725 }
Romain Guycbb89e42009-06-08 15:52:54 -07001726
Joe Onorato9c1289c2009-08-17 11:03:03 -04001727 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001728 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001729 }
1730
Michael Jurka28750fb2010-09-24 17:43:49 -07001731 private void completeAddLiveFolder(
1732 Intent data, int screen, int intersectCellX, int intersectCellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001733 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1734 final int[] cellXY = mTmpAddItemCellCoordinates;
1735 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1736 showOutOfSpaceMessage();
1737 return;
1738 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001739
Michael Jurka0280c3b2010-09-17 15:00:07 -07001740 final LiveFolderInfo info = addLiveFolder(this, data, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001741
1742 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001743 final View view = LiveFolderIcon.fromXml(R.layout.live_folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07001744 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001745 mWorkspace.addInScreen(view, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001746 }
1747 }
1748
1749 static LiveFolderInfo addLiveFolder(Context context, Intent data,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001750 int screen, int cellX, int cellY, boolean notify) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001751
1752 Intent baseIntent = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT);
1753 String name = data.getStringExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME);
1754
1755 Drawable icon = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001756 Intent.ShortcutIconResource iconResource = null;
1757
1758 Parcelable extra = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON);
1759 if (extra != null && extra instanceof Intent.ShortcutIconResource) {
1760 try {
1761 iconResource = (Intent.ShortcutIconResource) extra;
1762 final PackageManager packageManager = context.getPackageManager();
1763 Resources resources = packageManager.getResourcesForApplication(
1764 iconResource.packageName);
1765 final int id = resources.getIdentifier(iconResource.resourceName, null, null);
1766 icon = resources.getDrawable(id);
1767 } catch (Exception e) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001768 Log.w(TAG, "Could not load live folder icon: " + extra);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001769 }
1770 }
1771
1772 if (icon == null) {
1773 icon = context.getResources().getDrawable(R.drawable.ic_launcher_folder);
1774 }
1775
1776 final LiveFolderInfo info = new LiveFolderInfo();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001777 info.icon = Utilities.createIconBitmap(icon, context);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001778 info.title = name;
1779 info.iconResource = iconResource;
1780 info.uri = data.getData();
1781 info.baseIntent = baseIntent;
1782 info.displayMode = data.getIntExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE,
1783 LiveFolders.DISPLAY_MODE_GRID);
1784
1785 LauncherModel.addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001786 screen, cellX, cellY, notify);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001787 sFolders.put(info.id, info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001788
1789 return info;
1790 }
1791
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001792 private void showNotifications() {
1793 final StatusBarManager statusBar = (StatusBarManager) getSystemService(STATUS_BAR_SERVICE);
1794 if (statusBar != null) {
1795 statusBar.expand();
1796 }
1797 }
1798
1799 private void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001800 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001801 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001802 Intent chooser = Intent.createChooser(pickWallpaper,
1803 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001804 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1805 // Removed in Eclair MR1
1806// WallpaperManager wm = (WallpaperManager)
1807// getSystemService(Context.WALLPAPER_SERVICE);
1808// WallpaperInfo wi = wm.getWallpaperInfo();
1809// if (wi != null && wi.getSettingsActivity() != null) {
1810// LabeledIntent li = new LabeledIntent(getPackageName(),
1811// R.string.configure_wallpaper, 0);
1812// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1813// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1814// }
Mike Clerona0618e42009-10-22 13:55:21 -07001815 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001816 }
1817
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001818 /**
1819 * Registers various content observers. The current implementation registers
1820 * only a favorites observer to keep track of the favorites applications.
1821 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001822 private void registerContentObservers() {
1823 ContentResolver resolver = getContentResolver();
1824 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1825 true, mWidgetObserver);
1826 }
1827
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001828 @Override
1829 public boolean dispatchKeyEvent(KeyEvent event) {
1830 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1831 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001832 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001833 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001834 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jason Samseb5615d2009-11-30 11:50:10 -08001835 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
Joe Onoratobe386092009-11-17 17:32:16 -08001836 dumpState();
1837 return true;
1838 }
1839 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001840 }
1841 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1842 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001843 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001844 return true;
1845 }
1846 }
1847
1848 return super.dispatchKeyEvent(event);
1849 }
1850
Joe Onorato88ec0992009-11-19 13:16:06 -08001851 @Override
1852 public void onBackPressed() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001853 if (mState == State.ALL_APPS || mState == State.CUSTOMIZE) {
1854 showWorkspace(true);
Joe Onorato88ec0992009-11-19 13:16:06 -08001855 } else {
1856 closeFolder();
1857 }
Michael Jurkaaf442092010-06-10 17:01:57 -07001858 // Some launcher layouts don't have a previous and next view
1859 if (mPreviousView != null) {
1860 dismissPreview(mPreviousView);
1861 dismissPreview(mNextView);
1862 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001863 }
1864
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001865 private void closeFolder() {
1866 Folder folder = mWorkspace.getOpenFolder();
1867 if (folder != null) {
1868 closeFolder(folder);
1869 }
1870 }
1871
1872 void closeFolder(Folder folder) {
1873 folder.getInfo().opened = false;
1874 ViewGroup parent = (ViewGroup) folder.getParent();
1875 if (parent != null) {
Michael Jurkaf3ca3ab2010-10-20 17:08:24 -07001876 CellLayout cl = (CellLayout) parent;
1877 cl.removeViewWithoutMarkingCells(folder);
Joe Onoratob6341e92009-11-02 10:41:48 -05001878 if (folder instanceof DropTarget) {
1879 // Live folders aren't DropTargets.
1880 mDragController.removeDropTarget((DropTarget)folder);
1881 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001882 }
1883 folder.onClose();
1884 }
1885
1886 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001887 * Re-listen when widgets are reset.
1888 */
1889 private void onAppWidgetReset() {
1890 mAppWidgetHost.startListening();
1891 }
1892
1893 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001894 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1895 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001896 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04001897 private void unbindDesktopItems() {
1898 for (ItemInfo item: mDesktopItems) {
1899 item.unbind();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001900 }
1901 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001902
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001903 /**
1904 * Launches the intent referred by the clicked shortcut.
1905 *
1906 * @param v The view representing the clicked shortcut.
1907 */
1908 public void onClick(View v) {
1909 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001910 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001911 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08001912 final Intent intent = ((ShortcutInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001913 int[] pos = new int[2];
1914 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08001915 intent.setSourceBounds(new Rect(pos[0], pos[1],
1916 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Joe Onoratof984e852010-03-25 09:47:45 -07001917 startActivitySafely(intent, tag);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001918 } else if (tag instanceof FolderInfo) {
1919 handleFolderClick((FolderInfo) tag);
Joe Onorato7404ee42009-07-31 11:54:44 -07001920 } else if (v == mHandleView) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001921 if (mState == State.ALL_APPS) {
1922 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001923 } else {
Joe Onorato3a8820b2009-11-10 15:06:42 -08001924 showAllApps(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001925 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001926 }
1927 }
1928
Michael Jurka0e260592010-06-30 17:07:39 -07001929 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07001930 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001931 // clicking anywhere on the workspace causes the customization drawer to slide down
1932 showWorkspace(true);
Michael Jurka0e260592010-06-30 17:07:39 -07001933 return false;
1934 }
1935
Michael Jurkaaf442092010-06-10 17:01:57 -07001936 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001937 * Event handler for the search button
1938 *
1939 * @param v The view that was clicked.
1940 */
1941 public void onClickSearchButton(View v) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07001942 startSearch(null, false, null, true);
Amith Yamasani1f878a12010-11-22 14:58:22 -08001943 // Use a custom animation for launching search
1944 overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001945 }
1946
1947 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001948 * Event handler for the voice button
1949 *
1950 * @param v The view that was clicked.
1951 */
1952 public void onClickVoiceButton(View v) {
1953 startVoiceSearch();
1954 }
1955
1956 private void startVoiceSearch() {
1957 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
1958 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1959 startActivity(intent);
1960 }
1961
1962 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001963 * Event handler for the "gear" button that appears on the home screen, which
Michael Jurkaaf442092010-06-10 17:01:57 -07001964 * enters home screen customization mode.
1965 *
1966 * @param v The view that was clicked.
1967 */
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001968 public void onClickConfigureButton(View v) {
Patrick Dubroy558654c2010-07-23 16:48:11 -07001969 addItems();
Michael Jurkaaf442092010-06-10 17:01:57 -07001970 }
1971
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001972 /**
1973 * Event handler for the "grid" button that appears on the home screen, which
1974 * enters all apps mode.
1975 *
1976 * @param v The view that was clicked.
1977 */
1978 public void onClickAllAppsButton(View v) {
1979 showAllApps(true);
1980 }
1981
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001982 public void onClickAppMarketButton(View v) {
1983 if (mAppMarketIntent != null) {
1984 startActivitySafely(mAppMarketIntent, "app market");
1985 }
1986 }
1987
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001988 void startApplicationDetailsActivity(ComponentName componentName) {
1989 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001990 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
1991 Uri.fromParts("package", packageName, null));
1992 startActivity(intent);
1993 }
1994
Patrick Dubroy5539af72010-09-07 15:22:01 -07001995 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
1996 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
1997 // System applications cannot be installed. For now, show a toast explaining that.
1998 // We may give them the option of disabling apps this way.
1999 int messageId = R.string.uninstall_system_app_text;
2000 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
2001 } else {
2002 String packageName = appInfo.componentName.getPackageName();
2003 String className = appInfo.componentName.getClassName();
2004 Intent intent = new Intent(
2005 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
2006 startActivity(intent);
2007 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002008 }
2009
Joe Onoratof984e852010-03-25 09:47:45 -07002010 void startActivitySafely(Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002011 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2012 try {
2013 startActivity(intent);
2014 } catch (ActivityNotFoundException e) {
2015 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Daniel Sandlerc9b18772010-04-22 14:37:59 -04002016 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002017 } catch (SecurityException e) {
2018 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002019 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002020 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002021 "or use the exported attribute for this activity. "
2022 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002023 }
2024 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002025
Romain Guy8e633c52010-03-04 12:51:36 -08002026 void startActivityForResultSafely(Intent intent, int requestCode) {
2027 try {
2028 startActivityForResult(intent, requestCode);
2029 } catch (ActivityNotFoundException e) {
2030 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2031 } catch (SecurityException e) {
2032 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2033 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
2034 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
2035 "or use the exported attribute for this activity.", e);
2036 }
2037 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002038
2039 private void handleFolderClick(FolderInfo folderInfo) {
2040 if (!folderInfo.opened) {
2041 // Close any open folder
2042 closeFolder();
2043 // Open the requested folder
2044 openFolder(folderInfo);
2045 } else {
2046 // Find the open folder...
2047 Folder openFolder = mWorkspace.getFolderForTag(folderInfo);
2048 int folderScreen;
2049 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002050 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002051 // .. and close it
2052 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002053 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002054 // Close any folder open on the current screen
2055 closeFolder();
2056 // Pull the folder onto this screen
2057 openFolder(folderInfo);
2058 }
2059 }
2060 }
2061 }
2062
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002063 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002064 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002065 * is animated relative to the specified View. If the View is null, no animation
2066 * is played.
2067 *
2068 * @param folderInfo The FolderInfo describing the folder to open.
2069 */
Winson Chungaafa03c2010-06-11 17:34:16 -07002070 public void openFolder(FolderInfo folderInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002071 Folder openFolder;
2072
2073 if (folderInfo instanceof UserFolderInfo) {
2074 openFolder = UserFolder.fromXml(this);
2075 } else if (folderInfo instanceof LiveFolderInfo) {
Joe Onoratoa5902522009-07-30 13:37:37 -07002076 openFolder = com.android.launcher2.LiveFolder.fromXml(this, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002077 } else {
2078 return;
2079 }
2080
Joe Onorato00acb122009-08-04 16:04:30 -04002081 openFolder.setDragController(mDragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002082 openFolder.setLauncher(this);
2083
2084 openFolder.bind(folderInfo);
2085 folderInfo.opened = true;
2086
Winson Chungaafa03c2010-06-11 17:34:16 -07002087 mWorkspace.addInFullScreen(openFolder, folderInfo.screen);
2088
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002089 openFolder.onOpen();
2090 }
2091
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002092 public boolean onLongClick(View v) {
Romain Guy1fbc1c82009-11-09 20:43:08 -08002093 switch (v.getId()) {
2094 case R.id.previous_screen:
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002095 if (mState != State.ALL_APPS) {
Joe Onorato0d44e942009-11-16 18:20:51 -08002096 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2097 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Romain Guyf8e6a802009-12-07 17:48:02 -08002098 showPreviews(v);
Joe Onorato0d44e942009-11-16 18:20:51 -08002099 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002100 return true;
2101 case R.id.next_screen:
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002102 if (mState != State.ALL_APPS) {
Joe Onorato0d44e942009-11-16 18:20:51 -08002103 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2104 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Romain Guyf8e6a802009-12-07 17:48:02 -08002105 showPreviews(v);
2106 }
2107 return true;
2108 case R.id.all_apps_button:
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002109 if (mState != State.ALL_APPS) {
Romain Guyf8e6a802009-12-07 17:48:02 -08002110 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2111 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2112 showPreviews(v);
Joe Onorato0d44e942009-11-16 18:20:51 -08002113 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002114 return true;
2115 }
2116
Joe Onorato9c1289c2009-08-17 11:03:03 -04002117 if (isWorkspaceLocked()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002118 return false;
2119 }
2120
2121 if (!(v instanceof CellLayout)) {
2122 v = (View) v.getParent();
2123 }
2124
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002125
Michael Jurka0280c3b2010-09-17 15:00:07 -07002126 resetAddInfo();
2127 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002128 // This happens when long clicking an item with the dpad/trackball
Michael Jurka0280c3b2010-09-17 15:00:07 -07002129 if (longClickCellInfo == null || !longClickCellInfo.valid) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002130 return true;
2131 }
2132
Michael Jurka0280c3b2010-09-17 15:00:07 -07002133 final View itemUnderLongClick = longClickCellInfo.cell;
2134
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002135 if (mWorkspace.allowLongPress()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002136 if (itemUnderLongClick == null) {
2137 // User long pressed on empty space
2138 mWorkspace.setAllowLongPress(false);
2139 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2140 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Michael Jurka56170562010-10-05 14:14:56 -07002141 if (!LauncherApplication.isScreenXLarge()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002142 showAddDialog(longClickCellInfo.cellX, longClickCellInfo.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002143 }
2144 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002145 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002146 // User long pressed on an item
Joe Onorato0d44e942009-11-16 18:20:51 -08002147 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2148 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Michael Jurka0280c3b2010-09-17 15:00:07 -07002149 mAddIntersectCellX = longClickCellInfo.cellX;
2150 mAddIntersectCellY = longClickCellInfo.cellY;
2151 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002152 }
2153 }
2154 }
2155 return true;
2156 }
2157
Romain Guye6b8e2f2009-11-10 11:56:55 -08002158 @SuppressWarnings({"unchecked"})
Romain Guy9d31e9f2009-11-11 18:54:28 -08002159 private void dismissPreview(final View v) {
2160 final PopupWindow window = (PopupWindow) v.getTag();
Romain Guy1fbc1c82009-11-09 20:43:08 -08002161 if (window != null) {
Romain Guy9d31e9f2009-11-11 18:54:28 -08002162 window.setOnDismissListener(new PopupWindow.OnDismissListener() {
2163 public void onDismiss() {
2164 ViewGroup group = (ViewGroup) v.getTag(R.id.workspace);
2165 int count = group.getChildCount();
2166 for (int i = 0; i < count; i++) {
2167 ((ImageView) group.getChildAt(i)).setImageDrawable(null);
2168 }
Romain Guy9d31e9f2009-11-11 18:54:28 -08002169 ArrayList<Bitmap> bitmaps = (ArrayList<Bitmap>) v.getTag(R.id.icon);
2170 for (Bitmap bitmap : bitmaps) bitmap.recycle();
2171
2172 v.setTag(R.id.workspace, null);
2173 v.setTag(R.id.icon, null);
2174 window.setOnDismissListener(null);
2175 }
2176 });
Romain Guy1fbc1c82009-11-09 20:43:08 -08002177 window.dismiss();
Romain Guy1fbc1c82009-11-09 20:43:08 -08002178 }
2179 v.setTag(null);
2180 }
2181
Romain Guyf8e6a802009-12-07 17:48:02 -08002182 private void showPreviews(View anchor) {
Romain Guy9d31e9f2009-11-11 18:54:28 -08002183 showPreviews(anchor, 0, mWorkspace.getChildCount());
Romain Guy1fbc1c82009-11-09 20:43:08 -08002184 }
2185
Romain Guya6abce82009-11-10 02:54:41 -08002186 private void showPreviews(final View anchor, int start, int end) {
Romain Guyf8e6a802009-12-07 17:48:02 -08002187 final Resources resources = getResources();
2188 final Workspace workspace = mWorkspace;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002189
Romain Guya6abce82009-11-10 02:54:41 -08002190 CellLayout cell = ((CellLayout) workspace.getChildAt(start));
Winson Chungaafa03c2010-06-11 17:34:16 -07002191
Romain Guy9d31e9f2009-11-11 18:54:28 -08002192 float max = workspace.getChildCount();
Winson Chungaafa03c2010-06-11 17:34:16 -07002193
Romain Guyf8e6a802009-12-07 17:48:02 -08002194 final Rect r = new Rect();
Romain Guy9d31e9f2009-11-11 18:54:28 -08002195 resources.getDrawable(R.drawable.preview_background).getPadding(r);
Romain Guye6b8e2f2009-11-10 11:56:55 -08002196 int extraW = (int) ((r.left + r.right) * max);
2197 int extraH = r.top + r.bottom;
Romain Guya6abce82009-11-10 02:54:41 -08002198
2199 int aW = cell.getWidth() - extraW;
2200 float w = aW / max;
2201
2202 int width = cell.getWidth();
2203 int height = cell.getHeight();
2204 int x = cell.getLeftPadding();
2205 int y = cell.getTopPadding();
2206 width -= (x + cell.getRightPadding());
2207 height -= (y + cell.getBottomPadding());
2208
2209 float scale = w / width;
2210
2211 int count = end - start;
2212
2213 final float sWidth = width * scale;
2214 float sHeight = height * scale;
2215
Romain Guye6b8e2f2009-11-10 11:56:55 -08002216 LinearLayout preview = new LinearLayout(this);
Romain Guya6abce82009-11-10 02:54:41 -08002217
Romain Guye6b8e2f2009-11-10 11:56:55 -08002218 PreviewTouchHandler handler = new PreviewTouchHandler(anchor);
2219 ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>(count);
Romain Guya6abce82009-11-10 02:54:41 -08002220
2221 for (int i = start; i < end; i++) {
Romain Guye6b8e2f2009-11-10 11:56:55 -08002222 ImageView image = new ImageView(this);
Romain Guya6abce82009-11-10 02:54:41 -08002223 cell = (CellLayout) workspace.getChildAt(i);
2224
Romain Guyf8e6a802009-12-07 17:48:02 -08002225 final Bitmap bitmap = Bitmap.createBitmap((int) sWidth, (int) sHeight,
Romain Guye6b8e2f2009-11-10 11:56:55 -08002226 Bitmap.Config.ARGB_8888);
Romain Guyf8e6a802009-12-07 17:48:02 -08002227
2228 final Canvas c = new Canvas(bitmap);
Romain Guya6abce82009-11-10 02:54:41 -08002229 c.scale(scale, scale);
2230 c.translate(-cell.getLeftPadding(), -cell.getTopPadding());
Patrick Dubroy1262e362010-10-06 15:49:50 -07002231 cell.drawChildren(c);
Romain Guya6abce82009-11-10 02:54:41 -08002232
Romain Guy9d31e9f2009-11-11 18:54:28 -08002233 image.setBackgroundDrawable(resources.getDrawable(R.drawable.preview_background));
Romain Guye6b8e2f2009-11-10 11:56:55 -08002234 image.setImageBitmap(bitmap);
2235 image.setTag(i);
2236 image.setOnClickListener(handler);
Romain Guy9d31e9f2009-11-11 18:54:28 -08002237 image.setOnFocusChangeListener(handler);
2238 image.setFocusable(true);
Michael Jurka0142d492010-08-25 17:46:15 -07002239 if (i == mWorkspace.getCurrentPage()) image.requestFocus();
Romain Guye6b8e2f2009-11-10 11:56:55 -08002240
2241 preview.addView(image,
Romain Guy9d31e9f2009-11-11 18:54:28 -08002242 LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
2243
Winson Chungaafa03c2010-06-11 17:34:16 -07002244 bitmaps.add(bitmap);
Romain Guya6abce82009-11-10 02:54:41 -08002245 }
Romain Guyf8e6a802009-12-07 17:48:02 -08002246
2247 final PopupWindow p = new PopupWindow(this);
Romain Guye6b8e2f2009-11-10 11:56:55 -08002248 p.setContentView(preview);
2249 p.setWidth((int) (sWidth * count + extraW));
2250 p.setHeight((int) (sHeight + extraH));
2251 p.setAnimationStyle(R.style.AnimationPreview);
2252 p.setOutsideTouchable(true);
Romain Guy9d31e9f2009-11-11 18:54:28 -08002253 p.setFocusable(true);
Romain Guyff0c2e22009-11-10 12:09:59 -08002254 p.setBackgroundDrawable(new ColorDrawable(0));
Romain Guy9d31e9f2009-11-11 18:54:28 -08002255 p.showAsDropDown(anchor, 0, 0);
Romain Guya6abce82009-11-10 02:54:41 -08002256
Romain Guye6b8e2f2009-11-10 11:56:55 -08002257 p.setOnDismissListener(new PopupWindow.OnDismissListener() {
2258 public void onDismiss() {
2259 dismissPreview(anchor);
2260 }
2261 });
Romain Guy1fbc1c82009-11-09 20:43:08 -08002262
2263 anchor.setTag(p);
2264 anchor.setTag(R.id.workspace, preview);
Winson Chungaafa03c2010-06-11 17:34:16 -07002265 anchor.setTag(R.id.icon, bitmaps);
Romain Guy1fbc1c82009-11-09 20:43:08 -08002266 }
2267
Romain Guy9d31e9f2009-11-11 18:54:28 -08002268 class PreviewTouchHandler implements View.OnClickListener, Runnable, View.OnFocusChangeListener {
Romain Guya6abce82009-11-10 02:54:41 -08002269 private final View mAnchor;
Romain Guya6abce82009-11-10 02:54:41 -08002270
Romain Guye6b8e2f2009-11-10 11:56:55 -08002271 public PreviewTouchHandler(View anchor) {
Romain Guya6abce82009-11-10 02:54:41 -08002272 mAnchor = anchor;
Romain Guya6abce82009-11-10 02:54:41 -08002273 }
2274
2275 public void onClick(View v) {
Michael Jurka0142d492010-08-25 17:46:15 -07002276 mWorkspace.snapToPage((Integer) v.getTag());
Romain Guy9d31e9f2009-11-11 18:54:28 -08002277 v.post(this);
2278 }
2279
2280 public void run() {
Winson Chungaafa03c2010-06-11 17:34:16 -07002281 dismissPreview(mAnchor);
Romain Guy9d31e9f2009-11-11 18:54:28 -08002282 }
2283
2284 public void onFocusChange(View v, boolean hasFocus) {
2285 if (hasFocus) {
Michael Jurka0142d492010-08-25 17:46:15 -07002286 mWorkspace.snapToPage((Integer) v.getTag());
Romain Guy9d31e9f2009-11-11 18:54:28 -08002287 }
Romain Guya6abce82009-11-10 02:54:41 -08002288 }
2289 }
2290
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002291 Workspace getWorkspace() {
2292 return mWorkspace;
2293 }
2294
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002295 @Override
2296 protected Dialog onCreateDialog(int id) {
2297 switch (id) {
2298 case DIALOG_CREATE_SHORTCUT:
2299 return new CreateShortcut().createDialog();
2300 case DIALOG_RENAME_FOLDER:
2301 return new RenameFolder().createDialog();
2302 }
2303
2304 return super.onCreateDialog(id);
2305 }
2306
2307 @Override
2308 protected void onPrepareDialog(int id, Dialog dialog) {
2309 switch (id) {
2310 case DIALOG_CREATE_SHORTCUT:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002311 break;
2312 case DIALOG_RENAME_FOLDER:
Romain Guy7b4ef332009-07-14 13:58:08 -07002313 if (mFolderInfo != null) {
2314 EditText input = (EditText) dialog.findViewById(R.id.folder_name);
2315 final CharSequence text = mFolderInfo.title;
2316 input.setText(text);
2317 input.setSelection(0, text.length());
2318 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002319 break;
2320 }
2321 }
2322
2323 void showRenameDialog(FolderInfo info) {
2324 mFolderInfo = info;
2325 mWaitingForResult = true;
2326 showDialog(DIALOG_RENAME_FOLDER);
2327 }
2328
Michael Jurka0280c3b2010-09-17 15:00:07 -07002329 private void showAddDialog(int intersectX, int intersectY) {
2330 resetAddInfo();
2331 mAddIntersectCellX = intersectX;
2332 mAddIntersectCellY = intersectY;
2333 mAddScreen = mWorkspace.getCurrentPage();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002334 mWaitingForResult = true;
2335 showDialog(DIALOG_CREATE_SHORTCUT);
2336 }
2337
Joe Onoratodeb98af2010-02-19 14:59:39 -08002338 private void pickShortcut() {
Michael Jurka0e260592010-06-30 17:07:39 -07002339 // Insert extra item to handle picking application
Romain Guy73b979d2009-06-09 12:57:21 -07002340 Bundle bundle = new Bundle();
2341
2342 ArrayList<String> shortcutNames = new ArrayList<String>();
2343 shortcutNames.add(getString(R.string.group_applications));
2344 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
2345
2346 ArrayList<ShortcutIconResource> shortcutIcons = new ArrayList<ShortcutIconResource>();
2347 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
2348 R.drawable.ic_launcher_application));
2349 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
2350
2351 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2352 pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_CREATE_SHORTCUT));
Joe Onoratodeb98af2010-02-19 14:59:39 -08002353 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_shortcut));
Romain Guy73b979d2009-06-09 12:57:21 -07002354 pickIntent.putExtras(bundle);
2355
Joe Onoratodeb98af2010-02-19 14:59:39 -08002356 startActivityForResult(pickIntent, REQUEST_PICK_SHORTCUT);
Romain Guy73b979d2009-06-09 12:57:21 -07002357 }
2358
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002359 private class RenameFolder {
2360 private EditText mInput;
2361
2362 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002363 final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null);
2364 mInput = (EditText) layout.findViewById(R.id.folder_name);
2365
2366 AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
2367 builder.setIcon(0);
2368 builder.setTitle(getString(R.string.rename_folder_title));
2369 builder.setCancelable(true);
2370 builder.setOnCancelListener(new Dialog.OnCancelListener() {
2371 public void onCancel(DialogInterface dialog) {
2372 cleanup();
2373 }
2374 });
2375 builder.setNegativeButton(getString(R.string.cancel_action),
2376 new Dialog.OnClickListener() {
2377 public void onClick(DialogInterface dialog, int which) {
2378 cleanup();
2379 }
2380 }
2381 );
2382 builder.setPositiveButton(getString(R.string.rename_action),
2383 new Dialog.OnClickListener() {
2384 public void onClick(DialogInterface dialog, int which) {
2385 changeFolderName();
2386 }
2387 }
2388 );
2389 builder.setView(layout);
Romain Guy7b4ef332009-07-14 13:58:08 -07002390
2391 final AlertDialog dialog = builder.create();
2392 dialog.setOnShowListener(new DialogInterface.OnShowListener() {
2393 public void onShow(DialogInterface dialog) {
Joe Onorato7018d8e2010-04-13 20:25:47 -07002394 mWaitingForResult = true;
Joe Onoratod753b422009-11-08 13:31:11 -05002395 mInput.requestFocus();
2396 InputMethodManager inputManager = (InputMethodManager)
2397 getSystemService(Context.INPUT_METHOD_SERVICE);
2398 inputManager.showSoftInput(mInput, 0);
Romain Guy7b4ef332009-07-14 13:58:08 -07002399 }
2400 });
2401
2402 return dialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002403 }
2404
2405 private void changeFolderName() {
2406 final String name = mInput.getText().toString();
2407 if (!TextUtils.isEmpty(name)) {
2408 // Make sure we have the right folder info
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002409 mFolderInfo = sFolders.get(mFolderInfo.id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002410 mFolderInfo.title = name;
2411 LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo);
2412
Joe Onorato9c1289c2009-08-17 11:03:03 -04002413 if (mWorkspaceLoading) {
Joe Onorato7c312c12009-08-13 21:36:53 -07002414 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002415 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002416 } else {
2417 final FolderIcon folderIcon = (FolderIcon)
2418 mWorkspace.getViewForTag(mFolderInfo);
2419 if (folderIcon != null) {
2420 folderIcon.setText(name);
2421 getWorkspace().requestLayout();
2422 } else {
Joe Onorato7c312c12009-08-13 21:36:53 -07002423 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002424 mWorkspaceLoading = true;
2425 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002426 }
2427 }
2428 }
2429 cleanup();
2430 }
2431
2432 private void cleanup() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002433 dismissDialog(DIALOG_RENAME_FOLDER);
2434 mWaitingForResult = false;
2435 mFolderInfo = null;
2436 }
2437 }
2438
Daniel Sandler843e8602010-06-07 14:59:01 -04002439 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
2440 public boolean isAllAppsVisible() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002441 return mState == State.ALL_APPS;
Joe Onoratofb0ca672009-09-14 17:55:46 -04002442 }
2443
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002444 // AllAppsView.Watcher
2445 public void zoomed(float zoom) {
Michael Jurka213d9632010-07-28 11:29:25 -07002446 // In XLarge view, we zoom down the workspace below all apps so it's still visible
2447 if (zoom == 1.0f && !LauncherApplication.isScreenXLarge()) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002448 mWorkspace.setVisibility(View.GONE);
2449 }
2450 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002451
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002452 private void showToolbarButton(View button) {
2453 button.setAlpha(1.0f);
2454 button.setVisibility(View.VISIBLE);
2455 button.setFocusable(true);
2456 button.setClickable(true);
2457 }
2458
2459 private void hideToolbarButton(View button) {
2460 button.setAlpha(0.0f);
2461 // We can't set it to GONE, otherwise the RelativeLayout gets screwed up
2462 button.setVisibility(View.INVISIBLE);
2463 button.setFocusable(false);
2464 button.setClickable(false);
2465 }
2466
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002467 /**
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002468 * Helper function for showing or hiding a toolbar button, possibly animated.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002469 *
2470 * @param show If true, create an animation to the show the item. Otherwise, hide it.
2471 * @param view The toolbar button to be animated
Chet Haaseb1254a62010-09-07 13:35:00 -07002472 * @param seq A AnimatorSet that will be used to animate the transition. If null, the
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002473 * transition will not be animated.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002474 */
Chet Haaseb1254a62010-09-07 13:35:00 -07002475 private void hideOrShowToolbarButton(boolean show, final View view, AnimatorSet seq) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002476 final boolean showing = show;
2477 final boolean hiding = !show;
2478
2479 final int duration = show ?
2480 getResources().getInteger(R.integer.config_toolbarButtonFadeInTime) :
2481 getResources().getInteger(R.integer.config_toolbarButtonFadeOutTime);
2482
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002483 if (seq != null) {
Chet Haase472b2812010-10-14 07:02:04 -07002484 Animator anim = ObjectAnimator.ofFloat(view, "alpha", show ? 1.0f : 0.0f);
2485 anim.setDuration(duration);
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002486 anim.addListener(new LauncherAnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002487 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002488 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002489 if (showing) showToolbarButton(view);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002490 }
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002491 @Override
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002492 public void onAnimationEndOrCancel(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002493 if (hiding) hideToolbarButton(view);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002494 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002495 });
2496 seq.play(anim);
2497 } else {
2498 if (showing) {
2499 showToolbarButton(view);
2500 } else {
2501 hideToolbarButton(view);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002502 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002503 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002504 }
2505
2506 /**
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002507 * Show/hide the appropriate toolbar buttons for newState.
2508 * If showSeq or hideSeq is null, the transition will be done immediately (not animated).
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002509 *
2510 * @param newState The state that is being switched to
Chet Haaseb1254a62010-09-07 13:35:00 -07002511 * @param showSeq AnimatorSet in which to put "show" animations, or null.
2512 * @param hideSeq AnimatorSet in which to put "hide" animations, or null.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002513 */
Chet Haaseb1254a62010-09-07 13:35:00 -07002514 private void hideAndShowToolbarButtons(State newState, AnimatorSet showSeq, AnimatorSet hideSeq) {
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002515 final View searchButton = findViewById(R.id.search_button_cluster);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002516 final View allAppsButton = findViewById(R.id.all_apps_button);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002517 final View configureButton = findViewById(R.id.configure_button);
2518
2519 switch (newState) {
2520 case WORKSPACE:
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002521 hideOrShowToolbarButton(true, searchButton, showSeq);
2522 hideOrShowToolbarButton(true, allAppsButton, showSeq);
2523 hideOrShowToolbarButton(true, configureButton, showSeq);
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002524 mDeleteZone.setHandle(allAppsButton);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002525 break;
2526 case ALL_APPS:
Adam Lesinski6b879f02010-11-04 16:15:23 -07002527 hideOrShowToolbarButton(false, configureButton, hideSeq);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002528 hideOrShowToolbarButton(false, searchButton, hideSeq);
2529 hideOrShowToolbarButton(false, allAppsButton, hideSeq);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002530 break;
2531 case CUSTOMIZE:
Adam Lesinski6b879f02010-11-04 16:15:23 -07002532 hideOrShowToolbarButton(false, allAppsButton, hideSeq);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002533 hideOrShowToolbarButton(false, searchButton, hideSeq);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002534 hideOrShowToolbarButton(false, configureButton, hideSeq);
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002535 mDeleteZone.setHandle(allAppsButton);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002536 break;
2537 }
2538 }
2539
2540 /**
2541 * Helper method for the cameraZoomIn/cameraZoomOut animations
2542 * @param view The view being animated
2543 * @param state The state that we are moving in or out of -- either ALL_APPS or CUSTOMIZE
2544 * @param scaleFactor The scale factor used for the zoom
2545 */
2546 private void setPivotsForZoom(View view, State state, float scaleFactor) {
2547 final int height = view.getHeight();
Adam Cohen61033d32010-11-15 18:29:44 -08002548
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002549 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen61033d32010-11-15 18:29:44 -08002550 // Set pivotY so that at the starting zoom factor, the view is partially
2551 // visible. Modifying initialHeightFactor changes how much of the view is
2552 // initially showing, and hence the perceived angle from which the view enters.
2553 final float initialHeightFactor = 0.2f;
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002554 if (state == State.ALL_APPS) {
Adam Cohen61033d32010-11-15 18:29:44 -08002555 view.setPivotY((1 + initialHeightFactor) * height);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002556 } else {
Adam Cohen61033d32010-11-15 18:29:44 -08002557 view.setPivotY(-initialHeightFactor * height);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002558 }
2559 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002560
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002561 /**
2562 * Zoom the camera out from the workspace to reveal 'toView'.
2563 * Assumes that the view to show is anchored at either the very top or very bottom
2564 * of the screen.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002565 * @param toState The state to zoom out to. Must be ALL_APPS or CUSTOMIZE.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002566 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002567 private void cameraZoomOut(State toState, boolean animated) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002568 final Resources res = getResources();
2569 final int duration = res.getInteger(R.integer.config_allAppsZoomInTime);
2570 final float scale = (float) res.getInteger(R.integer.config_allAppsZoomScaleFactor);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002571 final boolean toAllApps = (toState == State.ALL_APPS);
2572 final View toView = toAllApps ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
Patrick Dubroy558654c2010-07-23 16:48:11 -07002573
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002574 setPivotsForZoom(toView, toState, scale);
2575
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002576 if (toAllApps) {
Adam Lesinski6b879f02010-11-04 16:15:23 -07002577 mWorkspace.shrinkToBottomHidden(animated);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002578 } else {
2579 mWorkspace.shrinkToTop(animated);
2580 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002581
2582 if (animated) {
Chet Haase472b2812010-10-14 07:02:04 -07002583 ValueAnimator scaleAnim = ObjectAnimator.ofPropertyValuesHolder(toView,
2584 PropertyValuesHolder.ofFloat("scaleX", scale, 1.0f),
2585 PropertyValuesHolder.ofFloat("scaleY", scale, 1.0f));
2586 scaleAnim.setDuration(duration);
Adam Cohen61033d32010-11-15 18:29:44 -08002587
2588 scaleAnim.setInterpolator(new Workspace.ZoomOutInterpolator());
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002589 scaleAnim.addListener(new LauncherAnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002590 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002591 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002592 // Prepare the position
2593 toView.setTranslationX(0.0f);
2594 toView.setTranslationY(0.0f);
2595 toView.setVisibility(View.VISIBLE);
Adam Cohen61033d32010-11-15 18:29:44 -08002596 toView.setAlpha(1.0f);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002597 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002598 @Override
2599 public void onAnimationEndOrCancel(Animator animation) {
2600 // If we don't set the final scale values here, if this animation is cancelled
2601 // it will have the wrong scale value and subsequent cameraPan animations will
2602 // not fix that
2603 toView.setScaleX(1.0f);
2604 toView.setScaleY(1.0f);
2605 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002606 });
2607
Chet Haaseb1254a62010-09-07 13:35:00 -07002608 AnimatorSet toolbarHideAnim = new AnimatorSet();
2609 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002610 hideAndShowToolbarButtons(toState, toolbarShowAnim, toolbarHideAnim);
2611
2612 // toView should appear right at the end of the workspace shrink animation
2613 final int startDelay = res.getInteger(R.integer.config_workspaceShrinkTime) - duration;
2614
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002615 if (mStateAnimation != null) mStateAnimation.cancel();
2616 mStateAnimation = new AnimatorSet();
2617 mStateAnimation.playTogether(scaleAnim, toolbarHideAnim);
2618 mStateAnimation.play(scaleAnim).after(startDelay);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002619
2620 // Show the new toolbar buttons just as the main animation is ending
2621 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002622 mStateAnimation.play(toolbarShowAnim).after(duration + startDelay - fadeInTime);
2623 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002624 } else {
2625 toView.setTranslationX(0.0f);
2626 toView.setTranslationY(0.0f);
2627 toView.setScaleX(1.0f);
2628 toView.setScaleY(1.0f);
2629 toView.setVisibility(View.VISIBLE);
2630 hideAndShowToolbarButtons(toState, null, null);
2631 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002632 }
2633
2634 /**
2635 * Zoom the camera back into the workspace, hiding 'fromView'.
2636 * This is the opposite of cameraZoomOut.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002637 * @param fromState The current state (must be ALL_APPS or CUSTOMIZE).
2638 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002639 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002640 private void cameraZoomIn(State fromState, boolean animated) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002641 Resources res = getResources();
2642 int duration = res.getInteger(R.integer.config_allAppsZoomOutTime);
2643 float scaleFactor = (float) res.getInteger(R.integer.config_allAppsZoomScaleFactor);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002644 final View fromView =
2645 (fromState == State.ALL_APPS) ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
2646
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002647 mCustomizePagedView.endChoiceMode();
2648 mAllAppsPagedView.endChoiceMode();
2649
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002650 setPivotsForZoom(fromView, fromState, scaleFactor);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002651
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002652 mWorkspace.unshrink(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002653
2654 if (animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002655 if (mStateAnimation != null) mStateAnimation.cancel();
2656 mStateAnimation = new AnimatorSet();
Chet Haase472b2812010-10-14 07:02:04 -07002657 ValueAnimator scaleAnim = ObjectAnimator.ofPropertyValuesHolder(fromView,
2658 PropertyValuesHolder.ofFloat("scaleX", scaleFactor),
2659 PropertyValuesHolder.ofFloat("scaleY", scaleFactor));
2660 scaleAnim.setDuration(duration);
Adam Cohen61033d32010-11-15 18:29:44 -08002661 scaleAnim.setInterpolator(new Workspace.ZoomInInterpolator());
2662
2663 ValueAnimator alphaAnim = ObjectAnimator.ofPropertyValuesHolder(fromView,
2664 PropertyValuesHolder.ofFloat("alpha", 1.0f, 0.0f));
2665 alphaAnim.setDuration(res.getInteger(R.integer.config_allAppsFadeOutTime));
2666 alphaAnim.addListener(new LauncherAnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002667 @Override
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002668 public void onAnimationEndOrCancel(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002669 fromView.setVisibility(View.GONE);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002670 }
2671 });
2672
Chet Haaseb1254a62010-09-07 13:35:00 -07002673 AnimatorSet toolbarHideAnim = new AnimatorSet();
2674 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002675 hideAndShowToolbarButtons(State.WORKSPACE, toolbarShowAnim, toolbarHideAnim);
2676
Adam Cohen61033d32010-11-15 18:29:44 -08002677 mStateAnimation.playTogether(scaleAnim, toolbarHideAnim, alphaAnim);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002678
2679 // Show the new toolbar buttons at the very end of the whole animation
2680 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
2681 final int unshrinkTime = res.getInteger(R.integer.config_workspaceUnshrinkTime);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002682 mStateAnimation.play(toolbarShowAnim).after(unshrinkTime - fadeInTime);
2683 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002684 } else {
2685 fromView.setVisibility(View.GONE);
2686 hideAndShowToolbarButtons(State.WORKSPACE, null, null);
2687 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002688 }
2689
2690 /**
2691 * Pan the camera in the vertical plane between 'fromView' and 'toView'.
2692 * This is the transition used on xlarge screens to go between all apps and
2693 * the home customization drawer.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002694 * @param fromState The view to pan away from. Must be ALL_APPS or CUSTOMIZE.
2695 * @param toState The view to pan into the frame. Must be ALL_APPS or CUSTOMIZE.
2696 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002697 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002698 private void cameraPan(State fromState, State toState, boolean animated) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002699 final Resources res = getResources();
2700 final int duration = res.getInteger(R.integer.config_allAppsCameraPanTime);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002701 final int workspaceHeight = mWorkspace.getHeight();
2702
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002703 final boolean fromAllApps = (fromState == State.ALL_APPS);
2704 final View fromView = fromAllApps ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
2705 final View toView = fromAllApps ? mHomeCustomizationDrawer : (View) mAllAppsGrid;
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002706
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002707 final float fromViewStartY = fromAllApps ? 0.0f : fromView.getY();
2708 final float fromViewEndY = fromAllApps ? -fromView.getHeight() * 2 : workspaceHeight * 2;
2709 final float toViewStartY = fromAllApps ? workspaceHeight * 2 : -toView.getHeight() * 2;
2710 final float toViewEndY = fromAllApps ? workspaceHeight - toView.getHeight() : 0.0f;
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002711
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002712 mCustomizePagedView.endChoiceMode();
2713 mAllAppsPagedView.endChoiceMode();
2714
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002715 if (toState == State.ALL_APPS) {
Adam Lesinski6b879f02010-11-04 16:15:23 -07002716 mWorkspace.shrinkToBottomHidden(animated);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002717 } else {
2718 mWorkspace.shrinkToTop(animated);
2719 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002720
2721 if (animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002722 if (mStateAnimation != null) mStateAnimation.cancel();
2723 mStateAnimation = new AnimatorSet();
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002724 mStateAnimation.addListener(new LauncherAnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002725 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002726 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002727 toView.setVisibility(View.VISIBLE);
2728 toView.setY(toViewStartY);
Adam Cohen61033d32010-11-15 18:29:44 -08002729 toView.setAlpha(1.0f);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002730 }
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002731 @Override
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002732 public void onAnimationEndOrCancel(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002733 fromView.setVisibility(View.GONE);
2734 }
2735 });
2736
Chet Haaseb1254a62010-09-07 13:35:00 -07002737 AnimatorSet toolbarHideAnim = new AnimatorSet();
2738 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002739 hideAndShowToolbarButtons(toState, toolbarShowAnim, toolbarHideAnim);
2740
Chet Haase472b2812010-10-14 07:02:04 -07002741 ObjectAnimator fromAnim = ObjectAnimator.ofFloat(fromView, "y",
2742 fromViewStartY, fromViewEndY);
2743 fromAnim.setDuration(duration);
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002744 ObjectAnimator toAnim = ObjectAnimator.ofPropertyValuesHolder(toView,
2745 PropertyValuesHolder.ofFloat("y", toViewStartY, toViewEndY),
2746 PropertyValuesHolder.ofFloat("scaleX", toView.getScaleX(), 1.0f),
2747 PropertyValuesHolder.ofFloat("scaleY", toView.getScaleY(), 1.0f)
2748 );
Chet Haase472b2812010-10-14 07:02:04 -07002749 fromAnim.setDuration(duration);
2750 mStateAnimation.playTogether(toolbarHideAnim, fromAnim, toAnim);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002751
2752 // Show the new toolbar buttons just as the main animation is ending
2753 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002754 mStateAnimation.play(toolbarShowAnim).after(duration - fadeInTime);
2755 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002756 } else {
2757 fromView.setY(fromViewEndY);
2758 fromView.setVisibility(View.GONE);
2759 toView.setY(toViewEndY);
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002760 toView.setScaleX(1.0f);
2761 toView.setScaleY(1.0f);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002762 toView.setVisibility(View.VISIBLE);
2763 hideAndShowToolbarButtons(toState, null, null);
2764 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002765 }
2766
2767 void showAllApps(boolean animated) {
Michael Jurka883f55b2010-10-21 15:47:14 -07002768 if (mState == State.ALL_APPS) {
Winson Chung80baf5a2010-08-09 16:03:15 -07002769 return;
Michael Jurka883f55b2010-10-21 15:47:14 -07002770 }
Winson Chung80baf5a2010-08-09 16:03:15 -07002771
Michael Jurka79212d82010-07-30 16:36:20 -07002772 if (LauncherApplication.isScreenXLarge()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002773 if (mState == State.CUSTOMIZE) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002774 cameraPan(State.CUSTOMIZE, State.ALL_APPS, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002775 } else {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002776 cameraZoomOut(State.ALL_APPS, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002777 }
Patrick Dubroy558654c2010-07-23 16:48:11 -07002778 } else {
2779 mAllAppsGrid.zoom(1.0f, animated);
2780 }
Joe Onorato3a8820b2009-11-10 15:06:42 -08002781
Romain Guyc16fea72010-03-12 17:17:56 -08002782 ((View) mAllAppsGrid).setFocusable(true);
2783 ((View) mAllAppsGrid).requestFocus();
Winson Chungaafa03c2010-06-11 17:34:16 -07002784
Joe Onorato7c312c12009-08-13 21:36:53 -07002785 // TODO: fade these two too
2786 mDeleteZone.setVisibility(View.GONE);
Adam Lesinski6b879f02010-11-04 16:15:23 -07002787
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002788 // Change the state *after* we've called all the transition code
2789 mState = State.ALL_APPS;
2790 }
2791
2792
2793 void showWorkspace(boolean animated) {
2794 showWorkspace(animated, null);
2795 }
2796
2797 void showWorkspace(boolean animated, CellLayout layout) {
Michael Jurka9c6de3d2010-11-23 16:23:58 -08002798 if (layout != null) {
2799 // always animated, but that's ok since we never specify a layout and
2800 // want no animation
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002801 mWorkspace.unshrink(layout);
2802 } else {
2803 mWorkspace.unshrink(animated);
2804 }
2805 if (mState == State.ALL_APPS) {
2806 closeAllApps(animated);
2807 } else if (mState == State.CUSTOMIZE) {
2808 hideCustomizationDrawer(animated);
2809 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07002810
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002811 // Change the state *after* we've called all the transition code
2812 mState = State.WORKSPACE;
Joe Onorato00acb122009-08-04 16:04:30 -04002813 }
2814
Joe Onoratob2061212009-11-24 16:13:54 -05002815 /**
Joe Onorato7e4ed992009-12-03 13:10:49 -08002816 * Things to test when changing this code.
Joe Onoratob2061212009-11-24 16:13:54 -05002817 * - Home from workspace
2818 * - from center screen
2819 * - from other screens
2820 * - Home from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002821 * - from center screen
2822 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002823 * - Back from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002824 * - from center screen
2825 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002826 * - Launch app from workspace and quit
2827 * - with back
2828 * - with home
2829 * - Launch app from all apps and quit
2830 * - with back
2831 * - with home
Joe Onorato7e4ed992009-12-03 13:10:49 -08002832 * - Go to a screen that's not the default, then all
2833 * apps, and launch and app, and go back
2834 * - with back
2835 * -with home
Joe Onoratob2061212009-11-24 16:13:54 -05002836 * - On workspace, long press power and go back
2837 * - with back
2838 * - with home
2839 * - On all apps, long press power and go back
2840 * - with back
2841 * - with home
2842 * - On workspace, power off
2843 * - On all apps, power off
Joe Onorato7e4ed992009-12-03 13:10:49 -08002844 * - Launch an app and turn off the screen while in that app
2845 * - Go back with home key
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002846 * - Go back with back key TODO: make this not go to workspace
Joe Onorato7e4ed992009-12-03 13:10:49 -08002847 * - From all apps
2848 * - From workspace
Joe Onoratoeffc4a82010-04-15 11:48:13 -07002849 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2850 * - From all apps
2851 * - From the center workspace
2852 * - From another workspace
Joe Onoratob2061212009-11-24 16:13:54 -05002853 */
Joe Onorato7bb17492009-09-24 17:51:01 -07002854 void closeAllApps(boolean animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002855 if (mState == State.ALL_APPS) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002856 mWorkspace.setVisibility(View.VISIBLE);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002857 if (LauncherApplication.isScreenXLarge()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002858 cameraZoomIn(State.ALL_APPS, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002859 } else {
2860 mAllAppsGrid.zoom(0.0f, animated);
2861 }
Daniel Sandler388f6792010-03-02 14:08:08 -05002862 ((View)mAllAppsGrid).setFocusable(false);
Michael Jurka0142d492010-08-25 17:46:15 -07002863 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onoratoe77c08d2009-08-01 00:01:20 -07002864 }
Joe Onorato7404ee42009-07-31 11:54:44 -07002865 }
2866
Joe Onorato7c312c12009-08-13 21:36:53 -07002867 void lockAllApps() {
2868 // TODO
2869 }
2870
2871 void unlockAllApps() {
2872 // TODO
2873 }
2874
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002875 // Show the customization drawer (only exists in x-large configuration)
2876 private void showCustomizationDrawer(boolean animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002877 if (mState == State.ALL_APPS) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002878 cameraPan(State.ALL_APPS, State.CUSTOMIZE, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002879 } else {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002880 cameraZoomOut(State.CUSTOMIZE, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002881 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002882 // Change the state *after* we've called all the transition code
2883 mState = State.CUSTOMIZE;
Patrick Dubroy558654c2010-07-23 16:48:11 -07002884 }
2885
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002886 // Hide the customization drawer (only exists in x-large configuration)
2887 void hideCustomizationDrawer(boolean animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002888 if (mState == State.CUSTOMIZE) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002889 cameraZoomIn(State.CUSTOMIZE, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002890 }
2891 }
2892
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002893 void addExternalItemToScreen(ItemInfo itemInfo, CellLayout layout) {
2894 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
2895 showOutOfSpaceMessage();
Michael Jurka213d9632010-07-28 11:29:25 -07002896 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002897 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002898
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002899 void onWorkspaceClick(CellLayout layout) {
2900 showWorkspace(true, layout);
Michael Jurka213d9632010-07-28 11:29:25 -07002901 }
2902
Michael Jurka4ef207b2010-11-29 17:05:45 -08002903 // if successful in getting icon, return it; otherwise, set button to use default drawable
2904 private Drawable updateButtonWithIconFromExternalActivity(
Michael Jurka0423dcf2010-10-05 14:56:18 -07002905 int buttonId, ComponentName activityName, int fallbackDrawableId) {
2906 ImageView button = (ImageView) findViewById(buttonId);
2907 Drawable toolbarIcon = null;
2908 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002909 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07002910 // Look for the toolbar icon specified in the activity meta-data
2911 Bundle metaData = packageManager.getActivityInfo(
2912 activityName, PackageManager.GET_META_DATA).metaData;
2913 if (metaData != null) {
2914 int iconResId = metaData.getInt(TOOLBAR_ICON_METADATA_NAME);
2915 if (iconResId != 0) {
2916 Resources res = packageManager.getResourcesForActivity(activityName);
2917 toolbarIcon = res.getDrawable(iconResId);
2918 }
2919 }
2920 } catch (NameNotFoundException e) {
2921 // Do nothing
2922 }
2923 // If we were unable to find the icon via the meta-data, use a generic one
2924 if (toolbarIcon == null) {
2925 button.setImageResource(fallbackDrawableId);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002926 return null;
Michael Jurka0423dcf2010-10-05 14:56:18 -07002927 } else {
2928 button.setImageDrawable(toolbarIcon);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002929 return toolbarIcon;
Michael Jurka0423dcf2010-10-05 14:56:18 -07002930 }
2931 }
2932
Michael Jurka4ef207b2010-11-29 17:05:45 -08002933 private void updateButtonWithDrawable(int buttonId, Drawable d) {
2934 ImageView button = (ImageView) findViewById(buttonId);
2935 button.setImageDrawable(d);
2936 }
2937
Michael Jurka0423dcf2010-10-05 14:56:18 -07002938 private void updateGlobalSearchIcon() {
2939 if (LauncherApplication.isScreenXLarge()) {
2940 final SearchManager searchManager =
2941 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2942 ComponentName activityName = searchManager.getGlobalSearchActivity();
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002943 if (activityName != null) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002944 sGlobalSearchIcon = updateButtonWithIconFromExternalActivity(
Michael Jurka0423dcf2010-10-05 14:56:18 -07002945 R.id.search_button, activityName, R.drawable.search_button_generic);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002946 } else {
2947 findViewById(R.id.search_button).setVisibility(View.GONE);
2948 }
2949 }
2950 }
2951
Michael Jurka4ef207b2010-11-29 17:05:45 -08002952 private void updateGlobalSearchIcon(Drawable d) {
2953 updateButtonWithDrawable(R.id.search_button, d);
2954 }
2955
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002956 private void updateVoiceSearchIcon() {
2957 if (LauncherApplication.isScreenXLarge()) {
2958 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2959 ComponentName activityName = intent.resolveActivity(getPackageManager());
2960 if (activityName != null) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002961 sVoiceSearchIcon = updateButtonWithIconFromExternalActivity(
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002962 R.id.voice_button, activityName, R.drawable.ic_voice_search);
2963 } else {
2964 findViewById(R.id.voice_button).setVisibility(View.GONE);
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002965 }
2966 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002967 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002968
Michael Jurka4ef207b2010-11-29 17:05:45 -08002969 private void updateVoiceSearchIcon(Drawable d) {
2970 updateButtonWithDrawable(R.id.voice_button, d);
2971 }
2972
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002973 /**
2974 * Sets the app market icon (shown when all apps is visible on x-large screens)
2975 */
2976 private void updateAppMarketIcon() {
Michael Jurka0423dcf2010-10-05 14:56:18 -07002977 if (LauncherApplication.isScreenXLarge()) {
2978 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
2979 // Find the app market activity by resolving an intent.
2980 // (If multiple app markets are installed, it will return the ResolverActivity.)
2981 ComponentName activityName = intent.resolveActivity(getPackageManager());
2982 if (activityName != null) {
2983 mAppMarketIntent = intent;
Michael Jurka4ef207b2010-11-29 17:05:45 -08002984 sAppMarketIcon = updateButtonWithIconFromExternalActivity(
Michael Jurka0423dcf2010-10-05 14:56:18 -07002985 R.id.market_button, activityName, R.drawable.app_market_generic);
2986 }
2987 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002988 }
2989
Michael Jurka4ef207b2010-11-29 17:05:45 -08002990 private void updateAppMarketIcon(Drawable d) {
2991 updateButtonWithDrawable(R.id.market_button, d);
2992 }
2993
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002994 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002995 * Displays the shortcut creation dialog and launches, if necessary, the
2996 * appropriate activity.
2997 */
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002998 private class CreateShortcut implements DialogInterface.OnClickListener,
Romain Guy7b4ef332009-07-14 13:58:08 -07002999 DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
3000 DialogInterface.OnShowListener {
3001
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003002 private AddAdapter mAdapter;
Romain Guy9ffb5432009-03-24 21:04:15 -07003003
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003004 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003005 mAdapter = new AddAdapter(Launcher.this);
Romain Guycbb89e42009-06-08 15:52:54 -07003006
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003007 final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
3008 builder.setTitle(getString(R.string.menu_item_add_item));
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003009 builder.setAdapter(mAdapter, this);
Romain Guycbb89e42009-06-08 15:52:54 -07003010
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003011 builder.setInverseBackgroundForced(true);
3012
3013 AlertDialog dialog = builder.create();
3014 dialog.setOnCancelListener(this);
Romain Guycbb89e42009-06-08 15:52:54 -07003015 dialog.setOnDismissListener(this);
Romain Guy7b4ef332009-07-14 13:58:08 -07003016 dialog.setOnShowListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003017
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003018 return dialog;
3019 }
3020
3021 public void onCancel(DialogInterface dialog) {
3022 mWaitingForResult = false;
3023 cleanup();
3024 }
3025
Romain Guycbb89e42009-06-08 15:52:54 -07003026 public void onDismiss(DialogInterface dialog) {
Romain Guycbb89e42009-06-08 15:52:54 -07003027 }
3028
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003029 private void cleanup() {
Joe Onoratocc19a532009-11-19 14:19:17 -08003030 try {
3031 dismissDialog(DIALOG_CREATE_SHORTCUT);
3032 } catch (Exception e) {
3033 // An exception is thrown if the dialog is not visible, which is fine
3034 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003035 }
3036
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003037 /**
3038 * Handle the action clicked in the "Add to home" dialog.
3039 */
3040 public void onClick(DialogInterface dialog, int which) {
3041 Resources res = getResources();
3042 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07003043
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003044 switch (which) {
3045 case AddAdapter.ITEM_SHORTCUT: {
Joe Onoratodeb98af2010-02-19 14:59:39 -08003046 pickShortcut();
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003047 break;
3048 }
Romain Guycbb89e42009-06-08 15:52:54 -07003049
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003050 case AddAdapter.ITEM_APPWIDGET: {
3051 int appWidgetId = Launcher.this.mAppWidgetHost.allocateAppWidgetId();
Romain Guycbb89e42009-06-08 15:52:54 -07003052
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003053 Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
3054 pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003055 // start the pick activity
3056 startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET);
3057 break;
3058 }
Romain Guycbb89e42009-06-08 15:52:54 -07003059
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003060 case AddAdapter.ITEM_LIVE_FOLDER: {
3061 // Insert extra item to handle inserting folder
3062 Bundle bundle = new Bundle();
Romain Guycbb89e42009-06-08 15:52:54 -07003063
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003064 ArrayList<String> shortcutNames = new ArrayList<String>();
3065 shortcutNames.add(res.getString(R.string.group_folder));
3066 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
Romain Guycbb89e42009-06-08 15:52:54 -07003067
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003068 ArrayList<ShortcutIconResource> shortcutIcons =
3069 new ArrayList<ShortcutIconResource>();
3070 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
3071 R.drawable.ic_launcher_folder));
3072 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
3073
3074 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
3075 pickIntent.putExtra(Intent.EXTRA_INTENT,
3076 new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER));
3077 pickIntent.putExtra(Intent.EXTRA_TITLE,
3078 getText(R.string.title_select_live_folder));
3079 pickIntent.putExtras(bundle);
Romain Guycbb89e42009-06-08 15:52:54 -07003080
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003081 startActivityForResult(pickIntent, REQUEST_PICK_LIVE_FOLDER);
3082 break;
3083 }
3084
3085 case AddAdapter.ITEM_WALLPAPER: {
3086 startWallpaper();
3087 break;
3088 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003089 }
3090 }
Romain Guy7b4ef332009-07-14 13:58:08 -07003091
3092 public void onShow(DialogInterface dialog) {
Winson Chungaafa03c2010-06-11 17:34:16 -07003093 mWaitingForResult = true;
Romain Guy7b4ef332009-07-14 13:58:08 -07003094 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003095 }
3096
3097 /**
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003098 * Receives notifications when applications are added/removed.
3099 */
3100 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3101 @Override
3102 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003103 closeSystemDialogs();
Joe Onoratob2061212009-11-24 16:13:54 -05003104 String reason = intent.getStringExtra("reason");
3105 if (!"homekey".equals(reason)) {
3106 boolean animate = true;
Joe Onorato34a0e1b2009-12-14 17:44:51 -08003107 if (mPaused || "lock".equals(reason)) {
Joe Onoratob2061212009-11-24 16:13:54 -05003108 animate = false;
3109 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003110 showWorkspace(animate);
Joe Onoratob2061212009-11-24 16:13:54 -05003111 }
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003112 }
3113 }
3114
3115 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003116 * Receives notifications whenever the appwidgets are reset.
3117 */
3118 private class AppWidgetResetObserver extends ContentObserver {
3119 public AppWidgetResetObserver() {
3120 super(new Handler());
3121 }
3122
3123 @Override
3124 public void onChange(boolean selfChange) {
3125 onAppWidgetReset();
3126 }
3127 }
3128
3129 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003130 * If the activity is currently paused, signal that we need to re-run the loader
3131 * in onResume.
3132 *
3133 * This needs to be called from incoming places where resources might have been loaded
3134 * while we are paused. That is becaues the Configuration might be wrong
3135 * when we're not running, and if it comes back to what it was when we
3136 * were paused, we are not restarted.
3137 *
3138 * Implementation of the method from LauncherModel.Callbacks.
3139 *
3140 * @return true if we are currently paused. The caller might be able to
3141 * skip some work in that case since we will come back again.
3142 */
3143 public boolean setLoadOnResume() {
3144 if (mPaused) {
3145 Log.i(TAG, "setLoadOnResume");
3146 mOnResumeNeedsLoad = true;
3147 return true;
3148 } else {
3149 return false;
3150 }
3151 }
3152
3153 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003154 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003155 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003156 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003157 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003158 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003159 } else {
3160 return SCREEN_COUNT / 2;
3161 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003162 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003163
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003164 void setAllAppsPagedView(PagedView view) {
3165 mAllAppsPagedView = view;
3166 }
3167
Joe Onorato9c1289c2009-08-17 11:03:03 -04003168 /**
3169 * Refreshes the shortcuts shown on the workspace.
3170 *
3171 * Implementation of the method from LauncherModel.Callbacks.
3172 */
3173 public void startBinding() {
3174 final Workspace workspace = mWorkspace;
3175 int count = workspace.getChildCount();
3176 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04003177 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Joe Onorato9c1289c2009-08-17 11:03:03 -04003178 ((ViewGroup) workspace.getChildAt(i)).removeAllViewsInLayout();
3179 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003180
Joe Onorato9c1289c2009-08-17 11:03:03 -04003181 if (DEBUG_USER_INTERFACE) {
3182 android.widget.Button finishButton = new android.widget.Button(this);
3183 finishButton.setText("Finish");
3184 workspace.addInScreen(finishButton, 1, 0, 0, 1, 1);
3185
3186 finishButton.setOnClickListener(new android.widget.Button.OnClickListener() {
3187 public void onClick(View v) {
3188 finish();
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003189 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003190 });
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003191 }
3192 }
3193
3194 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003195 * Bind the items start-end from the list.
3196 *
3197 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003198 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003199 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
3200
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003201 setLoadOnResume();
3202
Joe Onorato9c1289c2009-08-17 11:03:03 -04003203 final Workspace workspace = mWorkspace;
3204
3205 for (int i=start; i<end; i++) {
3206 final ItemInfo item = shortcuts.get(i);
3207 mDesktopItems.add(item);
3208 switch (item.itemType) {
3209 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3210 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Joe Onorato0589f0f2010-02-08 13:44:00 -08003211 final View shortcut = createShortcut((ShortcutInfo)item);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003212 workspace.addInScreen(shortcut, item.screen, item.cellX, item.cellY, 1, 1,
3213 false);
3214 break;
3215 case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER:
3216 final FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003217 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Michael Jurkac9a96192010-11-01 11:52:08 -07003218 (UserFolderInfo) item, mIconCache);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003219 workspace.addInScreen(newFolder, item.screen, item.cellX, item.cellY, 1, 1,
3220 false);
3221 break;
3222 case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER:
3223 final FolderIcon newLiveFolder = LiveFolderIcon.fromXml(
3224 R.layout.live_folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003225 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Joe Onorato9c1289c2009-08-17 11:03:03 -04003226 (LiveFolderInfo) item);
3227 workspace.addInScreen(newLiveFolder, item.screen, item.cellX, item.cellY, 1, 1,
3228 false);
3229 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003230 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003231 }
3232
Joe Onorato9c1289c2009-08-17 11:03:03 -04003233 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003234 }
3235
Joe Onorato9c1289c2009-08-17 11:03:03 -04003236 /**
3237 * Implementation of the method from LauncherModel.Callbacks.
3238 */
Joe Onoratoad72e172009-11-06 16:25:04 -05003239 public void bindFolders(HashMap<Long, FolderInfo> folders) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003240 setLoadOnResume();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003241 sFolders.clear();
3242 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003243 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003244
3245 /**
3246 * Add the views for a widget to the workspace.
3247 *
3248 * Implementation of the method from LauncherModel.Callbacks.
3249 */
3250 public void bindAppWidget(LauncherAppWidgetInfo item) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003251 setLoadOnResume();
3252
Daniel Sandler843e8602010-06-07 14:59:01 -04003253 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3254 if (DEBUG_WIDGETS) {
3255 Log.d(TAG, "bindAppWidget: " + item);
3256 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003257 final Workspace workspace = mWorkspace;
3258
3259 final int appWidgetId = item.appWidgetId;
3260 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003261 if (DEBUG_WIDGETS) {
3262 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3263 }
3264
Joe Onorato9c1289c2009-08-17 11:03:03 -04003265 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3266
Joe Onorato9c1289c2009-08-17 11:03:03 -04003267 item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
3268 item.hostView.setTag(item);
3269
3270 workspace.addInScreen(item.hostView, item.screen, item.cellX,
3271 item.cellY, item.spanX, item.spanY, false);
3272
Adam Cohended9f8d2010-11-03 13:25:16 -07003273 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3274
Joe Onorato9c1289c2009-08-17 11:03:03 -04003275 workspace.requestLayout();
3276
3277 mDesktopItems.add(item);
Daniel Sandler843e8602010-06-07 14:59:01 -04003278
3279 if (DEBUG_WIDGETS) {
3280 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3281 + (SystemClock.uptimeMillis()-start) + "ms");
3282 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003283 }
3284
3285 /**
3286 * Callback saying that there aren't any more items to bind.
3287 *
3288 * Implementation of the method from LauncherModel.Callbacks.
3289 */
3290 public void finishBindingItems() {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003291 setLoadOnResume();
3292
Joe Onorato9c1289c2009-08-17 11:03:03 -04003293 if (mSavedState != null) {
3294 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003295 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003296 }
3297
3298 final long[] userFolders = mSavedState.getLongArray(RUNTIME_STATE_USER_FOLDERS);
3299 if (userFolders != null) {
3300 for (long folderId : userFolders) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003301 final FolderInfo info = sFolders.get(folderId);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003302 if (info != null) {
3303 openFolder(info);
3304 }
3305 }
3306 final Folder openFolder = mWorkspace.getOpenFolder();
3307 if (openFolder != null) {
3308 openFolder.requestFocus();
3309 }
3310 }
3311
Joe Onorato9c1289c2009-08-17 11:03:03 -04003312 mSavedState = null;
3313 }
3314
3315 if (mSavedInstanceState != null) {
3316 super.onRestoreInstanceState(mSavedInstanceState);
3317 mSavedInstanceState = null;
3318 }
3319
Joe Onorato9c1289c2009-08-17 11:03:03 -04003320 mWorkspaceLoading = false;
3321 }
3322
3323 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003324 * Updates the icons on the launcher that are affected by changes to the package list
3325 * on the device.
3326 */
3327 private void updateIconsAffectedByPackageManagerChanges() {
3328 updateAppMarketIcon();
3329 updateGlobalSearchIcon();
3330 updateVoiceSearchIcon();
3331 }
3332
3333 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003334 * Add the icons for all apps.
3335 *
3336 * Implementation of the method from LauncherModel.Callbacks.
3337 */
3338 public void bindAllApplications(ArrayList<ApplicationInfo> apps) {
Romain Guy84f296c2009-11-04 15:00:44 -08003339 mAllAppsGrid.setApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003340 if (mCustomizePagedView != null) {
3341 mCustomizePagedView.setApps(apps);
3342 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003343 updateIconsAffectedByPackageManagerChanges();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003344 }
3345
3346 /**
3347 * A package was installed.
3348 *
3349 * Implementation of the method from LauncherModel.Callbacks.
3350 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003351 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003352 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003353 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onoratoa8138d52009-10-06 19:25:30 -07003354 mAllAppsGrid.addApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003355 if (mCustomizePagedView != null) {
3356 mCustomizePagedView.addApps(apps);
3357 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003358 updateIconsAffectedByPackageManagerChanges();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003359 }
3360
3361 /**
3362 * A package was updated.
3363 *
3364 * Implementation of the method from LauncherModel.Callbacks.
3365 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003366 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003367 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003368 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato64e6be72010-03-05 15:05:52 -05003369 mWorkspace.updateShortcuts(apps);
3370 mAllAppsGrid.updateApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003371 if (mCustomizePagedView != null) {
3372 mCustomizePagedView.updateApps(apps);
3373 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003374 updateIconsAffectedByPackageManagerChanges();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003375 }
3376
3377 /**
3378 * A package was uninstalled.
3379 *
3380 * Implementation of the method from LauncherModel.Callbacks.
3381 */
Joe Onorato36115782010-06-17 13:28:48 -04003382 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003383 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato36115782010-06-17 13:28:48 -04003384 if (permanent) {
3385 mWorkspace.removeItems(apps);
3386 }
Joe Onoratoa8138d52009-10-06 19:25:30 -07003387 mAllAppsGrid.removeApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003388 if (mCustomizePagedView != null) {
3389 mCustomizePagedView.removeApps(apps);
3390 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003391 updateIconsAffectedByPackageManagerChanges();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003392 }
Joe Onoratobe386092009-11-17 17:32:16 -08003393
3394 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003395 * A number of packages were updated.
3396 */
3397 public void bindPackagesUpdated() {
3398 // update the customization drawer contents
Winson Chung5f941722010-09-28 16:36:43 -07003399 if (mCustomizePagedView != null) {
Winson Chungb3347bb2010-08-19 14:51:28 -07003400 mCustomizePagedView.update();
Winson Chung5f941722010-09-28 16:36:43 -07003401 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003402 }
3403
3404 /**
Joe Onoratobe386092009-11-17 17:32:16 -08003405 * Prints out out state for debugging.
3406 */
3407 public void dumpState() {
3408 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08003409 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08003410 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
3411 Log.d(TAG, "mRestoring=" + mRestoring);
3412 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
3413 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
3414 Log.d(TAG, "mDesktopItems.size=" + mDesktopItems.size());
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003415 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08003416 mModel.dumpState();
3417 mAllAppsGrid.dumpState();
3418 Log.d(TAG, "END launcher2 dump state");
3419 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003420}