blob: 5be78f97fa827bf2a6d9c8327ed3f0f44b0618e7 [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
Chet Haaseb1254a62010-09-07 13:35:00 -070020import android.animation.Animator;
21import android.animation.AnimatorListenerAdapter;
22import android.animation.ValueAnimator;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070023import com.android.common.Search;
24import com.android.launcher.R;
25
Chet Haaseb1254a62010-09-07 13:35:00 -070026import android.animation.ObjectAnimator;
Patrick Dubroy07a0de42010-08-26 11:48:35 -070027import android.animation.PropertyValuesHolder;
Chet Haaseb1254a62010-09-07 13:35:00 -070028import android.animation.AnimatorSet;
Michael Jurka946ad472010-07-09 18:05:18 -070029import android.app.Activity;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080030import android.app.AlertDialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080031import android.app.Dialog;
32import android.app.SearchManager;
33import android.app.StatusBarManager;
Dianne Hackborn107f8392009-08-05 21:32:16 -070034import android.app.WallpaperManager;
Michael Jurkaaf442092010-06-10 17:01:57 -070035import android.appwidget.AppWidgetManager;
36import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080037import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080038import android.content.BroadcastReceiver;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040039import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080040import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041import android.content.Context;
42import android.content.DialogInterface;
43import android.content.Intent;
Winson Chung80baf5a2010-08-09 16:03:15 -070044import android.content.Intent.ShortcutIconResource;
Romain Guy5bbc91b2010-08-18 11:38:46 -070045import android.content.IntentFilter;
Winson Chungaafa03c2010-06-11 17:34:16 -070046import android.content.pm.ActivityInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080047import android.content.pm.PackageManager;
Patrick Dubroyceae05d2010-08-30 10:40:53 -070048import android.content.pm.PackageManager.NameNotFoundException;
Daniel Sandlerab1ebd72010-04-27 16:57:25 -040049import android.content.pm.ResolveInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080050import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070051import android.content.res.Resources;
Daniel Sandlerab1ebd72010-04-27 16:57:25 -040052import android.content.res.TypedArray;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080053import android.database.ContentObserver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080054import android.graphics.Bitmap;
Romain Guya6abce82009-11-10 02:54:41 -080055import android.graphics.Canvas;
Winson Chung80baf5a2010-08-09 16:03:15 -070056import android.graphics.Color;
Michael Jurkaaf442092010-06-10 17:01:57 -070057import android.graphics.Rect;
Romain Guyff0c2e22009-11-10 12:09:59 -080058import android.graphics.drawable.ColorDrawable;
Michael Jurkaaf442092010-06-10 17:01:57 -070059import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040060import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070061import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080062import android.os.Bundle;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080063import android.os.Handler;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080064import android.os.Parcelable;
Daniel Sandler843e8602010-06-07 14:59:01 -040065import android.os.SystemClock;
Joe Onoratobe386092009-11-17 17:32:16 -080066import android.os.SystemProperties;
Karl Rosaen138a0412009-04-23 19:00:21 -070067import android.provider.LiveFolders;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070068import android.provider.Settings;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080069import android.text.Selection;
70import android.text.SpannableStringBuilder;
71import android.text.TextUtils;
72import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070073import android.util.Log;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080074import android.view.Display;
Joe Onorato0d44e942009-11-16 18:20:51 -080075import android.view.HapticFeedbackConstants;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080076import android.view.KeyEvent;
77import android.view.LayoutInflater;
78import android.view.Menu;
79import android.view.MenuItem;
Michael Jurka0e260592010-06-30 17:07:39 -070080import android.view.MotionEvent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080081import android.view.View;
Romain Guy5bbc91b2010-08-18 11:38:46 -070082import android.view.View.OnLongClickListener;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080083import android.view.ViewGroup;
Winson Chungaafa03c2010-06-11 17:34:16 -070084import android.view.WindowManager;
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -070085import android.view.animation.AccelerateInterpolator;
Patrick Dubroy7247f632010-08-04 16:02:59 -070086import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080087import android.view.inputmethod.InputMethodManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080088import android.widget.EditText;
Michael Jurkaaf442092010-06-10 17:01:57 -070089import android.widget.ImageView;
90import android.widget.LinearLayout;
91import android.widget.PopupWindow;
Winson Chung80baf5a2010-08-09 16:03:15 -070092import android.widget.RelativeLayout;
Michael Jurka0e260592010-06-30 17:07:39 -070093import android.widget.TabHost;
Romain Guy5bbc91b2010-08-18 11:38:46 -070094import android.widget.TabHost.OnTabChangeListener;
95import android.widget.TabHost.TabContentFactory;
Winson Chung80baf5a2010-08-09 16:03:15 -070096import android.widget.TabWidget;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080097import android.widget.TextView;
98import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070099
100import java.io.DataInputStream;
101import java.io.DataOutputStream;
102import java.io.FileNotFoundException;
103import java.io.IOException;
104import java.util.ArrayList;
105import java.util.HashMap;
106import java.util.List;
Romain Guyedcce092010-03-04 13:03:17 -0800107
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800108/**
109 * Default launcher application.
110 */
Michael Jurka946ad472010-07-09 18:05:18 -0700111public final class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700112 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
113 AllAppsView.Watcher, View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800114 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700115 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800116
Joe Onorato9c1289c2009-08-17 11:03:03 -0400117 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400118 static final boolean DEBUG_WIDGETS = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400119 static final boolean DEBUG_USER_INTERFACE = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700120
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800121 private static final int MENU_GROUP_ADD = 1;
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800122 private static final int MENU_GROUP_WALLPAPER = MENU_GROUP_ADD + 1;
123
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800124 private static final int MENU_ADD = Menu.FIRST + 1;
125 private static final int MENU_WALLPAPER_SETTINGS = MENU_ADD + 1;
126 private static final int MENU_SEARCH = MENU_WALLPAPER_SETTINGS + 1;
127 private static final int MENU_NOTIFICATIONS = MENU_SEARCH + 1;
Romain Guy94dabf12009-07-21 10:55:43 -0700128 private static final int MENU_SETTINGS = MENU_NOTIFICATIONS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800129
130 private static final int REQUEST_CREATE_SHORTCUT = 1;
131 private static final int REQUEST_CREATE_LIVE_FOLDER = 4;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700132 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800133 private static final int REQUEST_PICK_APPLICATION = 6;
134 private static final int REQUEST_PICK_SHORTCUT = 7;
135 private static final int REQUEST_PICK_LIVE_FOLDER = 8;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700136 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700137 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800138
139 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
140
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800141 static final int SCREEN_COUNT = 5;
142 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800143
Joe Onorato7c312c12009-08-13 21:36:53 -0700144 static final int DIALOG_CREATE_SHORTCUT = 1;
145 static final int DIALOG_RENAME_FOLDER = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800146
Romain Guy98d01652009-06-30 16:21:04 -0700147 private static final String PREFERENCES = "launcher.preferences";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800148
149 // Type: int
150 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
151 // Type: boolean
152 private static final String RUNTIME_STATE_ALL_APPS_FOLDER = "launcher.all_apps_folder";
153 // Type: long
154 private static final String RUNTIME_STATE_USER_FOLDERS = "launcher.user_folder";
155 // Type: int
156 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
157 // Type: int
158 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cellX";
159 // Type: int
160 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cellY";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800161 // Type: boolean
162 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
163 // Type: long
164 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
165
Winson Chung80baf5a2010-08-09 16:03:15 -0700166 // tags for the customization tabs
167 private static final String WIDGETS_TAG = "widgets";
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700168 private static final String APPLICATIONS_TAG = "applications";
Winson Chung80baf5a2010-08-09 16:03:15 -0700169 private static final String FOLDERS_TAG = "folders";
170 private static final String SHORTCUTS_TAG = "shortcuts";
171 private static final String WALLPAPERS_TAG = "wallpapers";
172
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700173 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
174
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700175 /** The different states that Launcher can be in. */
176 private enum State { WORKSPACE, ALL_APPS, CUSTOMIZE, OVERVIEW };
177
Joe Onorato9c1289c2009-08-17 11:03:03 -0400178 static final int APPWIDGET_HOST_ID = 1024;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800179
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800180 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800181 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800182
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800183 private final BroadcastReceiver mCloseSystemDialogsReceiver
184 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800185 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
186
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800187 private LayoutInflater mInflater;
188
Joe Onorato00acb122009-08-04 16:04:30 -0400189 private DragController mDragController;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800190 private Workspace mWorkspace;
Romain Guycbb89e42009-06-08 15:52:54 -0700191
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700192 private AppWidgetManager mAppWidgetManager;
193 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700194
Michael Jurka0280c3b2010-09-17 15:00:07 -0700195 private int mAddScreen = -1;
196 private int mAddIntersectCellX = -1;
197 private int mAddIntersectCellY = -1;
198 private int[] mAddDropPosition;
199 private int[] mTmpAddItemCellCoordinates = new int[2];
200
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800201 private FolderInfo mFolderInfo;
202
Joe Onorato7c312c12009-08-13 21:36:53 -0700203 private DeleteZone mDeleteZone;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700204 private HandleView mHandleView;
Joe Onorato7c312c12009-08-13 21:36:53 -0700205 private AllAppsView mAllAppsGrid;
Michael Jurka0e260592010-06-30 17:07:39 -0700206 private TabHost mHomeCustomizationDrawer;
Patrick Dubroy2b9ff372010-09-07 17:49:27 -0700207
208 private PagedView mAllAppsPagedView = null;
209 private CustomizePagedView mCustomizePagedView = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800210
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800211 private Bundle mSavedState;
212
213 private SpannableStringBuilder mDefaultKeySsb = null;
214
Joe Onorato9c1289c2009-08-17 11:03:03 -0400215 private boolean mWorkspaceLoading = true;
216
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800217 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800218 private boolean mRestoring;
219 private boolean mWaitingForResult;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800220
221 private Bundle mSavedInstanceState;
222
Joe Onorato9c1289c2009-08-17 11:03:03 -0400223 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800224 private IconCache mIconCache;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400225
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700226 private static LocaleConfiguration sLocaleConfiguration = null;
227
Romain Guy84f296c2009-11-04 15:00:44 -0800228 private ArrayList<ItemInfo> mDesktopItems = new ArrayList<ItemInfo>();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700229 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700230
Romain Guy1fbc1c82009-11-09 20:43:08 -0800231 private ImageView mPreviousView;
232 private ImageView mNextView;
Joe Onorato080d9b62009-11-02 12:01:11 -0500233
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400234 // Hotseats (quick-launch icons next to AllApps)
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400235 private String[] mHotseatConfig = null;
236 private Intent[] mHotseats = null;
237 private Drawable[] mHotseatIcons = null;
238 private CharSequence[] mHotseatLabels = null;
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400239
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700240 private Intent mAppMarketIntent = null;
241
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800242 @Override
243 protected void onCreate(Bundle savedInstanceState) {
244 super.onCreate(savedInstanceState);
Romain Guyb1b69f52009-08-10 15:10:15 -0700245
Winson Chungaafa03c2010-06-11 17:34:16 -0700246 if (LauncherApplication.isInPlaceRotationEnabled()) {
247 // hide the status bar (temporary until we get the status bar design figured out)
248 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
249 this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
250 }
251
Joe Onorato0589f0f2010-02-08 13:44:00 -0800252 LauncherApplication app = ((LauncherApplication)getApplication());
253 mModel = app.setLauncher(this);
254 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400255 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800256 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700257
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700258 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700259 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
260 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700261
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800262 if (PROFILE_STARTUP) {
263 android.os.Debug.startMethodTracing("/sdcard/launcher");
264 }
265
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400266 loadHotseats();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800267 checkForLocaleChange();
268 setWallpaperDimension();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800269 setContentView(R.layout.launcher);
Michael Jurka946ad472010-07-09 18:05:18 -0700270 mHomeCustomizationDrawer = (TabHost) findViewById(com.android.internal.R.id.tabhost);
271 if (mHomeCustomizationDrawer != null) {
272 mHomeCustomizationDrawer.setup();
Winson Chungaafa03c2010-06-11 17:34:16 -0700273
Winson Chung80baf5a2010-08-09 16:03:15 -0700274 // share the same customization workspace across all the tabs
Winson Chunge3193b92010-09-10 11:44:42 -0700275 mCustomizePagedView = (CustomizePagedView) mInflater.inflate(
276 R.layout.customization_drawer, mHomeCustomizationDrawer, false);
Winson Chung80baf5a2010-08-09 16:03:15 -0700277 TabContentFactory contentFactory = new TabContentFactory() {
278 public View createTabContent(String tag) {
279 return mCustomizePagedView;
280 }
281 };
282
Michael Jurka946ad472010-07-09 18:05:18 -0700283 String widgetsLabel = getString(R.string.widgets_tab_label);
Winson Chung80baf5a2010-08-09 16:03:15 -0700284 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(WIDGETS_TAG)
285 .setIndicator(widgetsLabel).setContent(contentFactory));
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700286 String applicationsLabel = getString(R.string.applications_tab_label);
287 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(APPLICATIONS_TAG)
288 .setIndicator(applicationsLabel).setContent(contentFactory));
Michael Jurka946ad472010-07-09 18:05:18 -0700289 String foldersLabel = getString(R.string.folders_tab_label);
Winson Chung80baf5a2010-08-09 16:03:15 -0700290 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(FOLDERS_TAG)
291 .setIndicator(foldersLabel).setContent(contentFactory));
Michael Jurka946ad472010-07-09 18:05:18 -0700292 String wallpapersLabel = getString(R.string.wallpapers_tab_label);
Winson Chung80baf5a2010-08-09 16:03:15 -0700293 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(WALLPAPERS_TAG)
294 .setIndicator(wallpapersLabel).setContent(contentFactory));
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700295 String shortcutsLabel = getString(R.string.shortcuts_tab_label);
296 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(SHORTCUTS_TAG)
297 .setIndicator(shortcutsLabel).setContent(contentFactory));
Winson Chung80baf5a2010-08-09 16:03:15 -0700298
299 // TEMP: just styling the tab widget to be a bit nicer until we get the actual
300 // new assets
301 TabWidget tabWidget = mHomeCustomizationDrawer.getTabWidget();
302 for (int i = 0; i < tabWidget.getChildCount(); ++i) {
303 RelativeLayout tab = (RelativeLayout) tabWidget.getChildTabViewAt(i);
304 TextView text = (TextView) tab.getChildAt(1);
305 text.setTextSize(20.0f);
306 text.setPadding(20, 0, 20, 0);
307 text.setShadowLayer(1.0f, 0.0f, 1.0f, Color.BLACK);
308 tab.setBackgroundDrawable(null);
309 }
310
311 mHomeCustomizationDrawer.setOnTabChangedListener(new OnTabChangeListener() {
312 public void onTabChanged(String tabId) {
313 // animate the changing of the tab content by fading pages in and out
314 final int duration = 150;
315 final float alpha = mCustomizePagedView.getAlpha();
Chet Haaseb1254a62010-09-07 13:35:00 -0700316 ValueAnimator alphaAnim = new ObjectAnimator(duration, mCustomizePagedView,
Winson Chung80baf5a2010-08-09 16:03:15 -0700317 "alpha", alpha, 0.0f);
Chet Haaseb1254a62010-09-07 13:35:00 -0700318 alphaAnim.addListener(new AnimatorListenerAdapter() {
319 public void onAnimationEnd(Animator animation) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700320 String tag = mHomeCustomizationDrawer.getCurrentTabTag();
321 if (tag == WIDGETS_TAG) {
322 mCustomizePagedView.setCustomizationFilter(
323 CustomizePagedView.CustomizationType.WidgetCustomization);
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700324 } else if (tag == APPLICATIONS_TAG) {
325 mCustomizePagedView.setCustomizationFilter(
326 CustomizePagedView.CustomizationType.ApplicationCustomization);
Winson Chung80baf5a2010-08-09 16:03:15 -0700327 } else if (tag == FOLDERS_TAG) {
328 mCustomizePagedView.setCustomizationFilter(
329 CustomizePagedView.CustomizationType.FolderCustomization);
Winson Chung80baf5a2010-08-09 16:03:15 -0700330 } else if (tag == WALLPAPERS_TAG) {
331 mCustomizePagedView.setCustomizationFilter(
332 CustomizePagedView.CustomizationType.WallpaperCustomization);
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700333 } else if (tag == SHORTCUTS_TAG) {
334 mCustomizePagedView.setCustomizationFilter(
335 CustomizePagedView.CustomizationType.ShortcutCustomization);
Winson Chung80baf5a2010-08-09 16:03:15 -0700336 }
337
338 final float alpha = mCustomizePagedView.getAlpha();
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700339 ValueAnimator alphaAnim = new ObjectAnimator(duration,
340 mCustomizePagedView, "alpha", alpha, 1.0f);
Winson Chung80baf5a2010-08-09 16:03:15 -0700341 alphaAnim.start();
342 }
343 });
344 alphaAnim.start();
345 }
346 });
Michael Jurka946ad472010-07-09 18:05:18 -0700347
348 mHomeCustomizationDrawer.setCurrentTab(0);
349 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800350 setupViews();
351
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800352 registerContentObservers();
353
Joe Onorato7c312c12009-08-13 21:36:53 -0700354 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700355
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800356 mSavedState = savedInstanceState;
357 restoreState(mSavedState);
358
359 if (PROFILE_STARTUP) {
360 android.os.Debug.stopMethodTracing();
361 }
362
363 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400364 mModel.startLoader(this, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800365 }
366
367 // For handling default keys
368 mDefaultKeySsb = new SpannableStringBuilder();
369 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800370
371 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
372 registerReceiver(mCloseSystemDialogsReceiver, filter);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800373 }
Romain Guycbb89e42009-06-08 15:52:54 -0700374
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800375 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700376 if (sLocaleConfiguration == null) {
377 new AsyncTask<Void, Void, LocaleConfiguration>() {
378 @Override
379 protected LocaleConfiguration doInBackground(Void... unused) {
380 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
381 readConfiguration(Launcher.this, localeConfiguration);
382 return localeConfiguration;
383 }
384
385 @Override
386 protected void onPostExecute(LocaleConfiguration result) {
387 sLocaleConfiguration = result;
388 checkForLocaleChange(); // recursive, but now with a locale configuration
389 }
390 }.execute();
391 return;
392 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700393
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800394 final Configuration configuration = getResources().getConfiguration();
395
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700396 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800397 final String locale = configuration.locale.toString();
398
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700399 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800400 final int mcc = configuration.mcc;
401
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700402 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800403 final int mnc = configuration.mnc;
404
Romain Guy84f296c2009-11-04 15:00:44 -0800405 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800406
Romain Guy84f296c2009-11-04 15:00:44 -0800407 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700408 sLocaleConfiguration.locale = locale;
409 sLocaleConfiguration.mcc = mcc;
410 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700411
Joe Onorato0589f0f2010-02-08 13:44:00 -0800412 mIconCache.flush();
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400413 loadHotseats();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700414
415 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
416 new Thread("WriteLocaleConfiguration") {
417 public void run() {
418 writeConfiguration(Launcher.this, localeConfiguration);
419 }
420 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700421 }
422 }
423
424 private static class LocaleConfiguration {
425 public String locale;
426 public int mcc = -1;
427 public int mnc = -1;
428 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700429
Romain Guy98d01652009-06-30 16:21:04 -0700430 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
431 DataInputStream in = null;
432 try {
433 in = new DataInputStream(context.openFileInput(PREFERENCES));
434 configuration.locale = in.readUTF();
435 configuration.mcc = in.readInt();
436 configuration.mnc = in.readInt();
437 } catch (FileNotFoundException e) {
438 // Ignore
439 } catch (IOException e) {
440 // Ignore
441 } finally {
442 if (in != null) {
443 try {
444 in.close();
445 } catch (IOException e) {
446 // Ignore
447 }
448 }
449 }
450 }
451
452 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
453 DataOutputStream out = null;
454 try {
455 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
456 out.writeUTF(configuration.locale);
457 out.writeInt(configuration.mcc);
458 out.writeInt(configuration.mnc);
459 out.flush();
460 } catch (FileNotFoundException e) {
461 // Ignore
462 } catch (IOException e) {
463 //noinspection ResultOfMethodCallIgnored
464 context.getFileStreamPath(PREFERENCES).delete();
465 } finally {
466 if (out != null) {
467 try {
468 out.close();
469 } catch (IOException e) {
470 // Ignore
471 }
472 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800473 }
474 }
475
476 static int getScreen() {
477 synchronized (sLock) {
478 return sScreen;
479 }
480 }
481
482 static void setScreen(int screen) {
483 synchronized (sLock) {
484 sScreen = screen;
485 }
486 }
487
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800488 private void setWallpaperDimension() {
Dianne Hackborn107f8392009-08-05 21:32:16 -0700489 WallpaperManager wpm = (WallpaperManager)getSystemService(WALLPAPER_SERVICE);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800490
491 Display display = getWindowManager().getDefaultDisplay();
Romain Guy5bbc91b2010-08-18 11:38:46 -0700492 // TODO: Put back when we decide about scrolling the wallpaper
493 // boolean isPortrait = display.getWidth() < display.getHeight();
494 // final int width = isPortrait ? display.getWidth() : display.getHeight();
495 // final int height = isPortrait ? display.getHeight() : display.getWidth();
496 wpm.suggestDesiredDimensions(Math.max(display.getWidth(), display.getHeight()),
497 Math.max(display.getWidth(), display.getHeight()));
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800498 }
499
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400500 // Note: This doesn't do all the client-id magic that BrowserProvider does
501 // in Browser. (http://b/2425179)
502 private Uri getDefaultBrowserUri() {
503 String url = getString(R.string.default_browser_url);
504 if (url.indexOf("{CID}") != -1) {
505 url = url.replace("{CID}", "android-google");
506 }
507 return Uri.parse(url);
508 }
509
510 // Load the Intent templates from arrays.xml to populate the hotseats. For
511 // each Intent, if it resolves to a single app, use that as the launch
512 // intent & use that app's label as the contentDescription. Otherwise,
513 // retain the ResolveActivity so the user can pick an app.
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400514 private void loadHotseats() {
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400515 if (mHotseatConfig == null) {
516 mHotseatConfig = getResources().getStringArray(R.array.hotseats);
517 if (mHotseatConfig.length > 0) {
518 mHotseats = new Intent[mHotseatConfig.length];
519 mHotseatLabels = new CharSequence[mHotseatConfig.length];
520 mHotseatIcons = new Drawable[mHotseatConfig.length];
521 } else {
522 mHotseats = null;
523 mHotseatIcons = null;
524 mHotseatLabels = null;
525 }
526
527 TypedArray hotseatIconDrawables = getResources().obtainTypedArray(R.array.hotseat_icons);
528 for (int i=0; i<mHotseatConfig.length; i++) {
529 // load icon for this slot; currently unrelated to the actual activity
530 try {
531 mHotseatIcons[i] = hotseatIconDrawables.getDrawable(i);
532 } catch (ArrayIndexOutOfBoundsException ex) {
533 Log.w(TAG, "Missing hotseat_icons array item #" + i);
534 mHotseatIcons[i] = null;
535 }
536 }
537 hotseatIconDrawables.recycle();
538 }
539
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400540 PackageManager pm = getPackageManager();
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400541 for (int i=0; i<mHotseatConfig.length; i++) {
542 Intent intent = null;
543 if (mHotseatConfig[i].equals("*BROWSER*")) {
544 // magic value meaning "launch user's default web browser"
545 // replace it with a generic web request so we can see if there is indeed a default
546 String defaultUri = getString(R.string.default_browser_url);
547 intent = new Intent(
548 Intent.ACTION_VIEW,
549 ((defaultUri != null)
550 ? Uri.parse(defaultUri)
551 : getDefaultBrowserUri())
552 ).addCategory(Intent.CATEGORY_BROWSABLE);
553 // note: if the user launches this without a default set, she
554 // will always be taken to the default URL above; this is
555 // unavoidable as we must specify a valid URL in order for the
Winson Chungaafa03c2010-06-11 17:34:16 -0700556 // chooser to appear, and once the user selects something, that
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400557 // URL is unavoidably sent to the chosen app.
558 } else {
559 try {
560 intent = Intent.parseUri(mHotseatConfig[i], 0);
561 } catch (java.net.URISyntaxException ex) {
562 Log.w(TAG, "Invalid hotseat intent: " + mHotseatConfig[i]);
563 // bogus; leave intent=null
564 }
565 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700566
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400567 if (intent == null) {
568 mHotseats[i] = null;
569 mHotseatLabels[i] = getText(R.string.activity_not_found);
570 continue;
571 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400572
573 if (LOGD) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700574 Log.d(TAG, "loadHotseats: hotseat " + i
575 + " initial intent=["
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400576 + intent.toUri(Intent.URI_INTENT_SCHEME)
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400577 + "]");
578 }
579
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400580 ResolveInfo bestMatch = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
581 List<ResolveInfo> allMatches = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
Winson Chungaafa03c2010-06-11 17:34:16 -0700582 if (LOGD) {
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400583 Log.d(TAG, "Best match for intent: " + bestMatch);
584 Log.d(TAG, "All matches: ");
585 for (ResolveInfo ri : allMatches) {
586 Log.d(TAG, " --> " + ri);
587 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400588 }
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400589 // did this resolve to a single app, or the resolver?
590 if (allMatches.size() == 0 || bestMatch == null) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700591 // can't find any activity to handle this. let's leave the
592 // intent as-is and let Launcher show a toast when it fails
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400593 // to launch.
594 mHotseats[i] = intent;
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400595
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400596 // set accessibility text to "Not installed"
597 mHotseatLabels[i] = getText(R.string.activity_not_found);
598 } else {
599 boolean found = false;
600 for (ResolveInfo ri : allMatches) {
601 if (bestMatch.activityInfo.name.equals(ri.activityInfo.name)
602 && bestMatch.activityInfo.applicationInfo.packageName
603 .equals(ri.activityInfo.applicationInfo.packageName)) {
604 found = true;
605 break;
606 }
607 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700608
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400609 if (!found) {
610 if (LOGD) Log.d(TAG, "Multiple options, no default yet");
611 // the bestMatch is probably the ResolveActivity, meaning the
612 // user has not yet selected a default
613 // so: we'll keep the original intent for now
614 mHotseats[i] = intent;
615
616 // set the accessibility text to "Select shortcut"
617 mHotseatLabels[i] = getText(R.string.title_select_shortcut);
618 } else {
619 // we have an app!
620 // now reconstruct the intent to launch it through the front
621 // door
622 ComponentName com = new ComponentName(
623 bestMatch.activityInfo.applicationInfo.packageName,
624 bestMatch.activityInfo.name);
625 mHotseats[i] = new Intent(Intent.ACTION_MAIN).setComponent(com);
626
627 // load the app label for accessibility
628 mHotseatLabels[i] = bestMatch.activityInfo.loadLabel(pm);
629 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400630 }
631
632 if (LOGD) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700633 Log.d(TAG, "loadHotseats: hotseat " + i
634 + " final intent=["
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400635 + ((mHotseats[i] == null)
636 ? "null"
637 : mHotseats[i].toUri(Intent.URI_INTENT_SCHEME))
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400638 + "] label=[" + mHotseatLabels[i]
639 + "]"
640 );
641 }
642 }
643 }
644
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800645 @Override
646 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Romain Guyaad5ef42009-06-10 02:48:37 -0700647 mWaitingForResult = false;
648
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800649 // The pattern used here is that a user PICKs a specific application,
650 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700651
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800652 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
653 // launch over to the Music app to actually CREATE_SHORTCUT.
Romain Guycbb89e42009-06-08 15:52:54 -0700654
Michael Jurka0280c3b2010-09-17 15:00:07 -0700655 if (resultCode == RESULT_OK && mAddScreen != -1) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800656 switch (requestCode) {
657 case REQUEST_PICK_APPLICATION:
Michael Jurka0280c3b2010-09-17 15:00:07 -0700658 completeAddApplication(this, data, mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800659 break;
660 case REQUEST_PICK_SHORTCUT:
Joe Onoratodeb98af2010-02-19 14:59:39 -0800661 processShortcut(data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800662 break;
663 case REQUEST_CREATE_SHORTCUT:
Michael Jurka0280c3b2010-09-17 15:00:07 -0700664 completeAddShortcut(data, mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800665 break;
666 case REQUEST_PICK_LIVE_FOLDER:
667 addLiveFolder(data);
668 break;
669 case REQUEST_CREATE_LIVE_FOLDER:
Michael Jurka0280c3b2010-09-17 15:00:07 -0700670 completeAddLiveFolder(data, mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800671 break;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700672 case REQUEST_PICK_APPWIDGET:
Michael Jurkaaf442092010-06-10 17:01:57 -0700673 addAppWidgetFromPick(data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800674 break;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700675 case REQUEST_CREATE_APPWIDGET:
Michael Jurkaaf442092010-06-10 17:01:57 -0700676 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700677 completeAddAppWidget(appWidgetId, mAddScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800678 break;
Mike Clerona0618e42009-10-22 13:55:21 -0700679 case REQUEST_PICK_WALLPAPER:
680 // We just wanted the activity result here so we can clear mWaitingForResult
681 break;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800682 }
Romain Guy18042c82009-11-06 11:44:55 -0800683 } else if ((requestCode == REQUEST_PICK_APPWIDGET ||
684 requestCode == REQUEST_CREATE_APPWIDGET) && resultCode == RESULT_CANCELED &&
685 data != null) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700686 // Clean up the appWidgetId if we canceled
687 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
688 if (appWidgetId != -1) {
689 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800690 }
691 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800692 }
693
694 @Override
695 protected void onResume() {
696 super.onResume();
697
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800698 mPaused = false;
Joe Onorato7e4ed992009-12-03 13:10:49 -0800699
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800700 if (mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400701 mWorkspaceLoading = true;
702 mModel.startLoader(this, true);
703 mRestoring = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800704 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700705 // When we resume Launcher, a different Activity might be responsible for the app
706 // market intent, so refresh the icon
707 updateAppMarketIcon();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800708 }
709
710 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700711 protected void onPause() {
712 super.onPause();
Michael Jurkaaf442092010-06-10 17:01:57 -0700713 // Some launcher layouts don't have a previous and next view
714 if (mPreviousView != null) {
715 dismissPreview(mPreviousView);
Patrick Dubroyab962b72010-07-26 12:10:10 -0700716 }
717 if (mNextView != null) {
Michael Jurkaaf442092010-06-10 17:01:57 -0700718 dismissPreview(mNextView);
719 }
Joe Onorato24b6fd82009-11-12 13:47:09 -0800720 mDragController.cancelDrag();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700721 }
Romain Guycbb89e42009-06-08 15:52:54 -0700722
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700723 @Override
724 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400725 // Flag the loader to stop early before switching
726 mModel.stopLoader();
Romain Guy13c2e7b2010-03-10 19:45:00 -0800727 mAllAppsGrid.surrender();
Romain Guy13c2e7b2010-03-10 19:45:00 -0800728 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700729 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700730
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800731 // We can't hide the IME if it was forced open. So don't bother
732 /*
733 @Override
734 public void onWindowFocusChanged(boolean hasFocus) {
735 super.onWindowFocusChanged(hasFocus);
736
737 if (hasFocus) {
738 final InputMethodManager inputManager = (InputMethodManager)
739 getSystemService(Context.INPUT_METHOD_SERVICE);
740 WindowManager.LayoutParams lp = getWindow().getAttributes();
741 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
742 android.os.Handler()) {
743 protected void onReceiveResult(int resultCode, Bundle resultData) {
744 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
745 }
746 });
747 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
748 }
749 }
750 */
751
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800752 private boolean acceptFilter() {
753 final InputMethodManager inputManager = (InputMethodManager)
754 getSystemService(Context.INPUT_METHOD_SERVICE);
755 return !inputManager.isFullscreenMode();
756 }
757
758 @Override
759 public boolean onKeyDown(int keyCode, KeyEvent event) {
760 boolean handled = super.onKeyDown(keyCode, event);
761 if (!handled && acceptFilter() && keyCode != KeyEvent.KEYCODE_ENTER) {
762 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
763 keyCode, event);
764 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700765 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700766 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700767 // showSearchDialog()
768 // If there are multiple keystrokes before the search dialog takes focus,
769 // onSearchRequested() will be called for every keystroke,
770 // but it is idempotent, so it's fine.
771 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800772 }
773 }
774
Joe Onorato8a9625e2010-01-28 15:55:35 -0800775 // Eat the long press event so the keyboard doesn't come up.
776 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
777 return true;
778 }
779
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800780 return handled;
781 }
782
Karl Rosaen138a0412009-04-23 19:00:21 -0700783 private String getTypedText() {
784 return mDefaultKeySsb.toString();
785 }
786
787 private void clearTypedText() {
788 mDefaultKeySsb.clear();
789 mDefaultKeySsb.clearSpans();
790 Selection.setSelection(mDefaultKeySsb, 0);
791 }
792
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800793 /**
794 * Restores the previous state, if it exists.
795 *
796 * @param savedState The previous state.
797 */
798 private void restoreState(Bundle savedState) {
799 if (savedState == null) {
800 return;
801 }
802
Joe Onorato3a8820b2009-11-10 15:06:42 -0800803 final boolean allApps = savedState.getBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, false);
804 if (allApps) {
805 showAllApps(false);
806 }
807
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800808 final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
809 if (currentScreen > -1) {
Michael Jurka0142d492010-08-25 17:46:15 -0700810 mWorkspace.setCurrentPage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800811 }
812
813 final int addScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700814
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800815 if (addScreen > -1) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700816 mAddScreen = addScreen;
817 mAddIntersectCellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
818 mAddIntersectCellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800819 mRestoring = true;
820 }
821
822 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
823 if (renameFolder) {
824 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700825 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800826 mRestoring = true;
827 }
828 }
829
830 /**
831 * Finds all the views we need and configure them properly.
832 */
833 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700834 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -0400835
Romain Guyb1b69f52009-08-10 15:10:15 -0700836 DragLayer dragLayer = (DragLayer) findViewById(R.id.drag_layer);
Joe Onorato00acb122009-08-04 16:04:30 -0400837 dragLayer.setDragController(dragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800838
Joe Onorato7c312c12009-08-13 21:36:53 -0700839 mAllAppsGrid = (AllAppsView)dragLayer.findViewById(R.id.all_apps_view);
Joe Onorato6665c0f2009-09-02 15:27:24 -0700840 mAllAppsGrid.setLauncher(this);
Joe Onorato5162ea92009-09-03 09:39:42 -0700841 mAllAppsGrid.setDragController(dragController);
Romain Guyc16fea72010-03-12 17:17:56 -0800842 ((View) mAllAppsGrid).setWillNotDraw(false); // We don't want a hole punched in our window.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700843 // Manage focusability manually since this thing is always visible (in non-xlarge)
Winson Chungaafa03c2010-06-11 17:34:16 -0700844 ((View) mAllAppsGrid).setFocusable(false);
Joe Onorato7c312c12009-08-13 21:36:53 -0700845
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700846 if (LauncherApplication.isScreenXLarge()) {
847 // They need to be INVISIBLE initially so that they will be measured in the layout.
848 // Otherwise the animations are messed up when we show them for the first time.
849 ((View) mAllAppsGrid).setVisibility(View.INVISIBLE);
850 mHomeCustomizationDrawer.setVisibility(View.INVISIBLE);
851 }
852
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800853 mWorkspace = (Workspace) dragLayer.findViewById(R.id.workspace);
854 final Workspace workspace = mWorkspace;
Joe Onoratof0dde092010-02-16 18:25:23 -0500855 workspace.setHapticFeedbackEnabled(false);
Michael Jurka946ad472010-07-09 18:05:18 -0700856
Joe Onorato7c312c12009-08-13 21:36:53 -0700857 DeleteZone deleteZone = (DeleteZone) dragLayer.findViewById(R.id.delete_zone);
858 mDeleteZone = deleteZone;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800859
Michael Jurka2c3af5f2010-08-03 13:53:20 -0700860 View handleView = findViewById(R.id.all_apps_button);
861 if (handleView != null && handleView instanceof HandleView) {
862 // we don't use handle view in xlarge mode
Michael Jurka7ef4f752010-08-03 16:04:26 -0700863 mHandleView = (HandleView)handleView;
Michael Jurka2c3af5f2010-08-03 13:53:20 -0700864 mHandleView.setLauncher(this);
865 mHandleView.setOnClickListener(this);
866 mHandleView.setOnLongClickListener(this);
867 }
Romain Guy1fbc1c82009-11-09 20:43:08 -0800868
Winson Chung80baf5a2010-08-09 16:03:15 -0700869 if (mCustomizePagedView != null) {
870 mCustomizePagedView.setLauncher(this);
871 mCustomizePagedView.setDragController(dragController);
872 mCustomizePagedView.update();
Michael Jurkaaf442092010-06-10 17:01:57 -0700873 } else {
874 ImageView hotseatLeft = (ImageView) findViewById(R.id.hotseat_left);
875 hotseatLeft.setContentDescription(mHotseatLabels[0]);
876 hotseatLeft.setImageDrawable(mHotseatIcons[0]);
877 ImageView hotseatRight = (ImageView) findViewById(R.id.hotseat_right);
878 hotseatRight.setContentDescription(mHotseatLabels[1]);
879 hotseatRight.setImageDrawable(mHotseatIcons[1]);
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400880
Michael Jurkaaf442092010-06-10 17:01:57 -0700881 mPreviousView = (ImageView) dragLayer.findViewById(R.id.previous_screen);
882 mNextView = (ImageView) dragLayer.findViewById(R.id.next_screen);
Romain Guy1fbc1c82009-11-09 20:43:08 -0800883
Michael Jurkaaf442092010-06-10 17:01:57 -0700884 Drawable previous = mPreviousView.getDrawable();
885 Drawable next = mNextView.getDrawable();
886 mWorkspace.setIndicators(previous, next);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800887
Michael Jurkaaf442092010-06-10 17:01:57 -0700888 mPreviousView.setHapticFeedbackEnabled(false);
889 mPreviousView.setOnLongClickListener(this);
890 mNextView.setHapticFeedbackEnabled(false);
891 mNextView.setOnLongClickListener(this);
892 }
Romain Guy1fbc1c82009-11-09 20:43:08 -0800893
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800894 workspace.setOnLongClickListener(this);
Joe Onorato00acb122009-08-04 16:04:30 -0400895 workspace.setDragController(dragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800896 workspace.setLauncher(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800897
898 deleteZone.setLauncher(this);
Joe Onorato00acb122009-08-04 16:04:30 -0400899 deleteZone.setDragController(dragController);
Michael Jurka54f7ac32010-08-02 13:56:46 -0700900 int deleteZoneHandleId;
901 if (LauncherApplication.isScreenXLarge()) {
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700902 deleteZoneHandleId = R.id.all_apps_button;
Michael Jurka54f7ac32010-08-02 13:56:46 -0700903 } else {
904 deleteZoneHandleId = R.id.all_apps_button_cluster;
905 }
Michael Jurkaaf442092010-06-10 17:01:57 -0700906 deleteZone.setHandle(findViewById(deleteZoneHandleId));
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700907 dragController.addDragListener(deleteZone);
908
909 ApplicationInfoDropTarget infoButton = (ApplicationInfoDropTarget)findViewById(R.id.info_button);
910 if (infoButton != null) {
911 infoButton.setLauncher(this);
912 infoButton.setHandle(findViewById(R.id.configure_button));
913 infoButton.setDragColor(getResources().getColor(R.color.app_info_filter));
914 dragController.addDragListener(infoButton);
915 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800916
Joe Onorato00acb122009-08-04 16:04:30 -0400917 dragController.setDragScoller(workspace);
Joe Onorato00acb122009-08-04 16:04:30 -0400918 dragController.setScrollView(dragLayer);
Romain Guyea3763c2010-01-11 18:02:04 -0800919 dragController.setMoveTarget(workspace);
Jason Samsfd22dac2009-09-20 17:24:16 -0700920
Joe Onorato00acb122009-08-04 16:04:30 -0400921 // The order here is bottom to top.
922 dragController.addDropTarget(workspace);
923 dragController.addDropTarget(deleteZone);
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700924 if (infoButton != null) {
925 dragController.addDropTarget(infoButton);
926 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800927 }
928
Romain Guy8a73c512009-11-09 19:19:59 -0800929 @SuppressWarnings({"UnusedDeclaration"})
930 public void previousScreen(View v) {
Joe Onorato61597bd2009-11-19 12:51:57 -0800931 if (!isAllAppsVisible()) {
932 mWorkspace.scrollLeft();
933 }
Romain Guy8a73c512009-11-09 19:19:59 -0800934 }
935
936 @SuppressWarnings({"UnusedDeclaration"})
937 public void nextScreen(View v) {
Joe Onorato61597bd2009-11-19 12:51:57 -0800938 if (!isAllAppsVisible()) {
939 mWorkspace.scrollRight();
940 }
Romain Guy8a73c512009-11-09 19:19:59 -0800941 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400942
943 @SuppressWarnings({"UnusedDeclaration"})
944 public void launchHotSeat(View v) {
Daniel Sandler3e9454a2010-05-24 11:22:41 -0400945 if (isAllAppsVisible()) return;
946
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400947 int index = -1;
948 if (v.getId() == R.id.hotseat_left) {
949 index = 0;
950 } else if (v.getId() == R.id.hotseat_right) {
951 index = 1;
952 }
953
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400954 // reload these every tap; you never know when they might change
955 loadHotseats();
956 if (index >= 0 && index < mHotseats.length && mHotseats[index] != null) {
957 Intent intent = mHotseats[index];
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400958 startActivitySafely(
959 mHotseats[index],
960 "hotseat"
961 );
962 }
963 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700964
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800965 /**
966 * Creates a view representing a shortcut.
967 *
968 * @param info The data structure describing the shortcut.
969 *
970 * @return A View inflated from R.layout.application.
971 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800972 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800973 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -0700974 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800975 }
976
977 /**
978 * Creates a view representing a shortcut inflated from the specified resource.
979 *
980 * @param layoutResId The id of the XML layout used to create the shortcut.
981 * @param parent The group the shortcut belongs to.
982 * @param info The data structure describing the shortcut.
983 *
984 * @return A View inflated from layoutResId.
985 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800986 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800987 TextView favorite = (TextView) mInflater.inflate(layoutResId, parent, false);
988
Joe Onorato0589f0f2010-02-08 13:44:00 -0800989 favorite.setCompoundDrawablesWithIntrinsicBounds(null,
990 new FastBitmapDrawable(info.getIcon(mIconCache)),
991 null, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800992 favorite.setText(info.title);
993 favorite.setTag(info);
994 favorite.setOnClickListener(this);
995
996 return favorite;
997 }
998
999 /**
1000 * Add an application shortcut to the workspace.
1001 *
1002 * @param data The intent describing the application.
1003 * @param cellInfo The position on screen where to create the shortcut.
1004 */
Michael Jurka0280c3b2010-09-17 15:00:07 -07001005 void completeAddApplication(Context context, Intent data, int screen,
1006 int intersectCellX, int intersectCellY) {
1007 final int[] cellXY = mTmpAddItemCellCoordinates;
1008 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1009
1010 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1011 showOutOfSpaceMessage();
1012 return;
1013 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001014
Joe Onorato0589f0f2010-02-08 13:44:00 -08001015 final ShortcutInfo info = mModel.getShortcutInfo(context.getPackageManager(),
1016 data, context);
1017
Romain Guy73b979d2009-06-09 12:57:21 -07001018 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -08001019 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001020 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001021 info.container = ItemInfo.NO_ID;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001022 mWorkspace.addApplicationShortcut(info, screen, cellXY[0], cellXY[1],
1023 isWorkspaceLocked(), mAddIntersectCellX, mAddIntersectCellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001024 } else {
1025 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001026 }
1027 }
Romain Guycbb89e42009-06-08 15:52:54 -07001028
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001029 /**
1030 * Add a shortcut to the workspace.
1031 *
1032 * @param data The intent describing the shortcut.
1033 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001034 */
Michael Jurka0280c3b2010-09-17 15:00:07 -07001035 private void completeAddShortcut(Intent data, int screen,
1036 int intersectCellX, int intersectCellY) {
1037 final int[] cellXY = mTmpAddItemCellCoordinates;
1038 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
Romain Guycbb89e42009-06-08 15:52:54 -07001039
Michael Jurka0280c3b2010-09-17 15:00:07 -07001040 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1041 showOutOfSpaceMessage();
1042 return;
1043 }
1044
1045 final ShortcutInfo info = mModel.addShortcut(
1046 this, data, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001047
1048 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001049 final View view = createShortcut(info);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001050 mWorkspace.addInScreen(view, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001051 }
1052 }
1053
Romain Guycbb89e42009-06-08 15:52:54 -07001054
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001055 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001056 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001057 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001058 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001059 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001060 */
Michael Jurka0280c3b2010-09-17 15:00:07 -07001061 private void completeAddAppWidget(int appWidgetId, int screen) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001062 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Romain Guycbb89e42009-06-08 15:52:54 -07001063
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001064 // Calculate the grid spans needed to fit this widget
Michael Jurka0280c3b2010-09-17 15:00:07 -07001065 CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1066 int[] spanXY = layout.rectToCell(appWidgetInfo.minWidth, appWidgetInfo.minHeight, null);
Romain Guycbb89e42009-06-08 15:52:54 -07001067
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001068 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001069 // We have saved the position to which the widget was dragged-- this really only matters
1070 // if we are placing widgets on a "spring-loaded" screen
Michael Jurka0280c3b2010-09-17 15:00:07 -07001071 final int[] cellXY = mTmpAddItemCellCoordinates;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001072
1073 // For now, we don't save the coordinate where we dropped the icon because we're not
1074 // supporting spring-loaded mini-screens; however, leaving the ability to directly place
1075 // a widget on the home screen in case we want to add it in the future
Michael Jurka0280c3b2010-09-17 15:00:07 -07001076 final int[] touchXY = null;
1077 //final int[] touchXY = mAddDropPosition;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001078 boolean findNearestVacantAreaFailed = false;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001079 boolean foundCellSpan = false;
1080 if (touchXY != null) {
1081 // when dragging and dropping, just find the closest free spot
1082 CellLayout screenLayout = (CellLayout) mWorkspace.getChildAt(screen);
1083 int[] result = screenLayout.findNearestVacantArea(
1084 touchXY[0], touchXY[1], spanXY[0], spanXY[1], cellXY);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001085 findNearestVacantAreaFailed = (result == null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001086 foundCellSpan = !findNearestVacantAreaFailed;
1087 } else {
1088 if (mAddIntersectCellX != -1 && mAddIntersectCellY != -1) {
1089 // if we long pressed on an empty cell to bring up a menu,
1090 // make sure we intersect the empty cell
1091 foundCellSpan = layout.findCellForSpanThatIntersects(cellXY, spanXY[0], spanXY[1],
1092 mAddIntersectCellX, mAddIntersectCellY);
1093 } else {
1094 // if we went through the menu -> add, just find any spot
1095 foundCellSpan = layout.findCellForSpan(cellXY, spanXY[0], spanXY[1]);
1096 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001097 }
1098
Michael Jurka0280c3b2010-09-17 15:00:07 -07001099 if (!foundCellSpan) {
Romain Guy18042c82009-11-06 11:44:55 -08001100 if (appWidgetId != -1) mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001101 showOutOfSpaceMessage();
Romain Guy18042c82009-11-06 11:44:55 -08001102 return;
1103 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001104
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001105 // Build Launcher-specific widget info and save to database
1106 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001107 launcherInfo.spanX = spanXY[0];
1108 launcherInfo.spanY = spanXY[1];
Romain Guycbb89e42009-06-08 15:52:54 -07001109
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001110 LauncherModel.addItemToDatabase(this, launcherInfo,
1111 LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001112 screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001113
1114 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001115 mDesktopItems.add(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001116
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001117 // Perform actual inflation because we're live
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001118 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001119
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001120 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001121 launcherInfo.hostView.setTag(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001122
Michael Jurka0280c3b2010-09-17 15:00:07 -07001123 mWorkspace.addInScreen(launcherInfo.hostView, screen, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001124 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001125 }
1126 }
Romain Guycbb89e42009-06-08 15:52:54 -07001127
Michael Jurka0280c3b2010-09-17 15:00:07 -07001128 void showOutOfSpaceMessage() {
1129 Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show();
1130 }
1131
Joe Onorato9c1289c2009-08-17 11:03:03 -04001132 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
1133 mDesktopItems.remove(launcherInfo);
1134 launcherInfo.hostView = null;
1135 }
1136
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001137 public LauncherAppWidgetHost getAppWidgetHost() {
1138 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001139 }
Romain Guycbb89e42009-06-08 15:52:54 -07001140
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001141 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001142 getWindow().closeAllPanels();
1143
1144 try {
1145 dismissDialog(DIALOG_CREATE_SHORTCUT);
1146 // Unlock the workspace if the dialog was showing
1147 } catch (Exception e) {
1148 // An exception is thrown if the dialog is not visible, which is fine
1149 }
1150
1151 try {
1152 dismissDialog(DIALOG_RENAME_FOLDER);
1153 // Unlock the workspace if the dialog was showing
1154 } catch (Exception e) {
1155 // An exception is thrown if the dialog is not visible, which is fine
1156 }
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001157
1158 // Whatever we were doing is hereby canceled.
1159 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001160 }
1161
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001162 @Override
1163 protected void onNewIntent(Intent intent) {
1164 super.onNewIntent(intent);
1165
1166 // Close the menu
1167 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001168 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001169 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001170
Joe Onorato14f122b2009-11-19 14:06:36 -08001171 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1172 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
1173 boolean allAppsVisible = isAllAppsVisible();
Michael Jurka01f0ed42010-08-20 00:41:17 -07001174 boolean customizationDrawerVisible = isCustomizationDrawerVisible();
1175
Michael Jurka4cb37242010-08-09 21:05:32 -07001176 // in all these cases, only animate if we're already on home
1177 if (LauncherApplication.isScreenXLarge()) {
Michael Jurka99229f62010-09-09 11:49:32 -07001178 mWorkspace.unshrink(alreadyOnHome);
1179 }
1180 if (!mWorkspace.isDefaultPageShowing()) {
Michael Jurka4cb37242010-08-09 21:05:32 -07001181 // on the phone, we don't animate the change to the workspace if all apps is visible
Michael Jurka99229f62010-09-09 11:49:32 -07001182 mWorkspace.moveToDefaultScreen(
1183 alreadyOnHome && (LauncherApplication.isScreenXLarge() || !allAppsVisible));
Joe Onorato3a8820b2009-11-10 15:06:42 -08001184 }
Joe Onorato14f122b2009-11-19 14:06:36 -08001185 closeAllApps(alreadyOnHome && allAppsVisible);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07001186 hideCustomizationDrawer(alreadyOnHome);
Romain Guy1dd3a072009-07-16 13:21:01 -07001187
Joe Onorato3a8820b2009-11-10 15:06:42 -08001188 final View v = getWindow().peekDecorView();
1189 if (v != null && v.getWindowToken() != null) {
1190 InputMethodManager imm = (InputMethodManager)getSystemService(
1191 INPUT_METHOD_SERVICE);
1192 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001193 }
1194 }
1195 }
1196
1197 @Override
1198 protected void onRestoreInstanceState(Bundle savedInstanceState) {
1199 // Do not call super here
1200 mSavedInstanceState = savedInstanceState;
Michael Jurka946ad472010-07-09 18:05:18 -07001201
1202 if (mHomeCustomizationDrawer != null) {
1203 String cur = savedInstanceState.getString("currentTab");
1204 if (cur != null) {
1205 mHomeCustomizationDrawer.setCurrentTabByTag(cur);
1206 }
1207 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001208 }
1209
1210 @Override
1211 protected void onSaveInstanceState(Bundle outState) {
Michael Jurka0142d492010-08-25 17:46:15 -07001212 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001213
1214 final ArrayList<Folder> folders = mWorkspace.getOpenFolders();
1215 if (folders.size() > 0) {
1216 final int count = folders.size();
1217 long[] ids = new long[count];
1218 for (int i = 0; i < count; i++) {
1219 final FolderInfo info = folders.get(i).getInfo();
1220 ids[i] = info.id;
1221 }
1222 outState.putLongArray(RUNTIME_STATE_USER_FOLDERS, ids);
1223 } else {
1224 super.onSaveInstanceState(outState);
1225 }
1226
Joe Onoratofb0ca672009-09-14 17:55:46 -04001227 // TODO should not do this if the drawer is currently closing.
Joe Onorato3a8820b2009-11-10 15:06:42 -08001228 if (isAllAppsVisible()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001229 outState.putBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, true);
Romain Guy5a941392009-04-28 15:18:25 -07001230 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001231
Michael Jurka0280c3b2010-09-17 15:00:07 -07001232 if (mAddScreen > -1 && mWaitingForResult) {
1233 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mAddScreen);
1234 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mAddIntersectCellX);
1235 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001236 }
1237
1238 if (mFolderInfo != null && mWaitingForResult) {
1239 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1240 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1241 }
Michael Jurka946ad472010-07-09 18:05:18 -07001242
1243 if (mHomeCustomizationDrawer != null) {
1244 String currentTabTag = mHomeCustomizationDrawer.getCurrentTabTag();
1245 if (currentTabTag != null) {
1246 outState.putString("currentTab", currentTabTag);
1247 }
1248 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001249 }
1250
1251 @Override
1252 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001253 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001254
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001255 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001256 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001257 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001258 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001259 }
1260
1261 TextKeyListener.getInstance().release();
1262
Joe Onorato9c1289c2009-08-17 11:03:03 -04001263 mModel.stopLoader();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001264
Joe Onorato9c1289c2009-08-17 11:03:03 -04001265 unbindDesktopItems();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001266
1267 getContentResolver().unregisterContentObserver(mWidgetObserver);
Winson Chungaafa03c2010-06-11 17:34:16 -07001268
Patrick Dubroyab962b72010-07-26 12:10:10 -07001269 // Some launcher layouts don't have a previous and next view
1270 if (mPreviousView != null) {
1271 dismissPreview(mPreviousView);
1272 }
1273 if (mNextView != null) {
1274 dismissPreview(mNextView);
1275 }
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001276
1277 unregisterReceiver(mCloseSystemDialogsReceiver);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001278 }
1279
1280 @Override
1281 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001282 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001283 super.startActivityForResult(intent, requestCode);
1284 }
1285
1286 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001287 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001288 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001289
Joe Onorato7bb17492009-09-24 17:51:01 -07001290 closeAllApps(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001291
Karl Rosaen138a0412009-04-23 19:00:21 -07001292 if (initialQuery == null) {
1293 // Use any text typed in the launcher as the initial query
1294 initialQuery = getTypedText();
1295 clearTypedText();
1296 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001297 if (appSearchData == null) {
1298 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +00001299 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001300 }
Romain Guycbb89e42009-06-08 15:52:54 -07001301
Karl Rosaen138a0412009-04-23 19:00:21 -07001302 final SearchManager searchManager =
1303 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Karl Rosaen138a0412009-04-23 19:00:21 -07001304 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Romain Guycbb89e42009-06-08 15:52:54 -07001305 appSearchData, globalSearch);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001306 }
1307
1308 @Override
1309 public boolean onCreateOptionsMenu(Menu menu) {
Patrick Dubroy5905bca2010-09-08 22:43:38 -07001310 if (isWorkspaceLocked()) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001311 return false;
1312 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001313
1314 super.onCreateOptionsMenu(menu);
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001315
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001316 menu.add(MENU_GROUP_ADD, MENU_ADD, 0, R.string.menu_add)
1317 .setIcon(android.R.drawable.ic_menu_add)
1318 .setAlphabeticShortcut('A');
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001319 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001320 .setIcon(android.R.drawable.ic_menu_gallery)
1321 .setAlphabeticShortcut('W');
1322 menu.add(0, MENU_SEARCH, 0, R.string.menu_search)
1323 .setIcon(android.R.drawable.ic_search_category_default)
1324 .setAlphabeticShortcut(SearchManager.MENU_KEY);
1325 menu.add(0, MENU_NOTIFICATIONS, 0, R.string.menu_notifications)
1326 .setIcon(com.android.internal.R.drawable.ic_menu_notifications)
1327 .setAlphabeticShortcut('N');
1328
1329 final Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
Romain Guy5a941392009-04-28 15:18:25 -07001330 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
1331 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001332
1333 menu.add(0, MENU_SETTINGS, 0, R.string.menu_settings)
1334 .setIcon(android.R.drawable.ic_menu_preferences).setAlphabeticShortcut('P')
1335 .setIntent(settings);
1336
1337 return true;
1338 }
1339
1340 @Override
1341 public boolean onPrepareOptionsMenu(Menu menu) {
1342 super.onPrepareOptionsMenu(menu);
1343
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001344 // If all apps is animating, don't show the menu, because we don't know
1345 // which one to show.
Patrick Dubroyff5f0402010-07-26 15:23:26 -07001346 if (mAllAppsGrid.isAnimating()) {
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001347 return false;
1348 }
1349
1350 // Only show the add and wallpaper options when we're not in all apps.
Patrick Dubroyff5f0402010-07-26 15:23:26 -07001351 boolean visible = !mAllAppsGrid.isVisible();
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001352 menu.setGroupVisible(MENU_GROUP_ADD, visible);
1353 menu.setGroupVisible(MENU_GROUP_WALLPAPER, visible);
1354
1355 // Disable add if the workspace is full.
1356 if (visible) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001357 CellLayout layout = (CellLayout) mWorkspace.getChildAt(mWorkspace.getCurrentPage());
1358 menu.setGroupEnabled(MENU_GROUP_ADD, layout.existsEmptyCell());
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001359 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001360
1361 return true;
1362 }
1363
1364 @Override
1365 public boolean onOptionsItemSelected(MenuItem item) {
1366 switch (item.getItemId()) {
1367 case MENU_ADD:
1368 addItems();
1369 return true;
1370 case MENU_WALLPAPER_SETTINGS:
1371 startWallpaper();
1372 return true;
1373 case MENU_SEARCH:
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001374 onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001375 return true;
1376 case MENU_NOTIFICATIONS:
1377 showNotifications();
1378 return true;
1379 }
1380
1381 return super.onOptionsItemSelected(item);
1382 }
Romain Guycbb89e42009-06-08 15:52:54 -07001383
Karl Rosaen138a0412009-04-23 19:00:21 -07001384 /**
1385 * Indicates that we want global search for this activity by setting the globalSearch
1386 * argument for {@link #startSearch} to true.
1387 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001388
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001389 @Override
1390 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001391 startSearch(null, false, null, true);
Karl Rosaen138a0412009-04-23 19:00:21 -07001392 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001393 }
1394
Joe Onorato9c1289c2009-08-17 11:03:03 -04001395 public boolean isWorkspaceLocked() {
1396 return mWorkspaceLoading || mWaitingForResult;
1397 }
1398
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001399 private void addItems() {
Patrick Dubroy558654c2010-07-23 16:48:11 -07001400 if (LauncherApplication.isScreenXLarge()) {
1401 // Animate the widget chooser up from the bottom of the screen
1402 if (!isCustomizationDrawerVisible()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07001403 showCustomizationDrawer(true);
Patrick Dubroy558654c2010-07-23 16:48:11 -07001404 }
1405 } else {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001406 closeAllApps(true);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001407 showAddDialog(-1, -1);
Patrick Dubroy558654c2010-07-23 16:48:11 -07001408 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001409 }
1410
Michael Jurka0280c3b2010-09-17 15:00:07 -07001411 private void resetAddInfo() {
1412 mAddScreen = -1;
1413 mAddIntersectCellX = -1;
1414 mAddIntersectCellY = -1;
1415 mAddDropPosition = null;
1416 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001417
Michael Jurka0280c3b2010-09-17 15:00:07 -07001418 void addAppWidgetFromDrop(ComponentName appWidgetProvider, int screen, int[] position) {
1419 resetAddInfo();
1420 mAddScreen = screen;
1421
1422 // only set mAddDropPosition if we dropped on home screen in "spring-loaded" manner
1423 mAddDropPosition = position;
1424
Michael Jurkaaf442092010-06-10 17:01:57 -07001425 int appWidgetId = getAppWidgetHost().allocateAppWidgetId();
1426 AppWidgetManager.getInstance(this).bindAppWidgetId(appWidgetId, appWidgetProvider);
1427 addAppWidgetImpl(appWidgetId);
1428 }
1429
1430 void addAppWidgetFromPick(Intent data) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001431 // TODO: catch bad widget exception when sent
1432 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurkaaf442092010-06-10 17:01:57 -07001433 // TODO: Is this log message meaningful?
1434 if (LOGD) Log.d(TAG, "dumping extras content=" + data.getExtras());
1435 addAppWidgetImpl(appWidgetId);
1436 }
1437
1438 void addAppWidgetImpl(int appWidgetId) {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001439 AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001440
Bjorn Bringert7984c942009-12-09 15:38:25 +00001441 if (appWidget.configure != null) {
1442 // Launch over to configure widget, if needed
1443 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
1444 intent.setComponent(appWidget.configure);
1445 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
1446
Romain Guy8e633c52010-03-04 12:51:36 -08001447 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001448 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001449 // Otherwise just add it
Michael Jurka0280c3b2010-09-17 15:00:07 -07001450 completeAddAppWidget(appWidgetId, mAddScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001451 }
1452 }
Romain Guycbb89e42009-06-08 15:52:54 -07001453
Michael Jurka0280c3b2010-09-17 15:00:07 -07001454 void processShortcutFromDrop(ComponentName componentName, int screen, int[] position) {
1455 resetAddInfo();
1456 mAddScreen = screen;
1457 mAddDropPosition = position;
1458
1459 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1460 createShortcutIntent.setComponent(componentName);
1461 processShortcut(createShortcutIntent);
1462 }
1463
Joe Onoratodeb98af2010-02-19 14:59:39 -08001464 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001465 // Handle case where user selected "Applications"
1466 String applicationName = getResources().getString(R.string.group_applications);
1467 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001468
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001469 if (applicationName != null && applicationName.equals(shortcutName)) {
1470 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1471 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001472
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001473 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1474 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Joe Onoratodeb98af2010-02-19 14:59:39 -08001475 startActivityForResult(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001476 } else {
Joe Onoratodeb98af2010-02-19 14:59:39 -08001477 startActivityForResult(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001478 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001479 }
1480
Winson Chung24ab2f12010-09-16 14:10:47 -07001481 void processWallpaper(Intent intent) {
1482 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1483 }
1484
Michael Jurka0280c3b2010-09-17 15:00:07 -07001485 void addLiveFolderFromDrop(ComponentName componentName, int screen, int[] position) {
1486 resetAddInfo();
1487 mAddScreen = screen;
1488 mAddDropPosition = position;
1489
1490 Intent createFolderIntent = new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER);
1491 createFolderIntent.setComponent(componentName);
1492
1493 addLiveFolder(createFolderIntent);
1494 }
1495
1496 void addLiveFolder(Intent intent) { // YYY add screen intersect etc. parameters here
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001497 // Handle case where user selected "Folder"
Jeffrey Sharkeyc4bbd0a2009-03-24 22:47:52 -07001498 String folderName = getResources().getString(R.string.group_folder);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001499 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001500
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001501 if (folderName != null && folderName.equals(shortcutName)) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001502 addFolder(mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001503 } else {
1504 startActivityForResult(intent, REQUEST_CREATE_LIVE_FOLDER);
1505 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001506 }
1507
Michael Jurka0280c3b2010-09-17 15:00:07 -07001508 void addFolder(int screen, int intersectCellX, int intersectCellY) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001509 UserFolderInfo folderInfo = new UserFolderInfo();
1510 folderInfo.title = getText(R.string.folder_name);
1511
Michael Jurka0280c3b2010-09-17 15:00:07 -07001512 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1513 final int[] cellXY = mTmpAddItemCellCoordinates;
1514 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1515 showOutOfSpaceMessage();
1516 return;
1517 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001518
1519 // Update the model
Joe Onorato9c1289c2009-08-17 11:03:03 -04001520 LauncherModel.addItemToDatabase(this, folderInfo,
1521 LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001522 screen, cellXY[0], cellXY[1], false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001523 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001524
1525 // Create the view
1526 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07001527 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), folderInfo);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001528 mWorkspace.addInScreen(newFolder, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001529 }
Romain Guycbb89e42009-06-08 15:52:54 -07001530
Joe Onorato9c1289c2009-08-17 11:03:03 -04001531 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001532 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001533 }
1534
Michael Jurka0280c3b2010-09-17 15:00:07 -07001535 private void completeAddLiveFolder(Intent data, int screen, int intersectCellX, int intersectCellY) {
1536 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1537 final int[] cellXY = mTmpAddItemCellCoordinates;
1538 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1539 showOutOfSpaceMessage();
1540 return;
1541 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001542
Michael Jurka0280c3b2010-09-17 15:00:07 -07001543 final LiveFolderInfo info = addLiveFolder(this, data, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001544
1545 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001546 final View view = LiveFolderIcon.fromXml(R.layout.live_folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07001547 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001548 mWorkspace.addInScreen(view, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001549 }
1550 }
1551
1552 static LiveFolderInfo addLiveFolder(Context context, Intent data,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001553 int screen, int cellX, int cellY, boolean notify) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001554
1555 Intent baseIntent = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT);
1556 String name = data.getStringExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME);
1557
1558 Drawable icon = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001559 Intent.ShortcutIconResource iconResource = null;
1560
1561 Parcelable extra = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON);
1562 if (extra != null && extra instanceof Intent.ShortcutIconResource) {
1563 try {
1564 iconResource = (Intent.ShortcutIconResource) extra;
1565 final PackageManager packageManager = context.getPackageManager();
1566 Resources resources = packageManager.getResourcesForApplication(
1567 iconResource.packageName);
1568 final int id = resources.getIdentifier(iconResource.resourceName, null, null);
1569 icon = resources.getDrawable(id);
1570 } catch (Exception e) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001571 Log.w(TAG, "Could not load live folder icon: " + extra);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001572 }
1573 }
1574
1575 if (icon == null) {
1576 icon = context.getResources().getDrawable(R.drawable.ic_launcher_folder);
1577 }
1578
1579 final LiveFolderInfo info = new LiveFolderInfo();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001580 info.icon = Utilities.createIconBitmap(icon, context);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001581 info.title = name;
1582 info.iconResource = iconResource;
1583 info.uri = data.getData();
1584 info.baseIntent = baseIntent;
1585 info.displayMode = data.getIntExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE,
1586 LiveFolders.DISPLAY_MODE_GRID);
1587
1588 LauncherModel.addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001589 screen, cellX, cellY, notify);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001590 sFolders.put(info.id, info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001591
1592 return info;
1593 }
1594
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001595 private void showNotifications() {
1596 final StatusBarManager statusBar = (StatusBarManager) getSystemService(STATUS_BAR_SERVICE);
1597 if (statusBar != null) {
1598 statusBar.expand();
1599 }
1600 }
1601
1602 private void startWallpaper() {
Joe Onoratoe6168662009-11-08 13:39:30 -05001603 closeAllApps(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001604 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001605 Intent chooser = Intent.createChooser(pickWallpaper,
1606 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001607 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1608 // Removed in Eclair MR1
1609// WallpaperManager wm = (WallpaperManager)
1610// getSystemService(Context.WALLPAPER_SERVICE);
1611// WallpaperInfo wi = wm.getWallpaperInfo();
1612// if (wi != null && wi.getSettingsActivity() != null) {
1613// LabeledIntent li = new LabeledIntent(getPackageName(),
1614// R.string.configure_wallpaper, 0);
1615// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1616// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1617// }
Mike Clerona0618e42009-10-22 13:55:21 -07001618 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001619 }
1620
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001621 /**
1622 * Registers various content observers. The current implementation registers
1623 * only a favorites observer to keep track of the favorites applications.
1624 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001625 private void registerContentObservers() {
1626 ContentResolver resolver = getContentResolver();
1627 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1628 true, mWidgetObserver);
1629 }
1630
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001631 @Override
1632 public boolean dispatchKeyEvent(KeyEvent event) {
1633 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1634 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001635 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001636 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001637 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jason Samseb5615d2009-11-30 11:50:10 -08001638 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
Joe Onoratobe386092009-11-17 17:32:16 -08001639 dumpState();
1640 return true;
1641 }
1642 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001643 }
1644 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1645 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001646 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001647 return true;
1648 }
1649 }
1650
1651 return super.dispatchKeyEvent(event);
1652 }
1653
Joe Onorato88ec0992009-11-19 13:16:06 -08001654 @Override
1655 public void onBackPressed() {
1656 if (isAllAppsVisible()) {
1657 closeAllApps(true);
Patrick Dubroy558654c2010-07-23 16:48:11 -07001658 } else if (isCustomizationDrawerVisible()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07001659 hideCustomizationDrawer(true);
Joe Onorato88ec0992009-11-19 13:16:06 -08001660 } else {
1661 closeFolder();
1662 }
Michael Jurkaaf442092010-06-10 17:01:57 -07001663 // Some launcher layouts don't have a previous and next view
1664 if (mPreviousView != null) {
1665 dismissPreview(mPreviousView);
1666 dismissPreview(mNextView);
1667 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001668 }
1669
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001670 private void closeFolder() {
1671 Folder folder = mWorkspace.getOpenFolder();
1672 if (folder != null) {
1673 closeFolder(folder);
1674 }
1675 }
1676
1677 void closeFolder(Folder folder) {
1678 folder.getInfo().opened = false;
1679 ViewGroup parent = (ViewGroup) folder.getParent();
1680 if (parent != null) {
1681 parent.removeView(folder);
Joe Onoratob6341e92009-11-02 10:41:48 -05001682 if (folder instanceof DropTarget) {
1683 // Live folders aren't DropTargets.
1684 mDragController.removeDropTarget((DropTarget)folder);
1685 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001686 }
1687 folder.onClose();
1688 }
1689
1690 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001691 * Re-listen when widgets are reset.
1692 */
1693 private void onAppWidgetReset() {
1694 mAppWidgetHost.startListening();
1695 }
1696
1697 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001698 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1699 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001700 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04001701 private void unbindDesktopItems() {
1702 for (ItemInfo item: mDesktopItems) {
1703 item.unbind();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001704 }
1705 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001706
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001707 /**
1708 * Launches the intent referred by the clicked shortcut.
1709 *
1710 * @param v The view representing the clicked shortcut.
1711 */
1712 public void onClick(View v) {
1713 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001714 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001715 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08001716 final Intent intent = ((ShortcutInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001717 int[] pos = new int[2];
1718 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08001719 intent.setSourceBounds(new Rect(pos[0], pos[1],
1720 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Joe Onoratof984e852010-03-25 09:47:45 -07001721 startActivitySafely(intent, tag);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001722 } else if (tag instanceof FolderInfo) {
1723 handleFolderClick((FolderInfo) tag);
Joe Onorato7404ee42009-07-31 11:54:44 -07001724 } else if (v == mHandleView) {
Joe Onoratofb0ca672009-09-14 17:55:46 -04001725 if (isAllAppsVisible()) {
Joe Onorato7bb17492009-09-24 17:51:01 -07001726 closeAllApps(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001727 } else {
Joe Onorato3a8820b2009-11-10 15:06:42 -08001728 showAllApps(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001729 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001730 }
1731 }
1732
Michael Jurka0e260592010-06-30 17:07:39 -07001733 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07001734 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurka0e260592010-06-30 17:07:39 -07001735 // clicking anywhere on the workspace causes the drawer to slide down
Patrick Dubroy6b509c12010-08-23 15:08:16 -07001736 hideCustomizationDrawer(true);
Michael Jurka0e260592010-06-30 17:07:39 -07001737 return false;
1738 }
1739
Michael Jurkaaf442092010-06-10 17:01:57 -07001740 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001741 * Event handler for the search button
1742 *
1743 * @param v The view that was clicked.
1744 */
1745 public void onClickSearchButton(View v) {
1746 Intent i = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
1747 View button = findViewById(R.id.search_button);
1748 i.setSourceBounds(
1749 new Rect(button.getLeft(), button.getTop(), button.getRight(), button.getBottom()));
1750 startActivity(i);
1751 }
1752
1753 /**
1754 * Event handler for the "gear" button that appears on the home screen, which
Michael Jurkaaf442092010-06-10 17:01:57 -07001755 * enters home screen customization mode.
1756 *
1757 * @param v The view that was clicked.
1758 */
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001759 public void onClickConfigureButton(View v) {
Patrick Dubroy558654c2010-07-23 16:48:11 -07001760 addItems();
Michael Jurkaaf442092010-06-10 17:01:57 -07001761 }
1762
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001763 /**
1764 * Event handler for the "grid" button that appears on the home screen, which
1765 * enters all apps mode.
1766 *
1767 * @param v The view that was clicked.
1768 */
1769 public void onClickAllAppsButton(View v) {
1770 showAllApps(true);
1771 }
1772
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001773 public void onClickAppMarketButton(View v) {
1774 if (mAppMarketIntent != null) {
1775 startActivitySafely(mAppMarketIntent, "app market");
1776 }
1777 }
1778
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001779 void startApplicationDetailsActivity(ComponentName componentName) {
1780 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001781 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
1782 Uri.fromParts("package", packageName, null));
1783 startActivity(intent);
1784 }
1785
Patrick Dubroy5539af72010-09-07 15:22:01 -07001786 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
1787 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
1788 // System applications cannot be installed. For now, show a toast explaining that.
1789 // We may give them the option of disabling apps this way.
1790 int messageId = R.string.uninstall_system_app_text;
1791 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
1792 } else {
1793 String packageName = appInfo.componentName.getPackageName();
1794 String className = appInfo.componentName.getClassName();
1795 Intent intent = new Intent(
1796 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
1797 startActivity(intent);
1798 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001799 }
1800
Joe Onoratof984e852010-03-25 09:47:45 -07001801 void startActivitySafely(Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001802 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1803 try {
1804 startActivity(intent);
1805 } catch (ActivityNotFoundException e) {
1806 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Daniel Sandlerc9b18772010-04-22 14:37:59 -04001807 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001808 } catch (SecurityException e) {
1809 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001810 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001811 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07001812 "or use the exported attribute for this activity. "
1813 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001814 }
1815 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001816
Romain Guy8e633c52010-03-04 12:51:36 -08001817 void startActivityForResultSafely(Intent intent, int requestCode) {
1818 try {
1819 startActivityForResult(intent, requestCode);
1820 } catch (ActivityNotFoundException e) {
1821 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1822 } catch (SecurityException e) {
1823 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1824 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
1825 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
1826 "or use the exported attribute for this activity.", e);
1827 }
1828 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001829
1830 private void handleFolderClick(FolderInfo folderInfo) {
1831 if (!folderInfo.opened) {
1832 // Close any open folder
1833 closeFolder();
1834 // Open the requested folder
1835 openFolder(folderInfo);
1836 } else {
1837 // Find the open folder...
1838 Folder openFolder = mWorkspace.getFolderForTag(folderInfo);
1839 int folderScreen;
1840 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07001841 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001842 // .. and close it
1843 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07001844 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001845 // Close any folder open on the current screen
1846 closeFolder();
1847 // Pull the folder onto this screen
1848 openFolder(folderInfo);
1849 }
1850 }
1851 }
1852 }
1853
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001854 /**
1855 * Opens the user fodler described by the specified tag. The opening of the folder
1856 * is animated relative to the specified View. If the View is null, no animation
1857 * is played.
1858 *
1859 * @param folderInfo The FolderInfo describing the folder to open.
1860 */
Winson Chungaafa03c2010-06-11 17:34:16 -07001861 public void openFolder(FolderInfo folderInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001862 Folder openFolder;
1863
1864 if (folderInfo instanceof UserFolderInfo) {
1865 openFolder = UserFolder.fromXml(this);
1866 } else if (folderInfo instanceof LiveFolderInfo) {
Joe Onoratoa5902522009-07-30 13:37:37 -07001867 openFolder = com.android.launcher2.LiveFolder.fromXml(this, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001868 } else {
1869 return;
1870 }
1871
Joe Onorato00acb122009-08-04 16:04:30 -04001872 openFolder.setDragController(mDragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001873 openFolder.setLauncher(this);
1874
1875 openFolder.bind(folderInfo);
1876 folderInfo.opened = true;
1877
Winson Chungaafa03c2010-06-11 17:34:16 -07001878 mWorkspace.addInFullScreen(openFolder, folderInfo.screen);
1879
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001880 openFolder.onOpen();
1881 }
1882
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001883 public boolean onLongClick(View v) {
Romain Guy1fbc1c82009-11-09 20:43:08 -08001884 switch (v.getId()) {
1885 case R.id.previous_screen:
Joe Onorato0d44e942009-11-16 18:20:51 -08001886 if (!isAllAppsVisible()) {
1887 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1888 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Romain Guyf8e6a802009-12-07 17:48:02 -08001889 showPreviews(v);
Joe Onorato0d44e942009-11-16 18:20:51 -08001890 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08001891 return true;
1892 case R.id.next_screen:
Joe Onorato0d44e942009-11-16 18:20:51 -08001893 if (!isAllAppsVisible()) {
1894 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1895 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Romain Guyf8e6a802009-12-07 17:48:02 -08001896 showPreviews(v);
1897 }
1898 return true;
1899 case R.id.all_apps_button:
1900 if (!isAllAppsVisible()) {
1901 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1902 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
1903 showPreviews(v);
Joe Onorato0d44e942009-11-16 18:20:51 -08001904 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08001905 return true;
1906 }
1907
Joe Onorato9c1289c2009-08-17 11:03:03 -04001908 if (isWorkspaceLocked()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001909 return false;
1910 }
1911
1912 if (!(v instanceof CellLayout)) {
1913 v = (View) v.getParent();
1914 }
1915
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001916
Michael Jurka0280c3b2010-09-17 15:00:07 -07001917 resetAddInfo();
1918 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001919 // This happens when long clicking an item with the dpad/trackball
Michael Jurka0280c3b2010-09-17 15:00:07 -07001920 if (longClickCellInfo == null || !longClickCellInfo.valid) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001921 return true;
1922 }
1923
Michael Jurka0280c3b2010-09-17 15:00:07 -07001924 final View itemUnderLongClick = longClickCellInfo.cell;
1925
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001926 if (mWorkspace.allowLongPress()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001927 if (itemUnderLongClick == null) {
1928 // User long pressed on empty space
1929 mWorkspace.setAllowLongPress(false);
1930 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1931 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
1932 if (LauncherApplication.isScreenXLarge()) {
1933 // Animate the widget chooser up from the bottom of the screen
1934 if (!isCustomizationDrawerVisible()) {
1935 showCustomizationDrawer(true);
1936 }
1937 } else {
1938 showAddDialog(longClickCellInfo.cellX, longClickCellInfo.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001939 }
1940 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001941 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001942 // User long pressed on an item
Joe Onorato0d44e942009-11-16 18:20:51 -08001943 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1944 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001945 mAddIntersectCellX = longClickCellInfo.cellX;
1946 mAddIntersectCellY = longClickCellInfo.cellY;
1947 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001948 }
1949 }
1950 }
1951 return true;
1952 }
1953
Romain Guye6b8e2f2009-11-10 11:56:55 -08001954 @SuppressWarnings({"unchecked"})
Romain Guy9d31e9f2009-11-11 18:54:28 -08001955 private void dismissPreview(final View v) {
1956 final PopupWindow window = (PopupWindow) v.getTag();
Romain Guy1fbc1c82009-11-09 20:43:08 -08001957 if (window != null) {
Romain Guy9d31e9f2009-11-11 18:54:28 -08001958 window.setOnDismissListener(new PopupWindow.OnDismissListener() {
1959 public void onDismiss() {
1960 ViewGroup group = (ViewGroup) v.getTag(R.id.workspace);
1961 int count = group.getChildCount();
1962 for (int i = 0; i < count; i++) {
1963 ((ImageView) group.getChildAt(i)).setImageDrawable(null);
1964 }
Romain Guy9d31e9f2009-11-11 18:54:28 -08001965 ArrayList<Bitmap> bitmaps = (ArrayList<Bitmap>) v.getTag(R.id.icon);
1966 for (Bitmap bitmap : bitmaps) bitmap.recycle();
1967
1968 v.setTag(R.id.workspace, null);
1969 v.setTag(R.id.icon, null);
1970 window.setOnDismissListener(null);
1971 }
1972 });
Romain Guy1fbc1c82009-11-09 20:43:08 -08001973 window.dismiss();
Romain Guy1fbc1c82009-11-09 20:43:08 -08001974 }
1975 v.setTag(null);
1976 }
1977
Romain Guyf8e6a802009-12-07 17:48:02 -08001978 private void showPreviews(View anchor) {
Romain Guy9d31e9f2009-11-11 18:54:28 -08001979 showPreviews(anchor, 0, mWorkspace.getChildCount());
Romain Guy1fbc1c82009-11-09 20:43:08 -08001980 }
1981
Romain Guya6abce82009-11-10 02:54:41 -08001982 private void showPreviews(final View anchor, int start, int end) {
Romain Guyf8e6a802009-12-07 17:48:02 -08001983 final Resources resources = getResources();
1984 final Workspace workspace = mWorkspace;
Romain Guy1fbc1c82009-11-09 20:43:08 -08001985
Romain Guya6abce82009-11-10 02:54:41 -08001986 CellLayout cell = ((CellLayout) workspace.getChildAt(start));
Winson Chungaafa03c2010-06-11 17:34:16 -07001987
Romain Guy9d31e9f2009-11-11 18:54:28 -08001988 float max = workspace.getChildCount();
Winson Chungaafa03c2010-06-11 17:34:16 -07001989
Romain Guyf8e6a802009-12-07 17:48:02 -08001990 final Rect r = new Rect();
Romain Guy9d31e9f2009-11-11 18:54:28 -08001991 resources.getDrawable(R.drawable.preview_background).getPadding(r);
Romain Guye6b8e2f2009-11-10 11:56:55 -08001992 int extraW = (int) ((r.left + r.right) * max);
1993 int extraH = r.top + r.bottom;
Romain Guya6abce82009-11-10 02:54:41 -08001994
1995 int aW = cell.getWidth() - extraW;
1996 float w = aW / max;
1997
1998 int width = cell.getWidth();
1999 int height = cell.getHeight();
2000 int x = cell.getLeftPadding();
2001 int y = cell.getTopPadding();
2002 width -= (x + cell.getRightPadding());
2003 height -= (y + cell.getBottomPadding());
2004
2005 float scale = w / width;
2006
2007 int count = end - start;
2008
2009 final float sWidth = width * scale;
2010 float sHeight = height * scale;
2011
Romain Guye6b8e2f2009-11-10 11:56:55 -08002012 LinearLayout preview = new LinearLayout(this);
Romain Guya6abce82009-11-10 02:54:41 -08002013
Romain Guye6b8e2f2009-11-10 11:56:55 -08002014 PreviewTouchHandler handler = new PreviewTouchHandler(anchor);
2015 ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>(count);
Romain Guya6abce82009-11-10 02:54:41 -08002016
2017 for (int i = start; i < end; i++) {
Romain Guye6b8e2f2009-11-10 11:56:55 -08002018 ImageView image = new ImageView(this);
Romain Guya6abce82009-11-10 02:54:41 -08002019 cell = (CellLayout) workspace.getChildAt(i);
2020
Romain Guyf8e6a802009-12-07 17:48:02 -08002021 final Bitmap bitmap = Bitmap.createBitmap((int) sWidth, (int) sHeight,
Romain Guye6b8e2f2009-11-10 11:56:55 -08002022 Bitmap.Config.ARGB_8888);
Romain Guyf8e6a802009-12-07 17:48:02 -08002023
2024 final Canvas c = new Canvas(bitmap);
Romain Guya6abce82009-11-10 02:54:41 -08002025 c.scale(scale, scale);
2026 c.translate(-cell.getLeftPadding(), -cell.getTopPadding());
2027 cell.dispatchDraw(c);
Romain Guya6abce82009-11-10 02:54:41 -08002028
Romain Guy9d31e9f2009-11-11 18:54:28 -08002029 image.setBackgroundDrawable(resources.getDrawable(R.drawable.preview_background));
Romain Guye6b8e2f2009-11-10 11:56:55 -08002030 image.setImageBitmap(bitmap);
2031 image.setTag(i);
2032 image.setOnClickListener(handler);
Romain Guy9d31e9f2009-11-11 18:54:28 -08002033 image.setOnFocusChangeListener(handler);
2034 image.setFocusable(true);
Michael Jurka0142d492010-08-25 17:46:15 -07002035 if (i == mWorkspace.getCurrentPage()) image.requestFocus();
Romain Guye6b8e2f2009-11-10 11:56:55 -08002036
2037 preview.addView(image,
Romain Guy9d31e9f2009-11-11 18:54:28 -08002038 LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
2039
Winson Chungaafa03c2010-06-11 17:34:16 -07002040 bitmaps.add(bitmap);
Romain Guya6abce82009-11-10 02:54:41 -08002041 }
Romain Guyf8e6a802009-12-07 17:48:02 -08002042
2043 final PopupWindow p = new PopupWindow(this);
Romain Guye6b8e2f2009-11-10 11:56:55 -08002044 p.setContentView(preview);
2045 p.setWidth((int) (sWidth * count + extraW));
2046 p.setHeight((int) (sHeight + extraH));
2047 p.setAnimationStyle(R.style.AnimationPreview);
2048 p.setOutsideTouchable(true);
Romain Guy9d31e9f2009-11-11 18:54:28 -08002049 p.setFocusable(true);
Romain Guyff0c2e22009-11-10 12:09:59 -08002050 p.setBackgroundDrawable(new ColorDrawable(0));
Romain Guy9d31e9f2009-11-11 18:54:28 -08002051 p.showAsDropDown(anchor, 0, 0);
Romain Guya6abce82009-11-10 02:54:41 -08002052
Romain Guye6b8e2f2009-11-10 11:56:55 -08002053 p.setOnDismissListener(new PopupWindow.OnDismissListener() {
2054 public void onDismiss() {
2055 dismissPreview(anchor);
2056 }
2057 });
Romain Guy1fbc1c82009-11-09 20:43:08 -08002058
2059 anchor.setTag(p);
2060 anchor.setTag(R.id.workspace, preview);
Winson Chungaafa03c2010-06-11 17:34:16 -07002061 anchor.setTag(R.id.icon, bitmaps);
Romain Guy1fbc1c82009-11-09 20:43:08 -08002062 }
2063
Romain Guy9d31e9f2009-11-11 18:54:28 -08002064 class PreviewTouchHandler implements View.OnClickListener, Runnable, View.OnFocusChangeListener {
Romain Guya6abce82009-11-10 02:54:41 -08002065 private final View mAnchor;
Romain Guya6abce82009-11-10 02:54:41 -08002066
Romain Guye6b8e2f2009-11-10 11:56:55 -08002067 public PreviewTouchHandler(View anchor) {
Romain Guya6abce82009-11-10 02:54:41 -08002068 mAnchor = anchor;
Romain Guya6abce82009-11-10 02:54:41 -08002069 }
2070
2071 public void onClick(View v) {
Michael Jurka0142d492010-08-25 17:46:15 -07002072 mWorkspace.snapToPage((Integer) v.getTag());
Romain Guy9d31e9f2009-11-11 18:54:28 -08002073 v.post(this);
2074 }
2075
2076 public void run() {
Winson Chungaafa03c2010-06-11 17:34:16 -07002077 dismissPreview(mAnchor);
Romain Guy9d31e9f2009-11-11 18:54:28 -08002078 }
2079
2080 public void onFocusChange(View v, boolean hasFocus) {
2081 if (hasFocus) {
Michael Jurka0142d492010-08-25 17:46:15 -07002082 mWorkspace.snapToPage((Integer) v.getTag());
Romain Guy9d31e9f2009-11-11 18:54:28 -08002083 }
Romain Guya6abce82009-11-10 02:54:41 -08002084 }
2085 }
2086
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002087 Workspace getWorkspace() {
2088 return mWorkspace;
2089 }
2090
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002091 @Override
2092 protected Dialog onCreateDialog(int id) {
2093 switch (id) {
2094 case DIALOG_CREATE_SHORTCUT:
2095 return new CreateShortcut().createDialog();
2096 case DIALOG_RENAME_FOLDER:
2097 return new RenameFolder().createDialog();
2098 }
2099
2100 return super.onCreateDialog(id);
2101 }
2102
2103 @Override
2104 protected void onPrepareDialog(int id, Dialog dialog) {
2105 switch (id) {
2106 case DIALOG_CREATE_SHORTCUT:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002107 break;
2108 case DIALOG_RENAME_FOLDER:
Romain Guy7b4ef332009-07-14 13:58:08 -07002109 if (mFolderInfo != null) {
2110 EditText input = (EditText) dialog.findViewById(R.id.folder_name);
2111 final CharSequence text = mFolderInfo.title;
2112 input.setText(text);
2113 input.setSelection(0, text.length());
2114 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002115 break;
2116 }
2117 }
2118
2119 void showRenameDialog(FolderInfo info) {
2120 mFolderInfo = info;
2121 mWaitingForResult = true;
2122 showDialog(DIALOG_RENAME_FOLDER);
2123 }
2124
Michael Jurka0280c3b2010-09-17 15:00:07 -07002125 private void showAddDialog(int intersectX, int intersectY) {
2126 resetAddInfo();
2127 mAddIntersectCellX = intersectX;
2128 mAddIntersectCellY = intersectY;
2129 mAddScreen = mWorkspace.getCurrentPage();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002130 mWaitingForResult = true;
2131 showDialog(DIALOG_CREATE_SHORTCUT);
2132 }
2133
Joe Onoratodeb98af2010-02-19 14:59:39 -08002134 private void pickShortcut() {
Michael Jurka0e260592010-06-30 17:07:39 -07002135 // Insert extra item to handle picking application
Romain Guy73b979d2009-06-09 12:57:21 -07002136 Bundle bundle = new Bundle();
2137
2138 ArrayList<String> shortcutNames = new ArrayList<String>();
2139 shortcutNames.add(getString(R.string.group_applications));
2140 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
2141
2142 ArrayList<ShortcutIconResource> shortcutIcons = new ArrayList<ShortcutIconResource>();
2143 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
2144 R.drawable.ic_launcher_application));
2145 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
2146
2147 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2148 pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_CREATE_SHORTCUT));
Joe Onoratodeb98af2010-02-19 14:59:39 -08002149 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_shortcut));
Romain Guy73b979d2009-06-09 12:57:21 -07002150 pickIntent.putExtras(bundle);
2151
Joe Onoratodeb98af2010-02-19 14:59:39 -08002152 startActivityForResult(pickIntent, REQUEST_PICK_SHORTCUT);
Romain Guy73b979d2009-06-09 12:57:21 -07002153 }
2154
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002155 private class RenameFolder {
2156 private EditText mInput;
2157
2158 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002159 final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null);
2160 mInput = (EditText) layout.findViewById(R.id.folder_name);
2161
2162 AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
2163 builder.setIcon(0);
2164 builder.setTitle(getString(R.string.rename_folder_title));
2165 builder.setCancelable(true);
2166 builder.setOnCancelListener(new Dialog.OnCancelListener() {
2167 public void onCancel(DialogInterface dialog) {
2168 cleanup();
2169 }
2170 });
2171 builder.setNegativeButton(getString(R.string.cancel_action),
2172 new Dialog.OnClickListener() {
2173 public void onClick(DialogInterface dialog, int which) {
2174 cleanup();
2175 }
2176 }
2177 );
2178 builder.setPositiveButton(getString(R.string.rename_action),
2179 new Dialog.OnClickListener() {
2180 public void onClick(DialogInterface dialog, int which) {
2181 changeFolderName();
2182 }
2183 }
2184 );
2185 builder.setView(layout);
Romain Guy7b4ef332009-07-14 13:58:08 -07002186
2187 final AlertDialog dialog = builder.create();
2188 dialog.setOnShowListener(new DialogInterface.OnShowListener() {
2189 public void onShow(DialogInterface dialog) {
Joe Onorato7018d8e2010-04-13 20:25:47 -07002190 mWaitingForResult = true;
Joe Onoratod753b422009-11-08 13:31:11 -05002191 mInput.requestFocus();
2192 InputMethodManager inputManager = (InputMethodManager)
2193 getSystemService(Context.INPUT_METHOD_SERVICE);
2194 inputManager.showSoftInput(mInput, 0);
Romain Guy7b4ef332009-07-14 13:58:08 -07002195 }
2196 });
2197
2198 return dialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002199 }
2200
2201 private void changeFolderName() {
2202 final String name = mInput.getText().toString();
2203 if (!TextUtils.isEmpty(name)) {
2204 // Make sure we have the right folder info
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002205 mFolderInfo = sFolders.get(mFolderInfo.id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002206 mFolderInfo.title = name;
2207 LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo);
2208
Joe Onorato9c1289c2009-08-17 11:03:03 -04002209 if (mWorkspaceLoading) {
Joe Onorato7c312c12009-08-13 21:36:53 -07002210 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002211 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002212 } else {
2213 final FolderIcon folderIcon = (FolderIcon)
2214 mWorkspace.getViewForTag(mFolderInfo);
2215 if (folderIcon != null) {
2216 folderIcon.setText(name);
2217 getWorkspace().requestLayout();
2218 } else {
Joe Onorato7c312c12009-08-13 21:36:53 -07002219 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002220 mWorkspaceLoading = true;
2221 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002222 }
2223 }
2224 }
2225 cleanup();
2226 }
2227
2228 private void cleanup() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002229 dismissDialog(DIALOG_RENAME_FOLDER);
2230 mWaitingForResult = false;
2231 mFolderInfo = null;
2232 }
2233 }
2234
Daniel Sandler843e8602010-06-07 14:59:01 -04002235 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
2236 public boolean isAllAppsVisible() {
Romain Guy5bbc91b2010-08-18 11:38:46 -07002237 return mAllAppsGrid != null && mAllAppsGrid.isVisible();
Joe Onoratofb0ca672009-09-14 17:55:46 -04002238 }
2239
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002240 // AllAppsView.Watcher
2241 public void zoomed(float zoom) {
Michael Jurka213d9632010-07-28 11:29:25 -07002242 // In XLarge view, we zoom down the workspace below all apps so it's still visible
2243 if (zoom == 1.0f && !LauncherApplication.isScreenXLarge()) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002244 mWorkspace.setVisibility(View.GONE);
2245 }
2246 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002247
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002248 private void showToolbarButton(View button) {
2249 button.setAlpha(1.0f);
2250 button.setVisibility(View.VISIBLE);
2251 button.setFocusable(true);
2252 button.setClickable(true);
2253 }
2254
2255 private void hideToolbarButton(View button) {
2256 button.setAlpha(0.0f);
2257 // We can't set it to GONE, otherwise the RelativeLayout gets screwed up
2258 button.setVisibility(View.INVISIBLE);
2259 button.setFocusable(false);
2260 button.setClickable(false);
2261 }
2262
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002263 /**
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002264 * Helper function for showing or hiding a toolbar button, possibly animated.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002265 *
2266 * @param show If true, create an animation to the show the item. Otherwise, hide it.
2267 * @param view The toolbar button to be animated
Chet Haaseb1254a62010-09-07 13:35:00 -07002268 * @param seq A AnimatorSet that will be used to animate the transition. If null, the
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002269 * transition will not be animated.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002270 */
Chet Haaseb1254a62010-09-07 13:35:00 -07002271 private void hideOrShowToolbarButton(boolean show, final View view, AnimatorSet seq) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002272 final boolean showing = show;
2273 final boolean hiding = !show;
2274
2275 final int duration = show ?
2276 getResources().getInteger(R.integer.config_toolbarButtonFadeInTime) :
2277 getResources().getInteger(R.integer.config_toolbarButtonFadeOutTime);
2278
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002279 if (seq != null) {
Chet Haaseb1254a62010-09-07 13:35:00 -07002280 Animator anim = new ObjectAnimator<Float>(duration, view, "alpha", show ? 1.0f : 0.0f);
2281 anim.addListener(new AnimatorListenerAdapter() {
2282 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002283 if (showing) showToolbarButton(view);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002284 }
Chet Haaseb1254a62010-09-07 13:35:00 -07002285 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002286 if (hiding) hideToolbarButton(view);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002287 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002288 });
2289 seq.play(anim);
2290 } else {
2291 if (showing) {
2292 showToolbarButton(view);
2293 } else {
2294 hideToolbarButton(view);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002295 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002296 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002297 }
2298
2299 /**
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002300 * Show/hide the appropriate toolbar buttons for newState.
2301 * If showSeq or hideSeq is null, the transition will be done immediately (not animated).
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002302 *
2303 * @param newState The state that is being switched to
Chet Haaseb1254a62010-09-07 13:35:00 -07002304 * @param showSeq AnimatorSet in which to put "show" animations, or null.
2305 * @param hideSeq AnimatorSet in which to put "hide" animations, or null.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002306 */
Chet Haaseb1254a62010-09-07 13:35:00 -07002307 private void hideAndShowToolbarButtons(State newState, AnimatorSet showSeq, AnimatorSet hideSeq) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002308 final View searchButton = findViewById(R.id.search_button);
2309 final View allAppsButton = findViewById(R.id.all_apps_button);
2310 final View marketButton = findViewById(R.id.market_button);
2311 final View configureButton = findViewById(R.id.configure_button);
2312
2313 switch (newState) {
2314 case WORKSPACE:
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002315 hideOrShowToolbarButton(true, searchButton, showSeq);
2316 hideOrShowToolbarButton(true, allAppsButton, showSeq);
2317 hideOrShowToolbarButton(true, configureButton, showSeq);
2318 hideOrShowToolbarButton(false, marketButton, hideSeq);
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002319 mDeleteZone.setHandle(allAppsButton);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002320 break;
2321 case ALL_APPS:
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002322 hideOrShowToolbarButton(true, configureButton, showSeq);
2323 hideOrShowToolbarButton(true, marketButton, showSeq);
2324 hideOrShowToolbarButton(false, searchButton, hideSeq);
2325 hideOrShowToolbarButton(false, allAppsButton, hideSeq);
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002326 mDeleteZone.setHandle(marketButton);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002327 break;
2328 case CUSTOMIZE:
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002329 hideOrShowToolbarButton(true, allAppsButton, showSeq);
2330 hideOrShowToolbarButton(false, searchButton, hideSeq);
2331 hideOrShowToolbarButton(false, marketButton, hideSeq);
2332 hideOrShowToolbarButton(false, configureButton, hideSeq);
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002333 mDeleteZone.setHandle(allAppsButton);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002334 break;
2335 }
2336 }
2337
2338 /**
2339 * Helper method for the cameraZoomIn/cameraZoomOut animations
2340 * @param view The view being animated
2341 * @param state The state that we are moving in or out of -- either ALL_APPS or CUSTOMIZE
2342 * @param scaleFactor The scale factor used for the zoom
2343 */
2344 private void setPivotsForZoom(View view, State state, float scaleFactor) {
2345 final int height = view.getHeight();
2346 view.setPivotX(view.getWidth() / 2.0f);
2347 // Set pivotY so that at the starting zoom factor, the view is off-screen by a small margin
2348 // Assumes that the view is normally anchored to either the top or bottom of the screen
2349 final int margin = getResources().getInteger(R.integer.config_allAppsVerticalOffset);
2350 if (state == State.ALL_APPS) {
2351 view.setPivotY(height + ((view.getTop() + height) / scaleFactor) + margin);
2352 } else {
2353 view.setPivotY(0.0f - (view.getTop() / scaleFactor) - margin);
2354 }
2355 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002356
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002357 /**
2358 * Zoom the camera out from the workspace to reveal 'toView'.
2359 * Assumes that the view to show is anchored at either the very top or very bottom
2360 * of the screen.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002361 * @param toState The state to zoom out to. Must be ALL_APPS or CUSTOMIZE.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002362 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002363 private void cameraZoomOut(State toState, boolean animated) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002364 final Resources res = getResources();
2365 final int duration = res.getInteger(R.integer.config_allAppsZoomInTime);
2366 final float scale = (float) res.getInteger(R.integer.config_allAppsZoomScaleFactor);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002367 final boolean toAllApps = (toState == State.ALL_APPS);
2368 final View toView = toAllApps ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
Patrick Dubroy558654c2010-07-23 16:48:11 -07002369
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002370 setPivotsForZoom(toView, toState, scale);
2371
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002372 if (toState == State.ALL_APPS) {
2373 mWorkspace.shrinkToBottom(animated);
2374 } else {
2375 mWorkspace.shrinkToTop(animated);
2376 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002377
2378 if (animated) {
Chet Haaseb1254a62010-09-07 13:35:00 -07002379 ValueAnimator scaleAnim = new ObjectAnimator(duration, toView,
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002380 new PropertyValuesHolder<Float>("scaleX", scale, 1.0f),
2381 new PropertyValuesHolder<Float>("scaleY", scale, 1.0f));
2382 scaleAnim.setInterpolator(new DecelerateInterpolator());
Chet Haaseb1254a62010-09-07 13:35:00 -07002383 scaleAnim.addListener(new AnimatorListenerAdapter() {
2384 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002385 // Prepare the position
2386 toView.setTranslationX(0.0f);
2387 toView.setTranslationY(0.0f);
2388 toView.setVisibility(View.VISIBLE);
2389 }
2390 });
2391
Chet Haaseb1254a62010-09-07 13:35:00 -07002392 AnimatorSet toolbarHideAnim = new AnimatorSet();
2393 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002394 hideAndShowToolbarButtons(toState, toolbarShowAnim, toolbarHideAnim);
2395
2396 // toView should appear right at the end of the workspace shrink animation
2397 final int startDelay = res.getInteger(R.integer.config_workspaceShrinkTime) - duration;
2398
Chet Haaseb1254a62010-09-07 13:35:00 -07002399 AnimatorSet s = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002400 s.playTogether(scaleAnim, toolbarHideAnim);
2401 s.play(scaleAnim).after(startDelay);
2402
2403 // Show the new toolbar buttons just as the main animation is ending
2404 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
2405 s.play(toolbarShowAnim).after(duration + startDelay - fadeInTime);
2406 s.start();
2407 } else {
2408 toView.setTranslationX(0.0f);
2409 toView.setTranslationY(0.0f);
2410 toView.setScaleX(1.0f);
2411 toView.setScaleY(1.0f);
2412 toView.setVisibility(View.VISIBLE);
2413 hideAndShowToolbarButtons(toState, null, null);
2414 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002415 }
2416
2417 /**
2418 * Zoom the camera back into the workspace, hiding 'fromView'.
2419 * This is the opposite of cameraZoomOut.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002420 * @param fromState The current state (must be ALL_APPS or CUSTOMIZE).
2421 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002422 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002423 private void cameraZoomIn(State fromState, boolean animated) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002424 Resources res = getResources();
2425 int duration = res.getInteger(R.integer.config_allAppsZoomOutTime);
2426 float scaleFactor = (float) res.getInteger(R.integer.config_allAppsZoomScaleFactor);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002427 final View fromView =
2428 (fromState == State.ALL_APPS) ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
2429
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002430 mCustomizePagedView.endChoiceMode();
2431 mAllAppsPagedView.endChoiceMode();
2432
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002433 setPivotsForZoom(fromView, fromState, scaleFactor);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002434
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002435 mWorkspace.unshrink(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002436
2437 if (animated) {
Chet Haaseb1254a62010-09-07 13:35:00 -07002438 AnimatorSet s = new AnimatorSet();
2439 ValueAnimator scaleAnim = new ObjectAnimator(duration, fromView,
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002440 new PropertyValuesHolder<Float>("scaleX", scaleFactor),
2441 new PropertyValuesHolder<Float>("scaleY", scaleFactor));
2442 scaleAnim.setInterpolator(new AccelerateInterpolator());
Chet Haaseb1254a62010-09-07 13:35:00 -07002443 s.addListener(new AnimatorListenerAdapter() {
2444 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002445 fromView.setVisibility(View.GONE);
2446 fromView.setScaleX(1.0f);
2447 fromView.setScaleY(1.0f);
2448 }
2449 });
2450
Chet Haaseb1254a62010-09-07 13:35:00 -07002451 AnimatorSet toolbarHideAnim = new AnimatorSet();
2452 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002453 hideAndShowToolbarButtons(State.WORKSPACE, toolbarShowAnim, toolbarHideAnim);
2454
2455 s.playTogether(scaleAnim, toolbarHideAnim);
2456
2457 // Show the new toolbar buttons at the very end of the whole animation
2458 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
2459 final int unshrinkTime = res.getInteger(R.integer.config_workspaceUnshrinkTime);
2460 s.play(toolbarShowAnim).after(unshrinkTime - fadeInTime);
2461 s.start();
2462 } else {
2463 fromView.setVisibility(View.GONE);
2464 hideAndShowToolbarButtons(State.WORKSPACE, null, null);
2465 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002466 }
2467
2468 /**
2469 * Pan the camera in the vertical plane between 'fromView' and 'toView'.
2470 * This is the transition used on xlarge screens to go between all apps and
2471 * the home customization drawer.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002472 * @param fromState The view to pan away from. Must be ALL_APPS or CUSTOMIZE.
2473 * @param toState The view to pan into the frame. Must be ALL_APPS or CUSTOMIZE.
2474 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002475 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002476 private void cameraPan(State fromState, State toState, boolean animated) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002477 final Resources res = getResources();
2478 final int duration = res.getInteger(R.integer.config_allAppsCameraPanTime);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002479 final int workspaceHeight = mWorkspace.getHeight();
2480
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002481 final boolean fromAllApps = (fromState == State.ALL_APPS);
2482 final View fromView = fromAllApps ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
2483 final View toView = fromAllApps ? mHomeCustomizationDrawer : (View) mAllAppsGrid;
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002484
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002485 final float fromViewStartY = fromAllApps ? 0.0f : fromView.getY();
2486 final float fromViewEndY = fromAllApps ? -fromView.getHeight() * 2 : workspaceHeight * 2;
2487 final float toViewStartY = fromAllApps ? workspaceHeight * 2 : -toView.getHeight() * 2;
2488 final float toViewEndY = fromAllApps ? workspaceHeight - toView.getHeight() : 0.0f;
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002489
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002490 mCustomizePagedView.endChoiceMode();
2491 mAllAppsPagedView.endChoiceMode();
2492
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002493 if (toState == State.ALL_APPS) {
2494 mWorkspace.shrinkToBottom(animated);
2495 } else {
2496 mWorkspace.shrinkToTop(animated);
2497 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002498
2499 if (animated) {
Chet Haaseb1254a62010-09-07 13:35:00 -07002500 AnimatorSet s = new AnimatorSet();
2501 s.addListener(new AnimatorListenerAdapter() {
2502 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002503 toView.setVisibility(View.VISIBLE);
2504 toView.setY(toViewStartY);
2505 }
Chet Haaseb1254a62010-09-07 13:35:00 -07002506 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002507 fromView.setVisibility(View.GONE);
2508 }
2509 });
2510
Chet Haaseb1254a62010-09-07 13:35:00 -07002511 AnimatorSet toolbarHideAnim = new AnimatorSet();
2512 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002513 hideAndShowToolbarButtons(toState, toolbarShowAnim, toolbarHideAnim);
2514
2515 s.playTogether(
2516 toolbarHideAnim,
Chet Haaseb1254a62010-09-07 13:35:00 -07002517 new ObjectAnimator(duration, fromView, "y", fromViewStartY, fromViewEndY),
2518 new ObjectAnimator(duration, toView, "y", toViewStartY, toViewEndY));
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002519
2520 // Show the new toolbar buttons just as the main animation is ending
2521 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
2522 s.play(toolbarShowAnim).after(duration - fadeInTime);
2523 s.start();
2524 } else {
2525 fromView.setY(fromViewEndY);
2526 fromView.setVisibility(View.GONE);
2527 toView.setY(toViewEndY);
2528 toView.setVisibility(View.VISIBLE);
2529 hideAndShowToolbarButtons(toState, null, null);
2530 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002531 }
2532
2533 void showAllApps(boolean animated) {
Winson Chung80baf5a2010-08-09 16:03:15 -07002534 if (mAllAppsGrid.isVisible())
2535 return;
2536
Michael Jurka79212d82010-07-30 16:36:20 -07002537 if (LauncherApplication.isScreenXLarge()) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002538 if (isCustomizationDrawerVisible()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002539 cameraPan(State.CUSTOMIZE, State.ALL_APPS, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002540 } else {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002541 cameraZoomOut(State.ALL_APPS, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002542 }
Patrick Dubroy558654c2010-07-23 16:48:11 -07002543 } else {
2544 mAllAppsGrid.zoom(1.0f, animated);
2545 }
Joe Onorato3a8820b2009-11-10 15:06:42 -08002546
Romain Guyc16fea72010-03-12 17:17:56 -08002547 ((View) mAllAppsGrid).setFocusable(true);
2548 ((View) mAllAppsGrid).requestFocus();
Winson Chungaafa03c2010-06-11 17:34:16 -07002549
Joe Onorato7c312c12009-08-13 21:36:53 -07002550 // TODO: fade these two too
2551 mDeleteZone.setVisibility(View.GONE);
Joe Onorato00acb122009-08-04 16:04:30 -04002552 }
2553
Joe Onoratob2061212009-11-24 16:13:54 -05002554 /**
Joe Onorato7e4ed992009-12-03 13:10:49 -08002555 * Things to test when changing this code.
Joe Onoratob2061212009-11-24 16:13:54 -05002556 * - Home from workspace
2557 * - from center screen
2558 * - from other screens
2559 * - Home from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002560 * - from center screen
2561 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002562 * - Back from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002563 * - from center screen
2564 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002565 * - Launch app from workspace and quit
2566 * - with back
2567 * - with home
2568 * - Launch app from all apps and quit
2569 * - with back
2570 * - with home
Joe Onorato7e4ed992009-12-03 13:10:49 -08002571 * - Go to a screen that's not the default, then all
2572 * apps, and launch and app, and go back
2573 * - with back
2574 * -with home
Joe Onoratob2061212009-11-24 16:13:54 -05002575 * - On workspace, long press power and go back
2576 * - with back
2577 * - with home
2578 * - On all apps, long press power and go back
2579 * - with back
2580 * - with home
2581 * - On workspace, power off
2582 * - On all apps, power off
Joe Onorato7e4ed992009-12-03 13:10:49 -08002583 * - Launch an app and turn off the screen while in that app
2584 * - Go back with home key
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002585 * - Go back with back key TODO: make this not go to workspace
Joe Onorato7e4ed992009-12-03 13:10:49 -08002586 * - From all apps
2587 * - From workspace
Joe Onoratoeffc4a82010-04-15 11:48:13 -07002588 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2589 * - From all apps
2590 * - From the center workspace
2591 * - From another workspace
Joe Onoratob2061212009-11-24 16:13:54 -05002592 */
Joe Onorato7bb17492009-09-24 17:51:01 -07002593 void closeAllApps(boolean animated) {
Joe Onoratofb0ca672009-09-14 17:55:46 -04002594 if (mAllAppsGrid.isVisible()) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002595 mWorkspace.setVisibility(View.VISIBLE);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002596 if (LauncherApplication.isScreenXLarge()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002597 cameraZoomIn(State.ALL_APPS, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002598 } else {
2599 mAllAppsGrid.zoom(0.0f, animated);
2600 }
Daniel Sandler388f6792010-03-02 14:08:08 -05002601 ((View)mAllAppsGrid).setFocusable(false);
Michael Jurka0142d492010-08-25 17:46:15 -07002602 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onoratoe77c08d2009-08-01 00:01:20 -07002603 }
Joe Onorato7404ee42009-07-31 11:54:44 -07002604 }
2605
Joe Onorato7c312c12009-08-13 21:36:53 -07002606 void lockAllApps() {
2607 // TODO
2608 }
2609
2610 void unlockAllApps() {
2611 // TODO
2612 }
2613
Patrick Dubroy558654c2010-07-23 16:48:11 -07002614 private boolean isCustomizationDrawerVisible() {
Michael Jurka54f7ac32010-08-02 13:56:46 -07002615 return mHomeCustomizationDrawer != null &&
2616 mHomeCustomizationDrawer.getVisibility() == View.VISIBLE;
Patrick Dubroy558654c2010-07-23 16:48:11 -07002617 }
2618
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002619 // Show the customization drawer (only exists in x-large configuration)
2620 private void showCustomizationDrawer(boolean animated) {
Patrick Dubroy558654c2010-07-23 16:48:11 -07002621 if (isAllAppsVisible()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002622 cameraPan(State.ALL_APPS, State.CUSTOMIZE, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002623 } else {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002624 cameraZoomOut(State.CUSTOMIZE, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002625 }
Patrick Dubroy558654c2010-07-23 16:48:11 -07002626 }
2627
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002628 // Hide the customization drawer (only exists in x-large configuration)
2629 void hideCustomizationDrawer(boolean animated) {
Patrick Dubroy558654c2010-07-23 16:48:11 -07002630 if (isCustomizationDrawerVisible()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002631 cameraZoomIn(State.CUSTOMIZE, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002632 }
2633 }
2634
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002635 void onWorkspaceClick(CellLayout layout) {
2636 Object itemInfo = mAllAppsPagedView.getChosenItem();
2637 if (itemInfo == null) {
2638 itemInfo = mCustomizePagedView.getChosenItem();
Michael Jurka213d9632010-07-28 11:29:25 -07002639 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002640
2641 if (itemInfo == null) {
2642 // No items are chosen in All Apps or Customize, so just zoom into the workspace
2643 mWorkspace.unshrink(layout);
2644 if (isAllAppsVisible()) {
2645 closeAllApps(true);
2646 } else if (isCustomizationDrawerVisible()) {
2647 hideCustomizationDrawer(true);
2648 }
2649 } else {
2650 // Act as if the chosen item was dropped on the given CellLayout
2651 if (mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
2652 mAllAppsPagedView.endChoiceMode();
2653 mCustomizePagedView.endChoiceMode();
2654 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002655 showOutOfSpaceMessage();
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002656 }
Michael Jurka213d9632010-07-28 11:29:25 -07002657 }
2658 }
2659
Joe Onorato7404ee42009-07-31 11:54:44 -07002660 /**
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002661 * Sets the app market icon (shown when all apps is visible on x-large screens)
2662 */
2663 private void updateAppMarketIcon() {
2664 if (LauncherApplication.isScreenXLarge()) {
2665 // Find the app market activity by resolving an intent.
2666 // (If multiple app markets are installed, it will return the ResolverActivity.)
2667 PackageManager packageManager = getPackageManager();
2668 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
2669 ComponentName activityName = intent.resolveActivity(getPackageManager());
2670 if (activityName != null) {
2671 mAppMarketIntent = intent;
2672 ImageView marketButton = (ImageView) findViewById(R.id.market_button);
2673 Drawable toolbarIcon = null;
2674 try {
2675 // Look for the toolbar icon specified in the activity meta-data
2676 Bundle metaData = packageManager.getActivityInfo(
2677 activityName, PackageManager.GET_META_DATA).metaData;
2678 if (metaData != null) {
2679 int iconResId = metaData.getInt(TOOLBAR_ICON_METADATA_NAME);
2680 if (iconResId != 0) {
2681 Resources res = packageManager.getResourcesForActivity(activityName);
2682 toolbarIcon = res.getDrawable(iconResId);
2683 }
2684 }
2685 } catch (NameNotFoundException e) {
2686 // Do nothing
2687 }
2688 // If we were unable to find the icon via the meta-data, use a generic one
2689 if (toolbarIcon == null) {
2690 marketButton.setImageResource(R.drawable.app_market_generic);
2691 } else {
2692 marketButton.setImageDrawable(toolbarIcon);
2693 }
2694 } else {
2695 mAppMarketIntent = null;
2696 }
2697 }
2698 }
2699
2700 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002701 * Displays the shortcut creation dialog and launches, if necessary, the
2702 * appropriate activity.
2703 */
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002704 private class CreateShortcut implements DialogInterface.OnClickListener,
Romain Guy7b4ef332009-07-14 13:58:08 -07002705 DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
2706 DialogInterface.OnShowListener {
2707
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002708 private AddAdapter mAdapter;
Romain Guy9ffb5432009-03-24 21:04:15 -07002709
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002710 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002711 mAdapter = new AddAdapter(Launcher.this);
Romain Guycbb89e42009-06-08 15:52:54 -07002712
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002713 final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
2714 builder.setTitle(getString(R.string.menu_item_add_item));
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002715 builder.setAdapter(mAdapter, this);
Romain Guycbb89e42009-06-08 15:52:54 -07002716
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002717 builder.setInverseBackgroundForced(true);
2718
2719 AlertDialog dialog = builder.create();
2720 dialog.setOnCancelListener(this);
Romain Guycbb89e42009-06-08 15:52:54 -07002721 dialog.setOnDismissListener(this);
Romain Guy7b4ef332009-07-14 13:58:08 -07002722 dialog.setOnShowListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002723
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002724 return dialog;
2725 }
2726
2727 public void onCancel(DialogInterface dialog) {
2728 mWaitingForResult = false;
2729 cleanup();
2730 }
2731
Romain Guycbb89e42009-06-08 15:52:54 -07002732 public void onDismiss(DialogInterface dialog) {
Romain Guycbb89e42009-06-08 15:52:54 -07002733 }
2734
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002735 private void cleanup() {
Joe Onoratocc19a532009-11-19 14:19:17 -08002736 try {
2737 dismissDialog(DIALOG_CREATE_SHORTCUT);
2738 } catch (Exception e) {
2739 // An exception is thrown if the dialog is not visible, which is fine
2740 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002741 }
2742
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002743 /**
2744 * Handle the action clicked in the "Add to home" dialog.
2745 */
2746 public void onClick(DialogInterface dialog, int which) {
2747 Resources res = getResources();
2748 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002749
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002750 switch (which) {
2751 case AddAdapter.ITEM_SHORTCUT: {
Joe Onoratodeb98af2010-02-19 14:59:39 -08002752 pickShortcut();
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002753 break;
2754 }
Romain Guycbb89e42009-06-08 15:52:54 -07002755
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002756 case AddAdapter.ITEM_APPWIDGET: {
2757 int appWidgetId = Launcher.this.mAppWidgetHost.allocateAppWidgetId();
Romain Guycbb89e42009-06-08 15:52:54 -07002758
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002759 Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
2760 pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002761 // start the pick activity
2762 startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET);
2763 break;
2764 }
Romain Guycbb89e42009-06-08 15:52:54 -07002765
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002766 case AddAdapter.ITEM_LIVE_FOLDER: {
2767 // Insert extra item to handle inserting folder
2768 Bundle bundle = new Bundle();
Romain Guycbb89e42009-06-08 15:52:54 -07002769
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002770 ArrayList<String> shortcutNames = new ArrayList<String>();
2771 shortcutNames.add(res.getString(R.string.group_folder));
2772 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
Romain Guycbb89e42009-06-08 15:52:54 -07002773
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002774 ArrayList<ShortcutIconResource> shortcutIcons =
2775 new ArrayList<ShortcutIconResource>();
2776 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
2777 R.drawable.ic_launcher_folder));
2778 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
2779
2780 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2781 pickIntent.putExtra(Intent.EXTRA_INTENT,
2782 new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER));
2783 pickIntent.putExtra(Intent.EXTRA_TITLE,
2784 getText(R.string.title_select_live_folder));
2785 pickIntent.putExtras(bundle);
Romain Guycbb89e42009-06-08 15:52:54 -07002786
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002787 startActivityForResult(pickIntent, REQUEST_PICK_LIVE_FOLDER);
2788 break;
2789 }
2790
2791 case AddAdapter.ITEM_WALLPAPER: {
2792 startWallpaper();
2793 break;
2794 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002795 }
2796 }
Romain Guy7b4ef332009-07-14 13:58:08 -07002797
2798 public void onShow(DialogInterface dialog) {
Winson Chungaafa03c2010-06-11 17:34:16 -07002799 mWaitingForResult = true;
Romain Guy7b4ef332009-07-14 13:58:08 -07002800 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002801 }
2802
2803 /**
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002804 * Receives notifications when applications are added/removed.
2805 */
2806 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
2807 @Override
2808 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002809 closeSystemDialogs();
Joe Onoratob2061212009-11-24 16:13:54 -05002810 String reason = intent.getStringExtra("reason");
2811 if (!"homekey".equals(reason)) {
2812 boolean animate = true;
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002813 if (mPaused || "lock".equals(reason)) {
Joe Onoratob2061212009-11-24 16:13:54 -05002814 animate = false;
2815 }
Joe Onoratob2061212009-11-24 16:13:54 -05002816 closeAllApps(animate);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002817 hideCustomizationDrawer(animate);
Joe Onoratob2061212009-11-24 16:13:54 -05002818 }
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002819 }
2820 }
2821
2822 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002823 * Receives notifications whenever the appwidgets are reset.
2824 */
2825 private class AppWidgetResetObserver extends ContentObserver {
2826 public AppWidgetResetObserver() {
2827 super(new Handler());
2828 }
2829
2830 @Override
2831 public void onChange(boolean selfChange) {
2832 onAppWidgetReset();
2833 }
2834 }
2835
2836 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002837 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002838 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002839 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07002840 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002841 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07002842 } else {
2843 return SCREEN_COUNT / 2;
2844 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002845 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002846
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002847 void setAllAppsPagedView(PagedView view) {
2848 mAllAppsPagedView = view;
2849 }
2850
Joe Onorato9c1289c2009-08-17 11:03:03 -04002851 /**
2852 * Refreshes the shortcuts shown on the workspace.
2853 *
2854 * Implementation of the method from LauncherModel.Callbacks.
2855 */
2856 public void startBinding() {
2857 final Workspace workspace = mWorkspace;
2858 int count = workspace.getChildCount();
2859 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04002860 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Joe Onorato9c1289c2009-08-17 11:03:03 -04002861 ((ViewGroup) workspace.getChildAt(i)).removeAllViewsInLayout();
2862 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002863
Joe Onorato9c1289c2009-08-17 11:03:03 -04002864 if (DEBUG_USER_INTERFACE) {
2865 android.widget.Button finishButton = new android.widget.Button(this);
2866 finishButton.setText("Finish");
2867 workspace.addInScreen(finishButton, 1, 0, 0, 1, 1);
2868
2869 finishButton.setOnClickListener(new android.widget.Button.OnClickListener() {
2870 public void onClick(View v) {
2871 finish();
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002872 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002873 });
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002874 }
2875 }
2876
2877 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002878 * Bind the items start-end from the list.
2879 *
2880 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002881 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002882 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
2883
2884 final Workspace workspace = mWorkspace;
2885
2886 for (int i=start; i<end; i++) {
2887 final ItemInfo item = shortcuts.get(i);
2888 mDesktopItems.add(item);
2889 switch (item.itemType) {
2890 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
2891 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Joe Onorato0589f0f2010-02-08 13:44:00 -08002892 final View shortcut = createShortcut((ShortcutInfo)item);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002893 workspace.addInScreen(shortcut, item.screen, item.cellX, item.cellY, 1, 1,
2894 false);
2895 break;
2896 case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER:
2897 final FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07002898 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Joe Onorato9c1289c2009-08-17 11:03:03 -04002899 (UserFolderInfo) item);
2900 workspace.addInScreen(newFolder, item.screen, item.cellX, item.cellY, 1, 1,
2901 false);
2902 break;
2903 case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER:
2904 final FolderIcon newLiveFolder = LiveFolderIcon.fromXml(
2905 R.layout.live_folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07002906 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Joe Onorato9c1289c2009-08-17 11:03:03 -04002907 (LiveFolderInfo) item);
2908 workspace.addInScreen(newLiveFolder, item.screen, item.cellX, item.cellY, 1, 1,
2909 false);
2910 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002911 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002912 }
2913
Joe Onorato9c1289c2009-08-17 11:03:03 -04002914 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002915 }
2916
Joe Onorato9c1289c2009-08-17 11:03:03 -04002917 /**
2918 * Implementation of the method from LauncherModel.Callbacks.
2919 */
Joe Onoratoad72e172009-11-06 16:25:04 -05002920 public void bindFolders(HashMap<Long, FolderInfo> folders) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002921 sFolders.clear();
2922 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002923 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002924
2925 /**
2926 * Add the views for a widget to the workspace.
2927 *
2928 * Implementation of the method from LauncherModel.Callbacks.
2929 */
2930 public void bindAppWidget(LauncherAppWidgetInfo item) {
Daniel Sandler843e8602010-06-07 14:59:01 -04002931 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
2932 if (DEBUG_WIDGETS) {
2933 Log.d(TAG, "bindAppWidget: " + item);
2934 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002935 final Workspace workspace = mWorkspace;
2936
2937 final int appWidgetId = item.appWidgetId;
2938 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04002939 if (DEBUG_WIDGETS) {
2940 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
2941 }
2942
Joe Onorato9c1289c2009-08-17 11:03:03 -04002943 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
2944
Joe Onorato9c1289c2009-08-17 11:03:03 -04002945 item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
2946 item.hostView.setTag(item);
2947
2948 workspace.addInScreen(item.hostView, item.screen, item.cellX,
2949 item.cellY, item.spanX, item.spanY, false);
2950
2951 workspace.requestLayout();
2952
2953 mDesktopItems.add(item);
Daniel Sandler843e8602010-06-07 14:59:01 -04002954
2955 if (DEBUG_WIDGETS) {
2956 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
2957 + (SystemClock.uptimeMillis()-start) + "ms");
2958 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002959 }
2960
2961 /**
2962 * Callback saying that there aren't any more items to bind.
2963 *
2964 * Implementation of the method from LauncherModel.Callbacks.
2965 */
2966 public void finishBindingItems() {
2967 if (mSavedState != null) {
2968 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07002969 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002970 }
2971
2972 final long[] userFolders = mSavedState.getLongArray(RUNTIME_STATE_USER_FOLDERS);
2973 if (userFolders != null) {
2974 for (long folderId : userFolders) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002975 final FolderInfo info = sFolders.get(folderId);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002976 if (info != null) {
2977 openFolder(info);
2978 }
2979 }
2980 final Folder openFolder = mWorkspace.getOpenFolder();
2981 if (openFolder != null) {
2982 openFolder.requestFocus();
2983 }
2984 }
2985
Joe Onorato9c1289c2009-08-17 11:03:03 -04002986 mSavedState = null;
2987 }
2988
2989 if (mSavedInstanceState != null) {
2990 super.onRestoreInstanceState(mSavedInstanceState);
2991 mSavedInstanceState = null;
2992 }
2993
Joe Onorato9c1289c2009-08-17 11:03:03 -04002994 mWorkspaceLoading = false;
2995 }
2996
2997 /**
2998 * Add the icons for all apps.
2999 *
3000 * Implementation of the method from LauncherModel.Callbacks.
3001 */
3002 public void bindAllApplications(ArrayList<ApplicationInfo> apps) {
Romain Guy84f296c2009-11-04 15:00:44 -08003003 mAllAppsGrid.setApps(apps);
Winson Chung5ffd8ea2010-09-23 18:40:29 -07003004 mCustomizePagedView.setApps(apps);
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003005 updateAppMarketIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003006 }
3007
3008 /**
3009 * A package was installed.
3010 *
3011 * Implementation of the method from LauncherModel.Callbacks.
3012 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003013 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003014 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onoratoa8138d52009-10-06 19:25:30 -07003015 mAllAppsGrid.addApps(apps);
Winson Chung5ffd8ea2010-09-23 18:40:29 -07003016 mCustomizePagedView.addApps(apps);
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003017 updateAppMarketIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003018 }
3019
3020 /**
3021 * A package was updated.
3022 *
3023 * Implementation of the method from LauncherModel.Callbacks.
3024 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003025 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003026 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato64e6be72010-03-05 15:05:52 -05003027 mWorkspace.updateShortcuts(apps);
3028 mAllAppsGrid.updateApps(apps);
Winson Chung5ffd8ea2010-09-23 18:40:29 -07003029 mCustomizePagedView.updateApps(apps);
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003030 updateAppMarketIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003031 }
3032
3033 /**
3034 * A package was uninstalled.
3035 *
3036 * Implementation of the method from LauncherModel.Callbacks.
3037 */
Joe Onorato36115782010-06-17 13:28:48 -04003038 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003039 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato36115782010-06-17 13:28:48 -04003040 if (permanent) {
3041 mWorkspace.removeItems(apps);
3042 }
Joe Onoratoa8138d52009-10-06 19:25:30 -07003043 mAllAppsGrid.removeApps(apps);
Winson Chung5ffd8ea2010-09-23 18:40:29 -07003044 mCustomizePagedView.removeApps(apps);
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003045 updateAppMarketIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003046 }
Joe Onoratobe386092009-11-17 17:32:16 -08003047
3048 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003049 * A number of packages were updated.
3050 */
3051 public void bindPackagesUpdated() {
3052 // update the customization drawer contents
Winson Chungb3347bb2010-08-19 14:51:28 -07003053 if (mCustomizePagedView != null)
3054 mCustomizePagedView.update();
Winson Chung80baf5a2010-08-09 16:03:15 -07003055 }
3056
3057 /**
Joe Onoratobe386092009-11-17 17:32:16 -08003058 * Prints out out state for debugging.
3059 */
3060 public void dumpState() {
3061 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08003062 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08003063 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
3064 Log.d(TAG, "mRestoring=" + mRestoring);
3065 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
3066 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
3067 Log.d(TAG, "mDesktopItems.size=" + mDesktopItems.size());
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003068 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08003069 mModel.dumpState();
3070 mAllAppsGrid.dumpState();
3071 Log.d(TAG, "END launcher2 dump state");
3072 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003073}