blob: f81a9bf7cb5e94ef6830e41097b82acb59f05f6e [file] [log] [blame]
Michael Jurka01f0ed42010-08-20 00:41:17 -07001
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002/*
3 * Copyright (C) 2008 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
Joe Onoratoa5902522009-07-30 13:37:37 -070018package com.android.launcher2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080019
Chet Haaseb1254a62010-09-07 13:35:00 -070020import android.animation.Animator;
21import android.animation.AnimatorListenerAdapter;
22import android.animation.ValueAnimator;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070023import com.android.common.Search;
24import com.android.launcher.R;
25
Chet Haaseb1254a62010-09-07 13:35:00 -070026import android.animation.ObjectAnimator;
Patrick Dubroy07a0de42010-08-26 11:48:35 -070027import android.animation.PropertyValuesHolder;
Chet Haaseb1254a62010-09-07 13:35:00 -070028import android.animation.AnimatorSet;
Michael Jurka946ad472010-07-09 18:05:18 -070029import android.app.Activity;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080030import android.app.AlertDialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080031import android.app.Dialog;
32import android.app.SearchManager;
33import android.app.StatusBarManager;
Dianne Hackborn107f8392009-08-05 21:32:16 -070034import android.app.WallpaperManager;
Michael Jurkaaf442092010-06-10 17:01:57 -070035import android.appwidget.AppWidgetManager;
36import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080037import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080038import android.content.BroadcastReceiver;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040039import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080040import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041import android.content.Context;
42import android.content.DialogInterface;
43import android.content.Intent;
Winson Chung80baf5a2010-08-09 16:03:15 -070044import android.content.Intent.ShortcutIconResource;
Romain Guy5bbc91b2010-08-18 11:38:46 -070045import android.content.IntentFilter;
Winson Chungaafa03c2010-06-11 17:34:16 -070046import android.content.pm.ActivityInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080047import android.content.pm.PackageManager;
Patrick Dubroyceae05d2010-08-30 10:40:53 -070048import android.content.pm.PackageManager.NameNotFoundException;
Daniel Sandlerab1ebd72010-04-27 16:57:25 -040049import android.content.pm.ResolveInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080050import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070051import android.content.res.Resources;
Daniel Sandlerab1ebd72010-04-27 16:57:25 -040052import android.content.res.TypedArray;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080053import android.database.ContentObserver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080054import android.graphics.Bitmap;
Romain Guya6abce82009-11-10 02:54:41 -080055import android.graphics.Canvas;
Winson Chung80baf5a2010-08-09 16:03:15 -070056import android.graphics.Color;
Michael Jurkaaf442092010-06-10 17:01:57 -070057import android.graphics.Rect;
Romain Guyff0c2e22009-11-10 12:09:59 -080058import android.graphics.drawable.ColorDrawable;
Michael Jurkaaf442092010-06-10 17:01:57 -070059import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040060import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070061import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080062import android.os.Bundle;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080063import android.os.Handler;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080064import android.os.Parcelable;
Daniel Sandler843e8602010-06-07 14:59:01 -040065import android.os.SystemClock;
Joe Onoratobe386092009-11-17 17:32:16 -080066import android.os.SystemProperties;
Karl Rosaen138a0412009-04-23 19:00:21 -070067import android.provider.LiveFolders;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070068import android.provider.Settings;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080069import android.text.Selection;
70import android.text.SpannableStringBuilder;
71import android.text.TextUtils;
72import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070073import android.util.Log;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080074import android.view.Display;
Joe Onorato0d44e942009-11-16 18:20:51 -080075import android.view.HapticFeedbackConstants;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080076import android.view.KeyEvent;
77import android.view.LayoutInflater;
78import android.view.Menu;
79import android.view.MenuItem;
Michael Jurka0e260592010-06-30 17:07:39 -070080import android.view.MotionEvent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080081import android.view.View;
Romain Guy5bbc91b2010-08-18 11:38:46 -070082import android.view.View.OnLongClickListener;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080083import android.view.ViewGroup;
Winson Chungaafa03c2010-06-11 17:34:16 -070084import android.view.WindowManager;
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -070085import android.view.animation.AccelerateInterpolator;
Patrick Dubroy7247f632010-08-04 16:02:59 -070086import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080087import android.view.inputmethod.InputMethodManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080088import android.widget.EditText;
Michael Jurkaaf442092010-06-10 17:01:57 -070089import android.widget.ImageView;
90import android.widget.LinearLayout;
91import android.widget.PopupWindow;
Winson Chung80baf5a2010-08-09 16:03:15 -070092import android.widget.RelativeLayout;
Michael Jurka0e260592010-06-30 17:07:39 -070093import android.widget.TabHost;
Romain Guy5bbc91b2010-08-18 11:38:46 -070094import android.widget.TabHost.OnTabChangeListener;
95import android.widget.TabHost.TabContentFactory;
Winson Chung80baf5a2010-08-09 16:03:15 -070096import android.widget.TabWidget;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080097import android.widget.TextView;
98import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070099
100import java.io.DataInputStream;
101import java.io.DataOutputStream;
102import java.io.FileNotFoundException;
103import java.io.IOException;
104import java.util.ArrayList;
105import java.util.HashMap;
106import java.util.List;
Romain Guyedcce092010-03-04 13:03:17 -0800107
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800108/**
109 * Default launcher application.
110 */
Michael Jurka946ad472010-07-09 18:05:18 -0700111public final class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700112 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
113 AllAppsView.Watcher, View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800114 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700115 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800116
Joe Onorato9c1289c2009-08-17 11:03:03 -0400117 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400118 static final boolean DEBUG_WIDGETS = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400119 static final boolean DEBUG_USER_INTERFACE = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700120
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800121 private static final int MENU_GROUP_ADD = 1;
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800122 private static final int MENU_GROUP_WALLPAPER = MENU_GROUP_ADD + 1;
123
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800124 private static final int MENU_ADD = Menu.FIRST + 1;
Winson Chung7ad01412010-09-27 11:33:03 -0700125 private static final int MENU_MANAGE_APPS = MENU_ADD + 1;
126 private static final int MENU_WALLPAPER_SETTINGS = MENU_MANAGE_APPS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800127 private static final int MENU_SEARCH = MENU_WALLPAPER_SETTINGS + 1;
128 private static final int MENU_NOTIFICATIONS = MENU_SEARCH + 1;
Romain Guy94dabf12009-07-21 10:55:43 -0700129 private static final int MENU_SETTINGS = MENU_NOTIFICATIONS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800130
131 private static final int REQUEST_CREATE_SHORTCUT = 1;
132 private static final int REQUEST_CREATE_LIVE_FOLDER = 4;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700133 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800134 private static final int REQUEST_PICK_APPLICATION = 6;
135 private static final int REQUEST_PICK_SHORTCUT = 7;
136 private static final int REQUEST_PICK_LIVE_FOLDER = 8;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700137 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700138 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800139
140 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
141
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800142 static final int SCREEN_COUNT = 5;
143 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800144
Joe Onorato7c312c12009-08-13 21:36:53 -0700145 static final int DIALOG_CREATE_SHORTCUT = 1;
146 static final int DIALOG_RENAME_FOLDER = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800147
Romain Guy98d01652009-06-30 16:21:04 -0700148 private static final String PREFERENCES = "launcher.preferences";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800149
150 // Type: int
151 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
152 // Type: boolean
153 private static final String RUNTIME_STATE_ALL_APPS_FOLDER = "launcher.all_apps_folder";
154 // Type: long
155 private static final String RUNTIME_STATE_USER_FOLDERS = "launcher.user_folder";
156 // Type: int
157 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
158 // Type: int
159 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cellX";
160 // Type: int
161 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cellY";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800162 // Type: boolean
163 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
164 // Type: long
165 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
166
Winson Chung80baf5a2010-08-09 16:03:15 -0700167 // tags for the customization tabs
168 private static final String WIDGETS_TAG = "widgets";
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700169 private static final String APPLICATIONS_TAG = "applications";
Winson Chung80baf5a2010-08-09 16:03:15 -0700170 private static final String FOLDERS_TAG = "folders";
171 private static final String SHORTCUTS_TAG = "shortcuts";
172 private static final String WALLPAPERS_TAG = "wallpapers";
173
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700174 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
175
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700176 /** The different states that Launcher can be in. */
177 private enum State { WORKSPACE, ALL_APPS, CUSTOMIZE, OVERVIEW };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700178 private State mState = State.WORKSPACE;
179 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700180
Joe Onorato9c1289c2009-08-17 11:03:03 -0400181 static final int APPWIDGET_HOST_ID = 1024;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800182
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800183 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800184 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800185
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800186 private final BroadcastReceiver mCloseSystemDialogsReceiver
187 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800188 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
189
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800190 private LayoutInflater mInflater;
191
Joe Onorato00acb122009-08-04 16:04:30 -0400192 private DragController mDragController;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800193 private Workspace mWorkspace;
Romain Guycbb89e42009-06-08 15:52:54 -0700194
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700195 private AppWidgetManager mAppWidgetManager;
196 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700197
Michael Jurka0280c3b2010-09-17 15:00:07 -0700198 private int mAddScreen = -1;
199 private int mAddIntersectCellX = -1;
200 private int mAddIntersectCellY = -1;
201 private int[] mAddDropPosition;
202 private int[] mTmpAddItemCellCoordinates = new int[2];
203
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800204 private FolderInfo mFolderInfo;
205
Joe Onorato7c312c12009-08-13 21:36:53 -0700206 private DeleteZone mDeleteZone;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700207 private HandleView mHandleView;
Joe Onorato7c312c12009-08-13 21:36:53 -0700208 private AllAppsView mAllAppsGrid;
Michael Jurka0e260592010-06-30 17:07:39 -0700209 private TabHost mHomeCustomizationDrawer;
Patrick Dubroy2b9ff372010-09-07 17:49:27 -0700210
211 private PagedView mAllAppsPagedView = null;
212 private CustomizePagedView mCustomizePagedView = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800213
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800214 private Bundle mSavedState;
215
216 private SpannableStringBuilder mDefaultKeySsb = null;
217
Joe Onorato9c1289c2009-08-17 11:03:03 -0400218 private boolean mWorkspaceLoading = true;
219
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800220 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800221 private boolean mRestoring;
222 private boolean mWaitingForResult;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800223
224 private Bundle mSavedInstanceState;
225
Joe Onorato9c1289c2009-08-17 11:03:03 -0400226 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800227 private IconCache mIconCache;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400228
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700229 private static LocaleConfiguration sLocaleConfiguration = null;
230
Romain Guy84f296c2009-11-04 15:00:44 -0800231 private ArrayList<ItemInfo> mDesktopItems = new ArrayList<ItemInfo>();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700232 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700233
Romain Guy1fbc1c82009-11-09 20:43:08 -0800234 private ImageView mPreviousView;
235 private ImageView mNextView;
Joe Onorato080d9b62009-11-02 12:01:11 -0500236
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400237 // Hotseats (quick-launch icons next to AllApps)
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400238 private String[] mHotseatConfig = null;
239 private Intent[] mHotseats = null;
240 private Drawable[] mHotseatIcons = null;
241 private CharSequence[] mHotseatLabels = null;
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400242
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700243 private Intent mAppMarketIntent = null;
244
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800245 @Override
246 protected void onCreate(Bundle savedInstanceState) {
247 super.onCreate(savedInstanceState);
Romain Guyb1b69f52009-08-10 15:10:15 -0700248
Winson Chungaafa03c2010-06-11 17:34:16 -0700249 if (LauncherApplication.isInPlaceRotationEnabled()) {
250 // hide the status bar (temporary until we get the status bar design figured out)
251 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
252 this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
253 }
254
Joe Onorato0589f0f2010-02-08 13:44:00 -0800255 LauncherApplication app = ((LauncherApplication)getApplication());
256 mModel = app.setLauncher(this);
257 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400258 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800259 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700260
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700261 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700262 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
263 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700264
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800265 if (PROFILE_STARTUP) {
266 android.os.Debug.startMethodTracing("/sdcard/launcher");
267 }
268
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400269 loadHotseats();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800270 checkForLocaleChange();
271 setWallpaperDimension();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800272 setContentView(R.layout.launcher);
Michael Jurka946ad472010-07-09 18:05:18 -0700273 mHomeCustomizationDrawer = (TabHost) findViewById(com.android.internal.R.id.tabhost);
274 if (mHomeCustomizationDrawer != null) {
275 mHomeCustomizationDrawer.setup();
Winson Chungaafa03c2010-06-11 17:34:16 -0700276
Winson Chung80baf5a2010-08-09 16:03:15 -0700277 // share the same customization workspace across all the tabs
Winson Chunge3193b92010-09-10 11:44:42 -0700278 mCustomizePagedView = (CustomizePagedView) mInflater.inflate(
279 R.layout.customization_drawer, mHomeCustomizationDrawer, false);
Winson Chung80baf5a2010-08-09 16:03:15 -0700280 TabContentFactory contentFactory = new TabContentFactory() {
281 public View createTabContent(String tag) {
282 return mCustomizePagedView;
283 }
284 };
285
Michael Jurka946ad472010-07-09 18:05:18 -0700286 String widgetsLabel = getString(R.string.widgets_tab_label);
Winson Chung80baf5a2010-08-09 16:03:15 -0700287 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(WIDGETS_TAG)
288 .setIndicator(widgetsLabel).setContent(contentFactory));
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700289 String applicationsLabel = getString(R.string.applications_tab_label);
290 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(APPLICATIONS_TAG)
291 .setIndicator(applicationsLabel).setContent(contentFactory));
Michael Jurka946ad472010-07-09 18:05:18 -0700292 String foldersLabel = getString(R.string.folders_tab_label);
Winson Chung80baf5a2010-08-09 16:03:15 -0700293 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(FOLDERS_TAG)
294 .setIndicator(foldersLabel).setContent(contentFactory));
Michael Jurka946ad472010-07-09 18:05:18 -0700295 String wallpapersLabel = getString(R.string.wallpapers_tab_label);
Winson Chung80baf5a2010-08-09 16:03:15 -0700296 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(WALLPAPERS_TAG)
297 .setIndicator(wallpapersLabel).setContent(contentFactory));
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700298 String shortcutsLabel = getString(R.string.shortcuts_tab_label);
299 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(SHORTCUTS_TAG)
300 .setIndicator(shortcutsLabel).setContent(contentFactory));
Winson Chung80baf5a2010-08-09 16:03:15 -0700301
302 // TEMP: just styling the tab widget to be a bit nicer until we get the actual
303 // new assets
304 TabWidget tabWidget = mHomeCustomizationDrawer.getTabWidget();
305 for (int i = 0; i < tabWidget.getChildCount(); ++i) {
306 RelativeLayout tab = (RelativeLayout) tabWidget.getChildTabViewAt(i);
307 TextView text = (TextView) tab.getChildAt(1);
308 text.setTextSize(20.0f);
309 text.setPadding(20, 0, 20, 0);
310 text.setShadowLayer(1.0f, 0.0f, 1.0f, Color.BLACK);
311 tab.setBackgroundDrawable(null);
312 }
313
314 mHomeCustomizationDrawer.setOnTabChangedListener(new OnTabChangeListener() {
315 public void onTabChanged(String tabId) {
316 // animate the changing of the tab content by fading pages in and out
317 final int duration = 150;
318 final float alpha = mCustomizePagedView.getAlpha();
Chet Haaseb1254a62010-09-07 13:35:00 -0700319 ValueAnimator alphaAnim = new ObjectAnimator(duration, mCustomizePagedView,
Winson Chung80baf5a2010-08-09 16:03:15 -0700320 "alpha", alpha, 0.0f);
Chet Haaseb1254a62010-09-07 13:35:00 -0700321 alphaAnim.addListener(new AnimatorListenerAdapter() {
322 public void onAnimationEnd(Animator animation) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700323 String tag = mHomeCustomizationDrawer.getCurrentTabTag();
324 if (tag == WIDGETS_TAG) {
325 mCustomizePagedView.setCustomizationFilter(
326 CustomizePagedView.CustomizationType.WidgetCustomization);
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700327 } else if (tag == APPLICATIONS_TAG) {
328 mCustomizePagedView.setCustomizationFilter(
329 CustomizePagedView.CustomizationType.ApplicationCustomization);
Winson Chung80baf5a2010-08-09 16:03:15 -0700330 } else if (tag == FOLDERS_TAG) {
331 mCustomizePagedView.setCustomizationFilter(
332 CustomizePagedView.CustomizationType.FolderCustomization);
Winson Chung80baf5a2010-08-09 16:03:15 -0700333 } else if (tag == WALLPAPERS_TAG) {
334 mCustomizePagedView.setCustomizationFilter(
335 CustomizePagedView.CustomizationType.WallpaperCustomization);
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700336 } else if (tag == SHORTCUTS_TAG) {
337 mCustomizePagedView.setCustomizationFilter(
338 CustomizePagedView.CustomizationType.ShortcutCustomization);
Winson Chung80baf5a2010-08-09 16:03:15 -0700339 }
340
341 final float alpha = mCustomizePagedView.getAlpha();
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700342 ValueAnimator alphaAnim = new ObjectAnimator(duration,
343 mCustomizePagedView, "alpha", alpha, 1.0f);
Winson Chung80baf5a2010-08-09 16:03:15 -0700344 alphaAnim.start();
345 }
346 });
347 alphaAnim.start();
348 }
349 });
Michael Jurka946ad472010-07-09 18:05:18 -0700350
351 mHomeCustomizationDrawer.setCurrentTab(0);
352 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800353 setupViews();
354
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800355 registerContentObservers();
356
Joe Onorato7c312c12009-08-13 21:36:53 -0700357 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700358
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800359 mSavedState = savedInstanceState;
360 restoreState(mSavedState);
361
362 if (PROFILE_STARTUP) {
363 android.os.Debug.stopMethodTracing();
364 }
365
366 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400367 mModel.startLoader(this, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800368 }
369
370 // For handling default keys
371 mDefaultKeySsb = new SpannableStringBuilder();
372 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800373
374 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
375 registerReceiver(mCloseSystemDialogsReceiver, filter);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800376 }
Romain Guycbb89e42009-06-08 15:52:54 -0700377
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800378 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700379 if (sLocaleConfiguration == null) {
380 new AsyncTask<Void, Void, LocaleConfiguration>() {
381 @Override
382 protected LocaleConfiguration doInBackground(Void... unused) {
383 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
384 readConfiguration(Launcher.this, localeConfiguration);
385 return localeConfiguration;
386 }
387
388 @Override
389 protected void onPostExecute(LocaleConfiguration result) {
390 sLocaleConfiguration = result;
391 checkForLocaleChange(); // recursive, but now with a locale configuration
392 }
393 }.execute();
394 return;
395 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700396
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800397 final Configuration configuration = getResources().getConfiguration();
398
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700399 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800400 final String locale = configuration.locale.toString();
401
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700402 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800403 final int mcc = configuration.mcc;
404
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700405 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800406 final int mnc = configuration.mnc;
407
Romain Guy84f296c2009-11-04 15:00:44 -0800408 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800409
Romain Guy84f296c2009-11-04 15:00:44 -0800410 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700411 sLocaleConfiguration.locale = locale;
412 sLocaleConfiguration.mcc = mcc;
413 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700414
Joe Onorato0589f0f2010-02-08 13:44:00 -0800415 mIconCache.flush();
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400416 loadHotseats();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700417
418 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
419 new Thread("WriteLocaleConfiguration") {
420 public void run() {
421 writeConfiguration(Launcher.this, localeConfiguration);
422 }
423 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700424 }
425 }
426
427 private static class LocaleConfiguration {
428 public String locale;
429 public int mcc = -1;
430 public int mnc = -1;
431 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700432
Romain Guy98d01652009-06-30 16:21:04 -0700433 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
434 DataInputStream in = null;
435 try {
436 in = new DataInputStream(context.openFileInput(PREFERENCES));
437 configuration.locale = in.readUTF();
438 configuration.mcc = in.readInt();
439 configuration.mnc = in.readInt();
440 } catch (FileNotFoundException e) {
441 // Ignore
442 } catch (IOException e) {
443 // Ignore
444 } finally {
445 if (in != null) {
446 try {
447 in.close();
448 } catch (IOException e) {
449 // Ignore
450 }
451 }
452 }
453 }
454
455 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
456 DataOutputStream out = null;
457 try {
458 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
459 out.writeUTF(configuration.locale);
460 out.writeInt(configuration.mcc);
461 out.writeInt(configuration.mnc);
462 out.flush();
463 } catch (FileNotFoundException e) {
464 // Ignore
465 } catch (IOException e) {
466 //noinspection ResultOfMethodCallIgnored
467 context.getFileStreamPath(PREFERENCES).delete();
468 } finally {
469 if (out != null) {
470 try {
471 out.close();
472 } catch (IOException e) {
473 // Ignore
474 }
475 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800476 }
477 }
478
479 static int getScreen() {
480 synchronized (sLock) {
481 return sScreen;
482 }
483 }
484
485 static void setScreen(int screen) {
486 synchronized (sLock) {
487 sScreen = screen;
488 }
489 }
490
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800491 private void setWallpaperDimension() {
Dianne Hackborn107f8392009-08-05 21:32:16 -0700492 WallpaperManager wpm = (WallpaperManager)getSystemService(WALLPAPER_SERVICE);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800493
494 Display display = getWindowManager().getDefaultDisplay();
Romain Guy5bbc91b2010-08-18 11:38:46 -0700495 // TODO: Put back when we decide about scrolling the wallpaper
496 // boolean isPortrait = display.getWidth() < display.getHeight();
497 // final int width = isPortrait ? display.getWidth() : display.getHeight();
498 // final int height = isPortrait ? display.getHeight() : display.getWidth();
499 wpm.suggestDesiredDimensions(Math.max(display.getWidth(), display.getHeight()),
500 Math.max(display.getWidth(), display.getHeight()));
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800501 }
502
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400503 // Note: This doesn't do all the client-id magic that BrowserProvider does
504 // in Browser. (http://b/2425179)
505 private Uri getDefaultBrowserUri() {
506 String url = getString(R.string.default_browser_url);
507 if (url.indexOf("{CID}") != -1) {
508 url = url.replace("{CID}", "android-google");
509 }
510 return Uri.parse(url);
511 }
512
513 // Load the Intent templates from arrays.xml to populate the hotseats. For
514 // each Intent, if it resolves to a single app, use that as the launch
515 // intent & use that app's label as the contentDescription. Otherwise,
516 // retain the ResolveActivity so the user can pick an app.
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400517 private void loadHotseats() {
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400518 if (mHotseatConfig == null) {
519 mHotseatConfig = getResources().getStringArray(R.array.hotseats);
520 if (mHotseatConfig.length > 0) {
521 mHotseats = new Intent[mHotseatConfig.length];
522 mHotseatLabels = new CharSequence[mHotseatConfig.length];
523 mHotseatIcons = new Drawable[mHotseatConfig.length];
524 } else {
525 mHotseats = null;
526 mHotseatIcons = null;
527 mHotseatLabels = null;
528 }
529
530 TypedArray hotseatIconDrawables = getResources().obtainTypedArray(R.array.hotseat_icons);
531 for (int i=0; i<mHotseatConfig.length; i++) {
532 // load icon for this slot; currently unrelated to the actual activity
533 try {
534 mHotseatIcons[i] = hotseatIconDrawables.getDrawable(i);
535 } catch (ArrayIndexOutOfBoundsException ex) {
536 Log.w(TAG, "Missing hotseat_icons array item #" + i);
537 mHotseatIcons[i] = null;
538 }
539 }
540 hotseatIconDrawables.recycle();
541 }
542
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400543 PackageManager pm = getPackageManager();
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400544 for (int i=0; i<mHotseatConfig.length; i++) {
545 Intent intent = null;
546 if (mHotseatConfig[i].equals("*BROWSER*")) {
547 // magic value meaning "launch user's default web browser"
548 // replace it with a generic web request so we can see if there is indeed a default
549 String defaultUri = getString(R.string.default_browser_url);
550 intent = new Intent(
551 Intent.ACTION_VIEW,
552 ((defaultUri != null)
553 ? Uri.parse(defaultUri)
554 : getDefaultBrowserUri())
555 ).addCategory(Intent.CATEGORY_BROWSABLE);
556 // note: if the user launches this without a default set, she
557 // will always be taken to the default URL above; this is
558 // unavoidable as we must specify a valid URL in order for the
Winson Chungaafa03c2010-06-11 17:34:16 -0700559 // chooser to appear, and once the user selects something, that
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400560 // URL is unavoidably sent to the chosen app.
561 } else {
562 try {
563 intent = Intent.parseUri(mHotseatConfig[i], 0);
564 } catch (java.net.URISyntaxException ex) {
565 Log.w(TAG, "Invalid hotseat intent: " + mHotseatConfig[i]);
566 // bogus; leave intent=null
567 }
568 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700569
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400570 if (intent == null) {
571 mHotseats[i] = null;
572 mHotseatLabels[i] = getText(R.string.activity_not_found);
573 continue;
574 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400575
576 if (LOGD) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700577 Log.d(TAG, "loadHotseats: hotseat " + i
578 + " initial intent=["
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400579 + intent.toUri(Intent.URI_INTENT_SCHEME)
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400580 + "]");
581 }
582
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400583 ResolveInfo bestMatch = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
584 List<ResolveInfo> allMatches = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
Winson Chungaafa03c2010-06-11 17:34:16 -0700585 if (LOGD) {
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400586 Log.d(TAG, "Best match for intent: " + bestMatch);
587 Log.d(TAG, "All matches: ");
588 for (ResolveInfo ri : allMatches) {
589 Log.d(TAG, " --> " + ri);
590 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400591 }
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400592 // did this resolve to a single app, or the resolver?
593 if (allMatches.size() == 0 || bestMatch == null) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700594 // can't find any activity to handle this. let's leave the
595 // intent as-is and let Launcher show a toast when it fails
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400596 // to launch.
597 mHotseats[i] = intent;
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400598
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400599 // set accessibility text to "Not installed"
600 mHotseatLabels[i] = getText(R.string.activity_not_found);
601 } else {
602 boolean found = false;
603 for (ResolveInfo ri : allMatches) {
604 if (bestMatch.activityInfo.name.equals(ri.activityInfo.name)
605 && bestMatch.activityInfo.applicationInfo.packageName
606 .equals(ri.activityInfo.applicationInfo.packageName)) {
607 found = true;
608 break;
609 }
610 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700611
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400612 if (!found) {
613 if (LOGD) Log.d(TAG, "Multiple options, no default yet");
614 // the bestMatch is probably the ResolveActivity, meaning the
615 // user has not yet selected a default
616 // so: we'll keep the original intent for now
617 mHotseats[i] = intent;
618
619 // set the accessibility text to "Select shortcut"
620 mHotseatLabels[i] = getText(R.string.title_select_shortcut);
621 } else {
622 // we have an app!
623 // now reconstruct the intent to launch it through the front
624 // door
625 ComponentName com = new ComponentName(
626 bestMatch.activityInfo.applicationInfo.packageName,
627 bestMatch.activityInfo.name);
628 mHotseats[i] = new Intent(Intent.ACTION_MAIN).setComponent(com);
629
630 // load the app label for accessibility
631 mHotseatLabels[i] = bestMatch.activityInfo.loadLabel(pm);
632 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400633 }
634
635 if (LOGD) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700636 Log.d(TAG, "loadHotseats: hotseat " + i
637 + " final intent=["
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400638 + ((mHotseats[i] == null)
639 ? "null"
640 : mHotseats[i].toUri(Intent.URI_INTENT_SCHEME))
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400641 + "] label=[" + mHotseatLabels[i]
642 + "]"
643 );
644 }
645 }
646 }
647
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800648 @Override
649 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Romain Guyaad5ef42009-06-10 02:48:37 -0700650 mWaitingForResult = false;
651
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800652 // The pattern used here is that a user PICKs a specific application,
653 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700654
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800655 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
656 // launch over to the Music app to actually CREATE_SHORTCUT.
Romain Guycbb89e42009-06-08 15:52:54 -0700657
Michael Jurka0280c3b2010-09-17 15:00:07 -0700658 if (resultCode == RESULT_OK && mAddScreen != -1) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800659 switch (requestCode) {
660 case REQUEST_PICK_APPLICATION:
Michael Jurka28750fb2010-09-24 17:43:49 -0700661 completeAddApplication(
662 this, data, mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800663 break;
664 case REQUEST_PICK_SHORTCUT:
Joe Onoratodeb98af2010-02-19 14:59:39 -0800665 processShortcut(data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800666 break;
667 case REQUEST_CREATE_SHORTCUT:
Michael Jurka0280c3b2010-09-17 15:00:07 -0700668 completeAddShortcut(data, mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800669 break;
670 case REQUEST_PICK_LIVE_FOLDER:
671 addLiveFolder(data);
672 break;
673 case REQUEST_CREATE_LIVE_FOLDER:
Michael Jurka0280c3b2010-09-17 15:00:07 -0700674 completeAddLiveFolder(data, mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800675 break;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700676 case REQUEST_PICK_APPWIDGET:
Michael Jurkaaf442092010-06-10 17:01:57 -0700677 addAppWidgetFromPick(data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800678 break;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700679 case REQUEST_CREATE_APPWIDGET:
Michael Jurkaaf442092010-06-10 17:01:57 -0700680 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700681 completeAddAppWidget(appWidgetId, mAddScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800682 break;
Mike Clerona0618e42009-10-22 13:55:21 -0700683 case REQUEST_PICK_WALLPAPER:
684 // We just wanted the activity result here so we can clear mWaitingForResult
685 break;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800686 }
Romain Guy18042c82009-11-06 11:44:55 -0800687 } else if ((requestCode == REQUEST_PICK_APPWIDGET ||
688 requestCode == REQUEST_CREATE_APPWIDGET) && resultCode == RESULT_CANCELED &&
689 data != null) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700690 // Clean up the appWidgetId if we canceled
691 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
692 if (appWidgetId != -1) {
693 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800694 }
695 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800696 }
697
698 @Override
699 protected void onResume() {
700 super.onResume();
701
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800702 mPaused = false;
Joe Onorato7e4ed992009-12-03 13:10:49 -0800703
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800704 if (mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400705 mWorkspaceLoading = true;
706 mModel.startLoader(this, true);
707 mRestoring = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800708 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700709 // When we resume Launcher, a different Activity might be responsible for the app
710 // market intent, so refresh the icon
711 updateAppMarketIcon();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800712 }
713
714 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700715 protected void onPause() {
716 super.onPause();
Michael Jurkaaf442092010-06-10 17:01:57 -0700717 // Some launcher layouts don't have a previous and next view
718 if (mPreviousView != null) {
719 dismissPreview(mPreviousView);
Patrick Dubroyab962b72010-07-26 12:10:10 -0700720 }
721 if (mNextView != null) {
Michael Jurkaaf442092010-06-10 17:01:57 -0700722 dismissPreview(mNextView);
723 }
Joe Onorato24b6fd82009-11-12 13:47:09 -0800724 mDragController.cancelDrag();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700725 }
Romain Guycbb89e42009-06-08 15:52:54 -0700726
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700727 @Override
728 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400729 // Flag the loader to stop early before switching
730 mModel.stopLoader();
Romain Guy13c2e7b2010-03-10 19:45:00 -0800731 mAllAppsGrid.surrender();
Romain Guy13c2e7b2010-03-10 19:45:00 -0800732 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700733 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700734
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800735 // We can't hide the IME if it was forced open. So don't bother
736 /*
737 @Override
738 public void onWindowFocusChanged(boolean hasFocus) {
739 super.onWindowFocusChanged(hasFocus);
740
741 if (hasFocus) {
742 final InputMethodManager inputManager = (InputMethodManager)
743 getSystemService(Context.INPUT_METHOD_SERVICE);
744 WindowManager.LayoutParams lp = getWindow().getAttributes();
745 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
746 android.os.Handler()) {
747 protected void onReceiveResult(int resultCode, Bundle resultData) {
748 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
749 }
750 });
751 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
752 }
753 }
754 */
755
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800756 private boolean acceptFilter() {
757 final InputMethodManager inputManager = (InputMethodManager)
758 getSystemService(Context.INPUT_METHOD_SERVICE);
759 return !inputManager.isFullscreenMode();
760 }
761
762 @Override
763 public boolean onKeyDown(int keyCode, KeyEvent event) {
764 boolean handled = super.onKeyDown(keyCode, event);
765 if (!handled && acceptFilter() && keyCode != KeyEvent.KEYCODE_ENTER) {
766 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
767 keyCode, event);
768 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700769 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700770 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700771 // showSearchDialog()
772 // If there are multiple keystrokes before the search dialog takes focus,
773 // onSearchRequested() will be called for every keystroke,
774 // but it is idempotent, so it's fine.
775 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800776 }
777 }
778
Joe Onorato8a9625e2010-01-28 15:55:35 -0800779 // Eat the long press event so the keyboard doesn't come up.
780 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
781 return true;
782 }
783
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800784 return handled;
785 }
786
Karl Rosaen138a0412009-04-23 19:00:21 -0700787 private String getTypedText() {
788 return mDefaultKeySsb.toString();
789 }
790
791 private void clearTypedText() {
792 mDefaultKeySsb.clear();
793 mDefaultKeySsb.clearSpans();
794 Selection.setSelection(mDefaultKeySsb, 0);
795 }
796
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800797 /**
798 * Restores the previous state, if it exists.
799 *
800 * @param savedState The previous state.
801 */
802 private void restoreState(Bundle savedState) {
803 if (savedState == null) {
804 return;
805 }
806
Joe Onorato3a8820b2009-11-10 15:06:42 -0800807 final boolean allApps = savedState.getBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, false);
808 if (allApps) {
809 showAllApps(false);
810 }
811
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800812 final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
813 if (currentScreen > -1) {
Michael Jurka0142d492010-08-25 17:46:15 -0700814 mWorkspace.setCurrentPage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800815 }
816
817 final int addScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700818
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800819 if (addScreen > -1) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700820 mAddScreen = addScreen;
821 mAddIntersectCellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
822 mAddIntersectCellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800823 mRestoring = true;
824 }
825
826 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
827 if (renameFolder) {
828 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700829 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800830 mRestoring = true;
831 }
832 }
833
834 /**
835 * Finds all the views we need and configure them properly.
836 */
837 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700838 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -0400839
Romain Guyb1b69f52009-08-10 15:10:15 -0700840 DragLayer dragLayer = (DragLayer) findViewById(R.id.drag_layer);
Joe Onorato00acb122009-08-04 16:04:30 -0400841 dragLayer.setDragController(dragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800842
Joe Onorato7c312c12009-08-13 21:36:53 -0700843 mAllAppsGrid = (AllAppsView)dragLayer.findViewById(R.id.all_apps_view);
Joe Onorato6665c0f2009-09-02 15:27:24 -0700844 mAllAppsGrid.setLauncher(this);
Joe Onorato5162ea92009-09-03 09:39:42 -0700845 mAllAppsGrid.setDragController(dragController);
Romain Guyc16fea72010-03-12 17:17:56 -0800846 ((View) mAllAppsGrid).setWillNotDraw(false); // We don't want a hole punched in our window.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700847 // Manage focusability manually since this thing is always visible (in non-xlarge)
Winson Chungaafa03c2010-06-11 17:34:16 -0700848 ((View) mAllAppsGrid).setFocusable(false);
Joe Onorato7c312c12009-08-13 21:36:53 -0700849
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700850 if (LauncherApplication.isScreenXLarge()) {
851 // They need to be INVISIBLE initially so that they will be measured in the layout.
852 // Otherwise the animations are messed up when we show them for the first time.
853 ((View) mAllAppsGrid).setVisibility(View.INVISIBLE);
854 mHomeCustomizationDrawer.setVisibility(View.INVISIBLE);
855 }
856
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800857 mWorkspace = (Workspace) dragLayer.findViewById(R.id.workspace);
858 final Workspace workspace = mWorkspace;
Joe Onoratof0dde092010-02-16 18:25:23 -0500859 workspace.setHapticFeedbackEnabled(false);
Michael Jurka946ad472010-07-09 18:05:18 -0700860
Joe Onorato7c312c12009-08-13 21:36:53 -0700861 DeleteZone deleteZone = (DeleteZone) dragLayer.findViewById(R.id.delete_zone);
862 mDeleteZone = deleteZone;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800863
Michael Jurka2c3af5f2010-08-03 13:53:20 -0700864 View handleView = findViewById(R.id.all_apps_button);
865 if (handleView != null && handleView instanceof HandleView) {
866 // we don't use handle view in xlarge mode
Michael Jurka7ef4f752010-08-03 16:04:26 -0700867 mHandleView = (HandleView)handleView;
Michael Jurka2c3af5f2010-08-03 13:53:20 -0700868 mHandleView.setLauncher(this);
869 mHandleView.setOnClickListener(this);
870 mHandleView.setOnLongClickListener(this);
871 }
Romain Guy1fbc1c82009-11-09 20:43:08 -0800872
Winson Chung80baf5a2010-08-09 16:03:15 -0700873 if (mCustomizePagedView != null) {
874 mCustomizePagedView.setLauncher(this);
875 mCustomizePagedView.setDragController(dragController);
876 mCustomizePagedView.update();
Michael Jurkaaf442092010-06-10 17:01:57 -0700877 } else {
878 ImageView hotseatLeft = (ImageView) findViewById(R.id.hotseat_left);
879 hotseatLeft.setContentDescription(mHotseatLabels[0]);
880 hotseatLeft.setImageDrawable(mHotseatIcons[0]);
881 ImageView hotseatRight = (ImageView) findViewById(R.id.hotseat_right);
882 hotseatRight.setContentDescription(mHotseatLabels[1]);
883 hotseatRight.setImageDrawable(mHotseatIcons[1]);
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400884
Michael Jurkaaf442092010-06-10 17:01:57 -0700885 mPreviousView = (ImageView) dragLayer.findViewById(R.id.previous_screen);
886 mNextView = (ImageView) dragLayer.findViewById(R.id.next_screen);
Romain Guy1fbc1c82009-11-09 20:43:08 -0800887
Michael Jurkaaf442092010-06-10 17:01:57 -0700888 Drawable previous = mPreviousView.getDrawable();
889 Drawable next = mNextView.getDrawable();
890 mWorkspace.setIndicators(previous, next);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800891
Michael Jurkaaf442092010-06-10 17:01:57 -0700892 mPreviousView.setHapticFeedbackEnabled(false);
893 mPreviousView.setOnLongClickListener(this);
894 mNextView.setHapticFeedbackEnabled(false);
895 mNextView.setOnLongClickListener(this);
896 }
Romain Guy1fbc1c82009-11-09 20:43:08 -0800897
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800898 workspace.setOnLongClickListener(this);
Joe Onorato00acb122009-08-04 16:04:30 -0400899 workspace.setDragController(dragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800900 workspace.setLauncher(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800901
902 deleteZone.setLauncher(this);
Joe Onorato00acb122009-08-04 16:04:30 -0400903 deleteZone.setDragController(dragController);
Michael Jurka54f7ac32010-08-02 13:56:46 -0700904 int deleteZoneHandleId;
905 if (LauncherApplication.isScreenXLarge()) {
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700906 deleteZoneHandleId = R.id.all_apps_button;
Michael Jurka54f7ac32010-08-02 13:56:46 -0700907 } else {
908 deleteZoneHandleId = R.id.all_apps_button_cluster;
909 }
Michael Jurkaaf442092010-06-10 17:01:57 -0700910 deleteZone.setHandle(findViewById(deleteZoneHandleId));
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700911 dragController.addDragListener(deleteZone);
912
913 ApplicationInfoDropTarget infoButton = (ApplicationInfoDropTarget)findViewById(R.id.info_button);
914 if (infoButton != null) {
915 infoButton.setLauncher(this);
916 infoButton.setHandle(findViewById(R.id.configure_button));
917 infoButton.setDragColor(getResources().getColor(R.color.app_info_filter));
918 dragController.addDragListener(infoButton);
919 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800920
Joe Onorato00acb122009-08-04 16:04:30 -0400921 dragController.setDragScoller(workspace);
Joe Onorato00acb122009-08-04 16:04:30 -0400922 dragController.setScrollView(dragLayer);
Romain Guyea3763c2010-01-11 18:02:04 -0800923 dragController.setMoveTarget(workspace);
Jason Samsfd22dac2009-09-20 17:24:16 -0700924
Joe Onorato00acb122009-08-04 16:04:30 -0400925 // The order here is bottom to top.
926 dragController.addDropTarget(workspace);
927 dragController.addDropTarget(deleteZone);
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700928 if (infoButton != null) {
929 dragController.addDropTarget(infoButton);
930 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800931 }
932
Romain Guy8a73c512009-11-09 19:19:59 -0800933 @SuppressWarnings({"UnusedDeclaration"})
934 public void previousScreen(View v) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700935 if (mState != State.ALL_APPS) {
Joe Onorato61597bd2009-11-19 12:51:57 -0800936 mWorkspace.scrollLeft();
937 }
Romain Guy8a73c512009-11-09 19:19:59 -0800938 }
939
940 @SuppressWarnings({"UnusedDeclaration"})
941 public void nextScreen(View v) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700942 if (mState != State.ALL_APPS) {
Joe Onorato61597bd2009-11-19 12:51:57 -0800943 mWorkspace.scrollRight();
944 }
Romain Guy8a73c512009-11-09 19:19:59 -0800945 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400946
947 @SuppressWarnings({"UnusedDeclaration"})
948 public void launchHotSeat(View v) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700949 if (mState == State.ALL_APPS) return;
Daniel Sandler3e9454a2010-05-24 11:22:41 -0400950
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400951 int index = -1;
952 if (v.getId() == R.id.hotseat_left) {
953 index = 0;
954 } else if (v.getId() == R.id.hotseat_right) {
955 index = 1;
956 }
957
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400958 // reload these every tap; you never know when they might change
959 loadHotseats();
960 if (index >= 0 && index < mHotseats.length && mHotseats[index] != null) {
961 Intent intent = mHotseats[index];
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400962 startActivitySafely(
963 mHotseats[index],
964 "hotseat"
965 );
966 }
967 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700968
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800969 /**
970 * Creates a view representing a shortcut.
971 *
972 * @param info The data structure describing the shortcut.
973 *
974 * @return A View inflated from R.layout.application.
975 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800976 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800977 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -0700978 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800979 }
980
981 /**
982 * Creates a view representing a shortcut inflated from the specified resource.
983 *
984 * @param layoutResId The id of the XML layout used to create the shortcut.
985 * @param parent The group the shortcut belongs to.
986 * @param info The data structure describing the shortcut.
987 *
988 * @return A View inflated from layoutResId.
989 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800990 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800991 TextView favorite = (TextView) mInflater.inflate(layoutResId, parent, false);
992
Joe Onorato0589f0f2010-02-08 13:44:00 -0800993 favorite.setCompoundDrawablesWithIntrinsicBounds(null,
994 new FastBitmapDrawable(info.getIcon(mIconCache)),
995 null, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800996 favorite.setText(info.title);
997 favorite.setTag(info);
998 favorite.setOnClickListener(this);
999
1000 return favorite;
1001 }
1002
1003 /**
1004 * Add an application shortcut to the workspace.
1005 *
1006 * @param data The intent describing the application.
1007 * @param cellInfo The position on screen where to create the shortcut.
1008 */
Michael Jurka0280c3b2010-09-17 15:00:07 -07001009 void completeAddApplication(Context context, Intent data, int screen,
1010 int intersectCellX, int intersectCellY) {
1011 final int[] cellXY = mTmpAddItemCellCoordinates;
1012 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1013
1014 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1015 showOutOfSpaceMessage();
1016 return;
1017 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001018
Joe Onorato0589f0f2010-02-08 13:44:00 -08001019 final ShortcutInfo info = mModel.getShortcutInfo(context.getPackageManager(),
1020 data, context);
1021
Romain Guy73b979d2009-06-09 12:57:21 -07001022 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -08001023 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001024 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001025 info.container = ItemInfo.NO_ID;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001026 mWorkspace.addApplicationShortcut(info, screen, cellXY[0], cellXY[1],
1027 isWorkspaceLocked(), mAddIntersectCellX, mAddIntersectCellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001028 } else {
1029 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001030 }
1031 }
Romain Guycbb89e42009-06-08 15:52:54 -07001032
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001033 /**
1034 * Add a shortcut to the workspace.
1035 *
1036 * @param data The intent describing the shortcut.
1037 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001038 */
Michael Jurka0280c3b2010-09-17 15:00:07 -07001039 private void completeAddShortcut(Intent data, int screen,
1040 int intersectCellX, int intersectCellY) {
1041 final int[] cellXY = mTmpAddItemCellCoordinates;
1042 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
Romain Guycbb89e42009-06-08 15:52:54 -07001043
Michael Jurka0280c3b2010-09-17 15:00:07 -07001044 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1045 showOutOfSpaceMessage();
1046 return;
1047 }
1048
1049 final ShortcutInfo info = mModel.addShortcut(
1050 this, data, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001051
1052 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001053 final View view = createShortcut(info);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001054 mWorkspace.addInScreen(view, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001055 }
1056 }
1057
Romain Guycbb89e42009-06-08 15:52:54 -07001058
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001059 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001060 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001061 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001062 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001063 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001064 */
Michael Jurka0280c3b2010-09-17 15:00:07 -07001065 private void completeAddAppWidget(int appWidgetId, int screen) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001066 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Romain Guycbb89e42009-06-08 15:52:54 -07001067
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001068 // Calculate the grid spans needed to fit this widget
Michael Jurka0280c3b2010-09-17 15:00:07 -07001069 CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1070 int[] spanXY = layout.rectToCell(appWidgetInfo.minWidth, appWidgetInfo.minHeight, null);
Romain Guycbb89e42009-06-08 15:52:54 -07001071
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001072 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001073 // We have saved the position to which the widget was dragged-- this really only matters
1074 // if we are placing widgets on a "spring-loaded" screen
Michael Jurka0280c3b2010-09-17 15:00:07 -07001075 final int[] cellXY = mTmpAddItemCellCoordinates;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001076
1077 // For now, we don't save the coordinate where we dropped the icon because we're not
1078 // supporting spring-loaded mini-screens; however, leaving the ability to directly place
1079 // a widget on the home screen in case we want to add it in the future
Michael Jurka0280c3b2010-09-17 15:00:07 -07001080 final int[] touchXY = null;
1081 //final int[] touchXY = mAddDropPosition;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001082 boolean findNearestVacantAreaFailed = false;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001083 boolean foundCellSpan = false;
1084 if (touchXY != null) {
1085 // when dragging and dropping, just find the closest free spot
1086 CellLayout screenLayout = (CellLayout) mWorkspace.getChildAt(screen);
1087 int[] result = screenLayout.findNearestVacantArea(
1088 touchXY[0], touchXY[1], spanXY[0], spanXY[1], cellXY);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001089 findNearestVacantAreaFailed = (result == null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001090 foundCellSpan = !findNearestVacantAreaFailed;
1091 } else {
1092 if (mAddIntersectCellX != -1 && mAddIntersectCellY != -1) {
1093 // if we long pressed on an empty cell to bring up a menu,
1094 // make sure we intersect the empty cell
1095 foundCellSpan = layout.findCellForSpanThatIntersects(cellXY, spanXY[0], spanXY[1],
1096 mAddIntersectCellX, mAddIntersectCellY);
1097 } else {
1098 // if we went through the menu -> add, just find any spot
1099 foundCellSpan = layout.findCellForSpan(cellXY, spanXY[0], spanXY[1]);
1100 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001101 }
1102
Michael Jurka0280c3b2010-09-17 15:00:07 -07001103 if (!foundCellSpan) {
Romain Guy18042c82009-11-06 11:44:55 -08001104 if (appWidgetId != -1) mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001105 showOutOfSpaceMessage();
Romain Guy18042c82009-11-06 11:44:55 -08001106 return;
1107 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001108
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001109 // Build Launcher-specific widget info and save to database
1110 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001111 launcherInfo.spanX = spanXY[0];
1112 launcherInfo.spanY = spanXY[1];
Romain Guycbb89e42009-06-08 15:52:54 -07001113
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001114 LauncherModel.addItemToDatabase(this, launcherInfo,
1115 LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001116 screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001117
1118 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001119 mDesktopItems.add(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001120
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001121 // Perform actual inflation because we're live
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001122 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001123
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001124 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001125 launcherInfo.hostView.setTag(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001126
Michael Jurka0280c3b2010-09-17 15:00:07 -07001127 mWorkspace.addInScreen(launcherInfo.hostView, screen, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001128 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001129 }
1130 }
Romain Guycbb89e42009-06-08 15:52:54 -07001131
Michael Jurka0280c3b2010-09-17 15:00:07 -07001132 void showOutOfSpaceMessage() {
1133 Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show();
1134 }
1135
Joe Onorato9c1289c2009-08-17 11:03:03 -04001136 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
1137 mDesktopItems.remove(launcherInfo);
1138 launcherInfo.hostView = null;
1139 }
1140
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001141 public LauncherAppWidgetHost getAppWidgetHost() {
1142 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001143 }
Romain Guycbb89e42009-06-08 15:52:54 -07001144
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001145 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001146 getWindow().closeAllPanels();
1147
1148 try {
1149 dismissDialog(DIALOG_CREATE_SHORTCUT);
1150 // Unlock the workspace if the dialog was showing
1151 } catch (Exception e) {
1152 // An exception is thrown if the dialog is not visible, which is fine
1153 }
1154
1155 try {
1156 dismissDialog(DIALOG_RENAME_FOLDER);
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 }
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001161
1162 // Whatever we were doing is hereby canceled.
1163 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001164 }
1165
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001166 @Override
1167 protected void onNewIntent(Intent intent) {
1168 super.onNewIntent(intent);
1169
1170 // Close the menu
1171 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001172 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001173 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001174
Joe Onorato14f122b2009-11-19 14:06:36 -08001175 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1176 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001177
Michael Jurka4cb37242010-08-09 21:05:32 -07001178 // in all these cases, only animate if we're already on home
1179 if (LauncherApplication.isScreenXLarge()) {
Michael Jurka99229f62010-09-09 11:49:32 -07001180 mWorkspace.unshrink(alreadyOnHome);
1181 }
1182 if (!mWorkspace.isDefaultPageShowing()) {
Michael Jurka4cb37242010-08-09 21:05:32 -07001183 // on the phone, we don't animate the change to the workspace if all apps is visible
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001184 mWorkspace.moveToDefaultScreen(alreadyOnHome &&
1185 (LauncherApplication.isScreenXLarge() || mState != State.ALL_APPS));
Joe Onorato3a8820b2009-11-10 15:06:42 -08001186 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001187 showWorkspace(alreadyOnHome);
Romain Guy1dd3a072009-07-16 13:21:01 -07001188
Joe Onorato3a8820b2009-11-10 15:06:42 -08001189 final View v = getWindow().peekDecorView();
1190 if (v != null && v.getWindowToken() != null) {
1191 InputMethodManager imm = (InputMethodManager)getSystemService(
1192 INPUT_METHOD_SERVICE);
1193 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001194 }
1195 }
1196 }
1197
1198 @Override
1199 protected void onRestoreInstanceState(Bundle savedInstanceState) {
1200 // Do not call super here
1201 mSavedInstanceState = savedInstanceState;
Michael Jurka946ad472010-07-09 18:05:18 -07001202
1203 if (mHomeCustomizationDrawer != null) {
1204 String cur = savedInstanceState.getString("currentTab");
1205 if (cur != null) {
1206 mHomeCustomizationDrawer.setCurrentTabByTag(cur);
1207 }
1208 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001209 }
1210
1211 @Override
1212 protected void onSaveInstanceState(Bundle outState) {
Michael Jurka0142d492010-08-25 17:46:15 -07001213 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001214
1215 final ArrayList<Folder> folders = mWorkspace.getOpenFolders();
1216 if (folders.size() > 0) {
1217 final int count = folders.size();
1218 long[] ids = new long[count];
1219 for (int i = 0; i < count; i++) {
1220 final FolderInfo info = folders.get(i).getInfo();
1221 ids[i] = info.id;
1222 }
1223 outState.putLongArray(RUNTIME_STATE_USER_FOLDERS, ids);
1224 } else {
1225 super.onSaveInstanceState(outState);
1226 }
1227
Joe Onoratofb0ca672009-09-14 17:55:46 -04001228 // TODO should not do this if the drawer is currently closing.
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001229 if (mState == State.ALL_APPS) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001230 outState.putBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, true);
Romain Guy5a941392009-04-28 15:18:25 -07001231 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001232
Michael Jurka0280c3b2010-09-17 15:00:07 -07001233 if (mAddScreen > -1 && mWaitingForResult) {
1234 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mAddScreen);
1235 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mAddIntersectCellX);
1236 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001237 }
1238
1239 if (mFolderInfo != null && mWaitingForResult) {
1240 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1241 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1242 }
Michael Jurka946ad472010-07-09 18:05:18 -07001243
1244 if (mHomeCustomizationDrawer != null) {
1245 String currentTabTag = mHomeCustomizationDrawer.getCurrentTabTag();
1246 if (currentTabTag != null) {
1247 outState.putString("currentTab", currentTabTag);
1248 }
1249 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001250 }
1251
1252 @Override
1253 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001254 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001255
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001256 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001257 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001258 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001259 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001260 }
1261
1262 TextKeyListener.getInstance().release();
1263
Joe Onorato9c1289c2009-08-17 11:03:03 -04001264 mModel.stopLoader();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001265
Joe Onorato9c1289c2009-08-17 11:03:03 -04001266 unbindDesktopItems();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001267
1268 getContentResolver().unregisterContentObserver(mWidgetObserver);
Winson Chungaafa03c2010-06-11 17:34:16 -07001269
Patrick Dubroyab962b72010-07-26 12:10:10 -07001270 // Some launcher layouts don't have a previous and next view
1271 if (mPreviousView != null) {
1272 dismissPreview(mPreviousView);
1273 }
1274 if (mNextView != null) {
1275 dismissPreview(mNextView);
1276 }
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001277
1278 unregisterReceiver(mCloseSystemDialogsReceiver);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001279 }
1280
1281 @Override
1282 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001283 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001284 super.startActivityForResult(intent, requestCode);
1285 }
1286
1287 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001288 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001289 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001290
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001291 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001292
Karl Rosaen138a0412009-04-23 19:00:21 -07001293 if (initialQuery == null) {
1294 // Use any text typed in the launcher as the initial query
1295 initialQuery = getTypedText();
1296 clearTypedText();
1297 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001298 if (appSearchData == null) {
1299 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +00001300 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001301 }
Romain Guycbb89e42009-06-08 15:52:54 -07001302
Karl Rosaen138a0412009-04-23 19:00:21 -07001303 final SearchManager searchManager =
1304 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Karl Rosaen138a0412009-04-23 19:00:21 -07001305 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Romain Guycbb89e42009-06-08 15:52:54 -07001306 appSearchData, globalSearch);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001307 }
1308
1309 @Override
1310 public boolean onCreateOptionsMenu(Menu menu) {
Patrick Dubroy5905bca2010-09-08 22:43:38 -07001311 if (isWorkspaceLocked()) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001312 return false;
1313 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001314
1315 super.onCreateOptionsMenu(menu);
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001316
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001317 menu.add(MENU_GROUP_ADD, MENU_ADD, 0, R.string.menu_add)
1318 .setIcon(android.R.drawable.ic_menu_add)
1319 .setAlphabeticShortcut('A');
Winson Chung7ad01412010-09-27 11:33:03 -07001320 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1321 .setIcon(android.R.drawable.ic_menu_manage)
1322 .setAlphabeticShortcut('M');
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001323 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001324 .setIcon(android.R.drawable.ic_menu_gallery)
1325 .setAlphabeticShortcut('W');
1326 menu.add(0, MENU_SEARCH, 0, R.string.menu_search)
1327 .setIcon(android.R.drawable.ic_search_category_default)
1328 .setAlphabeticShortcut(SearchManager.MENU_KEY);
1329 menu.add(0, MENU_NOTIFICATIONS, 0, R.string.menu_notifications)
1330 .setIcon(com.android.internal.R.drawable.ic_menu_notifications)
1331 .setAlphabeticShortcut('N');
1332
1333 final Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
Romain Guy5a941392009-04-28 15:18:25 -07001334 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
1335 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001336
1337 menu.add(0, MENU_SETTINGS, 0, R.string.menu_settings)
1338 .setIcon(android.R.drawable.ic_menu_preferences).setAlphabeticShortcut('P')
1339 .setIntent(settings);
1340
1341 return true;
1342 }
1343
1344 @Override
1345 public boolean onPrepareOptionsMenu(Menu menu) {
1346 super.onPrepareOptionsMenu(menu);
1347
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001348 // If all apps is animating, don't show the menu, because we don't know
1349 // which one to show.
Patrick Dubroyff5f0402010-07-26 15:23:26 -07001350 if (mAllAppsGrid.isAnimating()) {
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001351 return false;
1352 }
1353
1354 // Only show the add and wallpaper options when we're not in all apps.
Patrick Dubroyff5f0402010-07-26 15:23:26 -07001355 boolean visible = !mAllAppsGrid.isVisible();
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001356 menu.setGroupVisible(MENU_GROUP_ADD, visible);
1357 menu.setGroupVisible(MENU_GROUP_WALLPAPER, visible);
1358
1359 // Disable add if the workspace is full.
1360 if (visible) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001361 CellLayout layout = (CellLayout) mWorkspace.getChildAt(mWorkspace.getCurrentPage());
1362 menu.setGroupEnabled(MENU_GROUP_ADD, layout.existsEmptyCell());
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001363 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001364
1365 return true;
1366 }
1367
1368 @Override
1369 public boolean onOptionsItemSelected(MenuItem item) {
1370 switch (item.getItemId()) {
1371 case MENU_ADD:
1372 addItems();
1373 return true;
Winson Chung7ad01412010-09-27 11:33:03 -07001374 case MENU_MANAGE_APPS:
1375 manageApps();
1376 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001377 case MENU_WALLPAPER_SETTINGS:
1378 startWallpaper();
1379 return true;
1380 case MENU_SEARCH:
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001381 onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001382 return true;
1383 case MENU_NOTIFICATIONS:
1384 showNotifications();
1385 return true;
1386 }
1387
1388 return super.onOptionsItemSelected(item);
1389 }
Romain Guycbb89e42009-06-08 15:52:54 -07001390
Karl Rosaen138a0412009-04-23 19:00:21 -07001391 /**
1392 * Indicates that we want global search for this activity by setting the globalSearch
1393 * argument for {@link #startSearch} to true.
1394 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001395
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001396 @Override
1397 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001398 startSearch(null, false, null, true);
Karl Rosaen138a0412009-04-23 19:00:21 -07001399 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001400 }
1401
Joe Onorato9c1289c2009-08-17 11:03:03 -04001402 public boolean isWorkspaceLocked() {
1403 return mWorkspaceLoading || mWaitingForResult;
1404 }
1405
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001406 private void addItems() {
Patrick Dubroy558654c2010-07-23 16:48:11 -07001407 if (LauncherApplication.isScreenXLarge()) {
1408 // Animate the widget chooser up from the bottom of the screen
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001409 if (mState != State.CUSTOMIZE) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07001410 showCustomizationDrawer(true);
Patrick Dubroy558654c2010-07-23 16:48:11 -07001411 }
1412 } else {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001413 showWorkspace(true);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001414 showAddDialog(-1, -1);
Patrick Dubroy558654c2010-07-23 16:48:11 -07001415 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001416 }
1417
Michael Jurka0280c3b2010-09-17 15:00:07 -07001418 private void resetAddInfo() {
1419 mAddScreen = -1;
1420 mAddIntersectCellX = -1;
1421 mAddIntersectCellY = -1;
1422 mAddDropPosition = null;
1423 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001424
Michael Jurka0280c3b2010-09-17 15:00:07 -07001425 void addAppWidgetFromDrop(ComponentName appWidgetProvider, int screen, int[] position) {
1426 resetAddInfo();
1427 mAddScreen = screen;
1428
1429 // only set mAddDropPosition if we dropped on home screen in "spring-loaded" manner
1430 mAddDropPosition = position;
1431
Michael Jurkaaf442092010-06-10 17:01:57 -07001432 int appWidgetId = getAppWidgetHost().allocateAppWidgetId();
1433 AppWidgetManager.getInstance(this).bindAppWidgetId(appWidgetId, appWidgetProvider);
1434 addAppWidgetImpl(appWidgetId);
1435 }
1436
Winson Chung7ad01412010-09-27 11:33:03 -07001437 private void manageApps() {
1438 startActivity(new Intent(android.provider.Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS));
1439 }
1440
Michael Jurkaaf442092010-06-10 17:01:57 -07001441 void addAppWidgetFromPick(Intent data) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001442 // TODO: catch bad widget exception when sent
1443 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurkaaf442092010-06-10 17:01:57 -07001444 // TODO: Is this log message meaningful?
1445 if (LOGD) Log.d(TAG, "dumping extras content=" + data.getExtras());
1446 addAppWidgetImpl(appWidgetId);
1447 }
1448
1449 void addAppWidgetImpl(int appWidgetId) {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001450 AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001451
Bjorn Bringert7984c942009-12-09 15:38:25 +00001452 if (appWidget.configure != null) {
1453 // Launch over to configure widget, if needed
1454 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
1455 intent.setComponent(appWidget.configure);
1456 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
1457
Romain Guy8e633c52010-03-04 12:51:36 -08001458 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001459 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001460 // Otherwise just add it
Michael Jurka0280c3b2010-09-17 15:00:07 -07001461 completeAddAppWidget(appWidgetId, mAddScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001462 }
1463 }
Romain Guycbb89e42009-06-08 15:52:54 -07001464
Michael Jurka0280c3b2010-09-17 15:00:07 -07001465 void processShortcutFromDrop(ComponentName componentName, int screen, int[] position) {
1466 resetAddInfo();
1467 mAddScreen = screen;
1468 mAddDropPosition = position;
1469
1470 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1471 createShortcutIntent.setComponent(componentName);
1472 processShortcut(createShortcutIntent);
1473 }
1474
Joe Onoratodeb98af2010-02-19 14:59:39 -08001475 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001476 // Handle case where user selected "Applications"
1477 String applicationName = getResources().getString(R.string.group_applications);
1478 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001479
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001480 if (applicationName != null && applicationName.equals(shortcutName)) {
1481 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1482 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001483
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001484 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1485 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07001486 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Joe Onorato4a79a042010-09-24 16:17:21 -07001487 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001488 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001489 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001490 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001491 }
1492
Winson Chung24ab2f12010-09-16 14:10:47 -07001493 void processWallpaper(Intent intent) {
1494 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1495 }
1496
Michael Jurka0280c3b2010-09-17 15:00:07 -07001497 void addLiveFolderFromDrop(ComponentName componentName, int screen, int[] position) {
1498 resetAddInfo();
1499 mAddScreen = screen;
1500 mAddDropPosition = position;
1501
1502 Intent createFolderIntent = new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER);
1503 createFolderIntent.setComponent(componentName);
1504
1505 addLiveFolder(createFolderIntent);
1506 }
1507
1508 void addLiveFolder(Intent intent) { // YYY add screen intersect etc. parameters here
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001509 // Handle case where user selected "Folder"
Jeffrey Sharkeyc4bbd0a2009-03-24 22:47:52 -07001510 String folderName = getResources().getString(R.string.group_folder);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001511 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001512
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001513 if (folderName != null && folderName.equals(shortcutName)) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001514 addFolder(mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001515 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001516 startActivityForResultSafely(intent, REQUEST_CREATE_LIVE_FOLDER);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001517 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001518 }
1519
Michael Jurka0280c3b2010-09-17 15:00:07 -07001520 void addFolder(int screen, int intersectCellX, int intersectCellY) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001521 UserFolderInfo folderInfo = new UserFolderInfo();
1522 folderInfo.title = getText(R.string.folder_name);
1523
Michael Jurka0280c3b2010-09-17 15:00:07 -07001524 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1525 final int[] cellXY = mTmpAddItemCellCoordinates;
1526 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1527 showOutOfSpaceMessage();
1528 return;
1529 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001530
1531 // Update the model
Joe Onorato9c1289c2009-08-17 11:03:03 -04001532 LauncherModel.addItemToDatabase(this, folderInfo,
1533 LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001534 screen, cellXY[0], cellXY[1], false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001535 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001536
1537 // Create the view
1538 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07001539 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), folderInfo);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001540 mWorkspace.addInScreen(newFolder, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001541 }
Romain Guycbb89e42009-06-08 15:52:54 -07001542
Joe Onorato9c1289c2009-08-17 11:03:03 -04001543 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001544 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001545 }
1546
Michael Jurka28750fb2010-09-24 17:43:49 -07001547 private void completeAddLiveFolder(
1548 Intent data, int screen, int intersectCellX, int intersectCellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001549 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1550 final int[] cellXY = mTmpAddItemCellCoordinates;
1551 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1552 showOutOfSpaceMessage();
1553 return;
1554 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001555
Michael Jurka0280c3b2010-09-17 15:00:07 -07001556 final LiveFolderInfo info = addLiveFolder(this, data, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001557
1558 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001559 final View view = LiveFolderIcon.fromXml(R.layout.live_folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07001560 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001561 mWorkspace.addInScreen(view, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001562 }
1563 }
1564
1565 static LiveFolderInfo addLiveFolder(Context context, Intent data,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001566 int screen, int cellX, int cellY, boolean notify) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001567
1568 Intent baseIntent = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT);
1569 String name = data.getStringExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME);
1570
1571 Drawable icon = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001572 Intent.ShortcutIconResource iconResource = null;
1573
1574 Parcelable extra = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON);
1575 if (extra != null && extra instanceof Intent.ShortcutIconResource) {
1576 try {
1577 iconResource = (Intent.ShortcutIconResource) extra;
1578 final PackageManager packageManager = context.getPackageManager();
1579 Resources resources = packageManager.getResourcesForApplication(
1580 iconResource.packageName);
1581 final int id = resources.getIdentifier(iconResource.resourceName, null, null);
1582 icon = resources.getDrawable(id);
1583 } catch (Exception e) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001584 Log.w(TAG, "Could not load live folder icon: " + extra);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001585 }
1586 }
1587
1588 if (icon == null) {
1589 icon = context.getResources().getDrawable(R.drawable.ic_launcher_folder);
1590 }
1591
1592 final LiveFolderInfo info = new LiveFolderInfo();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001593 info.icon = Utilities.createIconBitmap(icon, context);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001594 info.title = name;
1595 info.iconResource = iconResource;
1596 info.uri = data.getData();
1597 info.baseIntent = baseIntent;
1598 info.displayMode = data.getIntExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE,
1599 LiveFolders.DISPLAY_MODE_GRID);
1600
1601 LauncherModel.addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001602 screen, cellX, cellY, notify);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001603 sFolders.put(info.id, info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001604
1605 return info;
1606 }
1607
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001608 private void showNotifications() {
1609 final StatusBarManager statusBar = (StatusBarManager) getSystemService(STATUS_BAR_SERVICE);
1610 if (statusBar != null) {
1611 statusBar.expand();
1612 }
1613 }
1614
1615 private void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001616 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001617 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001618 Intent chooser = Intent.createChooser(pickWallpaper,
1619 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001620 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1621 // Removed in Eclair MR1
1622// WallpaperManager wm = (WallpaperManager)
1623// getSystemService(Context.WALLPAPER_SERVICE);
1624// WallpaperInfo wi = wm.getWallpaperInfo();
1625// if (wi != null && wi.getSettingsActivity() != null) {
1626// LabeledIntent li = new LabeledIntent(getPackageName(),
1627// R.string.configure_wallpaper, 0);
1628// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1629// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1630// }
Mike Clerona0618e42009-10-22 13:55:21 -07001631 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001632 }
1633
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001634 /**
1635 * Registers various content observers. The current implementation registers
1636 * only a favorites observer to keep track of the favorites applications.
1637 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001638 private void registerContentObservers() {
1639 ContentResolver resolver = getContentResolver();
1640 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1641 true, mWidgetObserver);
1642 }
1643
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001644 @Override
1645 public boolean dispatchKeyEvent(KeyEvent event) {
1646 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1647 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001648 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001649 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001650 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jason Samseb5615d2009-11-30 11:50:10 -08001651 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
Joe Onoratobe386092009-11-17 17:32:16 -08001652 dumpState();
1653 return true;
1654 }
1655 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001656 }
1657 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1658 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001659 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001660 return true;
1661 }
1662 }
1663
1664 return super.dispatchKeyEvent(event);
1665 }
1666
Joe Onorato88ec0992009-11-19 13:16:06 -08001667 @Override
1668 public void onBackPressed() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001669 if (mState == State.ALL_APPS || mState == State.CUSTOMIZE) {
1670 showWorkspace(true);
Joe Onorato88ec0992009-11-19 13:16:06 -08001671 } else {
1672 closeFolder();
1673 }
Michael Jurkaaf442092010-06-10 17:01:57 -07001674 // Some launcher layouts don't have a previous and next view
1675 if (mPreviousView != null) {
1676 dismissPreview(mPreviousView);
1677 dismissPreview(mNextView);
1678 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001679 }
1680
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001681 private void closeFolder() {
1682 Folder folder = mWorkspace.getOpenFolder();
1683 if (folder != null) {
1684 closeFolder(folder);
1685 }
1686 }
1687
1688 void closeFolder(Folder folder) {
1689 folder.getInfo().opened = false;
1690 ViewGroup parent = (ViewGroup) folder.getParent();
1691 if (parent != null) {
1692 parent.removeView(folder);
Joe Onoratob6341e92009-11-02 10:41:48 -05001693 if (folder instanceof DropTarget) {
1694 // Live folders aren't DropTargets.
1695 mDragController.removeDropTarget((DropTarget)folder);
1696 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001697 }
1698 folder.onClose();
1699 }
1700
1701 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001702 * Re-listen when widgets are reset.
1703 */
1704 private void onAppWidgetReset() {
1705 mAppWidgetHost.startListening();
1706 }
1707
1708 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001709 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1710 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001711 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04001712 private void unbindDesktopItems() {
1713 for (ItemInfo item: mDesktopItems) {
1714 item.unbind();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001715 }
1716 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001717
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001718 /**
1719 * Launches the intent referred by the clicked shortcut.
1720 *
1721 * @param v The view representing the clicked shortcut.
1722 */
1723 public void onClick(View v) {
1724 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001725 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001726 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08001727 final Intent intent = ((ShortcutInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001728 int[] pos = new int[2];
1729 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08001730 intent.setSourceBounds(new Rect(pos[0], pos[1],
1731 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Joe Onoratof984e852010-03-25 09:47:45 -07001732 startActivitySafely(intent, tag);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001733 } else if (tag instanceof FolderInfo) {
1734 handleFolderClick((FolderInfo) tag);
Joe Onorato7404ee42009-07-31 11:54:44 -07001735 } else if (v == mHandleView) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001736 if (mState == State.ALL_APPS) {
1737 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001738 } else {
Joe Onorato3a8820b2009-11-10 15:06:42 -08001739 showAllApps(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001740 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001741 }
1742 }
1743
Michael Jurka0e260592010-06-30 17:07:39 -07001744 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07001745 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001746 // clicking anywhere on the workspace causes the customization drawer to slide down
1747 showWorkspace(true);
Michael Jurka0e260592010-06-30 17:07:39 -07001748 return false;
1749 }
1750
Michael Jurkaaf442092010-06-10 17:01:57 -07001751 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001752 * Event handler for the search button
1753 *
1754 * @param v The view that was clicked.
1755 */
1756 public void onClickSearchButton(View v) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07001757 startSearch(null, false, null, true);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001758 }
1759
1760 /**
1761 * Event handler for the "gear" button that appears on the home screen, which
Michael Jurkaaf442092010-06-10 17:01:57 -07001762 * enters home screen customization mode.
1763 *
1764 * @param v The view that was clicked.
1765 */
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001766 public void onClickConfigureButton(View v) {
Patrick Dubroy558654c2010-07-23 16:48:11 -07001767 addItems();
Michael Jurkaaf442092010-06-10 17:01:57 -07001768 }
1769
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001770 /**
1771 * Event handler for the "grid" button that appears on the home screen, which
1772 * enters all apps mode.
1773 *
1774 * @param v The view that was clicked.
1775 */
1776 public void onClickAllAppsButton(View v) {
1777 showAllApps(true);
1778 }
1779
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001780 public void onClickAppMarketButton(View v) {
1781 if (mAppMarketIntent != null) {
1782 startActivitySafely(mAppMarketIntent, "app market");
1783 }
1784 }
1785
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001786 void startApplicationDetailsActivity(ComponentName componentName) {
1787 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001788 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
1789 Uri.fromParts("package", packageName, null));
1790 startActivity(intent);
1791 }
1792
Patrick Dubroy5539af72010-09-07 15:22:01 -07001793 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
1794 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
1795 // System applications cannot be installed. For now, show a toast explaining that.
1796 // We may give them the option of disabling apps this way.
1797 int messageId = R.string.uninstall_system_app_text;
1798 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
1799 } else {
1800 String packageName = appInfo.componentName.getPackageName();
1801 String className = appInfo.componentName.getClassName();
1802 Intent intent = new Intent(
1803 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
1804 startActivity(intent);
1805 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001806 }
1807
Joe Onoratof984e852010-03-25 09:47:45 -07001808 void startActivitySafely(Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001809 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1810 try {
1811 startActivity(intent);
1812 } catch (ActivityNotFoundException e) {
1813 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Daniel Sandlerc9b18772010-04-22 14:37:59 -04001814 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001815 } catch (SecurityException e) {
1816 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001817 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001818 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07001819 "or use the exported attribute for this activity. "
1820 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001821 }
1822 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001823
Romain Guy8e633c52010-03-04 12:51:36 -08001824 void startActivityForResultSafely(Intent intent, int requestCode) {
1825 try {
1826 startActivityForResult(intent, requestCode);
1827 } catch (ActivityNotFoundException e) {
1828 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1829 } catch (SecurityException e) {
1830 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1831 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
1832 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
1833 "or use the exported attribute for this activity.", e);
1834 }
1835 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001836
1837 private void handleFolderClick(FolderInfo folderInfo) {
1838 if (!folderInfo.opened) {
1839 // Close any open folder
1840 closeFolder();
1841 // Open the requested folder
1842 openFolder(folderInfo);
1843 } else {
1844 // Find the open folder...
1845 Folder openFolder = mWorkspace.getFolderForTag(folderInfo);
1846 int folderScreen;
1847 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07001848 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001849 // .. and close it
1850 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07001851 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001852 // Close any folder open on the current screen
1853 closeFolder();
1854 // Pull the folder onto this screen
1855 openFolder(folderInfo);
1856 }
1857 }
1858 }
1859 }
1860
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001861 /**
1862 * Opens the user fodler described by the specified tag. The opening of the folder
1863 * is animated relative to the specified View. If the View is null, no animation
1864 * is played.
1865 *
1866 * @param folderInfo The FolderInfo describing the folder to open.
1867 */
Winson Chungaafa03c2010-06-11 17:34:16 -07001868 public void openFolder(FolderInfo folderInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001869 Folder openFolder;
1870
1871 if (folderInfo instanceof UserFolderInfo) {
1872 openFolder = UserFolder.fromXml(this);
1873 } else if (folderInfo instanceof LiveFolderInfo) {
Joe Onoratoa5902522009-07-30 13:37:37 -07001874 openFolder = com.android.launcher2.LiveFolder.fromXml(this, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001875 } else {
1876 return;
1877 }
1878
Joe Onorato00acb122009-08-04 16:04:30 -04001879 openFolder.setDragController(mDragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001880 openFolder.setLauncher(this);
1881
1882 openFolder.bind(folderInfo);
1883 folderInfo.opened = true;
1884
Winson Chungaafa03c2010-06-11 17:34:16 -07001885 mWorkspace.addInFullScreen(openFolder, folderInfo.screen);
1886
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001887 openFolder.onOpen();
1888 }
1889
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001890 public boolean onLongClick(View v) {
Romain Guy1fbc1c82009-11-09 20:43:08 -08001891 switch (v.getId()) {
1892 case R.id.previous_screen:
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001893 if (mState != State.ALL_APPS) {
Joe Onorato0d44e942009-11-16 18:20:51 -08001894 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1895 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Romain Guyf8e6a802009-12-07 17:48:02 -08001896 showPreviews(v);
Joe Onorato0d44e942009-11-16 18:20:51 -08001897 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08001898 return true;
1899 case R.id.next_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);
1904 }
1905 return true;
1906 case R.id.all_apps_button:
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001907 if (mState != State.ALL_APPS) {
Romain Guyf8e6a802009-12-07 17:48:02 -08001908 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1909 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
1910 showPreviews(v);
Joe Onorato0d44e942009-11-16 18:20:51 -08001911 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08001912 return true;
1913 }
1914
Joe Onorato9c1289c2009-08-17 11:03:03 -04001915 if (isWorkspaceLocked()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001916 return false;
1917 }
1918
1919 if (!(v instanceof CellLayout)) {
1920 v = (View) v.getParent();
1921 }
1922
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001923
Michael Jurka0280c3b2010-09-17 15:00:07 -07001924 resetAddInfo();
1925 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001926 // This happens when long clicking an item with the dpad/trackball
Michael Jurka0280c3b2010-09-17 15:00:07 -07001927 if (longClickCellInfo == null || !longClickCellInfo.valid) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001928 return true;
1929 }
1930
Michael Jurka0280c3b2010-09-17 15:00:07 -07001931 final View itemUnderLongClick = longClickCellInfo.cell;
1932
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001933 if (mWorkspace.allowLongPress()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001934 if (itemUnderLongClick == null) {
1935 // User long pressed on empty space
1936 mWorkspace.setAllowLongPress(false);
1937 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1938 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Michael Jurka56170562010-10-05 14:14:56 -07001939 if (!LauncherApplication.isScreenXLarge()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001940 showAddDialog(longClickCellInfo.cellX, longClickCellInfo.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001941 }
1942 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001943 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001944 // User long pressed on an item
Joe Onorato0d44e942009-11-16 18:20:51 -08001945 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1946 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001947 mAddIntersectCellX = longClickCellInfo.cellX;
1948 mAddIntersectCellY = longClickCellInfo.cellY;
1949 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001950 }
1951 }
1952 }
1953 return true;
1954 }
1955
Romain Guye6b8e2f2009-11-10 11:56:55 -08001956 @SuppressWarnings({"unchecked"})
Romain Guy9d31e9f2009-11-11 18:54:28 -08001957 private void dismissPreview(final View v) {
1958 final PopupWindow window = (PopupWindow) v.getTag();
Romain Guy1fbc1c82009-11-09 20:43:08 -08001959 if (window != null) {
Romain Guy9d31e9f2009-11-11 18:54:28 -08001960 window.setOnDismissListener(new PopupWindow.OnDismissListener() {
1961 public void onDismiss() {
1962 ViewGroup group = (ViewGroup) v.getTag(R.id.workspace);
1963 int count = group.getChildCount();
1964 for (int i = 0; i < count; i++) {
1965 ((ImageView) group.getChildAt(i)).setImageDrawable(null);
1966 }
Romain Guy9d31e9f2009-11-11 18:54:28 -08001967 ArrayList<Bitmap> bitmaps = (ArrayList<Bitmap>) v.getTag(R.id.icon);
1968 for (Bitmap bitmap : bitmaps) bitmap.recycle();
1969
1970 v.setTag(R.id.workspace, null);
1971 v.setTag(R.id.icon, null);
1972 window.setOnDismissListener(null);
1973 }
1974 });
Romain Guy1fbc1c82009-11-09 20:43:08 -08001975 window.dismiss();
Romain Guy1fbc1c82009-11-09 20:43:08 -08001976 }
1977 v.setTag(null);
1978 }
1979
Romain Guyf8e6a802009-12-07 17:48:02 -08001980 private void showPreviews(View anchor) {
Romain Guy9d31e9f2009-11-11 18:54:28 -08001981 showPreviews(anchor, 0, mWorkspace.getChildCount());
Romain Guy1fbc1c82009-11-09 20:43:08 -08001982 }
1983
Romain Guya6abce82009-11-10 02:54:41 -08001984 private void showPreviews(final View anchor, int start, int end) {
Romain Guyf8e6a802009-12-07 17:48:02 -08001985 final Resources resources = getResources();
1986 final Workspace workspace = mWorkspace;
Romain Guy1fbc1c82009-11-09 20:43:08 -08001987
Romain Guya6abce82009-11-10 02:54:41 -08001988 CellLayout cell = ((CellLayout) workspace.getChildAt(start));
Winson Chungaafa03c2010-06-11 17:34:16 -07001989
Romain Guy9d31e9f2009-11-11 18:54:28 -08001990 float max = workspace.getChildCount();
Winson Chungaafa03c2010-06-11 17:34:16 -07001991
Romain Guyf8e6a802009-12-07 17:48:02 -08001992 final Rect r = new Rect();
Romain Guy9d31e9f2009-11-11 18:54:28 -08001993 resources.getDrawable(R.drawable.preview_background).getPadding(r);
Romain Guye6b8e2f2009-11-10 11:56:55 -08001994 int extraW = (int) ((r.left + r.right) * max);
1995 int extraH = r.top + r.bottom;
Romain Guya6abce82009-11-10 02:54:41 -08001996
1997 int aW = cell.getWidth() - extraW;
1998 float w = aW / max;
1999
2000 int width = cell.getWidth();
2001 int height = cell.getHeight();
2002 int x = cell.getLeftPadding();
2003 int y = cell.getTopPadding();
2004 width -= (x + cell.getRightPadding());
2005 height -= (y + cell.getBottomPadding());
2006
2007 float scale = w / width;
2008
2009 int count = end - start;
2010
2011 final float sWidth = width * scale;
2012 float sHeight = height * scale;
2013
Romain Guye6b8e2f2009-11-10 11:56:55 -08002014 LinearLayout preview = new LinearLayout(this);
Romain Guya6abce82009-11-10 02:54:41 -08002015
Romain Guye6b8e2f2009-11-10 11:56:55 -08002016 PreviewTouchHandler handler = new PreviewTouchHandler(anchor);
2017 ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>(count);
Romain Guya6abce82009-11-10 02:54:41 -08002018
2019 for (int i = start; i < end; i++) {
Romain Guye6b8e2f2009-11-10 11:56:55 -08002020 ImageView image = new ImageView(this);
Romain Guya6abce82009-11-10 02:54:41 -08002021 cell = (CellLayout) workspace.getChildAt(i);
2022
Romain Guyf8e6a802009-12-07 17:48:02 -08002023 final Bitmap bitmap = Bitmap.createBitmap((int) sWidth, (int) sHeight,
Romain Guye6b8e2f2009-11-10 11:56:55 -08002024 Bitmap.Config.ARGB_8888);
Romain Guyf8e6a802009-12-07 17:48:02 -08002025
2026 final Canvas c = new Canvas(bitmap);
Romain Guya6abce82009-11-10 02:54:41 -08002027 c.scale(scale, scale);
2028 c.translate(-cell.getLeftPadding(), -cell.getTopPadding());
Patrick Dubroy1262e362010-10-06 15:49:50 -07002029 cell.drawChildren(c);
Romain Guya6abce82009-11-10 02:54:41 -08002030
Romain Guy9d31e9f2009-11-11 18:54:28 -08002031 image.setBackgroundDrawable(resources.getDrawable(R.drawable.preview_background));
Romain Guye6b8e2f2009-11-10 11:56:55 -08002032 image.setImageBitmap(bitmap);
2033 image.setTag(i);
2034 image.setOnClickListener(handler);
Romain Guy9d31e9f2009-11-11 18:54:28 -08002035 image.setOnFocusChangeListener(handler);
2036 image.setFocusable(true);
Michael Jurka0142d492010-08-25 17:46:15 -07002037 if (i == mWorkspace.getCurrentPage()) image.requestFocus();
Romain Guye6b8e2f2009-11-10 11:56:55 -08002038
2039 preview.addView(image,
Romain Guy9d31e9f2009-11-11 18:54:28 -08002040 LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
2041
Winson Chungaafa03c2010-06-11 17:34:16 -07002042 bitmaps.add(bitmap);
Romain Guya6abce82009-11-10 02:54:41 -08002043 }
Romain Guyf8e6a802009-12-07 17:48:02 -08002044
2045 final PopupWindow p = new PopupWindow(this);
Romain Guye6b8e2f2009-11-10 11:56:55 -08002046 p.setContentView(preview);
2047 p.setWidth((int) (sWidth * count + extraW));
2048 p.setHeight((int) (sHeight + extraH));
2049 p.setAnimationStyle(R.style.AnimationPreview);
2050 p.setOutsideTouchable(true);
Romain Guy9d31e9f2009-11-11 18:54:28 -08002051 p.setFocusable(true);
Romain Guyff0c2e22009-11-10 12:09:59 -08002052 p.setBackgroundDrawable(new ColorDrawable(0));
Romain Guy9d31e9f2009-11-11 18:54:28 -08002053 p.showAsDropDown(anchor, 0, 0);
Romain Guya6abce82009-11-10 02:54:41 -08002054
Romain Guye6b8e2f2009-11-10 11:56:55 -08002055 p.setOnDismissListener(new PopupWindow.OnDismissListener() {
2056 public void onDismiss() {
2057 dismissPreview(anchor);
2058 }
2059 });
Romain Guy1fbc1c82009-11-09 20:43:08 -08002060
2061 anchor.setTag(p);
2062 anchor.setTag(R.id.workspace, preview);
Winson Chungaafa03c2010-06-11 17:34:16 -07002063 anchor.setTag(R.id.icon, bitmaps);
Romain Guy1fbc1c82009-11-09 20:43:08 -08002064 }
2065
Romain Guy9d31e9f2009-11-11 18:54:28 -08002066 class PreviewTouchHandler implements View.OnClickListener, Runnable, View.OnFocusChangeListener {
Romain Guya6abce82009-11-10 02:54:41 -08002067 private final View mAnchor;
Romain Guya6abce82009-11-10 02:54:41 -08002068
Romain Guye6b8e2f2009-11-10 11:56:55 -08002069 public PreviewTouchHandler(View anchor) {
Romain Guya6abce82009-11-10 02:54:41 -08002070 mAnchor = anchor;
Romain Guya6abce82009-11-10 02:54:41 -08002071 }
2072
2073 public void onClick(View v) {
Michael Jurka0142d492010-08-25 17:46:15 -07002074 mWorkspace.snapToPage((Integer) v.getTag());
Romain Guy9d31e9f2009-11-11 18:54:28 -08002075 v.post(this);
2076 }
2077
2078 public void run() {
Winson Chungaafa03c2010-06-11 17:34:16 -07002079 dismissPreview(mAnchor);
Romain Guy9d31e9f2009-11-11 18:54:28 -08002080 }
2081
2082 public void onFocusChange(View v, boolean hasFocus) {
2083 if (hasFocus) {
Michael Jurka0142d492010-08-25 17:46:15 -07002084 mWorkspace.snapToPage((Integer) v.getTag());
Romain Guy9d31e9f2009-11-11 18:54:28 -08002085 }
Romain Guya6abce82009-11-10 02:54:41 -08002086 }
2087 }
2088
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002089 Workspace getWorkspace() {
2090 return mWorkspace;
2091 }
2092
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002093 @Override
2094 protected Dialog onCreateDialog(int id) {
2095 switch (id) {
2096 case DIALOG_CREATE_SHORTCUT:
2097 return new CreateShortcut().createDialog();
2098 case DIALOG_RENAME_FOLDER:
2099 return new RenameFolder().createDialog();
2100 }
2101
2102 return super.onCreateDialog(id);
2103 }
2104
2105 @Override
2106 protected void onPrepareDialog(int id, Dialog dialog) {
2107 switch (id) {
2108 case DIALOG_CREATE_SHORTCUT:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002109 break;
2110 case DIALOG_RENAME_FOLDER:
Romain Guy7b4ef332009-07-14 13:58:08 -07002111 if (mFolderInfo != null) {
2112 EditText input = (EditText) dialog.findViewById(R.id.folder_name);
2113 final CharSequence text = mFolderInfo.title;
2114 input.setText(text);
2115 input.setSelection(0, text.length());
2116 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002117 break;
2118 }
2119 }
2120
2121 void showRenameDialog(FolderInfo info) {
2122 mFolderInfo = info;
2123 mWaitingForResult = true;
2124 showDialog(DIALOG_RENAME_FOLDER);
2125 }
2126
Michael Jurka0280c3b2010-09-17 15:00:07 -07002127 private void showAddDialog(int intersectX, int intersectY) {
2128 resetAddInfo();
2129 mAddIntersectCellX = intersectX;
2130 mAddIntersectCellY = intersectY;
2131 mAddScreen = mWorkspace.getCurrentPage();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002132 mWaitingForResult = true;
2133 showDialog(DIALOG_CREATE_SHORTCUT);
2134 }
2135
Joe Onoratodeb98af2010-02-19 14:59:39 -08002136 private void pickShortcut() {
Michael Jurka0e260592010-06-30 17:07:39 -07002137 // Insert extra item to handle picking application
Romain Guy73b979d2009-06-09 12:57:21 -07002138 Bundle bundle = new Bundle();
2139
2140 ArrayList<String> shortcutNames = new ArrayList<String>();
2141 shortcutNames.add(getString(R.string.group_applications));
2142 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
2143
2144 ArrayList<ShortcutIconResource> shortcutIcons = new ArrayList<ShortcutIconResource>();
2145 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
2146 R.drawable.ic_launcher_application));
2147 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
2148
2149 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2150 pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_CREATE_SHORTCUT));
Joe Onoratodeb98af2010-02-19 14:59:39 -08002151 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_shortcut));
Romain Guy73b979d2009-06-09 12:57:21 -07002152 pickIntent.putExtras(bundle);
2153
Joe Onoratodeb98af2010-02-19 14:59:39 -08002154 startActivityForResult(pickIntent, REQUEST_PICK_SHORTCUT);
Romain Guy73b979d2009-06-09 12:57:21 -07002155 }
2156
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002157 private class RenameFolder {
2158 private EditText mInput;
2159
2160 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002161 final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null);
2162 mInput = (EditText) layout.findViewById(R.id.folder_name);
2163
2164 AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
2165 builder.setIcon(0);
2166 builder.setTitle(getString(R.string.rename_folder_title));
2167 builder.setCancelable(true);
2168 builder.setOnCancelListener(new Dialog.OnCancelListener() {
2169 public void onCancel(DialogInterface dialog) {
2170 cleanup();
2171 }
2172 });
2173 builder.setNegativeButton(getString(R.string.cancel_action),
2174 new Dialog.OnClickListener() {
2175 public void onClick(DialogInterface dialog, int which) {
2176 cleanup();
2177 }
2178 }
2179 );
2180 builder.setPositiveButton(getString(R.string.rename_action),
2181 new Dialog.OnClickListener() {
2182 public void onClick(DialogInterface dialog, int which) {
2183 changeFolderName();
2184 }
2185 }
2186 );
2187 builder.setView(layout);
Romain Guy7b4ef332009-07-14 13:58:08 -07002188
2189 final AlertDialog dialog = builder.create();
2190 dialog.setOnShowListener(new DialogInterface.OnShowListener() {
2191 public void onShow(DialogInterface dialog) {
Joe Onorato7018d8e2010-04-13 20:25:47 -07002192 mWaitingForResult = true;
Joe Onoratod753b422009-11-08 13:31:11 -05002193 mInput.requestFocus();
2194 InputMethodManager inputManager = (InputMethodManager)
2195 getSystemService(Context.INPUT_METHOD_SERVICE);
2196 inputManager.showSoftInput(mInput, 0);
Romain Guy7b4ef332009-07-14 13:58:08 -07002197 }
2198 });
2199
2200 return dialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002201 }
2202
2203 private void changeFolderName() {
2204 final String name = mInput.getText().toString();
2205 if (!TextUtils.isEmpty(name)) {
2206 // Make sure we have the right folder info
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002207 mFolderInfo = sFolders.get(mFolderInfo.id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002208 mFolderInfo.title = name;
2209 LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo);
2210
Joe Onorato9c1289c2009-08-17 11:03:03 -04002211 if (mWorkspaceLoading) {
Joe Onorato7c312c12009-08-13 21:36:53 -07002212 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002213 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002214 } else {
2215 final FolderIcon folderIcon = (FolderIcon)
2216 mWorkspace.getViewForTag(mFolderInfo);
2217 if (folderIcon != null) {
2218 folderIcon.setText(name);
2219 getWorkspace().requestLayout();
2220 } else {
Joe Onorato7c312c12009-08-13 21:36:53 -07002221 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002222 mWorkspaceLoading = true;
2223 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002224 }
2225 }
2226 }
2227 cleanup();
2228 }
2229
2230 private void cleanup() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002231 dismissDialog(DIALOG_RENAME_FOLDER);
2232 mWaitingForResult = false;
2233 mFolderInfo = null;
2234 }
2235 }
2236
Daniel Sandler843e8602010-06-07 14:59:01 -04002237 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
2238 public boolean isAllAppsVisible() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002239 return mState == State.ALL_APPS;
Joe Onoratofb0ca672009-09-14 17:55:46 -04002240 }
2241
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002242 // AllAppsView.Watcher
2243 public void zoomed(float zoom) {
Michael Jurka213d9632010-07-28 11:29:25 -07002244 // In XLarge view, we zoom down the workspace below all apps so it's still visible
2245 if (zoom == 1.0f && !LauncherApplication.isScreenXLarge()) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002246 mWorkspace.setVisibility(View.GONE);
2247 }
2248 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002249
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002250 private void showToolbarButton(View button) {
2251 button.setAlpha(1.0f);
2252 button.setVisibility(View.VISIBLE);
2253 button.setFocusable(true);
2254 button.setClickable(true);
2255 }
2256
2257 private void hideToolbarButton(View button) {
2258 button.setAlpha(0.0f);
2259 // We can't set it to GONE, otherwise the RelativeLayout gets screwed up
2260 button.setVisibility(View.INVISIBLE);
2261 button.setFocusable(false);
2262 button.setClickable(false);
2263 }
2264
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002265 /**
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002266 * Helper function for showing or hiding a toolbar button, possibly animated.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002267 *
2268 * @param show If true, create an animation to the show the item. Otherwise, hide it.
2269 * @param view The toolbar button to be animated
Chet Haaseb1254a62010-09-07 13:35:00 -07002270 * @param seq A AnimatorSet that will be used to animate the transition. If null, the
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002271 * transition will not be animated.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002272 */
Chet Haaseb1254a62010-09-07 13:35:00 -07002273 private void hideOrShowToolbarButton(boolean show, final View view, AnimatorSet seq) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002274 final boolean showing = show;
2275 final boolean hiding = !show;
2276
2277 final int duration = show ?
2278 getResources().getInteger(R.integer.config_toolbarButtonFadeInTime) :
2279 getResources().getInteger(R.integer.config_toolbarButtonFadeOutTime);
2280
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002281 if (seq != null) {
Chet Haaseb1254a62010-09-07 13:35:00 -07002282 Animator anim = new ObjectAnimator<Float>(duration, view, "alpha", show ? 1.0f : 0.0f);
2283 anim.addListener(new AnimatorListenerAdapter() {
2284 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002285 if (showing) showToolbarButton(view);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002286 }
Chet Haaseb1254a62010-09-07 13:35:00 -07002287 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002288 if (hiding) hideToolbarButton(view);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002289 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002290 });
2291 seq.play(anim);
2292 } else {
2293 if (showing) {
2294 showToolbarButton(view);
2295 } else {
2296 hideToolbarButton(view);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002297 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002298 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002299 }
2300
2301 /**
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002302 * Show/hide the appropriate toolbar buttons for newState.
2303 * If showSeq or hideSeq is null, the transition will be done immediately (not animated).
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002304 *
2305 * @param newState The state that is being switched to
Chet Haaseb1254a62010-09-07 13:35:00 -07002306 * @param showSeq AnimatorSet in which to put "show" animations, or null.
2307 * @param hideSeq AnimatorSet in which to put "hide" animations, or null.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002308 */
Chet Haaseb1254a62010-09-07 13:35:00 -07002309 private void hideAndShowToolbarButtons(State newState, AnimatorSet showSeq, AnimatorSet hideSeq) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002310 final View searchButton = findViewById(R.id.search_button);
2311 final View allAppsButton = findViewById(R.id.all_apps_button);
2312 final View marketButton = findViewById(R.id.market_button);
2313 final View configureButton = findViewById(R.id.configure_button);
2314
2315 switch (newState) {
2316 case WORKSPACE:
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002317 hideOrShowToolbarButton(true, searchButton, showSeq);
2318 hideOrShowToolbarButton(true, allAppsButton, showSeq);
2319 hideOrShowToolbarButton(true, configureButton, showSeq);
2320 hideOrShowToolbarButton(false, marketButton, hideSeq);
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002321 mDeleteZone.setHandle(allAppsButton);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002322 break;
2323 case ALL_APPS:
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002324 hideOrShowToolbarButton(true, configureButton, showSeq);
2325 hideOrShowToolbarButton(true, marketButton, showSeq);
2326 hideOrShowToolbarButton(false, searchButton, hideSeq);
2327 hideOrShowToolbarButton(false, allAppsButton, hideSeq);
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002328 mDeleteZone.setHandle(marketButton);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002329 break;
2330 case CUSTOMIZE:
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002331 hideOrShowToolbarButton(true, allAppsButton, showSeq);
2332 hideOrShowToolbarButton(false, searchButton, hideSeq);
2333 hideOrShowToolbarButton(false, marketButton, hideSeq);
2334 hideOrShowToolbarButton(false, configureButton, hideSeq);
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002335 mDeleteZone.setHandle(allAppsButton);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002336 break;
2337 }
2338 }
2339
2340 /**
2341 * Helper method for the cameraZoomIn/cameraZoomOut animations
2342 * @param view The view being animated
2343 * @param state The state that we are moving in or out of -- either ALL_APPS or CUSTOMIZE
2344 * @param scaleFactor The scale factor used for the zoom
2345 */
2346 private void setPivotsForZoom(View view, State state, float scaleFactor) {
2347 final int height = view.getHeight();
2348 view.setPivotX(view.getWidth() / 2.0f);
2349 // Set pivotY so that at the starting zoom factor, the view is off-screen by a small margin
2350 // Assumes that the view is normally anchored to either the top or bottom of the screen
2351 final int margin = getResources().getInteger(R.integer.config_allAppsVerticalOffset);
2352 if (state == State.ALL_APPS) {
2353 view.setPivotY(height + ((view.getTop() + height) / scaleFactor) + margin);
2354 } else {
2355 view.setPivotY(0.0f - (view.getTop() / scaleFactor) - margin);
2356 }
2357 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002358
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002359 /**
2360 * Zoom the camera out from the workspace to reveal 'toView'.
2361 * Assumes that the view to show is anchored at either the very top or very bottom
2362 * of the screen.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002363 * @param toState The state to zoom out to. Must be ALL_APPS or CUSTOMIZE.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002364 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002365 private void cameraZoomOut(State toState, boolean animated) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002366 final Resources res = getResources();
2367 final int duration = res.getInteger(R.integer.config_allAppsZoomInTime);
2368 final float scale = (float) res.getInteger(R.integer.config_allAppsZoomScaleFactor);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002369 final boolean toAllApps = (toState == State.ALL_APPS);
2370 final View toView = toAllApps ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
Patrick Dubroy558654c2010-07-23 16:48:11 -07002371
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002372 setPivotsForZoom(toView, toState, scale);
2373
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002374 if (toState == State.ALL_APPS) {
2375 mWorkspace.shrinkToBottom(animated);
2376 } else {
2377 mWorkspace.shrinkToTop(animated);
2378 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002379
2380 if (animated) {
Chet Haaseb1254a62010-09-07 13:35:00 -07002381 ValueAnimator scaleAnim = new ObjectAnimator(duration, toView,
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002382 new PropertyValuesHolder<Float>("scaleX", scale, 1.0f),
2383 new PropertyValuesHolder<Float>("scaleY", scale, 1.0f));
2384 scaleAnim.setInterpolator(new DecelerateInterpolator());
Chet Haaseb1254a62010-09-07 13:35:00 -07002385 scaleAnim.addListener(new AnimatorListenerAdapter() {
2386 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002387 // Prepare the position
2388 toView.setTranslationX(0.0f);
2389 toView.setTranslationY(0.0f);
2390 toView.setVisibility(View.VISIBLE);
2391 }
2392 });
2393
Chet Haaseb1254a62010-09-07 13:35:00 -07002394 AnimatorSet toolbarHideAnim = new AnimatorSet();
2395 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002396 hideAndShowToolbarButtons(toState, toolbarShowAnim, toolbarHideAnim);
2397
2398 // toView should appear right at the end of the workspace shrink animation
2399 final int startDelay = res.getInteger(R.integer.config_workspaceShrinkTime) - duration;
2400
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002401 if (mStateAnimation != null) mStateAnimation.cancel();
2402 mStateAnimation = new AnimatorSet();
2403 mStateAnimation.playTogether(scaleAnim, toolbarHideAnim);
2404 mStateAnimation.play(scaleAnim).after(startDelay);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002405
2406 // Show the new toolbar buttons just as the main animation is ending
2407 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002408 mStateAnimation.play(toolbarShowAnim).after(duration + startDelay - fadeInTime);
2409 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002410 } else {
2411 toView.setTranslationX(0.0f);
2412 toView.setTranslationY(0.0f);
2413 toView.setScaleX(1.0f);
2414 toView.setScaleY(1.0f);
2415 toView.setVisibility(View.VISIBLE);
2416 hideAndShowToolbarButtons(toState, null, null);
2417 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002418 }
2419
2420 /**
2421 * Zoom the camera back into the workspace, hiding 'fromView'.
2422 * This is the opposite of cameraZoomOut.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002423 * @param fromState The current state (must be ALL_APPS or CUSTOMIZE).
2424 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002425 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002426 private void cameraZoomIn(State fromState, boolean animated) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002427 Resources res = getResources();
2428 int duration = res.getInteger(R.integer.config_allAppsZoomOutTime);
2429 float scaleFactor = (float) res.getInteger(R.integer.config_allAppsZoomScaleFactor);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002430 final View fromView =
2431 (fromState == State.ALL_APPS) ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
2432
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002433 mCustomizePagedView.endChoiceMode();
2434 mAllAppsPagedView.endChoiceMode();
2435
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002436 setPivotsForZoom(fromView, fromState, scaleFactor);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002437
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002438 mWorkspace.unshrink(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002439
2440 if (animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002441 if (mStateAnimation != null) mStateAnimation.cancel();
2442 mStateAnimation = new AnimatorSet();
Chet Haaseb1254a62010-09-07 13:35:00 -07002443 ValueAnimator scaleAnim = new ObjectAnimator(duration, fromView,
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002444 new PropertyValuesHolder<Float>("scaleX", scaleFactor),
2445 new PropertyValuesHolder<Float>("scaleY", scaleFactor));
2446 scaleAnim.setInterpolator(new AccelerateInterpolator());
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002447 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Chet Haaseb1254a62010-09-07 13:35:00 -07002448 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002449 fromView.setVisibility(View.GONE);
2450 fromView.setScaleX(1.0f);
2451 fromView.setScaleY(1.0f);
2452 }
2453 });
2454
Chet Haaseb1254a62010-09-07 13:35:00 -07002455 AnimatorSet toolbarHideAnim = new AnimatorSet();
2456 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002457 hideAndShowToolbarButtons(State.WORKSPACE, toolbarShowAnim, toolbarHideAnim);
2458
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002459 mStateAnimation.playTogether(scaleAnim, toolbarHideAnim);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002460
2461 // Show the new toolbar buttons at the very end of the whole animation
2462 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
2463 final int unshrinkTime = res.getInteger(R.integer.config_workspaceUnshrinkTime);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002464 mStateAnimation.play(toolbarShowAnim).after(unshrinkTime - fadeInTime);
2465 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002466 } else {
2467 fromView.setVisibility(View.GONE);
2468 hideAndShowToolbarButtons(State.WORKSPACE, null, null);
2469 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002470 }
2471
2472 /**
2473 * Pan the camera in the vertical plane between 'fromView' and 'toView'.
2474 * This is the transition used on xlarge screens to go between all apps and
2475 * the home customization drawer.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002476 * @param fromState The view to pan away from. Must be ALL_APPS or CUSTOMIZE.
2477 * @param toState The view to pan into the frame. Must be ALL_APPS or CUSTOMIZE.
2478 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002479 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002480 private void cameraPan(State fromState, State toState, boolean animated) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002481 final Resources res = getResources();
2482 final int duration = res.getInteger(R.integer.config_allAppsCameraPanTime);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002483 final int workspaceHeight = mWorkspace.getHeight();
2484
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002485 final boolean fromAllApps = (fromState == State.ALL_APPS);
2486 final View fromView = fromAllApps ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
2487 final View toView = fromAllApps ? mHomeCustomizationDrawer : (View) mAllAppsGrid;
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002488
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002489 final float fromViewStartY = fromAllApps ? 0.0f : fromView.getY();
2490 final float fromViewEndY = fromAllApps ? -fromView.getHeight() * 2 : workspaceHeight * 2;
2491 final float toViewStartY = fromAllApps ? workspaceHeight * 2 : -toView.getHeight() * 2;
2492 final float toViewEndY = fromAllApps ? workspaceHeight - toView.getHeight() : 0.0f;
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002493
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002494 mCustomizePagedView.endChoiceMode();
2495 mAllAppsPagedView.endChoiceMode();
2496
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002497 if (toState == State.ALL_APPS) {
2498 mWorkspace.shrinkToBottom(animated);
2499 } else {
2500 mWorkspace.shrinkToTop(animated);
2501 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002502
2503 if (animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002504 if (mStateAnimation != null) mStateAnimation.cancel();
2505 mStateAnimation = new AnimatorSet();
2506 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Chet Haaseb1254a62010-09-07 13:35:00 -07002507 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002508 toView.setVisibility(View.VISIBLE);
2509 toView.setY(toViewStartY);
2510 }
Chet Haaseb1254a62010-09-07 13:35:00 -07002511 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002512 fromView.setVisibility(View.GONE);
2513 }
2514 });
2515
Chet Haaseb1254a62010-09-07 13:35:00 -07002516 AnimatorSet toolbarHideAnim = new AnimatorSet();
2517 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002518 hideAndShowToolbarButtons(toState, toolbarShowAnim, toolbarHideAnim);
2519
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002520 mStateAnimation.playTogether(
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002521 toolbarHideAnim,
Chet Haaseb1254a62010-09-07 13:35:00 -07002522 new ObjectAnimator(duration, fromView, "y", fromViewStartY, fromViewEndY),
2523 new ObjectAnimator(duration, toView, "y", toViewStartY, toViewEndY));
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002524
2525 // Show the new toolbar buttons just as the main animation is ending
2526 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002527 mStateAnimation.play(toolbarShowAnim).after(duration - fadeInTime);
2528 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002529 } else {
2530 fromView.setY(fromViewEndY);
2531 fromView.setVisibility(View.GONE);
2532 toView.setY(toViewEndY);
2533 toView.setVisibility(View.VISIBLE);
2534 hideAndShowToolbarButtons(toState, null, null);
2535 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002536 }
2537
2538 void showAllApps(boolean animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002539 if (mState == State.ALL_APPS)
Winson Chung80baf5a2010-08-09 16:03:15 -07002540 return;
2541
Michael Jurka79212d82010-07-30 16:36:20 -07002542 if (LauncherApplication.isScreenXLarge()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002543 if (mState == State.CUSTOMIZE) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002544 cameraPan(State.CUSTOMIZE, State.ALL_APPS, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002545 } else {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002546 cameraZoomOut(State.ALL_APPS, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002547 }
Patrick Dubroy558654c2010-07-23 16:48:11 -07002548 } else {
2549 mAllAppsGrid.zoom(1.0f, animated);
2550 }
Joe Onorato3a8820b2009-11-10 15:06:42 -08002551
Romain Guyc16fea72010-03-12 17:17:56 -08002552 ((View) mAllAppsGrid).setFocusable(true);
2553 ((View) mAllAppsGrid).requestFocus();
Winson Chungaafa03c2010-06-11 17:34:16 -07002554
Joe Onorato7c312c12009-08-13 21:36:53 -07002555 // TODO: fade these two too
2556 mDeleteZone.setVisibility(View.GONE);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002557 // Change the state *after* we've called all the transition code
2558 mState = State.ALL_APPS;
2559 }
2560
2561
2562 void showWorkspace(boolean animated) {
2563 showWorkspace(animated, null);
2564 }
2565
2566 void showWorkspace(boolean animated, CellLayout layout) {
2567 if (layout != null && animated) {
2568 mWorkspace.unshrink(layout);
2569 } else {
2570 mWorkspace.unshrink(animated);
2571 }
2572 if (mState == State.ALL_APPS) {
2573 closeAllApps(animated);
2574 } else if (mState == State.CUSTOMIZE) {
2575 hideCustomizationDrawer(animated);
2576 }
2577 // Change the state *after* we've called all the transition code
2578 mState = State.WORKSPACE;
Joe Onorato00acb122009-08-04 16:04:30 -04002579 }
2580
Joe Onoratob2061212009-11-24 16:13:54 -05002581 /**
Joe Onorato7e4ed992009-12-03 13:10:49 -08002582 * Things to test when changing this code.
Joe Onoratob2061212009-11-24 16:13:54 -05002583 * - Home from workspace
2584 * - from center screen
2585 * - from other screens
2586 * - Home from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002587 * - from center screen
2588 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002589 * - Back from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002590 * - from center screen
2591 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002592 * - Launch app from workspace and quit
2593 * - with back
2594 * - with home
2595 * - Launch app from all apps and quit
2596 * - with back
2597 * - with home
Joe Onorato7e4ed992009-12-03 13:10:49 -08002598 * - Go to a screen that's not the default, then all
2599 * apps, and launch and app, and go back
2600 * - with back
2601 * -with home
Joe Onoratob2061212009-11-24 16:13:54 -05002602 * - On workspace, long press power and go back
2603 * - with back
2604 * - with home
2605 * - On all apps, long press power and go back
2606 * - with back
2607 * - with home
2608 * - On workspace, power off
2609 * - On all apps, power off
Joe Onorato7e4ed992009-12-03 13:10:49 -08002610 * - Launch an app and turn off the screen while in that app
2611 * - Go back with home key
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002612 * - Go back with back key TODO: make this not go to workspace
Joe Onorato7e4ed992009-12-03 13:10:49 -08002613 * - From all apps
2614 * - From workspace
Joe Onoratoeffc4a82010-04-15 11:48:13 -07002615 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2616 * - From all apps
2617 * - From the center workspace
2618 * - From another workspace
Joe Onoratob2061212009-11-24 16:13:54 -05002619 */
Joe Onorato7bb17492009-09-24 17:51:01 -07002620 void closeAllApps(boolean animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002621 if (mState == State.ALL_APPS) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002622 mWorkspace.setVisibility(View.VISIBLE);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002623 if (LauncherApplication.isScreenXLarge()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002624 cameraZoomIn(State.ALL_APPS, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002625 } else {
2626 mAllAppsGrid.zoom(0.0f, animated);
2627 }
Daniel Sandler388f6792010-03-02 14:08:08 -05002628 ((View)mAllAppsGrid).setFocusable(false);
Michael Jurka0142d492010-08-25 17:46:15 -07002629 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onoratoe77c08d2009-08-01 00:01:20 -07002630 }
Joe Onorato7404ee42009-07-31 11:54:44 -07002631 }
2632
Joe Onorato7c312c12009-08-13 21:36:53 -07002633 void lockAllApps() {
2634 // TODO
2635 }
2636
2637 void unlockAllApps() {
2638 // TODO
2639 }
2640
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002641 // Show the customization drawer (only exists in x-large configuration)
2642 private void showCustomizationDrawer(boolean animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002643 if (mState == State.ALL_APPS) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002644 cameraPan(State.ALL_APPS, State.CUSTOMIZE, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002645 } else {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002646 cameraZoomOut(State.CUSTOMIZE, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002647 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002648 // Change the state *after* we've called all the transition code
2649 mState = State.CUSTOMIZE;
Patrick Dubroy558654c2010-07-23 16:48:11 -07002650 }
2651
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002652 // Hide the customization drawer (only exists in x-large configuration)
2653 void hideCustomizationDrawer(boolean animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002654 if (mState == State.CUSTOMIZE) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002655 cameraZoomIn(State.CUSTOMIZE, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002656 }
2657 }
2658
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002659 void onWorkspaceClick(CellLayout layout) {
2660 Object itemInfo = mAllAppsPagedView.getChosenItem();
2661 if (itemInfo == null) {
2662 itemInfo = mCustomizePagedView.getChosenItem();
Michael Jurka213d9632010-07-28 11:29:25 -07002663 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002664
2665 if (itemInfo == null) {
2666 // No items are chosen in All Apps or Customize, so just zoom into the workspace
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002667 showWorkspace(true, layout);
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002668 } else {
2669 // Act as if the chosen item was dropped on the given CellLayout
2670 if (mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
2671 mAllAppsPagedView.endChoiceMode();
2672 mCustomizePagedView.endChoiceMode();
2673 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002674 showOutOfSpaceMessage();
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002675 }
Michael Jurka213d9632010-07-28 11:29:25 -07002676 }
2677 }
2678
Michael Jurka0423dcf2010-10-05 14:56:18 -07002679 private void updateButtonWithIconFromExternalActivity(
2680 int buttonId, ComponentName activityName, int fallbackDrawableId) {
2681 ImageView button = (ImageView) findViewById(buttonId);
2682 Drawable toolbarIcon = null;
2683 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002684 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07002685 // Look for the toolbar icon specified in the activity meta-data
2686 Bundle metaData = packageManager.getActivityInfo(
2687 activityName, PackageManager.GET_META_DATA).metaData;
2688 if (metaData != null) {
2689 int iconResId = metaData.getInt(TOOLBAR_ICON_METADATA_NAME);
2690 if (iconResId != 0) {
2691 Resources res = packageManager.getResourcesForActivity(activityName);
2692 toolbarIcon = res.getDrawable(iconResId);
2693 }
2694 }
2695 } catch (NameNotFoundException e) {
2696 // Do nothing
2697 }
2698 // If we were unable to find the icon via the meta-data, use a generic one
2699 if (toolbarIcon == null) {
2700 button.setImageResource(fallbackDrawableId);
2701 } else {
2702 button.setImageDrawable(toolbarIcon);
2703 }
2704 }
2705
2706 private void updateGlobalSearchIcon() {
2707 if (LauncherApplication.isScreenXLarge()) {
2708 final SearchManager searchManager =
2709 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2710 ComponentName activityName = searchManager.getGlobalSearchActivity();
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002711 if (activityName != null) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07002712 updateButtonWithIconFromExternalActivity(
2713 R.id.search_button, activityName, R.drawable.search_button_generic);
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002714 }
2715 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002716 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002717
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002718 /**
2719 * Sets the app market icon (shown when all apps is visible on x-large screens)
2720 */
2721 private void updateAppMarketIcon() {
Michael Jurka0423dcf2010-10-05 14:56:18 -07002722 if (LauncherApplication.isScreenXLarge()) {
2723 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
2724 // Find the app market activity by resolving an intent.
2725 // (If multiple app markets are installed, it will return the ResolverActivity.)
2726 ComponentName activityName = intent.resolveActivity(getPackageManager());
2727 if (activityName != null) {
2728 mAppMarketIntent = intent;
2729 updateButtonWithIconFromExternalActivity(
2730 R.id.market_button, activityName, R.drawable.app_market_generic);
2731 }
2732 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002733 }
2734
2735 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002736 * Displays the shortcut creation dialog and launches, if necessary, the
2737 * appropriate activity.
2738 */
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002739 private class CreateShortcut implements DialogInterface.OnClickListener,
Romain Guy7b4ef332009-07-14 13:58:08 -07002740 DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
2741 DialogInterface.OnShowListener {
2742
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002743 private AddAdapter mAdapter;
Romain Guy9ffb5432009-03-24 21:04:15 -07002744
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002745 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002746 mAdapter = new AddAdapter(Launcher.this);
Romain Guycbb89e42009-06-08 15:52:54 -07002747
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002748 final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
2749 builder.setTitle(getString(R.string.menu_item_add_item));
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002750 builder.setAdapter(mAdapter, this);
Romain Guycbb89e42009-06-08 15:52:54 -07002751
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002752 builder.setInverseBackgroundForced(true);
2753
2754 AlertDialog dialog = builder.create();
2755 dialog.setOnCancelListener(this);
Romain Guycbb89e42009-06-08 15:52:54 -07002756 dialog.setOnDismissListener(this);
Romain Guy7b4ef332009-07-14 13:58:08 -07002757 dialog.setOnShowListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002758
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002759 return dialog;
2760 }
2761
2762 public void onCancel(DialogInterface dialog) {
2763 mWaitingForResult = false;
2764 cleanup();
2765 }
2766
Romain Guycbb89e42009-06-08 15:52:54 -07002767 public void onDismiss(DialogInterface dialog) {
Romain Guycbb89e42009-06-08 15:52:54 -07002768 }
2769
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002770 private void cleanup() {
Joe Onoratocc19a532009-11-19 14:19:17 -08002771 try {
2772 dismissDialog(DIALOG_CREATE_SHORTCUT);
2773 } catch (Exception e) {
2774 // An exception is thrown if the dialog is not visible, which is fine
2775 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002776 }
2777
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002778 /**
2779 * Handle the action clicked in the "Add to home" dialog.
2780 */
2781 public void onClick(DialogInterface dialog, int which) {
2782 Resources res = getResources();
2783 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002784
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002785 switch (which) {
2786 case AddAdapter.ITEM_SHORTCUT: {
Joe Onoratodeb98af2010-02-19 14:59:39 -08002787 pickShortcut();
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002788 break;
2789 }
Romain Guycbb89e42009-06-08 15:52:54 -07002790
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002791 case AddAdapter.ITEM_APPWIDGET: {
2792 int appWidgetId = Launcher.this.mAppWidgetHost.allocateAppWidgetId();
Romain Guycbb89e42009-06-08 15:52:54 -07002793
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002794 Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
2795 pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002796 // start the pick activity
2797 startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET);
2798 break;
2799 }
Romain Guycbb89e42009-06-08 15:52:54 -07002800
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002801 case AddAdapter.ITEM_LIVE_FOLDER: {
2802 // Insert extra item to handle inserting folder
2803 Bundle bundle = new Bundle();
Romain Guycbb89e42009-06-08 15:52:54 -07002804
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002805 ArrayList<String> shortcutNames = new ArrayList<String>();
2806 shortcutNames.add(res.getString(R.string.group_folder));
2807 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
Romain Guycbb89e42009-06-08 15:52:54 -07002808
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002809 ArrayList<ShortcutIconResource> shortcutIcons =
2810 new ArrayList<ShortcutIconResource>();
2811 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
2812 R.drawable.ic_launcher_folder));
2813 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
2814
2815 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2816 pickIntent.putExtra(Intent.EXTRA_INTENT,
2817 new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER));
2818 pickIntent.putExtra(Intent.EXTRA_TITLE,
2819 getText(R.string.title_select_live_folder));
2820 pickIntent.putExtras(bundle);
Romain Guycbb89e42009-06-08 15:52:54 -07002821
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002822 startActivityForResult(pickIntent, REQUEST_PICK_LIVE_FOLDER);
2823 break;
2824 }
2825
2826 case AddAdapter.ITEM_WALLPAPER: {
2827 startWallpaper();
2828 break;
2829 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002830 }
2831 }
Romain Guy7b4ef332009-07-14 13:58:08 -07002832
2833 public void onShow(DialogInterface dialog) {
Winson Chungaafa03c2010-06-11 17:34:16 -07002834 mWaitingForResult = true;
Romain Guy7b4ef332009-07-14 13:58:08 -07002835 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002836 }
2837
2838 /**
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002839 * Receives notifications when applications are added/removed.
2840 */
2841 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
2842 @Override
2843 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002844 closeSystemDialogs();
Joe Onoratob2061212009-11-24 16:13:54 -05002845 String reason = intent.getStringExtra("reason");
2846 if (!"homekey".equals(reason)) {
2847 boolean animate = true;
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002848 if (mPaused || "lock".equals(reason)) {
Joe Onoratob2061212009-11-24 16:13:54 -05002849 animate = false;
2850 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002851 showWorkspace(animate);
Joe Onoratob2061212009-11-24 16:13:54 -05002852 }
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002853 }
2854 }
2855
2856 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002857 * Receives notifications whenever the appwidgets are reset.
2858 */
2859 private class AppWidgetResetObserver extends ContentObserver {
2860 public AppWidgetResetObserver() {
2861 super(new Handler());
2862 }
2863
2864 @Override
2865 public void onChange(boolean selfChange) {
2866 onAppWidgetReset();
2867 }
2868 }
2869
2870 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002871 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002872 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002873 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07002874 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002875 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07002876 } else {
2877 return SCREEN_COUNT / 2;
2878 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002879 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002880
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002881 void setAllAppsPagedView(PagedView view) {
2882 mAllAppsPagedView = view;
2883 }
2884
Joe Onorato9c1289c2009-08-17 11:03:03 -04002885 /**
2886 * Refreshes the shortcuts shown on the workspace.
2887 *
2888 * Implementation of the method from LauncherModel.Callbacks.
2889 */
2890 public void startBinding() {
2891 final Workspace workspace = mWorkspace;
2892 int count = workspace.getChildCount();
2893 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04002894 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Joe Onorato9c1289c2009-08-17 11:03:03 -04002895 ((ViewGroup) workspace.getChildAt(i)).removeAllViewsInLayout();
2896 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002897
Joe Onorato9c1289c2009-08-17 11:03:03 -04002898 if (DEBUG_USER_INTERFACE) {
2899 android.widget.Button finishButton = new android.widget.Button(this);
2900 finishButton.setText("Finish");
2901 workspace.addInScreen(finishButton, 1, 0, 0, 1, 1);
2902
2903 finishButton.setOnClickListener(new android.widget.Button.OnClickListener() {
2904 public void onClick(View v) {
2905 finish();
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002906 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002907 });
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002908 }
2909 }
2910
2911 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002912 * Bind the items start-end from the list.
2913 *
2914 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002915 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002916 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
2917
2918 final Workspace workspace = mWorkspace;
2919
2920 for (int i=start; i<end; i++) {
2921 final ItemInfo item = shortcuts.get(i);
2922 mDesktopItems.add(item);
2923 switch (item.itemType) {
2924 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
2925 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Joe Onorato0589f0f2010-02-08 13:44:00 -08002926 final View shortcut = createShortcut((ShortcutInfo)item);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002927 workspace.addInScreen(shortcut, item.screen, item.cellX, item.cellY, 1, 1,
2928 false);
2929 break;
2930 case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER:
2931 final FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07002932 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Joe Onorato9c1289c2009-08-17 11:03:03 -04002933 (UserFolderInfo) item);
2934 workspace.addInScreen(newFolder, item.screen, item.cellX, item.cellY, 1, 1,
2935 false);
2936 break;
2937 case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER:
2938 final FolderIcon newLiveFolder = LiveFolderIcon.fromXml(
2939 R.layout.live_folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07002940 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Joe Onorato9c1289c2009-08-17 11:03:03 -04002941 (LiveFolderInfo) item);
2942 workspace.addInScreen(newLiveFolder, item.screen, item.cellX, item.cellY, 1, 1,
2943 false);
2944 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002945 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002946 }
2947
Joe Onorato9c1289c2009-08-17 11:03:03 -04002948 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002949 }
2950
Joe Onorato9c1289c2009-08-17 11:03:03 -04002951 /**
2952 * Implementation of the method from LauncherModel.Callbacks.
2953 */
Joe Onoratoad72e172009-11-06 16:25:04 -05002954 public void bindFolders(HashMap<Long, FolderInfo> folders) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002955 sFolders.clear();
2956 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002957 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002958
2959 /**
2960 * Add the views for a widget to the workspace.
2961 *
2962 * Implementation of the method from LauncherModel.Callbacks.
2963 */
2964 public void bindAppWidget(LauncherAppWidgetInfo item) {
Daniel Sandler843e8602010-06-07 14:59:01 -04002965 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
2966 if (DEBUG_WIDGETS) {
2967 Log.d(TAG, "bindAppWidget: " + item);
2968 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002969 final Workspace workspace = mWorkspace;
2970
2971 final int appWidgetId = item.appWidgetId;
2972 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04002973 if (DEBUG_WIDGETS) {
2974 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
2975 }
2976
Joe Onorato9c1289c2009-08-17 11:03:03 -04002977 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
2978
Joe Onorato9c1289c2009-08-17 11:03:03 -04002979 item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
2980 item.hostView.setTag(item);
2981
2982 workspace.addInScreen(item.hostView, item.screen, item.cellX,
2983 item.cellY, item.spanX, item.spanY, false);
2984
2985 workspace.requestLayout();
2986
2987 mDesktopItems.add(item);
Daniel Sandler843e8602010-06-07 14:59:01 -04002988
2989 if (DEBUG_WIDGETS) {
2990 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
2991 + (SystemClock.uptimeMillis()-start) + "ms");
2992 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002993 }
2994
2995 /**
2996 * Callback saying that there aren't any more items to bind.
2997 *
2998 * Implementation of the method from LauncherModel.Callbacks.
2999 */
3000 public void finishBindingItems() {
3001 if (mSavedState != null) {
3002 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003003 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003004 }
3005
3006 final long[] userFolders = mSavedState.getLongArray(RUNTIME_STATE_USER_FOLDERS);
3007 if (userFolders != null) {
3008 for (long folderId : userFolders) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003009 final FolderInfo info = sFolders.get(folderId);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003010 if (info != null) {
3011 openFolder(info);
3012 }
3013 }
3014 final Folder openFolder = mWorkspace.getOpenFolder();
3015 if (openFolder != null) {
3016 openFolder.requestFocus();
3017 }
3018 }
3019
Joe Onorato9c1289c2009-08-17 11:03:03 -04003020 mSavedState = null;
3021 }
3022
3023 if (mSavedInstanceState != null) {
3024 super.onRestoreInstanceState(mSavedInstanceState);
3025 mSavedInstanceState = null;
3026 }
3027
Joe Onorato9c1289c2009-08-17 11:03:03 -04003028 mWorkspaceLoading = false;
3029 }
3030
3031 /**
3032 * Add the icons for all apps.
3033 *
3034 * Implementation of the method from LauncherModel.Callbacks.
3035 */
3036 public void bindAllApplications(ArrayList<ApplicationInfo> apps) {
Romain Guy84f296c2009-11-04 15:00:44 -08003037 mAllAppsGrid.setApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003038 if (mCustomizePagedView != null) {
3039 mCustomizePagedView.setApps(apps);
3040 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003041 updateAppMarketIcon();
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003042 updateGlobalSearchIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003043 }
3044
3045 /**
3046 * A package was installed.
3047 *
3048 * Implementation of the method from LauncherModel.Callbacks.
3049 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003050 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003051 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onoratoa8138d52009-10-06 19:25:30 -07003052 mAllAppsGrid.addApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003053 if (mCustomizePagedView != null) {
3054 mCustomizePagedView.addApps(apps);
3055 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003056 updateAppMarketIcon();
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003057 updateGlobalSearchIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003058 }
3059
3060 /**
3061 * A package was updated.
3062 *
3063 * Implementation of the method from LauncherModel.Callbacks.
3064 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003065 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003066 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato64e6be72010-03-05 15:05:52 -05003067 mWorkspace.updateShortcuts(apps);
3068 mAllAppsGrid.updateApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003069 if (mCustomizePagedView != null) {
3070 mCustomizePagedView.updateApps(apps);
3071 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003072 updateAppMarketIcon();
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003073 updateGlobalSearchIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003074 }
3075
3076 /**
3077 * A package was uninstalled.
3078 *
3079 * Implementation of the method from LauncherModel.Callbacks.
3080 */
Joe Onorato36115782010-06-17 13:28:48 -04003081 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003082 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato36115782010-06-17 13:28:48 -04003083 if (permanent) {
3084 mWorkspace.removeItems(apps);
3085 }
Joe Onoratoa8138d52009-10-06 19:25:30 -07003086 mAllAppsGrid.removeApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003087 if (mCustomizePagedView != null) {
3088 mCustomizePagedView.removeApps(apps);
3089 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003090 updateAppMarketIcon();
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003091 updateGlobalSearchIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003092 }
Joe Onoratobe386092009-11-17 17:32:16 -08003093
3094 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003095 * A number of packages were updated.
3096 */
3097 public void bindPackagesUpdated() {
3098 // update the customization drawer contents
Winson Chung5f941722010-09-28 16:36:43 -07003099 if (mCustomizePagedView != null) {
Winson Chungb3347bb2010-08-19 14:51:28 -07003100 mCustomizePagedView.update();
Winson Chung5f941722010-09-28 16:36:43 -07003101 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003102 }
3103
3104 /**
Joe Onoratobe386092009-11-17 17:32:16 -08003105 * Prints out out state for debugging.
3106 */
3107 public void dumpState() {
3108 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08003109 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08003110 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
3111 Log.d(TAG, "mRestoring=" + mRestoring);
3112 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
3113 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
3114 Log.d(TAG, "mDesktopItems.size=" + mDesktopItems.size());
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003115 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08003116 mModel.dumpState();
3117 mAllAppsGrid.dumpState();
3118 Log.d(TAG, "END launcher2 dump state");
3119 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003120}