blob: 019cd7b33342646cdee3257136078ea9725df5fb [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 Jurka28750fb2010-09-24 17:43:49 -0700658 completeAddApplication(
659 this, data, mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800660 break;
661 case REQUEST_PICK_SHORTCUT:
Joe Onoratodeb98af2010-02-19 14:59:39 -0800662 processShortcut(data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800663 break;
664 case REQUEST_CREATE_SHORTCUT:
Michael Jurka0280c3b2010-09-17 15:00:07 -0700665 completeAddShortcut(data, mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800666 break;
667 case REQUEST_PICK_LIVE_FOLDER:
668 addLiveFolder(data);
669 break;
670 case REQUEST_CREATE_LIVE_FOLDER:
Michael Jurka0280c3b2010-09-17 15:00:07 -0700671 completeAddLiveFolder(data, mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800672 break;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700673 case REQUEST_PICK_APPWIDGET:
Michael Jurkaaf442092010-06-10 17:01:57 -0700674 addAppWidgetFromPick(data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800675 break;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700676 case REQUEST_CREATE_APPWIDGET:
Michael Jurkaaf442092010-06-10 17:01:57 -0700677 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700678 completeAddAppWidget(appWidgetId, mAddScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800679 break;
Mike Clerona0618e42009-10-22 13:55:21 -0700680 case REQUEST_PICK_WALLPAPER:
681 // We just wanted the activity result here so we can clear mWaitingForResult
682 break;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800683 }
Romain Guy18042c82009-11-06 11:44:55 -0800684 } else if ((requestCode == REQUEST_PICK_APPWIDGET ||
685 requestCode == REQUEST_CREATE_APPWIDGET) && resultCode == RESULT_CANCELED &&
686 data != null) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700687 // Clean up the appWidgetId if we canceled
688 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
689 if (appWidgetId != -1) {
690 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800691 }
692 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800693 }
694
695 @Override
696 protected void onResume() {
697 super.onResume();
698
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800699 mPaused = false;
Joe Onorato7e4ed992009-12-03 13:10:49 -0800700
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800701 if (mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400702 mWorkspaceLoading = true;
703 mModel.startLoader(this, true);
704 mRestoring = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800705 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700706 // When we resume Launcher, a different Activity might be responsible for the app
707 // market intent, so refresh the icon
708 updateAppMarketIcon();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800709 }
710
711 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700712 protected void onPause() {
713 super.onPause();
Michael Jurkaaf442092010-06-10 17:01:57 -0700714 // Some launcher layouts don't have a previous and next view
715 if (mPreviousView != null) {
716 dismissPreview(mPreviousView);
Patrick Dubroyab962b72010-07-26 12:10:10 -0700717 }
718 if (mNextView != null) {
Michael Jurkaaf442092010-06-10 17:01:57 -0700719 dismissPreview(mNextView);
720 }
Joe Onorato24b6fd82009-11-12 13:47:09 -0800721 mDragController.cancelDrag();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700722 }
Romain Guycbb89e42009-06-08 15:52:54 -0700723
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700724 @Override
725 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400726 // Flag the loader to stop early before switching
727 mModel.stopLoader();
Romain Guy13c2e7b2010-03-10 19:45:00 -0800728 mAllAppsGrid.surrender();
Romain Guy13c2e7b2010-03-10 19:45:00 -0800729 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700730 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700731
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800732 // We can't hide the IME if it was forced open. So don't bother
733 /*
734 @Override
735 public void onWindowFocusChanged(boolean hasFocus) {
736 super.onWindowFocusChanged(hasFocus);
737
738 if (hasFocus) {
739 final InputMethodManager inputManager = (InputMethodManager)
740 getSystemService(Context.INPUT_METHOD_SERVICE);
741 WindowManager.LayoutParams lp = getWindow().getAttributes();
742 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
743 android.os.Handler()) {
744 protected void onReceiveResult(int resultCode, Bundle resultData) {
745 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
746 }
747 });
748 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
749 }
750 }
751 */
752
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800753 private boolean acceptFilter() {
754 final InputMethodManager inputManager = (InputMethodManager)
755 getSystemService(Context.INPUT_METHOD_SERVICE);
756 return !inputManager.isFullscreenMode();
757 }
758
759 @Override
760 public boolean onKeyDown(int keyCode, KeyEvent event) {
761 boolean handled = super.onKeyDown(keyCode, event);
762 if (!handled && acceptFilter() && keyCode != KeyEvent.KEYCODE_ENTER) {
763 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
764 keyCode, event);
765 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700766 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700767 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700768 // showSearchDialog()
769 // If there are multiple keystrokes before the search dialog takes focus,
770 // onSearchRequested() will be called for every keystroke,
771 // but it is idempotent, so it's fine.
772 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800773 }
774 }
775
Joe Onorato8a9625e2010-01-28 15:55:35 -0800776 // Eat the long press event so the keyboard doesn't come up.
777 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
778 return true;
779 }
780
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800781 return handled;
782 }
783
Karl Rosaen138a0412009-04-23 19:00:21 -0700784 private String getTypedText() {
785 return mDefaultKeySsb.toString();
786 }
787
788 private void clearTypedText() {
789 mDefaultKeySsb.clear();
790 mDefaultKeySsb.clearSpans();
791 Selection.setSelection(mDefaultKeySsb, 0);
792 }
793
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800794 /**
795 * Restores the previous state, if it exists.
796 *
797 * @param savedState The previous state.
798 */
799 private void restoreState(Bundle savedState) {
800 if (savedState == null) {
801 return;
802 }
803
Joe Onorato3a8820b2009-11-10 15:06:42 -0800804 final boolean allApps = savedState.getBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, false);
805 if (allApps) {
806 showAllApps(false);
807 }
808
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800809 final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
810 if (currentScreen > -1) {
Michael Jurka0142d492010-08-25 17:46:15 -0700811 mWorkspace.setCurrentPage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800812 }
813
814 final int addScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700815
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800816 if (addScreen > -1) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700817 mAddScreen = addScreen;
818 mAddIntersectCellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
819 mAddIntersectCellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800820 mRestoring = true;
821 }
822
823 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
824 if (renameFolder) {
825 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700826 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800827 mRestoring = true;
828 }
829 }
830
831 /**
832 * Finds all the views we need and configure them properly.
833 */
834 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700835 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -0400836
Romain Guyb1b69f52009-08-10 15:10:15 -0700837 DragLayer dragLayer = (DragLayer) findViewById(R.id.drag_layer);
Joe Onorato00acb122009-08-04 16:04:30 -0400838 dragLayer.setDragController(dragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800839
Joe Onorato7c312c12009-08-13 21:36:53 -0700840 mAllAppsGrid = (AllAppsView)dragLayer.findViewById(R.id.all_apps_view);
Joe Onorato6665c0f2009-09-02 15:27:24 -0700841 mAllAppsGrid.setLauncher(this);
Joe Onorato5162ea92009-09-03 09:39:42 -0700842 mAllAppsGrid.setDragController(dragController);
Romain Guyc16fea72010-03-12 17:17:56 -0800843 ((View) mAllAppsGrid).setWillNotDraw(false); // We don't want a hole punched in our window.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700844 // Manage focusability manually since this thing is always visible (in non-xlarge)
Winson Chungaafa03c2010-06-11 17:34:16 -0700845 ((View) mAllAppsGrid).setFocusable(false);
Joe Onorato7c312c12009-08-13 21:36:53 -0700846
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700847 if (LauncherApplication.isScreenXLarge()) {
848 // They need to be INVISIBLE initially so that they will be measured in the layout.
849 // Otherwise the animations are messed up when we show them for the first time.
850 ((View) mAllAppsGrid).setVisibility(View.INVISIBLE);
851 mHomeCustomizationDrawer.setVisibility(View.INVISIBLE);
852 }
853
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800854 mWorkspace = (Workspace) dragLayer.findViewById(R.id.workspace);
855 final Workspace workspace = mWorkspace;
Joe Onoratof0dde092010-02-16 18:25:23 -0500856 workspace.setHapticFeedbackEnabled(false);
Michael Jurka946ad472010-07-09 18:05:18 -0700857
Joe Onorato7c312c12009-08-13 21:36:53 -0700858 DeleteZone deleteZone = (DeleteZone) dragLayer.findViewById(R.id.delete_zone);
859 mDeleteZone = deleteZone;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800860
Michael Jurka2c3af5f2010-08-03 13:53:20 -0700861 View handleView = findViewById(R.id.all_apps_button);
862 if (handleView != null && handleView instanceof HandleView) {
863 // we don't use handle view in xlarge mode
Michael Jurka7ef4f752010-08-03 16:04:26 -0700864 mHandleView = (HandleView)handleView;
Michael Jurka2c3af5f2010-08-03 13:53:20 -0700865 mHandleView.setLauncher(this);
866 mHandleView.setOnClickListener(this);
867 mHandleView.setOnLongClickListener(this);
868 }
Romain Guy1fbc1c82009-11-09 20:43:08 -0800869
Winson Chung80baf5a2010-08-09 16:03:15 -0700870 if (mCustomizePagedView != null) {
871 mCustomizePagedView.setLauncher(this);
872 mCustomizePagedView.setDragController(dragController);
873 mCustomizePagedView.update();
Michael Jurkaaf442092010-06-10 17:01:57 -0700874 } else {
875 ImageView hotseatLeft = (ImageView) findViewById(R.id.hotseat_left);
876 hotseatLeft.setContentDescription(mHotseatLabels[0]);
877 hotseatLeft.setImageDrawable(mHotseatIcons[0]);
878 ImageView hotseatRight = (ImageView) findViewById(R.id.hotseat_right);
879 hotseatRight.setContentDescription(mHotseatLabels[1]);
880 hotseatRight.setImageDrawable(mHotseatIcons[1]);
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400881
Michael Jurkaaf442092010-06-10 17:01:57 -0700882 mPreviousView = (ImageView) dragLayer.findViewById(R.id.previous_screen);
883 mNextView = (ImageView) dragLayer.findViewById(R.id.next_screen);
Romain Guy1fbc1c82009-11-09 20:43:08 -0800884
Michael Jurkaaf442092010-06-10 17:01:57 -0700885 Drawable previous = mPreviousView.getDrawable();
886 Drawable next = mNextView.getDrawable();
887 mWorkspace.setIndicators(previous, next);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800888
Michael Jurkaaf442092010-06-10 17:01:57 -0700889 mPreviousView.setHapticFeedbackEnabled(false);
890 mPreviousView.setOnLongClickListener(this);
891 mNextView.setHapticFeedbackEnabled(false);
892 mNextView.setOnLongClickListener(this);
893 }
Romain Guy1fbc1c82009-11-09 20:43:08 -0800894
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800895 workspace.setOnLongClickListener(this);
Joe Onorato00acb122009-08-04 16:04:30 -0400896 workspace.setDragController(dragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800897 workspace.setLauncher(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800898
899 deleteZone.setLauncher(this);
Joe Onorato00acb122009-08-04 16:04:30 -0400900 deleteZone.setDragController(dragController);
Michael Jurka54f7ac32010-08-02 13:56:46 -0700901 int deleteZoneHandleId;
902 if (LauncherApplication.isScreenXLarge()) {
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700903 deleteZoneHandleId = R.id.all_apps_button;
Michael Jurka54f7ac32010-08-02 13:56:46 -0700904 } else {
905 deleteZoneHandleId = R.id.all_apps_button_cluster;
906 }
Michael Jurkaaf442092010-06-10 17:01:57 -0700907 deleteZone.setHandle(findViewById(deleteZoneHandleId));
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700908 dragController.addDragListener(deleteZone);
909
910 ApplicationInfoDropTarget infoButton = (ApplicationInfoDropTarget)findViewById(R.id.info_button);
911 if (infoButton != null) {
912 infoButton.setLauncher(this);
913 infoButton.setHandle(findViewById(R.id.configure_button));
914 infoButton.setDragColor(getResources().getColor(R.color.app_info_filter));
915 dragController.addDragListener(infoButton);
916 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800917
Joe Onorato00acb122009-08-04 16:04:30 -0400918 dragController.setDragScoller(workspace);
Joe Onorato00acb122009-08-04 16:04:30 -0400919 dragController.setScrollView(dragLayer);
Romain Guyea3763c2010-01-11 18:02:04 -0800920 dragController.setMoveTarget(workspace);
Jason Samsfd22dac2009-09-20 17:24:16 -0700921
Joe Onorato00acb122009-08-04 16:04:30 -0400922 // The order here is bottom to top.
923 dragController.addDropTarget(workspace);
924 dragController.addDropTarget(deleteZone);
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700925 if (infoButton != null) {
926 dragController.addDropTarget(infoButton);
927 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800928 }
929
Romain Guy8a73c512009-11-09 19:19:59 -0800930 @SuppressWarnings({"UnusedDeclaration"})
931 public void previousScreen(View v) {
Joe Onorato61597bd2009-11-19 12:51:57 -0800932 if (!isAllAppsVisible()) {
933 mWorkspace.scrollLeft();
934 }
Romain Guy8a73c512009-11-09 19:19:59 -0800935 }
936
937 @SuppressWarnings({"UnusedDeclaration"})
938 public void nextScreen(View v) {
Joe Onorato61597bd2009-11-19 12:51:57 -0800939 if (!isAllAppsVisible()) {
940 mWorkspace.scrollRight();
941 }
Romain Guy8a73c512009-11-09 19:19:59 -0800942 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400943
944 @SuppressWarnings({"UnusedDeclaration"})
945 public void launchHotSeat(View v) {
Daniel Sandler3e9454a2010-05-24 11:22:41 -0400946 if (isAllAppsVisible()) return;
947
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400948 int index = -1;
949 if (v.getId() == R.id.hotseat_left) {
950 index = 0;
951 } else if (v.getId() == R.id.hotseat_right) {
952 index = 1;
953 }
954
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400955 // reload these every tap; you never know when they might change
956 loadHotseats();
957 if (index >= 0 && index < mHotseats.length && mHotseats[index] != null) {
958 Intent intent = mHotseats[index];
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400959 startActivitySafely(
960 mHotseats[index],
961 "hotseat"
962 );
963 }
964 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700965
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800966 /**
967 * Creates a view representing a shortcut.
968 *
969 * @param info The data structure describing the shortcut.
970 *
971 * @return A View inflated from R.layout.application.
972 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800973 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800974 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -0700975 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800976 }
977
978 /**
979 * Creates a view representing a shortcut inflated from the specified resource.
980 *
981 * @param layoutResId The id of the XML layout used to create the shortcut.
982 * @param parent The group the shortcut belongs to.
983 * @param info The data structure describing the shortcut.
984 *
985 * @return A View inflated from layoutResId.
986 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800987 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800988 TextView favorite = (TextView) mInflater.inflate(layoutResId, parent, false);
989
Joe Onorato0589f0f2010-02-08 13:44:00 -0800990 favorite.setCompoundDrawablesWithIntrinsicBounds(null,
991 new FastBitmapDrawable(info.getIcon(mIconCache)),
992 null, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800993 favorite.setText(info.title);
994 favorite.setTag(info);
995 favorite.setOnClickListener(this);
996
997 return favorite;
998 }
999
1000 /**
1001 * Add an application shortcut to the workspace.
1002 *
1003 * @param data The intent describing the application.
1004 * @param cellInfo The position on screen where to create the shortcut.
1005 */
Michael Jurka0280c3b2010-09-17 15:00:07 -07001006 void completeAddApplication(Context context, Intent data, int screen,
1007 int intersectCellX, int intersectCellY) {
1008 final int[] cellXY = mTmpAddItemCellCoordinates;
1009 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1010
1011 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1012 showOutOfSpaceMessage();
1013 return;
1014 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001015
Joe Onorato0589f0f2010-02-08 13:44:00 -08001016 final ShortcutInfo info = mModel.getShortcutInfo(context.getPackageManager(),
1017 data, context);
1018
Romain Guy73b979d2009-06-09 12:57:21 -07001019 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -08001020 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001021 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001022 info.container = ItemInfo.NO_ID;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001023 mWorkspace.addApplicationShortcut(info, screen, cellXY[0], cellXY[1],
1024 isWorkspaceLocked(), mAddIntersectCellX, mAddIntersectCellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001025 } else {
1026 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001027 }
1028 }
Romain Guycbb89e42009-06-08 15:52:54 -07001029
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001030 /**
1031 * Add a shortcut to the workspace.
1032 *
1033 * @param data The intent describing the shortcut.
1034 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001035 */
Michael Jurka0280c3b2010-09-17 15:00:07 -07001036 private void completeAddShortcut(Intent data, int screen,
1037 int intersectCellX, int intersectCellY) {
1038 final int[] cellXY = mTmpAddItemCellCoordinates;
1039 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
Romain Guycbb89e42009-06-08 15:52:54 -07001040
Michael Jurka0280c3b2010-09-17 15:00:07 -07001041 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1042 showOutOfSpaceMessage();
1043 return;
1044 }
1045
1046 final ShortcutInfo info = mModel.addShortcut(
1047 this, data, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001048
1049 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001050 final View view = createShortcut(info);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001051 mWorkspace.addInScreen(view, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001052 }
1053 }
1054
Romain Guycbb89e42009-06-08 15:52:54 -07001055
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001056 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001057 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001058 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001059 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001060 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001061 */
Michael Jurka0280c3b2010-09-17 15:00:07 -07001062 private void completeAddAppWidget(int appWidgetId, int screen) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001063 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Romain Guycbb89e42009-06-08 15:52:54 -07001064
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001065 // Calculate the grid spans needed to fit this widget
Michael Jurka0280c3b2010-09-17 15:00:07 -07001066 CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1067 int[] spanXY = layout.rectToCell(appWidgetInfo.minWidth, appWidgetInfo.minHeight, null);
Romain Guycbb89e42009-06-08 15:52:54 -07001068
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001069 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001070 // We have saved the position to which the widget was dragged-- this really only matters
1071 // if we are placing widgets on a "spring-loaded" screen
Michael Jurka0280c3b2010-09-17 15:00:07 -07001072 final int[] cellXY = mTmpAddItemCellCoordinates;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001073
1074 // For now, we don't save the coordinate where we dropped the icon because we're not
1075 // supporting spring-loaded mini-screens; however, leaving the ability to directly place
1076 // a widget on the home screen in case we want to add it in the future
Michael Jurka0280c3b2010-09-17 15:00:07 -07001077 final int[] touchXY = null;
1078 //final int[] touchXY = mAddDropPosition;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001079 boolean findNearestVacantAreaFailed = false;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001080 boolean foundCellSpan = false;
1081 if (touchXY != null) {
1082 // when dragging and dropping, just find the closest free spot
1083 CellLayout screenLayout = (CellLayout) mWorkspace.getChildAt(screen);
1084 int[] result = screenLayout.findNearestVacantArea(
1085 touchXY[0], touchXY[1], spanXY[0], spanXY[1], cellXY);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001086 findNearestVacantAreaFailed = (result == null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001087 foundCellSpan = !findNearestVacantAreaFailed;
1088 } else {
1089 if (mAddIntersectCellX != -1 && mAddIntersectCellY != -1) {
1090 // if we long pressed on an empty cell to bring up a menu,
1091 // make sure we intersect the empty cell
1092 foundCellSpan = layout.findCellForSpanThatIntersects(cellXY, spanXY[0], spanXY[1],
1093 mAddIntersectCellX, mAddIntersectCellY);
1094 } else {
1095 // if we went through the menu -> add, just find any spot
1096 foundCellSpan = layout.findCellForSpan(cellXY, spanXY[0], spanXY[1]);
1097 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001098 }
1099
Michael Jurka0280c3b2010-09-17 15:00:07 -07001100 if (!foundCellSpan) {
Romain Guy18042c82009-11-06 11:44:55 -08001101 if (appWidgetId != -1) mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001102 showOutOfSpaceMessage();
Romain Guy18042c82009-11-06 11:44:55 -08001103 return;
1104 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001105
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001106 // Build Launcher-specific widget info and save to database
1107 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001108 launcherInfo.spanX = spanXY[0];
1109 launcherInfo.spanY = spanXY[1];
Romain Guycbb89e42009-06-08 15:52:54 -07001110
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001111 LauncherModel.addItemToDatabase(this, launcherInfo,
1112 LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001113 screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001114
1115 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001116 mDesktopItems.add(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001117
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001118 // Perform actual inflation because we're live
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001119 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001120
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001121 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001122 launcherInfo.hostView.setTag(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001123
Michael Jurka0280c3b2010-09-17 15:00:07 -07001124 mWorkspace.addInScreen(launcherInfo.hostView, screen, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001125 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001126 }
1127 }
Romain Guycbb89e42009-06-08 15:52:54 -07001128
Michael Jurka0280c3b2010-09-17 15:00:07 -07001129 void showOutOfSpaceMessage() {
1130 Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show();
1131 }
1132
Joe Onorato9c1289c2009-08-17 11:03:03 -04001133 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
1134 mDesktopItems.remove(launcherInfo);
1135 launcherInfo.hostView = null;
1136 }
1137
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001138 public LauncherAppWidgetHost getAppWidgetHost() {
1139 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001140 }
Romain Guycbb89e42009-06-08 15:52:54 -07001141
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001142 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001143 getWindow().closeAllPanels();
1144
1145 try {
1146 dismissDialog(DIALOG_CREATE_SHORTCUT);
1147 // Unlock the workspace if the dialog was showing
1148 } catch (Exception e) {
1149 // An exception is thrown if the dialog is not visible, which is fine
1150 }
1151
1152 try {
1153 dismissDialog(DIALOG_RENAME_FOLDER);
1154 // Unlock the workspace if the dialog was showing
1155 } catch (Exception e) {
1156 // An exception is thrown if the dialog is not visible, which is fine
1157 }
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001158
1159 // Whatever we were doing is hereby canceled.
1160 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001161 }
1162
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001163 @Override
1164 protected void onNewIntent(Intent intent) {
1165 super.onNewIntent(intent);
1166
1167 // Close the menu
1168 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001169 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001170 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001171
Joe Onorato14f122b2009-11-19 14:06:36 -08001172 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1173 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
1174 boolean allAppsVisible = isAllAppsVisible();
Michael Jurka01f0ed42010-08-20 00:41:17 -07001175 boolean customizationDrawerVisible = isCustomizationDrawerVisible();
1176
Michael Jurka4cb37242010-08-09 21:05:32 -07001177 // in all these cases, only animate if we're already on home
1178 if (LauncherApplication.isScreenXLarge()) {
Michael Jurka99229f62010-09-09 11:49:32 -07001179 mWorkspace.unshrink(alreadyOnHome);
1180 }
1181 if (!mWorkspace.isDefaultPageShowing()) {
Michael Jurka4cb37242010-08-09 21:05:32 -07001182 // on the phone, we don't animate the change to the workspace if all apps is visible
Michael Jurka99229f62010-09-09 11:49:32 -07001183 mWorkspace.moveToDefaultScreen(
1184 alreadyOnHome && (LauncherApplication.isScreenXLarge() || !allAppsVisible));
Joe Onorato3a8820b2009-11-10 15:06:42 -08001185 }
Joe Onorato14f122b2009-11-19 14:06:36 -08001186 closeAllApps(alreadyOnHome && allAppsVisible);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07001187 hideCustomizationDrawer(alreadyOnHome);
Romain Guy1dd3a072009-07-16 13:21:01 -07001188
Joe Onorato3a8820b2009-11-10 15:06:42 -08001189 final View v = getWindow().peekDecorView();
1190 if (v != null && v.getWindowToken() != null) {
1191 InputMethodManager imm = (InputMethodManager)getSystemService(
1192 INPUT_METHOD_SERVICE);
1193 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001194 }
1195 }
1196 }
1197
1198 @Override
1199 protected void onRestoreInstanceState(Bundle savedInstanceState) {
1200 // Do not call super here
1201 mSavedInstanceState = savedInstanceState;
Michael Jurka946ad472010-07-09 18:05:18 -07001202
1203 if (mHomeCustomizationDrawer != null) {
1204 String cur = savedInstanceState.getString("currentTab");
1205 if (cur != null) {
1206 mHomeCustomizationDrawer.setCurrentTabByTag(cur);
1207 }
1208 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001209 }
1210
1211 @Override
1212 protected void onSaveInstanceState(Bundle outState) {
Michael Jurka0142d492010-08-25 17:46:15 -07001213 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001214
1215 final ArrayList<Folder> folders = mWorkspace.getOpenFolders();
1216 if (folders.size() > 0) {
1217 final int count = folders.size();
1218 long[] ids = new long[count];
1219 for (int i = 0; i < count; i++) {
1220 final FolderInfo info = folders.get(i).getInfo();
1221 ids[i] = info.id;
1222 }
1223 outState.putLongArray(RUNTIME_STATE_USER_FOLDERS, ids);
1224 } else {
1225 super.onSaveInstanceState(outState);
1226 }
1227
Joe Onoratofb0ca672009-09-14 17:55:46 -04001228 // TODO should not do this if the drawer is currently closing.
Joe Onorato3a8820b2009-11-10 15:06:42 -08001229 if (isAllAppsVisible()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001230 outState.putBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, true);
Romain Guy5a941392009-04-28 15:18:25 -07001231 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001232
Michael Jurka0280c3b2010-09-17 15:00:07 -07001233 if (mAddScreen > -1 && mWaitingForResult) {
1234 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mAddScreen);
1235 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mAddIntersectCellX);
1236 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001237 }
1238
1239 if (mFolderInfo != null && mWaitingForResult) {
1240 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1241 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1242 }
Michael Jurka946ad472010-07-09 18:05:18 -07001243
1244 if (mHomeCustomizationDrawer != null) {
1245 String currentTabTag = mHomeCustomizationDrawer.getCurrentTabTag();
1246 if (currentTabTag != null) {
1247 outState.putString("currentTab", currentTabTag);
1248 }
1249 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001250 }
1251
1252 @Override
1253 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001254 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001255
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001256 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001257 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001258 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001259 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001260 }
1261
1262 TextKeyListener.getInstance().release();
1263
Joe Onorato9c1289c2009-08-17 11:03:03 -04001264 mModel.stopLoader();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001265
Joe Onorato9c1289c2009-08-17 11:03:03 -04001266 unbindDesktopItems();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001267
1268 getContentResolver().unregisterContentObserver(mWidgetObserver);
Winson Chungaafa03c2010-06-11 17:34:16 -07001269
Patrick Dubroyab962b72010-07-26 12:10:10 -07001270 // Some launcher layouts don't have a previous and next view
1271 if (mPreviousView != null) {
1272 dismissPreview(mPreviousView);
1273 }
1274 if (mNextView != null) {
1275 dismissPreview(mNextView);
1276 }
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001277
1278 unregisterReceiver(mCloseSystemDialogsReceiver);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001279 }
1280
1281 @Override
1282 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001283 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001284 super.startActivityForResult(intent, requestCode);
1285 }
1286
1287 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001288 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001289 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001290
Joe Onorato7bb17492009-09-24 17:51:01 -07001291 closeAllApps(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001292
Karl Rosaen138a0412009-04-23 19:00:21 -07001293 if (initialQuery == null) {
1294 // Use any text typed in the launcher as the initial query
1295 initialQuery = getTypedText();
1296 clearTypedText();
1297 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001298 if (appSearchData == null) {
1299 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +00001300 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001301 }
Romain Guycbb89e42009-06-08 15:52:54 -07001302
Karl Rosaen138a0412009-04-23 19:00:21 -07001303 final SearchManager searchManager =
1304 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Karl Rosaen138a0412009-04-23 19:00:21 -07001305 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Romain Guycbb89e42009-06-08 15:52:54 -07001306 appSearchData, globalSearch);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001307 }
1308
1309 @Override
1310 public boolean onCreateOptionsMenu(Menu menu) {
Patrick Dubroy5905bca2010-09-08 22:43:38 -07001311 if (isWorkspaceLocked()) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001312 return false;
1313 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001314
1315 super.onCreateOptionsMenu(menu);
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001316
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001317 menu.add(MENU_GROUP_ADD, MENU_ADD, 0, R.string.menu_add)
1318 .setIcon(android.R.drawable.ic_menu_add)
1319 .setAlphabeticShortcut('A');
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001320 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001321 .setIcon(android.R.drawable.ic_menu_gallery)
1322 .setAlphabeticShortcut('W');
1323 menu.add(0, MENU_SEARCH, 0, R.string.menu_search)
1324 .setIcon(android.R.drawable.ic_search_category_default)
1325 .setAlphabeticShortcut(SearchManager.MENU_KEY);
1326 menu.add(0, MENU_NOTIFICATIONS, 0, R.string.menu_notifications)
1327 .setIcon(com.android.internal.R.drawable.ic_menu_notifications)
1328 .setAlphabeticShortcut('N');
1329
1330 final Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
Romain Guy5a941392009-04-28 15:18:25 -07001331 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
1332 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001333
1334 menu.add(0, MENU_SETTINGS, 0, R.string.menu_settings)
1335 .setIcon(android.R.drawable.ic_menu_preferences).setAlphabeticShortcut('P')
1336 .setIntent(settings);
1337
1338 return true;
1339 }
1340
1341 @Override
1342 public boolean onPrepareOptionsMenu(Menu menu) {
1343 super.onPrepareOptionsMenu(menu);
1344
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001345 // If all apps is animating, don't show the menu, because we don't know
1346 // which one to show.
Patrick Dubroyff5f0402010-07-26 15:23:26 -07001347 if (mAllAppsGrid.isAnimating()) {
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001348 return false;
1349 }
1350
1351 // Only show the add and wallpaper options when we're not in all apps.
Patrick Dubroyff5f0402010-07-26 15:23:26 -07001352 boolean visible = !mAllAppsGrid.isVisible();
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001353 menu.setGroupVisible(MENU_GROUP_ADD, visible);
1354 menu.setGroupVisible(MENU_GROUP_WALLPAPER, visible);
1355
1356 // Disable add if the workspace is full.
1357 if (visible) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001358 CellLayout layout = (CellLayout) mWorkspace.getChildAt(mWorkspace.getCurrentPage());
1359 menu.setGroupEnabled(MENU_GROUP_ADD, layout.existsEmptyCell());
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001360 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001361
1362 return true;
1363 }
1364
1365 @Override
1366 public boolean onOptionsItemSelected(MenuItem item) {
1367 switch (item.getItemId()) {
1368 case MENU_ADD:
1369 addItems();
1370 return true;
1371 case MENU_WALLPAPER_SETTINGS:
1372 startWallpaper();
1373 return true;
1374 case MENU_SEARCH:
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001375 onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001376 return true;
1377 case MENU_NOTIFICATIONS:
1378 showNotifications();
1379 return true;
1380 }
1381
1382 return super.onOptionsItemSelected(item);
1383 }
Romain Guycbb89e42009-06-08 15:52:54 -07001384
Karl Rosaen138a0412009-04-23 19:00:21 -07001385 /**
1386 * Indicates that we want global search for this activity by setting the globalSearch
1387 * argument for {@link #startSearch} to true.
1388 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001389
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001390 @Override
1391 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001392 startSearch(null, false, null, true);
Karl Rosaen138a0412009-04-23 19:00:21 -07001393 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001394 }
1395
Joe Onorato9c1289c2009-08-17 11:03:03 -04001396 public boolean isWorkspaceLocked() {
1397 return mWorkspaceLoading || mWaitingForResult;
1398 }
1399
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001400 private void addItems() {
Patrick Dubroy558654c2010-07-23 16:48:11 -07001401 if (LauncherApplication.isScreenXLarge()) {
1402 // Animate the widget chooser up from the bottom of the screen
1403 if (!isCustomizationDrawerVisible()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07001404 showCustomizationDrawer(true);
Patrick Dubroy558654c2010-07-23 16:48:11 -07001405 }
1406 } else {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001407 closeAllApps(true);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001408 showAddDialog(-1, -1);
Patrick Dubroy558654c2010-07-23 16:48:11 -07001409 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001410 }
1411
Michael Jurka0280c3b2010-09-17 15:00:07 -07001412 private void resetAddInfo() {
1413 mAddScreen = -1;
1414 mAddIntersectCellX = -1;
1415 mAddIntersectCellY = -1;
1416 mAddDropPosition = null;
1417 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001418
Michael Jurka0280c3b2010-09-17 15:00:07 -07001419 void addAppWidgetFromDrop(ComponentName appWidgetProvider, int screen, int[] position) {
1420 resetAddInfo();
1421 mAddScreen = screen;
1422
1423 // only set mAddDropPosition if we dropped on home screen in "spring-loaded" manner
1424 mAddDropPosition = position;
1425
Michael Jurkaaf442092010-06-10 17:01:57 -07001426 int appWidgetId = getAppWidgetHost().allocateAppWidgetId();
1427 AppWidgetManager.getInstance(this).bindAppWidgetId(appWidgetId, appWidgetProvider);
1428 addAppWidgetImpl(appWidgetId);
1429 }
1430
1431 void addAppWidgetFromPick(Intent data) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001432 // TODO: catch bad widget exception when sent
1433 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurkaaf442092010-06-10 17:01:57 -07001434 // TODO: Is this log message meaningful?
1435 if (LOGD) Log.d(TAG, "dumping extras content=" + data.getExtras());
1436 addAppWidgetImpl(appWidgetId);
1437 }
1438
1439 void addAppWidgetImpl(int appWidgetId) {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001440 AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001441
Bjorn Bringert7984c942009-12-09 15:38:25 +00001442 if (appWidget.configure != null) {
1443 // Launch over to configure widget, if needed
1444 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
1445 intent.setComponent(appWidget.configure);
1446 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
1447
Romain Guy8e633c52010-03-04 12:51:36 -08001448 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001449 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001450 // Otherwise just add it
Michael Jurka0280c3b2010-09-17 15:00:07 -07001451 completeAddAppWidget(appWidgetId, mAddScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001452 }
1453 }
Romain Guycbb89e42009-06-08 15:52:54 -07001454
Michael Jurka0280c3b2010-09-17 15:00:07 -07001455 void processShortcutFromDrop(ComponentName componentName, int screen, int[] position) {
1456 resetAddInfo();
1457 mAddScreen = screen;
1458 mAddDropPosition = position;
1459
1460 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1461 createShortcutIntent.setComponent(componentName);
1462 processShortcut(createShortcutIntent);
1463 }
1464
Joe Onoratodeb98af2010-02-19 14:59:39 -08001465 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001466 // Handle case where user selected "Applications"
1467 String applicationName = getResources().getString(R.string.group_applications);
1468 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001469
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001470 if (applicationName != null && applicationName.equals(shortcutName)) {
1471 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1472 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001473
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001474 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1475 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Joe Onoratodeb98af2010-02-19 14:59:39 -08001476 startActivityForResult(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001477 } else {
Joe Onoratodeb98af2010-02-19 14:59:39 -08001478 startActivityForResult(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001479 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001480 }
1481
Winson Chung24ab2f12010-09-16 14:10:47 -07001482 void processWallpaper(Intent intent) {
1483 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1484 }
1485
Michael Jurka0280c3b2010-09-17 15:00:07 -07001486 void addLiveFolderFromDrop(ComponentName componentName, int screen, int[] position) {
1487 resetAddInfo();
1488 mAddScreen = screen;
1489 mAddDropPosition = position;
1490
1491 Intent createFolderIntent = new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER);
1492 createFolderIntent.setComponent(componentName);
1493
1494 addLiveFolder(createFolderIntent);
1495 }
1496
1497 void addLiveFolder(Intent intent) { // YYY add screen intersect etc. parameters here
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001498 // Handle case where user selected "Folder"
Jeffrey Sharkeyc4bbd0a2009-03-24 22:47:52 -07001499 String folderName = getResources().getString(R.string.group_folder);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001500 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001501
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001502 if (folderName != null && folderName.equals(shortcutName)) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001503 addFolder(mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001504 } else {
1505 startActivityForResult(intent, REQUEST_CREATE_LIVE_FOLDER);
1506 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001507 }
1508
Michael Jurka0280c3b2010-09-17 15:00:07 -07001509 void addFolder(int screen, int intersectCellX, int intersectCellY) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001510 UserFolderInfo folderInfo = new UserFolderInfo();
1511 folderInfo.title = getText(R.string.folder_name);
1512
Michael Jurka0280c3b2010-09-17 15:00:07 -07001513 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1514 final int[] cellXY = mTmpAddItemCellCoordinates;
1515 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1516 showOutOfSpaceMessage();
1517 return;
1518 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001519
1520 // Update the model
Joe Onorato9c1289c2009-08-17 11:03:03 -04001521 LauncherModel.addItemToDatabase(this, folderInfo,
1522 LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001523 screen, cellXY[0], cellXY[1], false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001524 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001525
1526 // Create the view
1527 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07001528 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), folderInfo);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001529 mWorkspace.addInScreen(newFolder, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001530 }
Romain Guycbb89e42009-06-08 15:52:54 -07001531
Joe Onorato9c1289c2009-08-17 11:03:03 -04001532 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001533 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001534 }
1535
Michael Jurka28750fb2010-09-24 17:43:49 -07001536 private void completeAddLiveFolder(
1537 Intent data, int screen, int intersectCellX, int intersectCellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001538 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1539 final int[] cellXY = mTmpAddItemCellCoordinates;
1540 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1541 showOutOfSpaceMessage();
1542 return;
1543 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001544
Michael Jurka0280c3b2010-09-17 15:00:07 -07001545 final LiveFolderInfo info = addLiveFolder(this, data, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001546
1547 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001548 final View view = LiveFolderIcon.fromXml(R.layout.live_folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07001549 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001550 mWorkspace.addInScreen(view, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001551 }
1552 }
1553
1554 static LiveFolderInfo addLiveFolder(Context context, Intent data,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001555 int screen, int cellX, int cellY, boolean notify) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001556
1557 Intent baseIntent = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT);
1558 String name = data.getStringExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME);
1559
1560 Drawable icon = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001561 Intent.ShortcutIconResource iconResource = null;
1562
1563 Parcelable extra = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON);
1564 if (extra != null && extra instanceof Intent.ShortcutIconResource) {
1565 try {
1566 iconResource = (Intent.ShortcutIconResource) extra;
1567 final PackageManager packageManager = context.getPackageManager();
1568 Resources resources = packageManager.getResourcesForApplication(
1569 iconResource.packageName);
1570 final int id = resources.getIdentifier(iconResource.resourceName, null, null);
1571 icon = resources.getDrawable(id);
1572 } catch (Exception e) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001573 Log.w(TAG, "Could not load live folder icon: " + extra);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001574 }
1575 }
1576
1577 if (icon == null) {
1578 icon = context.getResources().getDrawable(R.drawable.ic_launcher_folder);
1579 }
1580
1581 final LiveFolderInfo info = new LiveFolderInfo();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001582 info.icon = Utilities.createIconBitmap(icon, context);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001583 info.title = name;
1584 info.iconResource = iconResource;
1585 info.uri = data.getData();
1586 info.baseIntent = baseIntent;
1587 info.displayMode = data.getIntExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE,
1588 LiveFolders.DISPLAY_MODE_GRID);
1589
1590 LauncherModel.addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001591 screen, cellX, cellY, notify);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001592 sFolders.put(info.id, info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001593
1594 return info;
1595 }
1596
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001597 private void showNotifications() {
1598 final StatusBarManager statusBar = (StatusBarManager) getSystemService(STATUS_BAR_SERVICE);
1599 if (statusBar != null) {
1600 statusBar.expand();
1601 }
1602 }
1603
1604 private void startWallpaper() {
Joe Onoratoe6168662009-11-08 13:39:30 -05001605 closeAllApps(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001606 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001607 Intent chooser = Intent.createChooser(pickWallpaper,
1608 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001609 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1610 // Removed in Eclair MR1
1611// WallpaperManager wm = (WallpaperManager)
1612// getSystemService(Context.WALLPAPER_SERVICE);
1613// WallpaperInfo wi = wm.getWallpaperInfo();
1614// if (wi != null && wi.getSettingsActivity() != null) {
1615// LabeledIntent li = new LabeledIntent(getPackageName(),
1616// R.string.configure_wallpaper, 0);
1617// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1618// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1619// }
Mike Clerona0618e42009-10-22 13:55:21 -07001620 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001621 }
1622
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001623 /**
1624 * Registers various content observers. The current implementation registers
1625 * only a favorites observer to keep track of the favorites applications.
1626 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001627 private void registerContentObservers() {
1628 ContentResolver resolver = getContentResolver();
1629 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1630 true, mWidgetObserver);
1631 }
1632
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001633 @Override
1634 public boolean dispatchKeyEvent(KeyEvent event) {
1635 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1636 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001637 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001638 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001639 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jason Samseb5615d2009-11-30 11:50:10 -08001640 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
Joe Onoratobe386092009-11-17 17:32:16 -08001641 dumpState();
1642 return true;
1643 }
1644 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001645 }
1646 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1647 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001648 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001649 return true;
1650 }
1651 }
1652
1653 return super.dispatchKeyEvent(event);
1654 }
1655
Joe Onorato88ec0992009-11-19 13:16:06 -08001656 @Override
1657 public void onBackPressed() {
1658 if (isAllAppsVisible()) {
1659 closeAllApps(true);
Patrick Dubroy558654c2010-07-23 16:48:11 -07001660 } else if (isCustomizationDrawerVisible()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07001661 hideCustomizationDrawer(true);
Joe Onorato88ec0992009-11-19 13:16:06 -08001662 } else {
1663 closeFolder();
1664 }
Michael Jurkaaf442092010-06-10 17:01:57 -07001665 // Some launcher layouts don't have a previous and next view
1666 if (mPreviousView != null) {
1667 dismissPreview(mPreviousView);
1668 dismissPreview(mNextView);
1669 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001670 }
1671
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001672 private void closeFolder() {
1673 Folder folder = mWorkspace.getOpenFolder();
1674 if (folder != null) {
1675 closeFolder(folder);
1676 }
1677 }
1678
1679 void closeFolder(Folder folder) {
1680 folder.getInfo().opened = false;
1681 ViewGroup parent = (ViewGroup) folder.getParent();
1682 if (parent != null) {
1683 parent.removeView(folder);
Joe Onoratob6341e92009-11-02 10:41:48 -05001684 if (folder instanceof DropTarget) {
1685 // Live folders aren't DropTargets.
1686 mDragController.removeDropTarget((DropTarget)folder);
1687 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001688 }
1689 folder.onClose();
1690 }
1691
1692 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001693 * Re-listen when widgets are reset.
1694 */
1695 private void onAppWidgetReset() {
1696 mAppWidgetHost.startListening();
1697 }
1698
1699 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001700 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1701 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001702 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04001703 private void unbindDesktopItems() {
1704 for (ItemInfo item: mDesktopItems) {
1705 item.unbind();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001706 }
1707 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001708
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001709 /**
1710 * Launches the intent referred by the clicked shortcut.
1711 *
1712 * @param v The view representing the clicked shortcut.
1713 */
1714 public void onClick(View v) {
1715 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001716 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001717 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08001718 final Intent intent = ((ShortcutInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001719 int[] pos = new int[2];
1720 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08001721 intent.setSourceBounds(new Rect(pos[0], pos[1],
1722 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Joe Onoratof984e852010-03-25 09:47:45 -07001723 startActivitySafely(intent, tag);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001724 } else if (tag instanceof FolderInfo) {
1725 handleFolderClick((FolderInfo) tag);
Joe Onorato7404ee42009-07-31 11:54:44 -07001726 } else if (v == mHandleView) {
Joe Onoratofb0ca672009-09-14 17:55:46 -04001727 if (isAllAppsVisible()) {
Joe Onorato7bb17492009-09-24 17:51:01 -07001728 closeAllApps(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001729 } else {
Joe Onorato3a8820b2009-11-10 15:06:42 -08001730 showAllApps(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001731 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001732 }
1733 }
1734
Michael Jurka0e260592010-06-30 17:07:39 -07001735 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07001736 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurka0e260592010-06-30 17:07:39 -07001737 // clicking anywhere on the workspace causes the drawer to slide down
Patrick Dubroy6b509c12010-08-23 15:08:16 -07001738 hideCustomizationDrawer(true);
Michael Jurka0e260592010-06-30 17:07:39 -07001739 return false;
1740 }
1741
Michael Jurkaaf442092010-06-10 17:01:57 -07001742 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001743 * Event handler for the search button
1744 *
1745 * @param v The view that was clicked.
1746 */
1747 public void onClickSearchButton(View v) {
1748 Intent i = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
1749 View button = findViewById(R.id.search_button);
1750 i.setSourceBounds(
1751 new Rect(button.getLeft(), button.getTop(), button.getRight(), button.getBottom()));
1752 startActivity(i);
1753 }
1754
1755 /**
1756 * Event handler for the "gear" button that appears on the home screen, which
Michael Jurkaaf442092010-06-10 17:01:57 -07001757 * enters home screen customization mode.
1758 *
1759 * @param v The view that was clicked.
1760 */
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001761 public void onClickConfigureButton(View v) {
Patrick Dubroy558654c2010-07-23 16:48:11 -07001762 addItems();
Michael Jurkaaf442092010-06-10 17:01:57 -07001763 }
1764
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001765 /**
1766 * Event handler for the "grid" button that appears on the home screen, which
1767 * enters all apps mode.
1768 *
1769 * @param v The view that was clicked.
1770 */
1771 public void onClickAllAppsButton(View v) {
1772 showAllApps(true);
1773 }
1774
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001775 public void onClickAppMarketButton(View v) {
1776 if (mAppMarketIntent != null) {
1777 startActivitySafely(mAppMarketIntent, "app market");
1778 }
1779 }
1780
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001781 void startApplicationDetailsActivity(ComponentName componentName) {
1782 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001783 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
1784 Uri.fromParts("package", packageName, null));
1785 startActivity(intent);
1786 }
1787
Patrick Dubroy5539af72010-09-07 15:22:01 -07001788 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
1789 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
1790 // System applications cannot be installed. For now, show a toast explaining that.
1791 // We may give them the option of disabling apps this way.
1792 int messageId = R.string.uninstall_system_app_text;
1793 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
1794 } else {
1795 String packageName = appInfo.componentName.getPackageName();
1796 String className = appInfo.componentName.getClassName();
1797 Intent intent = new Intent(
1798 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
1799 startActivity(intent);
1800 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001801 }
1802
Joe Onoratof984e852010-03-25 09:47:45 -07001803 void startActivitySafely(Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001804 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1805 try {
1806 startActivity(intent);
1807 } catch (ActivityNotFoundException e) {
1808 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Daniel Sandlerc9b18772010-04-22 14:37:59 -04001809 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001810 } catch (SecurityException e) {
1811 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001812 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001813 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07001814 "or use the exported attribute for this activity. "
1815 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001816 }
1817 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001818
Romain Guy8e633c52010-03-04 12:51:36 -08001819 void startActivityForResultSafely(Intent intent, int requestCode) {
1820 try {
1821 startActivityForResult(intent, requestCode);
1822 } catch (ActivityNotFoundException e) {
1823 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1824 } catch (SecurityException e) {
1825 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1826 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
1827 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
1828 "or use the exported attribute for this activity.", e);
1829 }
1830 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001831
1832 private void handleFolderClick(FolderInfo folderInfo) {
1833 if (!folderInfo.opened) {
1834 // Close any open folder
1835 closeFolder();
1836 // Open the requested folder
1837 openFolder(folderInfo);
1838 } else {
1839 // Find the open folder...
1840 Folder openFolder = mWorkspace.getFolderForTag(folderInfo);
1841 int folderScreen;
1842 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07001843 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001844 // .. and close it
1845 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07001846 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001847 // Close any folder open on the current screen
1848 closeFolder();
1849 // Pull the folder onto this screen
1850 openFolder(folderInfo);
1851 }
1852 }
1853 }
1854 }
1855
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001856 /**
1857 * Opens the user fodler described by the specified tag. The opening of the folder
1858 * is animated relative to the specified View. If the View is null, no animation
1859 * is played.
1860 *
1861 * @param folderInfo The FolderInfo describing the folder to open.
1862 */
Winson Chungaafa03c2010-06-11 17:34:16 -07001863 public void openFolder(FolderInfo folderInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001864 Folder openFolder;
1865
1866 if (folderInfo instanceof UserFolderInfo) {
1867 openFolder = UserFolder.fromXml(this);
1868 } else if (folderInfo instanceof LiveFolderInfo) {
Joe Onoratoa5902522009-07-30 13:37:37 -07001869 openFolder = com.android.launcher2.LiveFolder.fromXml(this, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001870 } else {
1871 return;
1872 }
1873
Joe Onorato00acb122009-08-04 16:04:30 -04001874 openFolder.setDragController(mDragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001875 openFolder.setLauncher(this);
1876
1877 openFolder.bind(folderInfo);
1878 folderInfo.opened = true;
1879
Winson Chungaafa03c2010-06-11 17:34:16 -07001880 mWorkspace.addInFullScreen(openFolder, folderInfo.screen);
1881
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001882 openFolder.onOpen();
1883 }
1884
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001885 public boolean onLongClick(View v) {
Romain Guy1fbc1c82009-11-09 20:43:08 -08001886 switch (v.getId()) {
1887 case R.id.previous_screen:
Joe Onorato0d44e942009-11-16 18:20:51 -08001888 if (!isAllAppsVisible()) {
1889 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1890 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Romain Guyf8e6a802009-12-07 17:48:02 -08001891 showPreviews(v);
Joe Onorato0d44e942009-11-16 18:20:51 -08001892 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08001893 return true;
1894 case R.id.next_screen:
Joe Onorato0d44e942009-11-16 18:20:51 -08001895 if (!isAllAppsVisible()) {
1896 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1897 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Romain Guyf8e6a802009-12-07 17:48:02 -08001898 showPreviews(v);
1899 }
1900 return true;
1901 case R.id.all_apps_button:
1902 if (!isAllAppsVisible()) {
1903 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1904 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
1905 showPreviews(v);
Joe Onorato0d44e942009-11-16 18:20:51 -08001906 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08001907 return true;
1908 }
1909
Joe Onorato9c1289c2009-08-17 11:03:03 -04001910 if (isWorkspaceLocked()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001911 return false;
1912 }
1913
1914 if (!(v instanceof CellLayout)) {
1915 v = (View) v.getParent();
1916 }
1917
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001918
Michael Jurka0280c3b2010-09-17 15:00:07 -07001919 resetAddInfo();
1920 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001921 // This happens when long clicking an item with the dpad/trackball
Michael Jurka0280c3b2010-09-17 15:00:07 -07001922 if (longClickCellInfo == null || !longClickCellInfo.valid) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001923 return true;
1924 }
1925
Michael Jurka0280c3b2010-09-17 15:00:07 -07001926 final View itemUnderLongClick = longClickCellInfo.cell;
1927
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001928 if (mWorkspace.allowLongPress()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001929 if (itemUnderLongClick == null) {
1930 // User long pressed on empty space
1931 mWorkspace.setAllowLongPress(false);
1932 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1933 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
1934 if (LauncherApplication.isScreenXLarge()) {
1935 // Animate the widget chooser up from the bottom of the screen
1936 if (!isCustomizationDrawerVisible()) {
1937 showCustomizationDrawer(true);
1938 }
1939 } else {
1940 showAddDialog(longClickCellInfo.cellX, longClickCellInfo.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001941 }
1942 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001943 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001944 // User long pressed on an item
Joe Onorato0d44e942009-11-16 18:20:51 -08001945 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1946 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001947 mAddIntersectCellX = longClickCellInfo.cellX;
1948 mAddIntersectCellY = longClickCellInfo.cellY;
1949 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001950 }
1951 }
1952 }
1953 return true;
1954 }
1955
Romain Guye6b8e2f2009-11-10 11:56:55 -08001956 @SuppressWarnings({"unchecked"})
Romain Guy9d31e9f2009-11-11 18:54:28 -08001957 private void dismissPreview(final View v) {
1958 final PopupWindow window = (PopupWindow) v.getTag();
Romain Guy1fbc1c82009-11-09 20:43:08 -08001959 if (window != null) {
Romain Guy9d31e9f2009-11-11 18:54:28 -08001960 window.setOnDismissListener(new PopupWindow.OnDismissListener() {
1961 public void onDismiss() {
1962 ViewGroup group = (ViewGroup) v.getTag(R.id.workspace);
1963 int count = group.getChildCount();
1964 for (int i = 0; i < count; i++) {
1965 ((ImageView) group.getChildAt(i)).setImageDrawable(null);
1966 }
Romain Guy9d31e9f2009-11-11 18:54:28 -08001967 ArrayList<Bitmap> bitmaps = (ArrayList<Bitmap>) v.getTag(R.id.icon);
1968 for (Bitmap bitmap : bitmaps) bitmap.recycle();
1969
1970 v.setTag(R.id.workspace, null);
1971 v.setTag(R.id.icon, null);
1972 window.setOnDismissListener(null);
1973 }
1974 });
Romain Guy1fbc1c82009-11-09 20:43:08 -08001975 window.dismiss();
Romain Guy1fbc1c82009-11-09 20:43:08 -08001976 }
1977 v.setTag(null);
1978 }
1979
Romain Guyf8e6a802009-12-07 17:48:02 -08001980 private void showPreviews(View anchor) {
Romain Guy9d31e9f2009-11-11 18:54:28 -08001981 showPreviews(anchor, 0, mWorkspace.getChildCount());
Romain Guy1fbc1c82009-11-09 20:43:08 -08001982 }
1983
Romain Guya6abce82009-11-10 02:54:41 -08001984 private void showPreviews(final View anchor, int start, int end) {
Romain Guyf8e6a802009-12-07 17:48:02 -08001985 final Resources resources = getResources();
1986 final Workspace workspace = mWorkspace;
Romain Guy1fbc1c82009-11-09 20:43:08 -08001987
Romain Guya6abce82009-11-10 02:54:41 -08001988 CellLayout cell = ((CellLayout) workspace.getChildAt(start));
Winson Chungaafa03c2010-06-11 17:34:16 -07001989
Romain Guy9d31e9f2009-11-11 18:54:28 -08001990 float max = workspace.getChildCount();
Winson Chungaafa03c2010-06-11 17:34:16 -07001991
Romain Guyf8e6a802009-12-07 17:48:02 -08001992 final Rect r = new Rect();
Romain Guy9d31e9f2009-11-11 18:54:28 -08001993 resources.getDrawable(R.drawable.preview_background).getPadding(r);
Romain Guye6b8e2f2009-11-10 11:56:55 -08001994 int extraW = (int) ((r.left + r.right) * max);
1995 int extraH = r.top + r.bottom;
Romain Guya6abce82009-11-10 02:54:41 -08001996
1997 int aW = cell.getWidth() - extraW;
1998 float w = aW / max;
1999
2000 int width = cell.getWidth();
2001 int height = cell.getHeight();
2002 int x = cell.getLeftPadding();
2003 int y = cell.getTopPadding();
2004 width -= (x + cell.getRightPadding());
2005 height -= (y + cell.getBottomPadding());
2006
2007 float scale = w / width;
2008
2009 int count = end - start;
2010
2011 final float sWidth = width * scale;
2012 float sHeight = height * scale;
2013
Romain Guye6b8e2f2009-11-10 11:56:55 -08002014 LinearLayout preview = new LinearLayout(this);
Romain Guya6abce82009-11-10 02:54:41 -08002015
Romain Guye6b8e2f2009-11-10 11:56:55 -08002016 PreviewTouchHandler handler = new PreviewTouchHandler(anchor);
2017 ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>(count);
Romain Guya6abce82009-11-10 02:54:41 -08002018
2019 for (int i = start; i < end; i++) {
Romain Guye6b8e2f2009-11-10 11:56:55 -08002020 ImageView image = new ImageView(this);
Romain Guya6abce82009-11-10 02:54:41 -08002021 cell = (CellLayout) workspace.getChildAt(i);
2022
Romain Guyf8e6a802009-12-07 17:48:02 -08002023 final Bitmap bitmap = Bitmap.createBitmap((int) sWidth, (int) sHeight,
Romain Guye6b8e2f2009-11-10 11:56:55 -08002024 Bitmap.Config.ARGB_8888);
Romain Guyf8e6a802009-12-07 17:48:02 -08002025
2026 final Canvas c = new Canvas(bitmap);
Romain Guya6abce82009-11-10 02:54:41 -08002027 c.scale(scale, scale);
2028 c.translate(-cell.getLeftPadding(), -cell.getTopPadding());
2029 cell.dispatchDraw(c);
Romain Guya6abce82009-11-10 02:54:41 -08002030
Romain Guy9d31e9f2009-11-11 18:54:28 -08002031 image.setBackgroundDrawable(resources.getDrawable(R.drawable.preview_background));
Romain Guye6b8e2f2009-11-10 11:56:55 -08002032 image.setImageBitmap(bitmap);
2033 image.setTag(i);
2034 image.setOnClickListener(handler);
Romain Guy9d31e9f2009-11-11 18:54:28 -08002035 image.setOnFocusChangeListener(handler);
2036 image.setFocusable(true);
Michael Jurka0142d492010-08-25 17:46:15 -07002037 if (i == mWorkspace.getCurrentPage()) image.requestFocus();
Romain Guye6b8e2f2009-11-10 11:56:55 -08002038
2039 preview.addView(image,
Romain Guy9d31e9f2009-11-11 18:54:28 -08002040 LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
2041
Winson Chungaafa03c2010-06-11 17:34:16 -07002042 bitmaps.add(bitmap);
Romain Guya6abce82009-11-10 02:54:41 -08002043 }
Romain Guyf8e6a802009-12-07 17:48:02 -08002044
2045 final PopupWindow p = new PopupWindow(this);
Romain Guye6b8e2f2009-11-10 11:56:55 -08002046 p.setContentView(preview);
2047 p.setWidth((int) (sWidth * count + extraW));
2048 p.setHeight((int) (sHeight + extraH));
2049 p.setAnimationStyle(R.style.AnimationPreview);
2050 p.setOutsideTouchable(true);
Romain Guy9d31e9f2009-11-11 18:54:28 -08002051 p.setFocusable(true);
Romain Guyff0c2e22009-11-10 12:09:59 -08002052 p.setBackgroundDrawable(new ColorDrawable(0));
Romain Guy9d31e9f2009-11-11 18:54:28 -08002053 p.showAsDropDown(anchor, 0, 0);
Romain Guya6abce82009-11-10 02:54:41 -08002054
Romain Guye6b8e2f2009-11-10 11:56:55 -08002055 p.setOnDismissListener(new PopupWindow.OnDismissListener() {
2056 public void onDismiss() {
2057 dismissPreview(anchor);
2058 }
2059 });
Romain Guy1fbc1c82009-11-09 20:43:08 -08002060
2061 anchor.setTag(p);
2062 anchor.setTag(R.id.workspace, preview);
Winson Chungaafa03c2010-06-11 17:34:16 -07002063 anchor.setTag(R.id.icon, bitmaps);
Romain Guy1fbc1c82009-11-09 20:43:08 -08002064 }
2065
Romain Guy9d31e9f2009-11-11 18:54:28 -08002066 class PreviewTouchHandler implements View.OnClickListener, Runnable, View.OnFocusChangeListener {
Romain Guya6abce82009-11-10 02:54:41 -08002067 private final View mAnchor;
Romain Guya6abce82009-11-10 02:54:41 -08002068
Romain Guye6b8e2f2009-11-10 11:56:55 -08002069 public PreviewTouchHandler(View anchor) {
Romain Guya6abce82009-11-10 02:54:41 -08002070 mAnchor = anchor;
Romain Guya6abce82009-11-10 02:54:41 -08002071 }
2072
2073 public void onClick(View v) {
Michael Jurka0142d492010-08-25 17:46:15 -07002074 mWorkspace.snapToPage((Integer) v.getTag());
Romain Guy9d31e9f2009-11-11 18:54:28 -08002075 v.post(this);
2076 }
2077
2078 public void run() {
Winson Chungaafa03c2010-06-11 17:34:16 -07002079 dismissPreview(mAnchor);
Romain Guy9d31e9f2009-11-11 18:54:28 -08002080 }
2081
2082 public void onFocusChange(View v, boolean hasFocus) {
2083 if (hasFocus) {
Michael Jurka0142d492010-08-25 17:46:15 -07002084 mWorkspace.snapToPage((Integer) v.getTag());
Romain Guy9d31e9f2009-11-11 18:54:28 -08002085 }
Romain Guya6abce82009-11-10 02:54:41 -08002086 }
2087 }
2088
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002089 Workspace getWorkspace() {
2090 return mWorkspace;
2091 }
2092
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002093 @Override
2094 protected Dialog onCreateDialog(int id) {
2095 switch (id) {
2096 case DIALOG_CREATE_SHORTCUT:
2097 return new CreateShortcut().createDialog();
2098 case DIALOG_RENAME_FOLDER:
2099 return new RenameFolder().createDialog();
2100 }
2101
2102 return super.onCreateDialog(id);
2103 }
2104
2105 @Override
2106 protected void onPrepareDialog(int id, Dialog dialog) {
2107 switch (id) {
2108 case DIALOG_CREATE_SHORTCUT:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002109 break;
2110 case DIALOG_RENAME_FOLDER:
Romain Guy7b4ef332009-07-14 13:58:08 -07002111 if (mFolderInfo != null) {
2112 EditText input = (EditText) dialog.findViewById(R.id.folder_name);
2113 final CharSequence text = mFolderInfo.title;
2114 input.setText(text);
2115 input.setSelection(0, text.length());
2116 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002117 break;
2118 }
2119 }
2120
2121 void showRenameDialog(FolderInfo info) {
2122 mFolderInfo = info;
2123 mWaitingForResult = true;
2124 showDialog(DIALOG_RENAME_FOLDER);
2125 }
2126
Michael Jurka0280c3b2010-09-17 15:00:07 -07002127 private void showAddDialog(int intersectX, int intersectY) {
2128 resetAddInfo();
2129 mAddIntersectCellX = intersectX;
2130 mAddIntersectCellY = intersectY;
2131 mAddScreen = mWorkspace.getCurrentPage();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002132 mWaitingForResult = true;
2133 showDialog(DIALOG_CREATE_SHORTCUT);
2134 }
2135
Joe Onoratodeb98af2010-02-19 14:59:39 -08002136 private void pickShortcut() {
Michael Jurka0e260592010-06-30 17:07:39 -07002137 // Insert extra item to handle picking application
Romain Guy73b979d2009-06-09 12:57:21 -07002138 Bundle bundle = new Bundle();
2139
2140 ArrayList<String> shortcutNames = new ArrayList<String>();
2141 shortcutNames.add(getString(R.string.group_applications));
2142 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
2143
2144 ArrayList<ShortcutIconResource> shortcutIcons = new ArrayList<ShortcutIconResource>();
2145 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
2146 R.drawable.ic_launcher_application));
2147 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
2148
2149 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2150 pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_CREATE_SHORTCUT));
Joe Onoratodeb98af2010-02-19 14:59:39 -08002151 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_shortcut));
Romain Guy73b979d2009-06-09 12:57:21 -07002152 pickIntent.putExtras(bundle);
2153
Joe Onoratodeb98af2010-02-19 14:59:39 -08002154 startActivityForResult(pickIntent, REQUEST_PICK_SHORTCUT);
Romain Guy73b979d2009-06-09 12:57:21 -07002155 }
2156
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002157 private class RenameFolder {
2158 private EditText mInput;
2159
2160 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002161 final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null);
2162 mInput = (EditText) layout.findViewById(R.id.folder_name);
2163
2164 AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
2165 builder.setIcon(0);
2166 builder.setTitle(getString(R.string.rename_folder_title));
2167 builder.setCancelable(true);
2168 builder.setOnCancelListener(new Dialog.OnCancelListener() {
2169 public void onCancel(DialogInterface dialog) {
2170 cleanup();
2171 }
2172 });
2173 builder.setNegativeButton(getString(R.string.cancel_action),
2174 new Dialog.OnClickListener() {
2175 public void onClick(DialogInterface dialog, int which) {
2176 cleanup();
2177 }
2178 }
2179 );
2180 builder.setPositiveButton(getString(R.string.rename_action),
2181 new Dialog.OnClickListener() {
2182 public void onClick(DialogInterface dialog, int which) {
2183 changeFolderName();
2184 }
2185 }
2186 );
2187 builder.setView(layout);
Romain Guy7b4ef332009-07-14 13:58:08 -07002188
2189 final AlertDialog dialog = builder.create();
2190 dialog.setOnShowListener(new DialogInterface.OnShowListener() {
2191 public void onShow(DialogInterface dialog) {
Joe Onorato7018d8e2010-04-13 20:25:47 -07002192 mWaitingForResult = true;
Joe Onoratod753b422009-11-08 13:31:11 -05002193 mInput.requestFocus();
2194 InputMethodManager inputManager = (InputMethodManager)
2195 getSystemService(Context.INPUT_METHOD_SERVICE);
2196 inputManager.showSoftInput(mInput, 0);
Romain Guy7b4ef332009-07-14 13:58:08 -07002197 }
2198 });
2199
2200 return dialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002201 }
2202
2203 private void changeFolderName() {
2204 final String name = mInput.getText().toString();
2205 if (!TextUtils.isEmpty(name)) {
2206 // Make sure we have the right folder info
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002207 mFolderInfo = sFolders.get(mFolderInfo.id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002208 mFolderInfo.title = name;
2209 LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo);
2210
Joe Onorato9c1289c2009-08-17 11:03:03 -04002211 if (mWorkspaceLoading) {
Joe Onorato7c312c12009-08-13 21:36:53 -07002212 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002213 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002214 } else {
2215 final FolderIcon folderIcon = (FolderIcon)
2216 mWorkspace.getViewForTag(mFolderInfo);
2217 if (folderIcon != null) {
2218 folderIcon.setText(name);
2219 getWorkspace().requestLayout();
2220 } else {
Joe Onorato7c312c12009-08-13 21:36:53 -07002221 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002222 mWorkspaceLoading = true;
2223 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002224 }
2225 }
2226 }
2227 cleanup();
2228 }
2229
2230 private void cleanup() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002231 dismissDialog(DIALOG_RENAME_FOLDER);
2232 mWaitingForResult = false;
2233 mFolderInfo = null;
2234 }
2235 }
2236
Daniel Sandler843e8602010-06-07 14:59:01 -04002237 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
2238 public boolean isAllAppsVisible() {
Romain Guy5bbc91b2010-08-18 11:38:46 -07002239 return mAllAppsGrid != null && mAllAppsGrid.isVisible();
Joe Onoratofb0ca672009-09-14 17:55:46 -04002240 }
2241
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002242 // AllAppsView.Watcher
2243 public void zoomed(float zoom) {
Michael Jurka213d9632010-07-28 11:29:25 -07002244 // In XLarge view, we zoom down the workspace below all apps so it's still visible
2245 if (zoom == 1.0f && !LauncherApplication.isScreenXLarge()) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002246 mWorkspace.setVisibility(View.GONE);
2247 }
2248 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002249
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002250 private void showToolbarButton(View button) {
2251 button.setAlpha(1.0f);
2252 button.setVisibility(View.VISIBLE);
2253 button.setFocusable(true);
2254 button.setClickable(true);
2255 }
2256
2257 private void hideToolbarButton(View button) {
2258 button.setAlpha(0.0f);
2259 // We can't set it to GONE, otherwise the RelativeLayout gets screwed up
2260 button.setVisibility(View.INVISIBLE);
2261 button.setFocusable(false);
2262 button.setClickable(false);
2263 }
2264
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002265 /**
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002266 * Helper function for showing or hiding a toolbar button, possibly animated.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002267 *
2268 * @param show If true, create an animation to the show the item. Otherwise, hide it.
2269 * @param view The toolbar button to be animated
Chet Haaseb1254a62010-09-07 13:35:00 -07002270 * @param seq A AnimatorSet that will be used to animate the transition. If null, the
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002271 * transition will not be animated.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002272 */
Chet Haaseb1254a62010-09-07 13:35:00 -07002273 private void hideOrShowToolbarButton(boolean show, final View view, AnimatorSet seq) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002274 final boolean showing = show;
2275 final boolean hiding = !show;
2276
2277 final int duration = show ?
2278 getResources().getInteger(R.integer.config_toolbarButtonFadeInTime) :
2279 getResources().getInteger(R.integer.config_toolbarButtonFadeOutTime);
2280
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002281 if (seq != null) {
Chet Haaseb1254a62010-09-07 13:35:00 -07002282 Animator anim = new ObjectAnimator<Float>(duration, view, "alpha", show ? 1.0f : 0.0f);
2283 anim.addListener(new AnimatorListenerAdapter() {
2284 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002285 if (showing) showToolbarButton(view);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002286 }
Chet Haaseb1254a62010-09-07 13:35:00 -07002287 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002288 if (hiding) hideToolbarButton(view);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002289 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002290 });
2291 seq.play(anim);
2292 } else {
2293 if (showing) {
2294 showToolbarButton(view);
2295 } else {
2296 hideToolbarButton(view);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002297 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002298 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002299 }
2300
2301 /**
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002302 * Show/hide the appropriate toolbar buttons for newState.
2303 * If showSeq or hideSeq is null, the transition will be done immediately (not animated).
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002304 *
2305 * @param newState The state that is being switched to
Chet Haaseb1254a62010-09-07 13:35:00 -07002306 * @param showSeq AnimatorSet in which to put "show" animations, or null.
2307 * @param hideSeq AnimatorSet in which to put "hide" animations, or null.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002308 */
Chet Haaseb1254a62010-09-07 13:35:00 -07002309 private void hideAndShowToolbarButtons(State newState, AnimatorSet showSeq, AnimatorSet hideSeq) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002310 final View searchButton = findViewById(R.id.search_button);
2311 final View allAppsButton = findViewById(R.id.all_apps_button);
2312 final View marketButton = findViewById(R.id.market_button);
2313 final View configureButton = findViewById(R.id.configure_button);
2314
2315 switch (newState) {
2316 case WORKSPACE:
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002317 hideOrShowToolbarButton(true, searchButton, showSeq);
2318 hideOrShowToolbarButton(true, allAppsButton, showSeq);
2319 hideOrShowToolbarButton(true, configureButton, showSeq);
2320 hideOrShowToolbarButton(false, marketButton, hideSeq);
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002321 mDeleteZone.setHandle(allAppsButton);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002322 break;
2323 case ALL_APPS:
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002324 hideOrShowToolbarButton(true, configureButton, showSeq);
2325 hideOrShowToolbarButton(true, marketButton, showSeq);
2326 hideOrShowToolbarButton(false, searchButton, hideSeq);
2327 hideOrShowToolbarButton(false, allAppsButton, hideSeq);
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002328 mDeleteZone.setHandle(marketButton);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002329 break;
2330 case CUSTOMIZE:
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002331 hideOrShowToolbarButton(true, allAppsButton, showSeq);
2332 hideOrShowToolbarButton(false, searchButton, hideSeq);
2333 hideOrShowToolbarButton(false, marketButton, hideSeq);
2334 hideOrShowToolbarButton(false, configureButton, hideSeq);
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002335 mDeleteZone.setHandle(allAppsButton);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002336 break;
2337 }
2338 }
2339
2340 /**
2341 * Helper method for the cameraZoomIn/cameraZoomOut animations
2342 * @param view The view being animated
2343 * @param state The state that we are moving in or out of -- either ALL_APPS or CUSTOMIZE
2344 * @param scaleFactor The scale factor used for the zoom
2345 */
2346 private void setPivotsForZoom(View view, State state, float scaleFactor) {
2347 final int height = view.getHeight();
2348 view.setPivotX(view.getWidth() / 2.0f);
2349 // Set pivotY so that at the starting zoom factor, the view is off-screen by a small margin
2350 // Assumes that the view is normally anchored to either the top or bottom of the screen
2351 final int margin = getResources().getInteger(R.integer.config_allAppsVerticalOffset);
2352 if (state == State.ALL_APPS) {
2353 view.setPivotY(height + ((view.getTop() + height) / scaleFactor) + margin);
2354 } else {
2355 view.setPivotY(0.0f - (view.getTop() / scaleFactor) - margin);
2356 }
2357 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002358
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002359 /**
2360 * Zoom the camera out from the workspace to reveal 'toView'.
2361 * Assumes that the view to show is anchored at either the very top or very bottom
2362 * of the screen.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002363 * @param toState The state to zoom out to. Must be ALL_APPS or CUSTOMIZE.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002364 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002365 private void cameraZoomOut(State toState, boolean animated) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002366 final Resources res = getResources();
2367 final int duration = res.getInteger(R.integer.config_allAppsZoomInTime);
2368 final float scale = (float) res.getInteger(R.integer.config_allAppsZoomScaleFactor);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002369 final boolean toAllApps = (toState == State.ALL_APPS);
2370 final View toView = toAllApps ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
Patrick Dubroy558654c2010-07-23 16:48:11 -07002371
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002372 setPivotsForZoom(toView, toState, scale);
2373
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002374 if (toState == State.ALL_APPS) {
2375 mWorkspace.shrinkToBottom(animated);
2376 } else {
2377 mWorkspace.shrinkToTop(animated);
2378 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002379
2380 if (animated) {
Chet Haaseb1254a62010-09-07 13:35:00 -07002381 ValueAnimator scaleAnim = new ObjectAnimator(duration, toView,
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002382 new PropertyValuesHolder<Float>("scaleX", scale, 1.0f),
2383 new PropertyValuesHolder<Float>("scaleY", scale, 1.0f));
2384 scaleAnim.setInterpolator(new DecelerateInterpolator());
Chet Haaseb1254a62010-09-07 13:35:00 -07002385 scaleAnim.addListener(new AnimatorListenerAdapter() {
2386 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002387 // Prepare the position
2388 toView.setTranslationX(0.0f);
2389 toView.setTranslationY(0.0f);
2390 toView.setVisibility(View.VISIBLE);
2391 }
2392 });
2393
Chet Haaseb1254a62010-09-07 13:35:00 -07002394 AnimatorSet toolbarHideAnim = new AnimatorSet();
2395 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002396 hideAndShowToolbarButtons(toState, toolbarShowAnim, toolbarHideAnim);
2397
2398 // toView should appear right at the end of the workspace shrink animation
2399 final int startDelay = res.getInteger(R.integer.config_workspaceShrinkTime) - duration;
2400
Chet Haaseb1254a62010-09-07 13:35:00 -07002401 AnimatorSet s = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002402 s.playTogether(scaleAnim, toolbarHideAnim);
2403 s.play(scaleAnim).after(startDelay);
2404
2405 // Show the new toolbar buttons just as the main animation is ending
2406 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
2407 s.play(toolbarShowAnim).after(duration + startDelay - fadeInTime);
2408 s.start();
2409 } else {
2410 toView.setTranslationX(0.0f);
2411 toView.setTranslationY(0.0f);
2412 toView.setScaleX(1.0f);
2413 toView.setScaleY(1.0f);
2414 toView.setVisibility(View.VISIBLE);
2415 hideAndShowToolbarButtons(toState, null, null);
2416 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002417 }
2418
2419 /**
2420 * Zoom the camera back into the workspace, hiding 'fromView'.
2421 * This is the opposite of cameraZoomOut.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002422 * @param fromState The current state (must be ALL_APPS or CUSTOMIZE).
2423 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002424 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002425 private void cameraZoomIn(State fromState, boolean animated) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002426 Resources res = getResources();
2427 int duration = res.getInteger(R.integer.config_allAppsZoomOutTime);
2428 float scaleFactor = (float) res.getInteger(R.integer.config_allAppsZoomScaleFactor);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002429 final View fromView =
2430 (fromState == State.ALL_APPS) ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
2431
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002432 mCustomizePagedView.endChoiceMode();
2433 mAllAppsPagedView.endChoiceMode();
2434
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002435 setPivotsForZoom(fromView, fromState, scaleFactor);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002436
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002437 mWorkspace.unshrink(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002438
2439 if (animated) {
Chet Haaseb1254a62010-09-07 13:35:00 -07002440 AnimatorSet s = new AnimatorSet();
2441 ValueAnimator scaleAnim = new ObjectAnimator(duration, fromView,
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002442 new PropertyValuesHolder<Float>("scaleX", scaleFactor),
2443 new PropertyValuesHolder<Float>("scaleY", scaleFactor));
2444 scaleAnim.setInterpolator(new AccelerateInterpolator());
Chet Haaseb1254a62010-09-07 13:35:00 -07002445 s.addListener(new AnimatorListenerAdapter() {
2446 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002447 fromView.setVisibility(View.GONE);
2448 fromView.setScaleX(1.0f);
2449 fromView.setScaleY(1.0f);
2450 }
2451 });
2452
Chet Haaseb1254a62010-09-07 13:35:00 -07002453 AnimatorSet toolbarHideAnim = new AnimatorSet();
2454 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002455 hideAndShowToolbarButtons(State.WORKSPACE, toolbarShowAnim, toolbarHideAnim);
2456
2457 s.playTogether(scaleAnim, toolbarHideAnim);
2458
2459 // Show the new toolbar buttons at the very end of the whole animation
2460 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
2461 final int unshrinkTime = res.getInteger(R.integer.config_workspaceUnshrinkTime);
2462 s.play(toolbarShowAnim).after(unshrinkTime - fadeInTime);
2463 s.start();
2464 } else {
2465 fromView.setVisibility(View.GONE);
2466 hideAndShowToolbarButtons(State.WORKSPACE, null, null);
2467 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002468 }
2469
2470 /**
2471 * Pan the camera in the vertical plane between 'fromView' and 'toView'.
2472 * This is the transition used on xlarge screens to go between all apps and
2473 * the home customization drawer.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002474 * @param fromState The view to pan away from. Must be ALL_APPS or CUSTOMIZE.
2475 * @param toState The view to pan into the frame. Must be ALL_APPS or CUSTOMIZE.
2476 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002477 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002478 private void cameraPan(State fromState, State toState, boolean animated) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002479 final Resources res = getResources();
2480 final int duration = res.getInteger(R.integer.config_allAppsCameraPanTime);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002481 final int workspaceHeight = mWorkspace.getHeight();
2482
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002483 final boolean fromAllApps = (fromState == State.ALL_APPS);
2484 final View fromView = fromAllApps ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
2485 final View toView = fromAllApps ? mHomeCustomizationDrawer : (View) mAllAppsGrid;
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002486
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002487 final float fromViewStartY = fromAllApps ? 0.0f : fromView.getY();
2488 final float fromViewEndY = fromAllApps ? -fromView.getHeight() * 2 : workspaceHeight * 2;
2489 final float toViewStartY = fromAllApps ? workspaceHeight * 2 : -toView.getHeight() * 2;
2490 final float toViewEndY = fromAllApps ? workspaceHeight - toView.getHeight() : 0.0f;
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002491
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002492 mCustomizePagedView.endChoiceMode();
2493 mAllAppsPagedView.endChoiceMode();
2494
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002495 if (toState == State.ALL_APPS) {
2496 mWorkspace.shrinkToBottom(animated);
2497 } else {
2498 mWorkspace.shrinkToTop(animated);
2499 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002500
2501 if (animated) {
Chet Haaseb1254a62010-09-07 13:35:00 -07002502 AnimatorSet s = new AnimatorSet();
2503 s.addListener(new AnimatorListenerAdapter() {
2504 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002505 toView.setVisibility(View.VISIBLE);
2506 toView.setY(toViewStartY);
2507 }
Chet Haaseb1254a62010-09-07 13:35:00 -07002508 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002509 fromView.setVisibility(View.GONE);
2510 }
2511 });
2512
Chet Haaseb1254a62010-09-07 13:35:00 -07002513 AnimatorSet toolbarHideAnim = new AnimatorSet();
2514 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002515 hideAndShowToolbarButtons(toState, toolbarShowAnim, toolbarHideAnim);
2516
2517 s.playTogether(
2518 toolbarHideAnim,
Chet Haaseb1254a62010-09-07 13:35:00 -07002519 new ObjectAnimator(duration, fromView, "y", fromViewStartY, fromViewEndY),
2520 new ObjectAnimator(duration, toView, "y", toViewStartY, toViewEndY));
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002521
2522 // Show the new toolbar buttons just as the main animation is ending
2523 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
2524 s.play(toolbarShowAnim).after(duration - fadeInTime);
2525 s.start();
2526 } else {
2527 fromView.setY(fromViewEndY);
2528 fromView.setVisibility(View.GONE);
2529 toView.setY(toViewEndY);
2530 toView.setVisibility(View.VISIBLE);
2531 hideAndShowToolbarButtons(toState, null, null);
2532 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002533 }
2534
2535 void showAllApps(boolean animated) {
Winson Chung80baf5a2010-08-09 16:03:15 -07002536 if (mAllAppsGrid.isVisible())
2537 return;
2538
Michael Jurka79212d82010-07-30 16:36:20 -07002539 if (LauncherApplication.isScreenXLarge()) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002540 if (isCustomizationDrawerVisible()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002541 cameraPan(State.CUSTOMIZE, State.ALL_APPS, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002542 } else {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002543 cameraZoomOut(State.ALL_APPS, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002544 }
Patrick Dubroy558654c2010-07-23 16:48:11 -07002545 } else {
2546 mAllAppsGrid.zoom(1.0f, animated);
2547 }
Joe Onorato3a8820b2009-11-10 15:06:42 -08002548
Romain Guyc16fea72010-03-12 17:17:56 -08002549 ((View) mAllAppsGrid).setFocusable(true);
2550 ((View) mAllAppsGrid).requestFocus();
Winson Chungaafa03c2010-06-11 17:34:16 -07002551
Joe Onorato7c312c12009-08-13 21:36:53 -07002552 // TODO: fade these two too
2553 mDeleteZone.setVisibility(View.GONE);
Joe Onorato00acb122009-08-04 16:04:30 -04002554 }
2555
Joe Onoratob2061212009-11-24 16:13:54 -05002556 /**
Joe Onorato7e4ed992009-12-03 13:10:49 -08002557 * Things to test when changing this code.
Joe Onoratob2061212009-11-24 16:13:54 -05002558 * - Home from workspace
2559 * - from center screen
2560 * - from other screens
2561 * - Home from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002562 * - from center screen
2563 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002564 * - Back from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002565 * - from center screen
2566 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002567 * - Launch app from workspace and quit
2568 * - with back
2569 * - with home
2570 * - Launch app from all apps and quit
2571 * - with back
2572 * - with home
Joe Onorato7e4ed992009-12-03 13:10:49 -08002573 * - Go to a screen that's not the default, then all
2574 * apps, and launch and app, and go back
2575 * - with back
2576 * -with home
Joe Onoratob2061212009-11-24 16:13:54 -05002577 * - On workspace, long press power and go back
2578 * - with back
2579 * - with home
2580 * - On all apps, long press power and go back
2581 * - with back
2582 * - with home
2583 * - On workspace, power off
2584 * - On all apps, power off
Joe Onorato7e4ed992009-12-03 13:10:49 -08002585 * - Launch an app and turn off the screen while in that app
2586 * - Go back with home key
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002587 * - Go back with back key TODO: make this not go to workspace
Joe Onorato7e4ed992009-12-03 13:10:49 -08002588 * - From all apps
2589 * - From workspace
Joe Onoratoeffc4a82010-04-15 11:48:13 -07002590 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2591 * - From all apps
2592 * - From the center workspace
2593 * - From another workspace
Joe Onoratob2061212009-11-24 16:13:54 -05002594 */
Joe Onorato7bb17492009-09-24 17:51:01 -07002595 void closeAllApps(boolean animated) {
Joe Onoratofb0ca672009-09-14 17:55:46 -04002596 if (mAllAppsGrid.isVisible()) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002597 mWorkspace.setVisibility(View.VISIBLE);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002598 if (LauncherApplication.isScreenXLarge()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002599 cameraZoomIn(State.ALL_APPS, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002600 } else {
2601 mAllAppsGrid.zoom(0.0f, animated);
2602 }
Daniel Sandler388f6792010-03-02 14:08:08 -05002603 ((View)mAllAppsGrid).setFocusable(false);
Michael Jurka0142d492010-08-25 17:46:15 -07002604 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onoratoe77c08d2009-08-01 00:01:20 -07002605 }
Joe Onorato7404ee42009-07-31 11:54:44 -07002606 }
2607
Joe Onorato7c312c12009-08-13 21:36:53 -07002608 void lockAllApps() {
2609 // TODO
2610 }
2611
2612 void unlockAllApps() {
2613 // TODO
2614 }
2615
Patrick Dubroy558654c2010-07-23 16:48:11 -07002616 private boolean isCustomizationDrawerVisible() {
Michael Jurka54f7ac32010-08-02 13:56:46 -07002617 return mHomeCustomizationDrawer != null &&
2618 mHomeCustomizationDrawer.getVisibility() == View.VISIBLE;
Patrick Dubroy558654c2010-07-23 16:48:11 -07002619 }
2620
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002621 // Show the customization drawer (only exists in x-large configuration)
2622 private void showCustomizationDrawer(boolean animated) {
Patrick Dubroy558654c2010-07-23 16:48:11 -07002623 if (isAllAppsVisible()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002624 cameraPan(State.ALL_APPS, State.CUSTOMIZE, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002625 } else {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002626 cameraZoomOut(State.CUSTOMIZE, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002627 }
Patrick Dubroy558654c2010-07-23 16:48:11 -07002628 }
2629
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002630 // Hide the customization drawer (only exists in x-large configuration)
2631 void hideCustomizationDrawer(boolean animated) {
Patrick Dubroy558654c2010-07-23 16:48:11 -07002632 if (isCustomizationDrawerVisible()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002633 cameraZoomIn(State.CUSTOMIZE, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002634 }
2635 }
2636
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002637 void onWorkspaceClick(CellLayout layout) {
2638 Object itemInfo = mAllAppsPagedView.getChosenItem();
2639 if (itemInfo == null) {
2640 itemInfo = mCustomizePagedView.getChosenItem();
Michael Jurka213d9632010-07-28 11:29:25 -07002641 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002642
2643 if (itemInfo == null) {
2644 // No items are chosen in All Apps or Customize, so just zoom into the workspace
2645 mWorkspace.unshrink(layout);
2646 if (isAllAppsVisible()) {
2647 closeAllApps(true);
2648 } else if (isCustomizationDrawerVisible()) {
2649 hideCustomizationDrawer(true);
2650 }
2651 } else {
2652 // Act as if the chosen item was dropped on the given CellLayout
2653 if (mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
2654 mAllAppsPagedView.endChoiceMode();
2655 mCustomizePagedView.endChoiceMode();
2656 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002657 showOutOfSpaceMessage();
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002658 }
Michael Jurka213d9632010-07-28 11:29:25 -07002659 }
2660 }
2661
Joe Onorato7404ee42009-07-31 11:54:44 -07002662 /**
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002663 * Sets the app market icon (shown when all apps is visible on x-large screens)
2664 */
2665 private void updateAppMarketIcon() {
2666 if (LauncherApplication.isScreenXLarge()) {
2667 // Find the app market activity by resolving an intent.
2668 // (If multiple app markets are installed, it will return the ResolverActivity.)
2669 PackageManager packageManager = getPackageManager();
2670 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
2671 ComponentName activityName = intent.resolveActivity(getPackageManager());
2672 if (activityName != null) {
2673 mAppMarketIntent = intent;
2674 ImageView marketButton = (ImageView) findViewById(R.id.market_button);
2675 Drawable toolbarIcon = null;
2676 try {
2677 // Look for the toolbar icon specified in the activity meta-data
2678 Bundle metaData = packageManager.getActivityInfo(
2679 activityName, PackageManager.GET_META_DATA).metaData;
2680 if (metaData != null) {
2681 int iconResId = metaData.getInt(TOOLBAR_ICON_METADATA_NAME);
2682 if (iconResId != 0) {
2683 Resources res = packageManager.getResourcesForActivity(activityName);
2684 toolbarIcon = res.getDrawable(iconResId);
2685 }
2686 }
2687 } catch (NameNotFoundException e) {
2688 // Do nothing
2689 }
2690 // If we were unable to find the icon via the meta-data, use a generic one
2691 if (toolbarIcon == null) {
2692 marketButton.setImageResource(R.drawable.app_market_generic);
2693 } else {
2694 marketButton.setImageDrawable(toolbarIcon);
2695 }
2696 } else {
2697 mAppMarketIntent = null;
2698 }
2699 }
2700 }
2701
2702 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002703 * Displays the shortcut creation dialog and launches, if necessary, the
2704 * appropriate activity.
2705 */
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002706 private class CreateShortcut implements DialogInterface.OnClickListener,
Romain Guy7b4ef332009-07-14 13:58:08 -07002707 DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
2708 DialogInterface.OnShowListener {
2709
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002710 private AddAdapter mAdapter;
Romain Guy9ffb5432009-03-24 21:04:15 -07002711
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002712 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002713 mAdapter = new AddAdapter(Launcher.this);
Romain Guycbb89e42009-06-08 15:52:54 -07002714
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002715 final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
2716 builder.setTitle(getString(R.string.menu_item_add_item));
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002717 builder.setAdapter(mAdapter, this);
Romain Guycbb89e42009-06-08 15:52:54 -07002718
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002719 builder.setInverseBackgroundForced(true);
2720
2721 AlertDialog dialog = builder.create();
2722 dialog.setOnCancelListener(this);
Romain Guycbb89e42009-06-08 15:52:54 -07002723 dialog.setOnDismissListener(this);
Romain Guy7b4ef332009-07-14 13:58:08 -07002724 dialog.setOnShowListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002725
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002726 return dialog;
2727 }
2728
2729 public void onCancel(DialogInterface dialog) {
2730 mWaitingForResult = false;
2731 cleanup();
2732 }
2733
Romain Guycbb89e42009-06-08 15:52:54 -07002734 public void onDismiss(DialogInterface dialog) {
Romain Guycbb89e42009-06-08 15:52:54 -07002735 }
2736
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002737 private void cleanup() {
Joe Onoratocc19a532009-11-19 14:19:17 -08002738 try {
2739 dismissDialog(DIALOG_CREATE_SHORTCUT);
2740 } catch (Exception e) {
2741 // An exception is thrown if the dialog is not visible, which is fine
2742 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002743 }
2744
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002745 /**
2746 * Handle the action clicked in the "Add to home" dialog.
2747 */
2748 public void onClick(DialogInterface dialog, int which) {
2749 Resources res = getResources();
2750 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002751
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002752 switch (which) {
2753 case AddAdapter.ITEM_SHORTCUT: {
Joe Onoratodeb98af2010-02-19 14:59:39 -08002754 pickShortcut();
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002755 break;
2756 }
Romain Guycbb89e42009-06-08 15:52:54 -07002757
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002758 case AddAdapter.ITEM_APPWIDGET: {
2759 int appWidgetId = Launcher.this.mAppWidgetHost.allocateAppWidgetId();
Romain Guycbb89e42009-06-08 15:52:54 -07002760
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002761 Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
2762 pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002763 // start the pick activity
2764 startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET);
2765 break;
2766 }
Romain Guycbb89e42009-06-08 15:52:54 -07002767
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002768 case AddAdapter.ITEM_LIVE_FOLDER: {
2769 // Insert extra item to handle inserting folder
2770 Bundle bundle = new Bundle();
Romain Guycbb89e42009-06-08 15:52:54 -07002771
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002772 ArrayList<String> shortcutNames = new ArrayList<String>();
2773 shortcutNames.add(res.getString(R.string.group_folder));
2774 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
Romain Guycbb89e42009-06-08 15:52:54 -07002775
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002776 ArrayList<ShortcutIconResource> shortcutIcons =
2777 new ArrayList<ShortcutIconResource>();
2778 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
2779 R.drawable.ic_launcher_folder));
2780 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
2781
2782 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2783 pickIntent.putExtra(Intent.EXTRA_INTENT,
2784 new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER));
2785 pickIntent.putExtra(Intent.EXTRA_TITLE,
2786 getText(R.string.title_select_live_folder));
2787 pickIntent.putExtras(bundle);
Romain Guycbb89e42009-06-08 15:52:54 -07002788
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002789 startActivityForResult(pickIntent, REQUEST_PICK_LIVE_FOLDER);
2790 break;
2791 }
2792
2793 case AddAdapter.ITEM_WALLPAPER: {
2794 startWallpaper();
2795 break;
2796 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002797 }
2798 }
Romain Guy7b4ef332009-07-14 13:58:08 -07002799
2800 public void onShow(DialogInterface dialog) {
Winson Chungaafa03c2010-06-11 17:34:16 -07002801 mWaitingForResult = true;
Romain Guy7b4ef332009-07-14 13:58:08 -07002802 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002803 }
2804
2805 /**
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002806 * Receives notifications when applications are added/removed.
2807 */
2808 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
2809 @Override
2810 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002811 closeSystemDialogs();
Joe Onoratob2061212009-11-24 16:13:54 -05002812 String reason = intent.getStringExtra("reason");
2813 if (!"homekey".equals(reason)) {
2814 boolean animate = true;
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002815 if (mPaused || "lock".equals(reason)) {
Joe Onoratob2061212009-11-24 16:13:54 -05002816 animate = false;
2817 }
Joe Onoratob2061212009-11-24 16:13:54 -05002818 closeAllApps(animate);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002819 hideCustomizationDrawer(animate);
Joe Onoratob2061212009-11-24 16:13:54 -05002820 }
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002821 }
2822 }
2823
2824 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002825 * Receives notifications whenever the appwidgets are reset.
2826 */
2827 private class AppWidgetResetObserver extends ContentObserver {
2828 public AppWidgetResetObserver() {
2829 super(new Handler());
2830 }
2831
2832 @Override
2833 public void onChange(boolean selfChange) {
2834 onAppWidgetReset();
2835 }
2836 }
2837
2838 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002839 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002840 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002841 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07002842 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002843 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07002844 } else {
2845 return SCREEN_COUNT / 2;
2846 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002847 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002848
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002849 void setAllAppsPagedView(PagedView view) {
2850 mAllAppsPagedView = view;
2851 }
2852
Joe Onorato9c1289c2009-08-17 11:03:03 -04002853 /**
2854 * Refreshes the shortcuts shown on the workspace.
2855 *
2856 * Implementation of the method from LauncherModel.Callbacks.
2857 */
2858 public void startBinding() {
2859 final Workspace workspace = mWorkspace;
2860 int count = workspace.getChildCount();
2861 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04002862 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Joe Onorato9c1289c2009-08-17 11:03:03 -04002863 ((ViewGroup) workspace.getChildAt(i)).removeAllViewsInLayout();
2864 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002865
Joe Onorato9c1289c2009-08-17 11:03:03 -04002866 if (DEBUG_USER_INTERFACE) {
2867 android.widget.Button finishButton = new android.widget.Button(this);
2868 finishButton.setText("Finish");
2869 workspace.addInScreen(finishButton, 1, 0, 0, 1, 1);
2870
2871 finishButton.setOnClickListener(new android.widget.Button.OnClickListener() {
2872 public void onClick(View v) {
2873 finish();
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002874 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002875 });
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002876 }
2877 }
2878
2879 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002880 * Bind the items start-end from the list.
2881 *
2882 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002883 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002884 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
2885
2886 final Workspace workspace = mWorkspace;
2887
2888 for (int i=start; i<end; i++) {
2889 final ItemInfo item = shortcuts.get(i);
2890 mDesktopItems.add(item);
2891 switch (item.itemType) {
2892 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
2893 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Joe Onorato0589f0f2010-02-08 13:44:00 -08002894 final View shortcut = createShortcut((ShortcutInfo)item);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002895 workspace.addInScreen(shortcut, item.screen, item.cellX, item.cellY, 1, 1,
2896 false);
2897 break;
2898 case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER:
2899 final FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07002900 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Joe Onorato9c1289c2009-08-17 11:03:03 -04002901 (UserFolderInfo) item);
2902 workspace.addInScreen(newFolder, item.screen, item.cellX, item.cellY, 1, 1,
2903 false);
2904 break;
2905 case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER:
2906 final FolderIcon newLiveFolder = LiveFolderIcon.fromXml(
2907 R.layout.live_folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07002908 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Joe Onorato9c1289c2009-08-17 11:03:03 -04002909 (LiveFolderInfo) item);
2910 workspace.addInScreen(newLiveFolder, item.screen, item.cellX, item.cellY, 1, 1,
2911 false);
2912 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002913 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002914 }
2915
Joe Onorato9c1289c2009-08-17 11:03:03 -04002916 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002917 }
2918
Joe Onorato9c1289c2009-08-17 11:03:03 -04002919 /**
2920 * Implementation of the method from LauncherModel.Callbacks.
2921 */
Joe Onoratoad72e172009-11-06 16:25:04 -05002922 public void bindFolders(HashMap<Long, FolderInfo> folders) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002923 sFolders.clear();
2924 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002925 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002926
2927 /**
2928 * Add the views for a widget to the workspace.
2929 *
2930 * Implementation of the method from LauncherModel.Callbacks.
2931 */
2932 public void bindAppWidget(LauncherAppWidgetInfo item) {
Daniel Sandler843e8602010-06-07 14:59:01 -04002933 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
2934 if (DEBUG_WIDGETS) {
2935 Log.d(TAG, "bindAppWidget: " + item);
2936 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002937 final Workspace workspace = mWorkspace;
2938
2939 final int appWidgetId = item.appWidgetId;
2940 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04002941 if (DEBUG_WIDGETS) {
2942 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
2943 }
2944
Joe Onorato9c1289c2009-08-17 11:03:03 -04002945 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
2946
Joe Onorato9c1289c2009-08-17 11:03:03 -04002947 item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
2948 item.hostView.setTag(item);
2949
2950 workspace.addInScreen(item.hostView, item.screen, item.cellX,
2951 item.cellY, item.spanX, item.spanY, false);
2952
2953 workspace.requestLayout();
2954
2955 mDesktopItems.add(item);
Daniel Sandler843e8602010-06-07 14:59:01 -04002956
2957 if (DEBUG_WIDGETS) {
2958 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
2959 + (SystemClock.uptimeMillis()-start) + "ms");
2960 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002961 }
2962
2963 /**
2964 * Callback saying that there aren't any more items to bind.
2965 *
2966 * Implementation of the method from LauncherModel.Callbacks.
2967 */
2968 public void finishBindingItems() {
2969 if (mSavedState != null) {
2970 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07002971 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002972 }
2973
2974 final long[] userFolders = mSavedState.getLongArray(RUNTIME_STATE_USER_FOLDERS);
2975 if (userFolders != null) {
2976 for (long folderId : userFolders) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002977 final FolderInfo info = sFolders.get(folderId);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002978 if (info != null) {
2979 openFolder(info);
2980 }
2981 }
2982 final Folder openFolder = mWorkspace.getOpenFolder();
2983 if (openFolder != null) {
2984 openFolder.requestFocus();
2985 }
2986 }
2987
Joe Onorato9c1289c2009-08-17 11:03:03 -04002988 mSavedState = null;
2989 }
2990
2991 if (mSavedInstanceState != null) {
2992 super.onRestoreInstanceState(mSavedInstanceState);
2993 mSavedInstanceState = null;
2994 }
2995
Joe Onorato9c1289c2009-08-17 11:03:03 -04002996 mWorkspaceLoading = false;
2997 }
2998
2999 /**
3000 * Add the icons for all apps.
3001 *
3002 * Implementation of the method from LauncherModel.Callbacks.
3003 */
3004 public void bindAllApplications(ArrayList<ApplicationInfo> apps) {
Romain Guy84f296c2009-11-04 15:00:44 -08003005 mAllAppsGrid.setApps(apps);
Winson Chung5ffd8ea2010-09-23 18:40:29 -07003006 mCustomizePagedView.setApps(apps);
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003007 updateAppMarketIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003008 }
3009
3010 /**
3011 * A package was installed.
3012 *
3013 * Implementation of the method from LauncherModel.Callbacks.
3014 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003015 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003016 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onoratoa8138d52009-10-06 19:25:30 -07003017 mAllAppsGrid.addApps(apps);
Winson Chung5ffd8ea2010-09-23 18:40:29 -07003018 mCustomizePagedView.addApps(apps);
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003019 updateAppMarketIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003020 }
3021
3022 /**
3023 * A package was updated.
3024 *
3025 * Implementation of the method from LauncherModel.Callbacks.
3026 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003027 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003028 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato64e6be72010-03-05 15:05:52 -05003029 mWorkspace.updateShortcuts(apps);
3030 mAllAppsGrid.updateApps(apps);
Winson Chung5ffd8ea2010-09-23 18:40:29 -07003031 mCustomizePagedView.updateApps(apps);
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003032 updateAppMarketIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003033 }
3034
3035 /**
3036 * A package was uninstalled.
3037 *
3038 * Implementation of the method from LauncherModel.Callbacks.
3039 */
Joe Onorato36115782010-06-17 13:28:48 -04003040 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003041 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato36115782010-06-17 13:28:48 -04003042 if (permanent) {
3043 mWorkspace.removeItems(apps);
3044 }
Joe Onoratoa8138d52009-10-06 19:25:30 -07003045 mAllAppsGrid.removeApps(apps);
Winson Chung5ffd8ea2010-09-23 18:40:29 -07003046 mCustomizePagedView.removeApps(apps);
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003047 updateAppMarketIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003048 }
Joe Onoratobe386092009-11-17 17:32:16 -08003049
3050 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003051 * A number of packages were updated.
3052 */
3053 public void bindPackagesUpdated() {
3054 // update the customization drawer contents
Winson Chungb3347bb2010-08-19 14:51:28 -07003055 if (mCustomizePagedView != null)
3056 mCustomizePagedView.update();
Winson Chung80baf5a2010-08-09 16:03:15 -07003057 }
3058
3059 /**
Joe Onoratobe386092009-11-17 17:32:16 -08003060 * Prints out out state for debugging.
3061 */
3062 public void dumpState() {
3063 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08003064 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08003065 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
3066 Log.d(TAG, "mRestoring=" + mRestoring);
3067 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
3068 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
3069 Log.d(TAG, "mDesktopItems.size=" + mDesktopItems.size());
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003070 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08003071 mModel.dumpState();
3072 mAllAppsGrid.dumpState();
3073 Log.d(TAG, "END launcher2 dump state");
3074 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003075}