blob: ee70b5e1f2ab57999cf864670028f074e5e373db [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
Patrick Dubroy4ed62782010-08-17 15:11:18 -070020import com.android.common.Search;
21import com.android.launcher.R;
22
Patrick Dubroy7247f632010-08-04 16:02:59 -070023import android.animation.Animatable;
24import android.animation.AnimatableListenerAdapter;
25import android.animation.Animator;
26import android.animation.PropertyAnimator;
27import android.animation.Sequencer;
Michael Jurka946ad472010-07-09 18:05:18 -070028import android.app.Activity;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080029import android.app.AlertDialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080030import android.app.Dialog;
31import android.app.SearchManager;
32import android.app.StatusBarManager;
Dianne Hackborn107f8392009-08-05 21:32:16 -070033import android.app.WallpaperManager;
Michael Jurkaaf442092010-06-10 17:01:57 -070034import android.appwidget.AppWidgetManager;
35import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080036import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080037import android.content.BroadcastReceiver;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040038import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080039import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080040import android.content.Context;
41import android.content.DialogInterface;
42import android.content.Intent;
Winson Chung80baf5a2010-08-09 16:03:15 -070043import android.content.Intent.ShortcutIconResource;
Romain Guy5bbc91b2010-08-18 11:38:46 -070044import android.content.IntentFilter;
Winson Chungaafa03c2010-06-11 17:34:16 -070045import android.content.pm.ActivityInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080046import android.content.pm.PackageManager;
Daniel Sandlerab1ebd72010-04-27 16:57:25 -040047import android.content.pm.ResolveInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080048import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070049import android.content.res.Resources;
Daniel Sandlerab1ebd72010-04-27 16:57:25 -040050import android.content.res.TypedArray;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080051import android.database.ContentObserver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080052import android.graphics.Bitmap;
Romain Guya6abce82009-11-10 02:54:41 -080053import android.graphics.Canvas;
Winson Chung80baf5a2010-08-09 16:03:15 -070054import android.graphics.Color;
Michael Jurkaaf442092010-06-10 17:01:57 -070055import android.graphics.Rect;
Romain Guyff0c2e22009-11-10 12:09:59 -080056import android.graphics.drawable.ColorDrawable;
Michael Jurkaaf442092010-06-10 17:01:57 -070057import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040058import android.net.Uri;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080059import android.os.Bundle;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080060import android.os.Handler;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080061import android.os.Parcelable;
Daniel Sandler843e8602010-06-07 14:59:01 -040062import android.os.SystemClock;
Joe Onoratobe386092009-11-17 17:32:16 -080063import android.os.SystemProperties;
Karl Rosaen138a0412009-04-23 19:00:21 -070064import android.provider.LiveFolders;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070065import android.provider.Settings;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080066import android.text.Selection;
67import android.text.SpannableStringBuilder;
68import android.text.TextUtils;
69import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070070import android.util.Log;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080071import android.view.Display;
Joe Onorato0d44e942009-11-16 18:20:51 -080072import android.view.HapticFeedbackConstants;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080073import android.view.KeyEvent;
74import android.view.LayoutInflater;
75import android.view.Menu;
76import android.view.MenuItem;
Michael Jurka0e260592010-06-30 17:07:39 -070077import android.view.MotionEvent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080078import android.view.View;
Romain Guy5bbc91b2010-08-18 11:38:46 -070079import android.view.View.OnLongClickListener;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080080import android.view.ViewGroup;
Winson Chungaafa03c2010-06-11 17:34:16 -070081import android.view.WindowManager;
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -070082import android.view.animation.AccelerateInterpolator;
Patrick Dubroy7247f632010-08-04 16:02:59 -070083import android.view.animation.DecelerateInterpolator;
84import android.view.animation.Interpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080085import android.view.inputmethod.InputMethodManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080086import android.widget.EditText;
Michael Jurkaaf442092010-06-10 17:01:57 -070087import android.widget.ImageView;
88import android.widget.LinearLayout;
89import android.widget.PopupWindow;
Winson Chung80baf5a2010-08-09 16:03:15 -070090import android.widget.RelativeLayout;
Michael Jurka0e260592010-06-30 17:07:39 -070091import android.widget.TabHost;
Romain Guy5bbc91b2010-08-18 11:38:46 -070092import android.widget.TabHost.OnTabChangeListener;
93import android.widget.TabHost.TabContentFactory;
Winson Chung80baf5a2010-08-09 16:03:15 -070094import android.widget.TabWidget;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080095import android.widget.TextView;
96import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070097
98import java.io.DataInputStream;
99import java.io.DataOutputStream;
100import java.io.FileNotFoundException;
101import java.io.IOException;
102import java.util.ArrayList;
103import java.util.HashMap;
104import java.util.List;
Romain Guyedcce092010-03-04 13:03:17 -0800105
Romain Guy5bbc91b2010-08-18 11:38:46 -0700106import java.io.DataInputStream;
107import java.io.DataOutputStream;
108import java.io.FileNotFoundException;
109import java.io.IOException;
110import java.util.ArrayList;
111import java.util.HashMap;
112import java.util.List;
113
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800114/**
115 * Default launcher application.
116 */
Michael Jurka946ad472010-07-09 18:05:18 -0700117public final class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700118 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
119 AllAppsView.Watcher, View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800120 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700121 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800122
Joe Onorato9c1289c2009-08-17 11:03:03 -0400123 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400124 static final boolean DEBUG_WIDGETS = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400125 static final boolean DEBUG_USER_INTERFACE = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700126
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800127 private static final int WALLPAPER_SCREENS_SPAN = 2;
128
129 private static final int MENU_GROUP_ADD = 1;
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800130 private static final int MENU_GROUP_WALLPAPER = MENU_GROUP_ADD + 1;
131
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800132 private static final int MENU_ADD = Menu.FIRST + 1;
133 private static final int MENU_WALLPAPER_SETTINGS = MENU_ADD + 1;
134 private static final int MENU_SEARCH = MENU_WALLPAPER_SETTINGS + 1;
135 private static final int MENU_NOTIFICATIONS = MENU_SEARCH + 1;
Romain Guy94dabf12009-07-21 10:55:43 -0700136 private static final int MENU_SETTINGS = MENU_NOTIFICATIONS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800137
138 private static final int REQUEST_CREATE_SHORTCUT = 1;
139 private static final int REQUEST_CREATE_LIVE_FOLDER = 4;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700140 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800141 private static final int REQUEST_PICK_APPLICATION = 6;
142 private static final int REQUEST_PICK_SHORTCUT = 7;
143 private static final int REQUEST_PICK_LIVE_FOLDER = 8;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700144 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700145 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800146
147 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
148
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800149 static final int SCREEN_COUNT = 5;
150 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800151
Joe Onorato7c312c12009-08-13 21:36:53 -0700152 static final int DIALOG_CREATE_SHORTCUT = 1;
153 static final int DIALOG_RENAME_FOLDER = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800154
Romain Guy98d01652009-06-30 16:21:04 -0700155 private static final String PREFERENCES = "launcher.preferences";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800156
157 // Type: int
158 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
159 // Type: boolean
160 private static final String RUNTIME_STATE_ALL_APPS_FOLDER = "launcher.all_apps_folder";
161 // Type: long
162 private static final String RUNTIME_STATE_USER_FOLDERS = "launcher.user_folder";
163 // Type: int
164 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
165 // Type: int
166 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cellX";
167 // Type: int
168 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cellY";
169 // Type: int
170 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_spanX";
171 // Type: int
172 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_spanY";
173 // Type: int
174 private static final String RUNTIME_STATE_PENDING_ADD_COUNT_X = "launcher.add_countX";
175 // Type: int
176 private static final String RUNTIME_STATE_PENDING_ADD_COUNT_Y = "launcher.add_countY";
177 // Type: int[]
178 private static final String RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS = "launcher.add_occupied_cells";
179 // Type: boolean
180 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
181 // Type: long
182 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
183
Winson Chung80baf5a2010-08-09 16:03:15 -0700184 // tags for the customization tabs
185 private static final String WIDGETS_TAG = "widgets";
186 private static final String FOLDERS_TAG = "folders";
187 private static final String SHORTCUTS_TAG = "shortcuts";
188 private static final String WALLPAPERS_TAG = "wallpapers";
189
Joe Onorato9c1289c2009-08-17 11:03:03 -0400190 static final int APPWIDGET_HOST_ID = 1024;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800191
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800192 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800193 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800194
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800195 private final BroadcastReceiver mCloseSystemDialogsReceiver
196 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800197 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
198
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800199 private LayoutInflater mInflater;
200
Joe Onorato00acb122009-08-04 16:04:30 -0400201 private DragController mDragController;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800202 private Workspace mWorkspace;
Romain Guycbb89e42009-06-08 15:52:54 -0700203
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700204 private AppWidgetManager mAppWidgetManager;
205 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700206
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800207 private CellLayout.CellInfo mAddItemCellInfo;
Michael Jurkaa63c4522010-08-19 13:52:27 -0700208 private int[] mAddItemCoordinates;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800209 private CellLayout.CellInfo mMenuAddInfo;
210 private final int[] mCellCoordinates = new int[2];
211 private FolderInfo mFolderInfo;
212
Joe Onorato7c312c12009-08-13 21:36:53 -0700213 private DeleteZone mDeleteZone;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700214 private HandleView mHandleView;
Joe Onorato7c312c12009-08-13 21:36:53 -0700215 private AllAppsView mAllAppsGrid;
Michael Jurka0e260592010-06-30 17:07:39 -0700216 private TabHost mHomeCustomizationDrawer;
Winson Chung80baf5a2010-08-09 16:03:15 -0700217 private CustomizePagedView mCustomizePagedView;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800218
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800219 private Bundle mSavedState;
220
221 private SpannableStringBuilder mDefaultKeySsb = null;
222
Joe Onorato9c1289c2009-08-17 11:03:03 -0400223 private boolean mWorkspaceLoading = true;
224
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800225 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800226 private boolean mRestoring;
227 private boolean mWaitingForResult;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800228
229 private Bundle mSavedInstanceState;
230
Joe Onorato9c1289c2009-08-17 11:03:03 -0400231 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800232 private IconCache mIconCache;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400233
Romain Guy84f296c2009-11-04 15:00:44 -0800234 private ArrayList<ItemInfo> mDesktopItems = new ArrayList<ItemInfo>();
235 private static HashMap<Long, FolderInfo> mFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700236
Romain Guy1fbc1c82009-11-09 20:43:08 -0800237 private ImageView mPreviousView;
238 private ImageView mNextView;
Joe Onorato080d9b62009-11-02 12:01:11 -0500239
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400240 // Hotseats (quick-launch icons next to AllApps)
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400241 private String[] mHotseatConfig = null;
242 private Intent[] mHotseats = null;
243 private Drawable[] mHotseatIcons = null;
244 private CharSequence[] mHotseatLabels = null;
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400245
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800246 @Override
247 protected void onCreate(Bundle savedInstanceState) {
248 super.onCreate(savedInstanceState);
Romain Guyb1b69f52009-08-10 15:10:15 -0700249
Winson Chungaafa03c2010-06-11 17:34:16 -0700250 if (LauncherApplication.isInPlaceRotationEnabled()) {
251 // hide the status bar (temporary until we get the status bar design figured out)
252 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
253 this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
254 }
255
Joe Onorato0589f0f2010-02-08 13:44:00 -0800256 LauncherApplication app = ((LauncherApplication)getApplication());
257 mModel = app.setLauncher(this);
258 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400259 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800260 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700261
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700262 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700263 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
264 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700265
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800266 if (PROFILE_STARTUP) {
267 android.os.Debug.startMethodTracing("/sdcard/launcher");
268 }
269
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400270 loadHotseats();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800271 checkForLocaleChange();
272 setWallpaperDimension();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800273 setContentView(R.layout.launcher);
Michael Jurka946ad472010-07-09 18:05:18 -0700274 mHomeCustomizationDrawer = (TabHost) findViewById(com.android.internal.R.id.tabhost);
275 if (mHomeCustomizationDrawer != null) {
276 mHomeCustomizationDrawer.setup();
Winson Chungaafa03c2010-06-11 17:34:16 -0700277
Winson Chung80baf5a2010-08-09 16:03:15 -0700278 // share the same customization workspace across all the tabs
279 mCustomizePagedView = new CustomizePagedView(this);
280 TabContentFactory contentFactory = new TabContentFactory() {
281 public View createTabContent(String tag) {
282 return mCustomizePagedView;
283 }
284 };
285
Michael Jurka946ad472010-07-09 18:05:18 -0700286 String widgetsLabel = getString(R.string.widgets_tab_label);
Winson Chung80baf5a2010-08-09 16:03:15 -0700287 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(WIDGETS_TAG)
288 .setIndicator(widgetsLabel).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 shortcutsLabel = getString(R.string.shortcuts_tab_label);
Winson Chung80baf5a2010-08-09 16:03:15 -0700293 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(SHORTCUTS_TAG)
294 .setIndicator(shortcutsLabel).setContent(contentFactory));
Michael Jurka946ad472010-07-09 18:05:18 -0700295 String wallpapersLabel = getString(R.string.wallpapers_tab_label);
Winson Chung80baf5a2010-08-09 16:03:15 -0700296 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(WALLPAPERS_TAG)
297 .setIndicator(wallpapersLabel).setContent(contentFactory));
298
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();
316 Animator alphaAnim = new PropertyAnimator(duration, mCustomizePagedView,
317 "alpha", alpha, 0.0f);
318 alphaAnim.addListener(new AnimatableListenerAdapter() {
319 public void onAnimationEnd(Animatable animation) {
320 String tag = mHomeCustomizationDrawer.getCurrentTabTag();
321 if (tag == WIDGETS_TAG) {
322 mCustomizePagedView.setCustomizationFilter(
323 CustomizePagedView.CustomizationType.WidgetCustomization);
324 } else if (tag == FOLDERS_TAG) {
325 mCustomizePagedView.setCustomizationFilter(
326 CustomizePagedView.CustomizationType.FolderCustomization);
327 } else if (tag == SHORTCUTS_TAG) {
328 mCustomizePagedView.setCustomizationFilter(
329 CustomizePagedView.CustomizationType.ShortcutCustomization);
330 } else if (tag == WALLPAPERS_TAG) {
331 mCustomizePagedView.setCustomizationFilter(
332 CustomizePagedView.CustomizationType.WallpaperCustomization);
333 }
334
335 final float alpha = mCustomizePagedView.getAlpha();
336 Animator alphaAnim = new PropertyAnimator(duration, mCustomizePagedView,
337 "alpha", alpha, 1.0f);
338 alphaAnim.start();
339 }
340 });
341 alphaAnim.start();
342 }
343 });
Michael Jurka946ad472010-07-09 18:05:18 -0700344
345 mHomeCustomizationDrawer.setCurrentTab(0);
346 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800347 setupViews();
348
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800349 registerContentObservers();
350
Joe Onorato7c312c12009-08-13 21:36:53 -0700351 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700352
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800353 mSavedState = savedInstanceState;
354 restoreState(mSavedState);
355
356 if (PROFILE_STARTUP) {
357 android.os.Debug.stopMethodTracing();
358 }
359
360 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400361 mModel.startLoader(this, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800362 }
363
364 // For handling default keys
365 mDefaultKeySsb = new SpannableStringBuilder();
366 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800367
368 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
369 registerReceiver(mCloseSystemDialogsReceiver, filter);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800370 }
Romain Guycbb89e42009-06-08 15:52:54 -0700371
Winson Chungaafa03c2010-06-11 17:34:16 -0700372 @Override
373 public void onConfigurationChanged(Configuration newConfig) {
374 // TODO Auto-generated method stub
375 super.onConfigurationChanged(newConfig);
Winson Chungaafa03c2010-06-11 17:34:16 -0700376 }
377
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800378 private void checkForLocaleChange() {
Romain Guy98d01652009-06-30 16:21:04 -0700379 final LocaleConfiguration localeConfiguration = new LocaleConfiguration();
380 readConfiguration(this, localeConfiguration);
Jason Samsfd22dac2009-09-20 17:24:16 -0700381
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800382 final Configuration configuration = getResources().getConfiguration();
383
Romain Guy98d01652009-06-30 16:21:04 -0700384 final String previousLocale = localeConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800385 final String locale = configuration.locale.toString();
386
Romain Guy98d01652009-06-30 16:21:04 -0700387 final int previousMcc = localeConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800388 final int mcc = configuration.mcc;
389
Romain Guy98d01652009-06-30 16:21:04 -0700390 final int previousMnc = localeConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800391 final int mnc = configuration.mnc;
392
Romain Guy84f296c2009-11-04 15:00:44 -0800393 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800394
Romain Guy84f296c2009-11-04 15:00:44 -0800395 if (localeChanged) {
Romain Guy98d01652009-06-30 16:21:04 -0700396 localeConfiguration.locale = locale;
397 localeConfiguration.mcc = mcc;
398 localeConfiguration.mnc = mnc;
399
400 writeConfiguration(this, localeConfiguration);
Joe Onorato0589f0f2010-02-08 13:44:00 -0800401 mIconCache.flush();
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400402
403 loadHotseats();
Romain Guy98d01652009-06-30 16:21:04 -0700404 }
405 }
406
407 private static class LocaleConfiguration {
408 public String locale;
409 public int mcc = -1;
410 public int mnc = -1;
411 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700412
Romain Guy98d01652009-06-30 16:21:04 -0700413 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
414 DataInputStream in = null;
415 try {
416 in = new DataInputStream(context.openFileInput(PREFERENCES));
417 configuration.locale = in.readUTF();
418 configuration.mcc = in.readInt();
419 configuration.mnc = in.readInt();
420 } catch (FileNotFoundException e) {
421 // Ignore
422 } catch (IOException e) {
423 // Ignore
424 } finally {
425 if (in != null) {
426 try {
427 in.close();
428 } catch (IOException e) {
429 // Ignore
430 }
431 }
432 }
433 }
434
435 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
436 DataOutputStream out = null;
437 try {
438 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
439 out.writeUTF(configuration.locale);
440 out.writeInt(configuration.mcc);
441 out.writeInt(configuration.mnc);
442 out.flush();
443 } catch (FileNotFoundException e) {
444 // Ignore
445 } catch (IOException e) {
446 //noinspection ResultOfMethodCallIgnored
447 context.getFileStreamPath(PREFERENCES).delete();
448 } finally {
449 if (out != null) {
450 try {
451 out.close();
452 } catch (IOException e) {
453 // Ignore
454 }
455 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800456 }
457 }
458
459 static int getScreen() {
460 synchronized (sLock) {
461 return sScreen;
462 }
463 }
464
465 static void setScreen(int screen) {
466 synchronized (sLock) {
467 sScreen = screen;
468 }
469 }
470
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800471 private void setWallpaperDimension() {
Dianne Hackborn107f8392009-08-05 21:32:16 -0700472 WallpaperManager wpm = (WallpaperManager)getSystemService(WALLPAPER_SERVICE);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800473
474 Display display = getWindowManager().getDefaultDisplay();
Romain Guy5bbc91b2010-08-18 11:38:46 -0700475 // TODO: Put back when we decide about scrolling the wallpaper
476 // boolean isPortrait = display.getWidth() < display.getHeight();
477 // final int width = isPortrait ? display.getWidth() : display.getHeight();
478 // final int height = isPortrait ? display.getHeight() : display.getWidth();
479 wpm.suggestDesiredDimensions(Math.max(display.getWidth(), display.getHeight()),
480 Math.max(display.getWidth(), display.getHeight()));
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800481 }
482
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400483 // Note: This doesn't do all the client-id magic that BrowserProvider does
484 // in Browser. (http://b/2425179)
485 private Uri getDefaultBrowserUri() {
486 String url = getString(R.string.default_browser_url);
487 if (url.indexOf("{CID}") != -1) {
488 url = url.replace("{CID}", "android-google");
489 }
490 return Uri.parse(url);
491 }
492
493 // Load the Intent templates from arrays.xml to populate the hotseats. For
494 // each Intent, if it resolves to a single app, use that as the launch
495 // intent & use that app's label as the contentDescription. Otherwise,
496 // retain the ResolveActivity so the user can pick an app.
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400497 private void loadHotseats() {
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400498 if (mHotseatConfig == null) {
499 mHotseatConfig = getResources().getStringArray(R.array.hotseats);
500 if (mHotseatConfig.length > 0) {
501 mHotseats = new Intent[mHotseatConfig.length];
502 mHotseatLabels = new CharSequence[mHotseatConfig.length];
503 mHotseatIcons = new Drawable[mHotseatConfig.length];
504 } else {
505 mHotseats = null;
506 mHotseatIcons = null;
507 mHotseatLabels = null;
508 }
509
510 TypedArray hotseatIconDrawables = getResources().obtainTypedArray(R.array.hotseat_icons);
511 for (int i=0; i<mHotseatConfig.length; i++) {
512 // load icon for this slot; currently unrelated to the actual activity
513 try {
514 mHotseatIcons[i] = hotseatIconDrawables.getDrawable(i);
515 } catch (ArrayIndexOutOfBoundsException ex) {
516 Log.w(TAG, "Missing hotseat_icons array item #" + i);
517 mHotseatIcons[i] = null;
518 }
519 }
520 hotseatIconDrawables.recycle();
521 }
522
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400523 PackageManager pm = getPackageManager();
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400524 for (int i=0; i<mHotseatConfig.length; i++) {
525 Intent intent = null;
526 if (mHotseatConfig[i].equals("*BROWSER*")) {
527 // magic value meaning "launch user's default web browser"
528 // replace it with a generic web request so we can see if there is indeed a default
529 String defaultUri = getString(R.string.default_browser_url);
530 intent = new Intent(
531 Intent.ACTION_VIEW,
532 ((defaultUri != null)
533 ? Uri.parse(defaultUri)
534 : getDefaultBrowserUri())
535 ).addCategory(Intent.CATEGORY_BROWSABLE);
536 // note: if the user launches this without a default set, she
537 // will always be taken to the default URL above; this is
538 // unavoidable as we must specify a valid URL in order for the
Winson Chungaafa03c2010-06-11 17:34:16 -0700539 // chooser to appear, and once the user selects something, that
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400540 // URL is unavoidably sent to the chosen app.
541 } else {
542 try {
543 intent = Intent.parseUri(mHotseatConfig[i], 0);
544 } catch (java.net.URISyntaxException ex) {
545 Log.w(TAG, "Invalid hotseat intent: " + mHotseatConfig[i]);
546 // bogus; leave intent=null
547 }
548 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700549
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400550 if (intent == null) {
551 mHotseats[i] = null;
552 mHotseatLabels[i] = getText(R.string.activity_not_found);
553 continue;
554 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400555
556 if (LOGD) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700557 Log.d(TAG, "loadHotseats: hotseat " + i
558 + " initial intent=["
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400559 + intent.toUri(Intent.URI_INTENT_SCHEME)
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400560 + "]");
561 }
562
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400563 ResolveInfo bestMatch = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
564 List<ResolveInfo> allMatches = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
Winson Chungaafa03c2010-06-11 17:34:16 -0700565 if (LOGD) {
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400566 Log.d(TAG, "Best match for intent: " + bestMatch);
567 Log.d(TAG, "All matches: ");
568 for (ResolveInfo ri : allMatches) {
569 Log.d(TAG, " --> " + ri);
570 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400571 }
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400572 // did this resolve to a single app, or the resolver?
573 if (allMatches.size() == 0 || bestMatch == null) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700574 // can't find any activity to handle this. let's leave the
575 // intent as-is and let Launcher show a toast when it fails
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400576 // to launch.
577 mHotseats[i] = intent;
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400578
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400579 // set accessibility text to "Not installed"
580 mHotseatLabels[i] = getText(R.string.activity_not_found);
581 } else {
582 boolean found = false;
583 for (ResolveInfo ri : allMatches) {
584 if (bestMatch.activityInfo.name.equals(ri.activityInfo.name)
585 && bestMatch.activityInfo.applicationInfo.packageName
586 .equals(ri.activityInfo.applicationInfo.packageName)) {
587 found = true;
588 break;
589 }
590 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700591
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400592 if (!found) {
593 if (LOGD) Log.d(TAG, "Multiple options, no default yet");
594 // the bestMatch is probably the ResolveActivity, meaning the
595 // user has not yet selected a default
596 // so: we'll keep the original intent for now
597 mHotseats[i] = intent;
598
599 // set the accessibility text to "Select shortcut"
600 mHotseatLabels[i] = getText(R.string.title_select_shortcut);
601 } else {
602 // we have an app!
603 // now reconstruct the intent to launch it through the front
604 // door
605 ComponentName com = new ComponentName(
606 bestMatch.activityInfo.applicationInfo.packageName,
607 bestMatch.activityInfo.name);
608 mHotseats[i] = new Intent(Intent.ACTION_MAIN).setComponent(com);
609
610 // load the app label for accessibility
611 mHotseatLabels[i] = bestMatch.activityInfo.loadLabel(pm);
612 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400613 }
614
615 if (LOGD) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700616 Log.d(TAG, "loadHotseats: hotseat " + i
617 + " final intent=["
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400618 + ((mHotseats[i] == null)
619 ? "null"
620 : mHotseats[i].toUri(Intent.URI_INTENT_SCHEME))
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400621 + "] label=[" + mHotseatLabels[i]
622 + "]"
623 );
624 }
625 }
626 }
627
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800628 @Override
629 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Romain Guyaad5ef42009-06-10 02:48:37 -0700630 mWaitingForResult = false;
631
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800632 // The pattern used here is that a user PICKs a specific application,
633 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700634
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800635 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
636 // launch over to the Music app to actually CREATE_SHORTCUT.
Romain Guycbb89e42009-06-08 15:52:54 -0700637
Romain Guy94dabf12009-07-21 10:55:43 -0700638 if (resultCode == RESULT_OK && mAddItemCellInfo != null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800639 switch (requestCode) {
640 case REQUEST_PICK_APPLICATION:
Joe Onorato9c1289c2009-08-17 11:03:03 -0400641 completeAddApplication(this, data, mAddItemCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800642 break;
643 case REQUEST_PICK_SHORTCUT:
Joe Onoratodeb98af2010-02-19 14:59:39 -0800644 processShortcut(data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800645 break;
646 case REQUEST_CREATE_SHORTCUT:
Joe Onorato9c1289c2009-08-17 11:03:03 -0400647 completeAddShortcut(data, mAddItemCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800648 break;
649 case REQUEST_PICK_LIVE_FOLDER:
650 addLiveFolder(data);
651 break;
652 case REQUEST_CREATE_LIVE_FOLDER:
Joe Onorato9c1289c2009-08-17 11:03:03 -0400653 completeAddLiveFolder(data, mAddItemCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800654 break;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700655 case REQUEST_PICK_APPWIDGET:
Michael Jurkaaf442092010-06-10 17:01:57 -0700656 addAppWidgetFromPick(data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800657 break;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700658 case REQUEST_CREATE_APPWIDGET:
Michael Jurkaaf442092010-06-10 17:01:57 -0700659 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurkaaf442092010-06-10 17:01:57 -0700660 completeAddAppWidget(appWidgetId, mAddItemCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800661 break;
Mike Clerona0618e42009-10-22 13:55:21 -0700662 case REQUEST_PICK_WALLPAPER:
663 // We just wanted the activity result here so we can clear mWaitingForResult
664 break;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800665 }
Romain Guy18042c82009-11-06 11:44:55 -0800666 } else if ((requestCode == REQUEST_PICK_APPWIDGET ||
667 requestCode == REQUEST_CREATE_APPWIDGET) && resultCode == RESULT_CANCELED &&
668 data != null) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700669 // Clean up the appWidgetId if we canceled
670 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
671 if (appWidgetId != -1) {
672 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800673 }
674 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800675 }
676
677 @Override
678 protected void onResume() {
679 super.onResume();
680
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800681 mPaused = false;
Joe Onorato7e4ed992009-12-03 13:10:49 -0800682
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800683 if (mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400684 mWorkspaceLoading = true;
685 mModel.startLoader(this, true);
686 mRestoring = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800687 }
688 }
689
690 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700691 protected void onPause() {
692 super.onPause();
Michael Jurkaaf442092010-06-10 17:01:57 -0700693 // Some launcher layouts don't have a previous and next view
694 if (mPreviousView != null) {
695 dismissPreview(mPreviousView);
Patrick Dubroyab962b72010-07-26 12:10:10 -0700696 }
697 if (mNextView != null) {
Michael Jurkaaf442092010-06-10 17:01:57 -0700698 dismissPreview(mNextView);
699 }
Joe Onorato24b6fd82009-11-12 13:47:09 -0800700 mDragController.cancelDrag();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700701 }
Romain Guycbb89e42009-06-08 15:52:54 -0700702
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700703 @Override
704 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400705 // Flag the loader to stop early before switching
706 mModel.stopLoader();
Romain Guy13c2e7b2010-03-10 19:45:00 -0800707 mAllAppsGrid.surrender();
Romain Guy13c2e7b2010-03-10 19:45:00 -0800708 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700709 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700710
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800711 // We can't hide the IME if it was forced open. So don't bother
712 /*
713 @Override
714 public void onWindowFocusChanged(boolean hasFocus) {
715 super.onWindowFocusChanged(hasFocus);
716
717 if (hasFocus) {
718 final InputMethodManager inputManager = (InputMethodManager)
719 getSystemService(Context.INPUT_METHOD_SERVICE);
720 WindowManager.LayoutParams lp = getWindow().getAttributes();
721 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
722 android.os.Handler()) {
723 protected void onReceiveResult(int resultCode, Bundle resultData) {
724 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
725 }
726 });
727 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
728 }
729 }
730 */
731
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800732 private boolean acceptFilter() {
733 final InputMethodManager inputManager = (InputMethodManager)
734 getSystemService(Context.INPUT_METHOD_SERVICE);
735 return !inputManager.isFullscreenMode();
736 }
737
738 @Override
739 public boolean onKeyDown(int keyCode, KeyEvent event) {
740 boolean handled = super.onKeyDown(keyCode, event);
741 if (!handled && acceptFilter() && keyCode != KeyEvent.KEYCODE_ENTER) {
742 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
743 keyCode, event);
744 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700745 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700746 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700747 // showSearchDialog()
748 // If there are multiple keystrokes before the search dialog takes focus,
749 // onSearchRequested() will be called for every keystroke,
750 // but it is idempotent, so it's fine.
751 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800752 }
753 }
754
Joe Onorato8a9625e2010-01-28 15:55:35 -0800755 // Eat the long press event so the keyboard doesn't come up.
756 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
757 return true;
758 }
759
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800760 return handled;
761 }
762
Karl Rosaen138a0412009-04-23 19:00:21 -0700763 private String getTypedText() {
764 return mDefaultKeySsb.toString();
765 }
766
767 private void clearTypedText() {
768 mDefaultKeySsb.clear();
769 mDefaultKeySsb.clearSpans();
770 Selection.setSelection(mDefaultKeySsb, 0);
771 }
772
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800773 /**
774 * Restores the previous state, if it exists.
775 *
776 * @param savedState The previous state.
777 */
778 private void restoreState(Bundle savedState) {
779 if (savedState == null) {
780 return;
781 }
782
Joe Onorato3a8820b2009-11-10 15:06:42 -0800783 final boolean allApps = savedState.getBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, false);
784 if (allApps) {
785 showAllApps(false);
786 }
787
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800788 final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
789 if (currentScreen > -1) {
790 mWorkspace.setCurrentScreen(currentScreen);
791 }
792
793 final int addScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
794 if (addScreen > -1) {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700795 mAddItemCoordinates = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800796 mAddItemCellInfo = new CellLayout.CellInfo();
797 final CellLayout.CellInfo addItemCellInfo = mAddItemCellInfo;
798 addItemCellInfo.valid = true;
799 addItemCellInfo.screen = addScreen;
800 addItemCellInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
801 addItemCellInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
802 addItemCellInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
803 addItemCellInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
Michael Jurkac28de512010-08-13 11:27:44 -0700804 addItemCellInfo.updateOccupiedCells(
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800805 savedState.getBooleanArray(RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS),
806 savedState.getInt(RUNTIME_STATE_PENDING_ADD_COUNT_X),
807 savedState.getInt(RUNTIME_STATE_PENDING_ADD_COUNT_Y));
808 mRestoring = true;
809 }
810
811 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
812 if (renameFolder) {
813 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Joe Onorato9c1289c2009-08-17 11:03:03 -0400814 mFolderInfo = mModel.getFolderById(this, mFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800815 mRestoring = true;
816 }
817 }
818
819 /**
820 * Finds all the views we need and configure them properly.
821 */
822 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700823 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -0400824
Romain Guyb1b69f52009-08-10 15:10:15 -0700825 DragLayer dragLayer = (DragLayer) findViewById(R.id.drag_layer);
Joe Onorato00acb122009-08-04 16:04:30 -0400826 dragLayer.setDragController(dragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800827
Joe Onorato7c312c12009-08-13 21:36:53 -0700828 mAllAppsGrid = (AllAppsView)dragLayer.findViewById(R.id.all_apps_view);
Joe Onorato6665c0f2009-09-02 15:27:24 -0700829 mAllAppsGrid.setLauncher(this);
Joe Onorato5162ea92009-09-03 09:39:42 -0700830 mAllAppsGrid.setDragController(dragController);
Romain Guyc16fea72010-03-12 17:17:56 -0800831 ((View) mAllAppsGrid).setWillNotDraw(false); // We don't want a hole punched in our window.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700832 // Manage focusability manually since this thing is always visible (in non-xlarge)
Winson Chungaafa03c2010-06-11 17:34:16 -0700833 ((View) mAllAppsGrid).setFocusable(false);
Joe Onorato7c312c12009-08-13 21:36:53 -0700834
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700835 if (LauncherApplication.isScreenXLarge()) {
836 // They need to be INVISIBLE initially so that they will be measured in the layout.
837 // Otherwise the animations are messed up when we show them for the first time.
838 ((View) mAllAppsGrid).setVisibility(View.INVISIBLE);
839 mHomeCustomizationDrawer.setVisibility(View.INVISIBLE);
840 }
841
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800842 mWorkspace = (Workspace) dragLayer.findViewById(R.id.workspace);
843 final Workspace workspace = mWorkspace;
Joe Onoratof0dde092010-02-16 18:25:23 -0500844 workspace.setHapticFeedbackEnabled(false);
Michael Jurka946ad472010-07-09 18:05:18 -0700845
Joe Onorato7c312c12009-08-13 21:36:53 -0700846 DeleteZone deleteZone = (DeleteZone) dragLayer.findViewById(R.id.delete_zone);
847 mDeleteZone = deleteZone;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800848
Michael Jurka2c3af5f2010-08-03 13:53:20 -0700849 View handleView = findViewById(R.id.all_apps_button);
850 if (handleView != null && handleView instanceof HandleView) {
851 // we don't use handle view in xlarge mode
Michael Jurka7ef4f752010-08-03 16:04:26 -0700852 mHandleView = (HandleView)handleView;
Michael Jurka2c3af5f2010-08-03 13:53:20 -0700853 mHandleView.setLauncher(this);
854 mHandleView.setOnClickListener(this);
855 mHandleView.setOnLongClickListener(this);
856 }
Romain Guy1fbc1c82009-11-09 20:43:08 -0800857
Winson Chung80baf5a2010-08-09 16:03:15 -0700858 if (mCustomizePagedView != null) {
859 mCustomizePagedView.setLauncher(this);
860 mCustomizePagedView.setDragController(dragController);
861 mCustomizePagedView.update();
Michael Jurkaaf442092010-06-10 17:01:57 -0700862 } else {
863 ImageView hotseatLeft = (ImageView) findViewById(R.id.hotseat_left);
864 hotseatLeft.setContentDescription(mHotseatLabels[0]);
865 hotseatLeft.setImageDrawable(mHotseatIcons[0]);
866 ImageView hotseatRight = (ImageView) findViewById(R.id.hotseat_right);
867 hotseatRight.setContentDescription(mHotseatLabels[1]);
868 hotseatRight.setImageDrawable(mHotseatIcons[1]);
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400869
Michael Jurkaaf442092010-06-10 17:01:57 -0700870 mPreviousView = (ImageView) dragLayer.findViewById(R.id.previous_screen);
871 mNextView = (ImageView) dragLayer.findViewById(R.id.next_screen);
Romain Guy1fbc1c82009-11-09 20:43:08 -0800872
Michael Jurkaaf442092010-06-10 17:01:57 -0700873 Drawable previous = mPreviousView.getDrawable();
874 Drawable next = mNextView.getDrawable();
875 mWorkspace.setIndicators(previous, next);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800876
Michael Jurkaaf442092010-06-10 17:01:57 -0700877 mPreviousView.setHapticFeedbackEnabled(false);
878 mPreviousView.setOnLongClickListener(this);
879 mNextView.setHapticFeedbackEnabled(false);
880 mNextView.setOnLongClickListener(this);
881 }
Romain Guy1fbc1c82009-11-09 20:43:08 -0800882
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800883 workspace.setOnLongClickListener(this);
Joe Onorato00acb122009-08-04 16:04:30 -0400884 workspace.setDragController(dragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800885 workspace.setLauncher(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800886
887 deleteZone.setLauncher(this);
Joe Onorato00acb122009-08-04 16:04:30 -0400888 deleteZone.setDragController(dragController);
Michael Jurka54f7ac32010-08-02 13:56:46 -0700889 int deleteZoneHandleId;
890 if (LauncherApplication.isScreenXLarge()) {
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700891 deleteZoneHandleId = R.id.all_apps_button;
Michael Jurka54f7ac32010-08-02 13:56:46 -0700892 } else {
893 deleteZoneHandleId = R.id.all_apps_button_cluster;
894 }
Michael Jurkaaf442092010-06-10 17:01:57 -0700895 deleteZone.setHandle(findViewById(deleteZoneHandleId));
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700896 dragController.addDragListener(deleteZone);
897
898 ApplicationInfoDropTarget infoButton = (ApplicationInfoDropTarget)findViewById(R.id.info_button);
899 if (infoButton != null) {
900 infoButton.setLauncher(this);
901 infoButton.setHandle(findViewById(R.id.configure_button));
902 infoButton.setDragColor(getResources().getColor(R.color.app_info_filter));
903 dragController.addDragListener(infoButton);
904 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800905
Joe Onorato00acb122009-08-04 16:04:30 -0400906 dragController.setDragScoller(workspace);
Joe Onorato00acb122009-08-04 16:04:30 -0400907 dragController.setScrollView(dragLayer);
Romain Guyea3763c2010-01-11 18:02:04 -0800908 dragController.setMoveTarget(workspace);
Jason Samsfd22dac2009-09-20 17:24:16 -0700909
Joe Onorato00acb122009-08-04 16:04:30 -0400910 // The order here is bottom to top.
911 dragController.addDropTarget(workspace);
912 dragController.addDropTarget(deleteZone);
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700913 if (infoButton != null) {
914 dragController.addDropTarget(infoButton);
915 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800916 }
917
Romain Guy8a73c512009-11-09 19:19:59 -0800918 @SuppressWarnings({"UnusedDeclaration"})
919 public void previousScreen(View v) {
Joe Onorato61597bd2009-11-19 12:51:57 -0800920 if (!isAllAppsVisible()) {
921 mWorkspace.scrollLeft();
922 }
Romain Guy8a73c512009-11-09 19:19:59 -0800923 }
924
925 @SuppressWarnings({"UnusedDeclaration"})
926 public void nextScreen(View v) {
Joe Onorato61597bd2009-11-19 12:51:57 -0800927 if (!isAllAppsVisible()) {
928 mWorkspace.scrollRight();
929 }
Romain Guy8a73c512009-11-09 19:19:59 -0800930 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400931
932 @SuppressWarnings({"UnusedDeclaration"})
933 public void launchHotSeat(View v) {
Daniel Sandler3e9454a2010-05-24 11:22:41 -0400934 if (isAllAppsVisible()) return;
935
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400936 int index = -1;
937 if (v.getId() == R.id.hotseat_left) {
938 index = 0;
939 } else if (v.getId() == R.id.hotseat_right) {
940 index = 1;
941 }
942
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400943 // reload these every tap; you never know when they might change
944 loadHotseats();
945 if (index >= 0 && index < mHotseats.length && mHotseats[index] != null) {
946 Intent intent = mHotseats[index];
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400947 startActivitySafely(
948 mHotseats[index],
949 "hotseat"
950 );
951 }
952 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700953
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800954 /**
955 * Creates a view representing a shortcut.
956 *
957 * @param info The data structure describing the shortcut.
958 *
959 * @return A View inflated from R.layout.application.
960 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800961 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800962 return createShortcut(R.layout.application,
963 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentScreen()), info);
964 }
965
966 /**
967 * Creates a view representing a shortcut inflated from the specified resource.
968 *
969 * @param layoutResId The id of the XML layout used to create the shortcut.
970 * @param parent The group the shortcut belongs to.
971 * @param info The data structure describing the shortcut.
972 *
973 * @return A View inflated from layoutResId.
974 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800975 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800976 TextView favorite = (TextView) mInflater.inflate(layoutResId, parent, false);
977
Joe Onorato0589f0f2010-02-08 13:44:00 -0800978 favorite.setCompoundDrawablesWithIntrinsicBounds(null,
979 new FastBitmapDrawable(info.getIcon(mIconCache)),
980 null, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800981 favorite.setText(info.title);
982 favorite.setTag(info);
983 favorite.setOnClickListener(this);
984
985 return favorite;
986 }
987
988 /**
989 * Add an application shortcut to the workspace.
990 *
991 * @param data The intent describing the application.
992 * @param cellInfo The position on screen where to create the shortcut.
993 */
Joe Onorato9c1289c2009-08-17 11:03:03 -0400994 void completeAddApplication(Context context, Intent data, CellLayout.CellInfo cellInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800995 cellInfo.screen = mWorkspace.getCurrentScreen();
996 if (!findSingleSlot(cellInfo)) return;
997
Joe Onorato0589f0f2010-02-08 13:44:00 -0800998 final ShortcutInfo info = mModel.getShortcutInfo(context.getPackageManager(),
999 data, context);
1000
Romain Guy73b979d2009-06-09 12:57:21 -07001001 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -08001002 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001003 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001004 info.container = ItemInfo.NO_ID;
1005 mWorkspace.addApplicationShortcut(info, cellInfo, isWorkspaceLocked());
1006 } else {
1007 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001008 }
1009 }
Romain Guycbb89e42009-06-08 15:52:54 -07001010
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001011 /**
1012 * Add a shortcut to the workspace.
1013 *
1014 * @param data The intent describing the shortcut.
1015 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001016 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04001017 private void completeAddShortcut(Intent data, CellLayout.CellInfo cellInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001018 cellInfo.screen = mWorkspace.getCurrentScreen();
1019 if (!findSingleSlot(cellInfo)) return;
Romain Guycbb89e42009-06-08 15:52:54 -07001020
Joe Onorato0589f0f2010-02-08 13:44:00 -08001021 final ShortcutInfo info = mModel.addShortcut(this, data, cellInfo, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001022
1023 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001024 final View view = createShortcut(info);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001025 mWorkspace.addInCurrentScreen(view, cellInfo.cellX, cellInfo.cellY, 1, 1,
1026 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001027 }
1028 }
1029
Romain Guycbb89e42009-06-08 15:52:54 -07001030
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001031 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001032 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001033 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001034 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001035 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001036 */
Michael Jurkaaf442092010-06-10 17:01:57 -07001037 private void completeAddAppWidget(int appWidgetId, CellLayout.CellInfo cellInfo) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001038 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Romain Guycbb89e42009-06-08 15:52:54 -07001039
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001040 // Calculate the grid spans needed to fit this widget
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001041 CellLayout layout = (CellLayout) mWorkspace.getChildAt(cellInfo.screen);
Patrick Dubroy8f86ddc2010-07-16 13:55:32 -07001042 int[] spans = layout.rectToCell(appWidgetInfo.minWidth, appWidgetInfo.minHeight, null);
Romain Guycbb89e42009-06-08 15:52:54 -07001043
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001044 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001045 // We have saved the position to which the widget was dragged-- this really only matters
1046 // if we are placing widgets on a "spring-loaded" screen
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001047 final int[] xy = mCellCoordinates;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001048
1049 // For now, we don't save the coordinate where we dropped the icon because we're not
1050 // supporting spring-loaded mini-screens; however, leaving the ability to directly place
1051 // a widget on the home screen in case we want to add it in the future
1052 final int[] xyTouch = null;
1053 //final int[] xyTouch = mAddItemCoordinates;
1054 boolean findNearestVacantAreaFailed = false;
1055 if (xyTouch != null) {
1056 CellLayout screen = (CellLayout) mWorkspace.getChildAt(cellInfo.screen);
1057 int[] result = screen.findNearestVacantArea(
1058 mAddItemCoordinates[0], mAddItemCoordinates[1],
1059 spans[0], spans[1], cellInfo, xy);
1060 findNearestVacantAreaFailed = (result == null);
1061 }
1062
1063 if (findNearestVacantAreaFailed ||
1064 (xyTouch == null && !findSlot(cellInfo, xy, spans[0], spans[1]))) {
Romain Guy18042c82009-11-06 11:44:55 -08001065 if (appWidgetId != -1) mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1066 return;
1067 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001068
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001069 // Build Launcher-specific widget info and save to database
1070 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001071 launcherInfo.spanX = spans[0];
1072 launcherInfo.spanY = spans[1];
Romain Guycbb89e42009-06-08 15:52:54 -07001073
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001074 LauncherModel.addItemToDatabase(this, launcherInfo,
1075 LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurkaa63c4522010-08-19 13:52:27 -07001076 cellInfo.screen, xy[0], xy[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001077
1078 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001079 mDesktopItems.add(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001080
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001081 // Perform actual inflation because we're live
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001082 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001083
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001084 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001085 launcherInfo.hostView.setTag(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001086
Michael Jurkaa63c4522010-08-19 13:52:27 -07001087 mWorkspace.addInScreen(launcherInfo.hostView, cellInfo.screen, xy[0], xy[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001088 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001089 }
1090 }
Romain Guycbb89e42009-06-08 15:52:54 -07001091
Joe Onorato9c1289c2009-08-17 11:03:03 -04001092 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
1093 mDesktopItems.remove(launcherInfo);
1094 launcherInfo.hostView = null;
1095 }
1096
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001097 public LauncherAppWidgetHost getAppWidgetHost() {
1098 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001099 }
Romain Guycbb89e42009-06-08 15:52:54 -07001100
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001101 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001102 getWindow().closeAllPanels();
1103
1104 try {
1105 dismissDialog(DIALOG_CREATE_SHORTCUT);
1106 // Unlock the workspace if the dialog was showing
1107 } catch (Exception e) {
1108 // An exception is thrown if the dialog is not visible, which is fine
1109 }
1110
1111 try {
1112 dismissDialog(DIALOG_RENAME_FOLDER);
1113 // Unlock the workspace if the dialog was showing
1114 } catch (Exception e) {
1115 // An exception is thrown if the dialog is not visible, which is fine
1116 }
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001117
1118 // Whatever we were doing is hereby canceled.
1119 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001120 }
1121
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001122 @Override
1123 protected void onNewIntent(Intent intent) {
1124 super.onNewIntent(intent);
1125
1126 // Close the menu
1127 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001128 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001129 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001130
Joe Onorato14f122b2009-11-19 14:06:36 -08001131 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1132 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
1133 boolean allAppsVisible = isAllAppsVisible();
Michael Jurka01f0ed42010-08-20 00:41:17 -07001134 boolean customizationDrawerVisible = isCustomizationDrawerVisible();
1135
Patrick Dubroy558654c2010-07-23 16:48:11 -07001136
Michael Jurka4cb37242010-08-09 21:05:32 -07001137 // in all these cases, only animate if we're already on home
1138 if (LauncherApplication.isScreenXLarge()) {
Michael Jurka01f0ed42010-08-20 00:41:17 -07001139 if (alreadyOnHome && !mWorkspace.isSmall() &&
1140 !allAppsVisible && !customizationDrawerVisible) {
1141 mWorkspace.shrinkToMiddle();
1142 } else {
1143 mWorkspace.unshrink(alreadyOnHome);
1144 }
1145 } else if (!mWorkspace.isDefaultScreenShowing()) {
Michael Jurka4cb37242010-08-09 21:05:32 -07001146 // on the phone, we don't animate the change to the workspace if all apps is visible
Michael Jurka01f0ed42010-08-20 00:41:17 -07001147 mWorkspace.moveToDefaultScreen(alreadyOnHome && !allAppsVisible);
Joe Onorato3a8820b2009-11-10 15:06:42 -08001148 }
Joe Onorato14f122b2009-11-19 14:06:36 -08001149 closeAllApps(alreadyOnHome && allAppsVisible);
Patrick Dubroy558654c2010-07-23 16:48:11 -07001150 hideCustomizationDrawer();
Romain Guy1dd3a072009-07-16 13:21:01 -07001151
Joe Onorato3a8820b2009-11-10 15:06:42 -08001152 final View v = getWindow().peekDecorView();
1153 if (v != null && v.getWindowToken() != null) {
1154 InputMethodManager imm = (InputMethodManager)getSystemService(
1155 INPUT_METHOD_SERVICE);
1156 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001157 }
1158 }
1159 }
1160
1161 @Override
1162 protected void onRestoreInstanceState(Bundle savedInstanceState) {
1163 // Do not call super here
1164 mSavedInstanceState = savedInstanceState;
Michael Jurka946ad472010-07-09 18:05:18 -07001165
1166 if (mHomeCustomizationDrawer != null) {
1167 String cur = savedInstanceState.getString("currentTab");
1168 if (cur != null) {
1169 mHomeCustomizationDrawer.setCurrentTabByTag(cur);
1170 }
1171 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001172 }
1173
1174 @Override
1175 protected void onSaveInstanceState(Bundle outState) {
1176 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentScreen());
1177
1178 final ArrayList<Folder> folders = mWorkspace.getOpenFolders();
1179 if (folders.size() > 0) {
1180 final int count = folders.size();
1181 long[] ids = new long[count];
1182 for (int i = 0; i < count; i++) {
1183 final FolderInfo info = folders.get(i).getInfo();
1184 ids[i] = info.id;
1185 }
1186 outState.putLongArray(RUNTIME_STATE_USER_FOLDERS, ids);
1187 } else {
1188 super.onSaveInstanceState(outState);
1189 }
1190
Joe Onoratofb0ca672009-09-14 17:55:46 -04001191 // TODO should not do this if the drawer is currently closing.
Joe Onorato3a8820b2009-11-10 15:06:42 -08001192 if (isAllAppsVisible()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001193 outState.putBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, true);
Romain Guy5a941392009-04-28 15:18:25 -07001194 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001195
1196 if (mAddItemCellInfo != null && mAddItemCellInfo.valid && mWaitingForResult) {
1197 final CellLayout.CellInfo addItemCellInfo = mAddItemCellInfo;
1198 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(addItemCellInfo.screen);
1199
1200 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, addItemCellInfo.screen);
1201 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, addItemCellInfo.cellX);
1202 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, addItemCellInfo.cellY);
1203 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, addItemCellInfo.spanX);
1204 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, addItemCellInfo.spanY);
1205 outState.putInt(RUNTIME_STATE_PENDING_ADD_COUNT_X, layout.getCountX());
1206 outState.putInt(RUNTIME_STATE_PENDING_ADD_COUNT_Y, layout.getCountY());
1207 outState.putBooleanArray(RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS,
Patrick Dubroy6569f2c2010-07-12 14:25:18 -07001208 layout.getOccupiedCellsFlattened());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001209 }
1210
1211 if (mFolderInfo != null && mWaitingForResult) {
1212 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1213 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1214 }
Michael Jurka946ad472010-07-09 18:05:18 -07001215
1216 if (mHomeCustomizationDrawer != null) {
1217 String currentTabTag = mHomeCustomizationDrawer.getCurrentTabTag();
1218 if (currentTabTag != null) {
1219 outState.putString("currentTab", currentTabTag);
1220 }
1221 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001222 }
1223
1224 @Override
1225 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001226 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001227
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001228 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001229 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001230 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001231 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001232 }
1233
1234 TextKeyListener.getInstance().release();
1235
Joe Onorato9c1289c2009-08-17 11:03:03 -04001236 mModel.stopLoader();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001237
Joe Onorato9c1289c2009-08-17 11:03:03 -04001238 unbindDesktopItems();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001239
1240 getContentResolver().unregisterContentObserver(mWidgetObserver);
Winson Chungaafa03c2010-06-11 17:34:16 -07001241
Patrick Dubroyab962b72010-07-26 12:10:10 -07001242 // Some launcher layouts don't have a previous and next view
1243 if (mPreviousView != null) {
1244 dismissPreview(mPreviousView);
1245 }
1246 if (mNextView != null) {
1247 dismissPreview(mNextView);
1248 }
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001249
1250 unregisterReceiver(mCloseSystemDialogsReceiver);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001251 }
1252
1253 @Override
1254 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001255 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001256 super.startActivityForResult(intent, requestCode);
1257 }
1258
1259 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001260 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001261 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001262
Joe Onorato7bb17492009-09-24 17:51:01 -07001263 closeAllApps(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001264
Karl Rosaen138a0412009-04-23 19:00:21 -07001265 if (initialQuery == null) {
1266 // Use any text typed in the launcher as the initial query
1267 initialQuery = getTypedText();
1268 clearTypedText();
1269 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001270 if (appSearchData == null) {
1271 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +00001272 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001273 }
Romain Guycbb89e42009-06-08 15:52:54 -07001274
Karl Rosaen138a0412009-04-23 19:00:21 -07001275 final SearchManager searchManager =
1276 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Karl Rosaen138a0412009-04-23 19:00:21 -07001277 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Romain Guycbb89e42009-06-08 15:52:54 -07001278 appSearchData, globalSearch);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001279 }
1280
1281 @Override
1282 public boolean onCreateOptionsMenu(Menu menu) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001283 if (isWorkspaceLocked()) {
1284 return false;
1285 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001286
1287 super.onCreateOptionsMenu(menu);
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001288
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001289 menu.add(MENU_GROUP_ADD, MENU_ADD, 0, R.string.menu_add)
1290 .setIcon(android.R.drawable.ic_menu_add)
1291 .setAlphabeticShortcut('A');
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001292 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001293 .setIcon(android.R.drawable.ic_menu_gallery)
1294 .setAlphabeticShortcut('W');
1295 menu.add(0, MENU_SEARCH, 0, R.string.menu_search)
1296 .setIcon(android.R.drawable.ic_search_category_default)
1297 .setAlphabeticShortcut(SearchManager.MENU_KEY);
1298 menu.add(0, MENU_NOTIFICATIONS, 0, R.string.menu_notifications)
1299 .setIcon(com.android.internal.R.drawable.ic_menu_notifications)
1300 .setAlphabeticShortcut('N');
1301
1302 final Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
Romain Guy5a941392009-04-28 15:18:25 -07001303 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
1304 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001305
1306 menu.add(0, MENU_SETTINGS, 0, R.string.menu_settings)
1307 .setIcon(android.R.drawable.ic_menu_preferences).setAlphabeticShortcut('P')
1308 .setIntent(settings);
1309
1310 return true;
1311 }
1312
1313 @Override
1314 public boolean onPrepareOptionsMenu(Menu menu) {
1315 super.onPrepareOptionsMenu(menu);
1316
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001317 // If all apps is animating, don't show the menu, because we don't know
1318 // which one to show.
Patrick Dubroyff5f0402010-07-26 15:23:26 -07001319 if (mAllAppsGrid.isAnimating()) {
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001320 return false;
1321 }
1322
1323 // Only show the add and wallpaper options when we're not in all apps.
Patrick Dubroyff5f0402010-07-26 15:23:26 -07001324 boolean visible = !mAllAppsGrid.isVisible();
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001325 menu.setGroupVisible(MENU_GROUP_ADD, visible);
1326 menu.setGroupVisible(MENU_GROUP_WALLPAPER, visible);
1327
1328 // Disable add if the workspace is full.
1329 if (visible) {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001330 mMenuAddInfo = mWorkspace.updateOccupiedCellsForCurrentScreen(null);
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001331 menu.setGroupEnabled(MENU_GROUP_ADD, mMenuAddInfo != null && mMenuAddInfo.valid);
1332 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001333
1334 return true;
1335 }
1336
Michael Jurka0e260592010-06-30 17:07:39 -07001337 // we need to initialize mAddItemCellInfo before adding something to the homescreen -- when
1338 // using the settings menu to add an item, something similar happens in showAddDialog
1339 public void prepareAddItemFromHomeCustomizationDrawer() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001340 mMenuAddInfo = mWorkspace.updateOccupiedCellsForCurrentScreen(null);
Michael Jurka0e260592010-06-30 17:07:39 -07001341 mAddItemCellInfo = mMenuAddInfo;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001342 mAddItemCellInfo = null;
Michael Jurka0e260592010-06-30 17:07:39 -07001343 }
1344
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001345 @Override
1346 public boolean onOptionsItemSelected(MenuItem item) {
1347 switch (item.getItemId()) {
1348 case MENU_ADD:
1349 addItems();
1350 return true;
1351 case MENU_WALLPAPER_SETTINGS:
1352 startWallpaper();
1353 return true;
1354 case MENU_SEARCH:
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001355 onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001356 return true;
1357 case MENU_NOTIFICATIONS:
1358 showNotifications();
1359 return true;
1360 }
1361
1362 return super.onOptionsItemSelected(item);
1363 }
Romain Guycbb89e42009-06-08 15:52:54 -07001364
Karl Rosaen138a0412009-04-23 19:00:21 -07001365 /**
1366 * Indicates that we want global search for this activity by setting the globalSearch
1367 * argument for {@link #startSearch} to true.
1368 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001369
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001370 @Override
1371 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001372 startSearch(null, false, null, true);
Karl Rosaen138a0412009-04-23 19:00:21 -07001373 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001374 }
1375
Joe Onorato9c1289c2009-08-17 11:03:03 -04001376 public boolean isWorkspaceLocked() {
1377 return mWorkspaceLoading || mWaitingForResult;
1378 }
1379
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001380 private void addItems() {
Patrick Dubroy558654c2010-07-23 16:48:11 -07001381 if (LauncherApplication.isScreenXLarge()) {
1382 // Animate the widget chooser up from the bottom of the screen
1383 if (!isCustomizationDrawerVisible()) {
1384 showCustomizationDrawer();
Michael Jurka213d9632010-07-28 11:29:25 -07001385 mWorkspace.shrinkToTop();
Patrick Dubroy558654c2010-07-23 16:48:11 -07001386 }
1387 } else {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001388 closeAllApps(true);
Patrick Dubroy558654c2010-07-23 16:48:11 -07001389 showAddDialog(mMenuAddInfo);
1390 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001391 }
1392
Michael Jurkaa63c4522010-08-19 13:52:27 -07001393 void addAppWidgetFromDrop(ComponentName appWidgetProvider, CellLayout.CellInfo cellInfo,
1394 int[] position) {
Michael Jurkaaf442092010-06-10 17:01:57 -07001395 mAddItemCellInfo = cellInfo;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001396
1397 // only set mAddItemCoordinates if we dropped on home screen in "spring-loaded" manner
1398 mAddItemCoordinates = position;
Michael Jurkaaf442092010-06-10 17:01:57 -07001399 int appWidgetId = getAppWidgetHost().allocateAppWidgetId();
1400 AppWidgetManager.getInstance(this).bindAppWidgetId(appWidgetId, appWidgetProvider);
1401 addAppWidgetImpl(appWidgetId);
1402 }
1403
1404 void addAppWidgetFromPick(Intent data) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001405 // TODO: catch bad widget exception when sent
1406 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurkaaf442092010-06-10 17:01:57 -07001407 // TODO: Is this log message meaningful?
1408 if (LOGD) Log.d(TAG, "dumping extras content=" + data.getExtras());
1409 addAppWidgetImpl(appWidgetId);
1410 }
1411
1412 void addAppWidgetImpl(int appWidgetId) {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001413 AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001414
Bjorn Bringert7984c942009-12-09 15:38:25 +00001415 if (appWidget.configure != null) {
1416 // Launch over to configure widget, if needed
1417 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
1418 intent.setComponent(appWidget.configure);
1419 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
1420
Romain Guy8e633c52010-03-04 12:51:36 -08001421 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001422 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001423 // Otherwise just add it
Michael Jurkaaf442092010-06-10 17:01:57 -07001424 completeAddAppWidget(appWidgetId, mAddItemCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001425 }
1426 }
Romain Guycbb89e42009-06-08 15:52:54 -07001427
Joe Onoratodeb98af2010-02-19 14:59:39 -08001428 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001429 // Handle case where user selected "Applications"
1430 String applicationName = getResources().getString(R.string.group_applications);
1431 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001432
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001433 if (applicationName != null && applicationName.equals(shortcutName)) {
1434 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1435 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001436
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001437 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1438 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Joe Onoratodeb98af2010-02-19 14:59:39 -08001439 startActivityForResult(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001440 } else {
Joe Onoratodeb98af2010-02-19 14:59:39 -08001441 startActivityForResult(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001442 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001443 }
1444
1445 void addLiveFolder(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001446 // Handle case where user selected "Folder"
Jeffrey Sharkeyc4bbd0a2009-03-24 22:47:52 -07001447 String folderName = getResources().getString(R.string.group_folder);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001448 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001449
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001450 if (folderName != null && folderName.equals(shortcutName)) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001451 addFolder();
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001452 } else {
1453 startActivityForResult(intent, REQUEST_CREATE_LIVE_FOLDER);
1454 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001455 }
1456
Joe Onorato9c1289c2009-08-17 11:03:03 -04001457 void addFolder() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001458 UserFolderInfo folderInfo = new UserFolderInfo();
1459 folderInfo.title = getText(R.string.folder_name);
1460
1461 CellLayout.CellInfo cellInfo = mAddItemCellInfo;
1462 cellInfo.screen = mWorkspace.getCurrentScreen();
1463 if (!findSingleSlot(cellInfo)) return;
1464
1465 // Update the model
Joe Onorato9c1289c2009-08-17 11:03:03 -04001466 LauncherModel.addItemToDatabase(this, folderInfo,
1467 LauncherSettings.Favorites.CONTAINER_DESKTOP,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001468 mWorkspace.getCurrentScreen(), cellInfo.cellX, cellInfo.cellY, false);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001469 mFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001470
1471 // Create the view
1472 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
1473 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentScreen()), folderInfo);
1474 mWorkspace.addInCurrentScreen(newFolder,
Joe Onorato9c1289c2009-08-17 11:03:03 -04001475 cellInfo.cellX, cellInfo.cellY, 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001476 }
Romain Guycbb89e42009-06-08 15:52:54 -07001477
Joe Onorato9c1289c2009-08-17 11:03:03 -04001478 void removeFolder(FolderInfo folder) {
1479 mFolders.remove(folder.id);
1480 }
1481
1482 private void completeAddLiveFolder(Intent data, CellLayout.CellInfo cellInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001483 cellInfo.screen = mWorkspace.getCurrentScreen();
1484 if (!findSingleSlot(cellInfo)) return;
1485
1486 final LiveFolderInfo info = addLiveFolder(this, data, cellInfo, false);
1487
1488 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001489 final View view = LiveFolderIcon.fromXml(R.layout.live_folder_icon, this,
1490 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentScreen()), info);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001491 mWorkspace.addInCurrentScreen(view, cellInfo.cellX, cellInfo.cellY, 1, 1,
1492 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001493 }
1494 }
1495
1496 static LiveFolderInfo addLiveFolder(Context context, Intent data,
1497 CellLayout.CellInfo cellInfo, boolean notify) {
1498
1499 Intent baseIntent = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT);
1500 String name = data.getStringExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME);
1501
1502 Drawable icon = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001503 Intent.ShortcutIconResource iconResource = null;
1504
1505 Parcelable extra = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON);
1506 if (extra != null && extra instanceof Intent.ShortcutIconResource) {
1507 try {
1508 iconResource = (Intent.ShortcutIconResource) extra;
1509 final PackageManager packageManager = context.getPackageManager();
1510 Resources resources = packageManager.getResourcesForApplication(
1511 iconResource.packageName);
1512 final int id = resources.getIdentifier(iconResource.resourceName, null, null);
1513 icon = resources.getDrawable(id);
1514 } catch (Exception e) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001515 Log.w(TAG, "Could not load live folder icon: " + extra);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001516 }
1517 }
1518
1519 if (icon == null) {
1520 icon = context.getResources().getDrawable(R.drawable.ic_launcher_folder);
1521 }
1522
1523 final LiveFolderInfo info = new LiveFolderInfo();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001524 info.icon = Utilities.createIconBitmap(icon, context);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001525 info.title = name;
1526 info.iconResource = iconResource;
1527 info.uri = data.getData();
1528 info.baseIntent = baseIntent;
1529 info.displayMode = data.getIntExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE,
1530 LiveFolders.DISPLAY_MODE_GRID);
1531
1532 LauncherModel.addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
1533 cellInfo.screen, cellInfo.cellX, cellInfo.cellY, notify);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001534 mFolders.put(info.id, info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001535
1536 return info;
1537 }
1538
1539 private boolean findSingleSlot(CellLayout.CellInfo cellInfo) {
1540 final int[] xy = new int[2];
1541 if (findSlot(cellInfo, xy, 1, 1)) {
1542 cellInfo.cellX = xy[0];
1543 cellInfo.cellY = xy[1];
1544 return true;
1545 }
1546 return false;
1547 }
1548
1549 private boolean findSlot(CellLayout.CellInfo cellInfo, int[] xy, int spanX, int spanY) {
1550 if (!cellInfo.findCellForSpan(xy, spanX, spanY)) {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001551 CellLayout targetLayout = (CellLayout) mWorkspace.getChildAt(cellInfo.screen);
1552 cellInfo = targetLayout.updateOccupiedCells(null, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001553 if (!cellInfo.findCellForSpan(xy, spanX, spanY)) {
1554 Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show();
1555 return false;
1556 }
1557 }
1558 return true;
1559 }
1560
1561 private void showNotifications() {
1562 final StatusBarManager statusBar = (StatusBarManager) getSystemService(STATUS_BAR_SERVICE);
1563 if (statusBar != null) {
1564 statusBar.expand();
1565 }
1566 }
1567
1568 private void startWallpaper() {
Joe Onoratoe6168662009-11-08 13:39:30 -05001569 closeAllApps(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001570 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001571 Intent chooser = Intent.createChooser(pickWallpaper,
1572 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001573 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1574 // Removed in Eclair MR1
1575// WallpaperManager wm = (WallpaperManager)
1576// getSystemService(Context.WALLPAPER_SERVICE);
1577// WallpaperInfo wi = wm.getWallpaperInfo();
1578// if (wi != null && wi.getSettingsActivity() != null) {
1579// LabeledIntent li = new LabeledIntent(getPackageName(),
1580// R.string.configure_wallpaper, 0);
1581// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1582// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1583// }
Mike Clerona0618e42009-10-22 13:55:21 -07001584 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001585 }
1586
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001587 /**
1588 * Registers various content observers. The current implementation registers
1589 * only a favorites observer to keep track of the favorites applications.
1590 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001591 private void registerContentObservers() {
1592 ContentResolver resolver = getContentResolver();
1593 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1594 true, mWidgetObserver);
1595 }
1596
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001597 @Override
1598 public boolean dispatchKeyEvent(KeyEvent event) {
1599 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1600 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001601 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001602 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001603 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jason Samseb5615d2009-11-30 11:50:10 -08001604 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
Joe Onoratobe386092009-11-17 17:32:16 -08001605 dumpState();
1606 return true;
1607 }
1608 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001609 }
1610 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1611 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001612 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001613 return true;
1614 }
1615 }
1616
1617 return super.dispatchKeyEvent(event);
1618 }
1619
Joe Onorato88ec0992009-11-19 13:16:06 -08001620 @Override
1621 public void onBackPressed() {
1622 if (isAllAppsVisible()) {
1623 closeAllApps(true);
Patrick Dubroy558654c2010-07-23 16:48:11 -07001624 } else if (isCustomizationDrawerVisible()) {
1625 hideCustomizationDrawer();
Joe Onorato88ec0992009-11-19 13:16:06 -08001626 } else {
1627 closeFolder();
1628 }
Michael Jurkaaf442092010-06-10 17:01:57 -07001629 // Some launcher layouts don't have a previous and next view
1630 if (mPreviousView != null) {
1631 dismissPreview(mPreviousView);
1632 dismissPreview(mNextView);
1633 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001634 }
1635
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001636 private void closeFolder() {
1637 Folder folder = mWorkspace.getOpenFolder();
1638 if (folder != null) {
1639 closeFolder(folder);
1640 }
1641 }
1642
1643 void closeFolder(Folder folder) {
1644 folder.getInfo().opened = false;
1645 ViewGroup parent = (ViewGroup) folder.getParent();
1646 if (parent != null) {
1647 parent.removeView(folder);
Joe Onoratob6341e92009-11-02 10:41:48 -05001648 if (folder instanceof DropTarget) {
1649 // Live folders aren't DropTargets.
1650 mDragController.removeDropTarget((DropTarget)folder);
1651 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001652 }
1653 folder.onClose();
1654 }
1655
1656 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001657 * Re-listen when widgets are reset.
1658 */
1659 private void onAppWidgetReset() {
1660 mAppWidgetHost.startListening();
1661 }
1662
1663 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001664 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1665 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001666 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04001667 private void unbindDesktopItems() {
1668 for (ItemInfo item: mDesktopItems) {
1669 item.unbind();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001670 }
1671 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001672
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001673 /**
1674 * Launches the intent referred by the clicked shortcut.
1675 *
1676 * @param v The view representing the clicked shortcut.
1677 */
1678 public void onClick(View v) {
1679 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001680 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001681 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08001682 final Intent intent = ((ShortcutInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001683 int[] pos = new int[2];
1684 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08001685 intent.setSourceBounds(new Rect(pos[0], pos[1],
1686 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Joe Onoratof984e852010-03-25 09:47:45 -07001687 startActivitySafely(intent, tag);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001688 } else if (tag instanceof FolderInfo) {
1689 handleFolderClick((FolderInfo) tag);
Joe Onorato7404ee42009-07-31 11:54:44 -07001690 } else if (v == mHandleView) {
Joe Onoratofb0ca672009-09-14 17:55:46 -04001691 if (isAllAppsVisible()) {
Joe Onorato7bb17492009-09-24 17:51:01 -07001692 closeAllApps(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001693 } else {
Joe Onorato3a8820b2009-11-10 15:06:42 -08001694 showAllApps(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001695 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001696 }
1697 }
1698
Michael Jurka0e260592010-06-30 17:07:39 -07001699 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07001700 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurka0e260592010-06-30 17:07:39 -07001701 // clicking anywhere on the workspace causes the drawer to slide down
Patrick Dubroy558654c2010-07-23 16:48:11 -07001702 hideCustomizationDrawer();
Michael Jurka0e260592010-06-30 17:07:39 -07001703 return false;
1704 }
1705
Michael Jurkaaf442092010-06-10 17:01:57 -07001706 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001707 * Event handler for the search button
1708 *
1709 * @param v The view that was clicked.
1710 */
1711 public void onClickSearchButton(View v) {
1712 Intent i = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
1713 View button = findViewById(R.id.search_button);
1714 i.setSourceBounds(
1715 new Rect(button.getLeft(), button.getTop(), button.getRight(), button.getBottom()));
1716 startActivity(i);
1717 }
1718
1719 /**
1720 * Event handler for the "gear" button that appears on the home screen, which
Michael Jurkaaf442092010-06-10 17:01:57 -07001721 * enters home screen customization mode.
1722 *
1723 * @param v The view that was clicked.
1724 */
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001725 public void onClickConfigureButton(View v) {
Patrick Dubroy558654c2010-07-23 16:48:11 -07001726 addItems();
Michael Jurkaaf442092010-06-10 17:01:57 -07001727 }
1728
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001729 /**
1730 * Event handler for the "grid" button that appears on the home screen, which
1731 * enters all apps mode.
1732 *
1733 * @param v The view that was clicked.
1734 */
1735 public void onClickAllAppsButton(View v) {
1736 showAllApps(true);
1737 }
1738
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001739 void startApplicationDetailsActivity(String packageName) {
1740 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
1741 Uri.fromParts("package", packageName, null));
1742 startActivity(intent);
1743 }
1744
Joe Onoratof984e852010-03-25 09:47:45 -07001745 void startActivitySafely(Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001746 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1747 try {
1748 startActivity(intent);
1749 } catch (ActivityNotFoundException e) {
1750 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Daniel Sandlerc9b18772010-04-22 14:37:59 -04001751 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001752 } catch (SecurityException e) {
1753 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001754 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001755 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07001756 "or use the exported attribute for this activity. "
1757 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001758 }
1759 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001760
Romain Guy8e633c52010-03-04 12:51:36 -08001761 void startActivityForResultSafely(Intent intent, int requestCode) {
1762 try {
1763 startActivityForResult(intent, requestCode);
1764 } catch (ActivityNotFoundException e) {
1765 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1766 } catch (SecurityException e) {
1767 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1768 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
1769 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
1770 "or use the exported attribute for this activity.", e);
1771 }
1772 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001773
1774 private void handleFolderClick(FolderInfo folderInfo) {
1775 if (!folderInfo.opened) {
1776 // Close any open folder
1777 closeFolder();
1778 // Open the requested folder
1779 openFolder(folderInfo);
1780 } else {
1781 // Find the open folder...
1782 Folder openFolder = mWorkspace.getFolderForTag(folderInfo);
1783 int folderScreen;
1784 if (openFolder != null) {
1785 folderScreen = mWorkspace.getScreenForView(openFolder);
1786 // .. and close it
1787 closeFolder(openFolder);
1788 if (folderScreen != mWorkspace.getCurrentScreen()) {
1789 // Close any folder open on the current screen
1790 closeFolder();
1791 // Pull the folder onto this screen
1792 openFolder(folderInfo);
1793 }
1794 }
1795 }
1796 }
1797
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001798 /**
1799 * Opens the user fodler described by the specified tag. The opening of the folder
1800 * is animated relative to the specified View. If the View is null, no animation
1801 * is played.
1802 *
1803 * @param folderInfo The FolderInfo describing the folder to open.
1804 */
Winson Chungaafa03c2010-06-11 17:34:16 -07001805 public void openFolder(FolderInfo folderInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001806 Folder openFolder;
1807
1808 if (folderInfo instanceof UserFolderInfo) {
1809 openFolder = UserFolder.fromXml(this);
1810 } else if (folderInfo instanceof LiveFolderInfo) {
Joe Onoratoa5902522009-07-30 13:37:37 -07001811 openFolder = com.android.launcher2.LiveFolder.fromXml(this, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001812 } else {
1813 return;
1814 }
1815
Joe Onorato00acb122009-08-04 16:04:30 -04001816 openFolder.setDragController(mDragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001817 openFolder.setLauncher(this);
1818
1819 openFolder.bind(folderInfo);
1820 folderInfo.opened = true;
1821
Winson Chungaafa03c2010-06-11 17:34:16 -07001822 mWorkspace.addInFullScreen(openFolder, folderInfo.screen);
1823
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001824 openFolder.onOpen();
1825 }
1826
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001827 public boolean onLongClick(View v) {
Romain Guy1fbc1c82009-11-09 20:43:08 -08001828 switch (v.getId()) {
1829 case R.id.previous_screen:
Joe Onorato0d44e942009-11-16 18:20:51 -08001830 if (!isAllAppsVisible()) {
1831 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1832 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Romain Guyf8e6a802009-12-07 17:48:02 -08001833 showPreviews(v);
Joe Onorato0d44e942009-11-16 18:20:51 -08001834 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08001835 return true;
1836 case R.id.next_screen:
Joe Onorato0d44e942009-11-16 18:20:51 -08001837 if (!isAllAppsVisible()) {
1838 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1839 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Romain Guyf8e6a802009-12-07 17:48:02 -08001840 showPreviews(v);
1841 }
1842 return true;
1843 case R.id.all_apps_button:
1844 if (!isAllAppsVisible()) {
1845 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1846 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
1847 showPreviews(v);
Joe Onorato0d44e942009-11-16 18:20:51 -08001848 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08001849 return true;
1850 }
1851
Joe Onorato9c1289c2009-08-17 11:03:03 -04001852 if (isWorkspaceLocked()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001853 return false;
1854 }
1855
1856 if (!(v instanceof CellLayout)) {
1857 v = (View) v.getParent();
1858 }
1859
1860 CellLayout.CellInfo cellInfo = (CellLayout.CellInfo) v.getTag();
1861
1862 // This happens when long clicking an item with the dpad/trackball
1863 if (cellInfo == null) {
1864 return true;
1865 }
1866
1867 if (mWorkspace.allowLongPress()) {
1868 if (cellInfo.cell == null) {
1869 if (cellInfo.valid) {
1870 // User long pressed on empty space
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001871 mWorkspace.setAllowLongPress(false);
Joe Onoratof0dde092010-02-16 18:25:23 -05001872 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1873 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001874 showAddDialog(cellInfo);
1875 }
1876 } else {
1877 if (!(cellInfo.cell instanceof Folder)) {
1878 // User long pressed on an item
Joe Onorato0d44e942009-11-16 18:20:51 -08001879 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1880 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001881 mWorkspace.startDrag(cellInfo);
1882 }
1883 }
1884 }
1885 return true;
1886 }
1887
Romain Guye6b8e2f2009-11-10 11:56:55 -08001888 @SuppressWarnings({"unchecked"})
Romain Guy9d31e9f2009-11-11 18:54:28 -08001889 private void dismissPreview(final View v) {
1890 final PopupWindow window = (PopupWindow) v.getTag();
Romain Guy1fbc1c82009-11-09 20:43:08 -08001891 if (window != null) {
Romain Guy9d31e9f2009-11-11 18:54:28 -08001892 window.setOnDismissListener(new PopupWindow.OnDismissListener() {
1893 public void onDismiss() {
1894 ViewGroup group = (ViewGroup) v.getTag(R.id.workspace);
1895 int count = group.getChildCount();
1896 for (int i = 0; i < count; i++) {
1897 ((ImageView) group.getChildAt(i)).setImageDrawable(null);
1898 }
Romain Guy9d31e9f2009-11-11 18:54:28 -08001899 ArrayList<Bitmap> bitmaps = (ArrayList<Bitmap>) v.getTag(R.id.icon);
1900 for (Bitmap bitmap : bitmaps) bitmap.recycle();
1901
1902 v.setTag(R.id.workspace, null);
1903 v.setTag(R.id.icon, null);
1904 window.setOnDismissListener(null);
1905 }
1906 });
Romain Guy1fbc1c82009-11-09 20:43:08 -08001907 window.dismiss();
Romain Guy1fbc1c82009-11-09 20:43:08 -08001908 }
1909 v.setTag(null);
1910 }
1911
Romain Guyf8e6a802009-12-07 17:48:02 -08001912 private void showPreviews(View anchor) {
Romain Guy9d31e9f2009-11-11 18:54:28 -08001913 showPreviews(anchor, 0, mWorkspace.getChildCount());
Romain Guy1fbc1c82009-11-09 20:43:08 -08001914 }
1915
Romain Guya6abce82009-11-10 02:54:41 -08001916 private void showPreviews(final View anchor, int start, int end) {
Romain Guyf8e6a802009-12-07 17:48:02 -08001917 final Resources resources = getResources();
1918 final Workspace workspace = mWorkspace;
Romain Guy1fbc1c82009-11-09 20:43:08 -08001919
Romain Guya6abce82009-11-10 02:54:41 -08001920 CellLayout cell = ((CellLayout) workspace.getChildAt(start));
Winson Chungaafa03c2010-06-11 17:34:16 -07001921
Romain Guy9d31e9f2009-11-11 18:54:28 -08001922 float max = workspace.getChildCount();
Winson Chungaafa03c2010-06-11 17:34:16 -07001923
Romain Guyf8e6a802009-12-07 17:48:02 -08001924 final Rect r = new Rect();
Romain Guy9d31e9f2009-11-11 18:54:28 -08001925 resources.getDrawable(R.drawable.preview_background).getPadding(r);
Romain Guye6b8e2f2009-11-10 11:56:55 -08001926 int extraW = (int) ((r.left + r.right) * max);
1927 int extraH = r.top + r.bottom;
Romain Guya6abce82009-11-10 02:54:41 -08001928
1929 int aW = cell.getWidth() - extraW;
1930 float w = aW / max;
1931
1932 int width = cell.getWidth();
1933 int height = cell.getHeight();
1934 int x = cell.getLeftPadding();
1935 int y = cell.getTopPadding();
1936 width -= (x + cell.getRightPadding());
1937 height -= (y + cell.getBottomPadding());
1938
1939 float scale = w / width;
1940
1941 int count = end - start;
1942
1943 final float sWidth = width * scale;
1944 float sHeight = height * scale;
1945
Romain Guye6b8e2f2009-11-10 11:56:55 -08001946 LinearLayout preview = new LinearLayout(this);
Romain Guya6abce82009-11-10 02:54:41 -08001947
Romain Guye6b8e2f2009-11-10 11:56:55 -08001948 PreviewTouchHandler handler = new PreviewTouchHandler(anchor);
1949 ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>(count);
Romain Guya6abce82009-11-10 02:54:41 -08001950
1951 for (int i = start; i < end; i++) {
Romain Guye6b8e2f2009-11-10 11:56:55 -08001952 ImageView image = new ImageView(this);
Romain Guya6abce82009-11-10 02:54:41 -08001953 cell = (CellLayout) workspace.getChildAt(i);
1954
Romain Guyf8e6a802009-12-07 17:48:02 -08001955 final Bitmap bitmap = Bitmap.createBitmap((int) sWidth, (int) sHeight,
Romain Guye6b8e2f2009-11-10 11:56:55 -08001956 Bitmap.Config.ARGB_8888);
Romain Guyf8e6a802009-12-07 17:48:02 -08001957
1958 final Canvas c = new Canvas(bitmap);
Romain Guya6abce82009-11-10 02:54:41 -08001959 c.scale(scale, scale);
1960 c.translate(-cell.getLeftPadding(), -cell.getTopPadding());
1961 cell.dispatchDraw(c);
Romain Guya6abce82009-11-10 02:54:41 -08001962
Romain Guy9d31e9f2009-11-11 18:54:28 -08001963 image.setBackgroundDrawable(resources.getDrawable(R.drawable.preview_background));
Romain Guye6b8e2f2009-11-10 11:56:55 -08001964 image.setImageBitmap(bitmap);
1965 image.setTag(i);
1966 image.setOnClickListener(handler);
Romain Guy9d31e9f2009-11-11 18:54:28 -08001967 image.setOnFocusChangeListener(handler);
1968 image.setFocusable(true);
1969 if (i == mWorkspace.getCurrentScreen()) image.requestFocus();
Romain Guye6b8e2f2009-11-10 11:56:55 -08001970
1971 preview.addView(image,
Romain Guy9d31e9f2009-11-11 18:54:28 -08001972 LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
1973
Winson Chungaafa03c2010-06-11 17:34:16 -07001974 bitmaps.add(bitmap);
Romain Guya6abce82009-11-10 02:54:41 -08001975 }
Romain Guyf8e6a802009-12-07 17:48:02 -08001976
1977 final PopupWindow p = new PopupWindow(this);
Romain Guye6b8e2f2009-11-10 11:56:55 -08001978 p.setContentView(preview);
1979 p.setWidth((int) (sWidth * count + extraW));
1980 p.setHeight((int) (sHeight + extraH));
1981 p.setAnimationStyle(R.style.AnimationPreview);
1982 p.setOutsideTouchable(true);
Romain Guy9d31e9f2009-11-11 18:54:28 -08001983 p.setFocusable(true);
Romain Guyff0c2e22009-11-10 12:09:59 -08001984 p.setBackgroundDrawable(new ColorDrawable(0));
Romain Guy9d31e9f2009-11-11 18:54:28 -08001985 p.showAsDropDown(anchor, 0, 0);
Romain Guya6abce82009-11-10 02:54:41 -08001986
Romain Guye6b8e2f2009-11-10 11:56:55 -08001987 p.setOnDismissListener(new PopupWindow.OnDismissListener() {
1988 public void onDismiss() {
1989 dismissPreview(anchor);
1990 }
1991 });
Romain Guy1fbc1c82009-11-09 20:43:08 -08001992
1993 anchor.setTag(p);
1994 anchor.setTag(R.id.workspace, preview);
Winson Chungaafa03c2010-06-11 17:34:16 -07001995 anchor.setTag(R.id.icon, bitmaps);
Romain Guy1fbc1c82009-11-09 20:43:08 -08001996 }
1997
Romain Guy9d31e9f2009-11-11 18:54:28 -08001998 class PreviewTouchHandler implements View.OnClickListener, Runnable, View.OnFocusChangeListener {
Romain Guya6abce82009-11-10 02:54:41 -08001999 private final View mAnchor;
Romain Guya6abce82009-11-10 02:54:41 -08002000
Romain Guye6b8e2f2009-11-10 11:56:55 -08002001 public PreviewTouchHandler(View anchor) {
Romain Guya6abce82009-11-10 02:54:41 -08002002 mAnchor = anchor;
Romain Guya6abce82009-11-10 02:54:41 -08002003 }
2004
2005 public void onClick(View v) {
Romain Guye6b8e2f2009-11-10 11:56:55 -08002006 mWorkspace.snapToScreen((Integer) v.getTag());
Romain Guy9d31e9f2009-11-11 18:54:28 -08002007 v.post(this);
2008 }
2009
2010 public void run() {
Winson Chungaafa03c2010-06-11 17:34:16 -07002011 dismissPreview(mAnchor);
Romain Guy9d31e9f2009-11-11 18:54:28 -08002012 }
2013
2014 public void onFocusChange(View v, boolean hasFocus) {
2015 if (hasFocus) {
Romain Guye47f55c2009-11-11 19:21:22 -08002016 mWorkspace.snapToScreen((Integer) v.getTag());
Romain Guy9d31e9f2009-11-11 18:54:28 -08002017 }
Romain Guya6abce82009-11-10 02:54:41 -08002018 }
2019 }
2020
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002021 Workspace getWorkspace() {
2022 return mWorkspace;
2023 }
2024
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002025 @Override
2026 protected Dialog onCreateDialog(int id) {
2027 switch (id) {
2028 case DIALOG_CREATE_SHORTCUT:
2029 return new CreateShortcut().createDialog();
2030 case DIALOG_RENAME_FOLDER:
2031 return new RenameFolder().createDialog();
2032 }
2033
2034 return super.onCreateDialog(id);
2035 }
2036
2037 @Override
2038 protected void onPrepareDialog(int id, Dialog dialog) {
2039 switch (id) {
2040 case DIALOG_CREATE_SHORTCUT:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002041 break;
2042 case DIALOG_RENAME_FOLDER:
Romain Guy7b4ef332009-07-14 13:58:08 -07002043 if (mFolderInfo != null) {
2044 EditText input = (EditText) dialog.findViewById(R.id.folder_name);
2045 final CharSequence text = mFolderInfo.title;
2046 input.setText(text);
2047 input.setSelection(0, text.length());
2048 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002049 break;
2050 }
2051 }
2052
2053 void showRenameDialog(FolderInfo info) {
2054 mFolderInfo = info;
2055 mWaitingForResult = true;
2056 showDialog(DIALOG_RENAME_FOLDER);
2057 }
2058
2059 private void showAddDialog(CellLayout.CellInfo cellInfo) {
2060 mAddItemCellInfo = cellInfo;
Michael Jurkaa63c4522010-08-19 13:52:27 -07002061 mAddItemCoordinates = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002062 mWaitingForResult = true;
2063 showDialog(DIALOG_CREATE_SHORTCUT);
2064 }
2065
Joe Onoratodeb98af2010-02-19 14:59:39 -08002066 private void pickShortcut() {
Michael Jurka0e260592010-06-30 17:07:39 -07002067 // Insert extra item to handle picking application
Romain Guy73b979d2009-06-09 12:57:21 -07002068 Bundle bundle = new Bundle();
2069
2070 ArrayList<String> shortcutNames = new ArrayList<String>();
2071 shortcutNames.add(getString(R.string.group_applications));
2072 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
2073
2074 ArrayList<ShortcutIconResource> shortcutIcons = new ArrayList<ShortcutIconResource>();
2075 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
2076 R.drawable.ic_launcher_application));
2077 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
2078
2079 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2080 pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_CREATE_SHORTCUT));
Joe Onoratodeb98af2010-02-19 14:59:39 -08002081 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_shortcut));
Romain Guy73b979d2009-06-09 12:57:21 -07002082 pickIntent.putExtras(bundle);
2083
Joe Onoratodeb98af2010-02-19 14:59:39 -08002084 startActivityForResult(pickIntent, REQUEST_PICK_SHORTCUT);
Romain Guy73b979d2009-06-09 12:57:21 -07002085 }
2086
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002087 private class RenameFolder {
2088 private EditText mInput;
2089
2090 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002091 final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null);
2092 mInput = (EditText) layout.findViewById(R.id.folder_name);
2093
2094 AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
2095 builder.setIcon(0);
2096 builder.setTitle(getString(R.string.rename_folder_title));
2097 builder.setCancelable(true);
2098 builder.setOnCancelListener(new Dialog.OnCancelListener() {
2099 public void onCancel(DialogInterface dialog) {
2100 cleanup();
2101 }
2102 });
2103 builder.setNegativeButton(getString(R.string.cancel_action),
2104 new Dialog.OnClickListener() {
2105 public void onClick(DialogInterface dialog, int which) {
2106 cleanup();
2107 }
2108 }
2109 );
2110 builder.setPositiveButton(getString(R.string.rename_action),
2111 new Dialog.OnClickListener() {
2112 public void onClick(DialogInterface dialog, int which) {
2113 changeFolderName();
2114 }
2115 }
2116 );
2117 builder.setView(layout);
Romain Guy7b4ef332009-07-14 13:58:08 -07002118
2119 final AlertDialog dialog = builder.create();
2120 dialog.setOnShowListener(new DialogInterface.OnShowListener() {
2121 public void onShow(DialogInterface dialog) {
Joe Onorato7018d8e2010-04-13 20:25:47 -07002122 mWaitingForResult = true;
Joe Onoratod753b422009-11-08 13:31:11 -05002123 mInput.requestFocus();
2124 InputMethodManager inputManager = (InputMethodManager)
2125 getSystemService(Context.INPUT_METHOD_SERVICE);
2126 inputManager.showSoftInput(mInput, 0);
Romain Guy7b4ef332009-07-14 13:58:08 -07002127 }
2128 });
2129
2130 return dialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002131 }
2132
2133 private void changeFolderName() {
2134 final String name = mInput.getText().toString();
2135 if (!TextUtils.isEmpty(name)) {
2136 // Make sure we have the right folder info
Joe Onorato9c1289c2009-08-17 11:03:03 -04002137 mFolderInfo = mFolders.get(mFolderInfo.id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002138 mFolderInfo.title = name;
2139 LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo);
2140
Joe Onorato9c1289c2009-08-17 11:03:03 -04002141 if (mWorkspaceLoading) {
Joe Onorato7c312c12009-08-13 21:36:53 -07002142 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002143 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002144 } else {
2145 final FolderIcon folderIcon = (FolderIcon)
2146 mWorkspace.getViewForTag(mFolderInfo);
2147 if (folderIcon != null) {
2148 folderIcon.setText(name);
2149 getWorkspace().requestLayout();
2150 } else {
Joe Onorato7c312c12009-08-13 21:36:53 -07002151 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002152 mWorkspaceLoading = true;
2153 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002154 }
2155 }
2156 }
2157 cleanup();
2158 }
2159
2160 private void cleanup() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002161 dismissDialog(DIALOG_RENAME_FOLDER);
2162 mWaitingForResult = false;
2163 mFolderInfo = null;
2164 }
2165 }
2166
Daniel Sandler843e8602010-06-07 14:59:01 -04002167 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
2168 public boolean isAllAppsVisible() {
Romain Guy5bbc91b2010-08-18 11:38:46 -07002169 return mAllAppsGrid != null && mAllAppsGrid.isVisible();
Joe Onoratofb0ca672009-09-14 17:55:46 -04002170 }
2171
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002172 // AllAppsView.Watcher
2173 public void zoomed(float zoom) {
Michael Jurka213d9632010-07-28 11:29:25 -07002174 // In XLarge view, we zoom down the workspace below all apps so it's still visible
2175 if (zoom == 1.0f && !LauncherApplication.isScreenXLarge()) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002176 mWorkspace.setVisibility(View.GONE);
2177 }
2178 }
2179
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002180 /**
2181 * Zoom the camera out from the workspace to reveal 'toView'.
2182 * Assumes that the view to show is anchored at either the very top or very bottom
2183 * of the screen.
2184 * @param toView The view to show when the animation is complete
2185 * @param above If true, toView will appear from the top of the screen
2186 */
2187 private void cameraZoomOut(final View toView, boolean above) {
2188 final Resources res = getResources();
2189 final int duration = res.getInteger(R.integer.config_allAppsZoomInTime);
2190 final float scale = (float) res.getInteger(R.integer.config_allAppsZoomScaleFactor);
2191 final int height = toView.getHeight();
Patrick Dubroy558654c2010-07-23 16:48:11 -07002192
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002193 // toView should appear right at the end of the workspace shrink animation
2194 final int startDelay = res.getInteger(R.integer.config_workspaceShrinkTime) - duration;
2195
2196 Interpolator interp = new DecelerateInterpolator();
2197
2198 toView.setPivotX(toView.getWidth() / 2.0f);
2199 // Set pivotY so that at the starting zoom factor, the view is off-screen by a small margin
2200 // Assumes that the view is normally anchored to either the top or bottom of the screen
2201 final int margin = 200;
2202 if (above) {
2203 toView.setPivotY(height + ((toView.getTop() + height) / scale) + margin);
2204 } else {
2205 toView.setPivotY(0.0f - (toView.getTop() / scale) - margin);
2206 }
2207
2208 Animator scaleXAnim = new PropertyAnimator(duration, toView, "scaleX", scale, 1.0f);
2209 scaleXAnim.setInterpolator(interp);
2210 scaleXAnim.addListener(new AnimatableListenerAdapter() {
2211 public void onAnimationStart(Animatable animation) {
2212 // Prepare the position
2213 toView.setTranslationX(0.0f);
2214 toView.setTranslationY(0.0f);
2215 toView.setVisibility(View.VISIBLE);
2216 }
2217 });
2218
2219 Animator scaleYAnim = new PropertyAnimator(duration, toView, "scaleY", scale, 1.0f);
2220 scaleYAnim.setInterpolator(interp);
2221
2222 Sequencer s = new Sequencer();
2223 s.playTogether(scaleXAnim, scaleYAnim);
2224 s.play(scaleXAnim).after(startDelay);
2225 s.start();
2226 }
2227
2228 /**
2229 * Zoom the camera back into the workspace, hiding 'fromView'.
2230 * This is the opposite of cameraZoomOut.
2231 * @param fromView The currently-focused view, which will be hidden.
2232 */
2233 private void cameraZoomIn(final View fromView) {
2234 Resources res = getResources();
2235 int duration = res.getInteger(R.integer.config_allAppsZoomOutTime);
2236 float scaleFactor = (float) res.getInteger(R.integer.config_allAppsZoomScaleFactor);
2237
2238 Interpolator interp = new AccelerateInterpolator();
2239
2240 Sequencer s = new Sequencer();
2241 Animator scaleXAnim = new PropertyAnimator(duration, fromView, "scaleX", scaleFactor);
2242 scaleXAnim.setInterpolator(interp);
2243 Animator scaleYAnim = new PropertyAnimator(duration, fromView, "scaleY", scaleFactor);
2244 scaleYAnim.setInterpolator(interp);
2245 s.playTogether(scaleXAnim, scaleYAnim);
2246 s.addListener(new AnimatableListenerAdapter() {
2247 public void onAnimationEnd(Animatable animation) {
2248 fromView.setVisibility(View.GONE);
2249 fromView.setScaleX(1.0f);
2250 fromView.setScaleY(1.0f);
2251 }
2252 });
2253 s.start();
2254 }
2255
2256 /**
2257 * Pan the camera in the vertical plane between 'fromView' and 'toView'.
2258 * This is the transition used on xlarge screens to go between all apps and
2259 * the home customization drawer.
2260 * @param fromView The view to pan away from.
2261 * @param toView The view to pan into the frame.
2262 */
2263 private void cameraPan(final View fromView, final View toView) {
2264 final int duration = getResources().getInteger(R.integer.config_allAppsCameraPanTime);
2265 final int workspaceHeight = mWorkspace.getHeight();
2266
2267 final boolean panDown = fromView.getY() < toView.getY();
2268
2269 final float fromViewStartY = panDown ? 0.0f : fromView.getY();
2270 final float fromViewEndY = panDown ? -fromView.getHeight() * 2 : workspaceHeight * 2;
2271 final float toViewStartY = panDown ? workspaceHeight * 2 : -toView.getHeight() * 2;
2272 final float toViewEndY = panDown ? workspaceHeight - toView.getHeight() : 0.0f;
2273
2274 Sequencer s = new Sequencer();
2275 s.playTogether(
2276 new PropertyAnimator(duration, fromView, "y", fromViewStartY, fromViewEndY),
2277 new PropertyAnimator(duration, toView, "y", toViewStartY, toViewEndY));
2278 s.addListener(new AnimatableListenerAdapter() {
2279 public void onAnimationStart(Animatable animation) {
2280 toView.setVisibility(View.VISIBLE);
2281 toView.setY(toViewStartY);
2282 }
2283 public void onAnimationEnd(Animatable animation) {
2284 fromView.setVisibility(View.GONE);
2285 }
2286 });
2287 s.start();
2288 }
2289
2290 void showAllApps(boolean animated) {
Winson Chung80baf5a2010-08-09 16:03:15 -07002291 if (mAllAppsGrid.isVisible())
2292 return;
2293
Michael Jurka79212d82010-07-30 16:36:20 -07002294 if (LauncherApplication.isScreenXLarge()) {
2295 mWorkspace.shrinkToBottom(animated);
2296 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002297
Patrick Dubroy558654c2010-07-23 16:48:11 -07002298 if (LauncherApplication.isScreenXLarge() && animated) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002299 if (isCustomizationDrawerVisible()) {
2300 cameraPan(mHomeCustomizationDrawer, (View) mAllAppsGrid);
2301 } else {
2302 cameraZoomOut((View) mAllAppsGrid, true);
2303 }
Patrick Dubroy558654c2010-07-23 16:48:11 -07002304 } else {
2305 mAllAppsGrid.zoom(1.0f, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002306 hideCustomizationDrawer(); // TODO: Should be able to do this un-animated
Patrick Dubroy558654c2010-07-23 16:48:11 -07002307 }
Joe Onorato3a8820b2009-11-10 15:06:42 -08002308
Romain Guyc16fea72010-03-12 17:17:56 -08002309 ((View) mAllAppsGrid).setFocusable(true);
2310 ((View) mAllAppsGrid).requestFocus();
Winson Chungaafa03c2010-06-11 17:34:16 -07002311
Joe Onorato7c312c12009-08-13 21:36:53 -07002312 // TODO: fade these two too
2313 mDeleteZone.setVisibility(View.GONE);
Joe Onorato00acb122009-08-04 16:04:30 -04002314 }
2315
Joe Onoratob2061212009-11-24 16:13:54 -05002316 /**
Joe Onorato7e4ed992009-12-03 13:10:49 -08002317 * Things to test when changing this code.
Joe Onoratob2061212009-11-24 16:13:54 -05002318 * - Home from workspace
2319 * - from center screen
2320 * - from other screens
2321 * - Home from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002322 * - from center screen
2323 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002324 * - Back from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002325 * - from center screen
2326 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002327 * - Launch app from workspace and quit
2328 * - with back
2329 * - with home
2330 * - Launch app from all apps and quit
2331 * - with back
2332 * - with home
Joe Onorato7e4ed992009-12-03 13:10:49 -08002333 * - Go to a screen that's not the default, then all
2334 * apps, and launch and app, and go back
2335 * - with back
2336 * -with home
Joe Onoratob2061212009-11-24 16:13:54 -05002337 * - On workspace, long press power and go back
2338 * - with back
2339 * - with home
2340 * - On all apps, long press power and go back
2341 * - with back
2342 * - with home
2343 * - On workspace, power off
2344 * - On all apps, power off
Joe Onorato7e4ed992009-12-03 13:10:49 -08002345 * - Launch an app and turn off the screen while in that app
2346 * - Go back with home key
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002347 * - Go back with back key TODO: make this not go to workspace
Joe Onorato7e4ed992009-12-03 13:10:49 -08002348 * - From all apps
2349 * - From workspace
Joe Onoratoeffc4a82010-04-15 11:48:13 -07002350 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2351 * - From all apps
2352 * - From the center workspace
2353 * - From another workspace
Joe Onoratob2061212009-11-24 16:13:54 -05002354 */
Joe Onorato7bb17492009-09-24 17:51:01 -07002355 void closeAllApps(boolean animated) {
Joe Onoratofb0ca672009-09-14 17:55:46 -04002356 if (mAllAppsGrid.isVisible()) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002357 mWorkspace.setVisibility(View.VISIBLE);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002358 if (LauncherApplication.isScreenXLarge() && animated) {
Michael Jurka213d9632010-07-28 11:29:25 -07002359 mWorkspace.unshrink();
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002360 cameraZoomIn((View) mAllAppsGrid);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002361 } else {
2362 mAllAppsGrid.zoom(0.0f, animated);
2363 }
Daniel Sandler388f6792010-03-02 14:08:08 -05002364 ((View)mAllAppsGrid).setFocusable(false);
Joe Onoratoe77c08d2009-08-01 00:01:20 -07002365 mWorkspace.getChildAt(mWorkspace.getCurrentScreen()).requestFocus();
Joe Onoratoe77c08d2009-08-01 00:01:20 -07002366 }
Joe Onorato7404ee42009-07-31 11:54:44 -07002367 }
2368
Joe Onorato7c312c12009-08-13 21:36:53 -07002369 void lockAllApps() {
2370 // TODO
2371 }
2372
2373 void unlockAllApps() {
2374 // TODO
2375 }
2376
Patrick Dubroy558654c2010-07-23 16:48:11 -07002377 private boolean isCustomizationDrawerVisible() {
Michael Jurka54f7ac32010-08-02 13:56:46 -07002378 return mHomeCustomizationDrawer != null &&
2379 mHomeCustomizationDrawer.getVisibility() == View.VISIBLE;
Patrick Dubroy558654c2010-07-23 16:48:11 -07002380 }
2381
2382 private void showCustomizationDrawer() {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002383 mWorkspace.shrinkToTop();
Patrick Dubroy558654c2010-07-23 16:48:11 -07002384 if (isAllAppsVisible()) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002385 cameraPan((View) mAllAppsGrid, mHomeCustomizationDrawer);
2386 } else {
2387 cameraZoomOut(mHomeCustomizationDrawer, false);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002388 }
Patrick Dubroy558654c2010-07-23 16:48:11 -07002389 }
2390
Michael Jurka4bb4f732010-08-04 18:46:01 -07002391 void hideCustomizationDrawer() {
2392 hideCustomizationDrawer(true);
2393 }
2394
2395 void hideCustomizationDrawer(boolean unshrinkWorkspace) {
Patrick Dubroy558654c2010-07-23 16:48:11 -07002396 if (isCustomizationDrawerVisible()) {
Michael Jurka4bb4f732010-08-04 18:46:01 -07002397 if (unshrinkWorkspace) {
2398 mWorkspace.unshrink();
2399 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002400 cameraZoomIn(mHomeCustomizationDrawer);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002401 }
2402 }
2403
Michael Jurka213d9632010-07-28 11:29:25 -07002404 void onWorkspaceUnshrink() {
2405 if (isAllAppsVisible()) {
Michael Jurka54dd7542010-07-30 14:47:52 -07002406 closeAllApps(true);
Michael Jurka213d9632010-07-28 11:29:25 -07002407 }
2408 if (isCustomizationDrawerVisible()) {
2409 hideCustomizationDrawer();
2410 }
2411 }
2412
Joe Onorato7404ee42009-07-31 11:54:44 -07002413 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002414 * Displays the shortcut creation dialog and launches, if necessary, the
2415 * appropriate activity.
2416 */
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002417 private class CreateShortcut implements DialogInterface.OnClickListener,
Romain Guy7b4ef332009-07-14 13:58:08 -07002418 DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
2419 DialogInterface.OnShowListener {
2420
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002421 private AddAdapter mAdapter;
Romain Guy9ffb5432009-03-24 21:04:15 -07002422
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002423 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002424 mAdapter = new AddAdapter(Launcher.this);
Romain Guycbb89e42009-06-08 15:52:54 -07002425
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002426 final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
2427 builder.setTitle(getString(R.string.menu_item_add_item));
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002428 builder.setAdapter(mAdapter, this);
Romain Guycbb89e42009-06-08 15:52:54 -07002429
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002430 builder.setInverseBackgroundForced(true);
2431
2432 AlertDialog dialog = builder.create();
2433 dialog.setOnCancelListener(this);
Romain Guycbb89e42009-06-08 15:52:54 -07002434 dialog.setOnDismissListener(this);
Romain Guy7b4ef332009-07-14 13:58:08 -07002435 dialog.setOnShowListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002436
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002437 return dialog;
2438 }
2439
2440 public void onCancel(DialogInterface dialog) {
2441 mWaitingForResult = false;
2442 cleanup();
2443 }
2444
Romain Guycbb89e42009-06-08 15:52:54 -07002445 public void onDismiss(DialogInterface dialog) {
Romain Guycbb89e42009-06-08 15:52:54 -07002446 }
2447
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002448 private void cleanup() {
Joe Onoratocc19a532009-11-19 14:19:17 -08002449 try {
2450 dismissDialog(DIALOG_CREATE_SHORTCUT);
2451 } catch (Exception e) {
2452 // An exception is thrown if the dialog is not visible, which is fine
2453 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002454 }
2455
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002456 /**
2457 * Handle the action clicked in the "Add to home" dialog.
2458 */
2459 public void onClick(DialogInterface dialog, int which) {
2460 Resources res = getResources();
2461 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002462
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002463 switch (which) {
2464 case AddAdapter.ITEM_SHORTCUT: {
Joe Onoratodeb98af2010-02-19 14:59:39 -08002465 pickShortcut();
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002466 break;
2467 }
Romain Guycbb89e42009-06-08 15:52:54 -07002468
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002469 case AddAdapter.ITEM_APPWIDGET: {
2470 int appWidgetId = Launcher.this.mAppWidgetHost.allocateAppWidgetId();
Romain Guycbb89e42009-06-08 15:52:54 -07002471
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002472 Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
2473 pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002474 // start the pick activity
2475 startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET);
2476 break;
2477 }
Romain Guycbb89e42009-06-08 15:52:54 -07002478
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002479 case AddAdapter.ITEM_LIVE_FOLDER: {
2480 // Insert extra item to handle inserting folder
2481 Bundle bundle = new Bundle();
Romain Guycbb89e42009-06-08 15:52:54 -07002482
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002483 ArrayList<String> shortcutNames = new ArrayList<String>();
2484 shortcutNames.add(res.getString(R.string.group_folder));
2485 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
Romain Guycbb89e42009-06-08 15:52:54 -07002486
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002487 ArrayList<ShortcutIconResource> shortcutIcons =
2488 new ArrayList<ShortcutIconResource>();
2489 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
2490 R.drawable.ic_launcher_folder));
2491 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
2492
2493 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2494 pickIntent.putExtra(Intent.EXTRA_INTENT,
2495 new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER));
2496 pickIntent.putExtra(Intent.EXTRA_TITLE,
2497 getText(R.string.title_select_live_folder));
2498 pickIntent.putExtras(bundle);
Romain Guycbb89e42009-06-08 15:52:54 -07002499
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002500 startActivityForResult(pickIntent, REQUEST_PICK_LIVE_FOLDER);
2501 break;
2502 }
2503
2504 case AddAdapter.ITEM_WALLPAPER: {
2505 startWallpaper();
2506 break;
2507 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002508 }
2509 }
Romain Guy7b4ef332009-07-14 13:58:08 -07002510
2511 public void onShow(DialogInterface dialog) {
Winson Chungaafa03c2010-06-11 17:34:16 -07002512 mWaitingForResult = true;
Romain Guy7b4ef332009-07-14 13:58:08 -07002513 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002514 }
2515
2516 /**
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002517 * Receives notifications when applications are added/removed.
2518 */
2519 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
2520 @Override
2521 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002522 closeSystemDialogs();
Joe Onoratob2061212009-11-24 16:13:54 -05002523 String reason = intent.getStringExtra("reason");
2524 if (!"homekey".equals(reason)) {
2525 boolean animate = true;
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002526 if (mPaused || "lock".equals(reason)) {
Joe Onoratob2061212009-11-24 16:13:54 -05002527 animate = false;
2528 }
Joe Onoratob2061212009-11-24 16:13:54 -05002529 closeAllApps(animate);
Michael Jurka4cb37242010-08-09 21:05:32 -07002530 mWorkspace.unshrink(animate);
Michael Jurka909f9152010-08-19 23:08:00 -07002531 hideCustomizationDrawer();
Joe Onoratob2061212009-11-24 16:13:54 -05002532 }
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002533 }
2534 }
2535
2536 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002537 * Receives notifications whenever the appwidgets are reset.
2538 */
2539 private class AppWidgetResetObserver extends ContentObserver {
2540 public AppWidgetResetObserver() {
2541 super(new Handler());
2542 }
2543
2544 @Override
2545 public void onChange(boolean selfChange) {
2546 onAppWidgetReset();
2547 }
2548 }
2549
2550 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002551 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002552 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002553 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07002554 if (mWorkspace != null) {
2555 return mWorkspace.getCurrentScreen();
2556 } else {
2557 return SCREEN_COUNT / 2;
2558 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002559 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002560
Joe Onorato9c1289c2009-08-17 11:03:03 -04002561 /**
2562 * Refreshes the shortcuts shown on the workspace.
2563 *
2564 * Implementation of the method from LauncherModel.Callbacks.
2565 */
2566 public void startBinding() {
2567 final Workspace workspace = mWorkspace;
2568 int count = workspace.getChildCount();
2569 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04002570 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Joe Onorato9c1289c2009-08-17 11:03:03 -04002571 ((ViewGroup) workspace.getChildAt(i)).removeAllViewsInLayout();
2572 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002573
Joe Onorato9c1289c2009-08-17 11:03:03 -04002574 if (DEBUG_USER_INTERFACE) {
2575 android.widget.Button finishButton = new android.widget.Button(this);
2576 finishButton.setText("Finish");
2577 workspace.addInScreen(finishButton, 1, 0, 0, 1, 1);
2578
2579 finishButton.setOnClickListener(new android.widget.Button.OnClickListener() {
2580 public void onClick(View v) {
2581 finish();
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002582 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002583 });
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002584 }
2585 }
2586
2587 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002588 * Bind the items start-end from the list.
2589 *
2590 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002591 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002592 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
2593
2594 final Workspace workspace = mWorkspace;
2595
2596 for (int i=start; i<end; i++) {
2597 final ItemInfo item = shortcuts.get(i);
2598 mDesktopItems.add(item);
2599 switch (item.itemType) {
2600 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
2601 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Joe Onorato0589f0f2010-02-08 13:44:00 -08002602 final View shortcut = createShortcut((ShortcutInfo)item);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002603 workspace.addInScreen(shortcut, item.screen, item.cellX, item.cellY, 1, 1,
2604 false);
2605 break;
2606 case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER:
2607 final FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
2608 (ViewGroup) workspace.getChildAt(workspace.getCurrentScreen()),
2609 (UserFolderInfo) item);
2610 workspace.addInScreen(newFolder, item.screen, item.cellX, item.cellY, 1, 1,
2611 false);
2612 break;
2613 case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER:
2614 final FolderIcon newLiveFolder = LiveFolderIcon.fromXml(
2615 R.layout.live_folder_icon, this,
2616 (ViewGroup) workspace.getChildAt(workspace.getCurrentScreen()),
2617 (LiveFolderInfo) item);
2618 workspace.addInScreen(newLiveFolder, item.screen, item.cellX, item.cellY, 1, 1,
2619 false);
2620 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002621 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002622 }
2623
Joe Onorato9c1289c2009-08-17 11:03:03 -04002624 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002625 }
2626
Joe Onorato9c1289c2009-08-17 11:03:03 -04002627 /**
2628 * Implementation of the method from LauncherModel.Callbacks.
2629 */
Joe Onoratoad72e172009-11-06 16:25:04 -05002630 public void bindFolders(HashMap<Long, FolderInfo> folders) {
2631 mFolders.clear();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002632 mFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002633 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002634
2635 /**
2636 * Add the views for a widget to the workspace.
2637 *
2638 * Implementation of the method from LauncherModel.Callbacks.
2639 */
2640 public void bindAppWidget(LauncherAppWidgetInfo item) {
Daniel Sandler843e8602010-06-07 14:59:01 -04002641 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
2642 if (DEBUG_WIDGETS) {
2643 Log.d(TAG, "bindAppWidget: " + item);
2644 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002645 final Workspace workspace = mWorkspace;
2646
2647 final int appWidgetId = item.appWidgetId;
2648 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04002649 if (DEBUG_WIDGETS) {
2650 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
2651 }
2652
Joe Onorato9c1289c2009-08-17 11:03:03 -04002653 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
2654
Joe Onorato9c1289c2009-08-17 11:03:03 -04002655 item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
2656 item.hostView.setTag(item);
2657
2658 workspace.addInScreen(item.hostView, item.screen, item.cellX,
2659 item.cellY, item.spanX, item.spanY, false);
2660
2661 workspace.requestLayout();
2662
2663 mDesktopItems.add(item);
Daniel Sandler843e8602010-06-07 14:59:01 -04002664
2665 if (DEBUG_WIDGETS) {
2666 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
2667 + (SystemClock.uptimeMillis()-start) + "ms");
2668 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002669 }
2670
2671 /**
2672 * Callback saying that there aren't any more items to bind.
2673 *
2674 * Implementation of the method from LauncherModel.Callbacks.
2675 */
2676 public void finishBindingItems() {
2677 if (mSavedState != null) {
2678 if (!mWorkspace.hasFocus()) {
2679 mWorkspace.getChildAt(mWorkspace.getCurrentScreen()).requestFocus();
2680 }
2681
2682 final long[] userFolders = mSavedState.getLongArray(RUNTIME_STATE_USER_FOLDERS);
2683 if (userFolders != null) {
2684 for (long folderId : userFolders) {
2685 final FolderInfo info = mFolders.get(folderId);
2686 if (info != null) {
2687 openFolder(info);
2688 }
2689 }
2690 final Folder openFolder = mWorkspace.getOpenFolder();
2691 if (openFolder != null) {
2692 openFolder.requestFocus();
2693 }
2694 }
2695
Joe Onorato9c1289c2009-08-17 11:03:03 -04002696 mSavedState = null;
2697 }
2698
2699 if (mSavedInstanceState != null) {
2700 super.onRestoreInstanceState(mSavedInstanceState);
2701 mSavedInstanceState = null;
2702 }
2703
Joe Onorato9c1289c2009-08-17 11:03:03 -04002704 mWorkspaceLoading = false;
2705 }
2706
2707 /**
2708 * Add the icons for all apps.
2709 *
2710 * Implementation of the method from LauncherModel.Callbacks.
2711 */
2712 public void bindAllApplications(ArrayList<ApplicationInfo> apps) {
Romain Guy84f296c2009-11-04 15:00:44 -08002713 mAllAppsGrid.setApps(apps);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002714 }
2715
2716 /**
2717 * A package was installed.
2718 *
2719 * Implementation of the method from LauncherModel.Callbacks.
2720 */
Joe Onorato64e6be72010-03-05 15:05:52 -05002721 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04002722 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onoratoa8138d52009-10-06 19:25:30 -07002723 mAllAppsGrid.addApps(apps);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002724 }
2725
2726 /**
2727 * A package was updated.
2728 *
2729 * Implementation of the method from LauncherModel.Callbacks.
2730 */
Joe Onorato64e6be72010-03-05 15:05:52 -05002731 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04002732 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato64e6be72010-03-05 15:05:52 -05002733 mWorkspace.updateShortcuts(apps);
2734 mAllAppsGrid.updateApps(apps);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002735 }
2736
2737 /**
2738 * A package was uninstalled.
2739 *
2740 * Implementation of the method from LauncherModel.Callbacks.
2741 */
Joe Onorato36115782010-06-17 13:28:48 -04002742 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04002743 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato36115782010-06-17 13:28:48 -04002744 if (permanent) {
2745 mWorkspace.removeItems(apps);
2746 }
Joe Onoratoa8138d52009-10-06 19:25:30 -07002747 mAllAppsGrid.removeApps(apps);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002748 }
Joe Onoratobe386092009-11-17 17:32:16 -08002749
2750 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07002751 * A number of packages were updated.
2752 */
2753 public void bindPackagesUpdated() {
2754 // update the customization drawer contents
Winson Chungb3347bb2010-08-19 14:51:28 -07002755 if (mCustomizePagedView != null)
2756 mCustomizePagedView.update();
Winson Chung80baf5a2010-08-09 16:03:15 -07002757 }
2758
2759 /**
Joe Onoratobe386092009-11-17 17:32:16 -08002760 * Prints out out state for debugging.
2761 */
2762 public void dumpState() {
2763 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08002764 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08002765 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
2766 Log.d(TAG, "mRestoring=" + mRestoring);
2767 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
2768 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
2769 Log.d(TAG, "mDesktopItems.size=" + mDesktopItems.size());
2770 Log.d(TAG, "mFolders.size=" + mFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08002771 mModel.dumpState();
2772 mAllAppsGrid.dumpState();
2773 Log.d(TAG, "END launcher2 dump state");
2774 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002775}