blob: 033ccc3d443d0ce41f7982993b3c9ddb4fb55e92 [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) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001041 TextView favorite = (TextView) mInflater.inflate(layoutResId, parent, false);
1042
Patrick Dubroy9e482382010-11-01 15:16:13 -07001043 Bitmap b = info.getIcon(mIconCache);
1044
Joe Onorato0589f0f2010-02-08 13:44:00 -08001045 favorite.setCompoundDrawablesWithIntrinsicBounds(null,
Winson Chung0e41ae62010-10-27 18:10:32 -07001046 new FastBitmapDrawable(b),
Joe Onorato0589f0f2010-02-08 13:44:00 -08001047 null, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001048 favorite.setText(info.title);
1049 favorite.setTag(info);
1050 favorite.setOnClickListener(this);
1051
1052 return favorite;
1053 }
1054
1055 /**
1056 * Add an application shortcut to the workspace.
1057 *
1058 * @param data The intent describing the application.
1059 * @param cellInfo The position on screen where to create the shortcut.
1060 */
Michael Jurka0280c3b2010-09-17 15:00:07 -07001061 void completeAddApplication(Context context, Intent data, int screen,
1062 int intersectCellX, int intersectCellY) {
1063 final int[] cellXY = mTmpAddItemCellCoordinates;
1064 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1065
1066 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1067 showOutOfSpaceMessage();
1068 return;
1069 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001070
Joe Onorato0589f0f2010-02-08 13:44:00 -08001071 final ShortcutInfo info = mModel.getShortcutInfo(context.getPackageManager(),
1072 data, context);
1073
Romain Guy73b979d2009-06-09 12:57:21 -07001074 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -08001075 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001076 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001077 info.container = ItemInfo.NO_ID;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001078 mWorkspace.addApplicationShortcut(info, screen, cellXY[0], cellXY[1],
1079 isWorkspaceLocked(), mAddIntersectCellX, mAddIntersectCellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001080 } else {
1081 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001082 }
1083 }
Romain Guycbb89e42009-06-08 15:52:54 -07001084
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001085 /**
1086 * Add a shortcut to the workspace.
1087 *
1088 * @param data The intent describing the shortcut.
1089 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001090 */
Michael Jurka0280c3b2010-09-17 15:00:07 -07001091 private void completeAddShortcut(Intent data, int screen,
1092 int intersectCellX, int intersectCellY) {
1093 final int[] cellXY = mTmpAddItemCellCoordinates;
1094 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
Romain Guycbb89e42009-06-08 15:52:54 -07001095
Michael Jurka0280c3b2010-09-17 15:00:07 -07001096 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1097 showOutOfSpaceMessage();
1098 return;
1099 }
1100
1101 final ShortcutInfo info = mModel.addShortcut(
1102 this, data, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001103
1104 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001105 final View view = createShortcut(info);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001106 mWorkspace.addInScreen(view, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001107 }
1108 }
1109
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001110 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001111 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001112 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001113 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001114 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001115 */
Michael Jurka0280c3b2010-09-17 15:00:07 -07001116 private void completeAddAppWidget(int appWidgetId, int screen) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001117 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Romain Guycbb89e42009-06-08 15:52:54 -07001118
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001119 // Calculate the grid spans needed to fit this widget
Michael Jurka0280c3b2010-09-17 15:00:07 -07001120 CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1121 int[] spanXY = layout.rectToCell(appWidgetInfo.minWidth, appWidgetInfo.minHeight, null);
Romain Guycbb89e42009-06-08 15:52:54 -07001122
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001123 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001124 // We have saved the position to which the widget was dragged-- this really only matters
1125 // if we are placing widgets on a "spring-loaded" screen
Michael Jurka0280c3b2010-09-17 15:00:07 -07001126 final int[] cellXY = mTmpAddItemCellCoordinates;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001127
1128 // For now, we don't save the coordinate where we dropped the icon because we're not
1129 // supporting spring-loaded mini-screens; however, leaving the ability to directly place
1130 // a widget on the home screen in case we want to add it in the future
Winson Chung55cef262010-10-28 14:14:18 -07001131 int[] touchXY = null;
Michael Jurka9c6de3d2010-11-23 16:23:58 -08001132 if (mAddDropPosition != null && mAddDropPosition[0] > -1 && mAddDropPosition[1] > -1) {
Winson Chung55cef262010-10-28 14:14:18 -07001133 touchXY = mAddDropPosition;
1134 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001135 boolean findNearestVacantAreaFailed = false;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001136 boolean foundCellSpan = false;
1137 if (touchXY != null) {
1138 // when dragging and dropping, just find the closest free spot
1139 CellLayout screenLayout = (CellLayout) mWorkspace.getChildAt(screen);
1140 int[] result = screenLayout.findNearestVacantArea(
1141 touchXY[0], touchXY[1], spanXY[0], spanXY[1], cellXY);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001142 findNearestVacantAreaFailed = (result == null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001143 foundCellSpan = !findNearestVacantAreaFailed;
1144 } else {
Michael Jurka9c6de3d2010-11-23 16:23:58 -08001145 // if we long pressed on an empty cell to bring up a menu,
1146 // make sure we intersect the empty cell
1147 // if mAddIntersectCellX/Y are -1 (e.g. we used menu -> add) then
1148 // findCellForSpanThatIntersects will just ignore them
1149 foundCellSpan = layout.findCellForSpanThatIntersects(cellXY, spanXY[0], spanXY[1],
1150 mAddIntersectCellX, mAddIntersectCellY);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001151 }
1152
Michael Jurka0280c3b2010-09-17 15:00:07 -07001153 if (!foundCellSpan) {
Romain Guy18042c82009-11-06 11:44:55 -08001154 if (appWidgetId != -1) mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001155 showOutOfSpaceMessage();
Romain Guy18042c82009-11-06 11:44:55 -08001156 return;
1157 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001158
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001159 // Build Launcher-specific widget info and save to database
1160 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001161 launcherInfo.spanX = spanXY[0];
1162 launcherInfo.spanY = spanXY[1];
Romain Guycbb89e42009-06-08 15:52:54 -07001163
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001164 LauncherModel.addItemToDatabase(this, launcherInfo,
1165 LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001166 screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001167
1168 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001169 mDesktopItems.add(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001170
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001171 // Perform actual inflation because we're live
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001172 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001173
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001174 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001175 launcherInfo.hostView.setTag(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001176
Michael Jurka0280c3b2010-09-17 15:00:07 -07001177 mWorkspace.addInScreen(launcherInfo.hostView, screen, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001178 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001179
1180 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001181 }
1182 }
Romain Guycbb89e42009-06-08 15:52:54 -07001183
Adam Cohended9f8d2010-11-03 13:25:16 -07001184 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1185 @Override
1186 public void onReceive(Context context, Intent intent) {
1187 final String action = intent.getAction();
1188 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1189 mUserPresent = false;
1190 updateRunning();
1191 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1192 mUserPresent = true;
1193 updateRunning();
1194 }
1195 }
1196 };
1197
1198 @Override
1199 public void onAttachedToWindow() {
1200 super.onAttachedToWindow();
1201
1202 // Listen for broadcasts related to user-presence
1203 final IntentFilter filter = new IntentFilter();
1204 filter.addAction(Intent.ACTION_SCREEN_OFF);
1205 filter.addAction(Intent.ACTION_USER_PRESENT);
1206 registerReceiver(mReceiver, filter);
1207
Adam Cohend113e0c2010-11-11 10:48:05 -08001208 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001209 mVisible = true;
1210 }
1211
1212 @Override
1213 public void onDetachedFromWindow() {
1214 super.onDetachedFromWindow();
1215 mVisible = false;
1216
Adam Cohend113e0c2010-11-11 10:48:05 -08001217 if (mAttached) {
1218 unregisterReceiver(mReceiver);
1219 mAttached = false;
1220 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001221 updateRunning();
1222 }
1223
1224 public void onWindowVisibilityChanged(int visibility) {
1225 mVisible = visibility == View.VISIBLE;
1226 updateRunning();
1227 }
1228
1229 private void sendAdvanceMessage(long delay) {
1230 mHandler.removeMessages(ADVANCE_MSG);
1231 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1232 mHandler.sendMessageDelayed(msg, delay);
1233 mAutoAdvanceSentTime = System.currentTimeMillis();
1234 }
1235
1236 private void updateRunning() {
1237 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1238 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1239 mAutoAdvanceRunning = autoAdvanceRunning;
1240 if (autoAdvanceRunning) {
1241 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1242 sendAdvanceMessage(delay);
1243 } else {
1244 if (!mWidgetsToAdvance.isEmpty()) {
1245 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1246 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1247 }
1248 mHandler.removeMessages(ADVANCE_MSG);
1249 }
1250 }
1251 }
1252
1253 private final Handler mHandler = new Handler() {
1254 @Override
1255 public void handleMessage(Message msg) {
1256 if (msg.what == ADVANCE_MSG) {
1257 int i = 0;
1258 for (View key: mWidgetsToAdvance.keySet()) {
1259 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1260 final int delay = mAdvanceStagger * i;
1261 if (v instanceof Advanceable) {
1262 postDelayed(new Runnable() {
1263 public void run() {
1264 ((Advanceable) v).advance();
1265 }
1266 }, delay);
1267 }
1268 i++;
1269 }
1270 sendAdvanceMessage(mAdvanceInterval);
1271 }
1272 }
1273 };
1274
1275 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
1276 if (appWidgetInfo.autoAdvanceViewId == -1) return;
1277 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1278 if (v instanceof Advanceable) {
1279 mWidgetsToAdvance.put(hostView, appWidgetInfo);
1280 ((Advanceable) v).willBeAdvancedByHost();
1281 updateRunning();
1282 }
1283 }
1284
1285 void removeWidgetToAutoAdvance(View hostView) {
1286 if (mWidgetsToAdvance.containsKey(hostView)) {
1287 mWidgetsToAdvance.remove(hostView);
1288 updateRunning();
1289 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001290 }
1291
Joe Onorato9c1289c2009-08-17 11:03:03 -04001292 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
1293 mDesktopItems.remove(launcherInfo);
Adam Cohended9f8d2010-11-03 13:25:16 -07001294 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001295 launcherInfo.hostView = null;
1296 }
1297
Adam Cohended9f8d2010-11-03 13:25:16 -07001298 void showOutOfSpaceMessage() {
1299 Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show();
1300 }
1301
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001302 public LauncherAppWidgetHost getAppWidgetHost() {
1303 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001304 }
Romain Guycbb89e42009-06-08 15:52:54 -07001305
Winson Chunga9abd0e2010-10-27 17:18:37 -07001306 public LauncherModel getModel() {
1307 return mModel;
1308 }
1309
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001310 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001311 getWindow().closeAllPanels();
1312
1313 try {
1314 dismissDialog(DIALOG_CREATE_SHORTCUT);
1315 // Unlock the workspace if the dialog was showing
1316 } catch (Exception e) {
1317 // An exception is thrown if the dialog is not visible, which is fine
1318 }
1319
1320 try {
1321 dismissDialog(DIALOG_RENAME_FOLDER);
1322 // Unlock the workspace if the dialog was showing
1323 } catch (Exception e) {
1324 // An exception is thrown if the dialog is not visible, which is fine
1325 }
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001326
1327 // Whatever we were doing is hereby canceled.
1328 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001329 }
1330
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001331 @Override
1332 protected void onNewIntent(Intent intent) {
1333 super.onNewIntent(intent);
1334
1335 // Close the menu
1336 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001337 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001338 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001339
Joe Onorato14f122b2009-11-19 14:06:36 -08001340 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1341 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001342
Michael Jurka4cb37242010-08-09 21:05:32 -07001343 // in all these cases, only animate if we're already on home
1344 if (LauncherApplication.isScreenXLarge()) {
Michael Jurka99229f62010-09-09 11:49:32 -07001345 mWorkspace.unshrink(alreadyOnHome);
1346 }
1347 if (!mWorkspace.isDefaultPageShowing()) {
Michael Jurka4cb37242010-08-09 21:05:32 -07001348 // on the phone, we don't animate the change to the workspace if all apps is visible
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001349 mWorkspace.moveToDefaultScreen(alreadyOnHome &&
1350 (LauncherApplication.isScreenXLarge() || mState != State.ALL_APPS));
Joe Onorato3a8820b2009-11-10 15:06:42 -08001351 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001352 showWorkspace(alreadyOnHome);
Romain Guy1dd3a072009-07-16 13:21:01 -07001353
Joe Onorato3a8820b2009-11-10 15:06:42 -08001354 final View v = getWindow().peekDecorView();
1355 if (v != null && v.getWindowToken() != null) {
1356 InputMethodManager imm = (InputMethodManager)getSystemService(
1357 INPUT_METHOD_SERVICE);
1358 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001359 }
1360 }
1361 }
1362
1363 @Override
1364 protected void onRestoreInstanceState(Bundle savedInstanceState) {
1365 // Do not call super here
1366 mSavedInstanceState = savedInstanceState;
Michael Jurka946ad472010-07-09 18:05:18 -07001367
1368 if (mHomeCustomizationDrawer != null) {
1369 String cur = savedInstanceState.getString("currentTab");
1370 if (cur != null) {
1371 mHomeCustomizationDrawer.setCurrentTabByTag(cur);
1372 }
1373 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001374 }
1375
1376 @Override
1377 protected void onSaveInstanceState(Bundle outState) {
Michael Jurka0142d492010-08-25 17:46:15 -07001378 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001379
1380 final ArrayList<Folder> folders = mWorkspace.getOpenFolders();
1381 if (folders.size() > 0) {
1382 final int count = folders.size();
1383 long[] ids = new long[count];
1384 for (int i = 0; i < count; i++) {
1385 final FolderInfo info = folders.get(i).getInfo();
1386 ids[i] = info.id;
1387 }
1388 outState.putLongArray(RUNTIME_STATE_USER_FOLDERS, ids);
1389 } else {
1390 super.onSaveInstanceState(outState);
1391 }
1392
Michael Jurka883f55b2010-10-21 15:47:14 -07001393 outState.putInt(RUNTIME_STATE, mState.ordinal());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001394
Michael Jurka0280c3b2010-09-17 15:00:07 -07001395 if (mAddScreen > -1 && mWaitingForResult) {
1396 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mAddScreen);
1397 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mAddIntersectCellX);
1398 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001399 }
1400
1401 if (mFolderInfo != null && mWaitingForResult) {
1402 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1403 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1404 }
Michael Jurka946ad472010-07-09 18:05:18 -07001405
1406 if (mHomeCustomizationDrawer != null) {
1407 String currentTabTag = mHomeCustomizationDrawer.getCurrentTabTag();
1408 if (currentTabTag != null) {
1409 outState.putString("currentTab", currentTabTag);
1410 }
1411 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001412 }
1413
1414 @Override
1415 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001416 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001417
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001418 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001419 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001420 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001421 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001422 }
1423
1424 TextKeyListener.getInstance().release();
1425
Joe Onorato9c1289c2009-08-17 11:03:03 -04001426 mModel.stopLoader();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001427
Joe Onorato9c1289c2009-08-17 11:03:03 -04001428 unbindDesktopItems();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001429
1430 getContentResolver().unregisterContentObserver(mWidgetObserver);
Winson Chungaafa03c2010-06-11 17:34:16 -07001431
Patrick Dubroyab962b72010-07-26 12:10:10 -07001432 // Some launcher layouts don't have a previous and next view
1433 if (mPreviousView != null) {
1434 dismissPreview(mPreviousView);
1435 }
1436 if (mNextView != null) {
1437 dismissPreview(mNextView);
1438 }
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001439
1440 unregisterReceiver(mCloseSystemDialogsReceiver);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001441 }
1442
1443 @Override
1444 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001445 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001446 super.startActivityForResult(intent, requestCode);
1447 }
1448
1449 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001450 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001451 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001452
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001453 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001454
Karl Rosaen138a0412009-04-23 19:00:21 -07001455 if (initialQuery == null) {
1456 // Use any text typed in the launcher as the initial query
1457 initialQuery = getTypedText();
1458 clearTypedText();
1459 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001460 if (appSearchData == null) {
1461 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +00001462 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001463 }
Romain Guycbb89e42009-06-08 15:52:54 -07001464
Karl Rosaen138a0412009-04-23 19:00:21 -07001465 final SearchManager searchManager =
1466 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Karl Rosaen138a0412009-04-23 19:00:21 -07001467 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Romain Guycbb89e42009-06-08 15:52:54 -07001468 appSearchData, globalSearch);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001469 }
1470
1471 @Override
1472 public boolean onCreateOptionsMenu(Menu menu) {
Patrick Dubroy5905bca2010-09-08 22:43:38 -07001473 if (isWorkspaceLocked()) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001474 return false;
1475 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001476
1477 super.onCreateOptionsMenu(menu);
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001478
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001479 menu.add(MENU_GROUP_ADD, MENU_ADD, 0, R.string.menu_add)
1480 .setIcon(android.R.drawable.ic_menu_add)
1481 .setAlphabeticShortcut('A');
Winson Chung7ad01412010-09-27 11:33:03 -07001482 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1483 .setIcon(android.R.drawable.ic_menu_manage)
1484 .setAlphabeticShortcut('M');
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001485 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001486 .setIcon(android.R.drawable.ic_menu_gallery)
1487 .setAlphabeticShortcut('W');
1488 menu.add(0, MENU_SEARCH, 0, R.string.menu_search)
1489 .setIcon(android.R.drawable.ic_search_category_default)
1490 .setAlphabeticShortcut(SearchManager.MENU_KEY);
1491 menu.add(0, MENU_NOTIFICATIONS, 0, R.string.menu_notifications)
1492 .setIcon(com.android.internal.R.drawable.ic_menu_notifications)
1493 .setAlphabeticShortcut('N');
1494
1495 final Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
Romain Guy5a941392009-04-28 15:18:25 -07001496 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
1497 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001498
1499 menu.add(0, MENU_SETTINGS, 0, R.string.menu_settings)
1500 .setIcon(android.R.drawable.ic_menu_preferences).setAlphabeticShortcut('P')
1501 .setIntent(settings);
1502
1503 return true;
1504 }
1505
1506 @Override
1507 public boolean onPrepareOptionsMenu(Menu menu) {
1508 super.onPrepareOptionsMenu(menu);
1509
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001510 // If all apps is animating, don't show the menu, because we don't know
1511 // which one to show.
Patrick Dubroyff5f0402010-07-26 15:23:26 -07001512 if (mAllAppsGrid.isAnimating()) {
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001513 return false;
1514 }
1515
1516 // Only show the add and wallpaper options when we're not in all apps.
Patrick Dubroyff5f0402010-07-26 15:23:26 -07001517 boolean visible = !mAllAppsGrid.isVisible();
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001518 menu.setGroupVisible(MENU_GROUP_ADD, visible);
1519 menu.setGroupVisible(MENU_GROUP_WALLPAPER, visible);
1520
1521 // Disable add if the workspace is full.
1522 if (visible) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001523 CellLayout layout = (CellLayout) mWorkspace.getChildAt(mWorkspace.getCurrentPage());
1524 menu.setGroupEnabled(MENU_GROUP_ADD, layout.existsEmptyCell());
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001525 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001526
1527 return true;
1528 }
1529
1530 @Override
1531 public boolean onOptionsItemSelected(MenuItem item) {
1532 switch (item.getItemId()) {
1533 case MENU_ADD:
1534 addItems();
1535 return true;
Winson Chung7ad01412010-09-27 11:33:03 -07001536 case MENU_MANAGE_APPS:
1537 manageApps();
1538 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001539 case MENU_WALLPAPER_SETTINGS:
1540 startWallpaper();
1541 return true;
1542 case MENU_SEARCH:
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001543 onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001544 return true;
1545 case MENU_NOTIFICATIONS:
1546 showNotifications();
1547 return true;
1548 }
1549
1550 return super.onOptionsItemSelected(item);
1551 }
Romain Guycbb89e42009-06-08 15:52:54 -07001552
Karl Rosaen138a0412009-04-23 19:00:21 -07001553 /**
1554 * Indicates that we want global search for this activity by setting the globalSearch
1555 * argument for {@link #startSearch} to true.
1556 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001557
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001558 @Override
1559 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001560 startSearch(null, false, null, true);
Karl Rosaen138a0412009-04-23 19:00:21 -07001561 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001562 }
1563
Joe Onorato9c1289c2009-08-17 11:03:03 -04001564 public boolean isWorkspaceLocked() {
1565 return mWorkspaceLoading || mWaitingForResult;
1566 }
1567
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001568 private void addItems() {
Patrick Dubroy558654c2010-07-23 16:48:11 -07001569 if (LauncherApplication.isScreenXLarge()) {
1570 // Animate the widget chooser up from the bottom of the screen
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001571 if (mState != State.CUSTOMIZE) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07001572 showCustomizationDrawer(true);
Patrick Dubroy558654c2010-07-23 16:48:11 -07001573 }
1574 } else {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001575 showWorkspace(true);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001576 showAddDialog(-1, -1);
Patrick Dubroy558654c2010-07-23 16:48:11 -07001577 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001578 }
1579
Michael Jurka0280c3b2010-09-17 15:00:07 -07001580 private void resetAddInfo() {
1581 mAddScreen = -1;
1582 mAddIntersectCellX = -1;
1583 mAddIntersectCellY = -1;
1584 mAddDropPosition = null;
1585 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001586
Winson Chung55cef262010-10-28 14:14:18 -07001587 void addAppWidgetFromDrop(PendingAddWidgetInfo info, int screen, int[] position) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001588 resetAddInfo();
1589 mAddScreen = screen;
1590
1591 // only set mAddDropPosition if we dropped on home screen in "spring-loaded" manner
1592 mAddDropPosition = position;
1593
Michael Jurkaaf442092010-06-10 17:01:57 -07001594 int appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Winson Chung55cef262010-10-28 14:14:18 -07001595 AppWidgetManager.getInstance(this).bindAppWidgetId(appWidgetId, info.componentName);
1596 addAppWidgetImpl(appWidgetId, info);
Michael Jurkaaf442092010-06-10 17:01:57 -07001597 }
1598
Winson Chung7ad01412010-09-27 11:33:03 -07001599 private void manageApps() {
1600 startActivity(new Intent(android.provider.Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS));
1601 }
1602
Michael Jurkaaf442092010-06-10 17:01:57 -07001603 void addAppWidgetFromPick(Intent data) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001604 // TODO: catch bad widget exception when sent
1605 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurkaaf442092010-06-10 17:01:57 -07001606 // TODO: Is this log message meaningful?
1607 if (LOGD) Log.d(TAG, "dumping extras content=" + data.getExtras());
Winson Chung55cef262010-10-28 14:14:18 -07001608 addAppWidgetImpl(appWidgetId, null);
Michael Jurkaaf442092010-06-10 17:01:57 -07001609 }
1610
Winson Chung55cef262010-10-28 14:14:18 -07001611 void addAppWidgetImpl(int appWidgetId, PendingAddWidgetInfo info) {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001612 AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001613
Bjorn Bringert7984c942009-12-09 15:38:25 +00001614 if (appWidget.configure != null) {
1615 // Launch over to configure widget, if needed
1616 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
1617 intent.setComponent(appWidget.configure);
1618 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Winson Chung55cef262010-10-28 14:14:18 -07001619 if (info != null) {
Winson Chung68846fd2010-10-29 11:00:27 -07001620 if (info.mimeType != null && !info.mimeType.isEmpty()) {
1621 intent.putExtra(
1622 InstallWidgetReceiver.EXTRA_APPWIDGET_CONFIGURATION_DATA_MIME_TYPE,
1623 info.mimeType);
1624
1625 final String mimeType = info.mimeType;
1626 final ClipData clipData = (ClipData) info.configurationData;
1627 final ClipDescription clipDesc = clipData.getDescription();
1628 for (int i = 0; i < clipDesc.getMimeTypeCount(); ++i) {
1629 if (clipDesc.getMimeType(i).equals(mimeType)) {
1630 final ClipData.Item item = clipData.getItem(i);
1631 final CharSequence stringData = item.getText();
1632 final Uri uriData = item.getUri();
1633 final Intent intentData = item.getIntent();
1634 final String key =
1635 InstallWidgetReceiver.EXTRA_APPWIDGET_CONFIGURATION_DATA;
1636 if (uriData != null) {
1637 intent.putExtra(key, uriData);
1638 } else if (intentData != null) {
1639 intent.putExtra(key, intentData);
1640 } else if (stringData != null) {
1641 intent.putExtra(key, stringData);
1642 }
1643 break;
1644 }
1645 }
1646 }
Winson Chung55cef262010-10-28 14:14:18 -07001647 }
Bjorn Bringert7984c942009-12-09 15:38:25 +00001648
Romain Guy8e633c52010-03-04 12:51:36 -08001649 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001650 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001651 // Otherwise just add it
Michael Jurka0280c3b2010-09-17 15:00:07 -07001652 completeAddAppWidget(appWidgetId, mAddScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001653 }
1654 }
Romain Guycbb89e42009-06-08 15:52:54 -07001655
Michael Jurka0280c3b2010-09-17 15:00:07 -07001656 void processShortcutFromDrop(ComponentName componentName, int screen, int[] position) {
1657 resetAddInfo();
1658 mAddScreen = screen;
1659 mAddDropPosition = position;
1660
1661 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1662 createShortcutIntent.setComponent(componentName);
1663 processShortcut(createShortcutIntent);
1664 }
1665
Joe Onoratodeb98af2010-02-19 14:59:39 -08001666 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001667 // Handle case where user selected "Applications"
1668 String applicationName = getResources().getString(R.string.group_applications);
1669 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001670
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001671 if (applicationName != null && applicationName.equals(shortcutName)) {
1672 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1673 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001674
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001675 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1676 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07001677 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Joe Onorato4a79a042010-09-24 16:17:21 -07001678 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001679 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001680 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001681 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001682 }
1683
Winson Chung24ab2f12010-09-16 14:10:47 -07001684 void processWallpaper(Intent intent) {
1685 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1686 }
1687
Michael Jurka0280c3b2010-09-17 15:00:07 -07001688 void addLiveFolderFromDrop(ComponentName componentName, int screen, int[] position) {
1689 resetAddInfo();
1690 mAddScreen = screen;
1691 mAddDropPosition = position;
1692
1693 Intent createFolderIntent = new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER);
1694 createFolderIntent.setComponent(componentName);
1695
1696 addLiveFolder(createFolderIntent);
1697 }
1698
1699 void addLiveFolder(Intent intent) { // YYY add screen intersect etc. parameters here
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001700 // Handle case where user selected "Folder"
Jeffrey Sharkeyc4bbd0a2009-03-24 22:47:52 -07001701 String folderName = getResources().getString(R.string.group_folder);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001702 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001703
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001704 if (folderName != null && folderName.equals(shortcutName)) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001705 addFolder(mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001706 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001707 startActivityForResultSafely(intent, REQUEST_CREATE_LIVE_FOLDER);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001708 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001709 }
1710
Michael Jurka0280c3b2010-09-17 15:00:07 -07001711 void addFolder(int screen, int intersectCellX, int intersectCellY) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001712 UserFolderInfo folderInfo = new UserFolderInfo();
1713 folderInfo.title = getText(R.string.folder_name);
1714
Michael Jurka0280c3b2010-09-17 15:00:07 -07001715 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1716 final int[] cellXY = mTmpAddItemCellCoordinates;
1717 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1718 showOutOfSpaceMessage();
1719 return;
1720 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001721
1722 // Update the model
Joe Onorato9c1289c2009-08-17 11:03:03 -04001723 LauncherModel.addItemToDatabase(this, folderInfo,
1724 LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001725 screen, cellXY[0], cellXY[1], false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001726 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001727
1728 // Create the view
1729 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurkac9a96192010-11-01 11:52:08 -07001730 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()),
1731 folderInfo, mIconCache);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001732 mWorkspace.addInScreen(newFolder, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001733 }
Romain Guycbb89e42009-06-08 15:52:54 -07001734
Joe Onorato9c1289c2009-08-17 11:03:03 -04001735 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001736 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001737 }
1738
Michael Jurka28750fb2010-09-24 17:43:49 -07001739 private void completeAddLiveFolder(
1740 Intent data, int screen, int intersectCellX, int intersectCellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001741 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1742 final int[] cellXY = mTmpAddItemCellCoordinates;
1743 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1744 showOutOfSpaceMessage();
1745 return;
1746 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001747
Michael Jurka0280c3b2010-09-17 15:00:07 -07001748 final LiveFolderInfo info = addLiveFolder(this, data, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001749
1750 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001751 final View view = LiveFolderIcon.fromXml(R.layout.live_folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07001752 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001753 mWorkspace.addInScreen(view, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001754 }
1755 }
1756
1757 static LiveFolderInfo addLiveFolder(Context context, Intent data,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001758 int screen, int cellX, int cellY, boolean notify) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001759
1760 Intent baseIntent = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT);
1761 String name = data.getStringExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME);
1762
1763 Drawable icon = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001764 Intent.ShortcutIconResource iconResource = null;
1765
1766 Parcelable extra = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON);
1767 if (extra != null && extra instanceof Intent.ShortcutIconResource) {
1768 try {
1769 iconResource = (Intent.ShortcutIconResource) extra;
1770 final PackageManager packageManager = context.getPackageManager();
1771 Resources resources = packageManager.getResourcesForApplication(
1772 iconResource.packageName);
1773 final int id = resources.getIdentifier(iconResource.resourceName, null, null);
1774 icon = resources.getDrawable(id);
1775 } catch (Exception e) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001776 Log.w(TAG, "Could not load live folder icon: " + extra);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001777 }
1778 }
1779
1780 if (icon == null) {
1781 icon = context.getResources().getDrawable(R.drawable.ic_launcher_folder);
1782 }
1783
1784 final LiveFolderInfo info = new LiveFolderInfo();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001785 info.icon = Utilities.createIconBitmap(icon, context);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001786 info.title = name;
1787 info.iconResource = iconResource;
1788 info.uri = data.getData();
1789 info.baseIntent = baseIntent;
1790 info.displayMode = data.getIntExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE,
1791 LiveFolders.DISPLAY_MODE_GRID);
1792
1793 LauncherModel.addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001794 screen, cellX, cellY, notify);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001795 sFolders.put(info.id, info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001796
1797 return info;
1798 }
1799
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001800 private void showNotifications() {
1801 final StatusBarManager statusBar = (StatusBarManager) getSystemService(STATUS_BAR_SERVICE);
1802 if (statusBar != null) {
1803 statusBar.expand();
1804 }
1805 }
1806
1807 private void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001808 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001809 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001810 Intent chooser = Intent.createChooser(pickWallpaper,
1811 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001812 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1813 // Removed in Eclair MR1
1814// WallpaperManager wm = (WallpaperManager)
1815// getSystemService(Context.WALLPAPER_SERVICE);
1816// WallpaperInfo wi = wm.getWallpaperInfo();
1817// if (wi != null && wi.getSettingsActivity() != null) {
1818// LabeledIntent li = new LabeledIntent(getPackageName(),
1819// R.string.configure_wallpaper, 0);
1820// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1821// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1822// }
Mike Clerona0618e42009-10-22 13:55:21 -07001823 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001824 }
1825
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001826 /**
1827 * Registers various content observers. The current implementation registers
1828 * only a favorites observer to keep track of the favorites applications.
1829 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001830 private void registerContentObservers() {
1831 ContentResolver resolver = getContentResolver();
1832 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1833 true, mWidgetObserver);
1834 }
1835
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001836 @Override
1837 public boolean dispatchKeyEvent(KeyEvent event) {
1838 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1839 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001840 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001841 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001842 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jason Samseb5615d2009-11-30 11:50:10 -08001843 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
Joe Onoratobe386092009-11-17 17:32:16 -08001844 dumpState();
1845 return true;
1846 }
1847 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001848 }
1849 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1850 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001851 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001852 return true;
1853 }
1854 }
1855
1856 return super.dispatchKeyEvent(event);
1857 }
1858
Joe Onorato88ec0992009-11-19 13:16:06 -08001859 @Override
1860 public void onBackPressed() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001861 if (mState == State.ALL_APPS || mState == State.CUSTOMIZE) {
1862 showWorkspace(true);
Joe Onorato88ec0992009-11-19 13:16:06 -08001863 } else {
1864 closeFolder();
1865 }
Michael Jurkaaf442092010-06-10 17:01:57 -07001866 // Some launcher layouts don't have a previous and next view
1867 if (mPreviousView != null) {
1868 dismissPreview(mPreviousView);
1869 dismissPreview(mNextView);
1870 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001871 }
1872
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001873 private void closeFolder() {
1874 Folder folder = mWorkspace.getOpenFolder();
1875 if (folder != null) {
1876 closeFolder(folder);
1877 }
1878 }
1879
1880 void closeFolder(Folder folder) {
1881 folder.getInfo().opened = false;
1882 ViewGroup parent = (ViewGroup) folder.getParent();
1883 if (parent != null) {
Michael Jurkaf3ca3ab2010-10-20 17:08:24 -07001884 CellLayout cl = (CellLayout) parent;
1885 cl.removeViewWithoutMarkingCells(folder);
Joe Onoratob6341e92009-11-02 10:41:48 -05001886 if (folder instanceof DropTarget) {
1887 // Live folders aren't DropTargets.
1888 mDragController.removeDropTarget((DropTarget)folder);
1889 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001890 }
1891 folder.onClose();
1892 }
1893
1894 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001895 * Re-listen when widgets are reset.
1896 */
1897 private void onAppWidgetReset() {
1898 mAppWidgetHost.startListening();
1899 }
1900
1901 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001902 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1903 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001904 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04001905 private void unbindDesktopItems() {
1906 for (ItemInfo item: mDesktopItems) {
1907 item.unbind();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001908 }
1909 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001910
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001911 /**
1912 * Launches the intent referred by the clicked shortcut.
1913 *
1914 * @param v The view representing the clicked shortcut.
1915 */
1916 public void onClick(View v) {
1917 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001918 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001919 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08001920 final Intent intent = ((ShortcutInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001921 int[] pos = new int[2];
1922 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08001923 intent.setSourceBounds(new Rect(pos[0], pos[1],
1924 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Joe Onoratof984e852010-03-25 09:47:45 -07001925 startActivitySafely(intent, tag);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001926 } else if (tag instanceof FolderInfo) {
1927 handleFolderClick((FolderInfo) tag);
Joe Onorato7404ee42009-07-31 11:54:44 -07001928 } else if (v == mHandleView) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001929 if (mState == State.ALL_APPS) {
1930 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001931 } else {
Joe Onorato3a8820b2009-11-10 15:06:42 -08001932 showAllApps(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001933 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001934 }
1935 }
1936
Michael Jurka0e260592010-06-30 17:07:39 -07001937 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07001938 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001939 // clicking anywhere on the workspace causes the customization drawer to slide down
1940 showWorkspace(true);
Michael Jurka0e260592010-06-30 17:07:39 -07001941 return false;
1942 }
1943
Michael Jurkaaf442092010-06-10 17:01:57 -07001944 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001945 * Event handler for the search button
1946 *
1947 * @param v The view that was clicked.
1948 */
1949 public void onClickSearchButton(View v) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07001950 startSearch(null, false, null, true);
Amith Yamasani1f878a12010-11-22 14:58:22 -08001951 // Use a custom animation for launching search
1952 overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001953 }
1954
1955 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001956 * Event handler for the voice button
1957 *
1958 * @param v The view that was clicked.
1959 */
1960 public void onClickVoiceButton(View v) {
1961 startVoiceSearch();
1962 }
1963
1964 private void startVoiceSearch() {
1965 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
1966 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1967 startActivity(intent);
1968 }
1969
1970 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001971 * Event handler for the "gear" button that appears on the home screen, which
Michael Jurkaaf442092010-06-10 17:01:57 -07001972 * enters home screen customization mode.
1973 *
1974 * @param v The view that was clicked.
1975 */
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001976 public void onClickConfigureButton(View v) {
Patrick Dubroy558654c2010-07-23 16:48:11 -07001977 addItems();
Michael Jurkaaf442092010-06-10 17:01:57 -07001978 }
1979
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001980 /**
1981 * Event handler for the "grid" button that appears on the home screen, which
1982 * enters all apps mode.
1983 *
1984 * @param v The view that was clicked.
1985 */
1986 public void onClickAllAppsButton(View v) {
1987 showAllApps(true);
1988 }
1989
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001990 public void onClickAppMarketButton(View v) {
1991 if (mAppMarketIntent != null) {
1992 startActivitySafely(mAppMarketIntent, "app market");
1993 }
1994 }
1995
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001996 void startApplicationDetailsActivity(ComponentName componentName) {
1997 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001998 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
1999 Uri.fromParts("package", packageName, null));
2000 startActivity(intent);
2001 }
2002
Patrick Dubroy5539af72010-09-07 15:22:01 -07002003 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
2004 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
2005 // System applications cannot be installed. For now, show a toast explaining that.
2006 // We may give them the option of disabling apps this way.
2007 int messageId = R.string.uninstall_system_app_text;
2008 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
2009 } else {
2010 String packageName = appInfo.componentName.getPackageName();
2011 String className = appInfo.componentName.getClassName();
2012 Intent intent = new Intent(
2013 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
2014 startActivity(intent);
2015 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002016 }
2017
Joe Onoratof984e852010-03-25 09:47:45 -07002018 void startActivitySafely(Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002019 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2020 try {
2021 startActivity(intent);
2022 } catch (ActivityNotFoundException e) {
2023 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Daniel Sandlerc9b18772010-04-22 14:37:59 -04002024 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002025 } catch (SecurityException e) {
2026 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002027 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002028 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002029 "or use the exported attribute for this activity. "
2030 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002031 }
2032 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002033
Romain Guy8e633c52010-03-04 12:51:36 -08002034 void startActivityForResultSafely(Intent intent, int requestCode) {
2035 try {
2036 startActivityForResult(intent, requestCode);
2037 } catch (ActivityNotFoundException e) {
2038 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2039 } catch (SecurityException e) {
2040 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2041 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
2042 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
2043 "or use the exported attribute for this activity.", e);
2044 }
2045 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002046
2047 private void handleFolderClick(FolderInfo folderInfo) {
2048 if (!folderInfo.opened) {
2049 // Close any open folder
2050 closeFolder();
2051 // Open the requested folder
2052 openFolder(folderInfo);
2053 } else {
2054 // Find the open folder...
2055 Folder openFolder = mWorkspace.getFolderForTag(folderInfo);
2056 int folderScreen;
2057 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002058 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002059 // .. and close it
2060 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002061 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002062 // Close any folder open on the current screen
2063 closeFolder();
2064 // Pull the folder onto this screen
2065 openFolder(folderInfo);
2066 }
2067 }
2068 }
2069 }
2070
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002071 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002072 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002073 * is animated relative to the specified View. If the View is null, no animation
2074 * is played.
2075 *
2076 * @param folderInfo The FolderInfo describing the folder to open.
2077 */
Winson Chungaafa03c2010-06-11 17:34:16 -07002078 public void openFolder(FolderInfo folderInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002079 Folder openFolder;
2080
2081 if (folderInfo instanceof UserFolderInfo) {
2082 openFolder = UserFolder.fromXml(this);
2083 } else if (folderInfo instanceof LiveFolderInfo) {
Joe Onoratoa5902522009-07-30 13:37:37 -07002084 openFolder = com.android.launcher2.LiveFolder.fromXml(this, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002085 } else {
2086 return;
2087 }
2088
Joe Onorato00acb122009-08-04 16:04:30 -04002089 openFolder.setDragController(mDragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002090 openFolder.setLauncher(this);
2091
2092 openFolder.bind(folderInfo);
2093 folderInfo.opened = true;
2094
Winson Chungaafa03c2010-06-11 17:34:16 -07002095 mWorkspace.addInFullScreen(openFolder, folderInfo.screen);
2096
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002097 openFolder.onOpen();
2098 }
2099
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002100 public boolean onLongClick(View v) {
Romain Guy1fbc1c82009-11-09 20:43:08 -08002101 switch (v.getId()) {
2102 case R.id.previous_screen:
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002103 if (mState != State.ALL_APPS) {
Joe Onorato0d44e942009-11-16 18:20:51 -08002104 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2105 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Romain Guyf8e6a802009-12-07 17:48:02 -08002106 showPreviews(v);
Joe Onorato0d44e942009-11-16 18:20:51 -08002107 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002108 return true;
2109 case R.id.next_screen:
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002110 if (mState != State.ALL_APPS) {
Joe Onorato0d44e942009-11-16 18:20:51 -08002111 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2112 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Romain Guyf8e6a802009-12-07 17:48:02 -08002113 showPreviews(v);
2114 }
2115 return true;
2116 case R.id.all_apps_button:
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002117 if (mState != State.ALL_APPS) {
Romain Guyf8e6a802009-12-07 17:48:02 -08002118 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2119 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2120 showPreviews(v);
Joe Onorato0d44e942009-11-16 18:20:51 -08002121 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002122 return true;
2123 }
2124
Joe Onorato9c1289c2009-08-17 11:03:03 -04002125 if (isWorkspaceLocked()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002126 return false;
2127 }
2128
2129 if (!(v instanceof CellLayout)) {
2130 v = (View) v.getParent();
2131 }
2132
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002133
Michael Jurka0280c3b2010-09-17 15:00:07 -07002134 resetAddInfo();
2135 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002136 // This happens when long clicking an item with the dpad/trackball
Michael Jurka0280c3b2010-09-17 15:00:07 -07002137 if (longClickCellInfo == null || !longClickCellInfo.valid) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002138 return true;
2139 }
2140
Michael Jurka0280c3b2010-09-17 15:00:07 -07002141 final View itemUnderLongClick = longClickCellInfo.cell;
2142
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002143 if (mWorkspace.allowLongPress()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002144 if (itemUnderLongClick == null) {
2145 // User long pressed on empty space
2146 mWorkspace.setAllowLongPress(false);
2147 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2148 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Michael Jurka56170562010-10-05 14:14:56 -07002149 if (!LauncherApplication.isScreenXLarge()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002150 showAddDialog(longClickCellInfo.cellX, longClickCellInfo.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002151 }
2152 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002153 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002154 // User long pressed on an item
Joe Onorato0d44e942009-11-16 18:20:51 -08002155 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2156 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Michael Jurka0280c3b2010-09-17 15:00:07 -07002157 mAddIntersectCellX = longClickCellInfo.cellX;
2158 mAddIntersectCellY = longClickCellInfo.cellY;
2159 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002160 }
2161 }
2162 }
2163 return true;
2164 }
2165
Romain Guye6b8e2f2009-11-10 11:56:55 -08002166 @SuppressWarnings({"unchecked"})
Romain Guy9d31e9f2009-11-11 18:54:28 -08002167 private void dismissPreview(final View v) {
2168 final PopupWindow window = (PopupWindow) v.getTag();
Romain Guy1fbc1c82009-11-09 20:43:08 -08002169 if (window != null) {
Romain Guy9d31e9f2009-11-11 18:54:28 -08002170 window.setOnDismissListener(new PopupWindow.OnDismissListener() {
2171 public void onDismiss() {
2172 ViewGroup group = (ViewGroup) v.getTag(R.id.workspace);
2173 int count = group.getChildCount();
2174 for (int i = 0; i < count; i++) {
2175 ((ImageView) group.getChildAt(i)).setImageDrawable(null);
2176 }
Romain Guy9d31e9f2009-11-11 18:54:28 -08002177 ArrayList<Bitmap> bitmaps = (ArrayList<Bitmap>) v.getTag(R.id.icon);
2178 for (Bitmap bitmap : bitmaps) bitmap.recycle();
2179
2180 v.setTag(R.id.workspace, null);
2181 v.setTag(R.id.icon, null);
2182 window.setOnDismissListener(null);
2183 }
2184 });
Romain Guy1fbc1c82009-11-09 20:43:08 -08002185 window.dismiss();
Romain Guy1fbc1c82009-11-09 20:43:08 -08002186 }
2187 v.setTag(null);
2188 }
2189
Romain Guyf8e6a802009-12-07 17:48:02 -08002190 private void showPreviews(View anchor) {
Romain Guy9d31e9f2009-11-11 18:54:28 -08002191 showPreviews(anchor, 0, mWorkspace.getChildCount());
Romain Guy1fbc1c82009-11-09 20:43:08 -08002192 }
2193
Romain Guya6abce82009-11-10 02:54:41 -08002194 private void showPreviews(final View anchor, int start, int end) {
Romain Guyf8e6a802009-12-07 17:48:02 -08002195 final Resources resources = getResources();
2196 final Workspace workspace = mWorkspace;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002197
Romain Guya6abce82009-11-10 02:54:41 -08002198 CellLayout cell = ((CellLayout) workspace.getChildAt(start));
Winson Chungaafa03c2010-06-11 17:34:16 -07002199
Romain Guy9d31e9f2009-11-11 18:54:28 -08002200 float max = workspace.getChildCount();
Winson Chungaafa03c2010-06-11 17:34:16 -07002201
Romain Guyf8e6a802009-12-07 17:48:02 -08002202 final Rect r = new Rect();
Romain Guy9d31e9f2009-11-11 18:54:28 -08002203 resources.getDrawable(R.drawable.preview_background).getPadding(r);
Romain Guye6b8e2f2009-11-10 11:56:55 -08002204 int extraW = (int) ((r.left + r.right) * max);
2205 int extraH = r.top + r.bottom;
Romain Guya6abce82009-11-10 02:54:41 -08002206
2207 int aW = cell.getWidth() - extraW;
2208 float w = aW / max;
2209
2210 int width = cell.getWidth();
2211 int height = cell.getHeight();
2212 int x = cell.getLeftPadding();
2213 int y = cell.getTopPadding();
2214 width -= (x + cell.getRightPadding());
2215 height -= (y + cell.getBottomPadding());
2216
2217 float scale = w / width;
2218
2219 int count = end - start;
2220
2221 final float sWidth = width * scale;
2222 float sHeight = height * scale;
2223
Romain Guye6b8e2f2009-11-10 11:56:55 -08002224 LinearLayout preview = new LinearLayout(this);
Romain Guya6abce82009-11-10 02:54:41 -08002225
Romain Guye6b8e2f2009-11-10 11:56:55 -08002226 PreviewTouchHandler handler = new PreviewTouchHandler(anchor);
2227 ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>(count);
Romain Guya6abce82009-11-10 02:54:41 -08002228
2229 for (int i = start; i < end; i++) {
Romain Guye6b8e2f2009-11-10 11:56:55 -08002230 ImageView image = new ImageView(this);
Romain Guya6abce82009-11-10 02:54:41 -08002231 cell = (CellLayout) workspace.getChildAt(i);
2232
Romain Guyf8e6a802009-12-07 17:48:02 -08002233 final Bitmap bitmap = Bitmap.createBitmap((int) sWidth, (int) sHeight,
Romain Guye6b8e2f2009-11-10 11:56:55 -08002234 Bitmap.Config.ARGB_8888);
Romain Guyf8e6a802009-12-07 17:48:02 -08002235
2236 final Canvas c = new Canvas(bitmap);
Romain Guya6abce82009-11-10 02:54:41 -08002237 c.scale(scale, scale);
2238 c.translate(-cell.getLeftPadding(), -cell.getTopPadding());
Patrick Dubroy1262e362010-10-06 15:49:50 -07002239 cell.drawChildren(c);
Romain Guya6abce82009-11-10 02:54:41 -08002240
Romain Guy9d31e9f2009-11-11 18:54:28 -08002241 image.setBackgroundDrawable(resources.getDrawable(R.drawable.preview_background));
Romain Guye6b8e2f2009-11-10 11:56:55 -08002242 image.setImageBitmap(bitmap);
2243 image.setTag(i);
2244 image.setOnClickListener(handler);
Romain Guy9d31e9f2009-11-11 18:54:28 -08002245 image.setOnFocusChangeListener(handler);
2246 image.setFocusable(true);
Michael Jurka0142d492010-08-25 17:46:15 -07002247 if (i == mWorkspace.getCurrentPage()) image.requestFocus();
Romain Guye6b8e2f2009-11-10 11:56:55 -08002248
2249 preview.addView(image,
Romain Guy9d31e9f2009-11-11 18:54:28 -08002250 LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
2251
Winson Chungaafa03c2010-06-11 17:34:16 -07002252 bitmaps.add(bitmap);
Romain Guya6abce82009-11-10 02:54:41 -08002253 }
Romain Guyf8e6a802009-12-07 17:48:02 -08002254
2255 final PopupWindow p = new PopupWindow(this);
Romain Guye6b8e2f2009-11-10 11:56:55 -08002256 p.setContentView(preview);
2257 p.setWidth((int) (sWidth * count + extraW));
2258 p.setHeight((int) (sHeight + extraH));
2259 p.setAnimationStyle(R.style.AnimationPreview);
2260 p.setOutsideTouchable(true);
Romain Guy9d31e9f2009-11-11 18:54:28 -08002261 p.setFocusable(true);
Romain Guyff0c2e22009-11-10 12:09:59 -08002262 p.setBackgroundDrawable(new ColorDrawable(0));
Romain Guy9d31e9f2009-11-11 18:54:28 -08002263 p.showAsDropDown(anchor, 0, 0);
Romain Guya6abce82009-11-10 02:54:41 -08002264
Romain Guye6b8e2f2009-11-10 11:56:55 -08002265 p.setOnDismissListener(new PopupWindow.OnDismissListener() {
2266 public void onDismiss() {
2267 dismissPreview(anchor);
2268 }
2269 });
Romain Guy1fbc1c82009-11-09 20:43:08 -08002270
2271 anchor.setTag(p);
2272 anchor.setTag(R.id.workspace, preview);
Winson Chungaafa03c2010-06-11 17:34:16 -07002273 anchor.setTag(R.id.icon, bitmaps);
Romain Guy1fbc1c82009-11-09 20:43:08 -08002274 }
2275
Romain Guy9d31e9f2009-11-11 18:54:28 -08002276 class PreviewTouchHandler implements View.OnClickListener, Runnable, View.OnFocusChangeListener {
Romain Guya6abce82009-11-10 02:54:41 -08002277 private final View mAnchor;
Romain Guya6abce82009-11-10 02:54:41 -08002278
Romain Guye6b8e2f2009-11-10 11:56:55 -08002279 public PreviewTouchHandler(View anchor) {
Romain Guya6abce82009-11-10 02:54:41 -08002280 mAnchor = anchor;
Romain Guya6abce82009-11-10 02:54:41 -08002281 }
2282
2283 public void onClick(View v) {
Michael Jurka0142d492010-08-25 17:46:15 -07002284 mWorkspace.snapToPage((Integer) v.getTag());
Romain Guy9d31e9f2009-11-11 18:54:28 -08002285 v.post(this);
2286 }
2287
2288 public void run() {
Winson Chungaafa03c2010-06-11 17:34:16 -07002289 dismissPreview(mAnchor);
Romain Guy9d31e9f2009-11-11 18:54:28 -08002290 }
2291
2292 public void onFocusChange(View v, boolean hasFocus) {
2293 if (hasFocus) {
Michael Jurka0142d492010-08-25 17:46:15 -07002294 mWorkspace.snapToPage((Integer) v.getTag());
Romain Guy9d31e9f2009-11-11 18:54:28 -08002295 }
Romain Guya6abce82009-11-10 02:54:41 -08002296 }
2297 }
2298
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002299 Workspace getWorkspace() {
2300 return mWorkspace;
2301 }
2302
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002303 @Override
2304 protected Dialog onCreateDialog(int id) {
2305 switch (id) {
2306 case DIALOG_CREATE_SHORTCUT:
2307 return new CreateShortcut().createDialog();
2308 case DIALOG_RENAME_FOLDER:
2309 return new RenameFolder().createDialog();
2310 }
2311
2312 return super.onCreateDialog(id);
2313 }
2314
2315 @Override
2316 protected void onPrepareDialog(int id, Dialog dialog) {
2317 switch (id) {
2318 case DIALOG_CREATE_SHORTCUT:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002319 break;
2320 case DIALOG_RENAME_FOLDER:
Romain Guy7b4ef332009-07-14 13:58:08 -07002321 if (mFolderInfo != null) {
2322 EditText input = (EditText) dialog.findViewById(R.id.folder_name);
2323 final CharSequence text = mFolderInfo.title;
2324 input.setText(text);
2325 input.setSelection(0, text.length());
2326 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002327 break;
2328 }
2329 }
2330
2331 void showRenameDialog(FolderInfo info) {
2332 mFolderInfo = info;
2333 mWaitingForResult = true;
2334 showDialog(DIALOG_RENAME_FOLDER);
2335 }
2336
Michael Jurka0280c3b2010-09-17 15:00:07 -07002337 private void showAddDialog(int intersectX, int intersectY) {
2338 resetAddInfo();
2339 mAddIntersectCellX = intersectX;
2340 mAddIntersectCellY = intersectY;
2341 mAddScreen = mWorkspace.getCurrentPage();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002342 mWaitingForResult = true;
2343 showDialog(DIALOG_CREATE_SHORTCUT);
2344 }
2345
Joe Onoratodeb98af2010-02-19 14:59:39 -08002346 private void pickShortcut() {
Michael Jurka0e260592010-06-30 17:07:39 -07002347 // Insert extra item to handle picking application
Romain Guy73b979d2009-06-09 12:57:21 -07002348 Bundle bundle = new Bundle();
2349
2350 ArrayList<String> shortcutNames = new ArrayList<String>();
2351 shortcutNames.add(getString(R.string.group_applications));
2352 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
2353
2354 ArrayList<ShortcutIconResource> shortcutIcons = new ArrayList<ShortcutIconResource>();
2355 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
2356 R.drawable.ic_launcher_application));
2357 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
2358
2359 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2360 pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_CREATE_SHORTCUT));
Joe Onoratodeb98af2010-02-19 14:59:39 -08002361 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_shortcut));
Romain Guy73b979d2009-06-09 12:57:21 -07002362 pickIntent.putExtras(bundle);
2363
Joe Onoratodeb98af2010-02-19 14:59:39 -08002364 startActivityForResult(pickIntent, REQUEST_PICK_SHORTCUT);
Romain Guy73b979d2009-06-09 12:57:21 -07002365 }
2366
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002367 private class RenameFolder {
2368 private EditText mInput;
2369
2370 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002371 final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null);
2372 mInput = (EditText) layout.findViewById(R.id.folder_name);
2373
2374 AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
2375 builder.setIcon(0);
2376 builder.setTitle(getString(R.string.rename_folder_title));
2377 builder.setCancelable(true);
2378 builder.setOnCancelListener(new Dialog.OnCancelListener() {
2379 public void onCancel(DialogInterface dialog) {
2380 cleanup();
2381 }
2382 });
2383 builder.setNegativeButton(getString(R.string.cancel_action),
2384 new Dialog.OnClickListener() {
2385 public void onClick(DialogInterface dialog, int which) {
2386 cleanup();
2387 }
2388 }
2389 );
2390 builder.setPositiveButton(getString(R.string.rename_action),
2391 new Dialog.OnClickListener() {
2392 public void onClick(DialogInterface dialog, int which) {
2393 changeFolderName();
2394 }
2395 }
2396 );
2397 builder.setView(layout);
Romain Guy7b4ef332009-07-14 13:58:08 -07002398
2399 final AlertDialog dialog = builder.create();
2400 dialog.setOnShowListener(new DialogInterface.OnShowListener() {
2401 public void onShow(DialogInterface dialog) {
Joe Onorato7018d8e2010-04-13 20:25:47 -07002402 mWaitingForResult = true;
Joe Onoratod753b422009-11-08 13:31:11 -05002403 mInput.requestFocus();
2404 InputMethodManager inputManager = (InputMethodManager)
2405 getSystemService(Context.INPUT_METHOD_SERVICE);
2406 inputManager.showSoftInput(mInput, 0);
Romain Guy7b4ef332009-07-14 13:58:08 -07002407 }
2408 });
2409
2410 return dialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002411 }
2412
2413 private void changeFolderName() {
2414 final String name = mInput.getText().toString();
2415 if (!TextUtils.isEmpty(name)) {
2416 // Make sure we have the right folder info
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002417 mFolderInfo = sFolders.get(mFolderInfo.id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002418 mFolderInfo.title = name;
2419 LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo);
2420
Joe Onorato9c1289c2009-08-17 11:03:03 -04002421 if (mWorkspaceLoading) {
Joe Onorato7c312c12009-08-13 21:36:53 -07002422 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002423 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002424 } else {
2425 final FolderIcon folderIcon = (FolderIcon)
2426 mWorkspace.getViewForTag(mFolderInfo);
2427 if (folderIcon != null) {
2428 folderIcon.setText(name);
2429 getWorkspace().requestLayout();
2430 } else {
Joe Onorato7c312c12009-08-13 21:36:53 -07002431 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002432 mWorkspaceLoading = true;
2433 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002434 }
2435 }
2436 }
2437 cleanup();
2438 }
2439
2440 private void cleanup() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002441 dismissDialog(DIALOG_RENAME_FOLDER);
2442 mWaitingForResult = false;
2443 mFolderInfo = null;
2444 }
2445 }
2446
Daniel Sandler843e8602010-06-07 14:59:01 -04002447 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
2448 public boolean isAllAppsVisible() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002449 return mState == State.ALL_APPS;
Joe Onoratofb0ca672009-09-14 17:55:46 -04002450 }
2451
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002452 // AllAppsView.Watcher
2453 public void zoomed(float zoom) {
Michael Jurka213d9632010-07-28 11:29:25 -07002454 // In XLarge view, we zoom down the workspace below all apps so it's still visible
2455 if (zoom == 1.0f && !LauncherApplication.isScreenXLarge()) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002456 mWorkspace.setVisibility(View.GONE);
2457 }
2458 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002459
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002460 private void showToolbarButton(View button) {
2461 button.setAlpha(1.0f);
2462 button.setVisibility(View.VISIBLE);
2463 button.setFocusable(true);
2464 button.setClickable(true);
2465 }
2466
2467 private void hideToolbarButton(View button) {
2468 button.setAlpha(0.0f);
2469 // We can't set it to GONE, otherwise the RelativeLayout gets screwed up
2470 button.setVisibility(View.INVISIBLE);
2471 button.setFocusable(false);
2472 button.setClickable(false);
2473 }
2474
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002475 /**
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002476 * Helper function for showing or hiding a toolbar button, possibly animated.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002477 *
2478 * @param show If true, create an animation to the show the item. Otherwise, hide it.
2479 * @param view The toolbar button to be animated
Chet Haaseb1254a62010-09-07 13:35:00 -07002480 * @param seq A AnimatorSet that will be used to animate the transition. If null, the
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002481 * transition will not be animated.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002482 */
Chet Haaseb1254a62010-09-07 13:35:00 -07002483 private void hideOrShowToolbarButton(boolean show, final View view, AnimatorSet seq) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002484 final boolean showing = show;
2485 final boolean hiding = !show;
2486
2487 final int duration = show ?
2488 getResources().getInteger(R.integer.config_toolbarButtonFadeInTime) :
2489 getResources().getInteger(R.integer.config_toolbarButtonFadeOutTime);
2490
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002491 if (seq != null) {
Chet Haase472b2812010-10-14 07:02:04 -07002492 Animator anim = ObjectAnimator.ofFloat(view, "alpha", show ? 1.0f : 0.0f);
2493 anim.setDuration(duration);
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002494 anim.addListener(new LauncherAnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002495 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002496 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002497 if (showing) showToolbarButton(view);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002498 }
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002499 @Override
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002500 public void onAnimationEndOrCancel(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002501 if (hiding) hideToolbarButton(view);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002502 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002503 });
2504 seq.play(anim);
2505 } else {
2506 if (showing) {
2507 showToolbarButton(view);
2508 } else {
2509 hideToolbarButton(view);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002510 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002511 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002512 }
2513
2514 /**
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002515 * Show/hide the appropriate toolbar buttons for newState.
2516 * If showSeq or hideSeq is null, the transition will be done immediately (not animated).
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002517 *
2518 * @param newState The state that is being switched to
Chet Haaseb1254a62010-09-07 13:35:00 -07002519 * @param showSeq AnimatorSet in which to put "show" animations, or null.
2520 * @param hideSeq AnimatorSet in which to put "hide" animations, or null.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002521 */
Chet Haaseb1254a62010-09-07 13:35:00 -07002522 private void hideAndShowToolbarButtons(State newState, AnimatorSet showSeq, AnimatorSet hideSeq) {
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002523 final View searchButton = findViewById(R.id.search_button_cluster);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002524 final View allAppsButton = findViewById(R.id.all_apps_button);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002525 final View configureButton = findViewById(R.id.configure_button);
2526
2527 switch (newState) {
2528 case WORKSPACE:
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002529 hideOrShowToolbarButton(true, searchButton, showSeq);
2530 hideOrShowToolbarButton(true, allAppsButton, showSeq);
2531 hideOrShowToolbarButton(true, configureButton, showSeq);
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002532 mDeleteZone.setHandle(allAppsButton);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002533 break;
2534 case ALL_APPS:
Adam Lesinski6b879f02010-11-04 16:15:23 -07002535 hideOrShowToolbarButton(false, configureButton, hideSeq);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002536 hideOrShowToolbarButton(false, searchButton, hideSeq);
2537 hideOrShowToolbarButton(false, allAppsButton, hideSeq);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002538 break;
2539 case CUSTOMIZE:
Adam Lesinski6b879f02010-11-04 16:15:23 -07002540 hideOrShowToolbarButton(false, allAppsButton, hideSeq);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002541 hideOrShowToolbarButton(false, searchButton, hideSeq);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002542 hideOrShowToolbarButton(false, configureButton, hideSeq);
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002543 mDeleteZone.setHandle(allAppsButton);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002544 break;
2545 }
2546 }
2547
2548 /**
2549 * Helper method for the cameraZoomIn/cameraZoomOut animations
2550 * @param view The view being animated
2551 * @param state The state that we are moving in or out of -- either ALL_APPS or CUSTOMIZE
2552 * @param scaleFactor The scale factor used for the zoom
2553 */
2554 private void setPivotsForZoom(View view, State state, float scaleFactor) {
2555 final int height = view.getHeight();
Adam Cohen61033d32010-11-15 18:29:44 -08002556
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002557 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen61033d32010-11-15 18:29:44 -08002558 // Set pivotY so that at the starting zoom factor, the view is partially
2559 // visible. Modifying initialHeightFactor changes how much of the view is
2560 // initially showing, and hence the perceived angle from which the view enters.
2561 final float initialHeightFactor = 0.2f;
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002562 if (state == State.ALL_APPS) {
Adam Cohen61033d32010-11-15 18:29:44 -08002563 view.setPivotY((1 + initialHeightFactor) * height);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002564 } else {
Adam Cohen61033d32010-11-15 18:29:44 -08002565 view.setPivotY(-initialHeightFactor * height);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002566 }
2567 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002568
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002569 /**
2570 * Zoom the camera out from the workspace to reveal 'toView'.
2571 * Assumes that the view to show is anchored at either the very top or very bottom
2572 * of the screen.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002573 * @param toState The state to zoom out to. Must be ALL_APPS or CUSTOMIZE.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002574 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002575 private void cameraZoomOut(State toState, boolean animated) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002576 final Resources res = getResources();
2577 final int duration = res.getInteger(R.integer.config_allAppsZoomInTime);
2578 final float scale = (float) res.getInteger(R.integer.config_allAppsZoomScaleFactor);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002579 final boolean toAllApps = (toState == State.ALL_APPS);
2580 final View toView = toAllApps ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
Patrick Dubroy558654c2010-07-23 16:48:11 -07002581
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002582 setPivotsForZoom(toView, toState, scale);
2583
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002584 if (toAllApps) {
Adam Lesinski6b879f02010-11-04 16:15:23 -07002585 mWorkspace.shrinkToBottomHidden(animated);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002586 } else {
2587 mWorkspace.shrinkToTop(animated);
2588 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002589
2590 if (animated) {
Chet Haase472b2812010-10-14 07:02:04 -07002591 ValueAnimator scaleAnim = ObjectAnimator.ofPropertyValuesHolder(toView,
2592 PropertyValuesHolder.ofFloat("scaleX", scale, 1.0f),
2593 PropertyValuesHolder.ofFloat("scaleY", scale, 1.0f));
2594 scaleAnim.setDuration(duration);
Adam Cohen61033d32010-11-15 18:29:44 -08002595
2596 scaleAnim.setInterpolator(new Workspace.ZoomOutInterpolator());
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002597 scaleAnim.addListener(new LauncherAnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002598 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002599 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002600 // Prepare the position
2601 toView.setTranslationX(0.0f);
2602 toView.setTranslationY(0.0f);
2603 toView.setVisibility(View.VISIBLE);
Adam Cohen61033d32010-11-15 18:29:44 -08002604 toView.setAlpha(1.0f);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002605 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002606 @Override
2607 public void onAnimationEndOrCancel(Animator animation) {
2608 // If we don't set the final scale values here, if this animation is cancelled
2609 // it will have the wrong scale value and subsequent cameraPan animations will
2610 // not fix that
2611 toView.setScaleX(1.0f);
2612 toView.setScaleY(1.0f);
2613 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002614 });
2615
Chet Haaseb1254a62010-09-07 13:35:00 -07002616 AnimatorSet toolbarHideAnim = new AnimatorSet();
2617 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002618 hideAndShowToolbarButtons(toState, toolbarShowAnim, toolbarHideAnim);
2619
2620 // toView should appear right at the end of the workspace shrink animation
2621 final int startDelay = res.getInteger(R.integer.config_workspaceShrinkTime) - duration;
2622
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002623 if (mStateAnimation != null) mStateAnimation.cancel();
2624 mStateAnimation = new AnimatorSet();
2625 mStateAnimation.playTogether(scaleAnim, toolbarHideAnim);
2626 mStateAnimation.play(scaleAnim).after(startDelay);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002627
2628 // Show the new toolbar buttons just as the main animation is ending
2629 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002630 mStateAnimation.play(toolbarShowAnim).after(duration + startDelay - fadeInTime);
2631 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002632 } else {
2633 toView.setTranslationX(0.0f);
2634 toView.setTranslationY(0.0f);
2635 toView.setScaleX(1.0f);
2636 toView.setScaleY(1.0f);
2637 toView.setVisibility(View.VISIBLE);
2638 hideAndShowToolbarButtons(toState, null, null);
2639 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002640 }
2641
2642 /**
2643 * Zoom the camera back into the workspace, hiding 'fromView'.
2644 * This is the opposite of cameraZoomOut.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002645 * @param fromState The current state (must be ALL_APPS or CUSTOMIZE).
2646 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002647 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002648 private void cameraZoomIn(State fromState, boolean animated) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002649 Resources res = getResources();
2650 int duration = res.getInteger(R.integer.config_allAppsZoomOutTime);
2651 float scaleFactor = (float) res.getInteger(R.integer.config_allAppsZoomScaleFactor);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002652 final View fromView =
2653 (fromState == State.ALL_APPS) ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
2654
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002655 mCustomizePagedView.endChoiceMode();
2656 mAllAppsPagedView.endChoiceMode();
2657
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002658 setPivotsForZoom(fromView, fromState, scaleFactor);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002659
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002660 mWorkspace.unshrink(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002661
2662 if (animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002663 if (mStateAnimation != null) mStateAnimation.cancel();
2664 mStateAnimation = new AnimatorSet();
Chet Haase472b2812010-10-14 07:02:04 -07002665 ValueAnimator scaleAnim = ObjectAnimator.ofPropertyValuesHolder(fromView,
2666 PropertyValuesHolder.ofFloat("scaleX", scaleFactor),
2667 PropertyValuesHolder.ofFloat("scaleY", scaleFactor));
2668 scaleAnim.setDuration(duration);
Adam Cohen61033d32010-11-15 18:29:44 -08002669 scaleAnim.setInterpolator(new Workspace.ZoomInInterpolator());
2670
2671 ValueAnimator alphaAnim = ObjectAnimator.ofPropertyValuesHolder(fromView,
2672 PropertyValuesHolder.ofFloat("alpha", 1.0f, 0.0f));
2673 alphaAnim.setDuration(res.getInteger(R.integer.config_allAppsFadeOutTime));
2674 alphaAnim.addListener(new LauncherAnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002675 @Override
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002676 public void onAnimationEndOrCancel(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002677 fromView.setVisibility(View.GONE);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002678 }
2679 });
2680
Chet Haaseb1254a62010-09-07 13:35:00 -07002681 AnimatorSet toolbarHideAnim = new AnimatorSet();
2682 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002683 hideAndShowToolbarButtons(State.WORKSPACE, toolbarShowAnim, toolbarHideAnim);
2684
Adam Cohen61033d32010-11-15 18:29:44 -08002685 mStateAnimation.playTogether(scaleAnim, toolbarHideAnim, alphaAnim);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002686
2687 // Show the new toolbar buttons at the very end of the whole animation
2688 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
2689 final int unshrinkTime = res.getInteger(R.integer.config_workspaceUnshrinkTime);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002690 mStateAnimation.play(toolbarShowAnim).after(unshrinkTime - fadeInTime);
2691 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002692 } else {
2693 fromView.setVisibility(View.GONE);
2694 hideAndShowToolbarButtons(State.WORKSPACE, null, null);
2695 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002696 }
2697
2698 /**
2699 * Pan the camera in the vertical plane between 'fromView' and 'toView'.
2700 * This is the transition used on xlarge screens to go between all apps and
2701 * the home customization drawer.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002702 * @param fromState The view to pan away from. Must be ALL_APPS or CUSTOMIZE.
2703 * @param toState The view to pan into the frame. Must be ALL_APPS or CUSTOMIZE.
2704 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002705 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002706 private void cameraPan(State fromState, State toState, boolean animated) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002707 final Resources res = getResources();
2708 final int duration = res.getInteger(R.integer.config_allAppsCameraPanTime);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002709 final int workspaceHeight = mWorkspace.getHeight();
2710
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002711 final boolean fromAllApps = (fromState == State.ALL_APPS);
2712 final View fromView = fromAllApps ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
2713 final View toView = fromAllApps ? mHomeCustomizationDrawer : (View) mAllAppsGrid;
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002714
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002715 final float fromViewStartY = fromAllApps ? 0.0f : fromView.getY();
2716 final float fromViewEndY = fromAllApps ? -fromView.getHeight() * 2 : workspaceHeight * 2;
2717 final float toViewStartY = fromAllApps ? workspaceHeight * 2 : -toView.getHeight() * 2;
2718 final float toViewEndY = fromAllApps ? workspaceHeight - toView.getHeight() : 0.0f;
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002719
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002720 mCustomizePagedView.endChoiceMode();
2721 mAllAppsPagedView.endChoiceMode();
2722
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002723 if (toState == State.ALL_APPS) {
Adam Lesinski6b879f02010-11-04 16:15:23 -07002724 mWorkspace.shrinkToBottomHidden(animated);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002725 } else {
2726 mWorkspace.shrinkToTop(animated);
2727 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002728
2729 if (animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002730 if (mStateAnimation != null) mStateAnimation.cancel();
2731 mStateAnimation = new AnimatorSet();
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002732 mStateAnimation.addListener(new LauncherAnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002733 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002734 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002735 toView.setVisibility(View.VISIBLE);
2736 toView.setY(toViewStartY);
Adam Cohen61033d32010-11-15 18:29:44 -08002737 toView.setAlpha(1.0f);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002738 }
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002739 @Override
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002740 public void onAnimationEndOrCancel(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002741 fromView.setVisibility(View.GONE);
2742 }
2743 });
2744
Chet Haaseb1254a62010-09-07 13:35:00 -07002745 AnimatorSet toolbarHideAnim = new AnimatorSet();
2746 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002747 hideAndShowToolbarButtons(toState, toolbarShowAnim, toolbarHideAnim);
2748
Chet Haase472b2812010-10-14 07:02:04 -07002749 ObjectAnimator fromAnim = ObjectAnimator.ofFloat(fromView, "y",
2750 fromViewStartY, fromViewEndY);
2751 fromAnim.setDuration(duration);
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002752 ObjectAnimator toAnim = ObjectAnimator.ofPropertyValuesHolder(toView,
2753 PropertyValuesHolder.ofFloat("y", toViewStartY, toViewEndY),
2754 PropertyValuesHolder.ofFloat("scaleX", toView.getScaleX(), 1.0f),
2755 PropertyValuesHolder.ofFloat("scaleY", toView.getScaleY(), 1.0f)
2756 );
Chet Haase472b2812010-10-14 07:02:04 -07002757 fromAnim.setDuration(duration);
2758 mStateAnimation.playTogether(toolbarHideAnim, fromAnim, toAnim);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002759
2760 // Show the new toolbar buttons just as the main animation is ending
2761 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002762 mStateAnimation.play(toolbarShowAnim).after(duration - fadeInTime);
2763 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002764 } else {
2765 fromView.setY(fromViewEndY);
2766 fromView.setVisibility(View.GONE);
2767 toView.setY(toViewEndY);
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002768 toView.setScaleX(1.0f);
2769 toView.setScaleY(1.0f);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002770 toView.setVisibility(View.VISIBLE);
2771 hideAndShowToolbarButtons(toState, null, null);
2772 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002773 }
2774
2775 void showAllApps(boolean animated) {
Michael Jurka883f55b2010-10-21 15:47:14 -07002776 if (mState == State.ALL_APPS) {
Winson Chung80baf5a2010-08-09 16:03:15 -07002777 return;
Michael Jurka883f55b2010-10-21 15:47:14 -07002778 }
Winson Chung80baf5a2010-08-09 16:03:15 -07002779
Michael Jurka79212d82010-07-30 16:36:20 -07002780 if (LauncherApplication.isScreenXLarge()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002781 if (mState == State.CUSTOMIZE) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002782 cameraPan(State.CUSTOMIZE, State.ALL_APPS, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002783 } else {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002784 cameraZoomOut(State.ALL_APPS, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002785 }
Patrick Dubroy558654c2010-07-23 16:48:11 -07002786 } else {
2787 mAllAppsGrid.zoom(1.0f, animated);
2788 }
Joe Onorato3a8820b2009-11-10 15:06:42 -08002789
Romain Guyc16fea72010-03-12 17:17:56 -08002790 ((View) mAllAppsGrid).setFocusable(true);
2791 ((View) mAllAppsGrid).requestFocus();
Winson Chungaafa03c2010-06-11 17:34:16 -07002792
Joe Onorato7c312c12009-08-13 21:36:53 -07002793 // TODO: fade these two too
2794 mDeleteZone.setVisibility(View.GONE);
Adam Lesinski6b879f02010-11-04 16:15:23 -07002795
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002796 // Change the state *after* we've called all the transition code
2797 mState = State.ALL_APPS;
2798 }
2799
2800
2801 void showWorkspace(boolean animated) {
2802 showWorkspace(animated, null);
2803 }
2804
2805 void showWorkspace(boolean animated, CellLayout layout) {
Michael Jurka9c6de3d2010-11-23 16:23:58 -08002806 if (layout != null) {
2807 // always animated, but that's ok since we never specify a layout and
2808 // want no animation
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002809 mWorkspace.unshrink(layout);
2810 } else {
2811 mWorkspace.unshrink(animated);
2812 }
2813 if (mState == State.ALL_APPS) {
2814 closeAllApps(animated);
2815 } else if (mState == State.CUSTOMIZE) {
2816 hideCustomizationDrawer(animated);
2817 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07002818
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002819 // Change the state *after* we've called all the transition code
2820 mState = State.WORKSPACE;
Joe Onorato00acb122009-08-04 16:04:30 -04002821 }
2822
Joe Onoratob2061212009-11-24 16:13:54 -05002823 /**
Joe Onorato7e4ed992009-12-03 13:10:49 -08002824 * Things to test when changing this code.
Joe Onoratob2061212009-11-24 16:13:54 -05002825 * - Home from workspace
2826 * - from center screen
2827 * - from other screens
2828 * - Home from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002829 * - from center screen
2830 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002831 * - Back from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002832 * - from center screen
2833 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002834 * - Launch app from workspace and quit
2835 * - with back
2836 * - with home
2837 * - Launch app from all apps and quit
2838 * - with back
2839 * - with home
Joe Onorato7e4ed992009-12-03 13:10:49 -08002840 * - Go to a screen that's not the default, then all
2841 * apps, and launch and app, and go back
2842 * - with back
2843 * -with home
Joe Onoratob2061212009-11-24 16:13:54 -05002844 * - On workspace, long press power and go back
2845 * - with back
2846 * - with home
2847 * - On all apps, long press power and go back
2848 * - with back
2849 * - with home
2850 * - On workspace, power off
2851 * - On all apps, power off
Joe Onorato7e4ed992009-12-03 13:10:49 -08002852 * - Launch an app and turn off the screen while in that app
2853 * - Go back with home key
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002854 * - Go back with back key TODO: make this not go to workspace
Joe Onorato7e4ed992009-12-03 13:10:49 -08002855 * - From all apps
2856 * - From workspace
Joe Onoratoeffc4a82010-04-15 11:48:13 -07002857 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2858 * - From all apps
2859 * - From the center workspace
2860 * - From another workspace
Joe Onoratob2061212009-11-24 16:13:54 -05002861 */
Joe Onorato7bb17492009-09-24 17:51:01 -07002862 void closeAllApps(boolean animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002863 if (mState == State.ALL_APPS) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002864 mWorkspace.setVisibility(View.VISIBLE);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002865 if (LauncherApplication.isScreenXLarge()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002866 cameraZoomIn(State.ALL_APPS, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002867 } else {
2868 mAllAppsGrid.zoom(0.0f, animated);
2869 }
Daniel Sandler388f6792010-03-02 14:08:08 -05002870 ((View)mAllAppsGrid).setFocusable(false);
Michael Jurka0142d492010-08-25 17:46:15 -07002871 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onoratoe77c08d2009-08-01 00:01:20 -07002872 }
Joe Onorato7404ee42009-07-31 11:54:44 -07002873 }
2874
Joe Onorato7c312c12009-08-13 21:36:53 -07002875 void lockAllApps() {
2876 // TODO
2877 }
2878
2879 void unlockAllApps() {
2880 // TODO
2881 }
2882
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002883 // Show the customization drawer (only exists in x-large configuration)
2884 private void showCustomizationDrawer(boolean animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002885 if (mState == State.ALL_APPS) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002886 cameraPan(State.ALL_APPS, State.CUSTOMIZE, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002887 } else {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002888 cameraZoomOut(State.CUSTOMIZE, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002889 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002890 // Change the state *after* we've called all the transition code
2891 mState = State.CUSTOMIZE;
Patrick Dubroy558654c2010-07-23 16:48:11 -07002892 }
2893
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002894 // Hide the customization drawer (only exists in x-large configuration)
2895 void hideCustomizationDrawer(boolean animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002896 if (mState == State.CUSTOMIZE) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002897 cameraZoomIn(State.CUSTOMIZE, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002898 }
2899 }
2900
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002901 void addExternalItemToScreen(ItemInfo itemInfo, CellLayout layout) {
2902 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
2903 showOutOfSpaceMessage();
Michael Jurka213d9632010-07-28 11:29:25 -07002904 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002905 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002906
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002907 void onWorkspaceClick(CellLayout layout) {
2908 showWorkspace(true, layout);
Michael Jurka213d9632010-07-28 11:29:25 -07002909 }
2910
Michael Jurka4ef207b2010-11-29 17:05:45 -08002911 // if successful in getting icon, return it; otherwise, set button to use default drawable
2912 private Drawable updateButtonWithIconFromExternalActivity(
Michael Jurka0423dcf2010-10-05 14:56:18 -07002913 int buttonId, ComponentName activityName, int fallbackDrawableId) {
2914 ImageView button = (ImageView) findViewById(buttonId);
2915 Drawable toolbarIcon = null;
2916 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002917 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07002918 // Look for the toolbar icon specified in the activity meta-data
2919 Bundle metaData = packageManager.getActivityInfo(
2920 activityName, PackageManager.GET_META_DATA).metaData;
2921 if (metaData != null) {
2922 int iconResId = metaData.getInt(TOOLBAR_ICON_METADATA_NAME);
2923 if (iconResId != 0) {
2924 Resources res = packageManager.getResourcesForActivity(activityName);
2925 toolbarIcon = res.getDrawable(iconResId);
2926 }
2927 }
2928 } catch (NameNotFoundException e) {
2929 // Do nothing
2930 }
2931 // If we were unable to find the icon via the meta-data, use a generic one
2932 if (toolbarIcon == null) {
2933 button.setImageResource(fallbackDrawableId);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002934 return null;
Michael Jurka0423dcf2010-10-05 14:56:18 -07002935 } else {
2936 button.setImageDrawable(toolbarIcon);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002937 return toolbarIcon;
Michael Jurka0423dcf2010-10-05 14:56:18 -07002938 }
2939 }
2940
Michael Jurka4ef207b2010-11-29 17:05:45 -08002941 private void updateButtonWithDrawable(int buttonId, Drawable d) {
2942 ImageView button = (ImageView) findViewById(buttonId);
2943 button.setImageDrawable(d);
2944 }
2945
Michael Jurka0423dcf2010-10-05 14:56:18 -07002946 private void updateGlobalSearchIcon() {
2947 if (LauncherApplication.isScreenXLarge()) {
2948 final SearchManager searchManager =
2949 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2950 ComponentName activityName = searchManager.getGlobalSearchActivity();
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002951 if (activityName != null) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002952 sGlobalSearchIcon = updateButtonWithIconFromExternalActivity(
Michael Jurka0423dcf2010-10-05 14:56:18 -07002953 R.id.search_button, activityName, R.drawable.search_button_generic);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002954 } else {
2955 findViewById(R.id.search_button).setVisibility(View.GONE);
2956 }
2957 }
2958 }
2959
Michael Jurka4ef207b2010-11-29 17:05:45 -08002960 private void updateGlobalSearchIcon(Drawable d) {
2961 updateButtonWithDrawable(R.id.search_button, d);
2962 }
2963
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002964 private void updateVoiceSearchIcon() {
2965 if (LauncherApplication.isScreenXLarge()) {
2966 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2967 ComponentName activityName = intent.resolveActivity(getPackageManager());
2968 if (activityName != null) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002969 sVoiceSearchIcon = updateButtonWithIconFromExternalActivity(
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002970 R.id.voice_button, activityName, R.drawable.ic_voice_search);
2971 } else {
2972 findViewById(R.id.voice_button).setVisibility(View.GONE);
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002973 }
2974 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002975 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002976
Michael Jurka4ef207b2010-11-29 17:05:45 -08002977 private void updateVoiceSearchIcon(Drawable d) {
2978 updateButtonWithDrawable(R.id.voice_button, d);
2979 }
2980
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002981 /**
2982 * Sets the app market icon (shown when all apps is visible on x-large screens)
2983 */
2984 private void updateAppMarketIcon() {
Michael Jurka0423dcf2010-10-05 14:56:18 -07002985 if (LauncherApplication.isScreenXLarge()) {
2986 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
2987 // Find the app market activity by resolving an intent.
2988 // (If multiple app markets are installed, it will return the ResolverActivity.)
2989 ComponentName activityName = intent.resolveActivity(getPackageManager());
2990 if (activityName != null) {
2991 mAppMarketIntent = intent;
Michael Jurka4ef207b2010-11-29 17:05:45 -08002992 sAppMarketIcon = updateButtonWithIconFromExternalActivity(
Michael Jurka0423dcf2010-10-05 14:56:18 -07002993 R.id.market_button, activityName, R.drawable.app_market_generic);
2994 }
2995 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002996 }
2997
Michael Jurka4ef207b2010-11-29 17:05:45 -08002998 private void updateAppMarketIcon(Drawable d) {
2999 updateButtonWithDrawable(R.id.market_button, d);
3000 }
3001
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003002 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003003 * Displays the shortcut creation dialog and launches, if necessary, the
3004 * appropriate activity.
3005 */
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003006 private class CreateShortcut implements DialogInterface.OnClickListener,
Romain Guy7b4ef332009-07-14 13:58:08 -07003007 DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
3008 DialogInterface.OnShowListener {
3009
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003010 private AddAdapter mAdapter;
Romain Guy9ffb5432009-03-24 21:04:15 -07003011
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003012 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003013 mAdapter = new AddAdapter(Launcher.this);
Romain Guycbb89e42009-06-08 15:52:54 -07003014
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003015 final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
3016 builder.setTitle(getString(R.string.menu_item_add_item));
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003017 builder.setAdapter(mAdapter, this);
Romain Guycbb89e42009-06-08 15:52:54 -07003018
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003019 builder.setInverseBackgroundForced(true);
3020
3021 AlertDialog dialog = builder.create();
3022 dialog.setOnCancelListener(this);
Romain Guycbb89e42009-06-08 15:52:54 -07003023 dialog.setOnDismissListener(this);
Romain Guy7b4ef332009-07-14 13:58:08 -07003024 dialog.setOnShowListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003025
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003026 return dialog;
3027 }
3028
3029 public void onCancel(DialogInterface dialog) {
3030 mWaitingForResult = false;
3031 cleanup();
3032 }
3033
Romain Guycbb89e42009-06-08 15:52:54 -07003034 public void onDismiss(DialogInterface dialog) {
Romain Guycbb89e42009-06-08 15:52:54 -07003035 }
3036
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003037 private void cleanup() {
Joe Onoratocc19a532009-11-19 14:19:17 -08003038 try {
3039 dismissDialog(DIALOG_CREATE_SHORTCUT);
3040 } catch (Exception e) {
3041 // An exception is thrown if the dialog is not visible, which is fine
3042 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003043 }
3044
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003045 /**
3046 * Handle the action clicked in the "Add to home" dialog.
3047 */
3048 public void onClick(DialogInterface dialog, int which) {
3049 Resources res = getResources();
3050 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07003051
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003052 switch (which) {
3053 case AddAdapter.ITEM_SHORTCUT: {
Joe Onoratodeb98af2010-02-19 14:59:39 -08003054 pickShortcut();
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003055 break;
3056 }
Romain Guycbb89e42009-06-08 15:52:54 -07003057
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003058 case AddAdapter.ITEM_APPWIDGET: {
3059 int appWidgetId = Launcher.this.mAppWidgetHost.allocateAppWidgetId();
Romain Guycbb89e42009-06-08 15:52:54 -07003060
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003061 Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
3062 pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003063 // start the pick activity
3064 startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET);
3065 break;
3066 }
Romain Guycbb89e42009-06-08 15:52:54 -07003067
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003068 case AddAdapter.ITEM_LIVE_FOLDER: {
3069 // Insert extra item to handle inserting folder
3070 Bundle bundle = new Bundle();
Romain Guycbb89e42009-06-08 15:52:54 -07003071
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003072 ArrayList<String> shortcutNames = new ArrayList<String>();
3073 shortcutNames.add(res.getString(R.string.group_folder));
3074 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
Romain Guycbb89e42009-06-08 15:52:54 -07003075
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003076 ArrayList<ShortcutIconResource> shortcutIcons =
3077 new ArrayList<ShortcutIconResource>();
3078 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
3079 R.drawable.ic_launcher_folder));
3080 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
3081
3082 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
3083 pickIntent.putExtra(Intent.EXTRA_INTENT,
3084 new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER));
3085 pickIntent.putExtra(Intent.EXTRA_TITLE,
3086 getText(R.string.title_select_live_folder));
3087 pickIntent.putExtras(bundle);
Romain Guycbb89e42009-06-08 15:52:54 -07003088
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003089 startActivityForResult(pickIntent, REQUEST_PICK_LIVE_FOLDER);
3090 break;
3091 }
3092
3093 case AddAdapter.ITEM_WALLPAPER: {
3094 startWallpaper();
3095 break;
3096 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003097 }
3098 }
Romain Guy7b4ef332009-07-14 13:58:08 -07003099
3100 public void onShow(DialogInterface dialog) {
Winson Chungaafa03c2010-06-11 17:34:16 -07003101 mWaitingForResult = true;
Romain Guy7b4ef332009-07-14 13:58:08 -07003102 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003103 }
3104
3105 /**
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003106 * Receives notifications when applications are added/removed.
3107 */
3108 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3109 @Override
3110 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003111 closeSystemDialogs();
Joe Onoratob2061212009-11-24 16:13:54 -05003112 String reason = intent.getStringExtra("reason");
3113 if (!"homekey".equals(reason)) {
3114 boolean animate = true;
Joe Onorato34a0e1b2009-12-14 17:44:51 -08003115 if (mPaused || "lock".equals(reason)) {
Joe Onoratob2061212009-11-24 16:13:54 -05003116 animate = false;
3117 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003118 showWorkspace(animate);
Joe Onoratob2061212009-11-24 16:13:54 -05003119 }
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003120 }
3121 }
3122
3123 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003124 * Receives notifications whenever the appwidgets are reset.
3125 */
3126 private class AppWidgetResetObserver extends ContentObserver {
3127 public AppWidgetResetObserver() {
3128 super(new Handler());
3129 }
3130
3131 @Override
3132 public void onChange(boolean selfChange) {
3133 onAppWidgetReset();
3134 }
3135 }
3136
3137 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003138 * If the activity is currently paused, signal that we need to re-run the loader
3139 * in onResume.
3140 *
3141 * This needs to be called from incoming places where resources might have been loaded
3142 * while we are paused. That is becaues the Configuration might be wrong
3143 * when we're not running, and if it comes back to what it was when we
3144 * were paused, we are not restarted.
3145 *
3146 * Implementation of the method from LauncherModel.Callbacks.
3147 *
3148 * @return true if we are currently paused. The caller might be able to
3149 * skip some work in that case since we will come back again.
3150 */
3151 public boolean setLoadOnResume() {
3152 if (mPaused) {
3153 Log.i(TAG, "setLoadOnResume");
3154 mOnResumeNeedsLoad = true;
3155 return true;
3156 } else {
3157 return false;
3158 }
3159 }
3160
3161 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003162 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003163 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003164 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003165 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003166 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003167 } else {
3168 return SCREEN_COUNT / 2;
3169 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003170 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003171
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003172 void setAllAppsPagedView(PagedView view) {
3173 mAllAppsPagedView = view;
3174 }
3175
Joe Onorato9c1289c2009-08-17 11:03:03 -04003176 /**
3177 * Refreshes the shortcuts shown on the workspace.
3178 *
3179 * Implementation of the method from LauncherModel.Callbacks.
3180 */
3181 public void startBinding() {
3182 final Workspace workspace = mWorkspace;
3183 int count = workspace.getChildCount();
3184 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04003185 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Joe Onorato9c1289c2009-08-17 11:03:03 -04003186 ((ViewGroup) workspace.getChildAt(i)).removeAllViewsInLayout();
3187 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003188
Joe Onorato9c1289c2009-08-17 11:03:03 -04003189 if (DEBUG_USER_INTERFACE) {
3190 android.widget.Button finishButton = new android.widget.Button(this);
3191 finishButton.setText("Finish");
3192 workspace.addInScreen(finishButton, 1, 0, 0, 1, 1);
3193
3194 finishButton.setOnClickListener(new android.widget.Button.OnClickListener() {
3195 public void onClick(View v) {
3196 finish();
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003197 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003198 });
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003199 }
3200 }
3201
3202 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003203 * Bind the items start-end from the list.
3204 *
3205 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003206 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003207 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
3208
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003209 setLoadOnResume();
3210
Joe Onorato9c1289c2009-08-17 11:03:03 -04003211 final Workspace workspace = mWorkspace;
3212
3213 for (int i=start; i<end; i++) {
3214 final ItemInfo item = shortcuts.get(i);
3215 mDesktopItems.add(item);
3216 switch (item.itemType) {
3217 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3218 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Joe Onorato0589f0f2010-02-08 13:44:00 -08003219 final View shortcut = createShortcut((ShortcutInfo)item);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003220 workspace.addInScreen(shortcut, item.screen, item.cellX, item.cellY, 1, 1,
3221 false);
3222 break;
3223 case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER:
3224 final FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003225 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Michael Jurkac9a96192010-11-01 11:52:08 -07003226 (UserFolderInfo) item, mIconCache);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003227 workspace.addInScreen(newFolder, item.screen, item.cellX, item.cellY, 1, 1,
3228 false);
3229 break;
3230 case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER:
3231 final FolderIcon newLiveFolder = LiveFolderIcon.fromXml(
3232 R.layout.live_folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003233 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Joe Onorato9c1289c2009-08-17 11:03:03 -04003234 (LiveFolderInfo) item);
3235 workspace.addInScreen(newLiveFolder, item.screen, item.cellX, item.cellY, 1, 1,
3236 false);
3237 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003238 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003239 }
3240
Joe Onorato9c1289c2009-08-17 11:03:03 -04003241 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003242 }
3243
Joe Onorato9c1289c2009-08-17 11:03:03 -04003244 /**
3245 * Implementation of the method from LauncherModel.Callbacks.
3246 */
Joe Onoratoad72e172009-11-06 16:25:04 -05003247 public void bindFolders(HashMap<Long, FolderInfo> folders) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003248 setLoadOnResume();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003249 sFolders.clear();
3250 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003251 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003252
3253 /**
3254 * Add the views for a widget to the workspace.
3255 *
3256 * Implementation of the method from LauncherModel.Callbacks.
3257 */
3258 public void bindAppWidget(LauncherAppWidgetInfo item) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003259 setLoadOnResume();
3260
Daniel Sandler843e8602010-06-07 14:59:01 -04003261 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3262 if (DEBUG_WIDGETS) {
3263 Log.d(TAG, "bindAppWidget: " + item);
3264 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003265 final Workspace workspace = mWorkspace;
3266
3267 final int appWidgetId = item.appWidgetId;
3268 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003269 if (DEBUG_WIDGETS) {
3270 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3271 }
3272
Joe Onorato9c1289c2009-08-17 11:03:03 -04003273 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3274
Joe Onorato9c1289c2009-08-17 11:03:03 -04003275 item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
3276 item.hostView.setTag(item);
3277
3278 workspace.addInScreen(item.hostView, item.screen, item.cellX,
3279 item.cellY, item.spanX, item.spanY, false);
3280
Adam Cohended9f8d2010-11-03 13:25:16 -07003281 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3282
Joe Onorato9c1289c2009-08-17 11:03:03 -04003283 workspace.requestLayout();
3284
3285 mDesktopItems.add(item);
Daniel Sandler843e8602010-06-07 14:59:01 -04003286
3287 if (DEBUG_WIDGETS) {
3288 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3289 + (SystemClock.uptimeMillis()-start) + "ms");
3290 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003291 }
3292
3293 /**
3294 * Callback saying that there aren't any more items to bind.
3295 *
3296 * Implementation of the method from LauncherModel.Callbacks.
3297 */
3298 public void finishBindingItems() {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003299 setLoadOnResume();
3300
Joe Onorato9c1289c2009-08-17 11:03:03 -04003301 if (mSavedState != null) {
3302 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003303 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003304 }
3305
3306 final long[] userFolders = mSavedState.getLongArray(RUNTIME_STATE_USER_FOLDERS);
3307 if (userFolders != null) {
3308 for (long folderId : userFolders) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003309 final FolderInfo info = sFolders.get(folderId);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003310 if (info != null) {
3311 openFolder(info);
3312 }
3313 }
3314 final Folder openFolder = mWorkspace.getOpenFolder();
3315 if (openFolder != null) {
3316 openFolder.requestFocus();
3317 }
3318 }
3319
Joe Onorato9c1289c2009-08-17 11:03:03 -04003320 mSavedState = null;
3321 }
3322
3323 if (mSavedInstanceState != null) {
3324 super.onRestoreInstanceState(mSavedInstanceState);
3325 mSavedInstanceState = null;
3326 }
3327
Joe Onorato9c1289c2009-08-17 11:03:03 -04003328 mWorkspaceLoading = false;
3329 }
3330
3331 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003332 * Updates the icons on the launcher that are affected by changes to the package list
3333 * on the device.
3334 */
3335 private void updateIconsAffectedByPackageManagerChanges() {
3336 updateAppMarketIcon();
3337 updateGlobalSearchIcon();
3338 updateVoiceSearchIcon();
3339 }
3340
3341 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003342 * Add the icons for all apps.
3343 *
3344 * Implementation of the method from LauncherModel.Callbacks.
3345 */
3346 public void bindAllApplications(ArrayList<ApplicationInfo> apps) {
Romain Guy84f296c2009-11-04 15:00:44 -08003347 mAllAppsGrid.setApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003348 if (mCustomizePagedView != null) {
3349 mCustomizePagedView.setApps(apps);
3350 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003351 updateIconsAffectedByPackageManagerChanges();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003352 }
3353
3354 /**
3355 * A package was installed.
3356 *
3357 * Implementation of the method from LauncherModel.Callbacks.
3358 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003359 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003360 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003361 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onoratoa8138d52009-10-06 19:25:30 -07003362 mAllAppsGrid.addApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003363 if (mCustomizePagedView != null) {
3364 mCustomizePagedView.addApps(apps);
3365 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003366 updateIconsAffectedByPackageManagerChanges();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003367 }
3368
3369 /**
3370 * A package was updated.
3371 *
3372 * Implementation of the method from LauncherModel.Callbacks.
3373 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003374 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003375 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003376 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato64e6be72010-03-05 15:05:52 -05003377 mWorkspace.updateShortcuts(apps);
3378 mAllAppsGrid.updateApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003379 if (mCustomizePagedView != null) {
3380 mCustomizePagedView.updateApps(apps);
3381 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003382 updateIconsAffectedByPackageManagerChanges();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003383 }
3384
3385 /**
3386 * A package was uninstalled.
3387 *
3388 * Implementation of the method from LauncherModel.Callbacks.
3389 */
Joe Onorato36115782010-06-17 13:28:48 -04003390 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003391 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato36115782010-06-17 13:28:48 -04003392 if (permanent) {
3393 mWorkspace.removeItems(apps);
3394 }
Joe Onoratoa8138d52009-10-06 19:25:30 -07003395 mAllAppsGrid.removeApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003396 if (mCustomizePagedView != null) {
3397 mCustomizePagedView.removeApps(apps);
3398 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003399 updateIconsAffectedByPackageManagerChanges();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003400 }
Joe Onoratobe386092009-11-17 17:32:16 -08003401
3402 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003403 * A number of packages were updated.
3404 */
3405 public void bindPackagesUpdated() {
3406 // update the customization drawer contents
Winson Chung5f941722010-09-28 16:36:43 -07003407 if (mCustomizePagedView != null) {
Winson Chungb3347bb2010-08-19 14:51:28 -07003408 mCustomizePagedView.update();
Winson Chung5f941722010-09-28 16:36:43 -07003409 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003410 }
3411
3412 /**
Joe Onoratobe386092009-11-17 17:32:16 -08003413 * Prints out out state for debugging.
3414 */
3415 public void dumpState() {
3416 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08003417 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08003418 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
3419 Log.d(TAG, "mRestoring=" + mRestoring);
3420 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
3421 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
3422 Log.d(TAG, "mDesktopItems.size=" + mDesktopItems.size());
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003423 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08003424 mModel.dumpState();
3425 mAllAppsGrid.dumpState();
3426 Log.d(TAG, "END launcher2 dump state");
3427 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003428}