blob: 989ee25176081d0eb8f9b4d74bd668119219e2a7 [file] [log] [blame]
Michael Jurka01f0ed42010-08-20 00:41:17 -07001
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002/*
3 * Copyright (C) 2008 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
Joe Onoratoa5902522009-07-30 13:37:37 -070018package com.android.launcher2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080019
Chet Haaseb1254a62010-09-07 13:35:00 -070020import android.animation.Animator;
21import android.animation.AnimatorListenerAdapter;
22import android.animation.ValueAnimator;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070023import com.android.common.Search;
24import com.android.launcher.R;
25
Chet Haaseb1254a62010-09-07 13:35:00 -070026import android.animation.ObjectAnimator;
Patrick Dubroy07a0de42010-08-26 11:48:35 -070027import android.animation.PropertyValuesHolder;
Chet Haaseb1254a62010-09-07 13:35:00 -070028import android.animation.AnimatorSet;
Michael Jurka946ad472010-07-09 18:05:18 -070029import android.app.Activity;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080030import android.app.AlertDialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080031import android.app.Dialog;
32import android.app.SearchManager;
33import android.app.StatusBarManager;
Dianne Hackborn107f8392009-08-05 21:32:16 -070034import android.app.WallpaperManager;
Michael Jurkaaf442092010-06-10 17:01:57 -070035import android.appwidget.AppWidgetManager;
36import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080037import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080038import android.content.BroadcastReceiver;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040039import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080040import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041import android.content.Context;
42import android.content.DialogInterface;
43import android.content.Intent;
Winson Chung80baf5a2010-08-09 16:03:15 -070044import android.content.Intent.ShortcutIconResource;
Romain Guy5bbc91b2010-08-18 11:38:46 -070045import android.content.IntentFilter;
Winson Chungaafa03c2010-06-11 17:34:16 -070046import android.content.pm.ActivityInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080047import android.content.pm.PackageManager;
Patrick Dubroyceae05d2010-08-30 10:40:53 -070048import android.content.pm.PackageManager.NameNotFoundException;
Daniel Sandlerab1ebd72010-04-27 16:57:25 -040049import android.content.pm.ResolveInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080050import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070051import android.content.res.Resources;
Daniel Sandlerab1ebd72010-04-27 16:57:25 -040052import android.content.res.TypedArray;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080053import android.database.ContentObserver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080054import android.graphics.Bitmap;
Romain Guya6abce82009-11-10 02:54:41 -080055import android.graphics.Canvas;
Winson Chung80baf5a2010-08-09 16:03:15 -070056import android.graphics.Color;
Michael Jurkaaf442092010-06-10 17:01:57 -070057import android.graphics.Rect;
Romain Guyff0c2e22009-11-10 12:09:59 -080058import android.graphics.drawable.ColorDrawable;
Michael Jurkaaf442092010-06-10 17:01:57 -070059import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040060import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070061import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080062import android.os.Bundle;
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +020063import android.os.Environment;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080064import android.os.Handler;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080065import android.os.Parcelable;
Daniel Sandler843e8602010-06-07 14:59:01 -040066import android.os.SystemClock;
Joe Onoratobe386092009-11-17 17:32:16 -080067import android.os.SystemProperties;
Karl Rosaen138a0412009-04-23 19:00:21 -070068import android.provider.LiveFolders;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070069import android.provider.Settings;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080070import android.text.Selection;
71import android.text.SpannableStringBuilder;
72import android.text.TextUtils;
73import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070074import android.util.Log;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080075import android.view.Display;
Joe Onorato0d44e942009-11-16 18:20:51 -080076import android.view.HapticFeedbackConstants;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080077import android.view.KeyEvent;
78import android.view.LayoutInflater;
79import android.view.Menu;
80import android.view.MenuItem;
Michael Jurka0e260592010-06-30 17:07:39 -070081import android.view.MotionEvent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080082import android.view.View;
Romain Guy5bbc91b2010-08-18 11:38:46 -070083import android.view.View.OnLongClickListener;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080084import android.view.ViewGroup;
Winson Chungaafa03c2010-06-11 17:34:16 -070085import android.view.WindowManager;
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -070086import android.view.animation.AccelerateInterpolator;
Patrick Dubroy7247f632010-08-04 16:02:59 -070087import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080088import android.view.inputmethod.InputMethodManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080089import android.widget.EditText;
Michael Jurkaaf442092010-06-10 17:01:57 -070090import android.widget.ImageView;
91import android.widget.LinearLayout;
92import android.widget.PopupWindow;
Winson Chung80baf5a2010-08-09 16:03:15 -070093import android.widget.RelativeLayout;
Michael Jurka0e260592010-06-30 17:07:39 -070094import android.widget.TabHost;
Romain Guy5bbc91b2010-08-18 11:38:46 -070095import android.widget.TabHost.OnTabChangeListener;
96import android.widget.TabHost.TabContentFactory;
Winson Chung80baf5a2010-08-09 16:03:15 -070097import android.widget.TabWidget;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080098import android.widget.TextView;
99import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700100
101import java.io.DataInputStream;
102import java.io.DataOutputStream;
103import java.io.FileNotFoundException;
104import java.io.IOException;
105import java.util.ArrayList;
106import java.util.HashMap;
107import java.util.List;
Romain Guyedcce092010-03-04 13:03:17 -0800108
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800109/**
110 * Default launcher application.
111 */
Michael Jurka946ad472010-07-09 18:05:18 -0700112public final class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700113 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
114 AllAppsView.Watcher, View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800115 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700116 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800117
Joe Onorato9c1289c2009-08-17 11:03:03 -0400118 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400119 static final boolean DEBUG_WIDGETS = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400120 static final boolean DEBUG_USER_INTERFACE = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700121
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800122 private static final int MENU_GROUP_ADD = 1;
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800123 private static final int MENU_GROUP_WALLPAPER = MENU_GROUP_ADD + 1;
124
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800125 private static final int MENU_ADD = Menu.FIRST + 1;
Winson Chung7ad01412010-09-27 11:33:03 -0700126 private static final int MENU_MANAGE_APPS = MENU_ADD + 1;
127 private static final int MENU_WALLPAPER_SETTINGS = MENU_MANAGE_APPS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800128 private static final int MENU_SEARCH = MENU_WALLPAPER_SETTINGS + 1;
129 private static final int MENU_NOTIFICATIONS = MENU_SEARCH + 1;
Romain Guy94dabf12009-07-21 10:55:43 -0700130 private static final int MENU_SETTINGS = MENU_NOTIFICATIONS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800131
132 private static final int REQUEST_CREATE_SHORTCUT = 1;
133 private static final int REQUEST_CREATE_LIVE_FOLDER = 4;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700134 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800135 private static final int REQUEST_PICK_APPLICATION = 6;
136 private static final int REQUEST_PICK_SHORTCUT = 7;
137 private static final int REQUEST_PICK_LIVE_FOLDER = 8;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700138 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700139 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800140
141 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
142
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800143 static final int SCREEN_COUNT = 5;
144 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800145
Joe Onorato7c312c12009-08-13 21:36:53 -0700146 static final int DIALOG_CREATE_SHORTCUT = 1;
147 static final int DIALOG_RENAME_FOLDER = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800148
Romain Guy98d01652009-06-30 16:21:04 -0700149 private static final String PREFERENCES = "launcher.preferences";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800150
151 // Type: int
152 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
153 // Type: boolean
154 private static final String RUNTIME_STATE_ALL_APPS_FOLDER = "launcher.all_apps_folder";
155 // Type: long
156 private static final String RUNTIME_STATE_USER_FOLDERS = "launcher.user_folder";
157 // Type: int
158 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
159 // Type: int
160 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cellX";
161 // Type: int
162 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cellY";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800163 // Type: boolean
164 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
165 // Type: long
166 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
167
Winson Chung80baf5a2010-08-09 16:03:15 -0700168 // tags for the customization tabs
169 private static final String WIDGETS_TAG = "widgets";
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700170 private static final String APPLICATIONS_TAG = "applications";
Winson Chung80baf5a2010-08-09 16:03:15 -0700171 private static final String FOLDERS_TAG = "folders";
172 private static final String SHORTCUTS_TAG = "shortcuts";
173 private static final String WALLPAPERS_TAG = "wallpapers";
174
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700175 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
176
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700177 /** The different states that Launcher can be in. */
178 private enum State { WORKSPACE, ALL_APPS, CUSTOMIZE, OVERVIEW };
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700179 private State mState = State.WORKSPACE;
180 private AnimatorSet mStateAnimation;
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700181
Joe Onorato9c1289c2009-08-17 11:03:03 -0400182 static final int APPWIDGET_HOST_ID = 1024;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800183
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800184 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800185 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800186
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800187 private final BroadcastReceiver mCloseSystemDialogsReceiver
188 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800189 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
190
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800191 private LayoutInflater mInflater;
192
Joe Onorato00acb122009-08-04 16:04:30 -0400193 private DragController mDragController;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800194 private Workspace mWorkspace;
Romain Guycbb89e42009-06-08 15:52:54 -0700195
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700196 private AppWidgetManager mAppWidgetManager;
197 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700198
Michael Jurka0280c3b2010-09-17 15:00:07 -0700199 private int mAddScreen = -1;
200 private int mAddIntersectCellX = -1;
201 private int mAddIntersectCellY = -1;
202 private int[] mAddDropPosition;
203 private int[] mTmpAddItemCellCoordinates = new int[2];
204
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800205 private FolderInfo mFolderInfo;
206
Joe Onorato7c312c12009-08-13 21:36:53 -0700207 private DeleteZone mDeleteZone;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700208 private HandleView mHandleView;
Joe Onorato7c312c12009-08-13 21:36:53 -0700209 private AllAppsView mAllAppsGrid;
Michael Jurka0e260592010-06-30 17:07:39 -0700210 private TabHost mHomeCustomizationDrawer;
Patrick Dubroy2b9ff372010-09-07 17:49:27 -0700211
212 private PagedView mAllAppsPagedView = null;
213 private CustomizePagedView mCustomizePagedView = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800214
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800215 private Bundle mSavedState;
216
217 private SpannableStringBuilder mDefaultKeySsb = null;
218
Joe Onorato9c1289c2009-08-17 11:03:03 -0400219 private boolean mWorkspaceLoading = true;
220
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800221 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800222 private boolean mRestoring;
223 private boolean mWaitingForResult;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800224
225 private Bundle mSavedInstanceState;
226
Joe Onorato9c1289c2009-08-17 11:03:03 -0400227 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800228 private IconCache mIconCache;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400229
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700230 private static LocaleConfiguration sLocaleConfiguration = null;
231
Romain Guy84f296c2009-11-04 15:00:44 -0800232 private ArrayList<ItemInfo> mDesktopItems = new ArrayList<ItemInfo>();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700233 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700234
Romain Guy1fbc1c82009-11-09 20:43:08 -0800235 private ImageView mPreviousView;
236 private ImageView mNextView;
Joe Onorato080d9b62009-11-02 12:01:11 -0500237
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400238 // Hotseats (quick-launch icons next to AllApps)
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400239 private String[] mHotseatConfig = null;
240 private Intent[] mHotseats = null;
241 private Drawable[] mHotseatIcons = null;
242 private CharSequence[] mHotseatLabels = null;
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400243
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700244 private Intent mAppMarketIntent = null;
245
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800246 @Override
247 protected void onCreate(Bundle savedInstanceState) {
248 super.onCreate(savedInstanceState);
Romain Guyb1b69f52009-08-10 15:10:15 -0700249
Winson Chungaafa03c2010-06-11 17:34:16 -0700250 if (LauncherApplication.isInPlaceRotationEnabled()) {
251 // hide the status bar (temporary until we get the status bar design figured out)
252 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
253 this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
254 }
255
Joe Onorato0589f0f2010-02-08 13:44:00 -0800256 LauncherApplication app = ((LauncherApplication)getApplication());
257 mModel = app.setLauncher(this);
258 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400259 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800260 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700261
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700262 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700263 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
264 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700265
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800266 if (PROFILE_STARTUP) {
Christian Mehlmauer0fbe7bc2010-08-02 20:27:46 +0200267 android.os.Debug.startMethodTracing(
268 Environment.getExternalStorageDirectory() + "/launcher");
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800269 }
270
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400271 loadHotseats();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800272 checkForLocaleChange();
273 setWallpaperDimension();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800274 setContentView(R.layout.launcher);
Michael Jurka946ad472010-07-09 18:05:18 -0700275 mHomeCustomizationDrawer = (TabHost) findViewById(com.android.internal.R.id.tabhost);
276 if (mHomeCustomizationDrawer != null) {
277 mHomeCustomizationDrawer.setup();
Winson Chungaafa03c2010-06-11 17:34:16 -0700278
Winson Chung80baf5a2010-08-09 16:03:15 -0700279 // share the same customization workspace across all the tabs
Winson Chunge3193b92010-09-10 11:44:42 -0700280 mCustomizePagedView = (CustomizePagedView) mInflater.inflate(
281 R.layout.customization_drawer, mHomeCustomizationDrawer, false);
Winson Chung80baf5a2010-08-09 16:03:15 -0700282 TabContentFactory contentFactory = new TabContentFactory() {
283 public View createTabContent(String tag) {
284 return mCustomizePagedView;
285 }
286 };
287
Michael Jurka946ad472010-07-09 18:05:18 -0700288 String widgetsLabel = getString(R.string.widgets_tab_label);
Winson Chung80baf5a2010-08-09 16:03:15 -0700289 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(WIDGETS_TAG)
290 .setIndicator(widgetsLabel).setContent(contentFactory));
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700291 String applicationsLabel = getString(R.string.applications_tab_label);
292 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(APPLICATIONS_TAG)
293 .setIndicator(applicationsLabel).setContent(contentFactory));
Michael Jurka946ad472010-07-09 18:05:18 -0700294 String foldersLabel = getString(R.string.folders_tab_label);
Winson Chung80baf5a2010-08-09 16:03:15 -0700295 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(FOLDERS_TAG)
296 .setIndicator(foldersLabel).setContent(contentFactory));
Michael Jurka946ad472010-07-09 18:05:18 -0700297 String wallpapersLabel = getString(R.string.wallpapers_tab_label);
Winson Chung80baf5a2010-08-09 16:03:15 -0700298 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(WALLPAPERS_TAG)
299 .setIndicator(wallpapersLabel).setContent(contentFactory));
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700300 String shortcutsLabel = getString(R.string.shortcuts_tab_label);
301 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(SHORTCUTS_TAG)
302 .setIndicator(shortcutsLabel).setContent(contentFactory));
Winson Chung80baf5a2010-08-09 16:03:15 -0700303
304 // TEMP: just styling the tab widget to be a bit nicer until we get the actual
305 // new assets
306 TabWidget tabWidget = mHomeCustomizationDrawer.getTabWidget();
307 for (int i = 0; i < tabWidget.getChildCount(); ++i) {
308 RelativeLayout tab = (RelativeLayout) tabWidget.getChildTabViewAt(i);
309 TextView text = (TextView) tab.getChildAt(1);
310 text.setTextSize(20.0f);
311 text.setPadding(20, 0, 20, 0);
312 text.setShadowLayer(1.0f, 0.0f, 1.0f, Color.BLACK);
313 tab.setBackgroundDrawable(null);
314 }
315
316 mHomeCustomizationDrawer.setOnTabChangedListener(new OnTabChangeListener() {
317 public void onTabChanged(String tabId) {
318 // animate the changing of the tab content by fading pages in and out
319 final int duration = 150;
320 final float alpha = mCustomizePagedView.getAlpha();
Chet Haaseb1254a62010-09-07 13:35:00 -0700321 ValueAnimator alphaAnim = new ObjectAnimator(duration, mCustomizePagedView,
Winson Chung80baf5a2010-08-09 16:03:15 -0700322 "alpha", alpha, 0.0f);
Chet Haaseb1254a62010-09-07 13:35:00 -0700323 alphaAnim.addListener(new AnimatorListenerAdapter() {
324 public void onAnimationEnd(Animator animation) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700325 String tag = mHomeCustomizationDrawer.getCurrentTabTag();
326 if (tag == WIDGETS_TAG) {
327 mCustomizePagedView.setCustomizationFilter(
328 CustomizePagedView.CustomizationType.WidgetCustomization);
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700329 } else if (tag == APPLICATIONS_TAG) {
330 mCustomizePagedView.setCustomizationFilter(
331 CustomizePagedView.CustomizationType.ApplicationCustomization);
Winson Chung80baf5a2010-08-09 16:03:15 -0700332 } else if (tag == FOLDERS_TAG) {
333 mCustomizePagedView.setCustomizationFilter(
334 CustomizePagedView.CustomizationType.FolderCustomization);
Winson Chung80baf5a2010-08-09 16:03:15 -0700335 } else if (tag == WALLPAPERS_TAG) {
336 mCustomizePagedView.setCustomizationFilter(
337 CustomizePagedView.CustomizationType.WallpaperCustomization);
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700338 } else if (tag == SHORTCUTS_TAG) {
339 mCustomizePagedView.setCustomizationFilter(
340 CustomizePagedView.CustomizationType.ShortcutCustomization);
Winson Chung80baf5a2010-08-09 16:03:15 -0700341 }
342
343 final float alpha = mCustomizePagedView.getAlpha();
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700344 ValueAnimator alphaAnim = new ObjectAnimator(duration,
345 mCustomizePagedView, "alpha", alpha, 1.0f);
Winson Chung80baf5a2010-08-09 16:03:15 -0700346 alphaAnim.start();
347 }
348 });
349 alphaAnim.start();
350 }
351 });
Michael Jurka946ad472010-07-09 18:05:18 -0700352
353 mHomeCustomizationDrawer.setCurrentTab(0);
354 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800355 setupViews();
356
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800357 registerContentObservers();
358
Joe Onorato7c312c12009-08-13 21:36:53 -0700359 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700360
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800361 mSavedState = savedInstanceState;
362 restoreState(mSavedState);
363
364 if (PROFILE_STARTUP) {
365 android.os.Debug.stopMethodTracing();
366 }
367
368 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400369 mModel.startLoader(this, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800370 }
371
372 // For handling default keys
373 mDefaultKeySsb = new SpannableStringBuilder();
374 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800375
376 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
377 registerReceiver(mCloseSystemDialogsReceiver, filter);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800378 }
Romain Guycbb89e42009-06-08 15:52:54 -0700379
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800380 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700381 if (sLocaleConfiguration == null) {
382 new AsyncTask<Void, Void, LocaleConfiguration>() {
383 @Override
384 protected LocaleConfiguration doInBackground(Void... unused) {
385 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
386 readConfiguration(Launcher.this, localeConfiguration);
387 return localeConfiguration;
388 }
389
390 @Override
391 protected void onPostExecute(LocaleConfiguration result) {
392 sLocaleConfiguration = result;
393 checkForLocaleChange(); // recursive, but now with a locale configuration
394 }
395 }.execute();
396 return;
397 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700398
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800399 final Configuration configuration = getResources().getConfiguration();
400
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700401 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800402 final String locale = configuration.locale.toString();
403
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700404 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800405 final int mcc = configuration.mcc;
406
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700407 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800408 final int mnc = configuration.mnc;
409
Romain Guy84f296c2009-11-04 15:00:44 -0800410 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800411
Romain Guy84f296c2009-11-04 15:00:44 -0800412 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700413 sLocaleConfiguration.locale = locale;
414 sLocaleConfiguration.mcc = mcc;
415 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700416
Joe Onorato0589f0f2010-02-08 13:44:00 -0800417 mIconCache.flush();
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400418 loadHotseats();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700419
420 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
421 new Thread("WriteLocaleConfiguration") {
422 public void run() {
423 writeConfiguration(Launcher.this, localeConfiguration);
424 }
425 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700426 }
427 }
428
429 private static class LocaleConfiguration {
430 public String locale;
431 public int mcc = -1;
432 public int mnc = -1;
433 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700434
Romain Guy98d01652009-06-30 16:21:04 -0700435 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
436 DataInputStream in = null;
437 try {
438 in = new DataInputStream(context.openFileInput(PREFERENCES));
439 configuration.locale = in.readUTF();
440 configuration.mcc = in.readInt();
441 configuration.mnc = in.readInt();
442 } catch (FileNotFoundException e) {
443 // Ignore
444 } catch (IOException e) {
445 // Ignore
446 } finally {
447 if (in != null) {
448 try {
449 in.close();
450 } catch (IOException e) {
451 // Ignore
452 }
453 }
454 }
455 }
456
457 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
458 DataOutputStream out = null;
459 try {
460 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
461 out.writeUTF(configuration.locale);
462 out.writeInt(configuration.mcc);
463 out.writeInt(configuration.mnc);
464 out.flush();
465 } catch (FileNotFoundException e) {
466 // Ignore
467 } catch (IOException e) {
468 //noinspection ResultOfMethodCallIgnored
469 context.getFileStreamPath(PREFERENCES).delete();
470 } finally {
471 if (out != null) {
472 try {
473 out.close();
474 } catch (IOException e) {
475 // Ignore
476 }
477 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800478 }
479 }
480
481 static int getScreen() {
482 synchronized (sLock) {
483 return sScreen;
484 }
485 }
486
487 static void setScreen(int screen) {
488 synchronized (sLock) {
489 sScreen = screen;
490 }
491 }
492
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800493 private void setWallpaperDimension() {
Dianne Hackborn107f8392009-08-05 21:32:16 -0700494 WallpaperManager wpm = (WallpaperManager)getSystemService(WALLPAPER_SERVICE);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800495
496 Display display = getWindowManager().getDefaultDisplay();
Romain Guy5bbc91b2010-08-18 11:38:46 -0700497 // TODO: Put back when we decide about scrolling the wallpaper
498 // boolean isPortrait = display.getWidth() < display.getHeight();
499 // final int width = isPortrait ? display.getWidth() : display.getHeight();
500 // final int height = isPortrait ? display.getHeight() : display.getWidth();
501 wpm.suggestDesiredDimensions(Math.max(display.getWidth(), display.getHeight()),
502 Math.max(display.getWidth(), display.getHeight()));
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800503 }
504
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400505 // Note: This doesn't do all the client-id magic that BrowserProvider does
506 // in Browser. (http://b/2425179)
507 private Uri getDefaultBrowserUri() {
508 String url = getString(R.string.default_browser_url);
509 if (url.indexOf("{CID}") != -1) {
510 url = url.replace("{CID}", "android-google");
511 }
512 return Uri.parse(url);
513 }
514
515 // Load the Intent templates from arrays.xml to populate the hotseats. For
516 // each Intent, if it resolves to a single app, use that as the launch
517 // intent & use that app's label as the contentDescription. Otherwise,
518 // retain the ResolveActivity so the user can pick an app.
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400519 private void loadHotseats() {
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400520 if (mHotseatConfig == null) {
521 mHotseatConfig = getResources().getStringArray(R.array.hotseats);
522 if (mHotseatConfig.length > 0) {
523 mHotseats = new Intent[mHotseatConfig.length];
524 mHotseatLabels = new CharSequence[mHotseatConfig.length];
525 mHotseatIcons = new Drawable[mHotseatConfig.length];
526 } else {
527 mHotseats = null;
528 mHotseatIcons = null;
529 mHotseatLabels = null;
530 }
531
532 TypedArray hotseatIconDrawables = getResources().obtainTypedArray(R.array.hotseat_icons);
533 for (int i=0; i<mHotseatConfig.length; i++) {
534 // load icon for this slot; currently unrelated to the actual activity
535 try {
536 mHotseatIcons[i] = hotseatIconDrawables.getDrawable(i);
537 } catch (ArrayIndexOutOfBoundsException ex) {
538 Log.w(TAG, "Missing hotseat_icons array item #" + i);
539 mHotseatIcons[i] = null;
540 }
541 }
542 hotseatIconDrawables.recycle();
543 }
544
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400545 PackageManager pm = getPackageManager();
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400546 for (int i=0; i<mHotseatConfig.length; i++) {
547 Intent intent = null;
548 if (mHotseatConfig[i].equals("*BROWSER*")) {
549 // magic value meaning "launch user's default web browser"
550 // replace it with a generic web request so we can see if there is indeed a default
551 String defaultUri = getString(R.string.default_browser_url);
552 intent = new Intent(
553 Intent.ACTION_VIEW,
554 ((defaultUri != null)
555 ? Uri.parse(defaultUri)
556 : getDefaultBrowserUri())
557 ).addCategory(Intent.CATEGORY_BROWSABLE);
558 // note: if the user launches this without a default set, she
559 // will always be taken to the default URL above; this is
560 // unavoidable as we must specify a valid URL in order for the
Winson Chungaafa03c2010-06-11 17:34:16 -0700561 // chooser to appear, and once the user selects something, that
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400562 // URL is unavoidably sent to the chosen app.
563 } else {
564 try {
565 intent = Intent.parseUri(mHotseatConfig[i], 0);
566 } catch (java.net.URISyntaxException ex) {
567 Log.w(TAG, "Invalid hotseat intent: " + mHotseatConfig[i]);
568 // bogus; leave intent=null
569 }
570 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700571
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400572 if (intent == null) {
573 mHotseats[i] = null;
574 mHotseatLabels[i] = getText(R.string.activity_not_found);
575 continue;
576 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400577
578 if (LOGD) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700579 Log.d(TAG, "loadHotseats: hotseat " + i
580 + " initial intent=["
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400581 + intent.toUri(Intent.URI_INTENT_SCHEME)
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400582 + "]");
583 }
584
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400585 ResolveInfo bestMatch = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
586 List<ResolveInfo> allMatches = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
Winson Chungaafa03c2010-06-11 17:34:16 -0700587 if (LOGD) {
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400588 Log.d(TAG, "Best match for intent: " + bestMatch);
589 Log.d(TAG, "All matches: ");
590 for (ResolveInfo ri : allMatches) {
591 Log.d(TAG, " --> " + ri);
592 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400593 }
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400594 // did this resolve to a single app, or the resolver?
595 if (allMatches.size() == 0 || bestMatch == null) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700596 // can't find any activity to handle this. let's leave the
597 // intent as-is and let Launcher show a toast when it fails
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400598 // to launch.
599 mHotseats[i] = intent;
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400600
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400601 // set accessibility text to "Not installed"
602 mHotseatLabels[i] = getText(R.string.activity_not_found);
603 } else {
604 boolean found = false;
605 for (ResolveInfo ri : allMatches) {
606 if (bestMatch.activityInfo.name.equals(ri.activityInfo.name)
607 && bestMatch.activityInfo.applicationInfo.packageName
608 .equals(ri.activityInfo.applicationInfo.packageName)) {
609 found = true;
610 break;
611 }
612 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700613
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400614 if (!found) {
615 if (LOGD) Log.d(TAG, "Multiple options, no default yet");
616 // the bestMatch is probably the ResolveActivity, meaning the
617 // user has not yet selected a default
618 // so: we'll keep the original intent for now
619 mHotseats[i] = intent;
620
621 // set the accessibility text to "Select shortcut"
622 mHotseatLabels[i] = getText(R.string.title_select_shortcut);
623 } else {
624 // we have an app!
625 // now reconstruct the intent to launch it through the front
626 // door
627 ComponentName com = new ComponentName(
628 bestMatch.activityInfo.applicationInfo.packageName,
629 bestMatch.activityInfo.name);
630 mHotseats[i] = new Intent(Intent.ACTION_MAIN).setComponent(com);
631
632 // load the app label for accessibility
633 mHotseatLabels[i] = bestMatch.activityInfo.loadLabel(pm);
634 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400635 }
636
637 if (LOGD) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700638 Log.d(TAG, "loadHotseats: hotseat " + i
639 + " final intent=["
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400640 + ((mHotseats[i] == null)
641 ? "null"
642 : mHotseats[i].toUri(Intent.URI_INTENT_SCHEME))
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400643 + "] label=[" + mHotseatLabels[i]
644 + "]"
645 );
646 }
647 }
648 }
649
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800650 @Override
651 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Romain Guyaad5ef42009-06-10 02:48:37 -0700652 mWaitingForResult = false;
653
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800654 // The pattern used here is that a user PICKs a specific application,
655 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700656
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800657 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
658 // launch over to the Music app to actually CREATE_SHORTCUT.
Romain Guycbb89e42009-06-08 15:52:54 -0700659
Michael Jurka0280c3b2010-09-17 15:00:07 -0700660 if (resultCode == RESULT_OK && mAddScreen != -1) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800661 switch (requestCode) {
662 case REQUEST_PICK_APPLICATION:
Michael Jurka28750fb2010-09-24 17:43:49 -0700663 completeAddApplication(
664 this, data, mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800665 break;
666 case REQUEST_PICK_SHORTCUT:
Joe Onoratodeb98af2010-02-19 14:59:39 -0800667 processShortcut(data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800668 break;
669 case REQUEST_CREATE_SHORTCUT:
Michael Jurka0280c3b2010-09-17 15:00:07 -0700670 completeAddShortcut(data, mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800671 break;
672 case REQUEST_PICK_LIVE_FOLDER:
673 addLiveFolder(data);
674 break;
675 case REQUEST_CREATE_LIVE_FOLDER:
Michael Jurka0280c3b2010-09-17 15:00:07 -0700676 completeAddLiveFolder(data, mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800677 break;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700678 case REQUEST_PICK_APPWIDGET:
Michael Jurkaaf442092010-06-10 17:01:57 -0700679 addAppWidgetFromPick(data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800680 break;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700681 case REQUEST_CREATE_APPWIDGET:
Michael Jurkaaf442092010-06-10 17:01:57 -0700682 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700683 completeAddAppWidget(appWidgetId, mAddScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800684 break;
Mike Clerona0618e42009-10-22 13:55:21 -0700685 case REQUEST_PICK_WALLPAPER:
686 // We just wanted the activity result here so we can clear mWaitingForResult
687 break;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800688 }
Romain Guy18042c82009-11-06 11:44:55 -0800689 } else if ((requestCode == REQUEST_PICK_APPWIDGET ||
690 requestCode == REQUEST_CREATE_APPWIDGET) && resultCode == RESULT_CANCELED &&
691 data != null) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700692 // Clean up the appWidgetId if we canceled
693 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
694 if (appWidgetId != -1) {
695 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800696 }
697 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800698 }
699
700 @Override
701 protected void onResume() {
702 super.onResume();
703
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800704 mPaused = false;
Joe Onorato7e4ed992009-12-03 13:10:49 -0800705
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800706 if (mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400707 mWorkspaceLoading = true;
708 mModel.startLoader(this, true);
709 mRestoring = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800710 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700711 // When we resume Launcher, a different Activity might be responsible for the app
712 // market intent, so refresh the icon
713 updateAppMarketIcon();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800714 }
715
716 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700717 protected void onPause() {
718 super.onPause();
Michael Jurkaaf442092010-06-10 17:01:57 -0700719 // Some launcher layouts don't have a previous and next view
720 if (mPreviousView != null) {
721 dismissPreview(mPreviousView);
Patrick Dubroyab962b72010-07-26 12:10:10 -0700722 }
723 if (mNextView != null) {
Michael Jurkaaf442092010-06-10 17:01:57 -0700724 dismissPreview(mNextView);
725 }
Joe Onorato24b6fd82009-11-12 13:47:09 -0800726 mDragController.cancelDrag();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700727 }
Romain Guycbb89e42009-06-08 15:52:54 -0700728
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700729 @Override
730 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400731 // Flag the loader to stop early before switching
732 mModel.stopLoader();
Romain Guy13c2e7b2010-03-10 19:45:00 -0800733 mAllAppsGrid.surrender();
Romain Guy13c2e7b2010-03-10 19:45:00 -0800734 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700735 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700736
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800737 // We can't hide the IME if it was forced open. So don't bother
738 /*
739 @Override
740 public void onWindowFocusChanged(boolean hasFocus) {
741 super.onWindowFocusChanged(hasFocus);
742
743 if (hasFocus) {
744 final InputMethodManager inputManager = (InputMethodManager)
745 getSystemService(Context.INPUT_METHOD_SERVICE);
746 WindowManager.LayoutParams lp = getWindow().getAttributes();
747 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
748 android.os.Handler()) {
749 protected void onReceiveResult(int resultCode, Bundle resultData) {
750 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
751 }
752 });
753 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
754 }
755 }
756 */
757
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800758 private boolean acceptFilter() {
759 final InputMethodManager inputManager = (InputMethodManager)
760 getSystemService(Context.INPUT_METHOD_SERVICE);
761 return !inputManager.isFullscreenMode();
762 }
763
764 @Override
765 public boolean onKeyDown(int keyCode, KeyEvent event) {
766 boolean handled = super.onKeyDown(keyCode, event);
767 if (!handled && acceptFilter() && keyCode != KeyEvent.KEYCODE_ENTER) {
768 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
769 keyCode, event);
770 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700771 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700772 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700773 // showSearchDialog()
774 // If there are multiple keystrokes before the search dialog takes focus,
775 // onSearchRequested() will be called for every keystroke,
776 // but it is idempotent, so it's fine.
777 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800778 }
779 }
780
Joe Onorato8a9625e2010-01-28 15:55:35 -0800781 // Eat the long press event so the keyboard doesn't come up.
782 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
783 return true;
784 }
785
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800786 return handled;
787 }
788
Karl Rosaen138a0412009-04-23 19:00:21 -0700789 private String getTypedText() {
790 return mDefaultKeySsb.toString();
791 }
792
793 private void clearTypedText() {
794 mDefaultKeySsb.clear();
795 mDefaultKeySsb.clearSpans();
796 Selection.setSelection(mDefaultKeySsb, 0);
797 }
798
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800799 /**
800 * Restores the previous state, if it exists.
801 *
802 * @param savedState The previous state.
803 */
804 private void restoreState(Bundle savedState) {
805 if (savedState == null) {
806 return;
807 }
808
Joe Onorato3a8820b2009-11-10 15:06:42 -0800809 final boolean allApps = savedState.getBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, false);
810 if (allApps) {
811 showAllApps(false);
812 }
813
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800814 final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
815 if (currentScreen > -1) {
Michael Jurka0142d492010-08-25 17:46:15 -0700816 mWorkspace.setCurrentPage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800817 }
818
819 final int addScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700820
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800821 if (addScreen > -1) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700822 mAddScreen = addScreen;
823 mAddIntersectCellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
824 mAddIntersectCellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800825 mRestoring = true;
826 }
827
828 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
829 if (renameFolder) {
830 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700831 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800832 mRestoring = true;
833 }
834 }
835
836 /**
837 * Finds all the views we need and configure them properly.
838 */
839 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700840 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -0400841
Romain Guyb1b69f52009-08-10 15:10:15 -0700842 DragLayer dragLayer = (DragLayer) findViewById(R.id.drag_layer);
Joe Onorato00acb122009-08-04 16:04:30 -0400843 dragLayer.setDragController(dragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800844
Joe Onorato7c312c12009-08-13 21:36:53 -0700845 mAllAppsGrid = (AllAppsView)dragLayer.findViewById(R.id.all_apps_view);
Joe Onorato6665c0f2009-09-02 15:27:24 -0700846 mAllAppsGrid.setLauncher(this);
Joe Onorato5162ea92009-09-03 09:39:42 -0700847 mAllAppsGrid.setDragController(dragController);
Romain Guyc16fea72010-03-12 17:17:56 -0800848 ((View) mAllAppsGrid).setWillNotDraw(false); // We don't want a hole punched in our window.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700849 // Manage focusability manually since this thing is always visible (in non-xlarge)
Winson Chungaafa03c2010-06-11 17:34:16 -0700850 ((View) mAllAppsGrid).setFocusable(false);
Joe Onorato7c312c12009-08-13 21:36:53 -0700851
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700852 if (LauncherApplication.isScreenXLarge()) {
853 // They need to be INVISIBLE initially so that they will be measured in the layout.
854 // Otherwise the animations are messed up when we show them for the first time.
855 ((View) mAllAppsGrid).setVisibility(View.INVISIBLE);
856 mHomeCustomizationDrawer.setVisibility(View.INVISIBLE);
857 }
858
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800859 mWorkspace = (Workspace) dragLayer.findViewById(R.id.workspace);
860 final Workspace workspace = mWorkspace;
Joe Onoratof0dde092010-02-16 18:25:23 -0500861 workspace.setHapticFeedbackEnabled(false);
Michael Jurka946ad472010-07-09 18:05:18 -0700862
Joe Onorato7c312c12009-08-13 21:36:53 -0700863 DeleteZone deleteZone = (DeleteZone) dragLayer.findViewById(R.id.delete_zone);
864 mDeleteZone = deleteZone;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800865
Michael Jurka2c3af5f2010-08-03 13:53:20 -0700866 View handleView = findViewById(R.id.all_apps_button);
867 if (handleView != null && handleView instanceof HandleView) {
868 // we don't use handle view in xlarge mode
Michael Jurka7ef4f752010-08-03 16:04:26 -0700869 mHandleView = (HandleView)handleView;
Michael Jurka2c3af5f2010-08-03 13:53:20 -0700870 mHandleView.setLauncher(this);
871 mHandleView.setOnClickListener(this);
872 mHandleView.setOnLongClickListener(this);
873 }
Romain Guy1fbc1c82009-11-09 20:43:08 -0800874
Winson Chung80baf5a2010-08-09 16:03:15 -0700875 if (mCustomizePagedView != null) {
876 mCustomizePagedView.setLauncher(this);
877 mCustomizePagedView.setDragController(dragController);
878 mCustomizePagedView.update();
Michael Jurkaaf442092010-06-10 17:01:57 -0700879 } else {
880 ImageView hotseatLeft = (ImageView) findViewById(R.id.hotseat_left);
881 hotseatLeft.setContentDescription(mHotseatLabels[0]);
882 hotseatLeft.setImageDrawable(mHotseatIcons[0]);
883 ImageView hotseatRight = (ImageView) findViewById(R.id.hotseat_right);
884 hotseatRight.setContentDescription(mHotseatLabels[1]);
885 hotseatRight.setImageDrawable(mHotseatIcons[1]);
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400886
Michael Jurkaaf442092010-06-10 17:01:57 -0700887 mPreviousView = (ImageView) dragLayer.findViewById(R.id.previous_screen);
888 mNextView = (ImageView) dragLayer.findViewById(R.id.next_screen);
Romain Guy1fbc1c82009-11-09 20:43:08 -0800889
Michael Jurkaaf442092010-06-10 17:01:57 -0700890 Drawable previous = mPreviousView.getDrawable();
891 Drawable next = mNextView.getDrawable();
892 mWorkspace.setIndicators(previous, next);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800893
Michael Jurkaaf442092010-06-10 17:01:57 -0700894 mPreviousView.setHapticFeedbackEnabled(false);
895 mPreviousView.setOnLongClickListener(this);
896 mNextView.setHapticFeedbackEnabled(false);
897 mNextView.setOnLongClickListener(this);
898 }
Romain Guy1fbc1c82009-11-09 20:43:08 -0800899
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800900 workspace.setOnLongClickListener(this);
Joe Onorato00acb122009-08-04 16:04:30 -0400901 workspace.setDragController(dragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800902 workspace.setLauncher(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800903
904 deleteZone.setLauncher(this);
Joe Onorato00acb122009-08-04 16:04:30 -0400905 deleteZone.setDragController(dragController);
Michael Jurka54f7ac32010-08-02 13:56:46 -0700906 int deleteZoneHandleId;
907 if (LauncherApplication.isScreenXLarge()) {
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700908 deleteZoneHandleId = R.id.all_apps_button;
Michael Jurka54f7ac32010-08-02 13:56:46 -0700909 } else {
910 deleteZoneHandleId = R.id.all_apps_button_cluster;
911 }
Michael Jurkaaf442092010-06-10 17:01:57 -0700912 deleteZone.setHandle(findViewById(deleteZoneHandleId));
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700913 dragController.addDragListener(deleteZone);
914
915 ApplicationInfoDropTarget infoButton = (ApplicationInfoDropTarget)findViewById(R.id.info_button);
916 if (infoButton != null) {
917 infoButton.setLauncher(this);
918 infoButton.setHandle(findViewById(R.id.configure_button));
919 infoButton.setDragColor(getResources().getColor(R.color.app_info_filter));
920 dragController.addDragListener(infoButton);
921 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800922
Joe Onorato00acb122009-08-04 16:04:30 -0400923 dragController.setDragScoller(workspace);
Joe Onorato00acb122009-08-04 16:04:30 -0400924 dragController.setScrollView(dragLayer);
Romain Guyea3763c2010-01-11 18:02:04 -0800925 dragController.setMoveTarget(workspace);
Jason Samsfd22dac2009-09-20 17:24:16 -0700926
Joe Onorato00acb122009-08-04 16:04:30 -0400927 // The order here is bottom to top.
928 dragController.addDropTarget(workspace);
929 dragController.addDropTarget(deleteZone);
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700930 if (infoButton != null) {
931 dragController.addDropTarget(infoButton);
932 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800933 }
934
Romain Guy8a73c512009-11-09 19:19:59 -0800935 @SuppressWarnings({"UnusedDeclaration"})
936 public void previousScreen(View v) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700937 if (mState != State.ALL_APPS) {
Joe Onorato61597bd2009-11-19 12:51:57 -0800938 mWorkspace.scrollLeft();
939 }
Romain Guy8a73c512009-11-09 19:19:59 -0800940 }
941
942 @SuppressWarnings({"UnusedDeclaration"})
943 public void nextScreen(View v) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700944 if (mState != State.ALL_APPS) {
Joe Onorato61597bd2009-11-19 12:51:57 -0800945 mWorkspace.scrollRight();
946 }
Romain Guy8a73c512009-11-09 19:19:59 -0800947 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400948
949 @SuppressWarnings({"UnusedDeclaration"})
950 public void launchHotSeat(View v) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -0700951 if (mState == State.ALL_APPS) return;
Daniel Sandler3e9454a2010-05-24 11:22:41 -0400952
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400953 int index = -1;
954 if (v.getId() == R.id.hotseat_left) {
955 index = 0;
956 } else if (v.getId() == R.id.hotseat_right) {
957 index = 1;
958 }
959
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400960 // reload these every tap; you never know when they might change
961 loadHotseats();
962 if (index >= 0 && index < mHotseats.length && mHotseats[index] != null) {
963 Intent intent = mHotseats[index];
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400964 startActivitySafely(
965 mHotseats[index],
966 "hotseat"
967 );
968 }
969 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700970
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800971 /**
972 * Creates a view representing a shortcut.
973 *
974 * @param info The data structure describing the shortcut.
975 *
976 * @return A View inflated from R.layout.application.
977 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800978 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800979 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -0700980 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800981 }
982
983 /**
984 * Creates a view representing a shortcut inflated from the specified resource.
985 *
986 * @param layoutResId The id of the XML layout used to create the shortcut.
987 * @param parent The group the shortcut belongs to.
988 * @param info The data structure describing the shortcut.
989 *
990 * @return A View inflated from layoutResId.
991 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800992 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800993 TextView favorite = (TextView) mInflater.inflate(layoutResId, parent, false);
994
Joe Onorato0589f0f2010-02-08 13:44:00 -0800995 favorite.setCompoundDrawablesWithIntrinsicBounds(null,
996 new FastBitmapDrawable(info.getIcon(mIconCache)),
997 null, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800998 favorite.setText(info.title);
999 favorite.setTag(info);
1000 favorite.setOnClickListener(this);
1001
1002 return favorite;
1003 }
1004
1005 /**
1006 * Add an application shortcut to the workspace.
1007 *
1008 * @param data The intent describing the application.
1009 * @param cellInfo The position on screen where to create the shortcut.
1010 */
Michael Jurka0280c3b2010-09-17 15:00:07 -07001011 void completeAddApplication(Context context, Intent data, int screen,
1012 int intersectCellX, int intersectCellY) {
1013 final int[] cellXY = mTmpAddItemCellCoordinates;
1014 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1015
1016 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1017 showOutOfSpaceMessage();
1018 return;
1019 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001020
Joe Onorato0589f0f2010-02-08 13:44:00 -08001021 final ShortcutInfo info = mModel.getShortcutInfo(context.getPackageManager(),
1022 data, context);
1023
Romain Guy73b979d2009-06-09 12:57:21 -07001024 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -08001025 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001026 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001027 info.container = ItemInfo.NO_ID;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001028 mWorkspace.addApplicationShortcut(info, screen, cellXY[0], cellXY[1],
1029 isWorkspaceLocked(), mAddIntersectCellX, mAddIntersectCellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001030 } else {
1031 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001032 }
1033 }
Romain Guycbb89e42009-06-08 15:52:54 -07001034
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001035 /**
1036 * Add a shortcut to the workspace.
1037 *
1038 * @param data The intent describing the shortcut.
1039 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001040 */
Michael Jurka0280c3b2010-09-17 15:00:07 -07001041 private void completeAddShortcut(Intent data, int screen,
1042 int intersectCellX, int intersectCellY) {
1043 final int[] cellXY = mTmpAddItemCellCoordinates;
1044 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
Romain Guycbb89e42009-06-08 15:52:54 -07001045
Michael Jurka0280c3b2010-09-17 15:00:07 -07001046 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1047 showOutOfSpaceMessage();
1048 return;
1049 }
1050
1051 final ShortcutInfo info = mModel.addShortcut(
1052 this, data, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001053
1054 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001055 final View view = createShortcut(info);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001056 mWorkspace.addInScreen(view, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001057 }
1058 }
1059
Romain Guycbb89e42009-06-08 15:52:54 -07001060
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001061 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001062 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001063 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001064 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001065 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001066 */
Michael Jurka0280c3b2010-09-17 15:00:07 -07001067 private void completeAddAppWidget(int appWidgetId, int screen) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001068 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Romain Guycbb89e42009-06-08 15:52:54 -07001069
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001070 // Calculate the grid spans needed to fit this widget
Michael Jurka0280c3b2010-09-17 15:00:07 -07001071 CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1072 int[] spanXY = layout.rectToCell(appWidgetInfo.minWidth, appWidgetInfo.minHeight, null);
Romain Guycbb89e42009-06-08 15:52:54 -07001073
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001074 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001075 // We have saved the position to which the widget was dragged-- this really only matters
1076 // if we are placing widgets on a "spring-loaded" screen
Michael Jurka0280c3b2010-09-17 15:00:07 -07001077 final int[] cellXY = mTmpAddItemCellCoordinates;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001078
1079 // For now, we don't save the coordinate where we dropped the icon because we're not
1080 // supporting spring-loaded mini-screens; however, leaving the ability to directly place
1081 // a widget on the home screen in case we want to add it in the future
Michael Jurka0280c3b2010-09-17 15:00:07 -07001082 final int[] touchXY = null;
1083 //final int[] touchXY = mAddDropPosition;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001084 boolean findNearestVacantAreaFailed = false;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001085 boolean foundCellSpan = false;
1086 if (touchXY != null) {
1087 // when dragging and dropping, just find the closest free spot
1088 CellLayout screenLayout = (CellLayout) mWorkspace.getChildAt(screen);
1089 int[] result = screenLayout.findNearestVacantArea(
1090 touchXY[0], touchXY[1], spanXY[0], spanXY[1], cellXY);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001091 findNearestVacantAreaFailed = (result == null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001092 foundCellSpan = !findNearestVacantAreaFailed;
1093 } else {
1094 if (mAddIntersectCellX != -1 && mAddIntersectCellY != -1) {
1095 // if we long pressed on an empty cell to bring up a menu,
1096 // make sure we intersect the empty cell
1097 foundCellSpan = layout.findCellForSpanThatIntersects(cellXY, spanXY[0], spanXY[1],
1098 mAddIntersectCellX, mAddIntersectCellY);
1099 } else {
1100 // if we went through the menu -> add, just find any spot
1101 foundCellSpan = layout.findCellForSpan(cellXY, spanXY[0], spanXY[1]);
1102 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001103 }
1104
Michael Jurka0280c3b2010-09-17 15:00:07 -07001105 if (!foundCellSpan) {
Romain Guy18042c82009-11-06 11:44:55 -08001106 if (appWidgetId != -1) mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001107 showOutOfSpaceMessage();
Romain Guy18042c82009-11-06 11:44:55 -08001108 return;
1109 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001110
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001111 // Build Launcher-specific widget info and save to database
1112 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001113 launcherInfo.spanX = spanXY[0];
1114 launcherInfo.spanY = spanXY[1];
Romain Guycbb89e42009-06-08 15:52:54 -07001115
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001116 LauncherModel.addItemToDatabase(this, launcherInfo,
1117 LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001118 screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001119
1120 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001121 mDesktopItems.add(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001122
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001123 // Perform actual inflation because we're live
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001124 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001125
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001126 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001127 launcherInfo.hostView.setTag(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001128
Michael Jurka0280c3b2010-09-17 15:00:07 -07001129 mWorkspace.addInScreen(launcherInfo.hostView, screen, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001130 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001131 }
1132 }
Romain Guycbb89e42009-06-08 15:52:54 -07001133
Michael Jurka0280c3b2010-09-17 15:00:07 -07001134 void showOutOfSpaceMessage() {
1135 Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show();
1136 }
1137
Joe Onorato9c1289c2009-08-17 11:03:03 -04001138 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
1139 mDesktopItems.remove(launcherInfo);
1140 launcherInfo.hostView = null;
1141 }
1142
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001143 public LauncherAppWidgetHost getAppWidgetHost() {
1144 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001145 }
Romain Guycbb89e42009-06-08 15:52:54 -07001146
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001147 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001148 getWindow().closeAllPanels();
1149
1150 try {
1151 dismissDialog(DIALOG_CREATE_SHORTCUT);
1152 // Unlock the workspace if the dialog was showing
1153 } catch (Exception e) {
1154 // An exception is thrown if the dialog is not visible, which is fine
1155 }
1156
1157 try {
1158 dismissDialog(DIALOG_RENAME_FOLDER);
1159 // Unlock the workspace if the dialog was showing
1160 } catch (Exception e) {
1161 // An exception is thrown if the dialog is not visible, which is fine
1162 }
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001163
1164 // Whatever we were doing is hereby canceled.
1165 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001166 }
1167
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001168 @Override
1169 protected void onNewIntent(Intent intent) {
1170 super.onNewIntent(intent);
1171
1172 // Close the menu
1173 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001174 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001175 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001176
Joe Onorato14f122b2009-11-19 14:06:36 -08001177 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1178 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
Michael Jurka01f0ed42010-08-20 00:41:17 -07001179
Michael Jurka4cb37242010-08-09 21:05:32 -07001180 // in all these cases, only animate if we're already on home
1181 if (LauncherApplication.isScreenXLarge()) {
Michael Jurka99229f62010-09-09 11:49:32 -07001182 mWorkspace.unshrink(alreadyOnHome);
1183 }
1184 if (!mWorkspace.isDefaultPageShowing()) {
Michael Jurka4cb37242010-08-09 21:05:32 -07001185 // on the phone, we don't animate the change to the workspace if all apps is visible
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001186 mWorkspace.moveToDefaultScreen(alreadyOnHome &&
1187 (LauncherApplication.isScreenXLarge() || mState != State.ALL_APPS));
Joe Onorato3a8820b2009-11-10 15:06:42 -08001188 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001189 showWorkspace(alreadyOnHome);
Romain Guy1dd3a072009-07-16 13:21:01 -07001190
Joe Onorato3a8820b2009-11-10 15:06:42 -08001191 final View v = getWindow().peekDecorView();
1192 if (v != null && v.getWindowToken() != null) {
1193 InputMethodManager imm = (InputMethodManager)getSystemService(
1194 INPUT_METHOD_SERVICE);
1195 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001196 }
1197 }
1198 }
1199
1200 @Override
1201 protected void onRestoreInstanceState(Bundle savedInstanceState) {
1202 // Do not call super here
1203 mSavedInstanceState = savedInstanceState;
Michael Jurka946ad472010-07-09 18:05:18 -07001204
1205 if (mHomeCustomizationDrawer != null) {
1206 String cur = savedInstanceState.getString("currentTab");
1207 if (cur != null) {
1208 mHomeCustomizationDrawer.setCurrentTabByTag(cur);
1209 }
1210 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001211 }
1212
1213 @Override
1214 protected void onSaveInstanceState(Bundle outState) {
Michael Jurka0142d492010-08-25 17:46:15 -07001215 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001216
1217 final ArrayList<Folder> folders = mWorkspace.getOpenFolders();
1218 if (folders.size() > 0) {
1219 final int count = folders.size();
1220 long[] ids = new long[count];
1221 for (int i = 0; i < count; i++) {
1222 final FolderInfo info = folders.get(i).getInfo();
1223 ids[i] = info.id;
1224 }
1225 outState.putLongArray(RUNTIME_STATE_USER_FOLDERS, ids);
1226 } else {
1227 super.onSaveInstanceState(outState);
1228 }
1229
Joe Onoratofb0ca672009-09-14 17:55:46 -04001230 // TODO should not do this if the drawer is currently closing.
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001231 if (mState == State.ALL_APPS) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001232 outState.putBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, true);
Romain Guy5a941392009-04-28 15:18:25 -07001233 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001234
Michael Jurka0280c3b2010-09-17 15:00:07 -07001235 if (mAddScreen > -1 && mWaitingForResult) {
1236 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mAddScreen);
1237 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mAddIntersectCellX);
1238 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001239 }
1240
1241 if (mFolderInfo != null && mWaitingForResult) {
1242 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1243 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1244 }
Michael Jurka946ad472010-07-09 18:05:18 -07001245
1246 if (mHomeCustomizationDrawer != null) {
1247 String currentTabTag = mHomeCustomizationDrawer.getCurrentTabTag();
1248 if (currentTabTag != null) {
1249 outState.putString("currentTab", currentTabTag);
1250 }
1251 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001252 }
1253
1254 @Override
1255 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001256 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001257
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001258 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001259 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001260 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001261 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001262 }
1263
1264 TextKeyListener.getInstance().release();
1265
Joe Onorato9c1289c2009-08-17 11:03:03 -04001266 mModel.stopLoader();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001267
Joe Onorato9c1289c2009-08-17 11:03:03 -04001268 unbindDesktopItems();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001269
1270 getContentResolver().unregisterContentObserver(mWidgetObserver);
Winson Chungaafa03c2010-06-11 17:34:16 -07001271
Patrick Dubroyab962b72010-07-26 12:10:10 -07001272 // Some launcher layouts don't have a previous and next view
1273 if (mPreviousView != null) {
1274 dismissPreview(mPreviousView);
1275 }
1276 if (mNextView != null) {
1277 dismissPreview(mNextView);
1278 }
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001279
1280 unregisterReceiver(mCloseSystemDialogsReceiver);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001281 }
1282
1283 @Override
1284 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001285 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001286 super.startActivityForResult(intent, requestCode);
1287 }
1288
1289 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001290 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001291 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001292
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001293 showWorkspace(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001294
Karl Rosaen138a0412009-04-23 19:00:21 -07001295 if (initialQuery == null) {
1296 // Use any text typed in the launcher as the initial query
1297 initialQuery = getTypedText();
1298 clearTypedText();
1299 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001300 if (appSearchData == null) {
1301 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +00001302 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001303 }
Romain Guycbb89e42009-06-08 15:52:54 -07001304
Karl Rosaen138a0412009-04-23 19:00:21 -07001305 final SearchManager searchManager =
1306 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Karl Rosaen138a0412009-04-23 19:00:21 -07001307 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Romain Guycbb89e42009-06-08 15:52:54 -07001308 appSearchData, globalSearch);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001309 }
1310
1311 @Override
1312 public boolean onCreateOptionsMenu(Menu menu) {
Patrick Dubroy5905bca2010-09-08 22:43:38 -07001313 if (isWorkspaceLocked()) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001314 return false;
1315 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001316
1317 super.onCreateOptionsMenu(menu);
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001318
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001319 menu.add(MENU_GROUP_ADD, MENU_ADD, 0, R.string.menu_add)
1320 .setIcon(android.R.drawable.ic_menu_add)
1321 .setAlphabeticShortcut('A');
Winson Chung7ad01412010-09-27 11:33:03 -07001322 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1323 .setIcon(android.R.drawable.ic_menu_manage)
1324 .setAlphabeticShortcut('M');
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001325 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001326 .setIcon(android.R.drawable.ic_menu_gallery)
1327 .setAlphabeticShortcut('W');
1328 menu.add(0, MENU_SEARCH, 0, R.string.menu_search)
1329 .setIcon(android.R.drawable.ic_search_category_default)
1330 .setAlphabeticShortcut(SearchManager.MENU_KEY);
1331 menu.add(0, MENU_NOTIFICATIONS, 0, R.string.menu_notifications)
1332 .setIcon(com.android.internal.R.drawable.ic_menu_notifications)
1333 .setAlphabeticShortcut('N');
1334
1335 final Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
Romain Guy5a941392009-04-28 15:18:25 -07001336 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
1337 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001338
1339 menu.add(0, MENU_SETTINGS, 0, R.string.menu_settings)
1340 .setIcon(android.R.drawable.ic_menu_preferences).setAlphabeticShortcut('P')
1341 .setIntent(settings);
1342
1343 return true;
1344 }
1345
1346 @Override
1347 public boolean onPrepareOptionsMenu(Menu menu) {
1348 super.onPrepareOptionsMenu(menu);
1349
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001350 // If all apps is animating, don't show the menu, because we don't know
1351 // which one to show.
Patrick Dubroyff5f0402010-07-26 15:23:26 -07001352 if (mAllAppsGrid.isAnimating()) {
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001353 return false;
1354 }
1355
1356 // Only show the add and wallpaper options when we're not in all apps.
Patrick Dubroyff5f0402010-07-26 15:23:26 -07001357 boolean visible = !mAllAppsGrid.isVisible();
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001358 menu.setGroupVisible(MENU_GROUP_ADD, visible);
1359 menu.setGroupVisible(MENU_GROUP_WALLPAPER, visible);
1360
1361 // Disable add if the workspace is full.
1362 if (visible) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001363 CellLayout layout = (CellLayout) mWorkspace.getChildAt(mWorkspace.getCurrentPage());
1364 menu.setGroupEnabled(MENU_GROUP_ADD, layout.existsEmptyCell());
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001365 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001366
1367 return true;
1368 }
1369
1370 @Override
1371 public boolean onOptionsItemSelected(MenuItem item) {
1372 switch (item.getItemId()) {
1373 case MENU_ADD:
1374 addItems();
1375 return true;
Winson Chung7ad01412010-09-27 11:33:03 -07001376 case MENU_MANAGE_APPS:
1377 manageApps();
1378 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001379 case MENU_WALLPAPER_SETTINGS:
1380 startWallpaper();
1381 return true;
1382 case MENU_SEARCH:
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001383 onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001384 return true;
1385 case MENU_NOTIFICATIONS:
1386 showNotifications();
1387 return true;
1388 }
1389
1390 return super.onOptionsItemSelected(item);
1391 }
Romain Guycbb89e42009-06-08 15:52:54 -07001392
Karl Rosaen138a0412009-04-23 19:00:21 -07001393 /**
1394 * Indicates that we want global search for this activity by setting the globalSearch
1395 * argument for {@link #startSearch} to true.
1396 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001397
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001398 @Override
1399 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001400 startSearch(null, false, null, true);
Karl Rosaen138a0412009-04-23 19:00:21 -07001401 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001402 }
1403
Joe Onorato9c1289c2009-08-17 11:03:03 -04001404 public boolean isWorkspaceLocked() {
1405 return mWorkspaceLoading || mWaitingForResult;
1406 }
1407
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001408 private void addItems() {
Patrick Dubroy558654c2010-07-23 16:48:11 -07001409 if (LauncherApplication.isScreenXLarge()) {
1410 // Animate the widget chooser up from the bottom of the screen
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001411 if (mState != State.CUSTOMIZE) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07001412 showCustomizationDrawer(true);
Patrick Dubroy558654c2010-07-23 16:48:11 -07001413 }
1414 } else {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001415 showWorkspace(true);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001416 showAddDialog(-1, -1);
Patrick Dubroy558654c2010-07-23 16:48:11 -07001417 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001418 }
1419
Michael Jurka0280c3b2010-09-17 15:00:07 -07001420 private void resetAddInfo() {
1421 mAddScreen = -1;
1422 mAddIntersectCellX = -1;
1423 mAddIntersectCellY = -1;
1424 mAddDropPosition = null;
1425 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001426
Michael Jurka0280c3b2010-09-17 15:00:07 -07001427 void addAppWidgetFromDrop(ComponentName appWidgetProvider, int screen, int[] position) {
1428 resetAddInfo();
1429 mAddScreen = screen;
1430
1431 // only set mAddDropPosition if we dropped on home screen in "spring-loaded" manner
1432 mAddDropPosition = position;
1433
Michael Jurkaaf442092010-06-10 17:01:57 -07001434 int appWidgetId = getAppWidgetHost().allocateAppWidgetId();
1435 AppWidgetManager.getInstance(this).bindAppWidgetId(appWidgetId, appWidgetProvider);
1436 addAppWidgetImpl(appWidgetId);
1437 }
1438
Winson Chung7ad01412010-09-27 11:33:03 -07001439 private void manageApps() {
1440 startActivity(new Intent(android.provider.Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS));
1441 }
1442
Michael Jurkaaf442092010-06-10 17:01:57 -07001443 void addAppWidgetFromPick(Intent data) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001444 // TODO: catch bad widget exception when sent
1445 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurkaaf442092010-06-10 17:01:57 -07001446 // TODO: Is this log message meaningful?
1447 if (LOGD) Log.d(TAG, "dumping extras content=" + data.getExtras());
1448 addAppWidgetImpl(appWidgetId);
1449 }
1450
1451 void addAppWidgetImpl(int appWidgetId) {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001452 AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001453
Bjorn Bringert7984c942009-12-09 15:38:25 +00001454 if (appWidget.configure != null) {
1455 // Launch over to configure widget, if needed
1456 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
1457 intent.setComponent(appWidget.configure);
1458 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
1459
Romain Guy8e633c52010-03-04 12:51:36 -08001460 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001461 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001462 // Otherwise just add it
Michael Jurka0280c3b2010-09-17 15:00:07 -07001463 completeAddAppWidget(appWidgetId, mAddScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001464 }
1465 }
Romain Guycbb89e42009-06-08 15:52:54 -07001466
Michael Jurka0280c3b2010-09-17 15:00:07 -07001467 void processShortcutFromDrop(ComponentName componentName, int screen, int[] position) {
1468 resetAddInfo();
1469 mAddScreen = screen;
1470 mAddDropPosition = position;
1471
1472 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1473 createShortcutIntent.setComponent(componentName);
1474 processShortcut(createShortcutIntent);
1475 }
1476
Joe Onoratodeb98af2010-02-19 14:59:39 -08001477 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001478 // Handle case where user selected "Applications"
1479 String applicationName = getResources().getString(R.string.group_applications);
1480 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001481
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001482 if (applicationName != null && applicationName.equals(shortcutName)) {
1483 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1484 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001485
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001486 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1487 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Winson Chung58f20882010-10-01 13:44:56 -07001488 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Joe Onorato4a79a042010-09-24 16:17:21 -07001489 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001490 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001491 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001492 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001493 }
1494
Winson Chung24ab2f12010-09-16 14:10:47 -07001495 void processWallpaper(Intent intent) {
1496 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1497 }
1498
Michael Jurka0280c3b2010-09-17 15:00:07 -07001499 void addLiveFolderFromDrop(ComponentName componentName, int screen, int[] position) {
1500 resetAddInfo();
1501 mAddScreen = screen;
1502 mAddDropPosition = position;
1503
1504 Intent createFolderIntent = new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER);
1505 createFolderIntent.setComponent(componentName);
1506
1507 addLiveFolder(createFolderIntent);
1508 }
1509
1510 void addLiveFolder(Intent intent) { // YYY add screen intersect etc. parameters here
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001511 // Handle case where user selected "Folder"
Jeffrey Sharkeyc4bbd0a2009-03-24 22:47:52 -07001512 String folderName = getResources().getString(R.string.group_folder);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001513 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001514
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001515 if (folderName != null && folderName.equals(shortcutName)) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001516 addFolder(mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001517 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001518 startActivityForResultSafely(intent, REQUEST_CREATE_LIVE_FOLDER);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001519 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001520 }
1521
Michael Jurka0280c3b2010-09-17 15:00:07 -07001522 void addFolder(int screen, int intersectCellX, int intersectCellY) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001523 UserFolderInfo folderInfo = new UserFolderInfo();
1524 folderInfo.title = getText(R.string.folder_name);
1525
Michael Jurka0280c3b2010-09-17 15:00:07 -07001526 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1527 final int[] cellXY = mTmpAddItemCellCoordinates;
1528 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1529 showOutOfSpaceMessage();
1530 return;
1531 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001532
1533 // Update the model
Joe Onorato9c1289c2009-08-17 11:03:03 -04001534 LauncherModel.addItemToDatabase(this, folderInfo,
1535 LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001536 screen, cellXY[0], cellXY[1], false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001537 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001538
1539 // Create the view
1540 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07001541 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), folderInfo);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001542 mWorkspace.addInScreen(newFolder, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001543 }
Romain Guycbb89e42009-06-08 15:52:54 -07001544
Joe Onorato9c1289c2009-08-17 11:03:03 -04001545 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001546 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001547 }
1548
Michael Jurka28750fb2010-09-24 17:43:49 -07001549 private void completeAddLiveFolder(
1550 Intent data, int screen, int intersectCellX, int intersectCellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001551 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1552 final int[] cellXY = mTmpAddItemCellCoordinates;
1553 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1554 showOutOfSpaceMessage();
1555 return;
1556 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001557
Michael Jurka0280c3b2010-09-17 15:00:07 -07001558 final LiveFolderInfo info = addLiveFolder(this, data, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001559
1560 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001561 final View view = LiveFolderIcon.fromXml(R.layout.live_folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07001562 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001563 mWorkspace.addInScreen(view, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001564 }
1565 }
1566
1567 static LiveFolderInfo addLiveFolder(Context context, Intent data,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001568 int screen, int cellX, int cellY, boolean notify) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001569
1570 Intent baseIntent = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT);
1571 String name = data.getStringExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME);
1572
1573 Drawable icon = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001574 Intent.ShortcutIconResource iconResource = null;
1575
1576 Parcelable extra = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON);
1577 if (extra != null && extra instanceof Intent.ShortcutIconResource) {
1578 try {
1579 iconResource = (Intent.ShortcutIconResource) extra;
1580 final PackageManager packageManager = context.getPackageManager();
1581 Resources resources = packageManager.getResourcesForApplication(
1582 iconResource.packageName);
1583 final int id = resources.getIdentifier(iconResource.resourceName, null, null);
1584 icon = resources.getDrawable(id);
1585 } catch (Exception e) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001586 Log.w(TAG, "Could not load live folder icon: " + extra);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001587 }
1588 }
1589
1590 if (icon == null) {
1591 icon = context.getResources().getDrawable(R.drawable.ic_launcher_folder);
1592 }
1593
1594 final LiveFolderInfo info = new LiveFolderInfo();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001595 info.icon = Utilities.createIconBitmap(icon, context);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001596 info.title = name;
1597 info.iconResource = iconResource;
1598 info.uri = data.getData();
1599 info.baseIntent = baseIntent;
1600 info.displayMode = data.getIntExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE,
1601 LiveFolders.DISPLAY_MODE_GRID);
1602
1603 LauncherModel.addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001604 screen, cellX, cellY, notify);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001605 sFolders.put(info.id, info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001606
1607 return info;
1608 }
1609
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001610 private void showNotifications() {
1611 final StatusBarManager statusBar = (StatusBarManager) getSystemService(STATUS_BAR_SERVICE);
1612 if (statusBar != null) {
1613 statusBar.expand();
1614 }
1615 }
1616
1617 private void startWallpaper() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001618 showWorkspace(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001619 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001620 Intent chooser = Intent.createChooser(pickWallpaper,
1621 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001622 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1623 // Removed in Eclair MR1
1624// WallpaperManager wm = (WallpaperManager)
1625// getSystemService(Context.WALLPAPER_SERVICE);
1626// WallpaperInfo wi = wm.getWallpaperInfo();
1627// if (wi != null && wi.getSettingsActivity() != null) {
1628// LabeledIntent li = new LabeledIntent(getPackageName(),
1629// R.string.configure_wallpaper, 0);
1630// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1631// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1632// }
Mike Clerona0618e42009-10-22 13:55:21 -07001633 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001634 }
1635
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001636 /**
1637 * Registers various content observers. The current implementation registers
1638 * only a favorites observer to keep track of the favorites applications.
1639 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001640 private void registerContentObservers() {
1641 ContentResolver resolver = getContentResolver();
1642 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1643 true, mWidgetObserver);
1644 }
1645
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001646 @Override
1647 public boolean dispatchKeyEvent(KeyEvent event) {
1648 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1649 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001650 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001651 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001652 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jason Samseb5615d2009-11-30 11:50:10 -08001653 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
Joe Onoratobe386092009-11-17 17:32:16 -08001654 dumpState();
1655 return true;
1656 }
1657 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001658 }
1659 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1660 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001661 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001662 return true;
1663 }
1664 }
1665
1666 return super.dispatchKeyEvent(event);
1667 }
1668
Joe Onorato88ec0992009-11-19 13:16:06 -08001669 @Override
1670 public void onBackPressed() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001671 if (mState == State.ALL_APPS || mState == State.CUSTOMIZE) {
1672 showWorkspace(true);
Joe Onorato88ec0992009-11-19 13:16:06 -08001673 } else {
1674 closeFolder();
1675 }
Michael Jurkaaf442092010-06-10 17:01:57 -07001676 // Some launcher layouts don't have a previous and next view
1677 if (mPreviousView != null) {
1678 dismissPreview(mPreviousView);
1679 dismissPreview(mNextView);
1680 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001681 }
1682
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001683 private void closeFolder() {
1684 Folder folder = mWorkspace.getOpenFolder();
1685 if (folder != null) {
1686 closeFolder(folder);
1687 }
1688 }
1689
1690 void closeFolder(Folder folder) {
1691 folder.getInfo().opened = false;
1692 ViewGroup parent = (ViewGroup) folder.getParent();
1693 if (parent != null) {
1694 parent.removeView(folder);
Joe Onoratob6341e92009-11-02 10:41:48 -05001695 if (folder instanceof DropTarget) {
1696 // Live folders aren't DropTargets.
1697 mDragController.removeDropTarget((DropTarget)folder);
1698 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001699 }
1700 folder.onClose();
1701 }
1702
1703 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001704 * Re-listen when widgets are reset.
1705 */
1706 private void onAppWidgetReset() {
1707 mAppWidgetHost.startListening();
1708 }
1709
1710 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001711 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1712 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001713 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04001714 private void unbindDesktopItems() {
1715 for (ItemInfo item: mDesktopItems) {
1716 item.unbind();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001717 }
1718 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001719
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001720 /**
1721 * Launches the intent referred by the clicked shortcut.
1722 *
1723 * @param v The view representing the clicked shortcut.
1724 */
1725 public void onClick(View v) {
1726 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001727 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001728 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08001729 final Intent intent = ((ShortcutInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001730 int[] pos = new int[2];
1731 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08001732 intent.setSourceBounds(new Rect(pos[0], pos[1],
1733 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Joe Onoratof984e852010-03-25 09:47:45 -07001734 startActivitySafely(intent, tag);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001735 } else if (tag instanceof FolderInfo) {
1736 handleFolderClick((FolderInfo) tag);
Joe Onorato7404ee42009-07-31 11:54:44 -07001737 } else if (v == mHandleView) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001738 if (mState == State.ALL_APPS) {
1739 showWorkspace(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001740 } else {
Joe Onorato3a8820b2009-11-10 15:06:42 -08001741 showAllApps(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001742 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001743 }
1744 }
1745
Michael Jurka0e260592010-06-30 17:07:39 -07001746 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07001747 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001748 // clicking anywhere on the workspace causes the customization drawer to slide down
1749 showWorkspace(true);
Michael Jurka0e260592010-06-30 17:07:39 -07001750 return false;
1751 }
1752
Michael Jurkaaf442092010-06-10 17:01:57 -07001753 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001754 * Event handler for the search button
1755 *
1756 * @param v The view that was clicked.
1757 */
1758 public void onClickSearchButton(View v) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07001759 startSearch(null, false, null, true);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001760 }
1761
1762 /**
1763 * Event handler for the "gear" button that appears on the home screen, which
Michael Jurkaaf442092010-06-10 17:01:57 -07001764 * enters home screen customization mode.
1765 *
1766 * @param v The view that was clicked.
1767 */
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001768 public void onClickConfigureButton(View v) {
Patrick Dubroy558654c2010-07-23 16:48:11 -07001769 addItems();
Michael Jurkaaf442092010-06-10 17:01:57 -07001770 }
1771
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001772 /**
1773 * Event handler for the "grid" button that appears on the home screen, which
1774 * enters all apps mode.
1775 *
1776 * @param v The view that was clicked.
1777 */
1778 public void onClickAllAppsButton(View v) {
1779 showAllApps(true);
1780 }
1781
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001782 public void onClickAppMarketButton(View v) {
1783 if (mAppMarketIntent != null) {
1784 startActivitySafely(mAppMarketIntent, "app market");
1785 }
1786 }
1787
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001788 void startApplicationDetailsActivity(ComponentName componentName) {
1789 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001790 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
1791 Uri.fromParts("package", packageName, null));
1792 startActivity(intent);
1793 }
1794
Patrick Dubroy5539af72010-09-07 15:22:01 -07001795 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
1796 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
1797 // System applications cannot be installed. For now, show a toast explaining that.
1798 // We may give them the option of disabling apps this way.
1799 int messageId = R.string.uninstall_system_app_text;
1800 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
1801 } else {
1802 String packageName = appInfo.componentName.getPackageName();
1803 String className = appInfo.componentName.getClassName();
1804 Intent intent = new Intent(
1805 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
1806 startActivity(intent);
1807 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001808 }
1809
Joe Onoratof984e852010-03-25 09:47:45 -07001810 void startActivitySafely(Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001811 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1812 try {
1813 startActivity(intent);
1814 } catch (ActivityNotFoundException e) {
1815 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Daniel Sandlerc9b18772010-04-22 14:37:59 -04001816 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001817 } catch (SecurityException e) {
1818 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001819 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001820 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07001821 "or use the exported attribute for this activity. "
1822 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001823 }
1824 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001825
Romain Guy8e633c52010-03-04 12:51:36 -08001826 void startActivityForResultSafely(Intent intent, int requestCode) {
1827 try {
1828 startActivityForResult(intent, requestCode);
1829 } catch (ActivityNotFoundException e) {
1830 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1831 } catch (SecurityException e) {
1832 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1833 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
1834 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
1835 "or use the exported attribute for this activity.", e);
1836 }
1837 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001838
1839 private void handleFolderClick(FolderInfo folderInfo) {
1840 if (!folderInfo.opened) {
1841 // Close any open folder
1842 closeFolder();
1843 // Open the requested folder
1844 openFolder(folderInfo);
1845 } else {
1846 // Find the open folder...
1847 Folder openFolder = mWorkspace.getFolderForTag(folderInfo);
1848 int folderScreen;
1849 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07001850 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001851 // .. and close it
1852 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07001853 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001854 // Close any folder open on the current screen
1855 closeFolder();
1856 // Pull the folder onto this screen
1857 openFolder(folderInfo);
1858 }
1859 }
1860 }
1861 }
1862
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001863 /**
1864 * Opens the user fodler described by the specified tag. The opening of the folder
1865 * is animated relative to the specified View. If the View is null, no animation
1866 * is played.
1867 *
1868 * @param folderInfo The FolderInfo describing the folder to open.
1869 */
Winson Chungaafa03c2010-06-11 17:34:16 -07001870 public void openFolder(FolderInfo folderInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001871 Folder openFolder;
1872
1873 if (folderInfo instanceof UserFolderInfo) {
1874 openFolder = UserFolder.fromXml(this);
1875 } else if (folderInfo instanceof LiveFolderInfo) {
Joe Onoratoa5902522009-07-30 13:37:37 -07001876 openFolder = com.android.launcher2.LiveFolder.fromXml(this, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001877 } else {
1878 return;
1879 }
1880
Joe Onorato00acb122009-08-04 16:04:30 -04001881 openFolder.setDragController(mDragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001882 openFolder.setLauncher(this);
1883
1884 openFolder.bind(folderInfo);
1885 folderInfo.opened = true;
1886
Winson Chungaafa03c2010-06-11 17:34:16 -07001887 mWorkspace.addInFullScreen(openFolder, folderInfo.screen);
1888
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001889 openFolder.onOpen();
1890 }
1891
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001892 public boolean onLongClick(View v) {
Romain Guy1fbc1c82009-11-09 20:43:08 -08001893 switch (v.getId()) {
1894 case R.id.previous_screen:
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001895 if (mState != State.ALL_APPS) {
Joe Onorato0d44e942009-11-16 18:20:51 -08001896 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1897 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Romain Guyf8e6a802009-12-07 17:48:02 -08001898 showPreviews(v);
Joe Onorato0d44e942009-11-16 18:20:51 -08001899 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08001900 return true;
1901 case R.id.next_screen:
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001902 if (mState != State.ALL_APPS) {
Joe Onorato0d44e942009-11-16 18:20:51 -08001903 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1904 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Romain Guyf8e6a802009-12-07 17:48:02 -08001905 showPreviews(v);
1906 }
1907 return true;
1908 case R.id.all_apps_button:
Michael Jurkac0e8fca2010-10-06 16:41:29 -07001909 if (mState != State.ALL_APPS) {
Romain Guyf8e6a802009-12-07 17:48:02 -08001910 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1911 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
1912 showPreviews(v);
Joe Onorato0d44e942009-11-16 18:20:51 -08001913 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08001914 return true;
1915 }
1916
Joe Onorato9c1289c2009-08-17 11:03:03 -04001917 if (isWorkspaceLocked()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001918 return false;
1919 }
1920
1921 if (!(v instanceof CellLayout)) {
1922 v = (View) v.getParent();
1923 }
1924
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001925
Michael Jurka0280c3b2010-09-17 15:00:07 -07001926 resetAddInfo();
1927 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001928 // This happens when long clicking an item with the dpad/trackball
Michael Jurka0280c3b2010-09-17 15:00:07 -07001929 if (longClickCellInfo == null || !longClickCellInfo.valid) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001930 return true;
1931 }
1932
Michael Jurka0280c3b2010-09-17 15:00:07 -07001933 final View itemUnderLongClick = longClickCellInfo.cell;
1934
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001935 if (mWorkspace.allowLongPress()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001936 if (itemUnderLongClick == null) {
1937 // User long pressed on empty space
1938 mWorkspace.setAllowLongPress(false);
1939 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1940 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Michael Jurka56170562010-10-05 14:14:56 -07001941 if (!LauncherApplication.isScreenXLarge()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001942 showAddDialog(longClickCellInfo.cellX, longClickCellInfo.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001943 }
1944 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001945 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001946 // User long pressed on an item
Joe Onorato0d44e942009-11-16 18:20:51 -08001947 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1948 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001949 mAddIntersectCellX = longClickCellInfo.cellX;
1950 mAddIntersectCellY = longClickCellInfo.cellY;
1951 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001952 }
1953 }
1954 }
1955 return true;
1956 }
1957
Romain Guye6b8e2f2009-11-10 11:56:55 -08001958 @SuppressWarnings({"unchecked"})
Romain Guy9d31e9f2009-11-11 18:54:28 -08001959 private void dismissPreview(final View v) {
1960 final PopupWindow window = (PopupWindow) v.getTag();
Romain Guy1fbc1c82009-11-09 20:43:08 -08001961 if (window != null) {
Romain Guy9d31e9f2009-11-11 18:54:28 -08001962 window.setOnDismissListener(new PopupWindow.OnDismissListener() {
1963 public void onDismiss() {
1964 ViewGroup group = (ViewGroup) v.getTag(R.id.workspace);
1965 int count = group.getChildCount();
1966 for (int i = 0; i < count; i++) {
1967 ((ImageView) group.getChildAt(i)).setImageDrawable(null);
1968 }
Romain Guy9d31e9f2009-11-11 18:54:28 -08001969 ArrayList<Bitmap> bitmaps = (ArrayList<Bitmap>) v.getTag(R.id.icon);
1970 for (Bitmap bitmap : bitmaps) bitmap.recycle();
1971
1972 v.setTag(R.id.workspace, null);
1973 v.setTag(R.id.icon, null);
1974 window.setOnDismissListener(null);
1975 }
1976 });
Romain Guy1fbc1c82009-11-09 20:43:08 -08001977 window.dismiss();
Romain Guy1fbc1c82009-11-09 20:43:08 -08001978 }
1979 v.setTag(null);
1980 }
1981
Romain Guyf8e6a802009-12-07 17:48:02 -08001982 private void showPreviews(View anchor) {
Romain Guy9d31e9f2009-11-11 18:54:28 -08001983 showPreviews(anchor, 0, mWorkspace.getChildCount());
Romain Guy1fbc1c82009-11-09 20:43:08 -08001984 }
1985
Romain Guya6abce82009-11-10 02:54:41 -08001986 private void showPreviews(final View anchor, int start, int end) {
Romain Guyf8e6a802009-12-07 17:48:02 -08001987 final Resources resources = getResources();
1988 final Workspace workspace = mWorkspace;
Romain Guy1fbc1c82009-11-09 20:43:08 -08001989
Romain Guya6abce82009-11-10 02:54:41 -08001990 CellLayout cell = ((CellLayout) workspace.getChildAt(start));
Winson Chungaafa03c2010-06-11 17:34:16 -07001991
Romain Guy9d31e9f2009-11-11 18:54:28 -08001992 float max = workspace.getChildCount();
Winson Chungaafa03c2010-06-11 17:34:16 -07001993
Romain Guyf8e6a802009-12-07 17:48:02 -08001994 final Rect r = new Rect();
Romain Guy9d31e9f2009-11-11 18:54:28 -08001995 resources.getDrawable(R.drawable.preview_background).getPadding(r);
Romain Guye6b8e2f2009-11-10 11:56:55 -08001996 int extraW = (int) ((r.left + r.right) * max);
1997 int extraH = r.top + r.bottom;
Romain Guya6abce82009-11-10 02:54:41 -08001998
1999 int aW = cell.getWidth() - extraW;
2000 float w = aW / max;
2001
2002 int width = cell.getWidth();
2003 int height = cell.getHeight();
2004 int x = cell.getLeftPadding();
2005 int y = cell.getTopPadding();
2006 width -= (x + cell.getRightPadding());
2007 height -= (y + cell.getBottomPadding());
2008
2009 float scale = w / width;
2010
2011 int count = end - start;
2012
2013 final float sWidth = width * scale;
2014 float sHeight = height * scale;
2015
Romain Guye6b8e2f2009-11-10 11:56:55 -08002016 LinearLayout preview = new LinearLayout(this);
Romain Guya6abce82009-11-10 02:54:41 -08002017
Romain Guye6b8e2f2009-11-10 11:56:55 -08002018 PreviewTouchHandler handler = new PreviewTouchHandler(anchor);
2019 ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>(count);
Romain Guya6abce82009-11-10 02:54:41 -08002020
2021 for (int i = start; i < end; i++) {
Romain Guye6b8e2f2009-11-10 11:56:55 -08002022 ImageView image = new ImageView(this);
Romain Guya6abce82009-11-10 02:54:41 -08002023 cell = (CellLayout) workspace.getChildAt(i);
2024
Romain Guyf8e6a802009-12-07 17:48:02 -08002025 final Bitmap bitmap = Bitmap.createBitmap((int) sWidth, (int) sHeight,
Romain Guye6b8e2f2009-11-10 11:56:55 -08002026 Bitmap.Config.ARGB_8888);
Romain Guyf8e6a802009-12-07 17:48:02 -08002027
2028 final Canvas c = new Canvas(bitmap);
Romain Guya6abce82009-11-10 02:54:41 -08002029 c.scale(scale, scale);
2030 c.translate(-cell.getLeftPadding(), -cell.getTopPadding());
Patrick Dubroy1262e362010-10-06 15:49:50 -07002031 cell.drawChildren(c);
Romain Guya6abce82009-11-10 02:54:41 -08002032
Romain Guy9d31e9f2009-11-11 18:54:28 -08002033 image.setBackgroundDrawable(resources.getDrawable(R.drawable.preview_background));
Romain Guye6b8e2f2009-11-10 11:56:55 -08002034 image.setImageBitmap(bitmap);
2035 image.setTag(i);
2036 image.setOnClickListener(handler);
Romain Guy9d31e9f2009-11-11 18:54:28 -08002037 image.setOnFocusChangeListener(handler);
2038 image.setFocusable(true);
Michael Jurka0142d492010-08-25 17:46:15 -07002039 if (i == mWorkspace.getCurrentPage()) image.requestFocus();
Romain Guye6b8e2f2009-11-10 11:56:55 -08002040
2041 preview.addView(image,
Romain Guy9d31e9f2009-11-11 18:54:28 -08002042 LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
2043
Winson Chungaafa03c2010-06-11 17:34:16 -07002044 bitmaps.add(bitmap);
Romain Guya6abce82009-11-10 02:54:41 -08002045 }
Romain Guyf8e6a802009-12-07 17:48:02 -08002046
2047 final PopupWindow p = new PopupWindow(this);
Romain Guye6b8e2f2009-11-10 11:56:55 -08002048 p.setContentView(preview);
2049 p.setWidth((int) (sWidth * count + extraW));
2050 p.setHeight((int) (sHeight + extraH));
2051 p.setAnimationStyle(R.style.AnimationPreview);
2052 p.setOutsideTouchable(true);
Romain Guy9d31e9f2009-11-11 18:54:28 -08002053 p.setFocusable(true);
Romain Guyff0c2e22009-11-10 12:09:59 -08002054 p.setBackgroundDrawable(new ColorDrawable(0));
Romain Guy9d31e9f2009-11-11 18:54:28 -08002055 p.showAsDropDown(anchor, 0, 0);
Romain Guya6abce82009-11-10 02:54:41 -08002056
Romain Guye6b8e2f2009-11-10 11:56:55 -08002057 p.setOnDismissListener(new PopupWindow.OnDismissListener() {
2058 public void onDismiss() {
2059 dismissPreview(anchor);
2060 }
2061 });
Romain Guy1fbc1c82009-11-09 20:43:08 -08002062
2063 anchor.setTag(p);
2064 anchor.setTag(R.id.workspace, preview);
Winson Chungaafa03c2010-06-11 17:34:16 -07002065 anchor.setTag(R.id.icon, bitmaps);
Romain Guy1fbc1c82009-11-09 20:43:08 -08002066 }
2067
Romain Guy9d31e9f2009-11-11 18:54:28 -08002068 class PreviewTouchHandler implements View.OnClickListener, Runnable, View.OnFocusChangeListener {
Romain Guya6abce82009-11-10 02:54:41 -08002069 private final View mAnchor;
Romain Guya6abce82009-11-10 02:54:41 -08002070
Romain Guye6b8e2f2009-11-10 11:56:55 -08002071 public PreviewTouchHandler(View anchor) {
Romain Guya6abce82009-11-10 02:54:41 -08002072 mAnchor = anchor;
Romain Guya6abce82009-11-10 02:54:41 -08002073 }
2074
2075 public void onClick(View v) {
Michael Jurka0142d492010-08-25 17:46:15 -07002076 mWorkspace.snapToPage((Integer) v.getTag());
Romain Guy9d31e9f2009-11-11 18:54:28 -08002077 v.post(this);
2078 }
2079
2080 public void run() {
Winson Chungaafa03c2010-06-11 17:34:16 -07002081 dismissPreview(mAnchor);
Romain Guy9d31e9f2009-11-11 18:54:28 -08002082 }
2083
2084 public void onFocusChange(View v, boolean hasFocus) {
2085 if (hasFocus) {
Michael Jurka0142d492010-08-25 17:46:15 -07002086 mWorkspace.snapToPage((Integer) v.getTag());
Romain Guy9d31e9f2009-11-11 18:54:28 -08002087 }
Romain Guya6abce82009-11-10 02:54:41 -08002088 }
2089 }
2090
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002091 Workspace getWorkspace() {
2092 return mWorkspace;
2093 }
2094
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002095 @Override
2096 protected Dialog onCreateDialog(int id) {
2097 switch (id) {
2098 case DIALOG_CREATE_SHORTCUT:
2099 return new CreateShortcut().createDialog();
2100 case DIALOG_RENAME_FOLDER:
2101 return new RenameFolder().createDialog();
2102 }
2103
2104 return super.onCreateDialog(id);
2105 }
2106
2107 @Override
2108 protected void onPrepareDialog(int id, Dialog dialog) {
2109 switch (id) {
2110 case DIALOG_CREATE_SHORTCUT:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002111 break;
2112 case DIALOG_RENAME_FOLDER:
Romain Guy7b4ef332009-07-14 13:58:08 -07002113 if (mFolderInfo != null) {
2114 EditText input = (EditText) dialog.findViewById(R.id.folder_name);
2115 final CharSequence text = mFolderInfo.title;
2116 input.setText(text);
2117 input.setSelection(0, text.length());
2118 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002119 break;
2120 }
2121 }
2122
2123 void showRenameDialog(FolderInfo info) {
2124 mFolderInfo = info;
2125 mWaitingForResult = true;
2126 showDialog(DIALOG_RENAME_FOLDER);
2127 }
2128
Michael Jurka0280c3b2010-09-17 15:00:07 -07002129 private void showAddDialog(int intersectX, int intersectY) {
2130 resetAddInfo();
2131 mAddIntersectCellX = intersectX;
2132 mAddIntersectCellY = intersectY;
2133 mAddScreen = mWorkspace.getCurrentPage();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002134 mWaitingForResult = true;
2135 showDialog(DIALOG_CREATE_SHORTCUT);
2136 }
2137
Joe Onoratodeb98af2010-02-19 14:59:39 -08002138 private void pickShortcut() {
Michael Jurka0e260592010-06-30 17:07:39 -07002139 // Insert extra item to handle picking application
Romain Guy73b979d2009-06-09 12:57:21 -07002140 Bundle bundle = new Bundle();
2141
2142 ArrayList<String> shortcutNames = new ArrayList<String>();
2143 shortcutNames.add(getString(R.string.group_applications));
2144 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
2145
2146 ArrayList<ShortcutIconResource> shortcutIcons = new ArrayList<ShortcutIconResource>();
2147 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
2148 R.drawable.ic_launcher_application));
2149 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
2150
2151 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2152 pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_CREATE_SHORTCUT));
Joe Onoratodeb98af2010-02-19 14:59:39 -08002153 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_shortcut));
Romain Guy73b979d2009-06-09 12:57:21 -07002154 pickIntent.putExtras(bundle);
2155
Joe Onoratodeb98af2010-02-19 14:59:39 -08002156 startActivityForResult(pickIntent, REQUEST_PICK_SHORTCUT);
Romain Guy73b979d2009-06-09 12:57:21 -07002157 }
2158
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002159 private class RenameFolder {
2160 private EditText mInput;
2161
2162 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002163 final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null);
2164 mInput = (EditText) layout.findViewById(R.id.folder_name);
2165
2166 AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
2167 builder.setIcon(0);
2168 builder.setTitle(getString(R.string.rename_folder_title));
2169 builder.setCancelable(true);
2170 builder.setOnCancelListener(new Dialog.OnCancelListener() {
2171 public void onCancel(DialogInterface dialog) {
2172 cleanup();
2173 }
2174 });
2175 builder.setNegativeButton(getString(R.string.cancel_action),
2176 new Dialog.OnClickListener() {
2177 public void onClick(DialogInterface dialog, int which) {
2178 cleanup();
2179 }
2180 }
2181 );
2182 builder.setPositiveButton(getString(R.string.rename_action),
2183 new Dialog.OnClickListener() {
2184 public void onClick(DialogInterface dialog, int which) {
2185 changeFolderName();
2186 }
2187 }
2188 );
2189 builder.setView(layout);
Romain Guy7b4ef332009-07-14 13:58:08 -07002190
2191 final AlertDialog dialog = builder.create();
2192 dialog.setOnShowListener(new DialogInterface.OnShowListener() {
2193 public void onShow(DialogInterface dialog) {
Joe Onorato7018d8e2010-04-13 20:25:47 -07002194 mWaitingForResult = true;
Joe Onoratod753b422009-11-08 13:31:11 -05002195 mInput.requestFocus();
2196 InputMethodManager inputManager = (InputMethodManager)
2197 getSystemService(Context.INPUT_METHOD_SERVICE);
2198 inputManager.showSoftInput(mInput, 0);
Romain Guy7b4ef332009-07-14 13:58:08 -07002199 }
2200 });
2201
2202 return dialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002203 }
2204
2205 private void changeFolderName() {
2206 final String name = mInput.getText().toString();
2207 if (!TextUtils.isEmpty(name)) {
2208 // Make sure we have the right folder info
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002209 mFolderInfo = sFolders.get(mFolderInfo.id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002210 mFolderInfo.title = name;
2211 LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo);
2212
Joe Onorato9c1289c2009-08-17 11:03:03 -04002213 if (mWorkspaceLoading) {
Joe Onorato7c312c12009-08-13 21:36:53 -07002214 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002215 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002216 } else {
2217 final FolderIcon folderIcon = (FolderIcon)
2218 mWorkspace.getViewForTag(mFolderInfo);
2219 if (folderIcon != null) {
2220 folderIcon.setText(name);
2221 getWorkspace().requestLayout();
2222 } else {
Joe Onorato7c312c12009-08-13 21:36:53 -07002223 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002224 mWorkspaceLoading = true;
2225 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002226 }
2227 }
2228 }
2229 cleanup();
2230 }
2231
2232 private void cleanup() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002233 dismissDialog(DIALOG_RENAME_FOLDER);
2234 mWaitingForResult = false;
2235 mFolderInfo = null;
2236 }
2237 }
2238
Daniel Sandler843e8602010-06-07 14:59:01 -04002239 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
2240 public boolean isAllAppsVisible() {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002241 return mState == State.ALL_APPS;
Joe Onoratofb0ca672009-09-14 17:55:46 -04002242 }
2243
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002244 // AllAppsView.Watcher
2245 public void zoomed(float zoom) {
Michael Jurka213d9632010-07-28 11:29:25 -07002246 // In XLarge view, we zoom down the workspace below all apps so it's still visible
2247 if (zoom == 1.0f && !LauncherApplication.isScreenXLarge()) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002248 mWorkspace.setVisibility(View.GONE);
2249 }
2250 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002251
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002252 private void showToolbarButton(View button) {
2253 button.setAlpha(1.0f);
2254 button.setVisibility(View.VISIBLE);
2255 button.setFocusable(true);
2256 button.setClickable(true);
2257 }
2258
2259 private void hideToolbarButton(View button) {
2260 button.setAlpha(0.0f);
2261 // We can't set it to GONE, otherwise the RelativeLayout gets screwed up
2262 button.setVisibility(View.INVISIBLE);
2263 button.setFocusable(false);
2264 button.setClickable(false);
2265 }
2266
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002267 /**
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002268 * Helper function for showing or hiding a toolbar button, possibly animated.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002269 *
2270 * @param show If true, create an animation to the show the item. Otherwise, hide it.
2271 * @param view The toolbar button to be animated
Chet Haaseb1254a62010-09-07 13:35:00 -07002272 * @param seq A AnimatorSet that will be used to animate the transition. If null, the
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002273 * transition will not be animated.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002274 */
Chet Haaseb1254a62010-09-07 13:35:00 -07002275 private void hideOrShowToolbarButton(boolean show, final View view, AnimatorSet seq) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002276 final boolean showing = show;
2277 final boolean hiding = !show;
2278
2279 final int duration = show ?
2280 getResources().getInteger(R.integer.config_toolbarButtonFadeInTime) :
2281 getResources().getInteger(R.integer.config_toolbarButtonFadeOutTime);
2282
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002283 if (seq != null) {
Chet Haaseb1254a62010-09-07 13:35:00 -07002284 Animator anim = new ObjectAnimator<Float>(duration, view, "alpha", show ? 1.0f : 0.0f);
2285 anim.addListener(new AnimatorListenerAdapter() {
2286 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002287 if (showing) showToolbarButton(view);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002288 }
Chet Haaseb1254a62010-09-07 13:35:00 -07002289 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002290 if (hiding) hideToolbarButton(view);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002291 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002292 });
2293 seq.play(anim);
2294 } else {
2295 if (showing) {
2296 showToolbarButton(view);
2297 } else {
2298 hideToolbarButton(view);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002299 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002300 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002301 }
2302
2303 /**
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002304 * Show/hide the appropriate toolbar buttons for newState.
2305 * If showSeq or hideSeq is null, the transition will be done immediately (not animated).
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002306 *
2307 * @param newState The state that is being switched to
Chet Haaseb1254a62010-09-07 13:35:00 -07002308 * @param showSeq AnimatorSet in which to put "show" animations, or null.
2309 * @param hideSeq AnimatorSet in which to put "hide" animations, or null.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002310 */
Chet Haaseb1254a62010-09-07 13:35:00 -07002311 private void hideAndShowToolbarButtons(State newState, AnimatorSet showSeq, AnimatorSet hideSeq) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002312 final View searchButton = findViewById(R.id.search_button);
2313 final View allAppsButton = findViewById(R.id.all_apps_button);
2314 final View marketButton = findViewById(R.id.market_button);
2315 final View configureButton = findViewById(R.id.configure_button);
2316
2317 switch (newState) {
2318 case WORKSPACE:
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002319 hideOrShowToolbarButton(true, searchButton, showSeq);
2320 hideOrShowToolbarButton(true, allAppsButton, showSeq);
2321 hideOrShowToolbarButton(true, configureButton, showSeq);
2322 hideOrShowToolbarButton(false, marketButton, hideSeq);
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002323 mDeleteZone.setHandle(allAppsButton);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002324 break;
2325 case ALL_APPS:
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002326 hideOrShowToolbarButton(true, configureButton, showSeq);
2327 hideOrShowToolbarButton(true, marketButton, showSeq);
2328 hideOrShowToolbarButton(false, searchButton, hideSeq);
2329 hideOrShowToolbarButton(false, allAppsButton, hideSeq);
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002330 mDeleteZone.setHandle(marketButton);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002331 break;
2332 case CUSTOMIZE:
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002333 hideOrShowToolbarButton(true, allAppsButton, showSeq);
2334 hideOrShowToolbarButton(false, searchButton, hideSeq);
2335 hideOrShowToolbarButton(false, marketButton, hideSeq);
2336 hideOrShowToolbarButton(false, configureButton, hideSeq);
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002337 mDeleteZone.setHandle(allAppsButton);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002338 break;
2339 }
2340 }
2341
2342 /**
2343 * Helper method for the cameraZoomIn/cameraZoomOut animations
2344 * @param view The view being animated
2345 * @param state The state that we are moving in or out of -- either ALL_APPS or CUSTOMIZE
2346 * @param scaleFactor The scale factor used for the zoom
2347 */
2348 private void setPivotsForZoom(View view, State state, float scaleFactor) {
2349 final int height = view.getHeight();
2350 view.setPivotX(view.getWidth() / 2.0f);
2351 // Set pivotY so that at the starting zoom factor, the view is off-screen by a small margin
2352 // Assumes that the view is normally anchored to either the top or bottom of the screen
2353 final int margin = getResources().getInteger(R.integer.config_allAppsVerticalOffset);
2354 if (state == State.ALL_APPS) {
2355 view.setPivotY(height + ((view.getTop() + height) / scaleFactor) + margin);
2356 } else {
2357 view.setPivotY(0.0f - (view.getTop() / scaleFactor) - margin);
2358 }
2359 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002360
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002361 /**
2362 * Zoom the camera out from the workspace to reveal 'toView'.
2363 * Assumes that the view to show is anchored at either the very top or very bottom
2364 * of the screen.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002365 * @param toState The state to zoom out to. Must be ALL_APPS or CUSTOMIZE.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002366 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002367 private void cameraZoomOut(State toState, boolean animated) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002368 final Resources res = getResources();
2369 final int duration = res.getInteger(R.integer.config_allAppsZoomInTime);
2370 final float scale = (float) res.getInteger(R.integer.config_allAppsZoomScaleFactor);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002371 final boolean toAllApps = (toState == State.ALL_APPS);
2372 final View toView = toAllApps ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
Patrick Dubroy558654c2010-07-23 16:48:11 -07002373
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002374 setPivotsForZoom(toView, toState, scale);
2375
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002376 if (toState == State.ALL_APPS) {
2377 mWorkspace.shrinkToBottom(animated);
2378 } else {
2379 mWorkspace.shrinkToTop(animated);
2380 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002381
2382 if (animated) {
Chet Haaseb1254a62010-09-07 13:35:00 -07002383 ValueAnimator scaleAnim = new ObjectAnimator(duration, toView,
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002384 new PropertyValuesHolder<Float>("scaleX", scale, 1.0f),
2385 new PropertyValuesHolder<Float>("scaleY", scale, 1.0f));
2386 scaleAnim.setInterpolator(new DecelerateInterpolator());
Chet Haaseb1254a62010-09-07 13:35:00 -07002387 scaleAnim.addListener(new AnimatorListenerAdapter() {
2388 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002389 // Prepare the position
2390 toView.setTranslationX(0.0f);
2391 toView.setTranslationY(0.0f);
2392 toView.setVisibility(View.VISIBLE);
2393 }
2394 });
2395
Chet Haaseb1254a62010-09-07 13:35:00 -07002396 AnimatorSet toolbarHideAnim = new AnimatorSet();
2397 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002398 hideAndShowToolbarButtons(toState, toolbarShowAnim, toolbarHideAnim);
2399
2400 // toView should appear right at the end of the workspace shrink animation
2401 final int startDelay = res.getInteger(R.integer.config_workspaceShrinkTime) - duration;
2402
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002403 if (mStateAnimation != null) mStateAnimation.cancel();
2404 mStateAnimation = new AnimatorSet();
2405 mStateAnimation.playTogether(scaleAnim, toolbarHideAnim);
2406 mStateAnimation.play(scaleAnim).after(startDelay);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002407
2408 // Show the new toolbar buttons just as the main animation is ending
2409 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002410 mStateAnimation.play(toolbarShowAnim).after(duration + startDelay - fadeInTime);
2411 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002412 } else {
2413 toView.setTranslationX(0.0f);
2414 toView.setTranslationY(0.0f);
2415 toView.setScaleX(1.0f);
2416 toView.setScaleY(1.0f);
2417 toView.setVisibility(View.VISIBLE);
2418 hideAndShowToolbarButtons(toState, null, null);
2419 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002420 }
2421
2422 /**
2423 * Zoom the camera back into the workspace, hiding 'fromView'.
2424 * This is the opposite of cameraZoomOut.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002425 * @param fromState The current state (must be ALL_APPS or CUSTOMIZE).
2426 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002427 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002428 private void cameraZoomIn(State fromState, boolean animated) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002429 Resources res = getResources();
2430 int duration = res.getInteger(R.integer.config_allAppsZoomOutTime);
2431 float scaleFactor = (float) res.getInteger(R.integer.config_allAppsZoomScaleFactor);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002432 final View fromView =
2433 (fromState == State.ALL_APPS) ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
2434
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002435 mCustomizePagedView.endChoiceMode();
2436 mAllAppsPagedView.endChoiceMode();
2437
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002438 setPivotsForZoom(fromView, fromState, scaleFactor);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002439
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002440 mWorkspace.unshrink(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002441
2442 if (animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002443 if (mStateAnimation != null) mStateAnimation.cancel();
2444 mStateAnimation = new AnimatorSet();
Chet Haaseb1254a62010-09-07 13:35:00 -07002445 ValueAnimator scaleAnim = new ObjectAnimator(duration, fromView,
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002446 new PropertyValuesHolder<Float>("scaleX", scaleFactor),
2447 new PropertyValuesHolder<Float>("scaleY", scaleFactor));
2448 scaleAnim.setInterpolator(new AccelerateInterpolator());
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002449 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Chet Haaseb1254a62010-09-07 13:35:00 -07002450 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002451 fromView.setVisibility(View.GONE);
2452 fromView.setScaleX(1.0f);
2453 fromView.setScaleY(1.0f);
2454 }
2455 });
2456
Chet Haaseb1254a62010-09-07 13:35:00 -07002457 AnimatorSet toolbarHideAnim = new AnimatorSet();
2458 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002459 hideAndShowToolbarButtons(State.WORKSPACE, toolbarShowAnim, toolbarHideAnim);
2460
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002461 mStateAnimation.playTogether(scaleAnim, toolbarHideAnim);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002462
2463 // Show the new toolbar buttons at the very end of the whole animation
2464 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
2465 final int unshrinkTime = res.getInteger(R.integer.config_workspaceUnshrinkTime);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002466 mStateAnimation.play(toolbarShowAnim).after(unshrinkTime - fadeInTime);
2467 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002468 } else {
2469 fromView.setVisibility(View.GONE);
2470 hideAndShowToolbarButtons(State.WORKSPACE, null, null);
2471 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002472 }
2473
2474 /**
2475 * Pan the camera in the vertical plane between 'fromView' and 'toView'.
2476 * This is the transition used on xlarge screens to go between all apps and
2477 * the home customization drawer.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002478 * @param fromState The view to pan away from. Must be ALL_APPS or CUSTOMIZE.
2479 * @param toState The view to pan into the frame. Must be ALL_APPS or CUSTOMIZE.
2480 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002481 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002482 private void cameraPan(State fromState, State toState, boolean animated) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002483 final Resources res = getResources();
2484 final int duration = res.getInteger(R.integer.config_allAppsCameraPanTime);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002485 final int workspaceHeight = mWorkspace.getHeight();
2486
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002487 final boolean fromAllApps = (fromState == State.ALL_APPS);
2488 final View fromView = fromAllApps ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
2489 final View toView = fromAllApps ? mHomeCustomizationDrawer : (View) mAllAppsGrid;
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002490
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002491 final float fromViewStartY = fromAllApps ? 0.0f : fromView.getY();
2492 final float fromViewEndY = fromAllApps ? -fromView.getHeight() * 2 : workspaceHeight * 2;
2493 final float toViewStartY = fromAllApps ? workspaceHeight * 2 : -toView.getHeight() * 2;
2494 final float toViewEndY = fromAllApps ? workspaceHeight - toView.getHeight() : 0.0f;
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002495
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002496 mCustomizePagedView.endChoiceMode();
2497 mAllAppsPagedView.endChoiceMode();
2498
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002499 if (toState == State.ALL_APPS) {
2500 mWorkspace.shrinkToBottom(animated);
2501 } else {
2502 mWorkspace.shrinkToTop(animated);
2503 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002504
2505 if (animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002506 if (mStateAnimation != null) mStateAnimation.cancel();
2507 mStateAnimation = new AnimatorSet();
2508 mStateAnimation.addListener(new AnimatorListenerAdapter() {
Chet Haaseb1254a62010-09-07 13:35:00 -07002509 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002510 toView.setVisibility(View.VISIBLE);
2511 toView.setY(toViewStartY);
2512 }
Chet Haaseb1254a62010-09-07 13:35:00 -07002513 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002514 fromView.setVisibility(View.GONE);
2515 }
2516 });
2517
Chet Haaseb1254a62010-09-07 13:35:00 -07002518 AnimatorSet toolbarHideAnim = new AnimatorSet();
2519 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002520 hideAndShowToolbarButtons(toState, toolbarShowAnim, toolbarHideAnim);
2521
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002522 mStateAnimation.playTogether(
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002523 toolbarHideAnim,
Chet Haaseb1254a62010-09-07 13:35:00 -07002524 new ObjectAnimator(duration, fromView, "y", fromViewStartY, fromViewEndY),
2525 new ObjectAnimator(duration, toView, "y", toViewStartY, toViewEndY));
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002526
2527 // Show the new toolbar buttons just as the main animation is ending
2528 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002529 mStateAnimation.play(toolbarShowAnim).after(duration - fadeInTime);
2530 mStateAnimation.start();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002531 } else {
2532 fromView.setY(fromViewEndY);
2533 fromView.setVisibility(View.GONE);
2534 toView.setY(toViewEndY);
2535 toView.setVisibility(View.VISIBLE);
2536 hideAndShowToolbarButtons(toState, null, null);
2537 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002538 }
2539
2540 void showAllApps(boolean animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002541 if (mState == State.ALL_APPS)
Winson Chung80baf5a2010-08-09 16:03:15 -07002542 return;
2543
Michael Jurka79212d82010-07-30 16:36:20 -07002544 if (LauncherApplication.isScreenXLarge()) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002545 if (mState == State.CUSTOMIZE) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002546 cameraPan(State.CUSTOMIZE, State.ALL_APPS, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002547 } else {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002548 cameraZoomOut(State.ALL_APPS, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002549 }
Patrick Dubroy558654c2010-07-23 16:48:11 -07002550 } else {
2551 mAllAppsGrid.zoom(1.0f, animated);
2552 }
Joe Onorato3a8820b2009-11-10 15:06:42 -08002553
Romain Guyc16fea72010-03-12 17:17:56 -08002554 ((View) mAllAppsGrid).setFocusable(true);
2555 ((View) mAllAppsGrid).requestFocus();
Winson Chungaafa03c2010-06-11 17:34:16 -07002556
Joe Onorato7c312c12009-08-13 21:36:53 -07002557 // TODO: fade these two too
2558 mDeleteZone.setVisibility(View.GONE);
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002559 // Change the state *after* we've called all the transition code
2560 mState = State.ALL_APPS;
2561 }
2562
2563
2564 void showWorkspace(boolean animated) {
2565 showWorkspace(animated, null);
2566 }
2567
2568 void showWorkspace(boolean animated, CellLayout layout) {
2569 if (layout != null && animated) {
2570 mWorkspace.unshrink(layout);
2571 } else {
2572 mWorkspace.unshrink(animated);
2573 }
2574 if (mState == State.ALL_APPS) {
2575 closeAllApps(animated);
2576 } else if (mState == State.CUSTOMIZE) {
2577 hideCustomizationDrawer(animated);
2578 }
2579 // Change the state *after* we've called all the transition code
2580 mState = State.WORKSPACE;
Joe Onorato00acb122009-08-04 16:04:30 -04002581 }
2582
Joe Onoratob2061212009-11-24 16:13:54 -05002583 /**
Joe Onorato7e4ed992009-12-03 13:10:49 -08002584 * Things to test when changing this code.
Joe Onoratob2061212009-11-24 16:13:54 -05002585 * - Home from workspace
2586 * - from center screen
2587 * - from other screens
2588 * - Home from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002589 * - from center screen
2590 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002591 * - Back from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002592 * - from center screen
2593 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002594 * - Launch app from workspace and quit
2595 * - with back
2596 * - with home
2597 * - Launch app from all apps and quit
2598 * - with back
2599 * - with home
Joe Onorato7e4ed992009-12-03 13:10:49 -08002600 * - Go to a screen that's not the default, then all
2601 * apps, and launch and app, and go back
2602 * - with back
2603 * -with home
Joe Onoratob2061212009-11-24 16:13:54 -05002604 * - On workspace, long press power and go back
2605 * - with back
2606 * - with home
2607 * - On all apps, long press power and go back
2608 * - with back
2609 * - with home
2610 * - On workspace, power off
2611 * - On all apps, power off
Joe Onorato7e4ed992009-12-03 13:10:49 -08002612 * - Launch an app and turn off the screen while in that app
2613 * - Go back with home key
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002614 * - Go back with back key TODO: make this not go to workspace
Joe Onorato7e4ed992009-12-03 13:10:49 -08002615 * - From all apps
2616 * - From workspace
Joe Onoratoeffc4a82010-04-15 11:48:13 -07002617 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2618 * - From all apps
2619 * - From the center workspace
2620 * - From another workspace
Joe Onoratob2061212009-11-24 16:13:54 -05002621 */
Joe Onorato7bb17492009-09-24 17:51:01 -07002622 void closeAllApps(boolean animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002623 if (mState == State.ALL_APPS) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002624 mWorkspace.setVisibility(View.VISIBLE);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002625 if (LauncherApplication.isScreenXLarge()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002626 cameraZoomIn(State.ALL_APPS, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002627 } else {
2628 mAllAppsGrid.zoom(0.0f, animated);
2629 }
Daniel Sandler388f6792010-03-02 14:08:08 -05002630 ((View)mAllAppsGrid).setFocusable(false);
Michael Jurka0142d492010-08-25 17:46:15 -07002631 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onoratoe77c08d2009-08-01 00:01:20 -07002632 }
Joe Onorato7404ee42009-07-31 11:54:44 -07002633 }
2634
Joe Onorato7c312c12009-08-13 21:36:53 -07002635 void lockAllApps() {
2636 // TODO
2637 }
2638
2639 void unlockAllApps() {
2640 // TODO
2641 }
2642
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002643 // Show the customization drawer (only exists in x-large configuration)
2644 private void showCustomizationDrawer(boolean animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002645 if (mState == State.ALL_APPS) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002646 cameraPan(State.ALL_APPS, State.CUSTOMIZE, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002647 } else {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002648 cameraZoomOut(State.CUSTOMIZE, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002649 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002650 // Change the state *after* we've called all the transition code
2651 mState = State.CUSTOMIZE;
Patrick Dubroy558654c2010-07-23 16:48:11 -07002652 }
2653
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002654 // Hide the customization drawer (only exists in x-large configuration)
2655 void hideCustomizationDrawer(boolean animated) {
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002656 if (mState == State.CUSTOMIZE) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002657 cameraZoomIn(State.CUSTOMIZE, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002658 }
2659 }
2660
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002661 void onWorkspaceClick(CellLayout layout) {
2662 Object itemInfo = mAllAppsPagedView.getChosenItem();
2663 if (itemInfo == null) {
2664 itemInfo = mCustomizePagedView.getChosenItem();
Michael Jurka213d9632010-07-28 11:29:25 -07002665 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002666
2667 if (itemInfo == null) {
2668 // No items are chosen in All Apps or Customize, so just zoom into the workspace
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002669 showWorkspace(true, layout);
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002670 } else {
2671 // Act as if the chosen item was dropped on the given CellLayout
2672 if (mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
2673 mAllAppsPagedView.endChoiceMode();
2674 mCustomizePagedView.endChoiceMode();
2675 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002676 showOutOfSpaceMessage();
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002677 }
Michael Jurka213d9632010-07-28 11:29:25 -07002678 }
2679 }
2680
Michael Jurka0423dcf2010-10-05 14:56:18 -07002681 private void updateButtonWithIconFromExternalActivity(
2682 int buttonId, ComponentName activityName, int fallbackDrawableId) {
2683 ImageView button = (ImageView) findViewById(buttonId);
2684 Drawable toolbarIcon = null;
2685 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002686 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07002687 // Look for the toolbar icon specified in the activity meta-data
2688 Bundle metaData = packageManager.getActivityInfo(
2689 activityName, PackageManager.GET_META_DATA).metaData;
2690 if (metaData != null) {
2691 int iconResId = metaData.getInt(TOOLBAR_ICON_METADATA_NAME);
2692 if (iconResId != 0) {
2693 Resources res = packageManager.getResourcesForActivity(activityName);
2694 toolbarIcon = res.getDrawable(iconResId);
2695 }
2696 }
2697 } catch (NameNotFoundException e) {
2698 // Do nothing
2699 }
2700 // If we were unable to find the icon via the meta-data, use a generic one
2701 if (toolbarIcon == null) {
2702 button.setImageResource(fallbackDrawableId);
2703 } else {
2704 button.setImageDrawable(toolbarIcon);
2705 }
2706 }
2707
2708 private void updateGlobalSearchIcon() {
2709 if (LauncherApplication.isScreenXLarge()) {
2710 final SearchManager searchManager =
2711 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2712 ComponentName activityName = searchManager.getGlobalSearchActivity();
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002713 if (activityName != null) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07002714 updateButtonWithIconFromExternalActivity(
2715 R.id.search_button, activityName, R.drawable.search_button_generic);
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002716 }
2717 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002718 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002719
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002720 /**
2721 * Sets the app market icon (shown when all apps is visible on x-large screens)
2722 */
2723 private void updateAppMarketIcon() {
Michael Jurka0423dcf2010-10-05 14:56:18 -07002724 if (LauncherApplication.isScreenXLarge()) {
2725 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
2726 // Find the app market activity by resolving an intent.
2727 // (If multiple app markets are installed, it will return the ResolverActivity.)
2728 ComponentName activityName = intent.resolveActivity(getPackageManager());
2729 if (activityName != null) {
2730 mAppMarketIntent = intent;
2731 updateButtonWithIconFromExternalActivity(
2732 R.id.market_button, activityName, R.drawable.app_market_generic);
2733 }
2734 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002735 }
2736
2737 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002738 * Displays the shortcut creation dialog and launches, if necessary, the
2739 * appropriate activity.
2740 */
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002741 private class CreateShortcut implements DialogInterface.OnClickListener,
Romain Guy7b4ef332009-07-14 13:58:08 -07002742 DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
2743 DialogInterface.OnShowListener {
2744
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002745 private AddAdapter mAdapter;
Romain Guy9ffb5432009-03-24 21:04:15 -07002746
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002747 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002748 mAdapter = new AddAdapter(Launcher.this);
Romain Guycbb89e42009-06-08 15:52:54 -07002749
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002750 final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
2751 builder.setTitle(getString(R.string.menu_item_add_item));
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002752 builder.setAdapter(mAdapter, this);
Romain Guycbb89e42009-06-08 15:52:54 -07002753
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002754 builder.setInverseBackgroundForced(true);
2755
2756 AlertDialog dialog = builder.create();
2757 dialog.setOnCancelListener(this);
Romain Guycbb89e42009-06-08 15:52:54 -07002758 dialog.setOnDismissListener(this);
Romain Guy7b4ef332009-07-14 13:58:08 -07002759 dialog.setOnShowListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002760
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002761 return dialog;
2762 }
2763
2764 public void onCancel(DialogInterface dialog) {
2765 mWaitingForResult = false;
2766 cleanup();
2767 }
2768
Romain Guycbb89e42009-06-08 15:52:54 -07002769 public void onDismiss(DialogInterface dialog) {
Romain Guycbb89e42009-06-08 15:52:54 -07002770 }
2771
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002772 private void cleanup() {
Joe Onoratocc19a532009-11-19 14:19:17 -08002773 try {
2774 dismissDialog(DIALOG_CREATE_SHORTCUT);
2775 } catch (Exception e) {
2776 // An exception is thrown if the dialog is not visible, which is fine
2777 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002778 }
2779
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002780 /**
2781 * Handle the action clicked in the "Add to home" dialog.
2782 */
2783 public void onClick(DialogInterface dialog, int which) {
2784 Resources res = getResources();
2785 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002786
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002787 switch (which) {
2788 case AddAdapter.ITEM_SHORTCUT: {
Joe Onoratodeb98af2010-02-19 14:59:39 -08002789 pickShortcut();
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002790 break;
2791 }
Romain Guycbb89e42009-06-08 15:52:54 -07002792
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002793 case AddAdapter.ITEM_APPWIDGET: {
2794 int appWidgetId = Launcher.this.mAppWidgetHost.allocateAppWidgetId();
Romain Guycbb89e42009-06-08 15:52:54 -07002795
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002796 Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
2797 pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002798 // start the pick activity
2799 startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET);
2800 break;
2801 }
Romain Guycbb89e42009-06-08 15:52:54 -07002802
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002803 case AddAdapter.ITEM_LIVE_FOLDER: {
2804 // Insert extra item to handle inserting folder
2805 Bundle bundle = new Bundle();
Romain Guycbb89e42009-06-08 15:52:54 -07002806
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002807 ArrayList<String> shortcutNames = new ArrayList<String>();
2808 shortcutNames.add(res.getString(R.string.group_folder));
2809 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
Romain Guycbb89e42009-06-08 15:52:54 -07002810
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002811 ArrayList<ShortcutIconResource> shortcutIcons =
2812 new ArrayList<ShortcutIconResource>();
2813 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
2814 R.drawable.ic_launcher_folder));
2815 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
2816
2817 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2818 pickIntent.putExtra(Intent.EXTRA_INTENT,
2819 new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER));
2820 pickIntent.putExtra(Intent.EXTRA_TITLE,
2821 getText(R.string.title_select_live_folder));
2822 pickIntent.putExtras(bundle);
Romain Guycbb89e42009-06-08 15:52:54 -07002823
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002824 startActivityForResult(pickIntent, REQUEST_PICK_LIVE_FOLDER);
2825 break;
2826 }
2827
2828 case AddAdapter.ITEM_WALLPAPER: {
2829 startWallpaper();
2830 break;
2831 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002832 }
2833 }
Romain Guy7b4ef332009-07-14 13:58:08 -07002834
2835 public void onShow(DialogInterface dialog) {
Winson Chungaafa03c2010-06-11 17:34:16 -07002836 mWaitingForResult = true;
Romain Guy7b4ef332009-07-14 13:58:08 -07002837 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002838 }
2839
2840 /**
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002841 * Receives notifications when applications are added/removed.
2842 */
2843 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
2844 @Override
2845 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002846 closeSystemDialogs();
Joe Onoratob2061212009-11-24 16:13:54 -05002847 String reason = intent.getStringExtra("reason");
2848 if (!"homekey".equals(reason)) {
2849 boolean animate = true;
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002850 if (mPaused || "lock".equals(reason)) {
Joe Onoratob2061212009-11-24 16:13:54 -05002851 animate = false;
2852 }
Michael Jurkac0e8fca2010-10-06 16:41:29 -07002853 showWorkspace(animate);
Joe Onoratob2061212009-11-24 16:13:54 -05002854 }
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002855 }
2856 }
2857
2858 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002859 * Receives notifications whenever the appwidgets are reset.
2860 */
2861 private class AppWidgetResetObserver extends ContentObserver {
2862 public AppWidgetResetObserver() {
2863 super(new Handler());
2864 }
2865
2866 @Override
2867 public void onChange(boolean selfChange) {
2868 onAppWidgetReset();
2869 }
2870 }
2871
2872 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002873 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002874 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002875 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07002876 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002877 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07002878 } else {
2879 return SCREEN_COUNT / 2;
2880 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002881 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002882
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002883 void setAllAppsPagedView(PagedView view) {
2884 mAllAppsPagedView = view;
2885 }
2886
Joe Onorato9c1289c2009-08-17 11:03:03 -04002887 /**
2888 * Refreshes the shortcuts shown on the workspace.
2889 *
2890 * Implementation of the method from LauncherModel.Callbacks.
2891 */
2892 public void startBinding() {
2893 final Workspace workspace = mWorkspace;
2894 int count = workspace.getChildCount();
2895 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04002896 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Joe Onorato9c1289c2009-08-17 11:03:03 -04002897 ((ViewGroup) workspace.getChildAt(i)).removeAllViewsInLayout();
2898 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002899
Joe Onorato9c1289c2009-08-17 11:03:03 -04002900 if (DEBUG_USER_INTERFACE) {
2901 android.widget.Button finishButton = new android.widget.Button(this);
2902 finishButton.setText("Finish");
2903 workspace.addInScreen(finishButton, 1, 0, 0, 1, 1);
2904
2905 finishButton.setOnClickListener(new android.widget.Button.OnClickListener() {
2906 public void onClick(View v) {
2907 finish();
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002908 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002909 });
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002910 }
2911 }
2912
2913 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002914 * Bind the items start-end from the list.
2915 *
2916 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002917 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002918 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
2919
2920 final Workspace workspace = mWorkspace;
2921
2922 for (int i=start; i<end; i++) {
2923 final ItemInfo item = shortcuts.get(i);
2924 mDesktopItems.add(item);
2925 switch (item.itemType) {
2926 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
2927 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Joe Onorato0589f0f2010-02-08 13:44:00 -08002928 final View shortcut = createShortcut((ShortcutInfo)item);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002929 workspace.addInScreen(shortcut, item.screen, item.cellX, item.cellY, 1, 1,
2930 false);
2931 break;
2932 case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER:
2933 final FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07002934 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Joe Onorato9c1289c2009-08-17 11:03:03 -04002935 (UserFolderInfo) item);
2936 workspace.addInScreen(newFolder, item.screen, item.cellX, item.cellY, 1, 1,
2937 false);
2938 break;
2939 case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER:
2940 final FolderIcon newLiveFolder = LiveFolderIcon.fromXml(
2941 R.layout.live_folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07002942 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Joe Onorato9c1289c2009-08-17 11:03:03 -04002943 (LiveFolderInfo) item);
2944 workspace.addInScreen(newLiveFolder, item.screen, item.cellX, item.cellY, 1, 1,
2945 false);
2946 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002947 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002948 }
2949
Joe Onorato9c1289c2009-08-17 11:03:03 -04002950 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002951 }
2952
Joe Onorato9c1289c2009-08-17 11:03:03 -04002953 /**
2954 * Implementation of the method from LauncherModel.Callbacks.
2955 */
Joe Onoratoad72e172009-11-06 16:25:04 -05002956 public void bindFolders(HashMap<Long, FolderInfo> folders) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002957 sFolders.clear();
2958 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002959 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002960
2961 /**
2962 * Add the views for a widget to the workspace.
2963 *
2964 * Implementation of the method from LauncherModel.Callbacks.
2965 */
2966 public void bindAppWidget(LauncherAppWidgetInfo item) {
Daniel Sandler843e8602010-06-07 14:59:01 -04002967 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
2968 if (DEBUG_WIDGETS) {
2969 Log.d(TAG, "bindAppWidget: " + item);
2970 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002971 final Workspace workspace = mWorkspace;
2972
2973 final int appWidgetId = item.appWidgetId;
2974 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04002975 if (DEBUG_WIDGETS) {
2976 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
2977 }
2978
Joe Onorato9c1289c2009-08-17 11:03:03 -04002979 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
2980
Joe Onorato9c1289c2009-08-17 11:03:03 -04002981 item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
2982 item.hostView.setTag(item);
2983
2984 workspace.addInScreen(item.hostView, item.screen, item.cellX,
2985 item.cellY, item.spanX, item.spanY, false);
2986
2987 workspace.requestLayout();
2988
2989 mDesktopItems.add(item);
Daniel Sandler843e8602010-06-07 14:59:01 -04002990
2991 if (DEBUG_WIDGETS) {
2992 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
2993 + (SystemClock.uptimeMillis()-start) + "ms");
2994 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002995 }
2996
2997 /**
2998 * Callback saying that there aren't any more items to bind.
2999 *
3000 * Implementation of the method from LauncherModel.Callbacks.
3001 */
3002 public void finishBindingItems() {
3003 if (mSavedState != null) {
3004 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07003005 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003006 }
3007
3008 final long[] userFolders = mSavedState.getLongArray(RUNTIME_STATE_USER_FOLDERS);
3009 if (userFolders != null) {
3010 for (long folderId : userFolders) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003011 final FolderInfo info = sFolders.get(folderId);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003012 if (info != null) {
3013 openFolder(info);
3014 }
3015 }
3016 final Folder openFolder = mWorkspace.getOpenFolder();
3017 if (openFolder != null) {
3018 openFolder.requestFocus();
3019 }
3020 }
3021
Joe Onorato9c1289c2009-08-17 11:03:03 -04003022 mSavedState = null;
3023 }
3024
3025 if (mSavedInstanceState != null) {
3026 super.onRestoreInstanceState(mSavedInstanceState);
3027 mSavedInstanceState = null;
3028 }
3029
Joe Onorato9c1289c2009-08-17 11:03:03 -04003030 mWorkspaceLoading = false;
3031 }
3032
3033 /**
3034 * Add the icons for all apps.
3035 *
3036 * Implementation of the method from LauncherModel.Callbacks.
3037 */
3038 public void bindAllApplications(ArrayList<ApplicationInfo> apps) {
Romain Guy84f296c2009-11-04 15:00:44 -08003039 mAllAppsGrid.setApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003040 if (mCustomizePagedView != null) {
3041 mCustomizePagedView.setApps(apps);
3042 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003043 updateAppMarketIcon();
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003044 updateGlobalSearchIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003045 }
3046
3047 /**
3048 * A package was installed.
3049 *
3050 * Implementation of the method from LauncherModel.Callbacks.
3051 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003052 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003053 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onoratoa8138d52009-10-06 19:25:30 -07003054 mAllAppsGrid.addApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003055 if (mCustomizePagedView != null) {
3056 mCustomizePagedView.addApps(apps);
3057 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003058 updateAppMarketIcon();
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003059 updateGlobalSearchIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003060 }
3061
3062 /**
3063 * A package was updated.
3064 *
3065 * Implementation of the method from LauncherModel.Callbacks.
3066 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003067 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003068 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato64e6be72010-03-05 15:05:52 -05003069 mWorkspace.updateShortcuts(apps);
3070 mAllAppsGrid.updateApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003071 if (mCustomizePagedView != null) {
3072 mCustomizePagedView.updateApps(apps);
3073 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003074 updateAppMarketIcon();
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003075 updateGlobalSearchIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003076 }
3077
3078 /**
3079 * A package was uninstalled.
3080 *
3081 * Implementation of the method from LauncherModel.Callbacks.
3082 */
Joe Onorato36115782010-06-17 13:28:48 -04003083 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003084 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato36115782010-06-17 13:28:48 -04003085 if (permanent) {
3086 mWorkspace.removeItems(apps);
3087 }
Joe Onoratoa8138d52009-10-06 19:25:30 -07003088 mAllAppsGrid.removeApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003089 if (mCustomizePagedView != null) {
3090 mCustomizePagedView.removeApps(apps);
3091 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003092 updateAppMarketIcon();
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003093 updateGlobalSearchIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003094 }
Joe Onoratobe386092009-11-17 17:32:16 -08003095
3096 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003097 * A number of packages were updated.
3098 */
3099 public void bindPackagesUpdated() {
3100 // update the customization drawer contents
Winson Chung5f941722010-09-28 16:36:43 -07003101 if (mCustomizePagedView != null) {
Winson Chungb3347bb2010-08-19 14:51:28 -07003102 mCustomizePagedView.update();
Winson Chung5f941722010-09-28 16:36:43 -07003103 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003104 }
3105
3106 /**
Joe Onoratobe386092009-11-17 17:32:16 -08003107 * Prints out out state for debugging.
3108 */
3109 public void dumpState() {
3110 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08003111 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08003112 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
3113 Log.d(TAG, "mRestoring=" + mRestoring);
3114 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
3115 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
3116 Log.d(TAG, "mDesktopItems.size=" + mDesktopItems.size());
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003117 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08003118 mModel.dumpState();
3119 mAllAppsGrid.dumpState();
3120 Log.d(TAG, "END launcher2 dump state");
3121 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003122}