blob: 8a8ef595fd5c8ccd6b38df02e4d2bbfdc3478744 [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;
Adam Cohencdc30d52010-12-01 15:09:47 -080062import android.graphics.Color;
Michael Jurkaaf442092010-06-10 17:01:57 -070063import android.graphics.Rect;
Romain Guyff0c2e22009-11-10 12:09:59 -080064import android.graphics.drawable.ColorDrawable;
Michael Jurkaaf442092010-06-10 17:01:57 -070065import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040066import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070067import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080068import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020069import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080070import android.os.Handler;
Adam Cohended9f8d2010-11-03 13:25:16 -070071import android.os.Message;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080072import android.os.Parcelable;
Daniel Sandler843e8602010-06-07 14:59:01 -040073import android.os.SystemClock;
Joe Onoratobe386092009-11-17 17:32:16 -080074import android.os.SystemProperties;
Karl Rosaen138a0412009-04-23 19:00:21 -070075import android.provider.LiveFolders;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070076import android.provider.Settings;
Amith Yamasani6d7fe502010-11-16 09:05:07 -080077import android.speech.RecognizerIntent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080078import android.text.Selection;
79import android.text.SpannableStringBuilder;
80import android.text.TextUtils;
81import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070082import android.util.Log;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080083import android.view.Display;
Joe Onorato0d44e942009-11-16 18:20:51 -080084import android.view.HapticFeedbackConstants;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080085import android.view.KeyEvent;
86import android.view.LayoutInflater;
87import android.view.Menu;
88import android.view.MenuItem;
Michael Jurka0e260592010-06-30 17:07:39 -070089import android.view.MotionEvent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080090import android.view.View;
91import android.view.ViewGroup;
Winson Chungaafa03c2010-06-11 17:34:16 -070092import android.view.WindowManager;
Adam Cohended9f8d2010-11-03 13:25:16 -070093import android.view.View.OnLongClickListener;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080094import android.view.inputmethod.InputMethodManager;
Adam Cohended9f8d2010-11-03 13:25:16 -070095import android.widget.Advanceable;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080096import android.widget.EditText;
Michael Jurkaaf442092010-06-10 17:01:57 -070097import android.widget.ImageView;
98import android.widget.LinearLayout;
99import android.widget.PopupWindow;
Michael Jurka0e260592010-06-30 17:07:39 -0700100import android.widget.TabHost;
Winson Chung49767ae2010-11-29 14:48:30 -0800101import android.widget.TabWidget;
Winson Chung68846fd2010-10-29 11:00:27 -0700102import android.widget.TextView;
103import android.widget.Toast;
Adam Cohended9f8d2010-11-03 13:25:16 -0700104import android.widget.TabHost.OnTabChangeListener;
105import android.widget.TabHost.TabContentFactory;
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700106
Winson Chung68846fd2010-10-29 11:00:27 -0700107import com.android.common.Search;
108import com.android.launcher.R;
Romain Guyedcce092010-03-04 13:03:17 -0800109
Adam Cohended9f8d2010-11-03 13:25:16 -0700110
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800111/**
112 * Default launcher application.
113 */
Michael Jurka946ad472010-07-09 18:05:18 -0700114public final class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700115 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
116 AllAppsView.Watcher, View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800117 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700118 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800119
Joe Onorato9c1289c2009-08-17 11:03:03 -0400120 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400121 static final boolean DEBUG_WIDGETS = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400122 static final boolean DEBUG_USER_INTERFACE = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700123
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800124 private static final int MENU_GROUP_ADD = 1;
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800125 private static final int MENU_GROUP_WALLPAPER = MENU_GROUP_ADD + 1;
126
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800127 private static final int MENU_ADD = Menu.FIRST + 1;
Winson Chung7ad01412010-09-27 11:33:03 -0700128 private static final int MENU_MANAGE_APPS = MENU_ADD + 1;
129 private static final int MENU_WALLPAPER_SETTINGS = MENU_MANAGE_APPS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800130 private static final int MENU_SEARCH = MENU_WALLPAPER_SETTINGS + 1;
131 private static final int MENU_NOTIFICATIONS = MENU_SEARCH + 1;
Romain Guy94dabf12009-07-21 10:55:43 -0700132 private static final int MENU_SETTINGS = MENU_NOTIFICATIONS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800133
134 private static final int REQUEST_CREATE_SHORTCUT = 1;
135 private static final int REQUEST_CREATE_LIVE_FOLDER = 4;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700136 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800137 private static final int REQUEST_PICK_APPLICATION = 6;
138 private static final int REQUEST_PICK_SHORTCUT = 7;
139 private static final int REQUEST_PICK_LIVE_FOLDER = 8;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700140 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700141 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800142
143 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
144
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800145 static final int SCREEN_COUNT = 5;
146 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800147
Joe Onorato7c312c12009-08-13 21:36:53 -0700148 static final int DIALOG_CREATE_SHORTCUT = 1;
149 static final int DIALOG_RENAME_FOLDER = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800150
Romain Guy98d01652009-06-30 16:21:04 -0700151 private static final String PREFERENCES = "launcher.preferences";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800152
153 // Type: int
154 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
Michael Jurka883f55b2010-10-21 15:47:14 -0700155 // Type: int
156 private static final String RUNTIME_STATE = "launcher.state";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800157 // Type: long
158 private static final String RUNTIME_STATE_USER_FOLDERS = "launcher.user_folder";
159 // Type: int
160 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
161 // Type: int
162 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cellX";
163 // Type: int
164 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cellY";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800165 // Type: boolean
166 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
167 // Type: long
168 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
169
Winson Chung80baf5a2010-08-09 16:03:15 -0700170 // tags for the customization tabs
171 private static final String WIDGETS_TAG = "widgets";
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700172 private static final String APPLICATIONS_TAG = "applications";
Winson Chung80baf5a2010-08-09 16:03:15 -0700173 private static final String SHORTCUTS_TAG = "shortcuts";
174 private static final String WALLPAPERS_TAG = "wallpapers";
175
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700176 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
177
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700178 /** The different states that Launcher can be in. */
179 private enum State { WORKSPACE, ALL_APPS, CUSTOMIZE, OVERVIEW };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700180 private State mState = State.WORKSPACE;
181 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700182
Joe Onorato9c1289c2009-08-17 11:03:03 -0400183 static final int APPWIDGET_HOST_ID = 1024;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800184
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800185 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800186 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800187
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800188 private final BroadcastReceiver mCloseSystemDialogsReceiver
189 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800190 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
191
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800192 private LayoutInflater mInflater;
193
Joe Onorato00acb122009-08-04 16:04:30 -0400194 private DragController mDragController;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800195 private Workspace mWorkspace;
Romain Guycbb89e42009-06-08 15:52:54 -0700196
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700197 private AppWidgetManager mAppWidgetManager;
198 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700199
Michael Jurka0280c3b2010-09-17 15:00:07 -0700200 private int mAddScreen = -1;
201 private int mAddIntersectCellX = -1;
202 private int mAddIntersectCellY = -1;
203 private int[] mAddDropPosition;
204 private int[] mTmpAddItemCellCoordinates = new int[2];
205
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800206 private FolderInfo mFolderInfo;
207
Joe Onorato7c312c12009-08-13 21:36:53 -0700208 private DeleteZone mDeleteZone;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700209 private HandleView mHandleView;
Joe Onorato7c312c12009-08-13 21:36:53 -0700210 private AllAppsView mAllAppsGrid;
Michael Jurka0e260592010-06-30 17:07:39 -0700211 private TabHost mHomeCustomizationDrawer;
Adam Cohended9f8d2010-11-03 13:25:16 -0700212 private boolean mAutoAdvanceRunning = false;
Patrick Dubroy2b9ff372010-09-07 17:49:27 -0700213
214 private PagedView mAllAppsPagedView = null;
215 private CustomizePagedView mCustomizePagedView = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800216
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800217 private Bundle mSavedState;
218
219 private SpannableStringBuilder mDefaultKeySsb = null;
220
Joe Onorato9c1289c2009-08-17 11:03:03 -0400221 private boolean mWorkspaceLoading = true;
222
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800223 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800224 private boolean mRestoring;
225 private boolean mWaitingForResult;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700226 private boolean mOnResumeNeedsLoad;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800227
228 private Bundle mSavedInstanceState;
229
Joe Onorato9c1289c2009-08-17 11:03:03 -0400230 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800231 private IconCache mIconCache;
Adam Cohend113e0c2010-11-11 10:48:05 -0800232 private boolean mUserPresent = true;
233 private boolean mVisible = false;
234 private boolean mAttached = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400235
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700236 private static LocaleConfiguration sLocaleConfiguration = null;
237
Romain Guy84f296c2009-11-04 15:00:44 -0800238 private ArrayList<ItemInfo> mDesktopItems = new ArrayList<ItemInfo>();
Adam Cohended9f8d2010-11-03 13:25:16 -0700239
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700240 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700241
Romain Guy1fbc1c82009-11-09 20:43:08 -0800242 private ImageView mPreviousView;
243 private ImageView mNextView;
Joe Onorato080d9b62009-11-02 12:01:11 -0500244
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400245 // Hotseats (quick-launch icons next to AllApps)
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400246 private String[] mHotseatConfig = null;
247 private Intent[] mHotseats = null;
248 private Drawable[] mHotseatIcons = null;
249 private CharSequence[] mHotseatLabels = null;
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400250
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700251 private Intent mAppMarketIntent = null;
252
Adam Cohended9f8d2010-11-03 13:25:16 -0700253 // Related to the auto-advancing of widgets
254 private final int ADVANCE_MSG = 1;
255 private final int mAdvanceInterval = 20000;
256 private final int mAdvanceStagger = 250;
257 private long mAutoAdvanceSentTime;
258 private long mAutoAdvanceTimeLeft = -1;
259 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
260 new HashMap<View, AppWidgetProviderInfo>();
261
Michael Jurka4ef207b2010-11-29 17:05:45 -0800262 // External icons saved in case of resource changes, orientation, etc.
263 private static Drawable sGlobalSearchIcon;
264 private static Drawable sVoiceSearchIcon;
265 private static Drawable sAppMarketIcon;
266
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800267 @Override
268 protected void onCreate(Bundle savedInstanceState) {
269 super.onCreate(savedInstanceState);
Romain Guyb1b69f52009-08-10 15:10:15 -0700270
Winson Chungaafa03c2010-06-11 17:34:16 -0700271 if (LauncherApplication.isInPlaceRotationEnabled()) {
272 // hide the status bar (temporary until we get the status bar design figured out)
273 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
274 this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
275 }
276
Joe Onorato0589f0f2010-02-08 13:44:00 -0800277 LauncherApplication app = ((LauncherApplication)getApplication());
278 mModel = app.setLauncher(this);
279 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400280 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800281 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700282
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700283 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700284 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
285 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700286
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800287 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200288 android.os.Debug.startMethodTracing(
289 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800290 }
291
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400292 loadHotseats();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800293 checkForLocaleChange();
294 setWallpaperDimension();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800295 setContentView(R.layout.launcher);
Michael Jurka946ad472010-07-09 18:05:18 -0700296 mHomeCustomizationDrawer = (TabHost) findViewById(com.android.internal.R.id.tabhost);
297 if (mHomeCustomizationDrawer != null) {
298 mHomeCustomizationDrawer.setup();
Winson Chungaafa03c2010-06-11 17:34:16 -0700299
Winson Chung80baf5a2010-08-09 16:03:15 -0700300 // share the same customization workspace across all the tabs
Winson Chunge3193b92010-09-10 11:44:42 -0700301 mCustomizePagedView = (CustomizePagedView) mInflater.inflate(
302 R.layout.customization_drawer, mHomeCustomizationDrawer, false);
Winson Chung80baf5a2010-08-09 16:03:15 -0700303 TabContentFactory contentFactory = new TabContentFactory() {
304 public View createTabContent(String tag) {
305 return mCustomizePagedView;
306 }
307 };
308
Winson Chung49767ae2010-11-29 14:48:30 -0800309
310 TextView tabView;
311 TabWidget tabWidget = (TabWidget)
312 mHomeCustomizationDrawer.findViewById(com.android.internal.R.id.tabs);
313
314 tabView = (TextView) mInflater.inflate(R.layout.tab_widget_indicator, tabWidget, false);
315 tabView.setText(getString(R.string.widgets_tab_label));
Winson Chung80baf5a2010-08-09 16:03:15 -0700316 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(WIDGETS_TAG)
Winson Chung49767ae2010-11-29 14:48:30 -0800317 .setIndicator(tabView).setContent(contentFactory));
318 tabView = (TextView) mInflater.inflate(R.layout.tab_widget_indicator, tabWidget, false);
319 tabView.setText(getString(R.string.applications_tab_label));
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700320 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(APPLICATIONS_TAG)
Winson Chung49767ae2010-11-29 14:48:30 -0800321 .setIndicator(tabView).setContent(contentFactory));
322 tabView = (TextView) mInflater.inflate(R.layout.tab_widget_indicator, tabWidget, false);
323 tabView.setText(getString(R.string.wallpapers_tab_label));
Winson Chung80baf5a2010-08-09 16:03:15 -0700324 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(WALLPAPERS_TAG)
Winson Chung49767ae2010-11-29 14:48:30 -0800325 .setIndicator(tabView).setContent(contentFactory));
326 tabView = (TextView) mInflater.inflate(R.layout.tab_widget_indicator, tabWidget, false);
327 tabView.setText(getString(R.string.shortcuts_tab_label));
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700328 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(SHORTCUTS_TAG)
Winson Chung49767ae2010-11-29 14:48:30 -0800329 .setIndicator(tabView).setContent(contentFactory));
Winson Chung80baf5a2010-08-09 16:03:15 -0700330 mHomeCustomizationDrawer.setOnTabChangedListener(new OnTabChangeListener() {
331 public void onTabChanged(String tabId) {
332 // animate the changing of the tab content by fading pages in and out
Winson Chungbbc60d82010-11-11 16:34:41 -0800333 final Resources res = getResources();
334 final int duration = res.getInteger(R.integer.config_tabTransitionTime);
Winson Chung80baf5a2010-08-09 16:03:15 -0700335 final float alpha = mCustomizePagedView.getAlpha();
Chet Haase472b2812010-10-14 07:02:04 -0700336 ValueAnimator alphaAnim = ObjectAnimator.ofFloat(mCustomizePagedView,
Winson Chung80baf5a2010-08-09 16:03:15 -0700337 "alpha", alpha, 0.0f);
Chet Haase472b2812010-10-14 07:02:04 -0700338 alphaAnim.setDuration(duration);
Michael Jurka3c4c20f2010-10-28 15:36:06 -0700339 alphaAnim.addListener(new LauncherAnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700340 @Override
Michael Jurka3c4c20f2010-10-28 15:36:06 -0700341 public void onAnimationEndOrCancel(Animator animation) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700342 String tag = mHomeCustomizationDrawer.getCurrentTabTag();
343 if (tag == WIDGETS_TAG) {
344 mCustomizePagedView.setCustomizationFilter(
345 CustomizePagedView.CustomizationType.WidgetCustomization);
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700346 } else if (tag == APPLICATIONS_TAG) {
347 mCustomizePagedView.setCustomizationFilter(
348 CustomizePagedView.CustomizationType.ApplicationCustomization);
Winson Chung80baf5a2010-08-09 16:03:15 -0700349 } else if (tag == WALLPAPERS_TAG) {
350 mCustomizePagedView.setCustomizationFilter(
351 CustomizePagedView.CustomizationType.WallpaperCustomization);
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700352 } else if (tag == SHORTCUTS_TAG) {
353 mCustomizePagedView.setCustomizationFilter(
354 CustomizePagedView.CustomizationType.ShortcutCustomization);
Winson Chung80baf5a2010-08-09 16:03:15 -0700355 }
356
357 final float alpha = mCustomizePagedView.getAlpha();
Chet Haase472b2812010-10-14 07:02:04 -0700358 ValueAnimator alphaAnim = ObjectAnimator.ofFloat(
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700359 mCustomizePagedView, "alpha", alpha, 1.0f);
Chet Haase472b2812010-10-14 07:02:04 -0700360 alphaAnim.setDuration(duration);
Winson Chung80baf5a2010-08-09 16:03:15 -0700361 alphaAnim.start();
362 }
363 });
364 alphaAnim.start();
365 }
366 });
Michael Jurka946ad472010-07-09 18:05:18 -0700367 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800368 setupViews();
369
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800370 registerContentObservers();
371
Joe Onorato7c312c12009-08-13 21:36:53 -0700372 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700373
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800374 mSavedState = savedInstanceState;
375 restoreState(mSavedState);
376
377 if (PROFILE_STARTUP) {
378 android.os.Debug.stopMethodTracing();
379 }
380
381 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400382 mModel.startLoader(this, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800383 }
384
385 // For handling default keys
386 mDefaultKeySsb = new SpannableStringBuilder();
387 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800388
389 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
390 registerReceiver(mCloseSystemDialogsReceiver, filter);
Michael Jurka4ef207b2010-11-29 17:05:45 -0800391
392 // If we have a saved version of these external icons, we load them up immediately
393 if (LauncherApplication.isScreenXLarge()) {
394 if (sGlobalSearchIcon != null) {
395 updateGlobalSearchIcon(sGlobalSearchIcon);
396 }
397 if (sVoiceSearchIcon != null) {
398 updateVoiceSearchIcon(sVoiceSearchIcon);
399 }
400 if (sAppMarketIcon != null) {
401 updateAppMarketIcon(sAppMarketIcon);
402 }
403 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800404 }
Romain Guycbb89e42009-06-08 15:52:54 -0700405
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800406 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700407 if (sLocaleConfiguration == null) {
408 new AsyncTask<Void, Void, LocaleConfiguration>() {
409 @Override
410 protected LocaleConfiguration doInBackground(Void... unused) {
411 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
412 readConfiguration(Launcher.this, localeConfiguration);
413 return localeConfiguration;
414 }
415
416 @Override
417 protected void onPostExecute(LocaleConfiguration result) {
418 sLocaleConfiguration = result;
419 checkForLocaleChange(); // recursive, but now with a locale configuration
420 }
421 }.execute();
422 return;
423 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700424
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800425 final Configuration configuration = getResources().getConfiguration();
426
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700427 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800428 final String locale = configuration.locale.toString();
429
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700430 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800431 final int mcc = configuration.mcc;
432
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700433 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800434 final int mnc = configuration.mnc;
435
Romain Guy84f296c2009-11-04 15:00:44 -0800436 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800437
Romain Guy84f296c2009-11-04 15:00:44 -0800438 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700439 sLocaleConfiguration.locale = locale;
440 sLocaleConfiguration.mcc = mcc;
441 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700442
Joe Onorato0589f0f2010-02-08 13:44:00 -0800443 mIconCache.flush();
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400444 loadHotseats();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700445
446 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
447 new Thread("WriteLocaleConfiguration") {
Gilles Debunnedd6c9922010-10-25 11:23:41 -0700448 @Override
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700449 public void run() {
450 writeConfiguration(Launcher.this, localeConfiguration);
451 }
452 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700453 }
454 }
455
456 private static class LocaleConfiguration {
457 public String locale;
458 public int mcc = -1;
459 public int mnc = -1;
460 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700461
Romain Guy98d01652009-06-30 16:21:04 -0700462 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
463 DataInputStream in = null;
464 try {
465 in = new DataInputStream(context.openFileInput(PREFERENCES));
466 configuration.locale = in.readUTF();
467 configuration.mcc = in.readInt();
468 configuration.mnc = in.readInt();
469 } catch (FileNotFoundException e) {
470 // Ignore
471 } catch (IOException e) {
472 // Ignore
473 } finally {
474 if (in != null) {
475 try {
476 in.close();
477 } catch (IOException e) {
478 // Ignore
479 }
480 }
481 }
482 }
483
484 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
485 DataOutputStream out = null;
486 try {
487 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
488 out.writeUTF(configuration.locale);
489 out.writeInt(configuration.mcc);
490 out.writeInt(configuration.mnc);
491 out.flush();
492 } catch (FileNotFoundException e) {
493 // Ignore
494 } catch (IOException e) {
495 //noinspection ResultOfMethodCallIgnored
496 context.getFileStreamPath(PREFERENCES).delete();
497 } finally {
498 if (out != null) {
499 try {
500 out.close();
501 } catch (IOException e) {
502 // Ignore
503 }
504 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800505 }
506 }
507
508 static int getScreen() {
509 synchronized (sLock) {
510 return sScreen;
511 }
512 }
513
514 static void setScreen(int screen) {
515 synchronized (sLock) {
516 sScreen = screen;
517 }
518 }
519
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800520 private void setWallpaperDimension() {
Dianne Hackborn107f8392009-08-05 21:32:16 -0700521 WallpaperManager wpm = (WallpaperManager)getSystemService(WALLPAPER_SERVICE);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800522
523 Display display = getWindowManager().getDefaultDisplay();
Romain Guy5bbc91b2010-08-18 11:38:46 -0700524 // TODO: Put back when we decide about scrolling the wallpaper
525 // boolean isPortrait = display.getWidth() < display.getHeight();
526 // final int width = isPortrait ? display.getWidth() : display.getHeight();
527 // final int height = isPortrait ? display.getHeight() : display.getWidth();
528 wpm.suggestDesiredDimensions(Math.max(display.getWidth(), display.getHeight()),
529 Math.max(display.getWidth(), display.getHeight()));
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800530 }
531
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400532 // Note: This doesn't do all the client-id magic that BrowserProvider does
533 // in Browser. (http://b/2425179)
534 private Uri getDefaultBrowserUri() {
535 String url = getString(R.string.default_browser_url);
536 if (url.indexOf("{CID}") != -1) {
537 url = url.replace("{CID}", "android-google");
538 }
539 return Uri.parse(url);
540 }
541
542 // Load the Intent templates from arrays.xml to populate the hotseats. For
543 // each Intent, if it resolves to a single app, use that as the launch
544 // intent & use that app's label as the contentDescription. Otherwise,
545 // retain the ResolveActivity so the user can pick an app.
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400546 private void loadHotseats() {
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400547 if (mHotseatConfig == null) {
548 mHotseatConfig = getResources().getStringArray(R.array.hotseats);
549 if (mHotseatConfig.length > 0) {
550 mHotseats = new Intent[mHotseatConfig.length];
551 mHotseatLabels = new CharSequence[mHotseatConfig.length];
552 mHotseatIcons = new Drawable[mHotseatConfig.length];
553 } else {
554 mHotseats = null;
555 mHotseatIcons = null;
556 mHotseatLabels = null;
557 }
558
559 TypedArray hotseatIconDrawables = getResources().obtainTypedArray(R.array.hotseat_icons);
560 for (int i=0; i<mHotseatConfig.length; i++) {
561 // load icon for this slot; currently unrelated to the actual activity
562 try {
563 mHotseatIcons[i] = hotseatIconDrawables.getDrawable(i);
564 } catch (ArrayIndexOutOfBoundsException ex) {
565 Log.w(TAG, "Missing hotseat_icons array item #" + i);
566 mHotseatIcons[i] = null;
567 }
568 }
569 hotseatIconDrawables.recycle();
570 }
571
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400572 PackageManager pm = getPackageManager();
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400573 for (int i=0; i<mHotseatConfig.length; i++) {
574 Intent intent = null;
575 if (mHotseatConfig[i].equals("*BROWSER*")) {
576 // magic value meaning "launch user's default web browser"
577 // replace it with a generic web request so we can see if there is indeed a default
578 String defaultUri = getString(R.string.default_browser_url);
579 intent = new Intent(
580 Intent.ACTION_VIEW,
581 ((defaultUri != null)
582 ? Uri.parse(defaultUri)
583 : getDefaultBrowserUri())
584 ).addCategory(Intent.CATEGORY_BROWSABLE);
585 // note: if the user launches this without a default set, she
586 // will always be taken to the default URL above; this is
587 // unavoidable as we must specify a valid URL in order for the
Winson Chungaafa03c2010-06-11 17:34:16 -0700588 // chooser to appear, and once the user selects something, that
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400589 // URL is unavoidably sent to the chosen app.
590 } else {
591 try {
592 intent = Intent.parseUri(mHotseatConfig[i], 0);
593 } catch (java.net.URISyntaxException ex) {
594 Log.w(TAG, "Invalid hotseat intent: " + mHotseatConfig[i]);
595 // bogus; leave intent=null
596 }
597 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700598
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400599 if (intent == null) {
600 mHotseats[i] = null;
601 mHotseatLabels[i] = getText(R.string.activity_not_found);
602 continue;
603 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400604
605 if (LOGD) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700606 Log.d(TAG, "loadHotseats: hotseat " + i
607 + " initial intent=["
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400608 + intent.toUri(Intent.URI_INTENT_SCHEME)
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400609 + "]");
610 }
611
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400612 ResolveInfo bestMatch = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
613 List<ResolveInfo> allMatches = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
Winson Chungaafa03c2010-06-11 17:34:16 -0700614 if (LOGD) {
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400615 Log.d(TAG, "Best match for intent: " + bestMatch);
616 Log.d(TAG, "All matches: ");
617 for (ResolveInfo ri : allMatches) {
618 Log.d(TAG, " --> " + ri);
619 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400620 }
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400621 // did this resolve to a single app, or the resolver?
622 if (allMatches.size() == 0 || bestMatch == null) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700623 // can't find any activity to handle this. let's leave the
624 // intent as-is and let Launcher show a toast when it fails
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400625 // to launch.
626 mHotseats[i] = intent;
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400627
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400628 // set accessibility text to "Not installed"
629 mHotseatLabels[i] = getText(R.string.activity_not_found);
630 } else {
631 boolean found = false;
632 for (ResolveInfo ri : allMatches) {
633 if (bestMatch.activityInfo.name.equals(ri.activityInfo.name)
634 && bestMatch.activityInfo.applicationInfo.packageName
635 .equals(ri.activityInfo.applicationInfo.packageName)) {
636 found = true;
637 break;
638 }
639 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700640
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400641 if (!found) {
642 if (LOGD) Log.d(TAG, "Multiple options, no default yet");
643 // the bestMatch is probably the ResolveActivity, meaning the
644 // user has not yet selected a default
645 // so: we'll keep the original intent for now
646 mHotseats[i] = intent;
647
648 // set the accessibility text to "Select shortcut"
649 mHotseatLabels[i] = getText(R.string.title_select_shortcut);
650 } else {
651 // we have an app!
652 // now reconstruct the intent to launch it through the front
653 // door
654 ComponentName com = new ComponentName(
655 bestMatch.activityInfo.applicationInfo.packageName,
656 bestMatch.activityInfo.name);
657 mHotseats[i] = new Intent(Intent.ACTION_MAIN).setComponent(com);
658
659 // load the app label for accessibility
660 mHotseatLabels[i] = bestMatch.activityInfo.loadLabel(pm);
661 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400662 }
663
664 if (LOGD) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700665 Log.d(TAG, "loadHotseats: hotseat " + i
666 + " final intent=["
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400667 + ((mHotseats[i] == null)
668 ? "null"
669 : mHotseats[i].toUri(Intent.URI_INTENT_SCHEME))
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400670 + "] label=[" + mHotseatLabels[i]
671 + "]"
672 );
673 }
674 }
675 }
676
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800677 @Override
678 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Romain Guyaad5ef42009-06-10 02:48:37 -0700679 mWaitingForResult = false;
680
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800681 // The pattern used here is that a user PICKs a specific application,
682 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700683
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800684 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
685 // launch over to the Music app to actually CREATE_SHORTCUT.
Romain Guycbb89e42009-06-08 15:52:54 -0700686
Michael Jurka0280c3b2010-09-17 15:00:07 -0700687 if (resultCode == RESULT_OK && mAddScreen != -1) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800688 switch (requestCode) {
689 case REQUEST_PICK_APPLICATION:
Michael Jurka28750fb2010-09-24 17:43:49 -0700690 completeAddApplication(
691 this, data, mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800692 break;
693 case REQUEST_PICK_SHORTCUT:
Joe Onoratodeb98af2010-02-19 14:59:39 -0800694 processShortcut(data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800695 break;
696 case REQUEST_CREATE_SHORTCUT:
Michael Jurka0280c3b2010-09-17 15:00:07 -0700697 completeAddShortcut(data, mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800698 break;
699 case REQUEST_PICK_LIVE_FOLDER:
700 addLiveFolder(data);
701 break;
702 case REQUEST_CREATE_LIVE_FOLDER:
Michael Jurka0280c3b2010-09-17 15:00:07 -0700703 completeAddLiveFolder(data, mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800704 break;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700705 case REQUEST_PICK_APPWIDGET:
Michael Jurkaaf442092010-06-10 17:01:57 -0700706 addAppWidgetFromPick(data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800707 break;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700708 case REQUEST_CREATE_APPWIDGET:
Michael Jurkaaf442092010-06-10 17:01:57 -0700709 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700710 completeAddAppWidget(appWidgetId, mAddScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800711 break;
Mike Clerona0618e42009-10-22 13:55:21 -0700712 case REQUEST_PICK_WALLPAPER:
713 // We just wanted the activity result here so we can clear mWaitingForResult
714 break;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800715 }
Romain Guy18042c82009-11-06 11:44:55 -0800716 } else if ((requestCode == REQUEST_PICK_APPWIDGET ||
717 requestCode == REQUEST_CREATE_APPWIDGET) && resultCode == RESULT_CANCELED &&
718 data != null) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700719 // Clean up the appWidgetId if we canceled
720 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
721 if (appWidgetId != -1) {
722 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800723 }
724 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800725 }
726
727 @Override
728 protected void onResume() {
729 super.onResume();
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800730 mPaused = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700731 if (mRestoring || mOnResumeNeedsLoad) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400732 mWorkspaceLoading = true;
733 mModel.startLoader(this, true);
734 mRestoring = false;
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700735 mOnResumeNeedsLoad = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800736 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700737 // When we resume Launcher, a different Activity might be responsible for the app
738 // market intent, so refresh the icon
739 updateAppMarketIcon();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800740 }
741
742 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700743 protected void onPause() {
744 super.onPause();
Michael Jurkaaf442092010-06-10 17:01:57 -0700745 // Some launcher layouts don't have a previous and next view
746 if (mPreviousView != null) {
747 dismissPreview(mPreviousView);
Patrick Dubroyab962b72010-07-26 12:10:10 -0700748 }
749 if (mNextView != null) {
Michael Jurkaaf442092010-06-10 17:01:57 -0700750 dismissPreview(mNextView);
751 }
Joe Onoratoef2efcf2010-10-27 13:21:00 -0700752 mPaused = true;
Joe Onorato24b6fd82009-11-12 13:47:09 -0800753 mDragController.cancelDrag();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700754 }
Romain Guycbb89e42009-06-08 15:52:54 -0700755
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700756 @Override
757 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400758 // Flag the loader to stop early before switching
759 mModel.stopLoader();
Romain Guy13c2e7b2010-03-10 19:45:00 -0800760 mAllAppsGrid.surrender();
Romain Guy13c2e7b2010-03-10 19:45:00 -0800761 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700762 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700763
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800764 // We can't hide the IME if it was forced open. So don't bother
765 /*
766 @Override
767 public void onWindowFocusChanged(boolean hasFocus) {
768 super.onWindowFocusChanged(hasFocus);
769
770 if (hasFocus) {
771 final InputMethodManager inputManager = (InputMethodManager)
772 getSystemService(Context.INPUT_METHOD_SERVICE);
773 WindowManager.LayoutParams lp = getWindow().getAttributes();
774 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
775 android.os.Handler()) {
776 protected void onReceiveResult(int resultCode, Bundle resultData) {
777 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
778 }
779 });
780 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
781 }
782 }
783 */
784
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800785 private boolean acceptFilter() {
786 final InputMethodManager inputManager = (InputMethodManager)
787 getSystemService(Context.INPUT_METHOD_SERVICE);
788 return !inputManager.isFullscreenMode();
789 }
790
791 @Override
792 public boolean onKeyDown(int keyCode, KeyEvent event) {
793 boolean handled = super.onKeyDown(keyCode, event);
794 if (!handled && acceptFilter() && keyCode != KeyEvent.KEYCODE_ENTER) {
795 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
796 keyCode, event);
797 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700798 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700799 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700800 // showSearchDialog()
801 // If there are multiple keystrokes before the search dialog takes focus,
802 // onSearchRequested() will be called for every keystroke,
803 // but it is idempotent, so it's fine.
804 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800805 }
806 }
807
Joe Onorato8a9625e2010-01-28 15:55:35 -0800808 // Eat the long press event so the keyboard doesn't come up.
809 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
810 return true;
811 }
812
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800813 return handled;
814 }
815
Karl Rosaen138a0412009-04-23 19:00:21 -0700816 private String getTypedText() {
817 return mDefaultKeySsb.toString();
818 }
819
820 private void clearTypedText() {
821 mDefaultKeySsb.clear();
822 mDefaultKeySsb.clearSpans();
823 Selection.setSelection(mDefaultKeySsb, 0);
824 }
825
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800826 /**
Michael Jurka883f55b2010-10-21 15:47:14 -0700827 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
828 * State
829 */
830 private static State intToState(int stateOrdinal) {
831 State state = State.WORKSPACE;
832 final State[] stateValues = State.values();
833 for (int i = 0; i < stateValues.length; i++) {
834 if (stateValues[i].ordinal() == stateOrdinal) {
835 state = stateValues[i];
836 break;
837 }
838 }
839 return state;
840 }
841
842 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800843 * Restores the previous state, if it exists.
844 *
845 * @param savedState The previous state.
846 */
847 private void restoreState(Bundle savedState) {
848 if (savedState == null) {
849 return;
850 }
851
Michael Jurka883f55b2010-10-21 15:47:14 -0700852 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
853
854 if (state == State.ALL_APPS) {
Joe Onorato3a8820b2009-11-10 15:06:42 -0800855 showAllApps(false);
Michael Jurka883f55b2010-10-21 15:47:14 -0700856 } else if (state == State.CUSTOMIZE) {
857 showCustomizationDrawer(false);
Joe Onorato3a8820b2009-11-10 15:06:42 -0800858 }
859
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800860 final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
861 if (currentScreen > -1) {
Michael Jurka0142d492010-08-25 17:46:15 -0700862 mWorkspace.setCurrentPage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800863 }
864
865 final int addScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700866
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800867 if (addScreen > -1) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700868 mAddScreen = addScreen;
869 mAddIntersectCellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
870 mAddIntersectCellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800871 mRestoring = true;
872 }
873
874 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
875 if (renameFolder) {
876 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700877 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800878 mRestoring = true;
879 }
880 }
881
882 /**
883 * Finds all the views we need and configure them properly.
884 */
885 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700886 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -0400887
Romain Guyb1b69f52009-08-10 15:10:15 -0700888 DragLayer dragLayer = (DragLayer) findViewById(R.id.drag_layer);
Joe Onorato00acb122009-08-04 16:04:30 -0400889 dragLayer.setDragController(dragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800890
Joe Onorato7c312c12009-08-13 21:36:53 -0700891 mAllAppsGrid = (AllAppsView)dragLayer.findViewById(R.id.all_apps_view);
Joe Onorato6665c0f2009-09-02 15:27:24 -0700892 mAllAppsGrid.setLauncher(this);
Joe Onorato5162ea92009-09-03 09:39:42 -0700893 mAllAppsGrid.setDragController(dragController);
Romain Guyc16fea72010-03-12 17:17:56 -0800894 ((View) mAllAppsGrid).setWillNotDraw(false); // We don't want a hole punched in our window.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700895 // Manage focusability manually since this thing is always visible (in non-xlarge)
Winson Chungaafa03c2010-06-11 17:34:16 -0700896 ((View) mAllAppsGrid).setFocusable(false);
Joe Onorato7c312c12009-08-13 21:36:53 -0700897
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700898 if (LauncherApplication.isScreenXLarge()) {
899 // They need to be INVISIBLE initially so that they will be measured in the layout.
900 // Otherwise the animations are messed up when we show them for the first time.
901 ((View) mAllAppsGrid).setVisibility(View.INVISIBLE);
902 mHomeCustomizationDrawer.setVisibility(View.INVISIBLE);
903 }
904
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800905 mWorkspace = (Workspace) dragLayer.findViewById(R.id.workspace);
Adam Lesinski6b879f02010-11-04 16:15:23 -0700906
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800907 final Workspace workspace = mWorkspace;
Joe Onoratof0dde092010-02-16 18:25:23 -0500908 workspace.setHapticFeedbackEnabled(false);
Michael Jurka946ad472010-07-09 18:05:18 -0700909
Joe Onorato7c312c12009-08-13 21:36:53 -0700910 DeleteZone deleteZone = (DeleteZone) dragLayer.findViewById(R.id.delete_zone);
911 mDeleteZone = deleteZone;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800912
Michael Jurka2c3af5f2010-08-03 13:53:20 -0700913 View handleView = findViewById(R.id.all_apps_button);
914 if (handleView != null && handleView instanceof HandleView) {
915 // we don't use handle view in xlarge mode
Michael Jurka7ef4f752010-08-03 16:04:26 -0700916 mHandleView = (HandleView)handleView;
Michael Jurka2c3af5f2010-08-03 13:53:20 -0700917 mHandleView.setLauncher(this);
918 mHandleView.setOnClickListener(this);
919 mHandleView.setOnLongClickListener(this);
920 }
Romain Guy1fbc1c82009-11-09 20:43:08 -0800921
Winson Chung80baf5a2010-08-09 16:03:15 -0700922 if (mCustomizePagedView != null) {
923 mCustomizePagedView.setLauncher(this);
924 mCustomizePagedView.setDragController(dragController);
925 mCustomizePagedView.update();
Michael Jurkaaf442092010-06-10 17:01:57 -0700926 } else {
927 ImageView hotseatLeft = (ImageView) findViewById(R.id.hotseat_left);
928 hotseatLeft.setContentDescription(mHotseatLabels[0]);
929 hotseatLeft.setImageDrawable(mHotseatIcons[0]);
930 ImageView hotseatRight = (ImageView) findViewById(R.id.hotseat_right);
931 hotseatRight.setContentDescription(mHotseatLabels[1]);
932 hotseatRight.setImageDrawable(mHotseatIcons[1]);
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400933
Michael Jurkaaf442092010-06-10 17:01:57 -0700934 mPreviousView = (ImageView) dragLayer.findViewById(R.id.previous_screen);
935 mNextView = (ImageView) dragLayer.findViewById(R.id.next_screen);
Romain Guy1fbc1c82009-11-09 20:43:08 -0800936
Michael Jurkaaf442092010-06-10 17:01:57 -0700937 Drawable previous = mPreviousView.getDrawable();
938 Drawable next = mNextView.getDrawable();
939 mWorkspace.setIndicators(previous, next);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800940
Michael Jurkaaf442092010-06-10 17:01:57 -0700941 mPreviousView.setHapticFeedbackEnabled(false);
942 mPreviousView.setOnLongClickListener(this);
943 mNextView.setHapticFeedbackEnabled(false);
944 mNextView.setOnLongClickListener(this);
945 }
Romain Guy1fbc1c82009-11-09 20:43:08 -0800946
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800947 workspace.setOnLongClickListener(this);
Joe Onorato00acb122009-08-04 16:04:30 -0400948 workspace.setDragController(dragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800949 workspace.setLauncher(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800950
951 deleteZone.setLauncher(this);
Joe Onorato00acb122009-08-04 16:04:30 -0400952 deleteZone.setDragController(dragController);
Michael Jurka54f7ac32010-08-02 13:56:46 -0700953 int deleteZoneHandleId;
954 if (LauncherApplication.isScreenXLarge()) {
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700955 deleteZoneHandleId = R.id.all_apps_button;
Michael Jurka54f7ac32010-08-02 13:56:46 -0700956 } else {
957 deleteZoneHandleId = R.id.all_apps_button_cluster;
958 }
Michael Jurkaaf442092010-06-10 17:01:57 -0700959 deleteZone.setHandle(findViewById(deleteZoneHandleId));
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700960 dragController.addDragListener(deleteZone);
961
Adam Cohencdc30d52010-12-01 15:09:47 -0800962 DeleteZone allAppsDeleteZone = (DeleteZone) findViewById(R.id.all_apps_delete_zone);
963 if (allAppsDeleteZone != null) {
964 allAppsDeleteZone.setLauncher(this);
965 allAppsDeleteZone.setDragController(dragController);
966 allAppsDeleteZone.setDragAndDropEnabled(false);
967 dragController.addDragListener(allAppsDeleteZone);
968 dragController.addDropTarget(allAppsDeleteZone);
969 }
970
971 ApplicationInfoDropTarget allAppsInfoTarget = (ApplicationInfoDropTarget)
972 findViewById(R.id.all_apps_info_target);
973 if (allAppsInfoTarget != null) {
974 allAppsInfoTarget.setLauncher(this);
975 dragController.addDragListener(allAppsInfoTarget);
976 allAppsInfoTarget.setDragColor(getResources().getColor(R.color.app_info_filter));
977 allAppsInfoTarget.setDragAndDropEnabled(false);
978 View marketButton = findViewById(R.id.market_button);
979 if (marketButton != null) {
980 marketButton.setBackgroundColor(Color.RED);
981 allAppsInfoTarget.setHandle(marketButton);
982 }
983 }
984
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700985 ApplicationInfoDropTarget infoButton = (ApplicationInfoDropTarget)findViewById(R.id.info_button);
986 if (infoButton != null) {
987 infoButton.setLauncher(this);
988 infoButton.setHandle(findViewById(R.id.configure_button));
989 infoButton.setDragColor(getResources().getColor(R.color.app_info_filter));
990 dragController.addDragListener(infoButton);
991 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800992
Joe Onorato00acb122009-08-04 16:04:30 -0400993 dragController.setDragScoller(workspace);
Joe Onorato00acb122009-08-04 16:04:30 -0400994 dragController.setScrollView(dragLayer);
Romain Guyea3763c2010-01-11 18:02:04 -0800995 dragController.setMoveTarget(workspace);
Jason Samsfd22dac2009-09-20 17:24:16 -0700996
Joe Onorato00acb122009-08-04 16:04:30 -0400997 // The order here is bottom to top.
998 dragController.addDropTarget(workspace);
999 dragController.addDropTarget(deleteZone);
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001000 if (infoButton != null) {
1001 dragController.addDropTarget(infoButton);
1002 }
Adam Cohencdc30d52010-12-01 15:09:47 -08001003 if (allAppsInfoTarget != null) {
1004 dragController.addDropTarget(allAppsInfoTarget);
1005 }
1006 if (allAppsDeleteZone != null) {
1007 dragController.addDropTarget(allAppsDeleteZone);
1008 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001009 }
1010
Romain Guy8a73c512009-11-09 19:19:59 -08001011 @SuppressWarnings({"UnusedDeclaration"})
1012 public void previousScreen(View v) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001013 if (mState != State.ALL_APPS) {
Joe Onorato61597bd2009-11-19 12:51:57 -08001014 mWorkspace.scrollLeft();
1015 }
Romain Guy8a73c512009-11-09 19:19:59 -08001016 }
1017
1018 @SuppressWarnings({"UnusedDeclaration"})
1019 public void nextScreen(View v) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001020 if (mState != State.ALL_APPS) {
Joe Onorato61597bd2009-11-19 12:51:57 -08001021 mWorkspace.scrollRight();
1022 }
Romain Guy8a73c512009-11-09 19:19:59 -08001023 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -04001024
1025 @SuppressWarnings({"UnusedDeclaration"})
1026 public void launchHotSeat(View v) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001027 if (mState == State.ALL_APPS) return;
Daniel Sandler3e9454a2010-05-24 11:22:41 -04001028
Daniel Sandlerc9b18772010-04-22 14:37:59 -04001029 int index = -1;
1030 if (v.getId() == R.id.hotseat_left) {
1031 index = 0;
1032 } else if (v.getId() == R.id.hotseat_right) {
1033 index = 1;
1034 }
1035
Daniel Sandlerab1ebd72010-04-27 16:57:25 -04001036 // reload these every tap; you never know when they might change
1037 loadHotseats();
1038 if (index >= 0 && index < mHotseats.length && mHotseats[index] != null) {
1039 Intent intent = mHotseats[index];
Daniel Sandlerc9b18772010-04-22 14:37:59 -04001040 startActivitySafely(
1041 mHotseats[index],
1042 "hotseat"
1043 );
1044 }
1045 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001046
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001047 /**
1048 * Creates a view representing a shortcut.
1049 *
1050 * @param info The data structure describing the shortcut.
1051 *
1052 * @return A View inflated from R.layout.application.
1053 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001054 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001055 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -07001056 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001057 }
1058
1059 /**
1060 * Creates a view representing a shortcut inflated from the specified resource.
1061 *
1062 * @param layoutResId The id of the XML layout used to create the shortcut.
1063 * @param parent The group the shortcut belongs to.
1064 * @param info The data structure describing the shortcut.
1065 *
1066 * @return A View inflated from layoutResId.
1067 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001068 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
Michael Jurka67b2f6c2010-11-17 12:33:46 -08001069 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1070 favorite.applyFromShortcutInfo(info, mIconCache);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001071 favorite.setOnClickListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001072 return favorite;
1073 }
1074
1075 /**
1076 * Add an application shortcut to the workspace.
1077 *
1078 * @param data The intent describing the application.
1079 * @param cellInfo The position on screen where to create the shortcut.
1080 */
Michael Jurka0280c3b2010-09-17 15:00:07 -07001081 void completeAddApplication(Context context, Intent data, int screen,
1082 int intersectCellX, int intersectCellY) {
1083 final int[] cellXY = mTmpAddItemCellCoordinates;
1084 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1085
1086 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1087 showOutOfSpaceMessage();
1088 return;
1089 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001090
Joe Onorato0589f0f2010-02-08 13:44:00 -08001091 final ShortcutInfo info = mModel.getShortcutInfo(context.getPackageManager(),
1092 data, context);
1093
Romain Guy73b979d2009-06-09 12:57:21 -07001094 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -08001095 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001096 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001097 info.container = ItemInfo.NO_ID;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001098 mWorkspace.addApplicationShortcut(info, screen, cellXY[0], cellXY[1],
1099 isWorkspaceLocked(), mAddIntersectCellX, mAddIntersectCellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001100 } else {
1101 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001102 }
1103 }
Romain Guycbb89e42009-06-08 15:52:54 -07001104
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001105 /**
1106 * Add a shortcut to the workspace.
1107 *
1108 * @param data The intent describing the shortcut.
1109 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001110 */
Michael Jurka0280c3b2010-09-17 15:00:07 -07001111 private void completeAddShortcut(Intent data, int screen,
1112 int intersectCellX, int intersectCellY) {
1113 final int[] cellXY = mTmpAddItemCellCoordinates;
1114 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
Romain Guycbb89e42009-06-08 15:52:54 -07001115
Michael Jurka0280c3b2010-09-17 15:00:07 -07001116 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1117 showOutOfSpaceMessage();
1118 return;
1119 }
1120
1121 final ShortcutInfo info = mModel.addShortcut(
1122 this, data, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001123
1124 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001125 final View view = createShortcut(info);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001126 mWorkspace.addInScreen(view, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001127 }
1128 }
1129
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001130 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001131 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001132 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001133 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001134 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001135 */
Michael Jurka0280c3b2010-09-17 15:00:07 -07001136 private void completeAddAppWidget(int appWidgetId, int screen) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001137 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Romain Guycbb89e42009-06-08 15:52:54 -07001138
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001139 // Calculate the grid spans needed to fit this widget
Michael Jurka0280c3b2010-09-17 15:00:07 -07001140 CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1141 int[] spanXY = layout.rectToCell(appWidgetInfo.minWidth, appWidgetInfo.minHeight, null);
Romain Guycbb89e42009-06-08 15:52:54 -07001142
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001143 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001144 // We have saved the position to which the widget was dragged-- this really only matters
1145 // if we are placing widgets on a "spring-loaded" screen
Michael Jurka0280c3b2010-09-17 15:00:07 -07001146 final int[] cellXY = mTmpAddItemCellCoordinates;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001147
1148 // For now, we don't save the coordinate where we dropped the icon because we're not
1149 // supporting spring-loaded mini-screens; however, leaving the ability to directly place
1150 // a widget on the home screen in case we want to add it in the future
Winson Chung55cef262010-10-28 14:14:18 -07001151 int[] touchXY = null;
Michael Jurka9c6de3d2010-11-23 16:23:58 -08001152 if (mAddDropPosition != null && mAddDropPosition[0] > -1 && mAddDropPosition[1] > -1) {
Winson Chung55cef262010-10-28 14:14:18 -07001153 touchXY = mAddDropPosition;
1154 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001155 boolean findNearestVacantAreaFailed = false;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001156 boolean foundCellSpan = false;
1157 if (touchXY != null) {
1158 // when dragging and dropping, just find the closest free spot
1159 CellLayout screenLayout = (CellLayout) mWorkspace.getChildAt(screen);
1160 int[] result = screenLayout.findNearestVacantArea(
1161 touchXY[0], touchXY[1], spanXY[0], spanXY[1], cellXY);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001162 findNearestVacantAreaFailed = (result == null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001163 foundCellSpan = !findNearestVacantAreaFailed;
1164 } else {
Michael Jurka9c6de3d2010-11-23 16:23:58 -08001165 // if we long pressed on an empty cell to bring up a menu,
1166 // make sure we intersect the empty cell
1167 // if mAddIntersectCellX/Y are -1 (e.g. we used menu -> add) then
1168 // findCellForSpanThatIntersects will just ignore them
1169 foundCellSpan = layout.findCellForSpanThatIntersects(cellXY, spanXY[0], spanXY[1],
1170 mAddIntersectCellX, mAddIntersectCellY);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001171 }
1172
Michael Jurka0280c3b2010-09-17 15:00:07 -07001173 if (!foundCellSpan) {
Romain Guy18042c82009-11-06 11:44:55 -08001174 if (appWidgetId != -1) mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001175 showOutOfSpaceMessage();
Romain Guy18042c82009-11-06 11:44:55 -08001176 return;
1177 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001178
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001179 // Build Launcher-specific widget info and save to database
1180 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001181 launcherInfo.spanX = spanXY[0];
1182 launcherInfo.spanY = spanXY[1];
Romain Guycbb89e42009-06-08 15:52:54 -07001183
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001184 LauncherModel.addItemToDatabase(this, launcherInfo,
1185 LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001186 screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001187
1188 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001189 mDesktopItems.add(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001190
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001191 // Perform actual inflation because we're live
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001192 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001193
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001194 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001195 launcherInfo.hostView.setTag(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001196
Michael Jurka0280c3b2010-09-17 15:00:07 -07001197 mWorkspace.addInScreen(launcherInfo.hostView, screen, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001198 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
Adam Cohended9f8d2010-11-03 13:25:16 -07001199
1200 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001201 }
1202 }
Romain Guycbb89e42009-06-08 15:52:54 -07001203
Adam Cohended9f8d2010-11-03 13:25:16 -07001204 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1205 @Override
1206 public void onReceive(Context context, Intent intent) {
1207 final String action = intent.getAction();
1208 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1209 mUserPresent = false;
1210 updateRunning();
1211 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1212 mUserPresent = true;
1213 updateRunning();
1214 }
1215 }
1216 };
1217
1218 @Override
1219 public void onAttachedToWindow() {
1220 super.onAttachedToWindow();
1221
1222 // Listen for broadcasts related to user-presence
1223 final IntentFilter filter = new IntentFilter();
1224 filter.addAction(Intent.ACTION_SCREEN_OFF);
1225 filter.addAction(Intent.ACTION_USER_PRESENT);
1226 registerReceiver(mReceiver, filter);
1227
Adam Cohend113e0c2010-11-11 10:48:05 -08001228 mAttached = true;
Adam Cohended9f8d2010-11-03 13:25:16 -07001229 mVisible = true;
1230 }
1231
1232 @Override
1233 public void onDetachedFromWindow() {
1234 super.onDetachedFromWindow();
1235 mVisible = false;
1236
Adam Cohend113e0c2010-11-11 10:48:05 -08001237 if (mAttached) {
1238 unregisterReceiver(mReceiver);
1239 mAttached = false;
1240 }
Adam Cohended9f8d2010-11-03 13:25:16 -07001241 updateRunning();
1242 }
1243
1244 public void onWindowVisibilityChanged(int visibility) {
1245 mVisible = visibility == View.VISIBLE;
1246 updateRunning();
1247 }
1248
1249 private void sendAdvanceMessage(long delay) {
1250 mHandler.removeMessages(ADVANCE_MSG);
1251 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1252 mHandler.sendMessageDelayed(msg, delay);
1253 mAutoAdvanceSentTime = System.currentTimeMillis();
1254 }
1255
1256 private void updateRunning() {
1257 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1258 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1259 mAutoAdvanceRunning = autoAdvanceRunning;
1260 if (autoAdvanceRunning) {
1261 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1262 sendAdvanceMessage(delay);
1263 } else {
1264 if (!mWidgetsToAdvance.isEmpty()) {
1265 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1266 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1267 }
1268 mHandler.removeMessages(ADVANCE_MSG);
1269 }
1270 }
1271 }
1272
1273 private final Handler mHandler = new Handler() {
1274 @Override
1275 public void handleMessage(Message msg) {
1276 if (msg.what == ADVANCE_MSG) {
1277 int i = 0;
1278 for (View key: mWidgetsToAdvance.keySet()) {
1279 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1280 final int delay = mAdvanceStagger * i;
1281 if (v instanceof Advanceable) {
1282 postDelayed(new Runnable() {
1283 public void run() {
1284 ((Advanceable) v).advance();
1285 }
1286 }, delay);
1287 }
1288 i++;
1289 }
1290 sendAdvanceMessage(mAdvanceInterval);
1291 }
1292 }
1293 };
1294
1295 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
1296 if (appWidgetInfo.autoAdvanceViewId == -1) return;
1297 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1298 if (v instanceof Advanceable) {
1299 mWidgetsToAdvance.put(hostView, appWidgetInfo);
1300 ((Advanceable) v).willBeAdvancedByHost();
1301 updateRunning();
1302 }
1303 }
1304
1305 void removeWidgetToAutoAdvance(View hostView) {
1306 if (mWidgetsToAdvance.containsKey(hostView)) {
1307 mWidgetsToAdvance.remove(hostView);
1308 updateRunning();
1309 }
Michael Jurka0280c3b2010-09-17 15:00:07 -07001310 }
1311
Joe Onorato9c1289c2009-08-17 11:03:03 -04001312 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
1313 mDesktopItems.remove(launcherInfo);
Adam Cohended9f8d2010-11-03 13:25:16 -07001314 removeWidgetToAutoAdvance(launcherInfo.hostView);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001315 launcherInfo.hostView = null;
1316 }
1317
Adam Cohended9f8d2010-11-03 13:25:16 -07001318 void showOutOfSpaceMessage() {
1319 Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show();
1320 }
1321
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001322 public LauncherAppWidgetHost getAppWidgetHost() {
1323 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001324 }
Romain Guycbb89e42009-06-08 15:52:54 -07001325
Winson Chunga9abd0e2010-10-27 17:18:37 -07001326 public LauncherModel getModel() {
1327 return mModel;
1328 }
1329
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001330 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001331 getWindow().closeAllPanels();
1332
1333 try {
1334 dismissDialog(DIALOG_CREATE_SHORTCUT);
1335 // Unlock the workspace if the dialog was showing
1336 } catch (Exception e) {
1337 // An exception is thrown if the dialog is not visible, which is fine
1338 }
1339
1340 try {
1341 dismissDialog(DIALOG_RENAME_FOLDER);
1342 // Unlock the workspace if the dialog was showing
1343 } catch (Exception e) {
1344 // An exception is thrown if the dialog is not visible, which is fine
1345 }
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001346
1347 // Whatever we were doing is hereby canceled.
1348 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001349 }
1350
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001351 @Override
1352 protected void onNewIntent(Intent intent) {
1353 super.onNewIntent(intent);
1354
1355 // Close the menu
1356 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001357 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001358 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001359
Joe Onorato14f122b2009-11-19 14:06:36 -08001360 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1361 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001362
Michael Jurka4cb37242010-08-09 21:05:32 -07001363 // in all these cases, only animate if we're already on home
1364 if (LauncherApplication.isScreenXLarge()) {
Michael Jurka99229f62010-09-09 11:49:32 -07001365 mWorkspace.unshrink(alreadyOnHome);
1366 }
1367 if (!mWorkspace.isDefaultPageShowing()) {
Michael Jurka4cb37242010-08-09 21:05:32 -07001368 // on the phone, we don't animate the change to the workspace if all apps is visible
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001369 mWorkspace.moveToDefaultScreen(alreadyOnHome &&
1370 (LauncherApplication.isScreenXLarge() || mState != State.ALL_APPS));
Joe Onorato3a8820b2009-11-10 15:06:42 -08001371 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001372 showWorkspace(alreadyOnHome);
Romain Guy1dd3a072009-07-16 13:21:01 -07001373
Joe Onorato3a8820b2009-11-10 15:06:42 -08001374 final View v = getWindow().peekDecorView();
1375 if (v != null && v.getWindowToken() != null) {
1376 InputMethodManager imm = (InputMethodManager)getSystemService(
1377 INPUT_METHOD_SERVICE);
1378 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001379 }
1380 }
1381 }
1382
1383 @Override
1384 protected void onRestoreInstanceState(Bundle savedInstanceState) {
1385 // Do not call super here
1386 mSavedInstanceState = savedInstanceState;
Michael Jurka946ad472010-07-09 18:05:18 -07001387
1388 if (mHomeCustomizationDrawer != null) {
1389 String cur = savedInstanceState.getString("currentTab");
1390 if (cur != null) {
1391 mHomeCustomizationDrawer.setCurrentTabByTag(cur);
1392 }
1393 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001394 }
1395
1396 @Override
1397 protected void onSaveInstanceState(Bundle outState) {
Michael Jurka0142d492010-08-25 17:46:15 -07001398 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001399
1400 final ArrayList<Folder> folders = mWorkspace.getOpenFolders();
1401 if (folders.size() > 0) {
1402 final int count = folders.size();
1403 long[] ids = new long[count];
1404 for (int i = 0; i < count; i++) {
1405 final FolderInfo info = folders.get(i).getInfo();
1406 ids[i] = info.id;
1407 }
1408 outState.putLongArray(RUNTIME_STATE_USER_FOLDERS, ids);
1409 } else {
1410 super.onSaveInstanceState(outState);
1411 }
1412
Michael Jurka883f55b2010-10-21 15:47:14 -07001413 outState.putInt(RUNTIME_STATE, mState.ordinal());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001414
Michael Jurka0280c3b2010-09-17 15:00:07 -07001415 if (mAddScreen > -1 && mWaitingForResult) {
1416 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mAddScreen);
1417 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mAddIntersectCellX);
1418 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001419 }
1420
1421 if (mFolderInfo != null && mWaitingForResult) {
1422 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1423 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1424 }
Michael Jurka946ad472010-07-09 18:05:18 -07001425
1426 if (mHomeCustomizationDrawer != null) {
1427 String currentTabTag = mHomeCustomizationDrawer.getCurrentTabTag();
1428 if (currentTabTag != null) {
1429 outState.putString("currentTab", currentTabTag);
1430 }
1431 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001432 }
1433
1434 @Override
1435 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001436 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001437
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001438 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001439 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001440 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001441 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001442 }
1443
1444 TextKeyListener.getInstance().release();
1445
Joe Onorato9c1289c2009-08-17 11:03:03 -04001446 mModel.stopLoader();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001447
Joe Onorato9c1289c2009-08-17 11:03:03 -04001448 unbindDesktopItems();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001449
1450 getContentResolver().unregisterContentObserver(mWidgetObserver);
Winson Chungaafa03c2010-06-11 17:34:16 -07001451
Patrick Dubroyab962b72010-07-26 12:10:10 -07001452 // Some launcher layouts don't have a previous and next view
1453 if (mPreviousView != null) {
1454 dismissPreview(mPreviousView);
1455 }
1456 if (mNextView != null) {
1457 dismissPreview(mNextView);
1458 }
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001459
1460 unregisterReceiver(mCloseSystemDialogsReceiver);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001461 }
1462
1463 @Override
1464 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001465 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001466 super.startActivityForResult(intent, requestCode);
1467 }
1468
1469 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001470 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001471 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001472
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001473 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001474
Karl Rosaen138a0412009-04-23 19:00:21 -07001475 if (initialQuery == null) {
1476 // Use any text typed in the launcher as the initial query
1477 initialQuery = getTypedText();
1478 clearTypedText();
1479 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001480 if (appSearchData == null) {
1481 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +00001482 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001483 }
Romain Guycbb89e42009-06-08 15:52:54 -07001484
Karl Rosaen138a0412009-04-23 19:00:21 -07001485 final SearchManager searchManager =
1486 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Karl Rosaen138a0412009-04-23 19:00:21 -07001487 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Romain Guycbb89e42009-06-08 15:52:54 -07001488 appSearchData, globalSearch);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001489 }
1490
1491 @Override
1492 public boolean onCreateOptionsMenu(Menu menu) {
Patrick Dubroy5905bca2010-09-08 22:43:38 -07001493 if (isWorkspaceLocked()) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001494 return false;
1495 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001496
1497 super.onCreateOptionsMenu(menu);
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001498
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001499 menu.add(MENU_GROUP_ADD, MENU_ADD, 0, R.string.menu_add)
1500 .setIcon(android.R.drawable.ic_menu_add)
1501 .setAlphabeticShortcut('A');
Winson Chung7ad01412010-09-27 11:33:03 -07001502 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1503 .setIcon(android.R.drawable.ic_menu_manage)
1504 .setAlphabeticShortcut('M');
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001505 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001506 .setIcon(android.R.drawable.ic_menu_gallery)
1507 .setAlphabeticShortcut('W');
1508 menu.add(0, MENU_SEARCH, 0, R.string.menu_search)
1509 .setIcon(android.R.drawable.ic_search_category_default)
1510 .setAlphabeticShortcut(SearchManager.MENU_KEY);
1511 menu.add(0, MENU_NOTIFICATIONS, 0, R.string.menu_notifications)
1512 .setIcon(com.android.internal.R.drawable.ic_menu_notifications)
1513 .setAlphabeticShortcut('N');
1514
1515 final Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
Romain Guy5a941392009-04-28 15:18:25 -07001516 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
1517 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001518
1519 menu.add(0, MENU_SETTINGS, 0, R.string.menu_settings)
1520 .setIcon(android.R.drawable.ic_menu_preferences).setAlphabeticShortcut('P')
1521 .setIntent(settings);
1522
1523 return true;
1524 }
1525
1526 @Override
1527 public boolean onPrepareOptionsMenu(Menu menu) {
1528 super.onPrepareOptionsMenu(menu);
1529
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001530 // If all apps is animating, don't show the menu, because we don't know
1531 // which one to show.
Patrick Dubroyff5f0402010-07-26 15:23:26 -07001532 if (mAllAppsGrid.isAnimating()) {
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001533 return false;
1534 }
1535
1536 // Only show the add and wallpaper options when we're not in all apps.
Patrick Dubroyff5f0402010-07-26 15:23:26 -07001537 boolean visible = !mAllAppsGrid.isVisible();
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001538 menu.setGroupVisible(MENU_GROUP_ADD, visible);
1539 menu.setGroupVisible(MENU_GROUP_WALLPAPER, visible);
1540
1541 // Disable add if the workspace is full.
1542 if (visible) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001543 CellLayout layout = (CellLayout) mWorkspace.getChildAt(mWorkspace.getCurrentPage());
1544 menu.setGroupEnabled(MENU_GROUP_ADD, layout.existsEmptyCell());
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001545 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001546
1547 return true;
1548 }
1549
1550 @Override
1551 public boolean onOptionsItemSelected(MenuItem item) {
1552 switch (item.getItemId()) {
1553 case MENU_ADD:
1554 addItems();
1555 return true;
Winson Chung7ad01412010-09-27 11:33:03 -07001556 case MENU_MANAGE_APPS:
1557 manageApps();
1558 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001559 case MENU_WALLPAPER_SETTINGS:
1560 startWallpaper();
1561 return true;
1562 case MENU_SEARCH:
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001563 onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001564 return true;
1565 case MENU_NOTIFICATIONS:
1566 showNotifications();
1567 return true;
1568 }
1569
1570 return super.onOptionsItemSelected(item);
1571 }
Romain Guycbb89e42009-06-08 15:52:54 -07001572
Karl Rosaen138a0412009-04-23 19:00:21 -07001573 /**
1574 * Indicates that we want global search for this activity by setting the globalSearch
1575 * argument for {@link #startSearch} to true.
1576 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001577
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001578 @Override
1579 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001580 startSearch(null, false, null, true);
Karl Rosaen138a0412009-04-23 19:00:21 -07001581 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001582 }
1583
Joe Onorato9c1289c2009-08-17 11:03:03 -04001584 public boolean isWorkspaceLocked() {
1585 return mWorkspaceLoading || mWaitingForResult;
1586 }
1587
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001588 private void addItems() {
Patrick Dubroy558654c2010-07-23 16:48:11 -07001589 if (LauncherApplication.isScreenXLarge()) {
1590 // Animate the widget chooser up from the bottom of the screen
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001591 if (mState != State.CUSTOMIZE) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07001592 showCustomizationDrawer(true);
Patrick Dubroy558654c2010-07-23 16:48:11 -07001593 }
1594 } else {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001595 showWorkspace(true);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001596 showAddDialog(-1, -1);
Patrick Dubroy558654c2010-07-23 16:48:11 -07001597 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001598 }
1599
Michael Jurka0280c3b2010-09-17 15:00:07 -07001600 private void resetAddInfo() {
1601 mAddScreen = -1;
1602 mAddIntersectCellX = -1;
1603 mAddIntersectCellY = -1;
1604 mAddDropPosition = null;
1605 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001606
Winson Chung55cef262010-10-28 14:14:18 -07001607 void addAppWidgetFromDrop(PendingAddWidgetInfo info, int screen, int[] position) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001608 resetAddInfo();
1609 mAddScreen = screen;
1610
1611 // only set mAddDropPosition if we dropped on home screen in "spring-loaded" manner
1612 mAddDropPosition = position;
1613
Michael Jurkaaf442092010-06-10 17:01:57 -07001614 int appWidgetId = getAppWidgetHost().allocateAppWidgetId();
Winson Chung55cef262010-10-28 14:14:18 -07001615 AppWidgetManager.getInstance(this).bindAppWidgetId(appWidgetId, info.componentName);
1616 addAppWidgetImpl(appWidgetId, info);
Michael Jurkaaf442092010-06-10 17:01:57 -07001617 }
1618
Winson Chung7ad01412010-09-27 11:33:03 -07001619 private void manageApps() {
1620 startActivity(new Intent(android.provider.Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS));
1621 }
1622
Michael Jurkaaf442092010-06-10 17:01:57 -07001623 void addAppWidgetFromPick(Intent data) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001624 // TODO: catch bad widget exception when sent
1625 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurkaaf442092010-06-10 17:01:57 -07001626 // TODO: Is this log message meaningful?
1627 if (LOGD) Log.d(TAG, "dumping extras content=" + data.getExtras());
Winson Chung55cef262010-10-28 14:14:18 -07001628 addAppWidgetImpl(appWidgetId, null);
Michael Jurkaaf442092010-06-10 17:01:57 -07001629 }
1630
Winson Chung55cef262010-10-28 14:14:18 -07001631 void addAppWidgetImpl(int appWidgetId, PendingAddWidgetInfo info) {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001632 AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001633
Bjorn Bringert7984c942009-12-09 15:38:25 +00001634 if (appWidget.configure != null) {
1635 // Launch over to configure widget, if needed
1636 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
1637 intent.setComponent(appWidget.configure);
1638 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Winson Chung55cef262010-10-28 14:14:18 -07001639 if (info != null) {
Winson Chung68846fd2010-10-29 11:00:27 -07001640 if (info.mimeType != null && !info.mimeType.isEmpty()) {
1641 intent.putExtra(
1642 InstallWidgetReceiver.EXTRA_APPWIDGET_CONFIGURATION_DATA_MIME_TYPE,
1643 info.mimeType);
1644
1645 final String mimeType = info.mimeType;
1646 final ClipData clipData = (ClipData) info.configurationData;
1647 final ClipDescription clipDesc = clipData.getDescription();
1648 for (int i = 0; i < clipDesc.getMimeTypeCount(); ++i) {
1649 if (clipDesc.getMimeType(i).equals(mimeType)) {
1650 final ClipData.Item item = clipData.getItem(i);
1651 final CharSequence stringData = item.getText();
1652 final Uri uriData = item.getUri();
1653 final Intent intentData = item.getIntent();
1654 final String key =
1655 InstallWidgetReceiver.EXTRA_APPWIDGET_CONFIGURATION_DATA;
1656 if (uriData != null) {
1657 intent.putExtra(key, uriData);
1658 } else if (intentData != null) {
1659 intent.putExtra(key, intentData);
1660 } else if (stringData != null) {
1661 intent.putExtra(key, stringData);
1662 }
1663 break;
1664 }
1665 }
1666 }
Winson Chung55cef262010-10-28 14:14:18 -07001667 }
Bjorn Bringert7984c942009-12-09 15:38:25 +00001668
Romain Guy8e633c52010-03-04 12:51:36 -08001669 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001670 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001671 // Otherwise just add it
Michael Jurka0280c3b2010-09-17 15:00:07 -07001672 completeAddAppWidget(appWidgetId, mAddScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001673 }
1674 }
Romain Guycbb89e42009-06-08 15:52:54 -07001675
Michael Jurka0280c3b2010-09-17 15:00:07 -07001676 void processShortcutFromDrop(ComponentName componentName, int screen, int[] position) {
1677 resetAddInfo();
1678 mAddScreen = screen;
1679 mAddDropPosition = position;
1680
1681 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1682 createShortcutIntent.setComponent(componentName);
1683 processShortcut(createShortcutIntent);
1684 }
1685
Joe Onoratodeb98af2010-02-19 14:59:39 -08001686 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001687 // Handle case where user selected "Applications"
1688 String applicationName = getResources().getString(R.string.group_applications);
1689 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001690
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001691 if (applicationName != null && applicationName.equals(shortcutName)) {
1692 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1693 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001694
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001695 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1696 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07001697 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Joe Onorato4a79a042010-09-24 16:17:21 -07001698 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001699 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001700 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001701 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001702 }
1703
Winson Chung24ab2f12010-09-16 14:10:47 -07001704 void processWallpaper(Intent intent) {
1705 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1706 }
1707
Michael Jurka0280c3b2010-09-17 15:00:07 -07001708 void addLiveFolderFromDrop(ComponentName componentName, int screen, int[] position) {
1709 resetAddInfo();
1710 mAddScreen = screen;
1711 mAddDropPosition = position;
1712
1713 Intent createFolderIntent = new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER);
1714 createFolderIntent.setComponent(componentName);
1715
1716 addLiveFolder(createFolderIntent);
1717 }
1718
1719 void addLiveFolder(Intent intent) { // YYY add screen intersect etc. parameters here
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001720 // Handle case where user selected "Folder"
Jeffrey Sharkeyc4bbd0a2009-03-24 22:47:52 -07001721 String folderName = getResources().getString(R.string.group_folder);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001722 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001723
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001724 if (folderName != null && folderName.equals(shortcutName)) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001725 addFolder(mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001726 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001727 startActivityForResultSafely(intent, REQUEST_CREATE_LIVE_FOLDER);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001728 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001729 }
1730
Michael Jurka0280c3b2010-09-17 15:00:07 -07001731 void addFolder(int screen, int intersectCellX, int intersectCellY) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001732 UserFolderInfo folderInfo = new UserFolderInfo();
1733 folderInfo.title = getText(R.string.folder_name);
1734
Michael Jurka0280c3b2010-09-17 15:00:07 -07001735 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1736 final int[] cellXY = mTmpAddItemCellCoordinates;
1737 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1738 showOutOfSpaceMessage();
1739 return;
1740 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001741
1742 // Update the model
Joe Onorato9c1289c2009-08-17 11:03:03 -04001743 LauncherModel.addItemToDatabase(this, folderInfo,
1744 LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001745 screen, cellXY[0], cellXY[1], false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001746 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001747
1748 // Create the view
1749 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurkac9a96192010-11-01 11:52:08 -07001750 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()),
1751 folderInfo, mIconCache);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001752 mWorkspace.addInScreen(newFolder, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001753 }
Romain Guycbb89e42009-06-08 15:52:54 -07001754
Joe Onorato9c1289c2009-08-17 11:03:03 -04001755 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001756 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001757 }
1758
Michael Jurka28750fb2010-09-24 17:43:49 -07001759 private void completeAddLiveFolder(
1760 Intent data, int screen, int intersectCellX, int intersectCellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001761 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1762 final int[] cellXY = mTmpAddItemCellCoordinates;
1763 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1764 showOutOfSpaceMessage();
1765 return;
1766 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001767
Michael Jurka0280c3b2010-09-17 15:00:07 -07001768 final LiveFolderInfo info = addLiveFolder(this, data, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001769
1770 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001771 final View view = LiveFolderIcon.fromXml(R.layout.live_folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07001772 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001773 mWorkspace.addInScreen(view, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001774 }
1775 }
1776
1777 static LiveFolderInfo addLiveFolder(Context context, Intent data,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001778 int screen, int cellX, int cellY, boolean notify) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001779
1780 Intent baseIntent = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT);
1781 String name = data.getStringExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME);
1782
1783 Drawable icon = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001784 Intent.ShortcutIconResource iconResource = null;
1785
1786 Parcelable extra = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON);
1787 if (extra != null && extra instanceof Intent.ShortcutIconResource) {
1788 try {
1789 iconResource = (Intent.ShortcutIconResource) extra;
1790 final PackageManager packageManager = context.getPackageManager();
1791 Resources resources = packageManager.getResourcesForApplication(
1792 iconResource.packageName);
1793 final int id = resources.getIdentifier(iconResource.resourceName, null, null);
1794 icon = resources.getDrawable(id);
1795 } catch (Exception e) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001796 Log.w(TAG, "Could not load live folder icon: " + extra);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001797 }
1798 }
1799
1800 if (icon == null) {
1801 icon = context.getResources().getDrawable(R.drawable.ic_launcher_folder);
1802 }
1803
1804 final LiveFolderInfo info = new LiveFolderInfo();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001805 info.icon = Utilities.createIconBitmap(icon, context);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001806 info.title = name;
1807 info.iconResource = iconResource;
1808 info.uri = data.getData();
1809 info.baseIntent = baseIntent;
1810 info.displayMode = data.getIntExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE,
1811 LiveFolders.DISPLAY_MODE_GRID);
1812
1813 LauncherModel.addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001814 screen, cellX, cellY, notify);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001815 sFolders.put(info.id, info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001816
1817 return info;
1818 }
1819
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001820 private void showNotifications() {
1821 final StatusBarManager statusBar = (StatusBarManager) getSystemService(STATUS_BAR_SERVICE);
1822 if (statusBar != null) {
1823 statusBar.expand();
1824 }
1825 }
1826
1827 private void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001828 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001829 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001830 Intent chooser = Intent.createChooser(pickWallpaper,
1831 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001832 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1833 // Removed in Eclair MR1
1834// WallpaperManager wm = (WallpaperManager)
1835// getSystemService(Context.WALLPAPER_SERVICE);
1836// WallpaperInfo wi = wm.getWallpaperInfo();
1837// if (wi != null && wi.getSettingsActivity() != null) {
1838// LabeledIntent li = new LabeledIntent(getPackageName(),
1839// R.string.configure_wallpaper, 0);
1840// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1841// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1842// }
Mike Clerona0618e42009-10-22 13:55:21 -07001843 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001844 }
1845
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001846 /**
1847 * Registers various content observers. The current implementation registers
1848 * only a favorites observer to keep track of the favorites applications.
1849 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001850 private void registerContentObservers() {
1851 ContentResolver resolver = getContentResolver();
1852 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1853 true, mWidgetObserver);
1854 }
1855
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001856 @Override
1857 public boolean dispatchKeyEvent(KeyEvent event) {
1858 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1859 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001860 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001861 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001862 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jason Samseb5615d2009-11-30 11:50:10 -08001863 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
Joe Onoratobe386092009-11-17 17:32:16 -08001864 dumpState();
1865 return true;
1866 }
1867 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001868 }
1869 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1870 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001871 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001872 return true;
1873 }
1874 }
1875
1876 return super.dispatchKeyEvent(event);
1877 }
1878
Joe Onorato88ec0992009-11-19 13:16:06 -08001879 @Override
1880 public void onBackPressed() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001881 if (mState == State.ALL_APPS || mState == State.CUSTOMIZE) {
1882 showWorkspace(true);
Joe Onorato88ec0992009-11-19 13:16:06 -08001883 } else {
1884 closeFolder();
1885 }
Michael Jurkaaf442092010-06-10 17:01:57 -07001886 // Some launcher layouts don't have a previous and next view
1887 if (mPreviousView != null) {
1888 dismissPreview(mPreviousView);
1889 dismissPreview(mNextView);
1890 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001891 }
1892
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001893 private void closeFolder() {
1894 Folder folder = mWorkspace.getOpenFolder();
1895 if (folder != null) {
1896 closeFolder(folder);
1897 }
1898 }
1899
1900 void closeFolder(Folder folder) {
1901 folder.getInfo().opened = false;
1902 ViewGroup parent = (ViewGroup) folder.getParent();
1903 if (parent != null) {
Michael Jurkaf3ca3ab2010-10-20 17:08:24 -07001904 CellLayout cl = (CellLayout) parent;
1905 cl.removeViewWithoutMarkingCells(folder);
Joe Onoratob6341e92009-11-02 10:41:48 -05001906 if (folder instanceof DropTarget) {
1907 // Live folders aren't DropTargets.
1908 mDragController.removeDropTarget((DropTarget)folder);
1909 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001910 }
1911 folder.onClose();
1912 }
1913
1914 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001915 * Re-listen when widgets are reset.
1916 */
1917 private void onAppWidgetReset() {
1918 mAppWidgetHost.startListening();
1919 }
1920
1921 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001922 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1923 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001924 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04001925 private void unbindDesktopItems() {
1926 for (ItemInfo item: mDesktopItems) {
1927 item.unbind();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001928 }
1929 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001930
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001931 /**
1932 * Launches the intent referred by the clicked shortcut.
1933 *
1934 * @param v The view representing the clicked shortcut.
1935 */
1936 public void onClick(View v) {
1937 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001938 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001939 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08001940 final Intent intent = ((ShortcutInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001941 int[] pos = new int[2];
1942 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08001943 intent.setSourceBounds(new Rect(pos[0], pos[1],
1944 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Joe Onoratof984e852010-03-25 09:47:45 -07001945 startActivitySafely(intent, tag);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001946 } else if (tag instanceof FolderInfo) {
1947 handleFolderClick((FolderInfo) tag);
Joe Onorato7404ee42009-07-31 11:54:44 -07001948 } else if (v == mHandleView) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001949 if (mState == State.ALL_APPS) {
1950 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001951 } else {
Joe Onorato3a8820b2009-11-10 15:06:42 -08001952 showAllApps(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001953 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001954 }
1955 }
1956
Michael Jurka0e260592010-06-30 17:07:39 -07001957 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07001958 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001959 // clicking anywhere on the workspace causes the customization drawer to slide down
1960 showWorkspace(true);
Michael Jurka0e260592010-06-30 17:07:39 -07001961 return false;
1962 }
1963
Michael Jurkaaf442092010-06-10 17:01:57 -07001964 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001965 * Event handler for the search button
1966 *
1967 * @param v The view that was clicked.
1968 */
1969 public void onClickSearchButton(View v) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07001970 startSearch(null, false, null, true);
Amith Yamasani1f878a12010-11-22 14:58:22 -08001971 // Use a custom animation for launching search
1972 overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001973 }
1974
1975 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08001976 * Event handler for the voice button
1977 *
1978 * @param v The view that was clicked.
1979 */
1980 public void onClickVoiceButton(View v) {
1981 startVoiceSearch();
1982 }
1983
1984 private void startVoiceSearch() {
1985 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
1986 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1987 startActivity(intent);
1988 }
1989
1990 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001991 * Event handler for the "gear" button that appears on the home screen, which
Michael Jurkaaf442092010-06-10 17:01:57 -07001992 * enters home screen customization mode.
1993 *
1994 * @param v The view that was clicked.
1995 */
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001996 public void onClickConfigureButton(View v) {
Patrick Dubroy558654c2010-07-23 16:48:11 -07001997 addItems();
Michael Jurkaaf442092010-06-10 17:01:57 -07001998 }
1999
Michael Jurka2c3af5f2010-08-03 13:53:20 -07002000 /**
2001 * Event handler for the "grid" button that appears on the home screen, which
2002 * enters all apps mode.
2003 *
2004 * @param v The view that was clicked.
2005 */
2006 public void onClickAllAppsButton(View v) {
2007 showAllApps(true);
2008 }
2009
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002010 public void onClickAppMarketButton(View v) {
2011 if (mAppMarketIntent != null) {
2012 startActivitySafely(mAppMarketIntent, "app market");
2013 }
2014 }
2015
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002016 void startApplicationDetailsActivity(ComponentName componentName) {
2017 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07002018 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
2019 Uri.fromParts("package", packageName, null));
2020 startActivity(intent);
2021 }
2022
Patrick Dubroy5539af72010-09-07 15:22:01 -07002023 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
2024 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
2025 // System applications cannot be installed. For now, show a toast explaining that.
2026 // We may give them the option of disabling apps this way.
2027 int messageId = R.string.uninstall_system_app_text;
2028 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
2029 } else {
2030 String packageName = appInfo.componentName.getPackageName();
2031 String className = appInfo.componentName.getClassName();
2032 Intent intent = new Intent(
2033 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
2034 startActivity(intent);
2035 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002036 }
2037
Joe Onoratof984e852010-03-25 09:47:45 -07002038 void startActivitySafely(Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002039 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2040 try {
2041 startActivity(intent);
2042 } catch (ActivityNotFoundException e) {
2043 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Daniel Sandlerc9b18772010-04-22 14:37:59 -04002044 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002045 } catch (SecurityException e) {
2046 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08002047 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002048 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07002049 "or use the exported attribute for this activity. "
2050 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002051 }
2052 }
Winson Chungaafa03c2010-06-11 17:34:16 -07002053
Romain Guy8e633c52010-03-04 12:51:36 -08002054 void startActivityForResultSafely(Intent intent, int requestCode) {
2055 try {
2056 startActivityForResult(intent, requestCode);
2057 } catch (ActivityNotFoundException e) {
2058 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2059 } catch (SecurityException e) {
2060 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2061 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
2062 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
2063 "or use the exported attribute for this activity.", e);
2064 }
2065 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002066
2067 private void handleFolderClick(FolderInfo folderInfo) {
2068 if (!folderInfo.opened) {
2069 // Close any open folder
2070 closeFolder();
2071 // Open the requested folder
2072 openFolder(folderInfo);
2073 } else {
2074 // Find the open folder...
2075 Folder openFolder = mWorkspace.getFolderForTag(folderInfo);
2076 int folderScreen;
2077 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002078 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002079 // .. and close it
2080 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07002081 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002082 // Close any folder open on the current screen
2083 closeFolder();
2084 // Pull the folder onto this screen
2085 openFolder(folderInfo);
2086 }
2087 }
2088 }
2089 }
2090
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002091 /**
Michael Jurka774bd372010-10-22 13:40:50 -07002092 * Opens the user folder described by the specified tag. The opening of the folder
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002093 * is animated relative to the specified View. If the View is null, no animation
2094 * is played.
2095 *
2096 * @param folderInfo The FolderInfo describing the folder to open.
2097 */
Winson Chungaafa03c2010-06-11 17:34:16 -07002098 public void openFolder(FolderInfo folderInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002099 Folder openFolder;
2100
2101 if (folderInfo instanceof UserFolderInfo) {
2102 openFolder = UserFolder.fromXml(this);
2103 } else if (folderInfo instanceof LiveFolderInfo) {
Joe Onoratoa5902522009-07-30 13:37:37 -07002104 openFolder = com.android.launcher2.LiveFolder.fromXml(this, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002105 } else {
2106 return;
2107 }
2108
Joe Onorato00acb122009-08-04 16:04:30 -04002109 openFolder.setDragController(mDragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002110 openFolder.setLauncher(this);
2111
2112 openFolder.bind(folderInfo);
2113 folderInfo.opened = true;
2114
Winson Chungaafa03c2010-06-11 17:34:16 -07002115 mWorkspace.addInFullScreen(openFolder, folderInfo.screen);
2116
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002117 openFolder.onOpen();
2118 }
2119
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002120 public boolean onLongClick(View v) {
Romain Guy1fbc1c82009-11-09 20:43:08 -08002121 switch (v.getId()) {
2122 case R.id.previous_screen:
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002123 if (mState != State.ALL_APPS) {
Joe Onorato0d44e942009-11-16 18:20:51 -08002124 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2125 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Romain Guyf8e6a802009-12-07 17:48:02 -08002126 showPreviews(v);
Joe Onorato0d44e942009-11-16 18:20:51 -08002127 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002128 return true;
2129 case R.id.next_screen:
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002130 if (mState != State.ALL_APPS) {
Joe Onorato0d44e942009-11-16 18:20:51 -08002131 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2132 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Romain Guyf8e6a802009-12-07 17:48:02 -08002133 showPreviews(v);
2134 }
2135 return true;
2136 case R.id.all_apps_button:
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002137 if (mState != State.ALL_APPS) {
Romain Guyf8e6a802009-12-07 17:48:02 -08002138 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2139 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
2140 showPreviews(v);
Joe Onorato0d44e942009-11-16 18:20:51 -08002141 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08002142 return true;
2143 }
2144
Joe Onorato9c1289c2009-08-17 11:03:03 -04002145 if (isWorkspaceLocked()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002146 return false;
2147 }
2148
2149 if (!(v instanceof CellLayout)) {
2150 v = (View) v.getParent();
2151 }
2152
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002153
Michael Jurka0280c3b2010-09-17 15:00:07 -07002154 resetAddInfo();
2155 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002156 // This happens when long clicking an item with the dpad/trackball
Michael Jurka0280c3b2010-09-17 15:00:07 -07002157 if (longClickCellInfo == null || !longClickCellInfo.valid) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002158 return true;
2159 }
2160
Michael Jurka0280c3b2010-09-17 15:00:07 -07002161 final View itemUnderLongClick = longClickCellInfo.cell;
2162
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002163 if (mWorkspace.allowLongPress()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002164 if (itemUnderLongClick == null) {
2165 // User long pressed on empty space
2166 mWorkspace.setAllowLongPress(false);
2167 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2168 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Michael Jurka56170562010-10-05 14:14:56 -07002169 if (!LauncherApplication.isScreenXLarge()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002170 showAddDialog(longClickCellInfo.cellX, longClickCellInfo.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002171 }
2172 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002173 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002174 // User long pressed on an item
Joe Onorato0d44e942009-11-16 18:20:51 -08002175 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
2176 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Michael Jurka0280c3b2010-09-17 15:00:07 -07002177 mAddIntersectCellX = longClickCellInfo.cellX;
2178 mAddIntersectCellY = longClickCellInfo.cellY;
2179 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002180 }
2181 }
2182 }
2183 return true;
2184 }
2185
Romain Guye6b8e2f2009-11-10 11:56:55 -08002186 @SuppressWarnings({"unchecked"})
Romain Guy9d31e9f2009-11-11 18:54:28 -08002187 private void dismissPreview(final View v) {
2188 final PopupWindow window = (PopupWindow) v.getTag();
Romain Guy1fbc1c82009-11-09 20:43:08 -08002189 if (window != null) {
Romain Guy9d31e9f2009-11-11 18:54:28 -08002190 window.setOnDismissListener(new PopupWindow.OnDismissListener() {
2191 public void onDismiss() {
2192 ViewGroup group = (ViewGroup) v.getTag(R.id.workspace);
2193 int count = group.getChildCount();
2194 for (int i = 0; i < count; i++) {
2195 ((ImageView) group.getChildAt(i)).setImageDrawable(null);
2196 }
Romain Guy9d31e9f2009-11-11 18:54:28 -08002197 ArrayList<Bitmap> bitmaps = (ArrayList<Bitmap>) v.getTag(R.id.icon);
2198 for (Bitmap bitmap : bitmaps) bitmap.recycle();
2199
2200 v.setTag(R.id.workspace, null);
2201 v.setTag(R.id.icon, null);
2202 window.setOnDismissListener(null);
2203 }
2204 });
Romain Guy1fbc1c82009-11-09 20:43:08 -08002205 window.dismiss();
Romain Guy1fbc1c82009-11-09 20:43:08 -08002206 }
2207 v.setTag(null);
2208 }
2209
Romain Guyf8e6a802009-12-07 17:48:02 -08002210 private void showPreviews(View anchor) {
Romain Guy9d31e9f2009-11-11 18:54:28 -08002211 showPreviews(anchor, 0, mWorkspace.getChildCount());
Romain Guy1fbc1c82009-11-09 20:43:08 -08002212 }
2213
Romain Guya6abce82009-11-10 02:54:41 -08002214 private void showPreviews(final View anchor, int start, int end) {
Romain Guyf8e6a802009-12-07 17:48:02 -08002215 final Resources resources = getResources();
2216 final Workspace workspace = mWorkspace;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002217
Romain Guya6abce82009-11-10 02:54:41 -08002218 CellLayout cell = ((CellLayout) workspace.getChildAt(start));
Winson Chungaafa03c2010-06-11 17:34:16 -07002219
Romain Guy9d31e9f2009-11-11 18:54:28 -08002220 float max = workspace.getChildCount();
Winson Chungaafa03c2010-06-11 17:34:16 -07002221
Romain Guyf8e6a802009-12-07 17:48:02 -08002222 final Rect r = new Rect();
Romain Guy9d31e9f2009-11-11 18:54:28 -08002223 resources.getDrawable(R.drawable.preview_background).getPadding(r);
Romain Guye6b8e2f2009-11-10 11:56:55 -08002224 int extraW = (int) ((r.left + r.right) * max);
2225 int extraH = r.top + r.bottom;
Romain Guya6abce82009-11-10 02:54:41 -08002226
2227 int aW = cell.getWidth() - extraW;
2228 float w = aW / max;
2229
2230 int width = cell.getWidth();
2231 int height = cell.getHeight();
2232 int x = cell.getLeftPadding();
2233 int y = cell.getTopPadding();
2234 width -= (x + cell.getRightPadding());
2235 height -= (y + cell.getBottomPadding());
2236
2237 float scale = w / width;
2238
2239 int count = end - start;
2240
2241 final float sWidth = width * scale;
2242 float sHeight = height * scale;
2243
Romain Guye6b8e2f2009-11-10 11:56:55 -08002244 LinearLayout preview = new LinearLayout(this);
Romain Guya6abce82009-11-10 02:54:41 -08002245
Romain Guye6b8e2f2009-11-10 11:56:55 -08002246 PreviewTouchHandler handler = new PreviewTouchHandler(anchor);
2247 ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>(count);
Romain Guya6abce82009-11-10 02:54:41 -08002248
2249 for (int i = start; i < end; i++) {
Romain Guye6b8e2f2009-11-10 11:56:55 -08002250 ImageView image = new ImageView(this);
Romain Guya6abce82009-11-10 02:54:41 -08002251 cell = (CellLayout) workspace.getChildAt(i);
2252
Romain Guyf8e6a802009-12-07 17:48:02 -08002253 final Bitmap bitmap = Bitmap.createBitmap((int) sWidth, (int) sHeight,
Romain Guye6b8e2f2009-11-10 11:56:55 -08002254 Bitmap.Config.ARGB_8888);
Romain Guyf8e6a802009-12-07 17:48:02 -08002255
2256 final Canvas c = new Canvas(bitmap);
Romain Guya6abce82009-11-10 02:54:41 -08002257 c.scale(scale, scale);
2258 c.translate(-cell.getLeftPadding(), -cell.getTopPadding());
Patrick Dubroy1262e362010-10-06 15:49:50 -07002259 cell.drawChildren(c);
Romain Guya6abce82009-11-10 02:54:41 -08002260
Romain Guy9d31e9f2009-11-11 18:54:28 -08002261 image.setBackgroundDrawable(resources.getDrawable(R.drawable.preview_background));
Romain Guye6b8e2f2009-11-10 11:56:55 -08002262 image.setImageBitmap(bitmap);
2263 image.setTag(i);
2264 image.setOnClickListener(handler);
Romain Guy9d31e9f2009-11-11 18:54:28 -08002265 image.setOnFocusChangeListener(handler);
2266 image.setFocusable(true);
Michael Jurka0142d492010-08-25 17:46:15 -07002267 if (i == mWorkspace.getCurrentPage()) image.requestFocus();
Romain Guye6b8e2f2009-11-10 11:56:55 -08002268
2269 preview.addView(image,
Romain Guy9d31e9f2009-11-11 18:54:28 -08002270 LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
2271
Winson Chungaafa03c2010-06-11 17:34:16 -07002272 bitmaps.add(bitmap);
Romain Guya6abce82009-11-10 02:54:41 -08002273 }
Romain Guyf8e6a802009-12-07 17:48:02 -08002274
2275 final PopupWindow p = new PopupWindow(this);
Romain Guye6b8e2f2009-11-10 11:56:55 -08002276 p.setContentView(preview);
2277 p.setWidth((int) (sWidth * count + extraW));
2278 p.setHeight((int) (sHeight + extraH));
2279 p.setAnimationStyle(R.style.AnimationPreview);
2280 p.setOutsideTouchable(true);
Romain Guy9d31e9f2009-11-11 18:54:28 -08002281 p.setFocusable(true);
Romain Guyff0c2e22009-11-10 12:09:59 -08002282 p.setBackgroundDrawable(new ColorDrawable(0));
Romain Guy9d31e9f2009-11-11 18:54:28 -08002283 p.showAsDropDown(anchor, 0, 0);
Romain Guya6abce82009-11-10 02:54:41 -08002284
Romain Guye6b8e2f2009-11-10 11:56:55 -08002285 p.setOnDismissListener(new PopupWindow.OnDismissListener() {
2286 public void onDismiss() {
2287 dismissPreview(anchor);
2288 }
2289 });
Romain Guy1fbc1c82009-11-09 20:43:08 -08002290
2291 anchor.setTag(p);
2292 anchor.setTag(R.id.workspace, preview);
Winson Chungaafa03c2010-06-11 17:34:16 -07002293 anchor.setTag(R.id.icon, bitmaps);
Romain Guy1fbc1c82009-11-09 20:43:08 -08002294 }
2295
Romain Guy9d31e9f2009-11-11 18:54:28 -08002296 class PreviewTouchHandler implements View.OnClickListener, Runnable, View.OnFocusChangeListener {
Romain Guya6abce82009-11-10 02:54:41 -08002297 private final View mAnchor;
Romain Guya6abce82009-11-10 02:54:41 -08002298
Romain Guye6b8e2f2009-11-10 11:56:55 -08002299 public PreviewTouchHandler(View anchor) {
Romain Guya6abce82009-11-10 02:54:41 -08002300 mAnchor = anchor;
Romain Guya6abce82009-11-10 02:54:41 -08002301 }
2302
2303 public void onClick(View v) {
Michael Jurka0142d492010-08-25 17:46:15 -07002304 mWorkspace.snapToPage((Integer) v.getTag());
Romain Guy9d31e9f2009-11-11 18:54:28 -08002305 v.post(this);
2306 }
2307
2308 public void run() {
Winson Chungaafa03c2010-06-11 17:34:16 -07002309 dismissPreview(mAnchor);
Romain Guy9d31e9f2009-11-11 18:54:28 -08002310 }
2311
2312 public void onFocusChange(View v, boolean hasFocus) {
2313 if (hasFocus) {
Michael Jurka0142d492010-08-25 17:46:15 -07002314 mWorkspace.snapToPage((Integer) v.getTag());
Romain Guy9d31e9f2009-11-11 18:54:28 -08002315 }
Romain Guya6abce82009-11-10 02:54:41 -08002316 }
2317 }
2318
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002319 Workspace getWorkspace() {
2320 return mWorkspace;
2321 }
2322
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002323 @Override
2324 protected Dialog onCreateDialog(int id) {
2325 switch (id) {
2326 case DIALOG_CREATE_SHORTCUT:
2327 return new CreateShortcut().createDialog();
2328 case DIALOG_RENAME_FOLDER:
2329 return new RenameFolder().createDialog();
2330 }
2331
2332 return super.onCreateDialog(id);
2333 }
2334
2335 @Override
2336 protected void onPrepareDialog(int id, Dialog dialog) {
2337 switch (id) {
2338 case DIALOG_CREATE_SHORTCUT:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002339 break;
2340 case DIALOG_RENAME_FOLDER:
Romain Guy7b4ef332009-07-14 13:58:08 -07002341 if (mFolderInfo != null) {
2342 EditText input = (EditText) dialog.findViewById(R.id.folder_name);
2343 final CharSequence text = mFolderInfo.title;
2344 input.setText(text);
2345 input.setSelection(0, text.length());
2346 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002347 break;
2348 }
2349 }
2350
2351 void showRenameDialog(FolderInfo info) {
2352 mFolderInfo = info;
2353 mWaitingForResult = true;
2354 showDialog(DIALOG_RENAME_FOLDER);
2355 }
2356
Michael Jurka0280c3b2010-09-17 15:00:07 -07002357 private void showAddDialog(int intersectX, int intersectY) {
2358 resetAddInfo();
2359 mAddIntersectCellX = intersectX;
2360 mAddIntersectCellY = intersectY;
2361 mAddScreen = mWorkspace.getCurrentPage();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002362 mWaitingForResult = true;
2363 showDialog(DIALOG_CREATE_SHORTCUT);
2364 }
2365
Joe Onoratodeb98af2010-02-19 14:59:39 -08002366 private void pickShortcut() {
Michael Jurka0e260592010-06-30 17:07:39 -07002367 // Insert extra item to handle picking application
Romain Guy73b979d2009-06-09 12:57:21 -07002368 Bundle bundle = new Bundle();
2369
2370 ArrayList<String> shortcutNames = new ArrayList<String>();
2371 shortcutNames.add(getString(R.string.group_applications));
2372 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
2373
2374 ArrayList<ShortcutIconResource> shortcutIcons = new ArrayList<ShortcutIconResource>();
2375 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
2376 R.drawable.ic_launcher_application));
2377 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
2378
2379 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2380 pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_CREATE_SHORTCUT));
Joe Onoratodeb98af2010-02-19 14:59:39 -08002381 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_shortcut));
Romain Guy73b979d2009-06-09 12:57:21 -07002382 pickIntent.putExtras(bundle);
2383
Joe Onoratodeb98af2010-02-19 14:59:39 -08002384 startActivityForResult(pickIntent, REQUEST_PICK_SHORTCUT);
Romain Guy73b979d2009-06-09 12:57:21 -07002385 }
2386
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002387 private class RenameFolder {
2388 private EditText mInput;
2389
2390 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002391 final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null);
2392 mInput = (EditText) layout.findViewById(R.id.folder_name);
2393
2394 AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
2395 builder.setIcon(0);
2396 builder.setTitle(getString(R.string.rename_folder_title));
2397 builder.setCancelable(true);
2398 builder.setOnCancelListener(new Dialog.OnCancelListener() {
2399 public void onCancel(DialogInterface dialog) {
2400 cleanup();
2401 }
2402 });
2403 builder.setNegativeButton(getString(R.string.cancel_action),
2404 new Dialog.OnClickListener() {
2405 public void onClick(DialogInterface dialog, int which) {
2406 cleanup();
2407 }
2408 }
2409 );
2410 builder.setPositiveButton(getString(R.string.rename_action),
2411 new Dialog.OnClickListener() {
2412 public void onClick(DialogInterface dialog, int which) {
2413 changeFolderName();
2414 }
2415 }
2416 );
2417 builder.setView(layout);
Romain Guy7b4ef332009-07-14 13:58:08 -07002418
2419 final AlertDialog dialog = builder.create();
2420 dialog.setOnShowListener(new DialogInterface.OnShowListener() {
2421 public void onShow(DialogInterface dialog) {
Joe Onorato7018d8e2010-04-13 20:25:47 -07002422 mWaitingForResult = true;
Joe Onoratod753b422009-11-08 13:31:11 -05002423 mInput.requestFocus();
2424 InputMethodManager inputManager = (InputMethodManager)
2425 getSystemService(Context.INPUT_METHOD_SERVICE);
2426 inputManager.showSoftInput(mInput, 0);
Romain Guy7b4ef332009-07-14 13:58:08 -07002427 }
2428 });
2429
2430 return dialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002431 }
2432
2433 private void changeFolderName() {
2434 final String name = mInput.getText().toString();
2435 if (!TextUtils.isEmpty(name)) {
2436 // Make sure we have the right folder info
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002437 mFolderInfo = sFolders.get(mFolderInfo.id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002438 mFolderInfo.title = name;
2439 LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo);
2440
Joe Onorato9c1289c2009-08-17 11:03:03 -04002441 if (mWorkspaceLoading) {
Joe Onorato7c312c12009-08-13 21:36:53 -07002442 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002443 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002444 } else {
2445 final FolderIcon folderIcon = (FolderIcon)
2446 mWorkspace.getViewForTag(mFolderInfo);
2447 if (folderIcon != null) {
2448 folderIcon.setText(name);
2449 getWorkspace().requestLayout();
2450 } else {
Joe Onorato7c312c12009-08-13 21:36:53 -07002451 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002452 mWorkspaceLoading = true;
2453 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002454 }
2455 }
2456 }
2457 cleanup();
2458 }
2459
2460 private void cleanup() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002461 dismissDialog(DIALOG_RENAME_FOLDER);
2462 mWaitingForResult = false;
2463 mFolderInfo = null;
2464 }
2465 }
2466
Daniel Sandler843e8602010-06-07 14:59:01 -04002467 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
2468 public boolean isAllAppsVisible() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002469 return mState == State.ALL_APPS;
Joe Onoratofb0ca672009-09-14 17:55:46 -04002470 }
2471
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002472 // AllAppsView.Watcher
2473 public void zoomed(float zoom) {
Michael Jurka213d9632010-07-28 11:29:25 -07002474 // In XLarge view, we zoom down the workspace below all apps so it's still visible
2475 if (zoom == 1.0f && !LauncherApplication.isScreenXLarge()) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002476 mWorkspace.setVisibility(View.GONE);
2477 }
2478 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002479
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002480 private void showToolbarButton(View button) {
2481 button.setAlpha(1.0f);
2482 button.setVisibility(View.VISIBLE);
2483 button.setFocusable(true);
2484 button.setClickable(true);
2485 }
2486
2487 private void hideToolbarButton(View button) {
2488 button.setAlpha(0.0f);
2489 // We can't set it to GONE, otherwise the RelativeLayout gets screwed up
2490 button.setVisibility(View.INVISIBLE);
2491 button.setFocusable(false);
2492 button.setClickable(false);
2493 }
2494
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002495 /**
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002496 * Helper function for showing or hiding a toolbar button, possibly animated.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002497 *
2498 * @param show If true, create an animation to the show the item. Otherwise, hide it.
2499 * @param view The toolbar button to be animated
Chet Haaseb1254a62010-09-07 13:35:00 -07002500 * @param seq A AnimatorSet that will be used to animate the transition. If null, the
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002501 * transition will not be animated.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002502 */
Chet Haaseb1254a62010-09-07 13:35:00 -07002503 private void hideOrShowToolbarButton(boolean show, final View view, AnimatorSet seq) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002504 final boolean showing = show;
2505 final boolean hiding = !show;
2506
2507 final int duration = show ?
2508 getResources().getInteger(R.integer.config_toolbarButtonFadeInTime) :
2509 getResources().getInteger(R.integer.config_toolbarButtonFadeOutTime);
2510
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002511 if (seq != null) {
Chet Haase472b2812010-10-14 07:02:04 -07002512 Animator anim = ObjectAnimator.ofFloat(view, "alpha", show ? 1.0f : 0.0f);
2513 anim.setDuration(duration);
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002514 anim.addListener(new LauncherAnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002515 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002516 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002517 if (showing) showToolbarButton(view);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002518 }
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002519 @Override
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002520 public void onAnimationEndOrCancel(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002521 if (hiding) hideToolbarButton(view);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002522 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002523 });
2524 seq.play(anim);
2525 } else {
2526 if (showing) {
2527 showToolbarButton(view);
2528 } else {
2529 hideToolbarButton(view);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002530 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002531 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002532 }
2533
2534 /**
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002535 * Show/hide the appropriate toolbar buttons for newState.
2536 * If showSeq or hideSeq is null, the transition will be done immediately (not animated).
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002537 *
2538 * @param newState The state that is being switched to
Chet Haaseb1254a62010-09-07 13:35:00 -07002539 * @param showSeq AnimatorSet in which to put "show" animations, or null.
2540 * @param hideSeq AnimatorSet in which to put "hide" animations, or null.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002541 */
Chet Haaseb1254a62010-09-07 13:35:00 -07002542 private void hideAndShowToolbarButtons(State newState, AnimatorSet showSeq, AnimatorSet hideSeq) {
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002543 final View searchButton = findViewById(R.id.search_button_cluster);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002544 final View allAppsButton = findViewById(R.id.all_apps_button);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002545 final View configureButton = findViewById(R.id.configure_button);
2546
2547 switch (newState) {
2548 case WORKSPACE:
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002549 hideOrShowToolbarButton(true, searchButton, showSeq);
2550 hideOrShowToolbarButton(true, allAppsButton, showSeq);
2551 hideOrShowToolbarButton(true, configureButton, showSeq);
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002552 mDeleteZone.setHandle(allAppsButton);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002553 break;
2554 case ALL_APPS:
Adam Lesinski6b879f02010-11-04 16:15:23 -07002555 hideOrShowToolbarButton(false, configureButton, hideSeq);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002556 hideOrShowToolbarButton(false, searchButton, hideSeq);
2557 hideOrShowToolbarButton(false, allAppsButton, hideSeq);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002558 break;
2559 case CUSTOMIZE:
Adam Lesinski6b879f02010-11-04 16:15:23 -07002560 hideOrShowToolbarButton(false, allAppsButton, hideSeq);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002561 hideOrShowToolbarButton(false, searchButton, hideSeq);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002562 hideOrShowToolbarButton(false, configureButton, hideSeq);
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002563 mDeleteZone.setHandle(allAppsButton);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002564 break;
2565 }
2566 }
2567
2568 /**
2569 * Helper method for the cameraZoomIn/cameraZoomOut animations
2570 * @param view The view being animated
2571 * @param state The state that we are moving in or out of -- either ALL_APPS or CUSTOMIZE
2572 * @param scaleFactor The scale factor used for the zoom
2573 */
2574 private void setPivotsForZoom(View view, State state, float scaleFactor) {
2575 final int height = view.getHeight();
Adam Cohen61033d32010-11-15 18:29:44 -08002576
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002577 view.setPivotX(view.getWidth() / 2.0f);
Adam Cohen61033d32010-11-15 18:29:44 -08002578 // Set pivotY so that at the starting zoom factor, the view is partially
2579 // visible. Modifying initialHeightFactor changes how much of the view is
2580 // initially showing, and hence the perceived angle from which the view enters.
2581 final float initialHeightFactor = 0.2f;
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002582 if (state == State.ALL_APPS) {
Adam Cohen61033d32010-11-15 18:29:44 -08002583 view.setPivotY((1 + initialHeightFactor) * height);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002584 } else {
Adam Cohen61033d32010-11-15 18:29:44 -08002585 view.setPivotY(-initialHeightFactor * height);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002586 }
2587 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002588
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002589 /**
2590 * Zoom the camera out from the workspace to reveal 'toView'.
2591 * Assumes that the view to show is anchored at either the very top or very bottom
2592 * of the screen.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002593 * @param toState The state to zoom out to. Must be ALL_APPS or CUSTOMIZE.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002594 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002595 private void cameraZoomOut(State toState, boolean animated) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002596 final Resources res = getResources();
2597 final int duration = res.getInteger(R.integer.config_allAppsZoomInTime);
2598 final float scale = (float) res.getInteger(R.integer.config_allAppsZoomScaleFactor);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002599 final boolean toAllApps = (toState == State.ALL_APPS);
2600 final View toView = toAllApps ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
Patrick Dubroy558654c2010-07-23 16:48:11 -07002601
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002602 setPivotsForZoom(toView, toState, scale);
2603
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002604 if (toAllApps) {
Adam Lesinski6b879f02010-11-04 16:15:23 -07002605 mWorkspace.shrinkToBottomHidden(animated);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002606 } else {
2607 mWorkspace.shrinkToTop(animated);
2608 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002609
2610 if (animated) {
Chet Haase472b2812010-10-14 07:02:04 -07002611 ValueAnimator scaleAnim = ObjectAnimator.ofPropertyValuesHolder(toView,
2612 PropertyValuesHolder.ofFloat("scaleX", scale, 1.0f),
2613 PropertyValuesHolder.ofFloat("scaleY", scale, 1.0f));
2614 scaleAnim.setDuration(duration);
Adam Cohen61033d32010-11-15 18:29:44 -08002615
2616 scaleAnim.setInterpolator(new Workspace.ZoomOutInterpolator());
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002617 scaleAnim.addListener(new LauncherAnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002618 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002619 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002620 // Prepare the position
2621 toView.setTranslationX(0.0f);
2622 toView.setTranslationY(0.0f);
2623 toView.setVisibility(View.VISIBLE);
Adam Cohen61033d32010-11-15 18:29:44 -08002624 toView.setAlpha(1.0f);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002625 }
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002626 @Override
2627 public void onAnimationEndOrCancel(Animator animation) {
2628 // If we don't set the final scale values here, if this animation is cancelled
2629 // it will have the wrong scale value and subsequent cameraPan animations will
2630 // not fix that
2631 toView.setScaleX(1.0f);
2632 toView.setScaleY(1.0f);
2633 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002634 });
2635
Chet Haaseb1254a62010-09-07 13:35:00 -07002636 AnimatorSet toolbarHideAnim = new AnimatorSet();
2637 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002638 hideAndShowToolbarButtons(toState, toolbarShowAnim, toolbarHideAnim);
2639
2640 // toView should appear right at the end of the workspace shrink animation
2641 final int startDelay = res.getInteger(R.integer.config_workspaceShrinkTime) - duration;
2642
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002643 if (mStateAnimation != null) mStateAnimation.cancel();
2644 mStateAnimation = new AnimatorSet();
2645 mStateAnimation.playTogether(scaleAnim, toolbarHideAnim);
2646 mStateAnimation.play(scaleAnim).after(startDelay);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002647
2648 // Show the new toolbar buttons just as the main animation is ending
2649 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002650 mStateAnimation.play(toolbarShowAnim).after(duration + startDelay - fadeInTime);
2651 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002652 } else {
2653 toView.setTranslationX(0.0f);
2654 toView.setTranslationY(0.0f);
2655 toView.setScaleX(1.0f);
2656 toView.setScaleY(1.0f);
2657 toView.setVisibility(View.VISIBLE);
2658 hideAndShowToolbarButtons(toState, null, null);
2659 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002660 }
2661
2662 /**
2663 * Zoom the camera back into the workspace, hiding 'fromView'.
2664 * This is the opposite of cameraZoomOut.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002665 * @param fromState The current state (must be ALL_APPS or CUSTOMIZE).
2666 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002667 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002668 private void cameraZoomIn(State fromState, boolean animated) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002669 Resources res = getResources();
2670 int duration = res.getInteger(R.integer.config_allAppsZoomOutTime);
2671 float scaleFactor = (float) res.getInteger(R.integer.config_allAppsZoomScaleFactor);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002672 final View fromView =
2673 (fromState == State.ALL_APPS) ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
2674
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002675 mCustomizePagedView.endChoiceMode();
2676 mAllAppsPagedView.endChoiceMode();
2677
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002678 setPivotsForZoom(fromView, fromState, scaleFactor);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002679
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002680 mWorkspace.unshrink(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002681
2682 if (animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002683 if (mStateAnimation != null) mStateAnimation.cancel();
2684 mStateAnimation = new AnimatorSet();
Chet Haase472b2812010-10-14 07:02:04 -07002685 ValueAnimator scaleAnim = ObjectAnimator.ofPropertyValuesHolder(fromView,
2686 PropertyValuesHolder.ofFloat("scaleX", scaleFactor),
2687 PropertyValuesHolder.ofFloat("scaleY", scaleFactor));
2688 scaleAnim.setDuration(duration);
Adam Cohen61033d32010-11-15 18:29:44 -08002689 scaleAnim.setInterpolator(new Workspace.ZoomInInterpolator());
2690
2691 ValueAnimator alphaAnim = ObjectAnimator.ofPropertyValuesHolder(fromView,
2692 PropertyValuesHolder.ofFloat("alpha", 1.0f, 0.0f));
2693 alphaAnim.setDuration(res.getInteger(R.integer.config_allAppsFadeOutTime));
2694 alphaAnim.addListener(new LauncherAnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002695 @Override
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002696 public void onAnimationEndOrCancel(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002697 fromView.setVisibility(View.GONE);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002698 }
2699 });
2700
Chet Haaseb1254a62010-09-07 13:35:00 -07002701 AnimatorSet toolbarHideAnim = new AnimatorSet();
2702 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002703 hideAndShowToolbarButtons(State.WORKSPACE, toolbarShowAnim, toolbarHideAnim);
2704
Adam Cohen61033d32010-11-15 18:29:44 -08002705 mStateAnimation.playTogether(scaleAnim, toolbarHideAnim, alphaAnim);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002706
2707 // Show the new toolbar buttons at the very end of the whole animation
2708 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
2709 final int unshrinkTime = res.getInteger(R.integer.config_workspaceUnshrinkTime);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002710 mStateAnimation.play(toolbarShowAnim).after(unshrinkTime - fadeInTime);
2711 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002712 } else {
2713 fromView.setVisibility(View.GONE);
2714 hideAndShowToolbarButtons(State.WORKSPACE, null, null);
2715 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002716 }
2717
2718 /**
2719 * Pan the camera in the vertical plane between 'fromView' and 'toView'.
2720 * This is the transition used on xlarge screens to go between all apps and
2721 * the home customization drawer.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002722 * @param fromState The view to pan away from. Must be ALL_APPS or CUSTOMIZE.
2723 * @param toState The view to pan into the frame. Must be ALL_APPS or CUSTOMIZE.
2724 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002725 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002726 private void cameraPan(State fromState, State toState, boolean animated) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002727 final Resources res = getResources();
2728 final int duration = res.getInteger(R.integer.config_allAppsCameraPanTime);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002729 final int workspaceHeight = mWorkspace.getHeight();
2730
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002731 final boolean fromAllApps = (fromState == State.ALL_APPS);
2732 final View fromView = fromAllApps ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
2733 final View toView = fromAllApps ? mHomeCustomizationDrawer : (View) mAllAppsGrid;
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002734
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002735 final float fromViewStartY = fromAllApps ? 0.0f : fromView.getY();
2736 final float fromViewEndY = fromAllApps ? -fromView.getHeight() * 2 : workspaceHeight * 2;
2737 final float toViewStartY = fromAllApps ? workspaceHeight * 2 : -toView.getHeight() * 2;
2738 final float toViewEndY = fromAllApps ? workspaceHeight - toView.getHeight() : 0.0f;
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002739
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002740 mCustomizePagedView.endChoiceMode();
2741 mAllAppsPagedView.endChoiceMode();
2742
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002743 if (toState == State.ALL_APPS) {
Adam Lesinski6b879f02010-11-04 16:15:23 -07002744 mWorkspace.shrinkToBottomHidden(animated);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002745 } else {
2746 mWorkspace.shrinkToTop(animated);
2747 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002748
2749 if (animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002750 if (mStateAnimation != null) mStateAnimation.cancel();
2751 mStateAnimation = new AnimatorSet();
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002752 mStateAnimation.addListener(new LauncherAnimatorListenerAdapter() {
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002753 @Override
Chet Haaseb1254a62010-09-07 13:35:00 -07002754 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002755 toView.setVisibility(View.VISIBLE);
2756 toView.setY(toViewStartY);
Adam Cohen61033d32010-11-15 18:29:44 -08002757 toView.setAlpha(1.0f);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002758 }
Gilles Debunnedd6c9922010-10-25 11:23:41 -07002759 @Override
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002760 public void onAnimationEndOrCancel(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002761 fromView.setVisibility(View.GONE);
2762 }
2763 });
2764
Chet Haaseb1254a62010-09-07 13:35:00 -07002765 AnimatorSet toolbarHideAnim = new AnimatorSet();
2766 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002767 hideAndShowToolbarButtons(toState, toolbarShowAnim, toolbarHideAnim);
2768
Chet Haase472b2812010-10-14 07:02:04 -07002769 ObjectAnimator fromAnim = ObjectAnimator.ofFloat(fromView, "y",
2770 fromViewStartY, fromViewEndY);
2771 fromAnim.setDuration(duration);
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002772 ObjectAnimator toAnim = ObjectAnimator.ofPropertyValuesHolder(toView,
2773 PropertyValuesHolder.ofFloat("y", toViewStartY, toViewEndY),
2774 PropertyValuesHolder.ofFloat("scaleX", toView.getScaleX(), 1.0f),
2775 PropertyValuesHolder.ofFloat("scaleY", toView.getScaleY(), 1.0f)
2776 );
Chet Haase472b2812010-10-14 07:02:04 -07002777 fromAnim.setDuration(duration);
2778 mStateAnimation.playTogether(toolbarHideAnim, fromAnim, toAnim);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002779
2780 // Show the new toolbar buttons just as the main animation is ending
2781 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002782 mStateAnimation.play(toolbarShowAnim).after(duration - fadeInTime);
2783 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002784 } else {
2785 fromView.setY(fromViewEndY);
2786 fromView.setVisibility(View.GONE);
2787 toView.setY(toViewEndY);
Michael Jurka3c4c20f2010-10-28 15:36:06 -07002788 toView.setScaleX(1.0f);
2789 toView.setScaleY(1.0f);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002790 toView.setVisibility(View.VISIBLE);
2791 hideAndShowToolbarButtons(toState, null, null);
2792 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002793 }
2794
2795 void showAllApps(boolean animated) {
Michael Jurka883f55b2010-10-21 15:47:14 -07002796 if (mState == State.ALL_APPS) {
Winson Chung80baf5a2010-08-09 16:03:15 -07002797 return;
Michael Jurka883f55b2010-10-21 15:47:14 -07002798 }
Winson Chung80baf5a2010-08-09 16:03:15 -07002799
Michael Jurka79212d82010-07-30 16:36:20 -07002800 if (LauncherApplication.isScreenXLarge()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002801 if (mState == State.CUSTOMIZE) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002802 cameraPan(State.CUSTOMIZE, State.ALL_APPS, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002803 } else {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002804 cameraZoomOut(State.ALL_APPS, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002805 }
Patrick Dubroy558654c2010-07-23 16:48:11 -07002806 } else {
2807 mAllAppsGrid.zoom(1.0f, animated);
2808 }
Joe Onorato3a8820b2009-11-10 15:06:42 -08002809
Romain Guyc16fea72010-03-12 17:17:56 -08002810 ((View) mAllAppsGrid).setFocusable(true);
2811 ((View) mAllAppsGrid).requestFocus();
Winson Chungaafa03c2010-06-11 17:34:16 -07002812
Joe Onorato7c312c12009-08-13 21:36:53 -07002813 // TODO: fade these two too
2814 mDeleteZone.setVisibility(View.GONE);
Adam Lesinski6b879f02010-11-04 16:15:23 -07002815
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002816 // Change the state *after* we've called all the transition code
2817 mState = State.ALL_APPS;
2818 }
2819
2820
2821 void showWorkspace(boolean animated) {
2822 showWorkspace(animated, null);
2823 }
2824
2825 void showWorkspace(boolean animated, CellLayout layout) {
Michael Jurka9c6de3d2010-11-23 16:23:58 -08002826 if (layout != null) {
2827 // always animated, but that's ok since we never specify a layout and
2828 // want no animation
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002829 mWorkspace.unshrink(layout);
2830 } else {
2831 mWorkspace.unshrink(animated);
2832 }
2833 if (mState == State.ALL_APPS) {
2834 closeAllApps(animated);
2835 } else if (mState == State.CUSTOMIZE) {
2836 hideCustomizationDrawer(animated);
2837 }
Adam Lesinski6b879f02010-11-04 16:15:23 -07002838
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002839 // Change the state *after* we've called all the transition code
2840 mState = State.WORKSPACE;
Joe Onorato00acb122009-08-04 16:04:30 -04002841 }
2842
Joe Onoratob2061212009-11-24 16:13:54 -05002843 /**
Joe Onorato7e4ed992009-12-03 13:10:49 -08002844 * Things to test when changing this code.
Joe Onoratob2061212009-11-24 16:13:54 -05002845 * - Home from workspace
2846 * - from center screen
2847 * - from other screens
2848 * - Home from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002849 * - from center screen
2850 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002851 * - Back from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002852 * - from center screen
2853 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002854 * - Launch app from workspace and quit
2855 * - with back
2856 * - with home
2857 * - Launch app from all apps and quit
2858 * - with back
2859 * - with home
Joe Onorato7e4ed992009-12-03 13:10:49 -08002860 * - Go to a screen that's not the default, then all
2861 * apps, and launch and app, and go back
2862 * - with back
2863 * -with home
Joe Onoratob2061212009-11-24 16:13:54 -05002864 * - On workspace, long press power and go back
2865 * - with back
2866 * - with home
2867 * - On all apps, long press power and go back
2868 * - with back
2869 * - with home
2870 * - On workspace, power off
2871 * - On all apps, power off
Joe Onorato7e4ed992009-12-03 13:10:49 -08002872 * - Launch an app and turn off the screen while in that app
2873 * - Go back with home key
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002874 * - Go back with back key TODO: make this not go to workspace
Joe Onorato7e4ed992009-12-03 13:10:49 -08002875 * - From all apps
2876 * - From workspace
Joe Onoratoeffc4a82010-04-15 11:48:13 -07002877 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2878 * - From all apps
2879 * - From the center workspace
2880 * - From another workspace
Joe Onoratob2061212009-11-24 16:13:54 -05002881 */
Joe Onorato7bb17492009-09-24 17:51:01 -07002882 void closeAllApps(boolean animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002883 if (mState == State.ALL_APPS) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002884 mWorkspace.setVisibility(View.VISIBLE);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002885 if (LauncherApplication.isScreenXLarge()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002886 cameraZoomIn(State.ALL_APPS, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002887 } else {
2888 mAllAppsGrid.zoom(0.0f, animated);
2889 }
Daniel Sandler388f6792010-03-02 14:08:08 -05002890 ((View)mAllAppsGrid).setFocusable(false);
Michael Jurka0142d492010-08-25 17:46:15 -07002891 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onoratoe77c08d2009-08-01 00:01:20 -07002892 }
Joe Onorato7404ee42009-07-31 11:54:44 -07002893 }
2894
Joe Onorato7c312c12009-08-13 21:36:53 -07002895 void lockAllApps() {
2896 // TODO
2897 }
2898
2899 void unlockAllApps() {
2900 // TODO
2901 }
2902
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002903 // Show the customization drawer (only exists in x-large configuration)
2904 private void showCustomizationDrawer(boolean animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002905 if (mState == State.ALL_APPS) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002906 cameraPan(State.ALL_APPS, State.CUSTOMIZE, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002907 } else {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002908 cameraZoomOut(State.CUSTOMIZE, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002909 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002910 // Change the state *after* we've called all the transition code
2911 mState = State.CUSTOMIZE;
Patrick Dubroy558654c2010-07-23 16:48:11 -07002912 }
2913
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002914 // Hide the customization drawer (only exists in x-large configuration)
2915 void hideCustomizationDrawer(boolean animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002916 if (mState == State.CUSTOMIZE) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002917 cameraZoomIn(State.CUSTOMIZE, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002918 }
2919 }
2920
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002921 void addExternalItemToScreen(ItemInfo itemInfo, CellLayout layout) {
2922 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
2923 showOutOfSpaceMessage();
Michael Jurka213d9632010-07-28 11:29:25 -07002924 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002925 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002926
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002927 void onWorkspaceClick(CellLayout layout) {
2928 showWorkspace(true, layout);
Michael Jurka213d9632010-07-28 11:29:25 -07002929 }
2930
Michael Jurka4ef207b2010-11-29 17:05:45 -08002931 // if successful in getting icon, return it; otherwise, set button to use default drawable
2932 private Drawable updateButtonWithIconFromExternalActivity(
Michael Jurka0423dcf2010-10-05 14:56:18 -07002933 int buttonId, ComponentName activityName, int fallbackDrawableId) {
2934 ImageView button = (ImageView) findViewById(buttonId);
2935 Drawable toolbarIcon = null;
2936 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002937 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07002938 // Look for the toolbar icon specified in the activity meta-data
2939 Bundle metaData = packageManager.getActivityInfo(
2940 activityName, PackageManager.GET_META_DATA).metaData;
2941 if (metaData != null) {
2942 int iconResId = metaData.getInt(TOOLBAR_ICON_METADATA_NAME);
2943 if (iconResId != 0) {
2944 Resources res = packageManager.getResourcesForActivity(activityName);
2945 toolbarIcon = res.getDrawable(iconResId);
2946 }
2947 }
2948 } catch (NameNotFoundException e) {
2949 // Do nothing
2950 }
2951 // If we were unable to find the icon via the meta-data, use a generic one
2952 if (toolbarIcon == null) {
2953 button.setImageResource(fallbackDrawableId);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002954 return null;
Michael Jurka0423dcf2010-10-05 14:56:18 -07002955 } else {
2956 button.setImageDrawable(toolbarIcon);
Michael Jurka4ef207b2010-11-29 17:05:45 -08002957 return toolbarIcon;
Michael Jurka0423dcf2010-10-05 14:56:18 -07002958 }
2959 }
2960
Michael Jurka4ef207b2010-11-29 17:05:45 -08002961 private void updateButtonWithDrawable(int buttonId, Drawable d) {
2962 ImageView button = (ImageView) findViewById(buttonId);
2963 button.setImageDrawable(d);
2964 }
2965
Michael Jurka0423dcf2010-10-05 14:56:18 -07002966 private void updateGlobalSearchIcon() {
2967 if (LauncherApplication.isScreenXLarge()) {
2968 final SearchManager searchManager =
2969 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2970 ComponentName activityName = searchManager.getGlobalSearchActivity();
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002971 if (activityName != null) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002972 sGlobalSearchIcon = updateButtonWithIconFromExternalActivity(
Michael Jurka0423dcf2010-10-05 14:56:18 -07002973 R.id.search_button, activityName, R.drawable.search_button_generic);
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002974 } else {
2975 findViewById(R.id.search_button).setVisibility(View.GONE);
2976 }
2977 }
2978 }
2979
Michael Jurka4ef207b2010-11-29 17:05:45 -08002980 private void updateGlobalSearchIcon(Drawable d) {
2981 updateButtonWithDrawable(R.id.search_button, d);
2982 }
2983
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002984 private void updateVoiceSearchIcon() {
2985 if (LauncherApplication.isScreenXLarge()) {
2986 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2987 ComponentName activityName = intent.resolveActivity(getPackageManager());
2988 if (activityName != null) {
Michael Jurka4ef207b2010-11-29 17:05:45 -08002989 sVoiceSearchIcon = updateButtonWithIconFromExternalActivity(
Amith Yamasani6d7fe502010-11-16 09:05:07 -08002990 R.id.voice_button, activityName, R.drawable.ic_voice_search);
2991 } else {
2992 findViewById(R.id.voice_button).setVisibility(View.GONE);
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002993 }
2994 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002995 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002996
Michael Jurka4ef207b2010-11-29 17:05:45 -08002997 private void updateVoiceSearchIcon(Drawable d) {
2998 updateButtonWithDrawable(R.id.voice_button, d);
2999 }
3000
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003001 /**
3002 * Sets the app market icon (shown when all apps is visible on x-large screens)
3003 */
3004 private void updateAppMarketIcon() {
Michael Jurka0423dcf2010-10-05 14:56:18 -07003005 if (LauncherApplication.isScreenXLarge()) {
3006 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
3007 // Find the app market activity by resolving an intent.
3008 // (If multiple app markets are installed, it will return the ResolverActivity.)
3009 ComponentName activityName = intent.resolveActivity(getPackageManager());
3010 if (activityName != null) {
3011 mAppMarketIntent = intent;
Michael Jurka4ef207b2010-11-29 17:05:45 -08003012 sAppMarketIcon = updateButtonWithIconFromExternalActivity(
Michael Jurka0423dcf2010-10-05 14:56:18 -07003013 R.id.market_button, activityName, R.drawable.app_market_generic);
3014 }
3015 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003016 }
3017
Michael Jurka4ef207b2010-11-29 17:05:45 -08003018 private void updateAppMarketIcon(Drawable d) {
3019 updateButtonWithDrawable(R.id.market_button, d);
3020 }
3021
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003022 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003023 * Displays the shortcut creation dialog and launches, if necessary, the
3024 * appropriate activity.
3025 */
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003026 private class CreateShortcut implements DialogInterface.OnClickListener,
Romain Guy7b4ef332009-07-14 13:58:08 -07003027 DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
3028 DialogInterface.OnShowListener {
3029
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003030 private AddAdapter mAdapter;
Romain Guy9ffb5432009-03-24 21:04:15 -07003031
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003032 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003033 mAdapter = new AddAdapter(Launcher.this);
Romain Guycbb89e42009-06-08 15:52:54 -07003034
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003035 final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
3036 builder.setTitle(getString(R.string.menu_item_add_item));
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003037 builder.setAdapter(mAdapter, this);
Romain Guycbb89e42009-06-08 15:52:54 -07003038
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003039 builder.setInverseBackgroundForced(true);
3040
3041 AlertDialog dialog = builder.create();
3042 dialog.setOnCancelListener(this);
Romain Guycbb89e42009-06-08 15:52:54 -07003043 dialog.setOnDismissListener(this);
Romain Guy7b4ef332009-07-14 13:58:08 -07003044 dialog.setOnShowListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003045
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003046 return dialog;
3047 }
3048
3049 public void onCancel(DialogInterface dialog) {
3050 mWaitingForResult = false;
3051 cleanup();
3052 }
3053
Romain Guycbb89e42009-06-08 15:52:54 -07003054 public void onDismiss(DialogInterface dialog) {
Romain Guycbb89e42009-06-08 15:52:54 -07003055 }
3056
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003057 private void cleanup() {
Joe Onoratocc19a532009-11-19 14:19:17 -08003058 try {
3059 dismissDialog(DIALOG_CREATE_SHORTCUT);
3060 } catch (Exception e) {
3061 // An exception is thrown if the dialog is not visible, which is fine
3062 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003063 }
3064
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003065 /**
3066 * Handle the action clicked in the "Add to home" dialog.
3067 */
3068 public void onClick(DialogInterface dialog, int which) {
3069 Resources res = getResources();
3070 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07003071
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003072 switch (which) {
3073 case AddAdapter.ITEM_SHORTCUT: {
Joe Onoratodeb98af2010-02-19 14:59:39 -08003074 pickShortcut();
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003075 break;
3076 }
Romain Guycbb89e42009-06-08 15:52:54 -07003077
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003078 case AddAdapter.ITEM_APPWIDGET: {
3079 int appWidgetId = Launcher.this.mAppWidgetHost.allocateAppWidgetId();
Romain Guycbb89e42009-06-08 15:52:54 -07003080
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003081 Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
3082 pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003083 // start the pick activity
3084 startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET);
3085 break;
3086 }
Romain Guycbb89e42009-06-08 15:52:54 -07003087
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003088 case AddAdapter.ITEM_LIVE_FOLDER: {
3089 // Insert extra item to handle inserting folder
3090 Bundle bundle = new Bundle();
Romain Guycbb89e42009-06-08 15:52:54 -07003091
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003092 ArrayList<String> shortcutNames = new ArrayList<String>();
3093 shortcutNames.add(res.getString(R.string.group_folder));
3094 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
Romain Guycbb89e42009-06-08 15:52:54 -07003095
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003096 ArrayList<ShortcutIconResource> shortcutIcons =
3097 new ArrayList<ShortcutIconResource>();
3098 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
3099 R.drawable.ic_launcher_folder));
3100 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
3101
3102 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
3103 pickIntent.putExtra(Intent.EXTRA_INTENT,
3104 new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER));
3105 pickIntent.putExtra(Intent.EXTRA_TITLE,
3106 getText(R.string.title_select_live_folder));
3107 pickIntent.putExtras(bundle);
Romain Guycbb89e42009-06-08 15:52:54 -07003108
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07003109 startActivityForResult(pickIntent, REQUEST_PICK_LIVE_FOLDER);
3110 break;
3111 }
3112
3113 case AddAdapter.ITEM_WALLPAPER: {
3114 startWallpaper();
3115 break;
3116 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003117 }
3118 }
Romain Guy7b4ef332009-07-14 13:58:08 -07003119
3120 public void onShow(DialogInterface dialog) {
Winson Chungaafa03c2010-06-11 17:34:16 -07003121 mWaitingForResult = true;
Romain Guy7b4ef332009-07-14 13:58:08 -07003122 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003123 }
3124
3125 /**
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003126 * Receives notifications when applications are added/removed.
3127 */
3128 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
3129 @Override
3130 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003131 closeSystemDialogs();
Joe Onoratob2061212009-11-24 16:13:54 -05003132 String reason = intent.getStringExtra("reason");
3133 if (!"homekey".equals(reason)) {
3134 boolean animate = true;
Joe Onorato34a0e1b2009-12-14 17:44:51 -08003135 if (mPaused || "lock".equals(reason)) {
Joe Onoratob2061212009-11-24 16:13:54 -05003136 animate = false;
3137 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07003138 showWorkspace(animate);
Joe Onoratob2061212009-11-24 16:13:54 -05003139 }
Joe Onorato2ca0ae72009-11-10 13:14:13 -08003140 }
3141 }
3142
3143 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08003144 * Receives notifications whenever the appwidgets are reset.
3145 */
3146 private class AppWidgetResetObserver extends ContentObserver {
3147 public AppWidgetResetObserver() {
3148 super(new Handler());
3149 }
3150
3151 @Override
3152 public void onChange(boolean selfChange) {
3153 onAppWidgetReset();
3154 }
3155 }
3156
3157 /**
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003158 * If the activity is currently paused, signal that we need to re-run the loader
3159 * in onResume.
3160 *
3161 * This needs to be called from incoming places where resources might have been loaded
3162 * while we are paused. That is becaues the Configuration might be wrong
3163 * when we're not running, and if it comes back to what it was when we
3164 * were paused, we are not restarted.
3165 *
3166 * Implementation of the method from LauncherModel.Callbacks.
3167 *
3168 * @return true if we are currently paused. The caller might be able to
3169 * skip some work in that case since we will come back again.
3170 */
3171 public boolean setLoadOnResume() {
3172 if (mPaused) {
3173 Log.i(TAG, "setLoadOnResume");
3174 mOnResumeNeedsLoad = true;
3175 return true;
3176 } else {
3177 return false;
3178 }
3179 }
3180
3181 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003182 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003183 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003184 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07003185 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07003186 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07003187 } else {
3188 return SCREEN_COUNT / 2;
3189 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003190 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003191
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07003192 void setAllAppsPagedView(PagedView view) {
3193 mAllAppsPagedView = view;
3194 }
3195
Joe Onorato9c1289c2009-08-17 11:03:03 -04003196 /**
3197 * Refreshes the shortcuts shown on the workspace.
3198 *
3199 * Implementation of the method from LauncherModel.Callbacks.
3200 */
3201 public void startBinding() {
3202 final Workspace workspace = mWorkspace;
3203 int count = workspace.getChildCount();
3204 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04003205 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Joe Onorato9c1289c2009-08-17 11:03:03 -04003206 ((ViewGroup) workspace.getChildAt(i)).removeAllViewsInLayout();
3207 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003208
Joe Onorato9c1289c2009-08-17 11:03:03 -04003209 if (DEBUG_USER_INTERFACE) {
3210 android.widget.Button finishButton = new android.widget.Button(this);
3211 finishButton.setText("Finish");
3212 workspace.addInScreen(finishButton, 1, 0, 0, 1, 1);
3213
3214 finishButton.setOnClickListener(new android.widget.Button.OnClickListener() {
3215 public void onClick(View v) {
3216 finish();
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07003217 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003218 });
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003219 }
3220 }
3221
3222 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003223 * Bind the items start-end from the list.
3224 *
3225 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003226 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04003227 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
3228
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003229 setLoadOnResume();
3230
Joe Onorato9c1289c2009-08-17 11:03:03 -04003231 final Workspace workspace = mWorkspace;
3232
3233 for (int i=start; i<end; i++) {
3234 final ItemInfo item = shortcuts.get(i);
3235 mDesktopItems.add(item);
3236 switch (item.itemType) {
3237 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
3238 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Joe Onorato0589f0f2010-02-08 13:44:00 -08003239 final View shortcut = createShortcut((ShortcutInfo)item);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003240 workspace.addInScreen(shortcut, item.screen, item.cellX, item.cellY, 1, 1,
3241 false);
3242 break;
3243 case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER:
3244 final FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003245 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Michael Jurkac9a96192010-11-01 11:52:08 -07003246 (UserFolderInfo) item, mIconCache);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003247 workspace.addInScreen(newFolder, item.screen, item.cellX, item.cellY, 1, 1,
3248 false);
3249 break;
3250 case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER:
3251 final FolderIcon newLiveFolder = LiveFolderIcon.fromXml(
3252 R.layout.live_folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07003253 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Joe Onorato9c1289c2009-08-17 11:03:03 -04003254 (LiveFolderInfo) item);
3255 workspace.addInScreen(newLiveFolder, item.screen, item.cellX, item.cellY, 1, 1,
3256 false);
3257 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04003258 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003259 }
3260
Joe Onorato9c1289c2009-08-17 11:03:03 -04003261 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003262 }
3263
Joe Onorato9c1289c2009-08-17 11:03:03 -04003264 /**
3265 * Implementation of the method from LauncherModel.Callbacks.
3266 */
Joe Onoratoad72e172009-11-06 16:25:04 -05003267 public void bindFolders(HashMap<Long, FolderInfo> folders) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003268 setLoadOnResume();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003269 sFolders.clear();
3270 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003271 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003272
3273 /**
3274 * Add the views for a widget to the workspace.
3275 *
3276 * Implementation of the method from LauncherModel.Callbacks.
3277 */
3278 public void bindAppWidget(LauncherAppWidgetInfo item) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003279 setLoadOnResume();
3280
Daniel Sandler843e8602010-06-07 14:59:01 -04003281 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
3282 if (DEBUG_WIDGETS) {
3283 Log.d(TAG, "bindAppWidget: " + item);
3284 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003285 final Workspace workspace = mWorkspace;
3286
3287 final int appWidgetId = item.appWidgetId;
3288 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04003289 if (DEBUG_WIDGETS) {
3290 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
3291 }
3292
Joe Onorato9c1289c2009-08-17 11:03:03 -04003293 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
3294
Joe Onorato9c1289c2009-08-17 11:03:03 -04003295 item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
3296 item.hostView.setTag(item);
3297
3298 workspace.addInScreen(item.hostView, item.screen, item.cellX,
3299 item.cellY, item.spanX, item.spanY, false);
3300
Adam Cohended9f8d2010-11-03 13:25:16 -07003301 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
3302
Joe Onorato9c1289c2009-08-17 11:03:03 -04003303 workspace.requestLayout();
3304
3305 mDesktopItems.add(item);
Daniel Sandler843e8602010-06-07 14:59:01 -04003306
3307 if (DEBUG_WIDGETS) {
3308 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
3309 + (SystemClock.uptimeMillis()-start) + "ms");
3310 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04003311 }
3312
3313 /**
3314 * Callback saying that there aren't any more items to bind.
3315 *
3316 * Implementation of the method from LauncherModel.Callbacks.
3317 */
3318 public void finishBindingItems() {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003319 setLoadOnResume();
3320
Joe Onorato9c1289c2009-08-17 11:03:03 -04003321 if (mSavedState != null) {
3322 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003323 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003324 }
3325
3326 final long[] userFolders = mSavedState.getLongArray(RUNTIME_STATE_USER_FOLDERS);
3327 if (userFolders != null) {
3328 for (long folderId : userFolders) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003329 final FolderInfo info = sFolders.get(folderId);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003330 if (info != null) {
3331 openFolder(info);
3332 }
3333 }
3334 final Folder openFolder = mWorkspace.getOpenFolder();
3335 if (openFolder != null) {
3336 openFolder.requestFocus();
3337 }
3338 }
3339
Joe Onorato9c1289c2009-08-17 11:03:03 -04003340 mSavedState = null;
3341 }
3342
3343 if (mSavedInstanceState != null) {
3344 super.onRestoreInstanceState(mSavedInstanceState);
3345 mSavedInstanceState = null;
3346 }
3347
Joe Onorato9c1289c2009-08-17 11:03:03 -04003348 mWorkspaceLoading = false;
3349 }
3350
3351 /**
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003352 * Updates the icons on the launcher that are affected by changes to the package list
3353 * on the device.
3354 */
3355 private void updateIconsAffectedByPackageManagerChanges() {
3356 updateAppMarketIcon();
3357 updateGlobalSearchIcon();
3358 updateVoiceSearchIcon();
3359 }
3360
3361 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04003362 * Add the icons for all apps.
3363 *
3364 * Implementation of the method from LauncherModel.Callbacks.
3365 */
3366 public void bindAllApplications(ArrayList<ApplicationInfo> apps) {
Romain Guy84f296c2009-11-04 15:00:44 -08003367 mAllAppsGrid.setApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003368 if (mCustomizePagedView != null) {
3369 mCustomizePagedView.setApps(apps);
3370 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003371 updateIconsAffectedByPackageManagerChanges();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003372 }
3373
3374 /**
3375 * A package was installed.
3376 *
3377 * Implementation of the method from LauncherModel.Callbacks.
3378 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003379 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003380 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003381 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onoratoa8138d52009-10-06 19:25:30 -07003382 mAllAppsGrid.addApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003383 if (mCustomizePagedView != null) {
3384 mCustomizePagedView.addApps(apps);
3385 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003386 updateIconsAffectedByPackageManagerChanges();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003387 }
3388
3389 /**
3390 * A package was updated.
3391 *
3392 * Implementation of the method from LauncherModel.Callbacks.
3393 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003394 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
Joe Onoratoef2efcf2010-10-27 13:21:00 -07003395 setLoadOnResume();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003396 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato64e6be72010-03-05 15:05:52 -05003397 mWorkspace.updateShortcuts(apps);
3398 mAllAppsGrid.updateApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003399 if (mCustomizePagedView != null) {
3400 mCustomizePagedView.updateApps(apps);
3401 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003402 updateIconsAffectedByPackageManagerChanges();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003403 }
3404
3405 /**
3406 * A package was uninstalled.
3407 *
3408 * Implementation of the method from LauncherModel.Callbacks.
3409 */
Joe Onorato36115782010-06-17 13:28:48 -04003410 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003411 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato36115782010-06-17 13:28:48 -04003412 if (permanent) {
3413 mWorkspace.removeItems(apps);
3414 }
Joe Onoratoa8138d52009-10-06 19:25:30 -07003415 mAllAppsGrid.removeApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003416 if (mCustomizePagedView != null) {
3417 mCustomizePagedView.removeApps(apps);
3418 }
Amith Yamasani6d7fe502010-11-16 09:05:07 -08003419 updateIconsAffectedByPackageManagerChanges();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003420 }
Joe Onoratobe386092009-11-17 17:32:16 -08003421
3422 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003423 * A number of packages were updated.
3424 */
3425 public void bindPackagesUpdated() {
3426 // update the customization drawer contents
Winson Chung5f941722010-09-28 16:36:43 -07003427 if (mCustomizePagedView != null) {
Winson Chungb3347bb2010-08-19 14:51:28 -07003428 mCustomizePagedView.update();
Winson Chung5f941722010-09-28 16:36:43 -07003429 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003430 }
3431
3432 /**
Joe Onoratobe386092009-11-17 17:32:16 -08003433 * Prints out out state for debugging.
3434 */
3435 public void dumpState() {
3436 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08003437 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08003438 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
3439 Log.d(TAG, "mRestoring=" + mRestoring);
3440 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
3441 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
3442 Log.d(TAG, "mDesktopItems.size=" + mDesktopItems.size());
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003443 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08003444 mModel.dumpState();
3445 mAllAppsGrid.dumpState();
3446 Log.d(TAG, "END launcher2 dump state");
3447 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003448}