blob: 2688e54a3eedb3dd193b3a1ac3c1a4d05f1894b3 [file] [log] [blame]
Michael Jurka01f0ed42010-08-20 00:41:17 -07001
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002/*
3 * Copyright (C) 2008 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
Joe Onoratoa5902522009-07-30 13:37:37 -070018package com.android.launcher2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080019
Chet Haaseb1254a62010-09-07 13:35:00 -070020import android.animation.Animator;
21import android.animation.AnimatorListenerAdapter;
22import android.animation.ValueAnimator;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070023import com.android.common.Search;
24import com.android.launcher.R;
25
Chet Haaseb1254a62010-09-07 13:35:00 -070026import android.animation.ObjectAnimator;
Patrick Dubroy07a0de42010-08-26 11:48:35 -070027import android.animation.PropertyValuesHolder;
Chet Haaseb1254a62010-09-07 13:35:00 -070028import android.animation.AnimatorSet;
Michael Jurka946ad472010-07-09 18:05:18 -070029import android.app.Activity;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080030import android.app.AlertDialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080031import android.app.Dialog;
32import android.app.SearchManager;
33import android.app.StatusBarManager;
Dianne Hackborn107f8392009-08-05 21:32:16 -070034import android.app.WallpaperManager;
Michael Jurkaaf442092010-06-10 17:01:57 -070035import android.appwidget.AppWidgetManager;
36import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080037import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080038import android.content.BroadcastReceiver;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040039import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080040import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041import android.content.Context;
42import android.content.DialogInterface;
43import android.content.Intent;
Winson Chung80baf5a2010-08-09 16:03:15 -070044import android.content.Intent.ShortcutIconResource;
Romain Guy5bbc91b2010-08-18 11:38:46 -070045import android.content.IntentFilter;
Winson Chungaafa03c2010-06-11 17:34:16 -070046import android.content.pm.ActivityInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080047import android.content.pm.PackageManager;
Patrick Dubroyceae05d2010-08-30 10:40:53 -070048import android.content.pm.PackageManager.NameNotFoundException;
Daniel Sandlerab1ebd72010-04-27 16:57:25 -040049import android.content.pm.ResolveInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080050import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070051import android.content.res.Resources;
Daniel Sandlerab1ebd72010-04-27 16:57:25 -040052import android.content.res.TypedArray;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080053import android.database.ContentObserver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080054import android.graphics.Bitmap;
Romain Guya6abce82009-11-10 02:54:41 -080055import android.graphics.Canvas;
Winson Chung80baf5a2010-08-09 16:03:15 -070056import android.graphics.Color;
Michael Jurkaaf442092010-06-10 17:01:57 -070057import android.graphics.Rect;
Romain Guyff0c2e22009-11-10 12:09:59 -080058import android.graphics.drawable.ColorDrawable;
Michael Jurkaaf442092010-06-10 17:01:57 -070059import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040060import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070061import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080062import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020063import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080064import android.os.Handler;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080065import android.os.Parcelable;
Daniel Sandler843e8602010-06-07 14:59:01 -040066import android.os.SystemClock;
Joe Onoratobe386092009-11-17 17:32:16 -080067import android.os.SystemProperties;
Karl Rosaen138a0412009-04-23 19:00:21 -070068import android.provider.LiveFolders;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070069import android.provider.Settings;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080070import android.text.Selection;
71import android.text.SpannableStringBuilder;
72import android.text.TextUtils;
73import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070074import android.util.Log;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080075import android.view.Display;
Joe Onorato0d44e942009-11-16 18:20:51 -080076import android.view.HapticFeedbackConstants;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080077import android.view.KeyEvent;
78import android.view.LayoutInflater;
79import android.view.Menu;
80import android.view.MenuItem;
Michael Jurka0e260592010-06-30 17:07:39 -070081import android.view.MotionEvent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080082import android.view.View;
Romain Guy5bbc91b2010-08-18 11:38:46 -070083import android.view.View.OnLongClickListener;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080084import android.view.ViewGroup;
Winson Chungaafa03c2010-06-11 17:34:16 -070085import android.view.WindowManager;
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -070086import android.view.animation.AccelerateInterpolator;
Patrick Dubroy7247f632010-08-04 16:02:59 -070087import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080088import android.view.inputmethod.InputMethodManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080089import android.widget.EditText;
Michael Jurkaaf442092010-06-10 17:01:57 -070090import android.widget.ImageView;
91import android.widget.LinearLayout;
92import android.widget.PopupWindow;
Winson Chung80baf5a2010-08-09 16:03:15 -070093import android.widget.RelativeLayout;
Michael Jurka0e260592010-06-30 17:07:39 -070094import android.widget.TabHost;
Romain Guy5bbc91b2010-08-18 11:38:46 -070095import android.widget.TabHost.OnTabChangeListener;
96import android.widget.TabHost.TabContentFactory;
Winson Chung80baf5a2010-08-09 16:03:15 -070097import android.widget.TabWidget;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080098import android.widget.TextView;
99import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700100
101import java.io.DataInputStream;
102import java.io.DataOutputStream;
103import java.io.FileNotFoundException;
104import java.io.IOException;
105import java.util.ArrayList;
106import java.util.HashMap;
107import java.util.List;
Romain Guyedcce092010-03-04 13:03:17 -0800108
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800109/**
110 * Default launcher application.
111 */
Michael Jurka946ad472010-07-09 18:05:18 -0700112public final class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700113 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
114 AllAppsView.Watcher, View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800115 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700116 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800117
Joe Onorato9c1289c2009-08-17 11:03:03 -0400118 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400119 static final boolean DEBUG_WIDGETS = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400120 static final boolean DEBUG_USER_INTERFACE = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700121
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800122 private static final int MENU_GROUP_ADD = 1;
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800123 private static final int MENU_GROUP_WALLPAPER = MENU_GROUP_ADD + 1;
124
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800125 private static final int MENU_ADD = Menu.FIRST + 1;
Winson Chung7ad01412010-09-27 11:33:03 -0700126 private static final int MENU_MANAGE_APPS = MENU_ADD + 1;
127 private static final int MENU_WALLPAPER_SETTINGS = MENU_MANAGE_APPS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800128 private static final int MENU_SEARCH = MENU_WALLPAPER_SETTINGS + 1;
129 private static final int MENU_NOTIFICATIONS = MENU_SEARCH + 1;
Romain Guy94dabf12009-07-21 10:55:43 -0700130 private static final int MENU_SETTINGS = MENU_NOTIFICATIONS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800131
132 private static final int REQUEST_CREATE_SHORTCUT = 1;
133 private static final int REQUEST_CREATE_LIVE_FOLDER = 4;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700134 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800135 private static final int REQUEST_PICK_APPLICATION = 6;
136 private static final int REQUEST_PICK_SHORTCUT = 7;
137 private static final int REQUEST_PICK_LIVE_FOLDER = 8;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700138 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700139 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800140
141 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
142
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800143 static final int SCREEN_COUNT = 5;
144 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800145
Joe Onorato7c312c12009-08-13 21:36:53 -0700146 static final int DIALOG_CREATE_SHORTCUT = 1;
147 static final int DIALOG_RENAME_FOLDER = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800148
Romain Guy98d01652009-06-30 16:21:04 -0700149 private static final String PREFERENCES = "launcher.preferences";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800150
151 // Type: int
152 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
153 // Type: boolean
154 private static final String RUNTIME_STATE_ALL_APPS_FOLDER = "launcher.all_apps_folder";
155 // Type: long
156 private static final String RUNTIME_STATE_USER_FOLDERS = "launcher.user_folder";
157 // Type: int
158 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
159 // Type: int
160 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cellX";
161 // Type: int
162 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cellY";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800163 // Type: boolean
164 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
165 // Type: long
166 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
167
Winson Chung80baf5a2010-08-09 16:03:15 -0700168 // tags for the customization tabs
169 private static final String WIDGETS_TAG = "widgets";
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700170 private static final String APPLICATIONS_TAG = "applications";
Winson Chung80baf5a2010-08-09 16:03:15 -0700171 private static final String FOLDERS_TAG = "folders";
172 private static final String SHORTCUTS_TAG = "shortcuts";
173 private static final String WALLPAPERS_TAG = "wallpapers";
174
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700175 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
176
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700177 /** The different states that Launcher can be in. */
178 private enum State { WORKSPACE, ALL_APPS, CUSTOMIZE, OVERVIEW };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700179 private State mState = State.WORKSPACE;
180 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700181
Joe Onorato9c1289c2009-08-17 11:03:03 -0400182 static final int APPWIDGET_HOST_ID = 1024;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800183
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800184 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800185 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800186
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800187 private final BroadcastReceiver mCloseSystemDialogsReceiver
188 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800189 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
190
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800191 private LayoutInflater mInflater;
192
Joe Onorato00acb122009-08-04 16:04:30 -0400193 private DragController mDragController;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800194 private Workspace mWorkspace;
Romain Guycbb89e42009-06-08 15:52:54 -0700195
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700196 private AppWidgetManager mAppWidgetManager;
197 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700198
Michael Jurka0280c3b2010-09-17 15:00:07 -0700199 private int mAddScreen = -1;
200 private int mAddIntersectCellX = -1;
201 private int mAddIntersectCellY = -1;
202 private int[] mAddDropPosition;
203 private int[] mTmpAddItemCellCoordinates = new int[2];
204
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800205 private FolderInfo mFolderInfo;
206
Joe Onorato7c312c12009-08-13 21:36:53 -0700207 private DeleteZone mDeleteZone;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700208 private HandleView mHandleView;
Joe Onorato7c312c12009-08-13 21:36:53 -0700209 private AllAppsView mAllAppsGrid;
Michael Jurka0e260592010-06-30 17:07:39 -0700210 private TabHost mHomeCustomizationDrawer;
Patrick Dubroy2b9ff372010-09-07 17:49:27 -0700211
212 private PagedView mAllAppsPagedView = null;
213 private CustomizePagedView mCustomizePagedView = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800214
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800215 private Bundle mSavedState;
216
217 private SpannableStringBuilder mDefaultKeySsb = null;
218
Joe Onorato9c1289c2009-08-17 11:03:03 -0400219 private boolean mWorkspaceLoading = true;
220
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800221 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800222 private boolean mRestoring;
223 private boolean mWaitingForResult;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800224
225 private Bundle mSavedInstanceState;
226
Joe Onorato9c1289c2009-08-17 11:03:03 -0400227 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800228 private IconCache mIconCache;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400229
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700230 private static LocaleConfiguration sLocaleConfiguration = null;
231
Romain Guy84f296c2009-11-04 15:00:44 -0800232 private ArrayList<ItemInfo> mDesktopItems = new ArrayList<ItemInfo>();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700233 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700234
Romain Guy1fbc1c82009-11-09 20:43:08 -0800235 private ImageView mPreviousView;
236 private ImageView mNextView;
Joe Onorato080d9b62009-11-02 12:01:11 -0500237
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400238 // Hotseats (quick-launch icons next to AllApps)
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400239 private String[] mHotseatConfig = null;
240 private Intent[] mHotseats = null;
241 private Drawable[] mHotseatIcons = null;
242 private CharSequence[] mHotseatLabels = null;
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400243
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700244 private Intent mAppMarketIntent = null;
245
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) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200267 android.os.Debug.startMethodTracing(
268 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800269 }
270
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400271 loadHotseats();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800272 checkForLocaleChange();
273 setWallpaperDimension();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800274 setContentView(R.layout.launcher);
Michael Jurka946ad472010-07-09 18:05:18 -0700275 mHomeCustomizationDrawer = (TabHost) findViewById(com.android.internal.R.id.tabhost);
276 if (mHomeCustomizationDrawer != null) {
277 mHomeCustomizationDrawer.setup();
Winson Chungaafa03c2010-06-11 17:34:16 -0700278
Winson Chung80baf5a2010-08-09 16:03:15 -0700279 // share the same customization workspace across all the tabs
Winson Chunge3193b92010-09-10 11:44:42 -0700280 mCustomizePagedView = (CustomizePagedView) mInflater.inflate(
281 R.layout.customization_drawer, mHomeCustomizationDrawer, false);
Winson Chung80baf5a2010-08-09 16:03:15 -0700282 TabContentFactory contentFactory = new TabContentFactory() {
283 public View createTabContent(String tag) {
284 return mCustomizePagedView;
285 }
286 };
287
Michael Jurka946ad472010-07-09 18:05:18 -0700288 String widgetsLabel = getString(R.string.widgets_tab_label);
Winson Chung80baf5a2010-08-09 16:03:15 -0700289 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(WIDGETS_TAG)
290 .setIndicator(widgetsLabel).setContent(contentFactory));
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700291 String applicationsLabel = getString(R.string.applications_tab_label);
292 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(APPLICATIONS_TAG)
293 .setIndicator(applicationsLabel).setContent(contentFactory));
Michael Jurka946ad472010-07-09 18:05:18 -0700294 String foldersLabel = getString(R.string.folders_tab_label);
Winson Chung80baf5a2010-08-09 16:03:15 -0700295 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(FOLDERS_TAG)
296 .setIndicator(foldersLabel).setContent(contentFactory));
Michael Jurka946ad472010-07-09 18:05:18 -0700297 String wallpapersLabel = getString(R.string.wallpapers_tab_label);
Winson Chung80baf5a2010-08-09 16:03:15 -0700298 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(WALLPAPERS_TAG)
299 .setIndicator(wallpapersLabel).setContent(contentFactory));
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700300 String shortcutsLabel = getString(R.string.shortcuts_tab_label);
301 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(SHORTCUTS_TAG)
302 .setIndicator(shortcutsLabel).setContent(contentFactory));
Winson Chung80baf5a2010-08-09 16:03:15 -0700303
304 // TEMP: just styling the tab widget to be a bit nicer until we get the actual
305 // new assets
306 TabWidget tabWidget = mHomeCustomizationDrawer.getTabWidget();
307 for (int i = 0; i < tabWidget.getChildCount(); ++i) {
308 RelativeLayout tab = (RelativeLayout) tabWidget.getChildTabViewAt(i);
309 TextView text = (TextView) tab.getChildAt(1);
310 text.setTextSize(20.0f);
311 text.setPadding(20, 0, 20, 0);
312 text.setShadowLayer(1.0f, 0.0f, 1.0f, Color.BLACK);
313 tab.setBackgroundDrawable(null);
314 }
315
316 mHomeCustomizationDrawer.setOnTabChangedListener(new OnTabChangeListener() {
317 public void onTabChanged(String tabId) {
318 // animate the changing of the tab content by fading pages in and out
319 final int duration = 150;
320 final float alpha = mCustomizePagedView.getAlpha();
Chet Haase472b2812010-10-14 07:02:04 -0700321 ValueAnimator alphaAnim = ObjectAnimator.ofFloat(mCustomizePagedView,
Winson Chung80baf5a2010-08-09 16:03:15 -0700322 "alpha", alpha, 0.0f);
Chet Haase472b2812010-10-14 07:02:04 -0700323 alphaAnim.setDuration(duration);
Chet Haaseb1254a62010-09-07 13:35:00 -0700324 alphaAnim.addListener(new AnimatorListenerAdapter() {
325 public void onAnimationEnd(Animator animation) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700326 String tag = mHomeCustomizationDrawer.getCurrentTabTag();
327 if (tag == WIDGETS_TAG) {
328 mCustomizePagedView.setCustomizationFilter(
329 CustomizePagedView.CustomizationType.WidgetCustomization);
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700330 } else if (tag == APPLICATIONS_TAG) {
331 mCustomizePagedView.setCustomizationFilter(
332 CustomizePagedView.CustomizationType.ApplicationCustomization);
Winson Chung80baf5a2010-08-09 16:03:15 -0700333 } else if (tag == FOLDERS_TAG) {
334 mCustomizePagedView.setCustomizationFilter(
335 CustomizePagedView.CustomizationType.FolderCustomization);
Winson Chung80baf5a2010-08-09 16:03:15 -0700336 } else if (tag == WALLPAPERS_TAG) {
337 mCustomizePagedView.setCustomizationFilter(
338 CustomizePagedView.CustomizationType.WallpaperCustomization);
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700339 } else if (tag == SHORTCUTS_TAG) {
340 mCustomizePagedView.setCustomizationFilter(
341 CustomizePagedView.CustomizationType.ShortcutCustomization);
Winson Chung80baf5a2010-08-09 16:03:15 -0700342 }
343
344 final float alpha = mCustomizePagedView.getAlpha();
Chet Haase472b2812010-10-14 07:02:04 -0700345 ValueAnimator alphaAnim = ObjectAnimator.ofFloat(
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700346 mCustomizePagedView, "alpha", alpha, 1.0f);
Chet Haase472b2812010-10-14 07:02:04 -0700347 alphaAnim.setDuration(duration);
Winson Chung80baf5a2010-08-09 16:03:15 -0700348 alphaAnim.start();
349 }
350 });
351 alphaAnim.start();
352 }
353 });
Michael Jurka946ad472010-07-09 18:05:18 -0700354
Winson Chungb0b2e6f2010-10-12 17:49:56 -0700355 // TEMP: Working around a bug in tab host where the current tab does not initially have
356 // a highlight on it by selecting something else, then selecting the actual tab we want..
357 mHomeCustomizationDrawer.setCurrentTab(1);
Michael Jurka946ad472010-07-09 18:05:18 -0700358 mHomeCustomizationDrawer.setCurrentTab(0);
359 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800360 setupViews();
361
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800362 registerContentObservers();
363
Joe Onorato7c312c12009-08-13 21:36:53 -0700364 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700365
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800366 mSavedState = savedInstanceState;
367 restoreState(mSavedState);
368
369 if (PROFILE_STARTUP) {
370 android.os.Debug.stopMethodTracing();
371 }
372
373 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400374 mModel.startLoader(this, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800375 }
376
377 // For handling default keys
378 mDefaultKeySsb = new SpannableStringBuilder();
379 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800380
381 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
382 registerReceiver(mCloseSystemDialogsReceiver, filter);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800383 }
Romain Guycbb89e42009-06-08 15:52:54 -0700384
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800385 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700386 if (sLocaleConfiguration == null) {
387 new AsyncTask<Void, Void, LocaleConfiguration>() {
388 @Override
389 protected LocaleConfiguration doInBackground(Void... unused) {
390 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
391 readConfiguration(Launcher.this, localeConfiguration);
392 return localeConfiguration;
393 }
394
395 @Override
396 protected void onPostExecute(LocaleConfiguration result) {
397 sLocaleConfiguration = result;
398 checkForLocaleChange(); // recursive, but now with a locale configuration
399 }
400 }.execute();
401 return;
402 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700403
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800404 final Configuration configuration = getResources().getConfiguration();
405
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700406 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800407 final String locale = configuration.locale.toString();
408
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700409 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800410 final int mcc = configuration.mcc;
411
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700412 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800413 final int mnc = configuration.mnc;
414
Romain Guy84f296c2009-11-04 15:00:44 -0800415 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800416
Romain Guy84f296c2009-11-04 15:00:44 -0800417 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700418 sLocaleConfiguration.locale = locale;
419 sLocaleConfiguration.mcc = mcc;
420 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700421
Joe Onorato0589f0f2010-02-08 13:44:00 -0800422 mIconCache.flush();
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400423 loadHotseats();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700424
425 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
426 new Thread("WriteLocaleConfiguration") {
427 public void run() {
428 writeConfiguration(Launcher.this, localeConfiguration);
429 }
430 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700431 }
432 }
433
434 private static class LocaleConfiguration {
435 public String locale;
436 public int mcc = -1;
437 public int mnc = -1;
438 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700439
Romain Guy98d01652009-06-30 16:21:04 -0700440 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
441 DataInputStream in = null;
442 try {
443 in = new DataInputStream(context.openFileInput(PREFERENCES));
444 configuration.locale = in.readUTF();
445 configuration.mcc = in.readInt();
446 configuration.mnc = in.readInt();
447 } catch (FileNotFoundException e) {
448 // Ignore
449 } catch (IOException e) {
450 // Ignore
451 } finally {
452 if (in != null) {
453 try {
454 in.close();
455 } catch (IOException e) {
456 // Ignore
457 }
458 }
459 }
460 }
461
462 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
463 DataOutputStream out = null;
464 try {
465 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
466 out.writeUTF(configuration.locale);
467 out.writeInt(configuration.mcc);
468 out.writeInt(configuration.mnc);
469 out.flush();
470 } catch (FileNotFoundException e) {
471 // Ignore
472 } catch (IOException e) {
473 //noinspection ResultOfMethodCallIgnored
474 context.getFileStreamPath(PREFERENCES).delete();
475 } finally {
476 if (out != null) {
477 try {
478 out.close();
479 } catch (IOException e) {
480 // Ignore
481 }
482 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800483 }
484 }
485
486 static int getScreen() {
487 synchronized (sLock) {
488 return sScreen;
489 }
490 }
491
492 static void setScreen(int screen) {
493 synchronized (sLock) {
494 sScreen = screen;
495 }
496 }
497
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800498 private void setWallpaperDimension() {
Dianne Hackborn107f8392009-08-05 21:32:16 -0700499 WallpaperManager wpm = (WallpaperManager)getSystemService(WALLPAPER_SERVICE);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800500
501 Display display = getWindowManager().getDefaultDisplay();
Romain Guy5bbc91b2010-08-18 11:38:46 -0700502 // TODO: Put back when we decide about scrolling the wallpaper
503 // boolean isPortrait = display.getWidth() < display.getHeight();
504 // final int width = isPortrait ? display.getWidth() : display.getHeight();
505 // final int height = isPortrait ? display.getHeight() : display.getWidth();
506 wpm.suggestDesiredDimensions(Math.max(display.getWidth(), display.getHeight()),
507 Math.max(display.getWidth(), display.getHeight()));
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800508 }
509
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400510 // Note: This doesn't do all the client-id magic that BrowserProvider does
511 // in Browser. (http://b/2425179)
512 private Uri getDefaultBrowserUri() {
513 String url = getString(R.string.default_browser_url);
514 if (url.indexOf("{CID}") != -1) {
515 url = url.replace("{CID}", "android-google");
516 }
517 return Uri.parse(url);
518 }
519
520 // Load the Intent templates from arrays.xml to populate the hotseats. For
521 // each Intent, if it resolves to a single app, use that as the launch
522 // intent & use that app's label as the contentDescription. Otherwise,
523 // retain the ResolveActivity so the user can pick an app.
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400524 private void loadHotseats() {
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400525 if (mHotseatConfig == null) {
526 mHotseatConfig = getResources().getStringArray(R.array.hotseats);
527 if (mHotseatConfig.length > 0) {
528 mHotseats = new Intent[mHotseatConfig.length];
529 mHotseatLabels = new CharSequence[mHotseatConfig.length];
530 mHotseatIcons = new Drawable[mHotseatConfig.length];
531 } else {
532 mHotseats = null;
533 mHotseatIcons = null;
534 mHotseatLabels = null;
535 }
536
537 TypedArray hotseatIconDrawables = getResources().obtainTypedArray(R.array.hotseat_icons);
538 for (int i=0; i<mHotseatConfig.length; i++) {
539 // load icon for this slot; currently unrelated to the actual activity
540 try {
541 mHotseatIcons[i] = hotseatIconDrawables.getDrawable(i);
542 } catch (ArrayIndexOutOfBoundsException ex) {
543 Log.w(TAG, "Missing hotseat_icons array item #" + i);
544 mHotseatIcons[i] = null;
545 }
546 }
547 hotseatIconDrawables.recycle();
548 }
549
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400550 PackageManager pm = getPackageManager();
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400551 for (int i=0; i<mHotseatConfig.length; i++) {
552 Intent intent = null;
553 if (mHotseatConfig[i].equals("*BROWSER*")) {
554 // magic value meaning "launch user's default web browser"
555 // replace it with a generic web request so we can see if there is indeed a default
556 String defaultUri = getString(R.string.default_browser_url);
557 intent = new Intent(
558 Intent.ACTION_VIEW,
559 ((defaultUri != null)
560 ? Uri.parse(defaultUri)
561 : getDefaultBrowserUri())
562 ).addCategory(Intent.CATEGORY_BROWSABLE);
563 // note: if the user launches this without a default set, she
564 // will always be taken to the default URL above; this is
565 // unavoidable as we must specify a valid URL in order for the
Winson Chungaafa03c2010-06-11 17:34:16 -0700566 // chooser to appear, and once the user selects something, that
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400567 // URL is unavoidably sent to the chosen app.
568 } else {
569 try {
570 intent = Intent.parseUri(mHotseatConfig[i], 0);
571 } catch (java.net.URISyntaxException ex) {
572 Log.w(TAG, "Invalid hotseat intent: " + mHotseatConfig[i]);
573 // bogus; leave intent=null
574 }
575 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700576
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400577 if (intent == null) {
578 mHotseats[i] = null;
579 mHotseatLabels[i] = getText(R.string.activity_not_found);
580 continue;
581 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400582
583 if (LOGD) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700584 Log.d(TAG, "loadHotseats: hotseat " + i
585 + " initial intent=["
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400586 + intent.toUri(Intent.URI_INTENT_SCHEME)
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400587 + "]");
588 }
589
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400590 ResolveInfo bestMatch = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
591 List<ResolveInfo> allMatches = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
Winson Chungaafa03c2010-06-11 17:34:16 -0700592 if (LOGD) {
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400593 Log.d(TAG, "Best match for intent: " + bestMatch);
594 Log.d(TAG, "All matches: ");
595 for (ResolveInfo ri : allMatches) {
596 Log.d(TAG, " --> " + ri);
597 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400598 }
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400599 // did this resolve to a single app, or the resolver?
600 if (allMatches.size() == 0 || bestMatch == null) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700601 // can't find any activity to handle this. let's leave the
602 // intent as-is and let Launcher show a toast when it fails
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400603 // to launch.
604 mHotseats[i] = intent;
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400605
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400606 // set accessibility text to "Not installed"
607 mHotseatLabels[i] = getText(R.string.activity_not_found);
608 } else {
609 boolean found = false;
610 for (ResolveInfo ri : allMatches) {
611 if (bestMatch.activityInfo.name.equals(ri.activityInfo.name)
612 && bestMatch.activityInfo.applicationInfo.packageName
613 .equals(ri.activityInfo.applicationInfo.packageName)) {
614 found = true;
615 break;
616 }
617 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700618
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400619 if (!found) {
620 if (LOGD) Log.d(TAG, "Multiple options, no default yet");
621 // the bestMatch is probably the ResolveActivity, meaning the
622 // user has not yet selected a default
623 // so: we'll keep the original intent for now
624 mHotseats[i] = intent;
625
626 // set the accessibility text to "Select shortcut"
627 mHotseatLabels[i] = getText(R.string.title_select_shortcut);
628 } else {
629 // we have an app!
630 // now reconstruct the intent to launch it through the front
631 // door
632 ComponentName com = new ComponentName(
633 bestMatch.activityInfo.applicationInfo.packageName,
634 bestMatch.activityInfo.name);
635 mHotseats[i] = new Intent(Intent.ACTION_MAIN).setComponent(com);
636
637 // load the app label for accessibility
638 mHotseatLabels[i] = bestMatch.activityInfo.loadLabel(pm);
639 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400640 }
641
642 if (LOGD) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700643 Log.d(TAG, "loadHotseats: hotseat " + i
644 + " final intent=["
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400645 + ((mHotseats[i] == null)
646 ? "null"
647 : mHotseats[i].toUri(Intent.URI_INTENT_SCHEME))
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400648 + "] label=[" + mHotseatLabels[i]
649 + "]"
650 );
651 }
652 }
653 }
654
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800655 @Override
656 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Romain Guyaad5ef42009-06-10 02:48:37 -0700657 mWaitingForResult = false;
658
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800659 // The pattern used here is that a user PICKs a specific application,
660 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700661
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800662 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
663 // launch over to the Music app to actually CREATE_SHORTCUT.
Romain Guycbb89e42009-06-08 15:52:54 -0700664
Michael Jurka0280c3b2010-09-17 15:00:07 -0700665 if (resultCode == RESULT_OK && mAddScreen != -1) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800666 switch (requestCode) {
667 case REQUEST_PICK_APPLICATION:
Michael Jurka28750fb2010-09-24 17:43:49 -0700668 completeAddApplication(
669 this, data, mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800670 break;
671 case REQUEST_PICK_SHORTCUT:
Joe Onoratodeb98af2010-02-19 14:59:39 -0800672 processShortcut(data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800673 break;
674 case REQUEST_CREATE_SHORTCUT:
Michael Jurka0280c3b2010-09-17 15:00:07 -0700675 completeAddShortcut(data, mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800676 break;
677 case REQUEST_PICK_LIVE_FOLDER:
678 addLiveFolder(data);
679 break;
680 case REQUEST_CREATE_LIVE_FOLDER:
Michael Jurka0280c3b2010-09-17 15:00:07 -0700681 completeAddLiveFolder(data, mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800682 break;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700683 case REQUEST_PICK_APPWIDGET:
Michael Jurkaaf442092010-06-10 17:01:57 -0700684 addAppWidgetFromPick(data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800685 break;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700686 case REQUEST_CREATE_APPWIDGET:
Michael Jurkaaf442092010-06-10 17:01:57 -0700687 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700688 completeAddAppWidget(appWidgetId, mAddScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800689 break;
Mike Clerona0618e42009-10-22 13:55:21 -0700690 case REQUEST_PICK_WALLPAPER:
691 // We just wanted the activity result here so we can clear mWaitingForResult
692 break;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800693 }
Romain Guy18042c82009-11-06 11:44:55 -0800694 } else if ((requestCode == REQUEST_PICK_APPWIDGET ||
695 requestCode == REQUEST_CREATE_APPWIDGET) && resultCode == RESULT_CANCELED &&
696 data != null) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700697 // Clean up the appWidgetId if we canceled
698 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
699 if (appWidgetId != -1) {
700 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800701 }
702 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800703 }
704
705 @Override
706 protected void onResume() {
707 super.onResume();
708
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800709 mPaused = false;
Joe Onorato7e4ed992009-12-03 13:10:49 -0800710
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800711 if (mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400712 mWorkspaceLoading = true;
713 mModel.startLoader(this, true);
714 mRestoring = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800715 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700716 // When we resume Launcher, a different Activity might be responsible for the app
717 // market intent, so refresh the icon
718 updateAppMarketIcon();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800719 }
720
721 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700722 protected void onPause() {
723 super.onPause();
Michael Jurkaaf442092010-06-10 17:01:57 -0700724 // Some launcher layouts don't have a previous and next view
725 if (mPreviousView != null) {
726 dismissPreview(mPreviousView);
Patrick Dubroyab962b72010-07-26 12:10:10 -0700727 }
728 if (mNextView != null) {
Michael Jurkaaf442092010-06-10 17:01:57 -0700729 dismissPreview(mNextView);
730 }
Joe Onorato24b6fd82009-11-12 13:47:09 -0800731 mDragController.cancelDrag();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700732 }
Romain Guycbb89e42009-06-08 15:52:54 -0700733
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700734 @Override
735 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400736 // Flag the loader to stop early before switching
737 mModel.stopLoader();
Romain Guy13c2e7b2010-03-10 19:45:00 -0800738 mAllAppsGrid.surrender();
Romain Guy13c2e7b2010-03-10 19:45:00 -0800739 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700740 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700741
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800742 // We can't hide the IME if it was forced open. So don't bother
743 /*
744 @Override
745 public void onWindowFocusChanged(boolean hasFocus) {
746 super.onWindowFocusChanged(hasFocus);
747
748 if (hasFocus) {
749 final InputMethodManager inputManager = (InputMethodManager)
750 getSystemService(Context.INPUT_METHOD_SERVICE);
751 WindowManager.LayoutParams lp = getWindow().getAttributes();
752 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
753 android.os.Handler()) {
754 protected void onReceiveResult(int resultCode, Bundle resultData) {
755 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
756 }
757 });
758 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
759 }
760 }
761 */
762
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800763 private boolean acceptFilter() {
764 final InputMethodManager inputManager = (InputMethodManager)
765 getSystemService(Context.INPUT_METHOD_SERVICE);
766 return !inputManager.isFullscreenMode();
767 }
768
769 @Override
770 public boolean onKeyDown(int keyCode, KeyEvent event) {
771 boolean handled = super.onKeyDown(keyCode, event);
772 if (!handled && acceptFilter() && keyCode != KeyEvent.KEYCODE_ENTER) {
773 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
774 keyCode, event);
775 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700776 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700777 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700778 // showSearchDialog()
779 // If there are multiple keystrokes before the search dialog takes focus,
780 // onSearchRequested() will be called for every keystroke,
781 // but it is idempotent, so it's fine.
782 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800783 }
784 }
785
Joe Onorato8a9625e2010-01-28 15:55:35 -0800786 // Eat the long press event so the keyboard doesn't come up.
787 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
788 return true;
789 }
790
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800791 return handled;
792 }
793
Karl Rosaen138a0412009-04-23 19:00:21 -0700794 private String getTypedText() {
795 return mDefaultKeySsb.toString();
796 }
797
798 private void clearTypedText() {
799 mDefaultKeySsb.clear();
800 mDefaultKeySsb.clearSpans();
801 Selection.setSelection(mDefaultKeySsb, 0);
802 }
803
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800804 /**
805 * Restores the previous state, if it exists.
806 *
807 * @param savedState The previous state.
808 */
809 private void restoreState(Bundle savedState) {
810 if (savedState == null) {
811 return;
812 }
813
Joe Onorato3a8820b2009-11-10 15:06:42 -0800814 final boolean allApps = savedState.getBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, false);
815 if (allApps) {
816 showAllApps(false);
817 }
818
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800819 final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
820 if (currentScreen > -1) {
Michael Jurka0142d492010-08-25 17:46:15 -0700821 mWorkspace.setCurrentPage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800822 }
823
824 final int addScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700825
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800826 if (addScreen > -1) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700827 mAddScreen = addScreen;
828 mAddIntersectCellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
829 mAddIntersectCellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800830 mRestoring = true;
831 }
832
833 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
834 if (renameFolder) {
835 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700836 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800837 mRestoring = true;
838 }
839 }
840
841 /**
842 * Finds all the views we need and configure them properly.
843 */
844 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700845 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -0400846
Romain Guyb1b69f52009-08-10 15:10:15 -0700847 DragLayer dragLayer = (DragLayer) findViewById(R.id.drag_layer);
Joe Onorato00acb122009-08-04 16:04:30 -0400848 dragLayer.setDragController(dragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800849
Joe Onorato7c312c12009-08-13 21:36:53 -0700850 mAllAppsGrid = (AllAppsView)dragLayer.findViewById(R.id.all_apps_view);
Joe Onorato6665c0f2009-09-02 15:27:24 -0700851 mAllAppsGrid.setLauncher(this);
Joe Onorato5162ea92009-09-03 09:39:42 -0700852 mAllAppsGrid.setDragController(dragController);
Romain Guyc16fea72010-03-12 17:17:56 -0800853 ((View) mAllAppsGrid).setWillNotDraw(false); // We don't want a hole punched in our window.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700854 // Manage focusability manually since this thing is always visible (in non-xlarge)
Winson Chungaafa03c2010-06-11 17:34:16 -0700855 ((View) mAllAppsGrid).setFocusable(false);
Joe Onorato7c312c12009-08-13 21:36:53 -0700856
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700857 if (LauncherApplication.isScreenXLarge()) {
858 // They need to be INVISIBLE initially so that they will be measured in the layout.
859 // Otherwise the animations are messed up when we show them for the first time.
860 ((View) mAllAppsGrid).setVisibility(View.INVISIBLE);
861 mHomeCustomizationDrawer.setVisibility(View.INVISIBLE);
862 }
863
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800864 mWorkspace = (Workspace) dragLayer.findViewById(R.id.workspace);
865 final Workspace workspace = mWorkspace;
Joe Onoratof0dde092010-02-16 18:25:23 -0500866 workspace.setHapticFeedbackEnabled(false);
Michael Jurka946ad472010-07-09 18:05:18 -0700867
Joe Onorato7c312c12009-08-13 21:36:53 -0700868 DeleteZone deleteZone = (DeleteZone) dragLayer.findViewById(R.id.delete_zone);
869 mDeleteZone = deleteZone;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800870
Michael Jurka2c3af5f2010-08-03 13:53:20 -0700871 View handleView = findViewById(R.id.all_apps_button);
872 if (handleView != null && handleView instanceof HandleView) {
873 // we don't use handle view in xlarge mode
Michael Jurka7ef4f752010-08-03 16:04:26 -0700874 mHandleView = (HandleView)handleView;
Michael Jurka2c3af5f2010-08-03 13:53:20 -0700875 mHandleView.setLauncher(this);
876 mHandleView.setOnClickListener(this);
877 mHandleView.setOnLongClickListener(this);
878 }
Romain Guy1fbc1c82009-11-09 20:43:08 -0800879
Winson Chung80baf5a2010-08-09 16:03:15 -0700880 if (mCustomizePagedView != null) {
881 mCustomizePagedView.setLauncher(this);
882 mCustomizePagedView.setDragController(dragController);
883 mCustomizePagedView.update();
Michael Jurkaaf442092010-06-10 17:01:57 -0700884 } else {
885 ImageView hotseatLeft = (ImageView) findViewById(R.id.hotseat_left);
886 hotseatLeft.setContentDescription(mHotseatLabels[0]);
887 hotseatLeft.setImageDrawable(mHotseatIcons[0]);
888 ImageView hotseatRight = (ImageView) findViewById(R.id.hotseat_right);
889 hotseatRight.setContentDescription(mHotseatLabels[1]);
890 hotseatRight.setImageDrawable(mHotseatIcons[1]);
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400891
Michael Jurkaaf442092010-06-10 17:01:57 -0700892 mPreviousView = (ImageView) dragLayer.findViewById(R.id.previous_screen);
893 mNextView = (ImageView) dragLayer.findViewById(R.id.next_screen);
Romain Guy1fbc1c82009-11-09 20:43:08 -0800894
Michael Jurkaaf442092010-06-10 17:01:57 -0700895 Drawable previous = mPreviousView.getDrawable();
896 Drawable next = mNextView.getDrawable();
897 mWorkspace.setIndicators(previous, next);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800898
Michael Jurkaaf442092010-06-10 17:01:57 -0700899 mPreviousView.setHapticFeedbackEnabled(false);
900 mPreviousView.setOnLongClickListener(this);
901 mNextView.setHapticFeedbackEnabled(false);
902 mNextView.setOnLongClickListener(this);
903 }
Romain Guy1fbc1c82009-11-09 20:43:08 -0800904
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800905 workspace.setOnLongClickListener(this);
Joe Onorato00acb122009-08-04 16:04:30 -0400906 workspace.setDragController(dragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800907 workspace.setLauncher(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800908
909 deleteZone.setLauncher(this);
Joe Onorato00acb122009-08-04 16:04:30 -0400910 deleteZone.setDragController(dragController);
Michael Jurka54f7ac32010-08-02 13:56:46 -0700911 int deleteZoneHandleId;
912 if (LauncherApplication.isScreenXLarge()) {
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700913 deleteZoneHandleId = R.id.all_apps_button;
Michael Jurka54f7ac32010-08-02 13:56:46 -0700914 } else {
915 deleteZoneHandleId = R.id.all_apps_button_cluster;
916 }
Michael Jurkaaf442092010-06-10 17:01:57 -0700917 deleteZone.setHandle(findViewById(deleteZoneHandleId));
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700918 dragController.addDragListener(deleteZone);
919
920 ApplicationInfoDropTarget infoButton = (ApplicationInfoDropTarget)findViewById(R.id.info_button);
921 if (infoButton != null) {
922 infoButton.setLauncher(this);
923 infoButton.setHandle(findViewById(R.id.configure_button));
924 infoButton.setDragColor(getResources().getColor(R.color.app_info_filter));
925 dragController.addDragListener(infoButton);
926 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800927
Joe Onorato00acb122009-08-04 16:04:30 -0400928 dragController.setDragScoller(workspace);
Joe Onorato00acb122009-08-04 16:04:30 -0400929 dragController.setScrollView(dragLayer);
Romain Guyea3763c2010-01-11 18:02:04 -0800930 dragController.setMoveTarget(workspace);
Jason Samsfd22dac2009-09-20 17:24:16 -0700931
Joe Onorato00acb122009-08-04 16:04:30 -0400932 // The order here is bottom to top.
933 dragController.addDropTarget(workspace);
934 dragController.addDropTarget(deleteZone);
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700935 if (infoButton != null) {
936 dragController.addDropTarget(infoButton);
937 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800938 }
939
Romain Guy8a73c512009-11-09 19:19:59 -0800940 @SuppressWarnings({"UnusedDeclaration"})
941 public void previousScreen(View v) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700942 if (mState != State.ALL_APPS) {
Joe Onorato61597bd2009-11-19 12:51:57 -0800943 mWorkspace.scrollLeft();
944 }
Romain Guy8a73c512009-11-09 19:19:59 -0800945 }
946
947 @SuppressWarnings({"UnusedDeclaration"})
948 public void nextScreen(View v) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700949 if (mState != State.ALL_APPS) {
Joe Onorato61597bd2009-11-19 12:51:57 -0800950 mWorkspace.scrollRight();
951 }
Romain Guy8a73c512009-11-09 19:19:59 -0800952 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400953
954 @SuppressWarnings({"UnusedDeclaration"})
955 public void launchHotSeat(View v) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700956 if (mState == State.ALL_APPS) return;
Daniel Sandler3e9454a2010-05-24 11:22:41 -0400957
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400958 int index = -1;
959 if (v.getId() == R.id.hotseat_left) {
960 index = 0;
961 } else if (v.getId() == R.id.hotseat_right) {
962 index = 1;
963 }
964
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400965 // reload these every tap; you never know when they might change
966 loadHotseats();
967 if (index >= 0 && index < mHotseats.length && mHotseats[index] != null) {
968 Intent intent = mHotseats[index];
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400969 startActivitySafely(
970 mHotseats[index],
971 "hotseat"
972 );
973 }
974 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700975
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800976 /**
977 * Creates a view representing a shortcut.
978 *
979 * @param info The data structure describing the shortcut.
980 *
981 * @return A View inflated from R.layout.application.
982 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800983 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800984 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -0700985 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800986 }
987
988 /**
989 * Creates a view representing a shortcut inflated from the specified resource.
990 *
991 * @param layoutResId The id of the XML layout used to create the shortcut.
992 * @param parent The group the shortcut belongs to.
993 * @param info The data structure describing the shortcut.
994 *
995 * @return A View inflated from layoutResId.
996 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800997 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800998 TextView favorite = (TextView) mInflater.inflate(layoutResId, parent, false);
999
Joe Onorato0589f0f2010-02-08 13:44:00 -08001000 favorite.setCompoundDrawablesWithIntrinsicBounds(null,
1001 new FastBitmapDrawable(info.getIcon(mIconCache)),
1002 null, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001003 favorite.setText(info.title);
1004 favorite.setTag(info);
1005 favorite.setOnClickListener(this);
1006
1007 return favorite;
1008 }
1009
1010 /**
1011 * Add an application shortcut to the workspace.
1012 *
1013 * @param data The intent describing the application.
1014 * @param cellInfo The position on screen where to create the shortcut.
1015 */
Michael Jurka0280c3b2010-09-17 15:00:07 -07001016 void completeAddApplication(Context context, Intent data, int screen,
1017 int intersectCellX, int intersectCellY) {
1018 final int[] cellXY = mTmpAddItemCellCoordinates;
1019 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1020
1021 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1022 showOutOfSpaceMessage();
1023 return;
1024 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001025
Joe Onorato0589f0f2010-02-08 13:44:00 -08001026 final ShortcutInfo info = mModel.getShortcutInfo(context.getPackageManager(),
1027 data, context);
1028
Romain Guy73b979d2009-06-09 12:57:21 -07001029 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -08001030 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001031 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001032 info.container = ItemInfo.NO_ID;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001033 mWorkspace.addApplicationShortcut(info, screen, cellXY[0], cellXY[1],
1034 isWorkspaceLocked(), mAddIntersectCellX, mAddIntersectCellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001035 } else {
1036 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001037 }
1038 }
Romain Guycbb89e42009-06-08 15:52:54 -07001039
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001040 /**
1041 * Add a shortcut to the workspace.
1042 *
1043 * @param data The intent describing the shortcut.
1044 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001045 */
Michael Jurka0280c3b2010-09-17 15:00:07 -07001046 private void completeAddShortcut(Intent data, int screen,
1047 int intersectCellX, int intersectCellY) {
1048 final int[] cellXY = mTmpAddItemCellCoordinates;
1049 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
Romain Guycbb89e42009-06-08 15:52:54 -07001050
Michael Jurka0280c3b2010-09-17 15:00:07 -07001051 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1052 showOutOfSpaceMessage();
1053 return;
1054 }
1055
1056 final ShortcutInfo info = mModel.addShortcut(
1057 this, data, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001058
1059 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001060 final View view = createShortcut(info);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001061 mWorkspace.addInScreen(view, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001062 }
1063 }
1064
Romain Guycbb89e42009-06-08 15:52:54 -07001065
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001066 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001067 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001068 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001069 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001070 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001071 */
Michael Jurka0280c3b2010-09-17 15:00:07 -07001072 private void completeAddAppWidget(int appWidgetId, int screen) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001073 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Romain Guycbb89e42009-06-08 15:52:54 -07001074
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001075 // Calculate the grid spans needed to fit this widget
Michael Jurka0280c3b2010-09-17 15:00:07 -07001076 CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1077 int[] spanXY = layout.rectToCell(appWidgetInfo.minWidth, appWidgetInfo.minHeight, null);
Romain Guycbb89e42009-06-08 15:52:54 -07001078
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001079 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001080 // We have saved the position to which the widget was dragged-- this really only matters
1081 // if we are placing widgets on a "spring-loaded" screen
Michael Jurka0280c3b2010-09-17 15:00:07 -07001082 final int[] cellXY = mTmpAddItemCellCoordinates;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001083
1084 // For now, we don't save the coordinate where we dropped the icon because we're not
1085 // supporting spring-loaded mini-screens; however, leaving the ability to directly place
1086 // a widget on the home screen in case we want to add it in the future
Michael Jurka0280c3b2010-09-17 15:00:07 -07001087 final int[] touchXY = null;
1088 //final int[] touchXY = mAddDropPosition;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001089 boolean findNearestVacantAreaFailed = false;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001090 boolean foundCellSpan = false;
1091 if (touchXY != null) {
1092 // when dragging and dropping, just find the closest free spot
1093 CellLayout screenLayout = (CellLayout) mWorkspace.getChildAt(screen);
1094 int[] result = screenLayout.findNearestVacantArea(
1095 touchXY[0], touchXY[1], spanXY[0], spanXY[1], cellXY);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001096 findNearestVacantAreaFailed = (result == null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001097 foundCellSpan = !findNearestVacantAreaFailed;
1098 } else {
1099 if (mAddIntersectCellX != -1 && mAddIntersectCellY != -1) {
1100 // if we long pressed on an empty cell to bring up a menu,
1101 // make sure we intersect the empty cell
1102 foundCellSpan = layout.findCellForSpanThatIntersects(cellXY, spanXY[0], spanXY[1],
1103 mAddIntersectCellX, mAddIntersectCellY);
1104 } else {
1105 // if we went through the menu -> add, just find any spot
1106 foundCellSpan = layout.findCellForSpan(cellXY, spanXY[0], spanXY[1]);
1107 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001108 }
1109
Michael Jurka0280c3b2010-09-17 15:00:07 -07001110 if (!foundCellSpan) {
Romain Guy18042c82009-11-06 11:44:55 -08001111 if (appWidgetId != -1) mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001112 showOutOfSpaceMessage();
Romain Guy18042c82009-11-06 11:44:55 -08001113 return;
1114 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001115
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001116 // Build Launcher-specific widget info and save to database
1117 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001118 launcherInfo.spanX = spanXY[0];
1119 launcherInfo.spanY = spanXY[1];
Romain Guycbb89e42009-06-08 15:52:54 -07001120
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001121 LauncherModel.addItemToDatabase(this, launcherInfo,
1122 LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001123 screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001124
1125 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001126 mDesktopItems.add(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001127
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001128 // Perform actual inflation because we're live
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001129 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001130
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001131 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001132 launcherInfo.hostView.setTag(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001133
Michael Jurka0280c3b2010-09-17 15:00:07 -07001134 mWorkspace.addInScreen(launcherInfo.hostView, screen, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001135 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001136 }
1137 }
Romain Guycbb89e42009-06-08 15:52:54 -07001138
Michael Jurka0280c3b2010-09-17 15:00:07 -07001139 void showOutOfSpaceMessage() {
1140 Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show();
1141 }
1142
Joe Onorato9c1289c2009-08-17 11:03:03 -04001143 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
1144 mDesktopItems.remove(launcherInfo);
1145 launcherInfo.hostView = null;
1146 }
1147
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001148 public LauncherAppWidgetHost getAppWidgetHost() {
1149 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001150 }
Romain Guycbb89e42009-06-08 15:52:54 -07001151
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001152 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001153 getWindow().closeAllPanels();
1154
1155 try {
1156 dismissDialog(DIALOG_CREATE_SHORTCUT);
1157 // Unlock the workspace if the dialog was showing
1158 } catch (Exception e) {
1159 // An exception is thrown if the dialog is not visible, which is fine
1160 }
1161
1162 try {
1163 dismissDialog(DIALOG_RENAME_FOLDER);
1164 // Unlock the workspace if the dialog was showing
1165 } catch (Exception e) {
1166 // An exception is thrown if the dialog is not visible, which is fine
1167 }
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001168
1169 // Whatever we were doing is hereby canceled.
1170 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001171 }
1172
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001173 @Override
1174 protected void onNewIntent(Intent intent) {
1175 super.onNewIntent(intent);
1176
1177 // Close the menu
1178 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001179 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001180 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001181
Joe Onorato14f122b2009-11-19 14:06:36 -08001182 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1183 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001184
Michael Jurka4cb37242010-08-09 21:05:32 -07001185 // in all these cases, only animate if we're already on home
1186 if (LauncherApplication.isScreenXLarge()) {
Michael Jurka99229f62010-09-09 11:49:32 -07001187 mWorkspace.unshrink(alreadyOnHome);
1188 }
1189 if (!mWorkspace.isDefaultPageShowing()) {
Michael Jurka4cb37242010-08-09 21:05:32 -07001190 // on the phone, we don't animate the change to the workspace if all apps is visible
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001191 mWorkspace.moveToDefaultScreen(alreadyOnHome &&
1192 (LauncherApplication.isScreenXLarge() || mState != State.ALL_APPS));
Joe Onorato3a8820b2009-11-10 15:06:42 -08001193 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001194 showWorkspace(alreadyOnHome);
Romain Guy1dd3a072009-07-16 13:21:01 -07001195
Joe Onorato3a8820b2009-11-10 15:06:42 -08001196 final View v = getWindow().peekDecorView();
1197 if (v != null && v.getWindowToken() != null) {
1198 InputMethodManager imm = (InputMethodManager)getSystemService(
1199 INPUT_METHOD_SERVICE);
1200 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001201 }
1202 }
1203 }
1204
1205 @Override
1206 protected void onRestoreInstanceState(Bundle savedInstanceState) {
1207 // Do not call super here
1208 mSavedInstanceState = savedInstanceState;
Michael Jurka946ad472010-07-09 18:05:18 -07001209
1210 if (mHomeCustomizationDrawer != null) {
1211 String cur = savedInstanceState.getString("currentTab");
1212 if (cur != null) {
1213 mHomeCustomizationDrawer.setCurrentTabByTag(cur);
1214 }
1215 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001216 }
1217
1218 @Override
1219 protected void onSaveInstanceState(Bundle outState) {
Michael Jurka0142d492010-08-25 17:46:15 -07001220 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001221
1222 final ArrayList<Folder> folders = mWorkspace.getOpenFolders();
1223 if (folders.size() > 0) {
1224 final int count = folders.size();
1225 long[] ids = new long[count];
1226 for (int i = 0; i < count; i++) {
1227 final FolderInfo info = folders.get(i).getInfo();
1228 ids[i] = info.id;
1229 }
1230 outState.putLongArray(RUNTIME_STATE_USER_FOLDERS, ids);
1231 } else {
1232 super.onSaveInstanceState(outState);
1233 }
1234
Joe Onoratofb0ca672009-09-14 17:55:46 -04001235 // TODO should not do this if the drawer is currently closing.
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001236 if (mState == State.ALL_APPS) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001237 outState.putBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, true);
Romain Guy5a941392009-04-28 15:18:25 -07001238 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001239
Michael Jurka0280c3b2010-09-17 15:00:07 -07001240 if (mAddScreen > -1 && mWaitingForResult) {
1241 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mAddScreen);
1242 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mAddIntersectCellX);
1243 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001244 }
1245
1246 if (mFolderInfo != null && mWaitingForResult) {
1247 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1248 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1249 }
Michael Jurka946ad472010-07-09 18:05:18 -07001250
1251 if (mHomeCustomizationDrawer != null) {
1252 String currentTabTag = mHomeCustomizationDrawer.getCurrentTabTag();
1253 if (currentTabTag != null) {
1254 outState.putString("currentTab", currentTabTag);
1255 }
1256 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001257 }
1258
1259 @Override
1260 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001261 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001262
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001263 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001264 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001265 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001266 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001267 }
1268
1269 TextKeyListener.getInstance().release();
1270
Joe Onorato9c1289c2009-08-17 11:03:03 -04001271 mModel.stopLoader();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001272
Joe Onorato9c1289c2009-08-17 11:03:03 -04001273 unbindDesktopItems();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001274
1275 getContentResolver().unregisterContentObserver(mWidgetObserver);
Winson Chungaafa03c2010-06-11 17:34:16 -07001276
Patrick Dubroyab962b72010-07-26 12:10:10 -07001277 // Some launcher layouts don't have a previous and next view
1278 if (mPreviousView != null) {
1279 dismissPreview(mPreviousView);
1280 }
1281 if (mNextView != null) {
1282 dismissPreview(mNextView);
1283 }
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001284
1285 unregisterReceiver(mCloseSystemDialogsReceiver);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001286 }
1287
1288 @Override
1289 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001290 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001291 super.startActivityForResult(intent, requestCode);
1292 }
1293
1294 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001295 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001296 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001297
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001298 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001299
Karl Rosaen138a0412009-04-23 19:00:21 -07001300 if (initialQuery == null) {
1301 // Use any text typed in the launcher as the initial query
1302 initialQuery = getTypedText();
1303 clearTypedText();
1304 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001305 if (appSearchData == null) {
1306 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +00001307 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001308 }
Romain Guycbb89e42009-06-08 15:52:54 -07001309
Karl Rosaen138a0412009-04-23 19:00:21 -07001310 final SearchManager searchManager =
1311 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Karl Rosaen138a0412009-04-23 19:00:21 -07001312 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Romain Guycbb89e42009-06-08 15:52:54 -07001313 appSearchData, globalSearch);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001314 }
1315
1316 @Override
1317 public boolean onCreateOptionsMenu(Menu menu) {
Patrick Dubroy5905bca2010-09-08 22:43:38 -07001318 if (isWorkspaceLocked()) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001319 return false;
1320 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001321
1322 super.onCreateOptionsMenu(menu);
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001323
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001324 menu.add(MENU_GROUP_ADD, MENU_ADD, 0, R.string.menu_add)
1325 .setIcon(android.R.drawable.ic_menu_add)
1326 .setAlphabeticShortcut('A');
Winson Chung7ad01412010-09-27 11:33:03 -07001327 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1328 .setIcon(android.R.drawable.ic_menu_manage)
1329 .setAlphabeticShortcut('M');
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001330 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001331 .setIcon(android.R.drawable.ic_menu_gallery)
1332 .setAlphabeticShortcut('W');
1333 menu.add(0, MENU_SEARCH, 0, R.string.menu_search)
1334 .setIcon(android.R.drawable.ic_search_category_default)
1335 .setAlphabeticShortcut(SearchManager.MENU_KEY);
1336 menu.add(0, MENU_NOTIFICATIONS, 0, R.string.menu_notifications)
1337 .setIcon(com.android.internal.R.drawable.ic_menu_notifications)
1338 .setAlphabeticShortcut('N');
1339
1340 final Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
Romain Guy5a941392009-04-28 15:18:25 -07001341 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
1342 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001343
1344 menu.add(0, MENU_SETTINGS, 0, R.string.menu_settings)
1345 .setIcon(android.R.drawable.ic_menu_preferences).setAlphabeticShortcut('P')
1346 .setIntent(settings);
1347
1348 return true;
1349 }
1350
1351 @Override
1352 public boolean onPrepareOptionsMenu(Menu menu) {
1353 super.onPrepareOptionsMenu(menu);
1354
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001355 // If all apps is animating, don't show the menu, because we don't know
1356 // which one to show.
Patrick Dubroyff5f0402010-07-26 15:23:26 -07001357 if (mAllAppsGrid.isAnimating()) {
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001358 return false;
1359 }
1360
1361 // Only show the add and wallpaper options when we're not in all apps.
Patrick Dubroyff5f0402010-07-26 15:23:26 -07001362 boolean visible = !mAllAppsGrid.isVisible();
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001363 menu.setGroupVisible(MENU_GROUP_ADD, visible);
1364 menu.setGroupVisible(MENU_GROUP_WALLPAPER, visible);
1365
1366 // Disable add if the workspace is full.
1367 if (visible) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001368 CellLayout layout = (CellLayout) mWorkspace.getChildAt(mWorkspace.getCurrentPage());
1369 menu.setGroupEnabled(MENU_GROUP_ADD, layout.existsEmptyCell());
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001370 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001371
1372 return true;
1373 }
1374
1375 @Override
1376 public boolean onOptionsItemSelected(MenuItem item) {
1377 switch (item.getItemId()) {
1378 case MENU_ADD:
1379 addItems();
1380 return true;
Winson Chung7ad01412010-09-27 11:33:03 -07001381 case MENU_MANAGE_APPS:
1382 manageApps();
1383 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001384 case MENU_WALLPAPER_SETTINGS:
1385 startWallpaper();
1386 return true;
1387 case MENU_SEARCH:
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001388 onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001389 return true;
1390 case MENU_NOTIFICATIONS:
1391 showNotifications();
1392 return true;
1393 }
1394
1395 return super.onOptionsItemSelected(item);
1396 }
Romain Guycbb89e42009-06-08 15:52:54 -07001397
Karl Rosaen138a0412009-04-23 19:00:21 -07001398 /**
1399 * Indicates that we want global search for this activity by setting the globalSearch
1400 * argument for {@link #startSearch} to true.
1401 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001402
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001403 @Override
1404 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001405 startSearch(null, false, null, true);
Karl Rosaen138a0412009-04-23 19:00:21 -07001406 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001407 }
1408
Joe Onorato9c1289c2009-08-17 11:03:03 -04001409 public boolean isWorkspaceLocked() {
1410 return mWorkspaceLoading || mWaitingForResult;
1411 }
1412
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001413 private void addItems() {
Patrick Dubroy558654c2010-07-23 16:48:11 -07001414 if (LauncherApplication.isScreenXLarge()) {
1415 // Animate the widget chooser up from the bottom of the screen
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001416 if (mState != State.CUSTOMIZE) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07001417 showCustomizationDrawer(true);
Patrick Dubroy558654c2010-07-23 16:48:11 -07001418 }
1419 } else {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001420 showWorkspace(true);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001421 showAddDialog(-1, -1);
Patrick Dubroy558654c2010-07-23 16:48:11 -07001422 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001423 }
1424
Michael Jurka0280c3b2010-09-17 15:00:07 -07001425 private void resetAddInfo() {
1426 mAddScreen = -1;
1427 mAddIntersectCellX = -1;
1428 mAddIntersectCellY = -1;
1429 mAddDropPosition = null;
1430 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001431
Michael Jurka0280c3b2010-09-17 15:00:07 -07001432 void addAppWidgetFromDrop(ComponentName appWidgetProvider, int screen, int[] position) {
1433 resetAddInfo();
1434 mAddScreen = screen;
1435
1436 // only set mAddDropPosition if we dropped on home screen in "spring-loaded" manner
1437 mAddDropPosition = position;
1438
Michael Jurkaaf442092010-06-10 17:01:57 -07001439 int appWidgetId = getAppWidgetHost().allocateAppWidgetId();
1440 AppWidgetManager.getInstance(this).bindAppWidgetId(appWidgetId, appWidgetProvider);
1441 addAppWidgetImpl(appWidgetId);
1442 }
1443
Winson Chung7ad01412010-09-27 11:33:03 -07001444 private void manageApps() {
1445 startActivity(new Intent(android.provider.Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS));
1446 }
1447
Michael Jurkaaf442092010-06-10 17:01:57 -07001448 void addAppWidgetFromPick(Intent data) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001449 // TODO: catch bad widget exception when sent
1450 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurkaaf442092010-06-10 17:01:57 -07001451 // TODO: Is this log message meaningful?
1452 if (LOGD) Log.d(TAG, "dumping extras content=" + data.getExtras());
1453 addAppWidgetImpl(appWidgetId);
1454 }
1455
1456 void addAppWidgetImpl(int appWidgetId) {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001457 AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001458
Bjorn Bringert7984c942009-12-09 15:38:25 +00001459 if (appWidget.configure != null) {
1460 // Launch over to configure widget, if needed
1461 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
1462 intent.setComponent(appWidget.configure);
1463 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
1464
Romain Guy8e633c52010-03-04 12:51:36 -08001465 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001466 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001467 // Otherwise just add it
Michael Jurka0280c3b2010-09-17 15:00:07 -07001468 completeAddAppWidget(appWidgetId, mAddScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001469 }
1470 }
Romain Guycbb89e42009-06-08 15:52:54 -07001471
Michael Jurka0280c3b2010-09-17 15:00:07 -07001472 void processShortcutFromDrop(ComponentName componentName, int screen, int[] position) {
1473 resetAddInfo();
1474 mAddScreen = screen;
1475 mAddDropPosition = position;
1476
1477 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1478 createShortcutIntent.setComponent(componentName);
1479 processShortcut(createShortcutIntent);
1480 }
1481
Joe Onoratodeb98af2010-02-19 14:59:39 -08001482 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001483 // Handle case where user selected "Applications"
1484 String applicationName = getResources().getString(R.string.group_applications);
1485 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001486
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001487 if (applicationName != null && applicationName.equals(shortcutName)) {
1488 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1489 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001490
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001491 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1492 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07001493 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Joe Onorato4a79a042010-09-24 16:17:21 -07001494 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001495 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001496 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001497 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001498 }
1499
Winson Chung24ab2f12010-09-16 14:10:47 -07001500 void processWallpaper(Intent intent) {
1501 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1502 }
1503
Michael Jurka0280c3b2010-09-17 15:00:07 -07001504 void addLiveFolderFromDrop(ComponentName componentName, int screen, int[] position) {
1505 resetAddInfo();
1506 mAddScreen = screen;
1507 mAddDropPosition = position;
1508
1509 Intent createFolderIntent = new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER);
1510 createFolderIntent.setComponent(componentName);
1511
1512 addLiveFolder(createFolderIntent);
1513 }
1514
1515 void addLiveFolder(Intent intent) { // YYY add screen intersect etc. parameters here
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001516 // Handle case where user selected "Folder"
Jeffrey Sharkeyc4bbd0a2009-03-24 22:47:52 -07001517 String folderName = getResources().getString(R.string.group_folder);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001518 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001519
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001520 if (folderName != null && folderName.equals(shortcutName)) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001521 addFolder(mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001522 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001523 startActivityForResultSafely(intent, REQUEST_CREATE_LIVE_FOLDER);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001524 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001525 }
1526
Michael Jurka0280c3b2010-09-17 15:00:07 -07001527 void addFolder(int screen, int intersectCellX, int intersectCellY) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001528 UserFolderInfo folderInfo = new UserFolderInfo();
1529 folderInfo.title = getText(R.string.folder_name);
1530
Michael Jurka0280c3b2010-09-17 15:00:07 -07001531 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1532 final int[] cellXY = mTmpAddItemCellCoordinates;
1533 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1534 showOutOfSpaceMessage();
1535 return;
1536 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001537
1538 // Update the model
Joe Onorato9c1289c2009-08-17 11:03:03 -04001539 LauncherModel.addItemToDatabase(this, folderInfo,
1540 LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001541 screen, cellXY[0], cellXY[1], false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001542 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001543
1544 // Create the view
1545 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07001546 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), folderInfo);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001547 mWorkspace.addInScreen(newFolder, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001548 }
Romain Guycbb89e42009-06-08 15:52:54 -07001549
Joe Onorato9c1289c2009-08-17 11:03:03 -04001550 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001551 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001552 }
1553
Michael Jurka28750fb2010-09-24 17:43:49 -07001554 private void completeAddLiveFolder(
1555 Intent data, int screen, int intersectCellX, int intersectCellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001556 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1557 final int[] cellXY = mTmpAddItemCellCoordinates;
1558 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1559 showOutOfSpaceMessage();
1560 return;
1561 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001562
Michael Jurka0280c3b2010-09-17 15:00:07 -07001563 final LiveFolderInfo info = addLiveFolder(this, data, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001564
1565 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001566 final View view = LiveFolderIcon.fromXml(R.layout.live_folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07001567 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001568 mWorkspace.addInScreen(view, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001569 }
1570 }
1571
1572 static LiveFolderInfo addLiveFolder(Context context, Intent data,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001573 int screen, int cellX, int cellY, boolean notify) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001574
1575 Intent baseIntent = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT);
1576 String name = data.getStringExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME);
1577
1578 Drawable icon = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001579 Intent.ShortcutIconResource iconResource = null;
1580
1581 Parcelable extra = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON);
1582 if (extra != null && extra instanceof Intent.ShortcutIconResource) {
1583 try {
1584 iconResource = (Intent.ShortcutIconResource) extra;
1585 final PackageManager packageManager = context.getPackageManager();
1586 Resources resources = packageManager.getResourcesForApplication(
1587 iconResource.packageName);
1588 final int id = resources.getIdentifier(iconResource.resourceName, null, null);
1589 icon = resources.getDrawable(id);
1590 } catch (Exception e) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001591 Log.w(TAG, "Could not load live folder icon: " + extra);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001592 }
1593 }
1594
1595 if (icon == null) {
1596 icon = context.getResources().getDrawable(R.drawable.ic_launcher_folder);
1597 }
1598
1599 final LiveFolderInfo info = new LiveFolderInfo();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001600 info.icon = Utilities.createIconBitmap(icon, context);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001601 info.title = name;
1602 info.iconResource = iconResource;
1603 info.uri = data.getData();
1604 info.baseIntent = baseIntent;
1605 info.displayMode = data.getIntExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE,
1606 LiveFolders.DISPLAY_MODE_GRID);
1607
1608 LauncherModel.addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001609 screen, cellX, cellY, notify);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001610 sFolders.put(info.id, info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001611
1612 return info;
1613 }
1614
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001615 private void showNotifications() {
1616 final StatusBarManager statusBar = (StatusBarManager) getSystemService(STATUS_BAR_SERVICE);
1617 if (statusBar != null) {
1618 statusBar.expand();
1619 }
1620 }
1621
1622 private void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001623 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001624 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001625 Intent chooser = Intent.createChooser(pickWallpaper,
1626 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001627 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1628 // Removed in Eclair MR1
1629// WallpaperManager wm = (WallpaperManager)
1630// getSystemService(Context.WALLPAPER_SERVICE);
1631// WallpaperInfo wi = wm.getWallpaperInfo();
1632// if (wi != null && wi.getSettingsActivity() != null) {
1633// LabeledIntent li = new LabeledIntent(getPackageName(),
1634// R.string.configure_wallpaper, 0);
1635// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1636// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1637// }
Mike Clerona0618e42009-10-22 13:55:21 -07001638 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001639 }
1640
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001641 /**
1642 * Registers various content observers. The current implementation registers
1643 * only a favorites observer to keep track of the favorites applications.
1644 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001645 private void registerContentObservers() {
1646 ContentResolver resolver = getContentResolver();
1647 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1648 true, mWidgetObserver);
1649 }
1650
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001651 @Override
1652 public boolean dispatchKeyEvent(KeyEvent event) {
1653 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1654 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001655 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001656 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001657 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jason Samseb5615d2009-11-30 11:50:10 -08001658 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
Joe Onoratobe386092009-11-17 17:32:16 -08001659 dumpState();
1660 return true;
1661 }
1662 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001663 }
1664 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1665 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001666 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001667 return true;
1668 }
1669 }
1670
1671 return super.dispatchKeyEvent(event);
1672 }
1673
Joe Onorato88ec0992009-11-19 13:16:06 -08001674 @Override
1675 public void onBackPressed() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001676 if (mState == State.ALL_APPS || mState == State.CUSTOMIZE) {
1677 showWorkspace(true);
Joe Onorato88ec0992009-11-19 13:16:06 -08001678 } else {
1679 closeFolder();
1680 }
Michael Jurkaaf442092010-06-10 17:01:57 -07001681 // Some launcher layouts don't have a previous and next view
1682 if (mPreviousView != null) {
1683 dismissPreview(mPreviousView);
1684 dismissPreview(mNextView);
1685 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001686 }
1687
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001688 private void closeFolder() {
1689 Folder folder = mWorkspace.getOpenFolder();
1690 if (folder != null) {
1691 closeFolder(folder);
1692 }
1693 }
1694
1695 void closeFolder(Folder folder) {
1696 folder.getInfo().opened = false;
1697 ViewGroup parent = (ViewGroup) folder.getParent();
1698 if (parent != null) {
1699 parent.removeView(folder);
Joe Onoratob6341e92009-11-02 10:41:48 -05001700 if (folder instanceof DropTarget) {
1701 // Live folders aren't DropTargets.
1702 mDragController.removeDropTarget((DropTarget)folder);
1703 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001704 }
1705 folder.onClose();
1706 }
1707
1708 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001709 * Re-listen when widgets are reset.
1710 */
1711 private void onAppWidgetReset() {
1712 mAppWidgetHost.startListening();
1713 }
1714
1715 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001716 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1717 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001718 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04001719 private void unbindDesktopItems() {
1720 for (ItemInfo item: mDesktopItems) {
1721 item.unbind();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001722 }
1723 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001724
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001725 /**
1726 * Launches the intent referred by the clicked shortcut.
1727 *
1728 * @param v The view representing the clicked shortcut.
1729 */
1730 public void onClick(View v) {
1731 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001732 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001733 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08001734 final Intent intent = ((ShortcutInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001735 int[] pos = new int[2];
1736 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08001737 intent.setSourceBounds(new Rect(pos[0], pos[1],
1738 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Joe Onoratof984e852010-03-25 09:47:45 -07001739 startActivitySafely(intent, tag);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001740 } else if (tag instanceof FolderInfo) {
1741 handleFolderClick((FolderInfo) tag);
Joe Onorato7404ee42009-07-31 11:54:44 -07001742 } else if (v == mHandleView) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001743 if (mState == State.ALL_APPS) {
1744 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001745 } else {
Joe Onorato3a8820b2009-11-10 15:06:42 -08001746 showAllApps(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001747 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001748 }
1749 }
1750
Michael Jurka0e260592010-06-30 17:07:39 -07001751 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07001752 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001753 // clicking anywhere on the workspace causes the customization drawer to slide down
1754 showWorkspace(true);
Michael Jurka0e260592010-06-30 17:07:39 -07001755 return false;
1756 }
1757
Michael Jurkaaf442092010-06-10 17:01:57 -07001758 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001759 * Event handler for the search button
1760 *
1761 * @param v The view that was clicked.
1762 */
1763 public void onClickSearchButton(View v) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07001764 startSearch(null, false, null, true);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001765 }
1766
1767 /**
1768 * Event handler for the "gear" button that appears on the home screen, which
Michael Jurkaaf442092010-06-10 17:01:57 -07001769 * enters home screen customization mode.
1770 *
1771 * @param v The view that was clicked.
1772 */
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001773 public void onClickConfigureButton(View v) {
Patrick Dubroy558654c2010-07-23 16:48:11 -07001774 addItems();
Michael Jurkaaf442092010-06-10 17:01:57 -07001775 }
1776
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001777 /**
1778 * Event handler for the "grid" button that appears on the home screen, which
1779 * enters all apps mode.
1780 *
1781 * @param v The view that was clicked.
1782 */
1783 public void onClickAllAppsButton(View v) {
1784 showAllApps(true);
1785 }
1786
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001787 public void onClickAppMarketButton(View v) {
1788 if (mAppMarketIntent != null) {
1789 startActivitySafely(mAppMarketIntent, "app market");
1790 }
1791 }
1792
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001793 void startApplicationDetailsActivity(ComponentName componentName) {
1794 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001795 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
1796 Uri.fromParts("package", packageName, null));
1797 startActivity(intent);
1798 }
1799
Patrick Dubroy5539af72010-09-07 15:22:01 -07001800 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
1801 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
1802 // System applications cannot be installed. For now, show a toast explaining that.
1803 // We may give them the option of disabling apps this way.
1804 int messageId = R.string.uninstall_system_app_text;
1805 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
1806 } else {
1807 String packageName = appInfo.componentName.getPackageName();
1808 String className = appInfo.componentName.getClassName();
1809 Intent intent = new Intent(
1810 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
1811 startActivity(intent);
1812 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001813 }
1814
Joe Onoratof984e852010-03-25 09:47:45 -07001815 void startActivitySafely(Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001816 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1817 try {
1818 startActivity(intent);
1819 } catch (ActivityNotFoundException e) {
1820 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Daniel Sandlerc9b18772010-04-22 14:37:59 -04001821 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001822 } catch (SecurityException e) {
1823 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001824 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001825 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07001826 "or use the exported attribute for this activity. "
1827 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001828 }
1829 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001830
Romain Guy8e633c52010-03-04 12:51:36 -08001831 void startActivityForResultSafely(Intent intent, int requestCode) {
1832 try {
1833 startActivityForResult(intent, requestCode);
1834 } catch (ActivityNotFoundException e) {
1835 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1836 } catch (SecurityException e) {
1837 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1838 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
1839 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
1840 "or use the exported attribute for this activity.", e);
1841 }
1842 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001843
1844 private void handleFolderClick(FolderInfo folderInfo) {
1845 if (!folderInfo.opened) {
1846 // Close any open folder
1847 closeFolder();
1848 // Open the requested folder
1849 openFolder(folderInfo);
1850 } else {
1851 // Find the open folder...
1852 Folder openFolder = mWorkspace.getFolderForTag(folderInfo);
1853 int folderScreen;
1854 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07001855 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001856 // .. and close it
1857 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07001858 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001859 // Close any folder open on the current screen
1860 closeFolder();
1861 // Pull the folder onto this screen
1862 openFolder(folderInfo);
1863 }
1864 }
1865 }
1866 }
1867
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001868 /**
1869 * Opens the user fodler described by the specified tag. The opening of the folder
1870 * is animated relative to the specified View. If the View is null, no animation
1871 * is played.
1872 *
1873 * @param folderInfo The FolderInfo describing the folder to open.
1874 */
Winson Chungaafa03c2010-06-11 17:34:16 -07001875 public void openFolder(FolderInfo folderInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001876 Folder openFolder;
1877
1878 if (folderInfo instanceof UserFolderInfo) {
1879 openFolder = UserFolder.fromXml(this);
1880 } else if (folderInfo instanceof LiveFolderInfo) {
Joe Onoratoa5902522009-07-30 13:37:37 -07001881 openFolder = com.android.launcher2.LiveFolder.fromXml(this, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001882 } else {
1883 return;
1884 }
1885
Joe Onorato00acb122009-08-04 16:04:30 -04001886 openFolder.setDragController(mDragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001887 openFolder.setLauncher(this);
1888
1889 openFolder.bind(folderInfo);
1890 folderInfo.opened = true;
1891
Winson Chungaafa03c2010-06-11 17:34:16 -07001892 mWorkspace.addInFullScreen(openFolder, folderInfo.screen);
1893
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001894 openFolder.onOpen();
1895 }
1896
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001897 public boolean onLongClick(View v) {
Romain Guy1fbc1c82009-11-09 20:43:08 -08001898 switch (v.getId()) {
1899 case R.id.previous_screen:
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001900 if (mState != State.ALL_APPS) {
Joe Onorato0d44e942009-11-16 18:20:51 -08001901 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1902 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Romain Guyf8e6a802009-12-07 17:48:02 -08001903 showPreviews(v);
Joe Onorato0d44e942009-11-16 18:20:51 -08001904 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08001905 return true;
1906 case R.id.next_screen:
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001907 if (mState != State.ALL_APPS) {
Joe Onorato0d44e942009-11-16 18:20:51 -08001908 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1909 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Romain Guyf8e6a802009-12-07 17:48:02 -08001910 showPreviews(v);
1911 }
1912 return true;
1913 case R.id.all_apps_button:
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001914 if (mState != State.ALL_APPS) {
Romain Guyf8e6a802009-12-07 17:48:02 -08001915 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1916 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
1917 showPreviews(v);
Joe Onorato0d44e942009-11-16 18:20:51 -08001918 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08001919 return true;
1920 }
1921
Joe Onorato9c1289c2009-08-17 11:03:03 -04001922 if (isWorkspaceLocked()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001923 return false;
1924 }
1925
1926 if (!(v instanceof CellLayout)) {
1927 v = (View) v.getParent();
1928 }
1929
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001930
Michael Jurka0280c3b2010-09-17 15:00:07 -07001931 resetAddInfo();
1932 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001933 // This happens when long clicking an item with the dpad/trackball
Michael Jurka0280c3b2010-09-17 15:00:07 -07001934 if (longClickCellInfo == null || !longClickCellInfo.valid) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001935 return true;
1936 }
1937
Michael Jurka0280c3b2010-09-17 15:00:07 -07001938 final View itemUnderLongClick = longClickCellInfo.cell;
1939
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001940 if (mWorkspace.allowLongPress()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001941 if (itemUnderLongClick == null) {
1942 // User long pressed on empty space
1943 mWorkspace.setAllowLongPress(false);
1944 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1945 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Michael Jurka56170562010-10-05 14:14:56 -07001946 if (!LauncherApplication.isScreenXLarge()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001947 showAddDialog(longClickCellInfo.cellX, longClickCellInfo.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001948 }
1949 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001950 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001951 // User long pressed on an item
Joe Onorato0d44e942009-11-16 18:20:51 -08001952 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1953 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001954 mAddIntersectCellX = longClickCellInfo.cellX;
1955 mAddIntersectCellY = longClickCellInfo.cellY;
1956 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001957 }
1958 }
1959 }
1960 return true;
1961 }
1962
Romain Guye6b8e2f2009-11-10 11:56:55 -08001963 @SuppressWarnings({"unchecked"})
Romain Guy9d31e9f2009-11-11 18:54:28 -08001964 private void dismissPreview(final View v) {
1965 final PopupWindow window = (PopupWindow) v.getTag();
Romain Guy1fbc1c82009-11-09 20:43:08 -08001966 if (window != null) {
Romain Guy9d31e9f2009-11-11 18:54:28 -08001967 window.setOnDismissListener(new PopupWindow.OnDismissListener() {
1968 public void onDismiss() {
1969 ViewGroup group = (ViewGroup) v.getTag(R.id.workspace);
1970 int count = group.getChildCount();
1971 for (int i = 0; i < count; i++) {
1972 ((ImageView) group.getChildAt(i)).setImageDrawable(null);
1973 }
Romain Guy9d31e9f2009-11-11 18:54:28 -08001974 ArrayList<Bitmap> bitmaps = (ArrayList<Bitmap>) v.getTag(R.id.icon);
1975 for (Bitmap bitmap : bitmaps) bitmap.recycle();
1976
1977 v.setTag(R.id.workspace, null);
1978 v.setTag(R.id.icon, null);
1979 window.setOnDismissListener(null);
1980 }
1981 });
Romain Guy1fbc1c82009-11-09 20:43:08 -08001982 window.dismiss();
Romain Guy1fbc1c82009-11-09 20:43:08 -08001983 }
1984 v.setTag(null);
1985 }
1986
Romain Guyf8e6a802009-12-07 17:48:02 -08001987 private void showPreviews(View anchor) {
Romain Guy9d31e9f2009-11-11 18:54:28 -08001988 showPreviews(anchor, 0, mWorkspace.getChildCount());
Romain Guy1fbc1c82009-11-09 20:43:08 -08001989 }
1990
Romain Guya6abce82009-11-10 02:54:41 -08001991 private void showPreviews(final View anchor, int start, int end) {
Romain Guyf8e6a802009-12-07 17:48:02 -08001992 final Resources resources = getResources();
1993 final Workspace workspace = mWorkspace;
Romain Guy1fbc1c82009-11-09 20:43:08 -08001994
Romain Guya6abce82009-11-10 02:54:41 -08001995 CellLayout cell = ((CellLayout) workspace.getChildAt(start));
Winson Chungaafa03c2010-06-11 17:34:16 -07001996
Romain Guy9d31e9f2009-11-11 18:54:28 -08001997 float max = workspace.getChildCount();
Winson Chungaafa03c2010-06-11 17:34:16 -07001998
Romain Guyf8e6a802009-12-07 17:48:02 -08001999 final Rect r = new Rect();
Romain Guy9d31e9f2009-11-11 18:54:28 -08002000 resources.getDrawable(R.drawable.preview_background).getPadding(r);
Romain Guye6b8e2f2009-11-10 11:56:55 -08002001 int extraW = (int) ((r.left + r.right) * max);
2002 int extraH = r.top + r.bottom;
Romain Guya6abce82009-11-10 02:54:41 -08002003
2004 int aW = cell.getWidth() - extraW;
2005 float w = aW / max;
2006
2007 int width = cell.getWidth();
2008 int height = cell.getHeight();
2009 int x = cell.getLeftPadding();
2010 int y = cell.getTopPadding();
2011 width -= (x + cell.getRightPadding());
2012 height -= (y + cell.getBottomPadding());
2013
2014 float scale = w / width;
2015
2016 int count = end - start;
2017
2018 final float sWidth = width * scale;
2019 float sHeight = height * scale;
2020
Romain Guye6b8e2f2009-11-10 11:56:55 -08002021 LinearLayout preview = new LinearLayout(this);
Romain Guya6abce82009-11-10 02:54:41 -08002022
Romain Guye6b8e2f2009-11-10 11:56:55 -08002023 PreviewTouchHandler handler = new PreviewTouchHandler(anchor);
2024 ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>(count);
Romain Guya6abce82009-11-10 02:54:41 -08002025
2026 for (int i = start; i < end; i++) {
Romain Guye6b8e2f2009-11-10 11:56:55 -08002027 ImageView image = new ImageView(this);
Romain Guya6abce82009-11-10 02:54:41 -08002028 cell = (CellLayout) workspace.getChildAt(i);
2029
Romain Guyf8e6a802009-12-07 17:48:02 -08002030 final Bitmap bitmap = Bitmap.createBitmap((int) sWidth, (int) sHeight,
Romain Guye6b8e2f2009-11-10 11:56:55 -08002031 Bitmap.Config.ARGB_8888);
Romain Guyf8e6a802009-12-07 17:48:02 -08002032
2033 final Canvas c = new Canvas(bitmap);
Romain Guya6abce82009-11-10 02:54:41 -08002034 c.scale(scale, scale);
2035 c.translate(-cell.getLeftPadding(), -cell.getTopPadding());
Patrick Dubroy1262e362010-10-06 15:49:50 -07002036 cell.drawChildren(c);
Romain Guya6abce82009-11-10 02:54:41 -08002037
Romain Guy9d31e9f2009-11-11 18:54:28 -08002038 image.setBackgroundDrawable(resources.getDrawable(R.drawable.preview_background));
Romain Guye6b8e2f2009-11-10 11:56:55 -08002039 image.setImageBitmap(bitmap);
2040 image.setTag(i);
2041 image.setOnClickListener(handler);
Romain Guy9d31e9f2009-11-11 18:54:28 -08002042 image.setOnFocusChangeListener(handler);
2043 image.setFocusable(true);
Michael Jurka0142d492010-08-25 17:46:15 -07002044 if (i == mWorkspace.getCurrentPage()) image.requestFocus();
Romain Guye6b8e2f2009-11-10 11:56:55 -08002045
2046 preview.addView(image,
Romain Guy9d31e9f2009-11-11 18:54:28 -08002047 LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
2048
Winson Chungaafa03c2010-06-11 17:34:16 -07002049 bitmaps.add(bitmap);
Romain Guya6abce82009-11-10 02:54:41 -08002050 }
Romain Guyf8e6a802009-12-07 17:48:02 -08002051
2052 final PopupWindow p = new PopupWindow(this);
Romain Guye6b8e2f2009-11-10 11:56:55 -08002053 p.setContentView(preview);
2054 p.setWidth((int) (sWidth * count + extraW));
2055 p.setHeight((int) (sHeight + extraH));
2056 p.setAnimationStyle(R.style.AnimationPreview);
2057 p.setOutsideTouchable(true);
Romain Guy9d31e9f2009-11-11 18:54:28 -08002058 p.setFocusable(true);
Romain Guyff0c2e22009-11-10 12:09:59 -08002059 p.setBackgroundDrawable(new ColorDrawable(0));
Romain Guy9d31e9f2009-11-11 18:54:28 -08002060 p.showAsDropDown(anchor, 0, 0);
Romain Guya6abce82009-11-10 02:54:41 -08002061
Romain Guye6b8e2f2009-11-10 11:56:55 -08002062 p.setOnDismissListener(new PopupWindow.OnDismissListener() {
2063 public void onDismiss() {
2064 dismissPreview(anchor);
2065 }
2066 });
Romain Guy1fbc1c82009-11-09 20:43:08 -08002067
2068 anchor.setTag(p);
2069 anchor.setTag(R.id.workspace, preview);
Winson Chungaafa03c2010-06-11 17:34:16 -07002070 anchor.setTag(R.id.icon, bitmaps);
Romain Guy1fbc1c82009-11-09 20:43:08 -08002071 }
2072
Romain Guy9d31e9f2009-11-11 18:54:28 -08002073 class PreviewTouchHandler implements View.OnClickListener, Runnable, View.OnFocusChangeListener {
Romain Guya6abce82009-11-10 02:54:41 -08002074 private final View mAnchor;
Romain Guya6abce82009-11-10 02:54:41 -08002075
Romain Guye6b8e2f2009-11-10 11:56:55 -08002076 public PreviewTouchHandler(View anchor) {
Romain Guya6abce82009-11-10 02:54:41 -08002077 mAnchor = anchor;
Romain Guya6abce82009-11-10 02:54:41 -08002078 }
2079
2080 public void onClick(View v) {
Michael Jurka0142d492010-08-25 17:46:15 -07002081 mWorkspace.snapToPage((Integer) v.getTag());
Romain Guy9d31e9f2009-11-11 18:54:28 -08002082 v.post(this);
2083 }
2084
2085 public void run() {
Winson Chungaafa03c2010-06-11 17:34:16 -07002086 dismissPreview(mAnchor);
Romain Guy9d31e9f2009-11-11 18:54:28 -08002087 }
2088
2089 public void onFocusChange(View v, boolean hasFocus) {
2090 if (hasFocus) {
Michael Jurka0142d492010-08-25 17:46:15 -07002091 mWorkspace.snapToPage((Integer) v.getTag());
Romain Guy9d31e9f2009-11-11 18:54:28 -08002092 }
Romain Guya6abce82009-11-10 02:54:41 -08002093 }
2094 }
2095
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002096 Workspace getWorkspace() {
2097 return mWorkspace;
2098 }
2099
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002100 @Override
2101 protected Dialog onCreateDialog(int id) {
2102 switch (id) {
2103 case DIALOG_CREATE_SHORTCUT:
2104 return new CreateShortcut().createDialog();
2105 case DIALOG_RENAME_FOLDER:
2106 return new RenameFolder().createDialog();
2107 }
2108
2109 return super.onCreateDialog(id);
2110 }
2111
2112 @Override
2113 protected void onPrepareDialog(int id, Dialog dialog) {
2114 switch (id) {
2115 case DIALOG_CREATE_SHORTCUT:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002116 break;
2117 case DIALOG_RENAME_FOLDER:
Romain Guy7b4ef332009-07-14 13:58:08 -07002118 if (mFolderInfo != null) {
2119 EditText input = (EditText) dialog.findViewById(R.id.folder_name);
2120 final CharSequence text = mFolderInfo.title;
2121 input.setText(text);
2122 input.setSelection(0, text.length());
2123 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002124 break;
2125 }
2126 }
2127
2128 void showRenameDialog(FolderInfo info) {
2129 mFolderInfo = info;
2130 mWaitingForResult = true;
2131 showDialog(DIALOG_RENAME_FOLDER);
2132 }
2133
Michael Jurka0280c3b2010-09-17 15:00:07 -07002134 private void showAddDialog(int intersectX, int intersectY) {
2135 resetAddInfo();
2136 mAddIntersectCellX = intersectX;
2137 mAddIntersectCellY = intersectY;
2138 mAddScreen = mWorkspace.getCurrentPage();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002139 mWaitingForResult = true;
2140 showDialog(DIALOG_CREATE_SHORTCUT);
2141 }
2142
Joe Onoratodeb98af2010-02-19 14:59:39 -08002143 private void pickShortcut() {
Michael Jurka0e260592010-06-30 17:07:39 -07002144 // Insert extra item to handle picking application
Romain Guy73b979d2009-06-09 12:57:21 -07002145 Bundle bundle = new Bundle();
2146
2147 ArrayList<String> shortcutNames = new ArrayList<String>();
2148 shortcutNames.add(getString(R.string.group_applications));
2149 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
2150
2151 ArrayList<ShortcutIconResource> shortcutIcons = new ArrayList<ShortcutIconResource>();
2152 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
2153 R.drawable.ic_launcher_application));
2154 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
2155
2156 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2157 pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_CREATE_SHORTCUT));
Joe Onoratodeb98af2010-02-19 14:59:39 -08002158 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_shortcut));
Romain Guy73b979d2009-06-09 12:57:21 -07002159 pickIntent.putExtras(bundle);
2160
Joe Onoratodeb98af2010-02-19 14:59:39 -08002161 startActivityForResult(pickIntent, REQUEST_PICK_SHORTCUT);
Romain Guy73b979d2009-06-09 12:57:21 -07002162 }
2163
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002164 private class RenameFolder {
2165 private EditText mInput;
2166
2167 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002168 final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null);
2169 mInput = (EditText) layout.findViewById(R.id.folder_name);
2170
2171 AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
2172 builder.setIcon(0);
2173 builder.setTitle(getString(R.string.rename_folder_title));
2174 builder.setCancelable(true);
2175 builder.setOnCancelListener(new Dialog.OnCancelListener() {
2176 public void onCancel(DialogInterface dialog) {
2177 cleanup();
2178 }
2179 });
2180 builder.setNegativeButton(getString(R.string.cancel_action),
2181 new Dialog.OnClickListener() {
2182 public void onClick(DialogInterface dialog, int which) {
2183 cleanup();
2184 }
2185 }
2186 );
2187 builder.setPositiveButton(getString(R.string.rename_action),
2188 new Dialog.OnClickListener() {
2189 public void onClick(DialogInterface dialog, int which) {
2190 changeFolderName();
2191 }
2192 }
2193 );
2194 builder.setView(layout);
Romain Guy7b4ef332009-07-14 13:58:08 -07002195
2196 final AlertDialog dialog = builder.create();
2197 dialog.setOnShowListener(new DialogInterface.OnShowListener() {
2198 public void onShow(DialogInterface dialog) {
Joe Onorato7018d8e2010-04-13 20:25:47 -07002199 mWaitingForResult = true;
Joe Onoratod753b422009-11-08 13:31:11 -05002200 mInput.requestFocus();
2201 InputMethodManager inputManager = (InputMethodManager)
2202 getSystemService(Context.INPUT_METHOD_SERVICE);
2203 inputManager.showSoftInput(mInput, 0);
Romain Guy7b4ef332009-07-14 13:58:08 -07002204 }
2205 });
2206
2207 return dialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002208 }
2209
2210 private void changeFolderName() {
2211 final String name = mInput.getText().toString();
2212 if (!TextUtils.isEmpty(name)) {
2213 // Make sure we have the right folder info
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002214 mFolderInfo = sFolders.get(mFolderInfo.id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002215 mFolderInfo.title = name;
2216 LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo);
2217
Joe Onorato9c1289c2009-08-17 11:03:03 -04002218 if (mWorkspaceLoading) {
Joe Onorato7c312c12009-08-13 21:36:53 -07002219 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002220 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002221 } else {
2222 final FolderIcon folderIcon = (FolderIcon)
2223 mWorkspace.getViewForTag(mFolderInfo);
2224 if (folderIcon != null) {
2225 folderIcon.setText(name);
2226 getWorkspace().requestLayout();
2227 } else {
Joe Onorato7c312c12009-08-13 21:36:53 -07002228 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002229 mWorkspaceLoading = true;
2230 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002231 }
2232 }
2233 }
2234 cleanup();
2235 }
2236
2237 private void cleanup() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002238 dismissDialog(DIALOG_RENAME_FOLDER);
2239 mWaitingForResult = false;
2240 mFolderInfo = null;
2241 }
2242 }
2243
Daniel Sandler843e8602010-06-07 14:59:01 -04002244 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
2245 public boolean isAllAppsVisible() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002246 return mState == State.ALL_APPS;
Joe Onoratofb0ca672009-09-14 17:55:46 -04002247 }
2248
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002249 // AllAppsView.Watcher
2250 public void zoomed(float zoom) {
Michael Jurka213d9632010-07-28 11:29:25 -07002251 // In XLarge view, we zoom down the workspace below all apps so it's still visible
2252 if (zoom == 1.0f && !LauncherApplication.isScreenXLarge()) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002253 mWorkspace.setVisibility(View.GONE);
2254 }
2255 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002256
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002257 private void showToolbarButton(View button) {
2258 button.setAlpha(1.0f);
2259 button.setVisibility(View.VISIBLE);
2260 button.setFocusable(true);
2261 button.setClickable(true);
2262 }
2263
2264 private void hideToolbarButton(View button) {
2265 button.setAlpha(0.0f);
2266 // We can't set it to GONE, otherwise the RelativeLayout gets screwed up
2267 button.setVisibility(View.INVISIBLE);
2268 button.setFocusable(false);
2269 button.setClickable(false);
2270 }
2271
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002272 /**
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002273 * Helper function for showing or hiding a toolbar button, possibly animated.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002274 *
2275 * @param show If true, create an animation to the show the item. Otherwise, hide it.
2276 * @param view The toolbar button to be animated
Chet Haaseb1254a62010-09-07 13:35:00 -07002277 * @param seq A AnimatorSet that will be used to animate the transition. If null, the
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002278 * transition will not be animated.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002279 */
Chet Haaseb1254a62010-09-07 13:35:00 -07002280 private void hideOrShowToolbarButton(boolean show, final View view, AnimatorSet seq) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002281 final boolean showing = show;
2282 final boolean hiding = !show;
2283
2284 final int duration = show ?
2285 getResources().getInteger(R.integer.config_toolbarButtonFadeInTime) :
2286 getResources().getInteger(R.integer.config_toolbarButtonFadeOutTime);
2287
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002288 if (seq != null) {
Chet Haase472b2812010-10-14 07:02:04 -07002289 Animator anim = ObjectAnimator.ofFloat(view, "alpha", show ? 1.0f : 0.0f);
2290 anim.setDuration(duration);
Chet Haaseb1254a62010-09-07 13:35:00 -07002291 anim.addListener(new AnimatorListenerAdapter() {
2292 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002293 if (showing) showToolbarButton(view);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002294 }
Chet Haaseb1254a62010-09-07 13:35:00 -07002295 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002296 if (hiding) hideToolbarButton(view);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002297 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002298 });
2299 seq.play(anim);
2300 } else {
2301 if (showing) {
2302 showToolbarButton(view);
2303 } else {
2304 hideToolbarButton(view);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002305 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002306 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002307 }
2308
2309 /**
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002310 * Show/hide the appropriate toolbar buttons for newState.
2311 * If showSeq or hideSeq is null, the transition will be done immediately (not animated).
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002312 *
2313 * @param newState The state that is being switched to
Chet Haaseb1254a62010-09-07 13:35:00 -07002314 * @param showSeq AnimatorSet in which to put "show" animations, or null.
2315 * @param hideSeq AnimatorSet in which to put "hide" animations, or null.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002316 */
Chet Haaseb1254a62010-09-07 13:35:00 -07002317 private void hideAndShowToolbarButtons(State newState, AnimatorSet showSeq, AnimatorSet hideSeq) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002318 final View searchButton = findViewById(R.id.search_button);
2319 final View allAppsButton = findViewById(R.id.all_apps_button);
2320 final View marketButton = findViewById(R.id.market_button);
2321 final View configureButton = findViewById(R.id.configure_button);
2322
2323 switch (newState) {
2324 case WORKSPACE:
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002325 hideOrShowToolbarButton(true, searchButton, showSeq);
2326 hideOrShowToolbarButton(true, allAppsButton, showSeq);
2327 hideOrShowToolbarButton(true, configureButton, showSeq);
2328 hideOrShowToolbarButton(false, marketButton, hideSeq);
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002329 mDeleteZone.setHandle(allAppsButton);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002330 break;
2331 case ALL_APPS:
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002332 hideOrShowToolbarButton(true, configureButton, showSeq);
2333 hideOrShowToolbarButton(true, marketButton, showSeq);
2334 hideOrShowToolbarButton(false, searchButton, hideSeq);
2335 hideOrShowToolbarButton(false, allAppsButton, hideSeq);
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002336 mDeleteZone.setHandle(marketButton);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002337 break;
2338 case CUSTOMIZE:
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002339 hideOrShowToolbarButton(true, allAppsButton, showSeq);
2340 hideOrShowToolbarButton(false, searchButton, hideSeq);
2341 hideOrShowToolbarButton(false, marketButton, hideSeq);
2342 hideOrShowToolbarButton(false, configureButton, hideSeq);
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002343 mDeleteZone.setHandle(allAppsButton);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002344 break;
2345 }
2346 }
2347
2348 /**
2349 * Helper method for the cameraZoomIn/cameraZoomOut animations
2350 * @param view The view being animated
2351 * @param state The state that we are moving in or out of -- either ALL_APPS or CUSTOMIZE
2352 * @param scaleFactor The scale factor used for the zoom
2353 */
2354 private void setPivotsForZoom(View view, State state, float scaleFactor) {
2355 final int height = view.getHeight();
2356 view.setPivotX(view.getWidth() / 2.0f);
2357 // Set pivotY so that at the starting zoom factor, the view is off-screen by a small margin
2358 // Assumes that the view is normally anchored to either the top or bottom of the screen
2359 final int margin = getResources().getInteger(R.integer.config_allAppsVerticalOffset);
2360 if (state == State.ALL_APPS) {
2361 view.setPivotY(height + ((view.getTop() + height) / scaleFactor) + margin);
2362 } else {
2363 view.setPivotY(0.0f - (view.getTop() / scaleFactor) - margin);
2364 }
2365 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002366
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002367 /**
2368 * Zoom the camera out from the workspace to reveal 'toView'.
2369 * Assumes that the view to show is anchored at either the very top or very bottom
2370 * of the screen.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002371 * @param toState The state to zoom out to. Must be ALL_APPS or CUSTOMIZE.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002372 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002373 private void cameraZoomOut(State toState, boolean animated) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002374 final Resources res = getResources();
2375 final int duration = res.getInteger(R.integer.config_allAppsZoomInTime);
2376 final float scale = (float) res.getInteger(R.integer.config_allAppsZoomScaleFactor);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002377 final boolean toAllApps = (toState == State.ALL_APPS);
2378 final View toView = toAllApps ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
Patrick Dubroy558654c2010-07-23 16:48:11 -07002379
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002380 setPivotsForZoom(toView, toState, scale);
2381
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002382 if (toState == State.ALL_APPS) {
2383 mWorkspace.shrinkToBottom(animated);
2384 } else {
2385 mWorkspace.shrinkToTop(animated);
2386 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002387
2388 if (animated) {
Chet Haase472b2812010-10-14 07:02:04 -07002389 ValueAnimator scaleAnim = ObjectAnimator.ofPropertyValuesHolder(toView,
2390 PropertyValuesHolder.ofFloat("scaleX", scale, 1.0f),
2391 PropertyValuesHolder.ofFloat("scaleY", scale, 1.0f));
2392 scaleAnim.setDuration(duration);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002393 scaleAnim.setInterpolator(new DecelerateInterpolator());
Chet Haaseb1254a62010-09-07 13:35:00 -07002394 scaleAnim.addListener(new AnimatorListenerAdapter() {
2395 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002396 // Prepare the position
2397 toView.setTranslationX(0.0f);
2398 toView.setTranslationY(0.0f);
2399 toView.setVisibility(View.VISIBLE);
2400 }
2401 });
2402
Chet Haaseb1254a62010-09-07 13:35:00 -07002403 AnimatorSet toolbarHideAnim = new AnimatorSet();
2404 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002405 hideAndShowToolbarButtons(toState, toolbarShowAnim, toolbarHideAnim);
2406
2407 // toView should appear right at the end of the workspace shrink animation
2408 final int startDelay = res.getInteger(R.integer.config_workspaceShrinkTime) - duration;
2409
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002410 if (mStateAnimation != null) mStateAnimation.cancel();
2411 mStateAnimation = new AnimatorSet();
2412 mStateAnimation.playTogether(scaleAnim, toolbarHideAnim);
2413 mStateAnimation.play(scaleAnim).after(startDelay);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002414
2415 // Show the new toolbar buttons just as the main animation is ending
2416 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002417 mStateAnimation.play(toolbarShowAnim).after(duration + startDelay - fadeInTime);
2418 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002419 } else {
2420 toView.setTranslationX(0.0f);
2421 toView.setTranslationY(0.0f);
2422 toView.setScaleX(1.0f);
2423 toView.setScaleY(1.0f);
2424 toView.setVisibility(View.VISIBLE);
2425 hideAndShowToolbarButtons(toState, null, null);
2426 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002427 }
2428
2429 /**
2430 * Zoom the camera back into the workspace, hiding 'fromView'.
2431 * This is the opposite of cameraZoomOut.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002432 * @param fromState The current state (must be ALL_APPS or CUSTOMIZE).
2433 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002434 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002435 private void cameraZoomIn(State fromState, boolean animated) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002436 Resources res = getResources();
2437 int duration = res.getInteger(R.integer.config_allAppsZoomOutTime);
2438 float scaleFactor = (float) res.getInteger(R.integer.config_allAppsZoomScaleFactor);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002439 final View fromView =
2440 (fromState == State.ALL_APPS) ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
2441
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002442 mCustomizePagedView.endChoiceMode();
2443 mAllAppsPagedView.endChoiceMode();
2444
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002445 setPivotsForZoom(fromView, fromState, scaleFactor);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002446
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002447 mWorkspace.unshrink(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002448
2449 if (animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002450 if (mStateAnimation != null) mStateAnimation.cancel();
2451 mStateAnimation = new AnimatorSet();
Chet Haase472b2812010-10-14 07:02:04 -07002452 ValueAnimator scaleAnim = ObjectAnimator.ofPropertyValuesHolder(fromView,
2453 PropertyValuesHolder.ofFloat("scaleX", scaleFactor),
2454 PropertyValuesHolder.ofFloat("scaleY", scaleFactor));
2455 scaleAnim.setDuration(duration);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002456 scaleAnim.setInterpolator(new AccelerateInterpolator());
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002457 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Chet Haaseb1254a62010-09-07 13:35:00 -07002458 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002459 fromView.setVisibility(View.GONE);
2460 fromView.setScaleX(1.0f);
2461 fromView.setScaleY(1.0f);
2462 }
2463 });
2464
Chet Haaseb1254a62010-09-07 13:35:00 -07002465 AnimatorSet toolbarHideAnim = new AnimatorSet();
2466 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002467 hideAndShowToolbarButtons(State.WORKSPACE, toolbarShowAnim, toolbarHideAnim);
2468
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002469 mStateAnimation.playTogether(scaleAnim, toolbarHideAnim);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002470
2471 // Show the new toolbar buttons at the very end of the whole animation
2472 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
2473 final int unshrinkTime = res.getInteger(R.integer.config_workspaceUnshrinkTime);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002474 mStateAnimation.play(toolbarShowAnim).after(unshrinkTime - fadeInTime);
2475 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002476 } else {
2477 fromView.setVisibility(View.GONE);
2478 hideAndShowToolbarButtons(State.WORKSPACE, null, null);
2479 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002480 }
2481
2482 /**
2483 * Pan the camera in the vertical plane between 'fromView' and 'toView'.
2484 * This is the transition used on xlarge screens to go between all apps and
2485 * the home customization drawer.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002486 * @param fromState The view to pan away from. Must be ALL_APPS or CUSTOMIZE.
2487 * @param toState The view to pan into the frame. Must be ALL_APPS or CUSTOMIZE.
2488 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002489 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002490 private void cameraPan(State fromState, State toState, boolean animated) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002491 final Resources res = getResources();
2492 final int duration = res.getInteger(R.integer.config_allAppsCameraPanTime);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002493 final int workspaceHeight = mWorkspace.getHeight();
2494
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002495 final boolean fromAllApps = (fromState == State.ALL_APPS);
2496 final View fromView = fromAllApps ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
2497 final View toView = fromAllApps ? mHomeCustomizationDrawer : (View) mAllAppsGrid;
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002498
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002499 final float fromViewStartY = fromAllApps ? 0.0f : fromView.getY();
2500 final float fromViewEndY = fromAllApps ? -fromView.getHeight() * 2 : workspaceHeight * 2;
2501 final float toViewStartY = fromAllApps ? workspaceHeight * 2 : -toView.getHeight() * 2;
2502 final float toViewEndY = fromAllApps ? workspaceHeight - toView.getHeight() : 0.0f;
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002503
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002504 mCustomizePagedView.endChoiceMode();
2505 mAllAppsPagedView.endChoiceMode();
2506
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002507 if (toState == State.ALL_APPS) {
2508 mWorkspace.shrinkToBottom(animated);
2509 } else {
2510 mWorkspace.shrinkToTop(animated);
2511 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002512
2513 if (animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002514 if (mStateAnimation != null) mStateAnimation.cancel();
2515 mStateAnimation = new AnimatorSet();
2516 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Chet Haaseb1254a62010-09-07 13:35:00 -07002517 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002518 toView.setVisibility(View.VISIBLE);
2519 toView.setY(toViewStartY);
2520 }
Chet Haaseb1254a62010-09-07 13:35:00 -07002521 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002522 fromView.setVisibility(View.GONE);
2523 }
2524 });
2525
Chet Haaseb1254a62010-09-07 13:35:00 -07002526 AnimatorSet toolbarHideAnim = new AnimatorSet();
2527 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002528 hideAndShowToolbarButtons(toState, toolbarShowAnim, toolbarHideAnim);
2529
Chet Haase472b2812010-10-14 07:02:04 -07002530 ObjectAnimator fromAnim = ObjectAnimator.ofFloat(fromView, "y",
2531 fromViewStartY, fromViewEndY);
2532 fromAnim.setDuration(duration);
2533 ObjectAnimator toAnim = ObjectAnimator.ofFloat(toView, "y",
2534 toViewStartY, toViewEndY);
2535 fromAnim.setDuration(duration);
2536 mStateAnimation.playTogether(toolbarHideAnim, fromAnim, toAnim);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002537
2538 // Show the new toolbar buttons just as the main animation is ending
2539 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002540 mStateAnimation.play(toolbarShowAnim).after(duration - fadeInTime);
2541 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002542 } else {
2543 fromView.setY(fromViewEndY);
2544 fromView.setVisibility(View.GONE);
2545 toView.setY(toViewEndY);
2546 toView.setVisibility(View.VISIBLE);
2547 hideAndShowToolbarButtons(toState, null, null);
2548 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002549 }
2550
2551 void showAllApps(boolean animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002552 if (mState == State.ALL_APPS)
Winson Chung80baf5a2010-08-09 16:03:15 -07002553 return;
2554
Michael Jurka79212d82010-07-30 16:36:20 -07002555 if (LauncherApplication.isScreenXLarge()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002556 if (mState == State.CUSTOMIZE) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002557 cameraPan(State.CUSTOMIZE, State.ALL_APPS, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002558 } else {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002559 cameraZoomOut(State.ALL_APPS, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002560 }
Patrick Dubroy558654c2010-07-23 16:48:11 -07002561 } else {
2562 mAllAppsGrid.zoom(1.0f, animated);
2563 }
Joe Onorato3a8820b2009-11-10 15:06:42 -08002564
Romain Guyc16fea72010-03-12 17:17:56 -08002565 ((View) mAllAppsGrid).setFocusable(true);
2566 ((View) mAllAppsGrid).requestFocus();
Winson Chungaafa03c2010-06-11 17:34:16 -07002567
Joe Onorato7c312c12009-08-13 21:36:53 -07002568 // TODO: fade these two too
2569 mDeleteZone.setVisibility(View.GONE);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002570 // Change the state *after* we've called all the transition code
2571 mState = State.ALL_APPS;
2572 }
2573
2574
2575 void showWorkspace(boolean animated) {
2576 showWorkspace(animated, null);
2577 }
2578
2579 void showWorkspace(boolean animated, CellLayout layout) {
2580 if (layout != null && animated) {
2581 mWorkspace.unshrink(layout);
2582 } else {
2583 mWorkspace.unshrink(animated);
2584 }
2585 if (mState == State.ALL_APPS) {
2586 closeAllApps(animated);
2587 } else if (mState == State.CUSTOMIZE) {
2588 hideCustomizationDrawer(animated);
2589 }
2590 // Change the state *after* we've called all the transition code
2591 mState = State.WORKSPACE;
Joe Onorato00acb122009-08-04 16:04:30 -04002592 }
2593
Joe Onoratob2061212009-11-24 16:13:54 -05002594 /**
Joe Onorato7e4ed992009-12-03 13:10:49 -08002595 * Things to test when changing this code.
Joe Onoratob2061212009-11-24 16:13:54 -05002596 * - Home from workspace
2597 * - from center screen
2598 * - from other screens
2599 * - Home from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002600 * - from center screen
2601 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002602 * - Back from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002603 * - from center screen
2604 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002605 * - Launch app from workspace and quit
2606 * - with back
2607 * - with home
2608 * - Launch app from all apps and quit
2609 * - with back
2610 * - with home
Joe Onorato7e4ed992009-12-03 13:10:49 -08002611 * - Go to a screen that's not the default, then all
2612 * apps, and launch and app, and go back
2613 * - with back
2614 * -with home
Joe Onoratob2061212009-11-24 16:13:54 -05002615 * - On workspace, long press power and go back
2616 * - with back
2617 * - with home
2618 * - On all apps, long press power and go back
2619 * - with back
2620 * - with home
2621 * - On workspace, power off
2622 * - On all apps, power off
Joe Onorato7e4ed992009-12-03 13:10:49 -08002623 * - Launch an app and turn off the screen while in that app
2624 * - Go back with home key
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002625 * - Go back with back key TODO: make this not go to workspace
Joe Onorato7e4ed992009-12-03 13:10:49 -08002626 * - From all apps
2627 * - From workspace
Joe Onoratoeffc4a82010-04-15 11:48:13 -07002628 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2629 * - From all apps
2630 * - From the center workspace
2631 * - From another workspace
Joe Onoratob2061212009-11-24 16:13:54 -05002632 */
Joe Onorato7bb17492009-09-24 17:51:01 -07002633 void closeAllApps(boolean animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002634 if (mState == State.ALL_APPS) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002635 mWorkspace.setVisibility(View.VISIBLE);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002636 if (LauncherApplication.isScreenXLarge()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002637 cameraZoomIn(State.ALL_APPS, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002638 } else {
2639 mAllAppsGrid.zoom(0.0f, animated);
2640 }
Daniel Sandler388f6792010-03-02 14:08:08 -05002641 ((View)mAllAppsGrid).setFocusable(false);
Michael Jurka0142d492010-08-25 17:46:15 -07002642 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onoratoe77c08d2009-08-01 00:01:20 -07002643 }
Joe Onorato7404ee42009-07-31 11:54:44 -07002644 }
2645
Joe Onorato7c312c12009-08-13 21:36:53 -07002646 void lockAllApps() {
2647 // TODO
2648 }
2649
2650 void unlockAllApps() {
2651 // TODO
2652 }
2653
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002654 // Show the customization drawer (only exists in x-large configuration)
2655 private void showCustomizationDrawer(boolean animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002656 if (mState == State.ALL_APPS) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002657 cameraPan(State.ALL_APPS, State.CUSTOMIZE, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002658 } else {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002659 cameraZoomOut(State.CUSTOMIZE, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002660 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002661 // Change the state *after* we've called all the transition code
2662 mState = State.CUSTOMIZE;
Patrick Dubroy558654c2010-07-23 16:48:11 -07002663 }
2664
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002665 // Hide the customization drawer (only exists in x-large configuration)
2666 void hideCustomizationDrawer(boolean animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002667 if (mState == State.CUSTOMIZE) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002668 cameraZoomIn(State.CUSTOMIZE, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002669 }
2670 }
2671
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002672 void addExternalItemToScreen(ItemInfo itemInfo, CellLayout layout) {
2673 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
2674 showOutOfSpaceMessage();
Michael Jurka213d9632010-07-28 11:29:25 -07002675 }
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002676 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002677
Michael Jurka6b4b25d2010-10-20 18:19:45 -07002678 void onWorkspaceClick(CellLayout layout) {
2679 showWorkspace(true, layout);
Michael Jurka213d9632010-07-28 11:29:25 -07002680 }
2681
Michael Jurka0423dcf2010-10-05 14:56:18 -07002682 private void updateButtonWithIconFromExternalActivity(
2683 int buttonId, ComponentName activityName, int fallbackDrawableId) {
2684 ImageView button = (ImageView) findViewById(buttonId);
2685 Drawable toolbarIcon = null;
2686 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002687 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07002688 // Look for the toolbar icon specified in the activity meta-data
2689 Bundle metaData = packageManager.getActivityInfo(
2690 activityName, PackageManager.GET_META_DATA).metaData;
2691 if (metaData != null) {
2692 int iconResId = metaData.getInt(TOOLBAR_ICON_METADATA_NAME);
2693 if (iconResId != 0) {
2694 Resources res = packageManager.getResourcesForActivity(activityName);
2695 toolbarIcon = res.getDrawable(iconResId);
2696 }
2697 }
2698 } catch (NameNotFoundException e) {
2699 // Do nothing
2700 }
2701 // If we were unable to find the icon via the meta-data, use a generic one
2702 if (toolbarIcon == null) {
2703 button.setImageResource(fallbackDrawableId);
2704 } else {
2705 button.setImageDrawable(toolbarIcon);
2706 }
2707 }
2708
2709 private void updateGlobalSearchIcon() {
2710 if (LauncherApplication.isScreenXLarge()) {
2711 final SearchManager searchManager =
2712 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2713 ComponentName activityName = searchManager.getGlobalSearchActivity();
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002714 if (activityName != null) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07002715 updateButtonWithIconFromExternalActivity(
2716 R.id.search_button, activityName, R.drawable.search_button_generic);
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002717 }
2718 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002719 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002720
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002721 /**
2722 * Sets the app market icon (shown when all apps is visible on x-large screens)
2723 */
2724 private void updateAppMarketIcon() {
Michael Jurka0423dcf2010-10-05 14:56:18 -07002725 if (LauncherApplication.isScreenXLarge()) {
2726 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
2727 // Find the app market activity by resolving an intent.
2728 // (If multiple app markets are installed, it will return the ResolverActivity.)
2729 ComponentName activityName = intent.resolveActivity(getPackageManager());
2730 if (activityName != null) {
2731 mAppMarketIntent = intent;
2732 updateButtonWithIconFromExternalActivity(
2733 R.id.market_button, activityName, R.drawable.app_market_generic);
2734 }
2735 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002736 }
2737
2738 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002739 * Displays the shortcut creation dialog and launches, if necessary, the
2740 * appropriate activity.
2741 */
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002742 private class CreateShortcut implements DialogInterface.OnClickListener,
Romain Guy7b4ef332009-07-14 13:58:08 -07002743 DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
2744 DialogInterface.OnShowListener {
2745
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002746 private AddAdapter mAdapter;
Romain Guy9ffb5432009-03-24 21:04:15 -07002747
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002748 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002749 mAdapter = new AddAdapter(Launcher.this);
Romain Guycbb89e42009-06-08 15:52:54 -07002750
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002751 final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
2752 builder.setTitle(getString(R.string.menu_item_add_item));
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002753 builder.setAdapter(mAdapter, this);
Romain Guycbb89e42009-06-08 15:52:54 -07002754
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002755 builder.setInverseBackgroundForced(true);
2756
2757 AlertDialog dialog = builder.create();
2758 dialog.setOnCancelListener(this);
Romain Guycbb89e42009-06-08 15:52:54 -07002759 dialog.setOnDismissListener(this);
Romain Guy7b4ef332009-07-14 13:58:08 -07002760 dialog.setOnShowListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002761
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002762 return dialog;
2763 }
2764
2765 public void onCancel(DialogInterface dialog) {
2766 mWaitingForResult = false;
2767 cleanup();
2768 }
2769
Romain Guycbb89e42009-06-08 15:52:54 -07002770 public void onDismiss(DialogInterface dialog) {
Romain Guycbb89e42009-06-08 15:52:54 -07002771 }
2772
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002773 private void cleanup() {
Joe Onoratocc19a532009-11-19 14:19:17 -08002774 try {
2775 dismissDialog(DIALOG_CREATE_SHORTCUT);
2776 } catch (Exception e) {
2777 // An exception is thrown if the dialog is not visible, which is fine
2778 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002779 }
2780
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002781 /**
2782 * Handle the action clicked in the "Add to home" dialog.
2783 */
2784 public void onClick(DialogInterface dialog, int which) {
2785 Resources res = getResources();
2786 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002787
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002788 switch (which) {
2789 case AddAdapter.ITEM_SHORTCUT: {
Joe Onoratodeb98af2010-02-19 14:59:39 -08002790 pickShortcut();
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002791 break;
2792 }
Romain Guycbb89e42009-06-08 15:52:54 -07002793
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002794 case AddAdapter.ITEM_APPWIDGET: {
2795 int appWidgetId = Launcher.this.mAppWidgetHost.allocateAppWidgetId();
Romain Guycbb89e42009-06-08 15:52:54 -07002796
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002797 Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
2798 pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002799 // start the pick activity
2800 startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET);
2801 break;
2802 }
Romain Guycbb89e42009-06-08 15:52:54 -07002803
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002804 case AddAdapter.ITEM_LIVE_FOLDER: {
2805 // Insert extra item to handle inserting folder
2806 Bundle bundle = new Bundle();
Romain Guycbb89e42009-06-08 15:52:54 -07002807
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002808 ArrayList<String> shortcutNames = new ArrayList<String>();
2809 shortcutNames.add(res.getString(R.string.group_folder));
2810 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
Romain Guycbb89e42009-06-08 15:52:54 -07002811
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002812 ArrayList<ShortcutIconResource> shortcutIcons =
2813 new ArrayList<ShortcutIconResource>();
2814 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
2815 R.drawable.ic_launcher_folder));
2816 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
2817
2818 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2819 pickIntent.putExtra(Intent.EXTRA_INTENT,
2820 new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER));
2821 pickIntent.putExtra(Intent.EXTRA_TITLE,
2822 getText(R.string.title_select_live_folder));
2823 pickIntent.putExtras(bundle);
Romain Guycbb89e42009-06-08 15:52:54 -07002824
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002825 startActivityForResult(pickIntent, REQUEST_PICK_LIVE_FOLDER);
2826 break;
2827 }
2828
2829 case AddAdapter.ITEM_WALLPAPER: {
2830 startWallpaper();
2831 break;
2832 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002833 }
2834 }
Romain Guy7b4ef332009-07-14 13:58:08 -07002835
2836 public void onShow(DialogInterface dialog) {
Winson Chungaafa03c2010-06-11 17:34:16 -07002837 mWaitingForResult = true;
Romain Guy7b4ef332009-07-14 13:58:08 -07002838 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002839 }
2840
2841 /**
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002842 * Receives notifications when applications are added/removed.
2843 */
2844 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
2845 @Override
2846 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002847 closeSystemDialogs();
Joe Onoratob2061212009-11-24 16:13:54 -05002848 String reason = intent.getStringExtra("reason");
2849 if (!"homekey".equals(reason)) {
2850 boolean animate = true;
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002851 if (mPaused || "lock".equals(reason)) {
Joe Onoratob2061212009-11-24 16:13:54 -05002852 animate = false;
2853 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002854 showWorkspace(animate);
Joe Onoratob2061212009-11-24 16:13:54 -05002855 }
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002856 }
2857 }
2858
2859 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002860 * Receives notifications whenever the appwidgets are reset.
2861 */
2862 private class AppWidgetResetObserver extends ContentObserver {
2863 public AppWidgetResetObserver() {
2864 super(new Handler());
2865 }
2866
2867 @Override
2868 public void onChange(boolean selfChange) {
2869 onAppWidgetReset();
2870 }
2871 }
2872
2873 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002874 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002875 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002876 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07002877 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002878 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07002879 } else {
2880 return SCREEN_COUNT / 2;
2881 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002882 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002883
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002884 void setAllAppsPagedView(PagedView view) {
2885 mAllAppsPagedView = view;
2886 }
2887
Joe Onorato9c1289c2009-08-17 11:03:03 -04002888 /**
2889 * Refreshes the shortcuts shown on the workspace.
2890 *
2891 * Implementation of the method from LauncherModel.Callbacks.
2892 */
2893 public void startBinding() {
2894 final Workspace workspace = mWorkspace;
2895 int count = workspace.getChildCount();
2896 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04002897 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Joe Onorato9c1289c2009-08-17 11:03:03 -04002898 ((ViewGroup) workspace.getChildAt(i)).removeAllViewsInLayout();
2899 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002900
Joe Onorato9c1289c2009-08-17 11:03:03 -04002901 if (DEBUG_USER_INTERFACE) {
2902 android.widget.Button finishButton = new android.widget.Button(this);
2903 finishButton.setText("Finish");
2904 workspace.addInScreen(finishButton, 1, 0, 0, 1, 1);
2905
2906 finishButton.setOnClickListener(new android.widget.Button.OnClickListener() {
2907 public void onClick(View v) {
2908 finish();
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002909 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002910 });
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002911 }
2912 }
2913
2914 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002915 * Bind the items start-end from the list.
2916 *
2917 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002918 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002919 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
2920
2921 final Workspace workspace = mWorkspace;
2922
2923 for (int i=start; i<end; i++) {
2924 final ItemInfo item = shortcuts.get(i);
2925 mDesktopItems.add(item);
2926 switch (item.itemType) {
2927 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
2928 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Joe Onorato0589f0f2010-02-08 13:44:00 -08002929 final View shortcut = createShortcut((ShortcutInfo)item);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002930 workspace.addInScreen(shortcut, item.screen, item.cellX, item.cellY, 1, 1,
2931 false);
2932 break;
2933 case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER:
2934 final FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07002935 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Joe Onorato9c1289c2009-08-17 11:03:03 -04002936 (UserFolderInfo) item);
2937 workspace.addInScreen(newFolder, item.screen, item.cellX, item.cellY, 1, 1,
2938 false);
2939 break;
2940 case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER:
2941 final FolderIcon newLiveFolder = LiveFolderIcon.fromXml(
2942 R.layout.live_folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07002943 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Joe Onorato9c1289c2009-08-17 11:03:03 -04002944 (LiveFolderInfo) item);
2945 workspace.addInScreen(newLiveFolder, item.screen, item.cellX, item.cellY, 1, 1,
2946 false);
2947 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002948 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002949 }
2950
Joe Onorato9c1289c2009-08-17 11:03:03 -04002951 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002952 }
2953
Joe Onorato9c1289c2009-08-17 11:03:03 -04002954 /**
2955 * Implementation of the method from LauncherModel.Callbacks.
2956 */
Joe Onoratoad72e172009-11-06 16:25:04 -05002957 public void bindFolders(HashMap<Long, FolderInfo> folders) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002958 sFolders.clear();
2959 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002960 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002961
2962 /**
2963 * Add the views for a widget to the workspace.
2964 *
2965 * Implementation of the method from LauncherModel.Callbacks.
2966 */
2967 public void bindAppWidget(LauncherAppWidgetInfo item) {
Daniel Sandler843e8602010-06-07 14:59:01 -04002968 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
2969 if (DEBUG_WIDGETS) {
2970 Log.d(TAG, "bindAppWidget: " + item);
2971 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002972 final Workspace workspace = mWorkspace;
2973
2974 final int appWidgetId = item.appWidgetId;
2975 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04002976 if (DEBUG_WIDGETS) {
2977 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
2978 }
2979
Joe Onorato9c1289c2009-08-17 11:03:03 -04002980 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
2981
Joe Onorato9c1289c2009-08-17 11:03:03 -04002982 item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
2983 item.hostView.setTag(item);
2984
2985 workspace.addInScreen(item.hostView, item.screen, item.cellX,
2986 item.cellY, item.spanX, item.spanY, false);
2987
2988 workspace.requestLayout();
2989
2990 mDesktopItems.add(item);
Daniel Sandler843e8602010-06-07 14:59:01 -04002991
2992 if (DEBUG_WIDGETS) {
2993 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
2994 + (SystemClock.uptimeMillis()-start) + "ms");
2995 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002996 }
2997
2998 /**
2999 * Callback saying that there aren't any more items to bind.
3000 *
3001 * Implementation of the method from LauncherModel.Callbacks.
3002 */
3003 public void finishBindingItems() {
3004 if (mSavedState != null) {
3005 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003006 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003007 }
3008
3009 final long[] userFolders = mSavedState.getLongArray(RUNTIME_STATE_USER_FOLDERS);
3010 if (userFolders != null) {
3011 for (long folderId : userFolders) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003012 final FolderInfo info = sFolders.get(folderId);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003013 if (info != null) {
3014 openFolder(info);
3015 }
3016 }
3017 final Folder openFolder = mWorkspace.getOpenFolder();
3018 if (openFolder != null) {
3019 openFolder.requestFocus();
3020 }
3021 }
3022
Joe Onorato9c1289c2009-08-17 11:03:03 -04003023 mSavedState = null;
3024 }
3025
3026 if (mSavedInstanceState != null) {
3027 super.onRestoreInstanceState(mSavedInstanceState);
3028 mSavedInstanceState = null;
3029 }
3030
Joe Onorato9c1289c2009-08-17 11:03:03 -04003031 mWorkspaceLoading = false;
3032 }
3033
3034 /**
3035 * Add the icons for all apps.
3036 *
3037 * Implementation of the method from LauncherModel.Callbacks.
3038 */
3039 public void bindAllApplications(ArrayList<ApplicationInfo> apps) {
Romain Guy84f296c2009-11-04 15:00:44 -08003040 mAllAppsGrid.setApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003041 if (mCustomizePagedView != null) {
3042 mCustomizePagedView.setApps(apps);
3043 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003044 updateAppMarketIcon();
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003045 updateGlobalSearchIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003046 }
3047
3048 /**
3049 * A package was installed.
3050 *
3051 * Implementation of the method from LauncherModel.Callbacks.
3052 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003053 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003054 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onoratoa8138d52009-10-06 19:25:30 -07003055 mAllAppsGrid.addApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003056 if (mCustomizePagedView != null) {
3057 mCustomizePagedView.addApps(apps);
3058 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003059 updateAppMarketIcon();
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003060 updateGlobalSearchIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003061 }
3062
3063 /**
3064 * A package was updated.
3065 *
3066 * Implementation of the method from LauncherModel.Callbacks.
3067 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003068 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003069 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato64e6be72010-03-05 15:05:52 -05003070 mWorkspace.updateShortcuts(apps);
3071 mAllAppsGrid.updateApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003072 if (mCustomizePagedView != null) {
3073 mCustomizePagedView.updateApps(apps);
3074 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003075 updateAppMarketIcon();
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003076 updateGlobalSearchIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003077 }
3078
3079 /**
3080 * A package was uninstalled.
3081 *
3082 * Implementation of the method from LauncherModel.Callbacks.
3083 */
Joe Onorato36115782010-06-17 13:28:48 -04003084 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003085 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato36115782010-06-17 13:28:48 -04003086 if (permanent) {
3087 mWorkspace.removeItems(apps);
3088 }
Joe Onoratoa8138d52009-10-06 19:25:30 -07003089 mAllAppsGrid.removeApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003090 if (mCustomizePagedView != null) {
3091 mCustomizePagedView.removeApps(apps);
3092 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003093 updateAppMarketIcon();
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003094 updateGlobalSearchIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003095 }
Joe Onoratobe386092009-11-17 17:32:16 -08003096
3097 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003098 * A number of packages were updated.
3099 */
3100 public void bindPackagesUpdated() {
3101 // update the customization drawer contents
Winson Chung5f941722010-09-28 16:36:43 -07003102 if (mCustomizePagedView != null) {
Winson Chungb3347bb2010-08-19 14:51:28 -07003103 mCustomizePagedView.update();
Winson Chung5f941722010-09-28 16:36:43 -07003104 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003105 }
3106
3107 /**
Joe Onoratobe386092009-11-17 17:32:16 -08003108 * Prints out out state for debugging.
3109 */
3110 public void dumpState() {
3111 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08003112 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08003113 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
3114 Log.d(TAG, "mRestoring=" + mRestoring);
3115 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
3116 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
3117 Log.d(TAG, "mDesktopItems.size=" + mDesktopItems.size());
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003118 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08003119 mModel.dumpState();
3120 mAllAppsGrid.dumpState();
3121 Log.d(TAG, "END launcher2 dump state");
3122 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003123}