blob: bdaa43d49382cd6a7783635e88c9d3a411b5facc [file] [log] [blame]
Michael Jurka01f0ed42010-08-20 00:41:17 -07001
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002/*
3 * Copyright (C) 2008 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
Joe Onoratoa5902522009-07-30 13:37:37 -070018package com.android.launcher2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080019
Chet Haaseb1254a62010-09-07 13:35:00 -070020import android.animation.Animator;
21import android.animation.AnimatorListenerAdapter;
22import android.animation.ValueAnimator;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070023import com.android.common.Search;
24import com.android.launcher.R;
25
Chet Haaseb1254a62010-09-07 13:35:00 -070026import android.animation.ObjectAnimator;
Patrick Dubroy07a0de42010-08-26 11:48:35 -070027import android.animation.PropertyValuesHolder;
Chet Haaseb1254a62010-09-07 13:35:00 -070028import android.animation.AnimatorSet;
Michael Jurka946ad472010-07-09 18:05:18 -070029import android.app.Activity;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080030import android.app.AlertDialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080031import android.app.Dialog;
32import android.app.SearchManager;
33import android.app.StatusBarManager;
Dianne Hackborn107f8392009-08-05 21:32:16 -070034import android.app.WallpaperManager;
Michael Jurkaaf442092010-06-10 17:01:57 -070035import android.appwidget.AppWidgetManager;
36import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080037import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080038import android.content.BroadcastReceiver;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040039import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080040import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041import android.content.Context;
42import android.content.DialogInterface;
43import android.content.Intent;
Winson Chung80baf5a2010-08-09 16:03:15 -070044import android.content.Intent.ShortcutIconResource;
Romain Guy5bbc91b2010-08-18 11:38:46 -070045import android.content.IntentFilter;
Winson Chungaafa03c2010-06-11 17:34:16 -070046import android.content.pm.ActivityInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080047import android.content.pm.PackageManager;
Patrick Dubroyceae05d2010-08-30 10:40:53 -070048import android.content.pm.PackageManager.NameNotFoundException;
Daniel Sandlerab1ebd72010-04-27 16:57:25 -040049import android.content.pm.ResolveInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080050import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070051import android.content.res.Resources;
Daniel Sandlerab1ebd72010-04-27 16:57:25 -040052import android.content.res.TypedArray;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080053import android.database.ContentObserver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080054import android.graphics.Bitmap;
Romain Guya6abce82009-11-10 02:54:41 -080055import android.graphics.Canvas;
Winson Chung80baf5a2010-08-09 16:03:15 -070056import android.graphics.Color;
Michael Jurkaaf442092010-06-10 17:01:57 -070057import android.graphics.Rect;
Romain Guyff0c2e22009-11-10 12:09:59 -080058import android.graphics.drawable.ColorDrawable;
Michael Jurkaaf442092010-06-10 17:01:57 -070059import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040060import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070061import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080062import android.os.Bundle;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080063import android.os.Handler;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080064import android.os.Parcelable;
Daniel Sandler843e8602010-06-07 14:59:01 -040065import android.os.SystemClock;
Joe Onoratobe386092009-11-17 17:32:16 -080066import android.os.SystemProperties;
Karl Rosaen138a0412009-04-23 19:00:21 -070067import android.provider.LiveFolders;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070068import android.provider.Settings;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080069import android.text.Selection;
70import android.text.SpannableStringBuilder;
71import android.text.TextUtils;
72import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070073import android.util.Log;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080074import android.view.Display;
Joe Onorato0d44e942009-11-16 18:20:51 -080075import android.view.HapticFeedbackConstants;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080076import android.view.KeyEvent;
77import android.view.LayoutInflater;
78import android.view.Menu;
79import android.view.MenuItem;
Michael Jurka0e260592010-06-30 17:07:39 -070080import android.view.MotionEvent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080081import android.view.View;
Romain Guy5bbc91b2010-08-18 11:38:46 -070082import android.view.View.OnLongClickListener;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080083import android.view.ViewGroup;
Winson Chungaafa03c2010-06-11 17:34:16 -070084import android.view.WindowManager;
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -070085import android.view.animation.AccelerateInterpolator;
Patrick Dubroy7247f632010-08-04 16:02:59 -070086import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080087import android.view.inputmethod.InputMethodManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080088import android.widget.EditText;
Michael Jurkaaf442092010-06-10 17:01:57 -070089import android.widget.ImageView;
90import android.widget.LinearLayout;
91import android.widget.PopupWindow;
Winson Chung80baf5a2010-08-09 16:03:15 -070092import android.widget.RelativeLayout;
Michael Jurka0e260592010-06-30 17:07:39 -070093import android.widget.TabHost;
Romain Guy5bbc91b2010-08-18 11:38:46 -070094import android.widget.TabHost.OnTabChangeListener;
95import android.widget.TabHost.TabContentFactory;
Winson Chung80baf5a2010-08-09 16:03:15 -070096import android.widget.TabWidget;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080097import android.widget.TextView;
98import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070099
100import java.io.DataInputStream;
101import java.io.DataOutputStream;
102import java.io.FileNotFoundException;
103import java.io.IOException;
104import java.util.ArrayList;
105import java.util.HashMap;
106import java.util.List;
Romain Guyedcce092010-03-04 13:03:17 -0800107
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800108/**
109 * Default launcher application.
110 */
Michael Jurka946ad472010-07-09 18:05:18 -0700111public final class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700112 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
113 AllAppsView.Watcher, View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800114 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700115 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800116
Joe Onorato9c1289c2009-08-17 11:03:03 -0400117 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400118 static final boolean DEBUG_WIDGETS = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400119 static final boolean DEBUG_USER_INTERFACE = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700120
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800121 private static final int MENU_GROUP_ADD = 1;
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800122 private static final int MENU_GROUP_WALLPAPER = MENU_GROUP_ADD + 1;
123
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800124 private static final int MENU_ADD = Menu.FIRST + 1;
Winson Chung7ad01412010-09-27 11:33:03 -0700125 private static final int MENU_MANAGE_APPS = MENU_ADD + 1;
126 private static final int MENU_WALLPAPER_SETTINGS = MENU_MANAGE_APPS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800127 private static final int MENU_SEARCH = MENU_WALLPAPER_SETTINGS + 1;
128 private static final int MENU_NOTIFICATIONS = MENU_SEARCH + 1;
Romain Guy94dabf12009-07-21 10:55:43 -0700129 private static final int MENU_SETTINGS = MENU_NOTIFICATIONS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800130
131 private static final int REQUEST_CREATE_SHORTCUT = 1;
132 private static final int REQUEST_CREATE_LIVE_FOLDER = 4;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700133 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800134 private static final int REQUEST_PICK_APPLICATION = 6;
135 private static final int REQUEST_PICK_SHORTCUT = 7;
136 private static final int REQUEST_PICK_LIVE_FOLDER = 8;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700137 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700138 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800139
140 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
141
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800142 static final int SCREEN_COUNT = 5;
143 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800144
Joe Onorato7c312c12009-08-13 21:36:53 -0700145 static final int DIALOG_CREATE_SHORTCUT = 1;
146 static final int DIALOG_RENAME_FOLDER = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800147
Romain Guy98d01652009-06-30 16:21:04 -0700148 private static final String PREFERENCES = "launcher.preferences";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800149
150 // Type: int
151 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
152 // Type: boolean
153 private static final String RUNTIME_STATE_ALL_APPS_FOLDER = "launcher.all_apps_folder";
154 // Type: long
155 private static final String RUNTIME_STATE_USER_FOLDERS = "launcher.user_folder";
156 // Type: int
157 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
158 // Type: int
159 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cellX";
160 // Type: int
161 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cellY";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800162 // Type: boolean
163 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
164 // Type: long
165 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
166
Winson Chung80baf5a2010-08-09 16:03:15 -0700167 // tags for the customization tabs
168 private static final String WIDGETS_TAG = "widgets";
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700169 private static final String APPLICATIONS_TAG = "applications";
Winson Chung80baf5a2010-08-09 16:03:15 -0700170 private static final String FOLDERS_TAG = "folders";
171 private static final String SHORTCUTS_TAG = "shortcuts";
172 private static final String WALLPAPERS_TAG = "wallpapers";
173
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700174 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
175
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700176 /** The different states that Launcher can be in. */
177 private enum State { WORKSPACE, ALL_APPS, CUSTOMIZE, OVERVIEW };
178
Joe Onorato9c1289c2009-08-17 11:03:03 -0400179 static final int APPWIDGET_HOST_ID = 1024;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800180
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800181 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800182 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800183
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800184 private final BroadcastReceiver mCloseSystemDialogsReceiver
185 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800186 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
187
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800188 private LayoutInflater mInflater;
189
Joe Onorato00acb122009-08-04 16:04:30 -0400190 private DragController mDragController;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800191 private Workspace mWorkspace;
Romain Guycbb89e42009-06-08 15:52:54 -0700192
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700193 private AppWidgetManager mAppWidgetManager;
194 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700195
Michael Jurka0280c3b2010-09-17 15:00:07 -0700196 private int mAddScreen = -1;
197 private int mAddIntersectCellX = -1;
198 private int mAddIntersectCellY = -1;
199 private int[] mAddDropPosition;
200 private int[] mTmpAddItemCellCoordinates = new int[2];
201
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800202 private FolderInfo mFolderInfo;
203
Joe Onorato7c312c12009-08-13 21:36:53 -0700204 private DeleteZone mDeleteZone;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700205 private HandleView mHandleView;
Joe Onorato7c312c12009-08-13 21:36:53 -0700206 private AllAppsView mAllAppsGrid;
Michael Jurka0e260592010-06-30 17:07:39 -0700207 private TabHost mHomeCustomizationDrawer;
Patrick Dubroy2b9ff372010-09-07 17:49:27 -0700208
209 private PagedView mAllAppsPagedView = null;
210 private CustomizePagedView mCustomizePagedView = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800211
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800212 private Bundle mSavedState;
213
214 private SpannableStringBuilder mDefaultKeySsb = null;
215
Joe Onorato9c1289c2009-08-17 11:03:03 -0400216 private boolean mWorkspaceLoading = true;
217
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800218 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800219 private boolean mRestoring;
220 private boolean mWaitingForResult;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800221
222 private Bundle mSavedInstanceState;
223
Joe Onorato9c1289c2009-08-17 11:03:03 -0400224 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800225 private IconCache mIconCache;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400226
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700227 private static LocaleConfiguration sLocaleConfiguration = null;
228
Romain Guy84f296c2009-11-04 15:00:44 -0800229 private ArrayList<ItemInfo> mDesktopItems = new ArrayList<ItemInfo>();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700230 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700231
Romain Guy1fbc1c82009-11-09 20:43:08 -0800232 private ImageView mPreviousView;
233 private ImageView mNextView;
Joe Onorato080d9b62009-11-02 12:01:11 -0500234
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400235 // Hotseats (quick-launch icons next to AllApps)
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400236 private String[] mHotseatConfig = null;
237 private Intent[] mHotseats = null;
238 private Drawable[] mHotseatIcons = null;
239 private CharSequence[] mHotseatLabels = null;
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400240
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700241 private Intent mAppMarketIntent = null;
242
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800243 @Override
244 protected void onCreate(Bundle savedInstanceState) {
245 super.onCreate(savedInstanceState);
Romain Guyb1b69f52009-08-10 15:10:15 -0700246
Winson Chungaafa03c2010-06-11 17:34:16 -0700247 if (LauncherApplication.isInPlaceRotationEnabled()) {
248 // hide the status bar (temporary until we get the status bar design figured out)
249 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
250 this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
251 }
252
Joe Onorato0589f0f2010-02-08 13:44:00 -0800253 LauncherApplication app = ((LauncherApplication)getApplication());
254 mModel = app.setLauncher(this);
255 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400256 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800257 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700258
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700259 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700260 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
261 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700262
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800263 if (PROFILE_STARTUP) {
264 android.os.Debug.startMethodTracing("/sdcard/launcher");
265 }
266
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400267 loadHotseats();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800268 checkForLocaleChange();
269 setWallpaperDimension();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800270 setContentView(R.layout.launcher);
Michael Jurka946ad472010-07-09 18:05:18 -0700271 mHomeCustomizationDrawer = (TabHost) findViewById(com.android.internal.R.id.tabhost);
272 if (mHomeCustomizationDrawer != null) {
273 mHomeCustomizationDrawer.setup();
Winson Chungaafa03c2010-06-11 17:34:16 -0700274
Winson Chung80baf5a2010-08-09 16:03:15 -0700275 // share the same customization workspace across all the tabs
Winson Chunge3193b92010-09-10 11:44:42 -0700276 mCustomizePagedView = (CustomizePagedView) mInflater.inflate(
277 R.layout.customization_drawer, mHomeCustomizationDrawer, false);
Winson Chung80baf5a2010-08-09 16:03:15 -0700278 TabContentFactory contentFactory = new TabContentFactory() {
279 public View createTabContent(String tag) {
280 return mCustomizePagedView;
281 }
282 };
283
Michael Jurka946ad472010-07-09 18:05:18 -0700284 String widgetsLabel = getString(R.string.widgets_tab_label);
Winson Chung80baf5a2010-08-09 16:03:15 -0700285 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(WIDGETS_TAG)
286 .setIndicator(widgetsLabel).setContent(contentFactory));
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700287 String applicationsLabel = getString(R.string.applications_tab_label);
288 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(APPLICATIONS_TAG)
289 .setIndicator(applicationsLabel).setContent(contentFactory));
Michael Jurka946ad472010-07-09 18:05:18 -0700290 String foldersLabel = getString(R.string.folders_tab_label);
Winson Chung80baf5a2010-08-09 16:03:15 -0700291 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(FOLDERS_TAG)
292 .setIndicator(foldersLabel).setContent(contentFactory));
Michael Jurka946ad472010-07-09 18:05:18 -0700293 String wallpapersLabel = getString(R.string.wallpapers_tab_label);
Winson Chung80baf5a2010-08-09 16:03:15 -0700294 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(WALLPAPERS_TAG)
295 .setIndicator(wallpapersLabel).setContent(contentFactory));
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700296 String shortcutsLabel = getString(R.string.shortcuts_tab_label);
297 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(SHORTCUTS_TAG)
298 .setIndicator(shortcutsLabel).setContent(contentFactory));
Winson Chung80baf5a2010-08-09 16:03:15 -0700299
300 // TEMP: just styling the tab widget to be a bit nicer until we get the actual
301 // new assets
302 TabWidget tabWidget = mHomeCustomizationDrawer.getTabWidget();
303 for (int i = 0; i < tabWidget.getChildCount(); ++i) {
304 RelativeLayout tab = (RelativeLayout) tabWidget.getChildTabViewAt(i);
305 TextView text = (TextView) tab.getChildAt(1);
306 text.setTextSize(20.0f);
307 text.setPadding(20, 0, 20, 0);
308 text.setShadowLayer(1.0f, 0.0f, 1.0f, Color.BLACK);
309 tab.setBackgroundDrawable(null);
310 }
311
312 mHomeCustomizationDrawer.setOnTabChangedListener(new OnTabChangeListener() {
313 public void onTabChanged(String tabId) {
314 // animate the changing of the tab content by fading pages in and out
315 final int duration = 150;
316 final float alpha = mCustomizePagedView.getAlpha();
Chet Haaseb1254a62010-09-07 13:35:00 -0700317 ValueAnimator alphaAnim = new ObjectAnimator(duration, mCustomizePagedView,
Winson Chung80baf5a2010-08-09 16:03:15 -0700318 "alpha", alpha, 0.0f);
Chet Haaseb1254a62010-09-07 13:35:00 -0700319 alphaAnim.addListener(new AnimatorListenerAdapter() {
320 public void onAnimationEnd(Animator animation) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700321 String tag = mHomeCustomizationDrawer.getCurrentTabTag();
322 if (tag == WIDGETS_TAG) {
323 mCustomizePagedView.setCustomizationFilter(
324 CustomizePagedView.CustomizationType.WidgetCustomization);
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700325 } else if (tag == APPLICATIONS_TAG) {
326 mCustomizePagedView.setCustomizationFilter(
327 CustomizePagedView.CustomizationType.ApplicationCustomization);
Winson Chung80baf5a2010-08-09 16:03:15 -0700328 } else if (tag == FOLDERS_TAG) {
329 mCustomizePagedView.setCustomizationFilter(
330 CustomizePagedView.CustomizationType.FolderCustomization);
Winson Chung80baf5a2010-08-09 16:03:15 -0700331 } else if (tag == WALLPAPERS_TAG) {
332 mCustomizePagedView.setCustomizationFilter(
333 CustomizePagedView.CustomizationType.WallpaperCustomization);
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700334 } else if (tag == SHORTCUTS_TAG) {
335 mCustomizePagedView.setCustomizationFilter(
336 CustomizePagedView.CustomizationType.ShortcutCustomization);
Winson Chung80baf5a2010-08-09 16:03:15 -0700337 }
338
339 final float alpha = mCustomizePagedView.getAlpha();
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700340 ValueAnimator alphaAnim = new ObjectAnimator(duration,
341 mCustomizePagedView, "alpha", alpha, 1.0f);
Winson Chung80baf5a2010-08-09 16:03:15 -0700342 alphaAnim.start();
343 }
344 });
345 alphaAnim.start();
346 }
347 });
Michael Jurka946ad472010-07-09 18:05:18 -0700348
349 mHomeCustomizationDrawer.setCurrentTab(0);
350 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800351 setupViews();
352
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800353 registerContentObservers();
354
Joe Onorato7c312c12009-08-13 21:36:53 -0700355 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700356
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800357 mSavedState = savedInstanceState;
358 restoreState(mSavedState);
359
360 if (PROFILE_STARTUP) {
361 android.os.Debug.stopMethodTracing();
362 }
363
364 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400365 mModel.startLoader(this, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800366 }
367
368 // For handling default keys
369 mDefaultKeySsb = new SpannableStringBuilder();
370 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800371
372 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
373 registerReceiver(mCloseSystemDialogsReceiver, filter);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800374 }
Romain Guycbb89e42009-06-08 15:52:54 -0700375
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800376 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700377 if (sLocaleConfiguration == null) {
378 new AsyncTask<Void, Void, LocaleConfiguration>() {
379 @Override
380 protected LocaleConfiguration doInBackground(Void... unused) {
381 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
382 readConfiguration(Launcher.this, localeConfiguration);
383 return localeConfiguration;
384 }
385
386 @Override
387 protected void onPostExecute(LocaleConfiguration result) {
388 sLocaleConfiguration = result;
389 checkForLocaleChange(); // recursive, but now with a locale configuration
390 }
391 }.execute();
392 return;
393 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700394
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800395 final Configuration configuration = getResources().getConfiguration();
396
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700397 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800398 final String locale = configuration.locale.toString();
399
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700400 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800401 final int mcc = configuration.mcc;
402
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700403 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800404 final int mnc = configuration.mnc;
405
Romain Guy84f296c2009-11-04 15:00:44 -0800406 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800407
Romain Guy84f296c2009-11-04 15:00:44 -0800408 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700409 sLocaleConfiguration.locale = locale;
410 sLocaleConfiguration.mcc = mcc;
411 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700412
Joe Onorato0589f0f2010-02-08 13:44:00 -0800413 mIconCache.flush();
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400414 loadHotseats();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700415
416 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
417 new Thread("WriteLocaleConfiguration") {
418 public void run() {
419 writeConfiguration(Launcher.this, localeConfiguration);
420 }
421 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700422 }
423 }
424
425 private static class LocaleConfiguration {
426 public String locale;
427 public int mcc = -1;
428 public int mnc = -1;
429 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700430
Romain Guy98d01652009-06-30 16:21:04 -0700431 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
432 DataInputStream in = null;
433 try {
434 in = new DataInputStream(context.openFileInput(PREFERENCES));
435 configuration.locale = in.readUTF();
436 configuration.mcc = in.readInt();
437 configuration.mnc = in.readInt();
438 } catch (FileNotFoundException e) {
439 // Ignore
440 } catch (IOException e) {
441 // Ignore
442 } finally {
443 if (in != null) {
444 try {
445 in.close();
446 } catch (IOException e) {
447 // Ignore
448 }
449 }
450 }
451 }
452
453 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
454 DataOutputStream out = null;
455 try {
456 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
457 out.writeUTF(configuration.locale);
458 out.writeInt(configuration.mcc);
459 out.writeInt(configuration.mnc);
460 out.flush();
461 } catch (FileNotFoundException e) {
462 // Ignore
463 } catch (IOException e) {
464 //noinspection ResultOfMethodCallIgnored
465 context.getFileStreamPath(PREFERENCES).delete();
466 } finally {
467 if (out != null) {
468 try {
469 out.close();
470 } catch (IOException e) {
471 // Ignore
472 }
473 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800474 }
475 }
476
477 static int getScreen() {
478 synchronized (sLock) {
479 return sScreen;
480 }
481 }
482
483 static void setScreen(int screen) {
484 synchronized (sLock) {
485 sScreen = screen;
486 }
487 }
488
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800489 private void setWallpaperDimension() {
Dianne Hackborn107f8392009-08-05 21:32:16 -0700490 WallpaperManager wpm = (WallpaperManager)getSystemService(WALLPAPER_SERVICE);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800491
492 Display display = getWindowManager().getDefaultDisplay();
Romain Guy5bbc91b2010-08-18 11:38:46 -0700493 // TODO: Put back when we decide about scrolling the wallpaper
494 // boolean isPortrait = display.getWidth() < display.getHeight();
495 // final int width = isPortrait ? display.getWidth() : display.getHeight();
496 // final int height = isPortrait ? display.getHeight() : display.getWidth();
497 wpm.suggestDesiredDimensions(Math.max(display.getWidth(), display.getHeight()),
498 Math.max(display.getWidth(), display.getHeight()));
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800499 }
500
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400501 // Note: This doesn't do all the client-id magic that BrowserProvider does
502 // in Browser. (http://b/2425179)
503 private Uri getDefaultBrowserUri() {
504 String url = getString(R.string.default_browser_url);
505 if (url.indexOf("{CID}") != -1) {
506 url = url.replace("{CID}", "android-google");
507 }
508 return Uri.parse(url);
509 }
510
511 // Load the Intent templates from arrays.xml to populate the hotseats. For
512 // each Intent, if it resolves to a single app, use that as the launch
513 // intent & use that app's label as the contentDescription. Otherwise,
514 // retain the ResolveActivity so the user can pick an app.
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400515 private void loadHotseats() {
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400516 if (mHotseatConfig == null) {
517 mHotseatConfig = getResources().getStringArray(R.array.hotseats);
518 if (mHotseatConfig.length > 0) {
519 mHotseats = new Intent[mHotseatConfig.length];
520 mHotseatLabels = new CharSequence[mHotseatConfig.length];
521 mHotseatIcons = new Drawable[mHotseatConfig.length];
522 } else {
523 mHotseats = null;
524 mHotseatIcons = null;
525 mHotseatLabels = null;
526 }
527
528 TypedArray hotseatIconDrawables = getResources().obtainTypedArray(R.array.hotseat_icons);
529 for (int i=0; i<mHotseatConfig.length; i++) {
530 // load icon for this slot; currently unrelated to the actual activity
531 try {
532 mHotseatIcons[i] = hotseatIconDrawables.getDrawable(i);
533 } catch (ArrayIndexOutOfBoundsException ex) {
534 Log.w(TAG, "Missing hotseat_icons array item #" + i);
535 mHotseatIcons[i] = null;
536 }
537 }
538 hotseatIconDrawables.recycle();
539 }
540
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400541 PackageManager pm = getPackageManager();
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400542 for (int i=0; i<mHotseatConfig.length; i++) {
543 Intent intent = null;
544 if (mHotseatConfig[i].equals("*BROWSER*")) {
545 // magic value meaning "launch user's default web browser"
546 // replace it with a generic web request so we can see if there is indeed a default
547 String defaultUri = getString(R.string.default_browser_url);
548 intent = new Intent(
549 Intent.ACTION_VIEW,
550 ((defaultUri != null)
551 ? Uri.parse(defaultUri)
552 : getDefaultBrowserUri())
553 ).addCategory(Intent.CATEGORY_BROWSABLE);
554 // note: if the user launches this without a default set, she
555 // will always be taken to the default URL above; this is
556 // unavoidable as we must specify a valid URL in order for the
Winson Chungaafa03c2010-06-11 17:34:16 -0700557 // chooser to appear, and once the user selects something, that
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400558 // URL is unavoidably sent to the chosen app.
559 } else {
560 try {
561 intent = Intent.parseUri(mHotseatConfig[i], 0);
562 } catch (java.net.URISyntaxException ex) {
563 Log.w(TAG, "Invalid hotseat intent: " + mHotseatConfig[i]);
564 // bogus; leave intent=null
565 }
566 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700567
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400568 if (intent == null) {
569 mHotseats[i] = null;
570 mHotseatLabels[i] = getText(R.string.activity_not_found);
571 continue;
572 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400573
574 if (LOGD) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700575 Log.d(TAG, "loadHotseats: hotseat " + i
576 + " initial intent=["
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400577 + intent.toUri(Intent.URI_INTENT_SCHEME)
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400578 + "]");
579 }
580
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400581 ResolveInfo bestMatch = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
582 List<ResolveInfo> allMatches = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
Winson Chungaafa03c2010-06-11 17:34:16 -0700583 if (LOGD) {
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400584 Log.d(TAG, "Best match for intent: " + bestMatch);
585 Log.d(TAG, "All matches: ");
586 for (ResolveInfo ri : allMatches) {
587 Log.d(TAG, " --> " + ri);
588 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400589 }
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400590 // did this resolve to a single app, or the resolver?
591 if (allMatches.size() == 0 || bestMatch == null) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700592 // can't find any activity to handle this. let's leave the
593 // intent as-is and let Launcher show a toast when it fails
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400594 // to launch.
595 mHotseats[i] = intent;
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400596
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400597 // set accessibility text to "Not installed"
598 mHotseatLabels[i] = getText(R.string.activity_not_found);
599 } else {
600 boolean found = false;
601 for (ResolveInfo ri : allMatches) {
602 if (bestMatch.activityInfo.name.equals(ri.activityInfo.name)
603 && bestMatch.activityInfo.applicationInfo.packageName
604 .equals(ri.activityInfo.applicationInfo.packageName)) {
605 found = true;
606 break;
607 }
608 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700609
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400610 if (!found) {
611 if (LOGD) Log.d(TAG, "Multiple options, no default yet");
612 // the bestMatch is probably the ResolveActivity, meaning the
613 // user has not yet selected a default
614 // so: we'll keep the original intent for now
615 mHotseats[i] = intent;
616
617 // set the accessibility text to "Select shortcut"
618 mHotseatLabels[i] = getText(R.string.title_select_shortcut);
619 } else {
620 // we have an app!
621 // now reconstruct the intent to launch it through the front
622 // door
623 ComponentName com = new ComponentName(
624 bestMatch.activityInfo.applicationInfo.packageName,
625 bestMatch.activityInfo.name);
626 mHotseats[i] = new Intent(Intent.ACTION_MAIN).setComponent(com);
627
628 // load the app label for accessibility
629 mHotseatLabels[i] = bestMatch.activityInfo.loadLabel(pm);
630 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400631 }
632
633 if (LOGD) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700634 Log.d(TAG, "loadHotseats: hotseat " + i
635 + " final intent=["
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400636 + ((mHotseats[i] == null)
637 ? "null"
638 : mHotseats[i].toUri(Intent.URI_INTENT_SCHEME))
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400639 + "] label=[" + mHotseatLabels[i]
640 + "]"
641 );
642 }
643 }
644 }
645
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800646 @Override
647 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Romain Guyaad5ef42009-06-10 02:48:37 -0700648 mWaitingForResult = false;
649
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800650 // The pattern used here is that a user PICKs a specific application,
651 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700652
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800653 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
654 // launch over to the Music app to actually CREATE_SHORTCUT.
Romain Guycbb89e42009-06-08 15:52:54 -0700655
Michael Jurka0280c3b2010-09-17 15:00:07 -0700656 if (resultCode == RESULT_OK && mAddScreen != -1) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800657 switch (requestCode) {
658 case REQUEST_PICK_APPLICATION:
Michael Jurka28750fb2010-09-24 17:43:49 -0700659 completeAddApplication(
660 this, data, mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800661 break;
662 case REQUEST_PICK_SHORTCUT:
Joe Onoratodeb98af2010-02-19 14:59:39 -0800663 processShortcut(data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800664 break;
665 case REQUEST_CREATE_SHORTCUT:
Michael Jurka0280c3b2010-09-17 15:00:07 -0700666 completeAddShortcut(data, mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800667 break;
668 case REQUEST_PICK_LIVE_FOLDER:
669 addLiveFolder(data);
670 break;
671 case REQUEST_CREATE_LIVE_FOLDER:
Michael Jurka0280c3b2010-09-17 15:00:07 -0700672 completeAddLiveFolder(data, mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800673 break;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700674 case REQUEST_PICK_APPWIDGET:
Michael Jurkaaf442092010-06-10 17:01:57 -0700675 addAppWidgetFromPick(data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800676 break;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700677 case REQUEST_CREATE_APPWIDGET:
Michael Jurkaaf442092010-06-10 17:01:57 -0700678 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700679 completeAddAppWidget(appWidgetId, mAddScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800680 break;
Mike Clerona0618e42009-10-22 13:55:21 -0700681 case REQUEST_PICK_WALLPAPER:
682 // We just wanted the activity result here so we can clear mWaitingForResult
683 break;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800684 }
Romain Guy18042c82009-11-06 11:44:55 -0800685 } else if ((requestCode == REQUEST_PICK_APPWIDGET ||
686 requestCode == REQUEST_CREATE_APPWIDGET) && resultCode == RESULT_CANCELED &&
687 data != null) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700688 // Clean up the appWidgetId if we canceled
689 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
690 if (appWidgetId != -1) {
691 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800692 }
693 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800694 }
695
696 @Override
697 protected void onResume() {
698 super.onResume();
699
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800700 mPaused = false;
Joe Onorato7e4ed992009-12-03 13:10:49 -0800701
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800702 if (mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400703 mWorkspaceLoading = true;
704 mModel.startLoader(this, true);
705 mRestoring = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800706 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700707 // When we resume Launcher, a different Activity might be responsible for the app
708 // market intent, so refresh the icon
709 updateAppMarketIcon();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800710 }
711
712 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700713 protected void onPause() {
714 super.onPause();
Michael Jurkaaf442092010-06-10 17:01:57 -0700715 // Some launcher layouts don't have a previous and next view
716 if (mPreviousView != null) {
717 dismissPreview(mPreviousView);
Patrick Dubroyab962b72010-07-26 12:10:10 -0700718 }
719 if (mNextView != null) {
Michael Jurkaaf442092010-06-10 17:01:57 -0700720 dismissPreview(mNextView);
721 }
Joe Onorato24b6fd82009-11-12 13:47:09 -0800722 mDragController.cancelDrag();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700723 }
Romain Guycbb89e42009-06-08 15:52:54 -0700724
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700725 @Override
726 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400727 // Flag the loader to stop early before switching
728 mModel.stopLoader();
Romain Guy13c2e7b2010-03-10 19:45:00 -0800729 mAllAppsGrid.surrender();
Romain Guy13c2e7b2010-03-10 19:45:00 -0800730 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700731 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700732
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800733 // We can't hide the IME if it was forced open. So don't bother
734 /*
735 @Override
736 public void onWindowFocusChanged(boolean hasFocus) {
737 super.onWindowFocusChanged(hasFocus);
738
739 if (hasFocus) {
740 final InputMethodManager inputManager = (InputMethodManager)
741 getSystemService(Context.INPUT_METHOD_SERVICE);
742 WindowManager.LayoutParams lp = getWindow().getAttributes();
743 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
744 android.os.Handler()) {
745 protected void onReceiveResult(int resultCode, Bundle resultData) {
746 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
747 }
748 });
749 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
750 }
751 }
752 */
753
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800754 private boolean acceptFilter() {
755 final InputMethodManager inputManager = (InputMethodManager)
756 getSystemService(Context.INPUT_METHOD_SERVICE);
757 return !inputManager.isFullscreenMode();
758 }
759
760 @Override
761 public boolean onKeyDown(int keyCode, KeyEvent event) {
762 boolean handled = super.onKeyDown(keyCode, event);
763 if (!handled && acceptFilter() && keyCode != KeyEvent.KEYCODE_ENTER) {
764 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
765 keyCode, event);
766 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700767 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700768 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700769 // showSearchDialog()
770 // If there are multiple keystrokes before the search dialog takes focus,
771 // onSearchRequested() will be called for every keystroke,
772 // but it is idempotent, so it's fine.
773 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800774 }
775 }
776
Joe Onorato8a9625e2010-01-28 15:55:35 -0800777 // Eat the long press event so the keyboard doesn't come up.
778 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
779 return true;
780 }
781
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800782 return handled;
783 }
784
Karl Rosaen138a0412009-04-23 19:00:21 -0700785 private String getTypedText() {
786 return mDefaultKeySsb.toString();
787 }
788
789 private void clearTypedText() {
790 mDefaultKeySsb.clear();
791 mDefaultKeySsb.clearSpans();
792 Selection.setSelection(mDefaultKeySsb, 0);
793 }
794
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800795 /**
796 * Restores the previous state, if it exists.
797 *
798 * @param savedState The previous state.
799 */
800 private void restoreState(Bundle savedState) {
801 if (savedState == null) {
802 return;
803 }
804
Joe Onorato3a8820b2009-11-10 15:06:42 -0800805 final boolean allApps = savedState.getBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, false);
806 if (allApps) {
807 showAllApps(false);
808 }
809
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800810 final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
811 if (currentScreen > -1) {
Michael Jurka0142d492010-08-25 17:46:15 -0700812 mWorkspace.setCurrentPage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800813 }
814
815 final int addScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700816
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800817 if (addScreen > -1) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700818 mAddScreen = addScreen;
819 mAddIntersectCellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
820 mAddIntersectCellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800821 mRestoring = true;
822 }
823
824 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
825 if (renameFolder) {
826 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700827 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800828 mRestoring = true;
829 }
830 }
831
832 /**
833 * Finds all the views we need and configure them properly.
834 */
835 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700836 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -0400837
Romain Guyb1b69f52009-08-10 15:10:15 -0700838 DragLayer dragLayer = (DragLayer) findViewById(R.id.drag_layer);
Joe Onorato00acb122009-08-04 16:04:30 -0400839 dragLayer.setDragController(dragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800840
Joe Onorato7c312c12009-08-13 21:36:53 -0700841 mAllAppsGrid = (AllAppsView)dragLayer.findViewById(R.id.all_apps_view);
Joe Onorato6665c0f2009-09-02 15:27:24 -0700842 mAllAppsGrid.setLauncher(this);
Joe Onorato5162ea92009-09-03 09:39:42 -0700843 mAllAppsGrid.setDragController(dragController);
Romain Guyc16fea72010-03-12 17:17:56 -0800844 ((View) mAllAppsGrid).setWillNotDraw(false); // We don't want a hole punched in our window.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700845 // Manage focusability manually since this thing is always visible (in non-xlarge)
Winson Chungaafa03c2010-06-11 17:34:16 -0700846 ((View) mAllAppsGrid).setFocusable(false);
Joe Onorato7c312c12009-08-13 21:36:53 -0700847
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700848 if (LauncherApplication.isScreenXLarge()) {
849 // They need to be INVISIBLE initially so that they will be measured in the layout.
850 // Otherwise the animations are messed up when we show them for the first time.
851 ((View) mAllAppsGrid).setVisibility(View.INVISIBLE);
852 mHomeCustomizationDrawer.setVisibility(View.INVISIBLE);
853 }
854
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800855 mWorkspace = (Workspace) dragLayer.findViewById(R.id.workspace);
856 final Workspace workspace = mWorkspace;
Joe Onoratof0dde092010-02-16 18:25:23 -0500857 workspace.setHapticFeedbackEnabled(false);
Michael Jurka946ad472010-07-09 18:05:18 -0700858
Joe Onorato7c312c12009-08-13 21:36:53 -0700859 DeleteZone deleteZone = (DeleteZone) dragLayer.findViewById(R.id.delete_zone);
860 mDeleteZone = deleteZone;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800861
Michael Jurka2c3af5f2010-08-03 13:53:20 -0700862 View handleView = findViewById(R.id.all_apps_button);
863 if (handleView != null && handleView instanceof HandleView) {
864 // we don't use handle view in xlarge mode
Michael Jurka7ef4f752010-08-03 16:04:26 -0700865 mHandleView = (HandleView)handleView;
Michael Jurka2c3af5f2010-08-03 13:53:20 -0700866 mHandleView.setLauncher(this);
867 mHandleView.setOnClickListener(this);
868 mHandleView.setOnLongClickListener(this);
869 }
Romain Guy1fbc1c82009-11-09 20:43:08 -0800870
Winson Chung80baf5a2010-08-09 16:03:15 -0700871 if (mCustomizePagedView != null) {
872 mCustomizePagedView.setLauncher(this);
873 mCustomizePagedView.setDragController(dragController);
874 mCustomizePagedView.update();
Michael Jurkaaf442092010-06-10 17:01:57 -0700875 } else {
876 ImageView hotseatLeft = (ImageView) findViewById(R.id.hotseat_left);
877 hotseatLeft.setContentDescription(mHotseatLabels[0]);
878 hotseatLeft.setImageDrawable(mHotseatIcons[0]);
879 ImageView hotseatRight = (ImageView) findViewById(R.id.hotseat_right);
880 hotseatRight.setContentDescription(mHotseatLabels[1]);
881 hotseatRight.setImageDrawable(mHotseatIcons[1]);
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400882
Michael Jurkaaf442092010-06-10 17:01:57 -0700883 mPreviousView = (ImageView) dragLayer.findViewById(R.id.previous_screen);
884 mNextView = (ImageView) dragLayer.findViewById(R.id.next_screen);
Romain Guy1fbc1c82009-11-09 20:43:08 -0800885
Michael Jurkaaf442092010-06-10 17:01:57 -0700886 Drawable previous = mPreviousView.getDrawable();
887 Drawable next = mNextView.getDrawable();
888 mWorkspace.setIndicators(previous, next);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800889
Michael Jurkaaf442092010-06-10 17:01:57 -0700890 mPreviousView.setHapticFeedbackEnabled(false);
891 mPreviousView.setOnLongClickListener(this);
892 mNextView.setHapticFeedbackEnabled(false);
893 mNextView.setOnLongClickListener(this);
894 }
Romain Guy1fbc1c82009-11-09 20:43:08 -0800895
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800896 workspace.setOnLongClickListener(this);
Joe Onorato00acb122009-08-04 16:04:30 -0400897 workspace.setDragController(dragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800898 workspace.setLauncher(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800899
900 deleteZone.setLauncher(this);
Joe Onorato00acb122009-08-04 16:04:30 -0400901 deleteZone.setDragController(dragController);
Michael Jurka54f7ac32010-08-02 13:56:46 -0700902 int deleteZoneHandleId;
903 if (LauncherApplication.isScreenXLarge()) {
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700904 deleteZoneHandleId = R.id.all_apps_button;
Michael Jurka54f7ac32010-08-02 13:56:46 -0700905 } else {
906 deleteZoneHandleId = R.id.all_apps_button_cluster;
907 }
Michael Jurkaaf442092010-06-10 17:01:57 -0700908 deleteZone.setHandle(findViewById(deleteZoneHandleId));
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700909 dragController.addDragListener(deleteZone);
910
911 ApplicationInfoDropTarget infoButton = (ApplicationInfoDropTarget)findViewById(R.id.info_button);
912 if (infoButton != null) {
913 infoButton.setLauncher(this);
914 infoButton.setHandle(findViewById(R.id.configure_button));
915 infoButton.setDragColor(getResources().getColor(R.color.app_info_filter));
916 dragController.addDragListener(infoButton);
917 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800918
Joe Onorato00acb122009-08-04 16:04:30 -0400919 dragController.setDragScoller(workspace);
Joe Onorato00acb122009-08-04 16:04:30 -0400920 dragController.setScrollView(dragLayer);
Romain Guyea3763c2010-01-11 18:02:04 -0800921 dragController.setMoveTarget(workspace);
Jason Samsfd22dac2009-09-20 17:24:16 -0700922
Joe Onorato00acb122009-08-04 16:04:30 -0400923 // The order here is bottom to top.
924 dragController.addDropTarget(workspace);
925 dragController.addDropTarget(deleteZone);
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700926 if (infoButton != null) {
927 dragController.addDropTarget(infoButton);
928 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800929 }
930
Romain Guy8a73c512009-11-09 19:19:59 -0800931 @SuppressWarnings({"UnusedDeclaration"})
932 public void previousScreen(View v) {
Joe Onorato61597bd2009-11-19 12:51:57 -0800933 if (!isAllAppsVisible()) {
934 mWorkspace.scrollLeft();
935 }
Romain Guy8a73c512009-11-09 19:19:59 -0800936 }
937
938 @SuppressWarnings({"UnusedDeclaration"})
939 public void nextScreen(View v) {
Joe Onorato61597bd2009-11-19 12:51:57 -0800940 if (!isAllAppsVisible()) {
941 mWorkspace.scrollRight();
942 }
Romain Guy8a73c512009-11-09 19:19:59 -0800943 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400944
945 @SuppressWarnings({"UnusedDeclaration"})
946 public void launchHotSeat(View v) {
Daniel Sandler3e9454a2010-05-24 11:22:41 -0400947 if (isAllAppsVisible()) return;
948
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400949 int index = -1;
950 if (v.getId() == R.id.hotseat_left) {
951 index = 0;
952 } else if (v.getId() == R.id.hotseat_right) {
953 index = 1;
954 }
955
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400956 // reload these every tap; you never know when they might change
957 loadHotseats();
958 if (index >= 0 && index < mHotseats.length && mHotseats[index] != null) {
959 Intent intent = mHotseats[index];
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400960 startActivitySafely(
961 mHotseats[index],
962 "hotseat"
963 );
964 }
965 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700966
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800967 /**
968 * Creates a view representing a shortcut.
969 *
970 * @param info The data structure describing the shortcut.
971 *
972 * @return A View inflated from R.layout.application.
973 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800974 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800975 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -0700976 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800977 }
978
979 /**
980 * Creates a view representing a shortcut inflated from the specified resource.
981 *
982 * @param layoutResId The id of the XML layout used to create the shortcut.
983 * @param parent The group the shortcut belongs to.
984 * @param info The data structure describing the shortcut.
985 *
986 * @return A View inflated from layoutResId.
987 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800988 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800989 TextView favorite = (TextView) mInflater.inflate(layoutResId, parent, false);
990
Joe Onorato0589f0f2010-02-08 13:44:00 -0800991 favorite.setCompoundDrawablesWithIntrinsicBounds(null,
992 new FastBitmapDrawable(info.getIcon(mIconCache)),
993 null, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800994 favorite.setText(info.title);
995 favorite.setTag(info);
996 favorite.setOnClickListener(this);
997
998 return favorite;
999 }
1000
1001 /**
1002 * Add an application shortcut to the workspace.
1003 *
1004 * @param data The intent describing the application.
1005 * @param cellInfo The position on screen where to create the shortcut.
1006 */
Michael Jurka0280c3b2010-09-17 15:00:07 -07001007 void completeAddApplication(Context context, Intent data, int screen,
1008 int intersectCellX, int intersectCellY) {
1009 final int[] cellXY = mTmpAddItemCellCoordinates;
1010 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1011
1012 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1013 showOutOfSpaceMessage();
1014 return;
1015 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001016
Joe Onorato0589f0f2010-02-08 13:44:00 -08001017 final ShortcutInfo info = mModel.getShortcutInfo(context.getPackageManager(),
1018 data, context);
1019
Romain Guy73b979d2009-06-09 12:57:21 -07001020 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -08001021 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001022 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001023 info.container = ItemInfo.NO_ID;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001024 mWorkspace.addApplicationShortcut(info, screen, cellXY[0], cellXY[1],
1025 isWorkspaceLocked(), mAddIntersectCellX, mAddIntersectCellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001026 } else {
1027 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001028 }
1029 }
Romain Guycbb89e42009-06-08 15:52:54 -07001030
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001031 /**
1032 * Add a shortcut to the workspace.
1033 *
1034 * @param data The intent describing the shortcut.
1035 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001036 */
Michael Jurka0280c3b2010-09-17 15:00:07 -07001037 private void completeAddShortcut(Intent data, int screen,
1038 int intersectCellX, int intersectCellY) {
1039 final int[] cellXY = mTmpAddItemCellCoordinates;
1040 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
Romain Guycbb89e42009-06-08 15:52:54 -07001041
Michael Jurka0280c3b2010-09-17 15:00:07 -07001042 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1043 showOutOfSpaceMessage();
1044 return;
1045 }
1046
1047 final ShortcutInfo info = mModel.addShortcut(
1048 this, data, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001049
1050 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001051 final View view = createShortcut(info);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001052 mWorkspace.addInScreen(view, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001053 }
1054 }
1055
Romain Guycbb89e42009-06-08 15:52:54 -07001056
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001057 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001058 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001059 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001060 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001061 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001062 */
Michael Jurka0280c3b2010-09-17 15:00:07 -07001063 private void completeAddAppWidget(int appWidgetId, int screen) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001064 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Romain Guycbb89e42009-06-08 15:52:54 -07001065
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001066 // Calculate the grid spans needed to fit this widget
Michael Jurka0280c3b2010-09-17 15:00:07 -07001067 CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1068 int[] spanXY = layout.rectToCell(appWidgetInfo.minWidth, appWidgetInfo.minHeight, null);
Romain Guycbb89e42009-06-08 15:52:54 -07001069
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001070 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001071 // We have saved the position to which the widget was dragged-- this really only matters
1072 // if we are placing widgets on a "spring-loaded" screen
Michael Jurka0280c3b2010-09-17 15:00:07 -07001073 final int[] cellXY = mTmpAddItemCellCoordinates;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001074
1075 // For now, we don't save the coordinate where we dropped the icon because we're not
1076 // supporting spring-loaded mini-screens; however, leaving the ability to directly place
1077 // a widget on the home screen in case we want to add it in the future
Michael Jurka0280c3b2010-09-17 15:00:07 -07001078 final int[] touchXY = null;
1079 //final int[] touchXY = mAddDropPosition;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001080 boolean findNearestVacantAreaFailed = false;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001081 boolean foundCellSpan = false;
1082 if (touchXY != null) {
1083 // when dragging and dropping, just find the closest free spot
1084 CellLayout screenLayout = (CellLayout) mWorkspace.getChildAt(screen);
1085 int[] result = screenLayout.findNearestVacantArea(
1086 touchXY[0], touchXY[1], spanXY[0], spanXY[1], cellXY);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001087 findNearestVacantAreaFailed = (result == null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001088 foundCellSpan = !findNearestVacantAreaFailed;
1089 } else {
1090 if (mAddIntersectCellX != -1 && mAddIntersectCellY != -1) {
1091 // if we long pressed on an empty cell to bring up a menu,
1092 // make sure we intersect the empty cell
1093 foundCellSpan = layout.findCellForSpanThatIntersects(cellXY, spanXY[0], spanXY[1],
1094 mAddIntersectCellX, mAddIntersectCellY);
1095 } else {
1096 // if we went through the menu -> add, just find any spot
1097 foundCellSpan = layout.findCellForSpan(cellXY, spanXY[0], spanXY[1]);
1098 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001099 }
1100
Michael Jurka0280c3b2010-09-17 15:00:07 -07001101 if (!foundCellSpan) {
Romain Guy18042c82009-11-06 11:44:55 -08001102 if (appWidgetId != -1) mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001103 showOutOfSpaceMessage();
Romain Guy18042c82009-11-06 11:44:55 -08001104 return;
1105 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001106
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001107 // Build Launcher-specific widget info and save to database
1108 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001109 launcherInfo.spanX = spanXY[0];
1110 launcherInfo.spanY = spanXY[1];
Romain Guycbb89e42009-06-08 15:52:54 -07001111
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001112 LauncherModel.addItemToDatabase(this, launcherInfo,
1113 LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001114 screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001115
1116 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001117 mDesktopItems.add(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001118
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001119 // Perform actual inflation because we're live
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001120 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001121
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001122 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001123 launcherInfo.hostView.setTag(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001124
Michael Jurka0280c3b2010-09-17 15:00:07 -07001125 mWorkspace.addInScreen(launcherInfo.hostView, screen, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001126 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001127 }
1128 }
Romain Guycbb89e42009-06-08 15:52:54 -07001129
Michael Jurka0280c3b2010-09-17 15:00:07 -07001130 void showOutOfSpaceMessage() {
1131 Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show();
1132 }
1133
Joe Onorato9c1289c2009-08-17 11:03:03 -04001134 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
1135 mDesktopItems.remove(launcherInfo);
1136 launcherInfo.hostView = null;
1137 }
1138
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001139 public LauncherAppWidgetHost getAppWidgetHost() {
1140 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001141 }
Romain Guycbb89e42009-06-08 15:52:54 -07001142
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001143 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001144 getWindow().closeAllPanels();
1145
1146 try {
1147 dismissDialog(DIALOG_CREATE_SHORTCUT);
1148 // Unlock the workspace if the dialog was showing
1149 } catch (Exception e) {
1150 // An exception is thrown if the dialog is not visible, which is fine
1151 }
1152
1153 try {
1154 dismissDialog(DIALOG_RENAME_FOLDER);
1155 // Unlock the workspace if the dialog was showing
1156 } catch (Exception e) {
1157 // An exception is thrown if the dialog is not visible, which is fine
1158 }
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001159
1160 // Whatever we were doing is hereby canceled.
1161 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001162 }
1163
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001164 @Override
1165 protected void onNewIntent(Intent intent) {
1166 super.onNewIntent(intent);
1167
1168 // Close the menu
1169 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001170 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001171 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001172
Joe Onorato14f122b2009-11-19 14:06:36 -08001173 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1174 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
1175 boolean allAppsVisible = isAllAppsVisible();
Michael Jurka01f0ed42010-08-20 00:41:17 -07001176 boolean customizationDrawerVisible = isCustomizationDrawerVisible();
1177
Michael Jurka4cb37242010-08-09 21:05:32 -07001178 // in all these cases, only animate if we're already on home
1179 if (LauncherApplication.isScreenXLarge()) {
Michael Jurka99229f62010-09-09 11:49:32 -07001180 mWorkspace.unshrink(alreadyOnHome);
1181 }
1182 if (!mWorkspace.isDefaultPageShowing()) {
Michael Jurka4cb37242010-08-09 21:05:32 -07001183 // on the phone, we don't animate the change to the workspace if all apps is visible
Michael Jurka99229f62010-09-09 11:49:32 -07001184 mWorkspace.moveToDefaultScreen(
1185 alreadyOnHome && (LauncherApplication.isScreenXLarge() || !allAppsVisible));
Joe Onorato3a8820b2009-11-10 15:06:42 -08001186 }
Joe Onorato14f122b2009-11-19 14:06:36 -08001187 closeAllApps(alreadyOnHome && allAppsVisible);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07001188 hideCustomizationDrawer(alreadyOnHome);
Romain Guy1dd3a072009-07-16 13:21:01 -07001189
Joe Onorato3a8820b2009-11-10 15:06:42 -08001190 final View v = getWindow().peekDecorView();
1191 if (v != null && v.getWindowToken() != null) {
1192 InputMethodManager imm = (InputMethodManager)getSystemService(
1193 INPUT_METHOD_SERVICE);
1194 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001195 }
1196 }
1197 }
1198
1199 @Override
1200 protected void onRestoreInstanceState(Bundle savedInstanceState) {
1201 // Do not call super here
1202 mSavedInstanceState = savedInstanceState;
Michael Jurka946ad472010-07-09 18:05:18 -07001203
1204 if (mHomeCustomizationDrawer != null) {
1205 String cur = savedInstanceState.getString("currentTab");
1206 if (cur != null) {
1207 mHomeCustomizationDrawer.setCurrentTabByTag(cur);
1208 }
1209 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001210 }
1211
1212 @Override
1213 protected void onSaveInstanceState(Bundle outState) {
Michael Jurka0142d492010-08-25 17:46:15 -07001214 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001215
1216 final ArrayList<Folder> folders = mWorkspace.getOpenFolders();
1217 if (folders.size() > 0) {
1218 final int count = folders.size();
1219 long[] ids = new long[count];
1220 for (int i = 0; i < count; i++) {
1221 final FolderInfo info = folders.get(i).getInfo();
1222 ids[i] = info.id;
1223 }
1224 outState.putLongArray(RUNTIME_STATE_USER_FOLDERS, ids);
1225 } else {
1226 super.onSaveInstanceState(outState);
1227 }
1228
Joe Onoratofb0ca672009-09-14 17:55:46 -04001229 // TODO should not do this if the drawer is currently closing.
Joe Onorato3a8820b2009-11-10 15:06:42 -08001230 if (isAllAppsVisible()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001231 outState.putBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, true);
Romain Guy5a941392009-04-28 15:18:25 -07001232 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001233
Michael Jurka0280c3b2010-09-17 15:00:07 -07001234 if (mAddScreen > -1 && mWaitingForResult) {
1235 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mAddScreen);
1236 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mAddIntersectCellX);
1237 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001238 }
1239
1240 if (mFolderInfo != null && mWaitingForResult) {
1241 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1242 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1243 }
Michael Jurka946ad472010-07-09 18:05:18 -07001244
1245 if (mHomeCustomizationDrawer != null) {
1246 String currentTabTag = mHomeCustomizationDrawer.getCurrentTabTag();
1247 if (currentTabTag != null) {
1248 outState.putString("currentTab", currentTabTag);
1249 }
1250 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001251 }
1252
1253 @Override
1254 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001255 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001256
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001257 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001258 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001259 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001260 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001261 }
1262
1263 TextKeyListener.getInstance().release();
1264
Joe Onorato9c1289c2009-08-17 11:03:03 -04001265 mModel.stopLoader();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001266
Joe Onorato9c1289c2009-08-17 11:03:03 -04001267 unbindDesktopItems();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001268
1269 getContentResolver().unregisterContentObserver(mWidgetObserver);
Winson Chungaafa03c2010-06-11 17:34:16 -07001270
Patrick Dubroyab962b72010-07-26 12:10:10 -07001271 // Some launcher layouts don't have a previous and next view
1272 if (mPreviousView != null) {
1273 dismissPreview(mPreviousView);
1274 }
1275 if (mNextView != null) {
1276 dismissPreview(mNextView);
1277 }
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001278
1279 unregisterReceiver(mCloseSystemDialogsReceiver);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001280 }
1281
1282 @Override
1283 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001284 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001285 super.startActivityForResult(intent, requestCode);
1286 }
1287
1288 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001289 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001290 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001291
Joe Onorato7bb17492009-09-24 17:51:01 -07001292 closeAllApps(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001293
Karl Rosaen138a0412009-04-23 19:00:21 -07001294 if (initialQuery == null) {
1295 // Use any text typed in the launcher as the initial query
1296 initialQuery = getTypedText();
1297 clearTypedText();
1298 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001299 if (appSearchData == null) {
1300 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +00001301 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001302 }
Romain Guycbb89e42009-06-08 15:52:54 -07001303
Karl Rosaen138a0412009-04-23 19:00:21 -07001304 final SearchManager searchManager =
1305 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Karl Rosaen138a0412009-04-23 19:00:21 -07001306 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Romain Guycbb89e42009-06-08 15:52:54 -07001307 appSearchData, globalSearch);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001308 }
1309
1310 @Override
1311 public boolean onCreateOptionsMenu(Menu menu) {
Patrick Dubroy5905bca2010-09-08 22:43:38 -07001312 if (isWorkspaceLocked()) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001313 return false;
1314 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001315
1316 super.onCreateOptionsMenu(menu);
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001317
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001318 menu.add(MENU_GROUP_ADD, MENU_ADD, 0, R.string.menu_add)
1319 .setIcon(android.R.drawable.ic_menu_add)
1320 .setAlphabeticShortcut('A');
Winson Chung7ad01412010-09-27 11:33:03 -07001321 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1322 .setIcon(android.R.drawable.ic_menu_manage)
1323 .setAlphabeticShortcut('M');
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001324 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001325 .setIcon(android.R.drawable.ic_menu_gallery)
1326 .setAlphabeticShortcut('W');
1327 menu.add(0, MENU_SEARCH, 0, R.string.menu_search)
1328 .setIcon(android.R.drawable.ic_search_category_default)
1329 .setAlphabeticShortcut(SearchManager.MENU_KEY);
1330 menu.add(0, MENU_NOTIFICATIONS, 0, R.string.menu_notifications)
1331 .setIcon(com.android.internal.R.drawable.ic_menu_notifications)
1332 .setAlphabeticShortcut('N');
1333
1334 final Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
Romain Guy5a941392009-04-28 15:18:25 -07001335 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
1336 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001337
1338 menu.add(0, MENU_SETTINGS, 0, R.string.menu_settings)
1339 .setIcon(android.R.drawable.ic_menu_preferences).setAlphabeticShortcut('P')
1340 .setIntent(settings);
1341
1342 return true;
1343 }
1344
1345 @Override
1346 public boolean onPrepareOptionsMenu(Menu menu) {
1347 super.onPrepareOptionsMenu(menu);
1348
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001349 // If all apps is animating, don't show the menu, because we don't know
1350 // which one to show.
Patrick Dubroyff5f0402010-07-26 15:23:26 -07001351 if (mAllAppsGrid.isAnimating()) {
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001352 return false;
1353 }
1354
1355 // Only show the add and wallpaper options when we're not in all apps.
Patrick Dubroyff5f0402010-07-26 15:23:26 -07001356 boolean visible = !mAllAppsGrid.isVisible();
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001357 menu.setGroupVisible(MENU_GROUP_ADD, visible);
1358 menu.setGroupVisible(MENU_GROUP_WALLPAPER, visible);
1359
1360 // Disable add if the workspace is full.
1361 if (visible) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001362 CellLayout layout = (CellLayout) mWorkspace.getChildAt(mWorkspace.getCurrentPage());
1363 menu.setGroupEnabled(MENU_GROUP_ADD, layout.existsEmptyCell());
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001364 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001365
1366 return true;
1367 }
1368
1369 @Override
1370 public boolean onOptionsItemSelected(MenuItem item) {
1371 switch (item.getItemId()) {
1372 case MENU_ADD:
1373 addItems();
1374 return true;
Winson Chung7ad01412010-09-27 11:33:03 -07001375 case MENU_MANAGE_APPS:
1376 manageApps();
1377 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001378 case MENU_WALLPAPER_SETTINGS:
1379 startWallpaper();
1380 return true;
1381 case MENU_SEARCH:
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001382 onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001383 return true;
1384 case MENU_NOTIFICATIONS:
1385 showNotifications();
1386 return true;
1387 }
1388
1389 return super.onOptionsItemSelected(item);
1390 }
Romain Guycbb89e42009-06-08 15:52:54 -07001391
Karl Rosaen138a0412009-04-23 19:00:21 -07001392 /**
1393 * Indicates that we want global search for this activity by setting the globalSearch
1394 * argument for {@link #startSearch} to true.
1395 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001396
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001397 @Override
1398 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001399 startSearch(null, false, null, true);
Karl Rosaen138a0412009-04-23 19:00:21 -07001400 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001401 }
1402
Joe Onorato9c1289c2009-08-17 11:03:03 -04001403 public boolean isWorkspaceLocked() {
1404 return mWorkspaceLoading || mWaitingForResult;
1405 }
1406
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001407 private void addItems() {
Patrick Dubroy558654c2010-07-23 16:48:11 -07001408 if (LauncherApplication.isScreenXLarge()) {
1409 // Animate the widget chooser up from the bottom of the screen
1410 if (!isCustomizationDrawerVisible()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07001411 showCustomizationDrawer(true);
Patrick Dubroy558654c2010-07-23 16:48:11 -07001412 }
1413 } else {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001414 closeAllApps(true);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001415 showAddDialog(-1, -1);
Patrick Dubroy558654c2010-07-23 16:48:11 -07001416 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001417 }
1418
Michael Jurka0280c3b2010-09-17 15:00:07 -07001419 private void resetAddInfo() {
1420 mAddScreen = -1;
1421 mAddIntersectCellX = -1;
1422 mAddIntersectCellY = -1;
1423 mAddDropPosition = null;
1424 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001425
Michael Jurka0280c3b2010-09-17 15:00:07 -07001426 void addAppWidgetFromDrop(ComponentName appWidgetProvider, int screen, int[] position) {
1427 resetAddInfo();
1428 mAddScreen = screen;
1429
1430 // only set mAddDropPosition if we dropped on home screen in "spring-loaded" manner
1431 mAddDropPosition = position;
1432
Michael Jurkaaf442092010-06-10 17:01:57 -07001433 int appWidgetId = getAppWidgetHost().allocateAppWidgetId();
1434 AppWidgetManager.getInstance(this).bindAppWidgetId(appWidgetId, appWidgetProvider);
1435 addAppWidgetImpl(appWidgetId);
1436 }
1437
Winson Chung7ad01412010-09-27 11:33:03 -07001438 private void manageApps() {
1439 startActivity(new Intent(android.provider.Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS));
1440 }
1441
Michael Jurkaaf442092010-06-10 17:01:57 -07001442 void addAppWidgetFromPick(Intent data) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001443 // TODO: catch bad widget exception when sent
1444 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurkaaf442092010-06-10 17:01:57 -07001445 // TODO: Is this log message meaningful?
1446 if (LOGD) Log.d(TAG, "dumping extras content=" + data.getExtras());
1447 addAppWidgetImpl(appWidgetId);
1448 }
1449
1450 void addAppWidgetImpl(int appWidgetId) {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001451 AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001452
Bjorn Bringert7984c942009-12-09 15:38:25 +00001453 if (appWidget.configure != null) {
1454 // Launch over to configure widget, if needed
1455 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
1456 intent.setComponent(appWidget.configure);
1457 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
1458
Romain Guy8e633c52010-03-04 12:51:36 -08001459 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001460 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001461 // Otherwise just add it
Michael Jurka0280c3b2010-09-17 15:00:07 -07001462 completeAddAppWidget(appWidgetId, mAddScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001463 }
1464 }
Romain Guycbb89e42009-06-08 15:52:54 -07001465
Michael Jurka0280c3b2010-09-17 15:00:07 -07001466 void processShortcutFromDrop(ComponentName componentName, int screen, int[] position) {
1467 resetAddInfo();
1468 mAddScreen = screen;
1469 mAddDropPosition = position;
1470
1471 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1472 createShortcutIntent.setComponent(componentName);
1473 processShortcut(createShortcutIntent);
1474 }
1475
Joe Onoratodeb98af2010-02-19 14:59:39 -08001476 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001477 // Handle case where user selected "Applications"
1478 String applicationName = getResources().getString(R.string.group_applications);
1479 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001480
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001481 if (applicationName != null && applicationName.equals(shortcutName)) {
1482 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1483 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001484
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001485 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1486 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Joe Onorato4a79a042010-09-24 16:17:21 -07001487 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001488 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001489 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001490 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001491 }
1492
Winson Chung24ab2f12010-09-16 14:10:47 -07001493 void processWallpaper(Intent intent) {
1494 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1495 }
1496
Michael Jurka0280c3b2010-09-17 15:00:07 -07001497 void addLiveFolderFromDrop(ComponentName componentName, int screen, int[] position) {
1498 resetAddInfo();
1499 mAddScreen = screen;
1500 mAddDropPosition = position;
1501
1502 Intent createFolderIntent = new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER);
1503 createFolderIntent.setComponent(componentName);
1504
1505 addLiveFolder(createFolderIntent);
1506 }
1507
1508 void addLiveFolder(Intent intent) { // YYY add screen intersect etc. parameters here
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001509 // Handle case where user selected "Folder"
Jeffrey Sharkeyc4bbd0a2009-03-24 22:47:52 -07001510 String folderName = getResources().getString(R.string.group_folder);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001511 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001512
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001513 if (folderName != null && folderName.equals(shortcutName)) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001514 addFolder(mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001515 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001516 startActivityForResultSafely(intent, REQUEST_CREATE_LIVE_FOLDER);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001517 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001518 }
1519
Michael Jurka0280c3b2010-09-17 15:00:07 -07001520 void addFolder(int screen, int intersectCellX, int intersectCellY) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001521 UserFolderInfo folderInfo = new UserFolderInfo();
1522 folderInfo.title = getText(R.string.folder_name);
1523
Michael Jurka0280c3b2010-09-17 15:00:07 -07001524 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1525 final int[] cellXY = mTmpAddItemCellCoordinates;
1526 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1527 showOutOfSpaceMessage();
1528 return;
1529 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001530
1531 // Update the model
Joe Onorato9c1289c2009-08-17 11:03:03 -04001532 LauncherModel.addItemToDatabase(this, folderInfo,
1533 LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001534 screen, cellXY[0], cellXY[1], false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001535 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001536
1537 // Create the view
1538 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07001539 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), folderInfo);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001540 mWorkspace.addInScreen(newFolder, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001541 }
Romain Guycbb89e42009-06-08 15:52:54 -07001542
Joe Onorato9c1289c2009-08-17 11:03:03 -04001543 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001544 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001545 }
1546
Michael Jurka28750fb2010-09-24 17:43:49 -07001547 private void completeAddLiveFolder(
1548 Intent data, int screen, int intersectCellX, int intersectCellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001549 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1550 final int[] cellXY = mTmpAddItemCellCoordinates;
1551 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1552 showOutOfSpaceMessage();
1553 return;
1554 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001555
Michael Jurka0280c3b2010-09-17 15:00:07 -07001556 final LiveFolderInfo info = addLiveFolder(this, data, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001557
1558 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001559 final View view = LiveFolderIcon.fromXml(R.layout.live_folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07001560 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001561 mWorkspace.addInScreen(view, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001562 }
1563 }
1564
1565 static LiveFolderInfo addLiveFolder(Context context, Intent data,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001566 int screen, int cellX, int cellY, boolean notify) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001567
1568 Intent baseIntent = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT);
1569 String name = data.getStringExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME);
1570
1571 Drawable icon = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001572 Intent.ShortcutIconResource iconResource = null;
1573
1574 Parcelable extra = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON);
1575 if (extra != null && extra instanceof Intent.ShortcutIconResource) {
1576 try {
1577 iconResource = (Intent.ShortcutIconResource) extra;
1578 final PackageManager packageManager = context.getPackageManager();
1579 Resources resources = packageManager.getResourcesForApplication(
1580 iconResource.packageName);
1581 final int id = resources.getIdentifier(iconResource.resourceName, null, null);
1582 icon = resources.getDrawable(id);
1583 } catch (Exception e) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001584 Log.w(TAG, "Could not load live folder icon: " + extra);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001585 }
1586 }
1587
1588 if (icon == null) {
1589 icon = context.getResources().getDrawable(R.drawable.ic_launcher_folder);
1590 }
1591
1592 final LiveFolderInfo info = new LiveFolderInfo();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001593 info.icon = Utilities.createIconBitmap(icon, context);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001594 info.title = name;
1595 info.iconResource = iconResource;
1596 info.uri = data.getData();
1597 info.baseIntent = baseIntent;
1598 info.displayMode = data.getIntExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE,
1599 LiveFolders.DISPLAY_MODE_GRID);
1600
1601 LauncherModel.addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001602 screen, cellX, cellY, notify);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001603 sFolders.put(info.id, info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001604
1605 return info;
1606 }
1607
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001608 private void showNotifications() {
1609 final StatusBarManager statusBar = (StatusBarManager) getSystemService(STATUS_BAR_SERVICE);
1610 if (statusBar != null) {
1611 statusBar.expand();
1612 }
1613 }
1614
1615 private void startWallpaper() {
Joe Onoratoe6168662009-11-08 13:39:30 -05001616 closeAllApps(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001617 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001618 Intent chooser = Intent.createChooser(pickWallpaper,
1619 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001620 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1621 // Removed in Eclair MR1
1622// WallpaperManager wm = (WallpaperManager)
1623// getSystemService(Context.WALLPAPER_SERVICE);
1624// WallpaperInfo wi = wm.getWallpaperInfo();
1625// if (wi != null && wi.getSettingsActivity() != null) {
1626// LabeledIntent li = new LabeledIntent(getPackageName(),
1627// R.string.configure_wallpaper, 0);
1628// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1629// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1630// }
Mike Clerona0618e42009-10-22 13:55:21 -07001631 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001632 }
1633
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001634 /**
1635 * Registers various content observers. The current implementation registers
1636 * only a favorites observer to keep track of the favorites applications.
1637 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001638 private void registerContentObservers() {
1639 ContentResolver resolver = getContentResolver();
1640 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1641 true, mWidgetObserver);
1642 }
1643
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001644 @Override
1645 public boolean dispatchKeyEvent(KeyEvent event) {
1646 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1647 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001648 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001649 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001650 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jason Samseb5615d2009-11-30 11:50:10 -08001651 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
Joe Onoratobe386092009-11-17 17:32:16 -08001652 dumpState();
1653 return true;
1654 }
1655 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001656 }
1657 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1658 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001659 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001660 return true;
1661 }
1662 }
1663
1664 return super.dispatchKeyEvent(event);
1665 }
1666
Joe Onorato88ec0992009-11-19 13:16:06 -08001667 @Override
1668 public void onBackPressed() {
1669 if (isAllAppsVisible()) {
1670 closeAllApps(true);
Patrick Dubroy558654c2010-07-23 16:48:11 -07001671 } else if (isCustomizationDrawerVisible()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07001672 hideCustomizationDrawer(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) {
Joe Onoratofb0ca672009-09-14 17:55:46 -04001738 if (isAllAppsVisible()) {
Joe Onorato7bb17492009-09-24 17:51:01 -07001739 closeAllApps(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 Jurka0e260592010-06-30 17:07:39 -07001748 // clicking anywhere on the workspace causes the drawer to slide down
Patrick Dubroy6b509c12010-08-23 15:08:16 -07001749 hideCustomizationDrawer(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:
Joe Onorato0d44e942009-11-16 18:20:51 -08001895 if (!isAllAppsVisible()) {
1896 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1897 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Romain Guyf8e6a802009-12-07 17:48:02 -08001898 showPreviews(v);
Joe Onorato0d44e942009-11-16 18:20:51 -08001899 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08001900 return true;
1901 case R.id.next_screen:
Joe Onorato0d44e942009-11-16 18:20:51 -08001902 if (!isAllAppsVisible()) {
1903 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:
1909 if (!isAllAppsVisible()) {
1910 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());
2031 cell.dispatchDraw(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() {
Romain Guy5bbc91b2010-08-18 11:38:46 -07002241 return mAllAppsGrid != null && mAllAppsGrid.isVisible();
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
Chet Haaseb1254a62010-09-07 13:35:00 -07002403 AnimatorSet s = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002404 s.playTogether(scaleAnim, toolbarHideAnim);
2405 s.play(scaleAnim).after(startDelay);
2406
2407 // Show the new toolbar buttons just as the main animation is ending
2408 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
2409 s.play(toolbarShowAnim).after(duration + startDelay - fadeInTime);
2410 s.start();
2411 } else {
2412 toView.setTranslationX(0.0f);
2413 toView.setTranslationY(0.0f);
2414 toView.setScaleX(1.0f);
2415 toView.setScaleY(1.0f);
2416 toView.setVisibility(View.VISIBLE);
2417 hideAndShowToolbarButtons(toState, null, null);
2418 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002419 }
2420
2421 /**
2422 * Zoom the camera back into the workspace, hiding 'fromView'.
2423 * This is the opposite of cameraZoomOut.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002424 * @param fromState The current state (must be ALL_APPS or CUSTOMIZE).
2425 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002426 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002427 private void cameraZoomIn(State fromState, boolean animated) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002428 Resources res = getResources();
2429 int duration = res.getInteger(R.integer.config_allAppsZoomOutTime);
2430 float scaleFactor = (float) res.getInteger(R.integer.config_allAppsZoomScaleFactor);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002431 final View fromView =
2432 (fromState == State.ALL_APPS) ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
2433
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002434 mCustomizePagedView.endChoiceMode();
2435 mAllAppsPagedView.endChoiceMode();
2436
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002437 setPivotsForZoom(fromView, fromState, scaleFactor);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002438
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002439 mWorkspace.unshrink(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002440
2441 if (animated) {
Chet Haaseb1254a62010-09-07 13:35:00 -07002442 AnimatorSet s = new AnimatorSet();
2443 ValueAnimator scaleAnim = new ObjectAnimator(duration, fromView,
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002444 new PropertyValuesHolder<Float>("scaleX", scaleFactor),
2445 new PropertyValuesHolder<Float>("scaleY", scaleFactor));
2446 scaleAnim.setInterpolator(new AccelerateInterpolator());
Chet Haaseb1254a62010-09-07 13:35:00 -07002447 s.addListener(new AnimatorListenerAdapter() {
2448 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002449 fromView.setVisibility(View.GONE);
2450 fromView.setScaleX(1.0f);
2451 fromView.setScaleY(1.0f);
2452 }
2453 });
2454
Chet Haaseb1254a62010-09-07 13:35:00 -07002455 AnimatorSet toolbarHideAnim = new AnimatorSet();
2456 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002457 hideAndShowToolbarButtons(State.WORKSPACE, toolbarShowAnim, toolbarHideAnim);
2458
2459 s.playTogether(scaleAnim, toolbarHideAnim);
2460
2461 // Show the new toolbar buttons at the very end of the whole animation
2462 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
2463 final int unshrinkTime = res.getInteger(R.integer.config_workspaceUnshrinkTime);
2464 s.play(toolbarShowAnim).after(unshrinkTime - fadeInTime);
2465 s.start();
2466 } else {
2467 fromView.setVisibility(View.GONE);
2468 hideAndShowToolbarButtons(State.WORKSPACE, null, null);
2469 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002470 }
2471
2472 /**
2473 * Pan the camera in the vertical plane between 'fromView' and 'toView'.
2474 * This is the transition used on xlarge screens to go between all apps and
2475 * the home customization drawer.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002476 * @param fromState The view to pan away from. Must be ALL_APPS or CUSTOMIZE.
2477 * @param toState The view to pan into the frame. Must be ALL_APPS or CUSTOMIZE.
2478 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002479 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002480 private void cameraPan(State fromState, State toState, boolean animated) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002481 final Resources res = getResources();
2482 final int duration = res.getInteger(R.integer.config_allAppsCameraPanTime);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002483 final int workspaceHeight = mWorkspace.getHeight();
2484
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002485 final boolean fromAllApps = (fromState == State.ALL_APPS);
2486 final View fromView = fromAllApps ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
2487 final View toView = fromAllApps ? mHomeCustomizationDrawer : (View) mAllAppsGrid;
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002488
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002489 final float fromViewStartY = fromAllApps ? 0.0f : fromView.getY();
2490 final float fromViewEndY = fromAllApps ? -fromView.getHeight() * 2 : workspaceHeight * 2;
2491 final float toViewStartY = fromAllApps ? workspaceHeight * 2 : -toView.getHeight() * 2;
2492 final float toViewEndY = fromAllApps ? workspaceHeight - toView.getHeight() : 0.0f;
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002493
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002494 mCustomizePagedView.endChoiceMode();
2495 mAllAppsPagedView.endChoiceMode();
2496
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002497 if (toState == State.ALL_APPS) {
2498 mWorkspace.shrinkToBottom(animated);
2499 } else {
2500 mWorkspace.shrinkToTop(animated);
2501 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002502
2503 if (animated) {
Chet Haaseb1254a62010-09-07 13:35:00 -07002504 AnimatorSet s = new AnimatorSet();
2505 s.addListener(new AnimatorListenerAdapter() {
2506 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002507 toView.setVisibility(View.VISIBLE);
2508 toView.setY(toViewStartY);
2509 }
Chet Haaseb1254a62010-09-07 13:35:00 -07002510 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002511 fromView.setVisibility(View.GONE);
2512 }
2513 });
2514
Chet Haaseb1254a62010-09-07 13:35:00 -07002515 AnimatorSet toolbarHideAnim = new AnimatorSet();
2516 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002517 hideAndShowToolbarButtons(toState, toolbarShowAnim, toolbarHideAnim);
2518
2519 s.playTogether(
2520 toolbarHideAnim,
Chet Haaseb1254a62010-09-07 13:35:00 -07002521 new ObjectAnimator(duration, fromView, "y", fromViewStartY, fromViewEndY),
2522 new ObjectAnimator(duration, toView, "y", toViewStartY, toViewEndY));
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002523
2524 // Show the new toolbar buttons just as the main animation is ending
2525 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
2526 s.play(toolbarShowAnim).after(duration - fadeInTime);
2527 s.start();
2528 } else {
2529 fromView.setY(fromViewEndY);
2530 fromView.setVisibility(View.GONE);
2531 toView.setY(toViewEndY);
2532 toView.setVisibility(View.VISIBLE);
2533 hideAndShowToolbarButtons(toState, null, null);
2534 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002535 }
2536
2537 void showAllApps(boolean animated) {
Winson Chung80baf5a2010-08-09 16:03:15 -07002538 if (mAllAppsGrid.isVisible())
2539 return;
2540
Michael Jurka79212d82010-07-30 16:36:20 -07002541 if (LauncherApplication.isScreenXLarge()) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002542 if (isCustomizationDrawerVisible()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002543 cameraPan(State.CUSTOMIZE, State.ALL_APPS, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002544 } else {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002545 cameraZoomOut(State.ALL_APPS, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002546 }
Patrick Dubroy558654c2010-07-23 16:48:11 -07002547 } else {
2548 mAllAppsGrid.zoom(1.0f, animated);
2549 }
Joe Onorato3a8820b2009-11-10 15:06:42 -08002550
Romain Guyc16fea72010-03-12 17:17:56 -08002551 ((View) mAllAppsGrid).setFocusable(true);
2552 ((View) mAllAppsGrid).requestFocus();
Winson Chungaafa03c2010-06-11 17:34:16 -07002553
Joe Onorato7c312c12009-08-13 21:36:53 -07002554 // TODO: fade these two too
2555 mDeleteZone.setVisibility(View.GONE);
Joe Onorato00acb122009-08-04 16:04:30 -04002556 }
2557
Joe Onoratob2061212009-11-24 16:13:54 -05002558 /**
Joe Onorato7e4ed992009-12-03 13:10:49 -08002559 * Things to test when changing this code.
Joe Onoratob2061212009-11-24 16:13:54 -05002560 * - Home from workspace
2561 * - from center screen
2562 * - from other screens
2563 * - Home from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002564 * - from center screen
2565 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002566 * - Back from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002567 * - from center screen
2568 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002569 * - Launch app from workspace and quit
2570 * - with back
2571 * - with home
2572 * - Launch app from all apps and quit
2573 * - with back
2574 * - with home
Joe Onorato7e4ed992009-12-03 13:10:49 -08002575 * - Go to a screen that's not the default, then all
2576 * apps, and launch and app, and go back
2577 * - with back
2578 * -with home
Joe Onoratob2061212009-11-24 16:13:54 -05002579 * - On workspace, long press power and go back
2580 * - with back
2581 * - with home
2582 * - On all apps, long press power and go back
2583 * - with back
2584 * - with home
2585 * - On workspace, power off
2586 * - On all apps, power off
Joe Onorato7e4ed992009-12-03 13:10:49 -08002587 * - Launch an app and turn off the screen while in that app
2588 * - Go back with home key
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002589 * - Go back with back key TODO: make this not go to workspace
Joe Onorato7e4ed992009-12-03 13:10:49 -08002590 * - From all apps
2591 * - From workspace
Joe Onoratoeffc4a82010-04-15 11:48:13 -07002592 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2593 * - From all apps
2594 * - From the center workspace
2595 * - From another workspace
Joe Onoratob2061212009-11-24 16:13:54 -05002596 */
Joe Onorato7bb17492009-09-24 17:51:01 -07002597 void closeAllApps(boolean animated) {
Joe Onoratofb0ca672009-09-14 17:55:46 -04002598 if (mAllAppsGrid.isVisible()) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002599 mWorkspace.setVisibility(View.VISIBLE);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002600 if (LauncherApplication.isScreenXLarge()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002601 cameraZoomIn(State.ALL_APPS, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002602 } else {
2603 mAllAppsGrid.zoom(0.0f, animated);
2604 }
Daniel Sandler388f6792010-03-02 14:08:08 -05002605 ((View)mAllAppsGrid).setFocusable(false);
Michael Jurka0142d492010-08-25 17:46:15 -07002606 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onoratoe77c08d2009-08-01 00:01:20 -07002607 }
Joe Onorato7404ee42009-07-31 11:54:44 -07002608 }
2609
Joe Onorato7c312c12009-08-13 21:36:53 -07002610 void lockAllApps() {
2611 // TODO
2612 }
2613
2614 void unlockAllApps() {
2615 // TODO
2616 }
2617
Patrick Dubroy558654c2010-07-23 16:48:11 -07002618 private boolean isCustomizationDrawerVisible() {
Michael Jurka54f7ac32010-08-02 13:56:46 -07002619 return mHomeCustomizationDrawer != null &&
2620 mHomeCustomizationDrawer.getVisibility() == View.VISIBLE;
Patrick Dubroy558654c2010-07-23 16:48:11 -07002621 }
2622
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002623 // Show the customization drawer (only exists in x-large configuration)
2624 private void showCustomizationDrawer(boolean animated) {
Patrick Dubroy558654c2010-07-23 16:48:11 -07002625 if (isAllAppsVisible()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002626 cameraPan(State.ALL_APPS, State.CUSTOMIZE, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002627 } else {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002628 cameraZoomOut(State.CUSTOMIZE, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002629 }
Patrick Dubroy558654c2010-07-23 16:48:11 -07002630 }
2631
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002632 // Hide the customization drawer (only exists in x-large configuration)
2633 void hideCustomizationDrawer(boolean animated) {
Patrick Dubroy558654c2010-07-23 16:48:11 -07002634 if (isCustomizationDrawerVisible()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002635 cameraZoomIn(State.CUSTOMIZE, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002636 }
2637 }
2638
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002639 void onWorkspaceClick(CellLayout layout) {
2640 Object itemInfo = mAllAppsPagedView.getChosenItem();
2641 if (itemInfo == null) {
2642 itemInfo = mCustomizePagedView.getChosenItem();
Michael Jurka213d9632010-07-28 11:29:25 -07002643 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002644
2645 if (itemInfo == null) {
2646 // No items are chosen in All Apps or Customize, so just zoom into the workspace
2647 mWorkspace.unshrink(layout);
2648 if (isAllAppsVisible()) {
2649 closeAllApps(true);
2650 } else if (isCustomizationDrawerVisible()) {
2651 hideCustomizationDrawer(true);
2652 }
2653 } else {
2654 // Act as if the chosen item was dropped on the given CellLayout
2655 if (mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
2656 mAllAppsPagedView.endChoiceMode();
2657 mCustomizePagedView.endChoiceMode();
2658 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002659 showOutOfSpaceMessage();
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002660 }
Michael Jurka213d9632010-07-28 11:29:25 -07002661 }
2662 }
2663
Michael Jurka0423dcf2010-10-05 14:56:18 -07002664 private void updateButtonWithIconFromExternalActivity(
2665 int buttonId, ComponentName activityName, int fallbackDrawableId) {
2666 ImageView button = (ImageView) findViewById(buttonId);
2667 Drawable toolbarIcon = null;
2668 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002669 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07002670 // Look for the toolbar icon specified in the activity meta-data
2671 Bundle metaData = packageManager.getActivityInfo(
2672 activityName, PackageManager.GET_META_DATA).metaData;
2673 if (metaData != null) {
2674 int iconResId = metaData.getInt(TOOLBAR_ICON_METADATA_NAME);
2675 if (iconResId != 0) {
2676 Resources res = packageManager.getResourcesForActivity(activityName);
2677 toolbarIcon = res.getDrawable(iconResId);
2678 }
2679 }
2680 } catch (NameNotFoundException e) {
2681 // Do nothing
2682 }
2683 // If we were unable to find the icon via the meta-data, use a generic one
2684 if (toolbarIcon == null) {
2685 button.setImageResource(fallbackDrawableId);
2686 } else {
2687 button.setImageDrawable(toolbarIcon);
2688 }
2689 }
2690
2691 private void updateGlobalSearchIcon() {
2692 if (LauncherApplication.isScreenXLarge()) {
2693 final SearchManager searchManager =
2694 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2695 ComponentName activityName = searchManager.getGlobalSearchActivity();
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002696 if (activityName != null) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07002697 updateButtonWithIconFromExternalActivity(
2698 R.id.search_button, activityName, R.drawable.search_button_generic);
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002699 }
2700 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002701 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002702
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002703 /**
2704 * Sets the app market icon (shown when all apps is visible on x-large screens)
2705 */
2706 private void updateAppMarketIcon() {
Michael Jurka0423dcf2010-10-05 14:56:18 -07002707 if (LauncherApplication.isScreenXLarge()) {
2708 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
2709 // Find the app market activity by resolving an intent.
2710 // (If multiple app markets are installed, it will return the ResolverActivity.)
2711 ComponentName activityName = intent.resolveActivity(getPackageManager());
2712 if (activityName != null) {
2713 mAppMarketIntent = intent;
2714 updateButtonWithIconFromExternalActivity(
2715 R.id.market_button, activityName, R.drawable.app_market_generic);
2716 }
2717 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002718 }
2719
2720 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002721 * Displays the shortcut creation dialog and launches, if necessary, the
2722 * appropriate activity.
2723 */
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002724 private class CreateShortcut implements DialogInterface.OnClickListener,
Romain Guy7b4ef332009-07-14 13:58:08 -07002725 DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
2726 DialogInterface.OnShowListener {
2727
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002728 private AddAdapter mAdapter;
Romain Guy9ffb5432009-03-24 21:04:15 -07002729
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002730 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002731 mAdapter = new AddAdapter(Launcher.this);
Romain Guycbb89e42009-06-08 15:52:54 -07002732
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002733 final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
2734 builder.setTitle(getString(R.string.menu_item_add_item));
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002735 builder.setAdapter(mAdapter, this);
Romain Guycbb89e42009-06-08 15:52:54 -07002736
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002737 builder.setInverseBackgroundForced(true);
2738
2739 AlertDialog dialog = builder.create();
2740 dialog.setOnCancelListener(this);
Romain Guycbb89e42009-06-08 15:52:54 -07002741 dialog.setOnDismissListener(this);
Romain Guy7b4ef332009-07-14 13:58:08 -07002742 dialog.setOnShowListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002743
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002744 return dialog;
2745 }
2746
2747 public void onCancel(DialogInterface dialog) {
2748 mWaitingForResult = false;
2749 cleanup();
2750 }
2751
Romain Guycbb89e42009-06-08 15:52:54 -07002752 public void onDismiss(DialogInterface dialog) {
Romain Guycbb89e42009-06-08 15:52:54 -07002753 }
2754
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002755 private void cleanup() {
Joe Onoratocc19a532009-11-19 14:19:17 -08002756 try {
2757 dismissDialog(DIALOG_CREATE_SHORTCUT);
2758 } catch (Exception e) {
2759 // An exception is thrown if the dialog is not visible, which is fine
2760 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002761 }
2762
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002763 /**
2764 * Handle the action clicked in the "Add to home" dialog.
2765 */
2766 public void onClick(DialogInterface dialog, int which) {
2767 Resources res = getResources();
2768 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002769
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002770 switch (which) {
2771 case AddAdapter.ITEM_SHORTCUT: {
Joe Onoratodeb98af2010-02-19 14:59:39 -08002772 pickShortcut();
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002773 break;
2774 }
Romain Guycbb89e42009-06-08 15:52:54 -07002775
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002776 case AddAdapter.ITEM_APPWIDGET: {
2777 int appWidgetId = Launcher.this.mAppWidgetHost.allocateAppWidgetId();
Romain Guycbb89e42009-06-08 15:52:54 -07002778
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002779 Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
2780 pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002781 // start the pick activity
2782 startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET);
2783 break;
2784 }
Romain Guycbb89e42009-06-08 15:52:54 -07002785
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002786 case AddAdapter.ITEM_LIVE_FOLDER: {
2787 // Insert extra item to handle inserting folder
2788 Bundle bundle = new Bundle();
Romain Guycbb89e42009-06-08 15:52:54 -07002789
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002790 ArrayList<String> shortcutNames = new ArrayList<String>();
2791 shortcutNames.add(res.getString(R.string.group_folder));
2792 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
Romain Guycbb89e42009-06-08 15:52:54 -07002793
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002794 ArrayList<ShortcutIconResource> shortcutIcons =
2795 new ArrayList<ShortcutIconResource>();
2796 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
2797 R.drawable.ic_launcher_folder));
2798 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
2799
2800 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2801 pickIntent.putExtra(Intent.EXTRA_INTENT,
2802 new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER));
2803 pickIntent.putExtra(Intent.EXTRA_TITLE,
2804 getText(R.string.title_select_live_folder));
2805 pickIntent.putExtras(bundle);
Romain Guycbb89e42009-06-08 15:52:54 -07002806
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002807 startActivityForResult(pickIntent, REQUEST_PICK_LIVE_FOLDER);
2808 break;
2809 }
2810
2811 case AddAdapter.ITEM_WALLPAPER: {
2812 startWallpaper();
2813 break;
2814 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002815 }
2816 }
Romain Guy7b4ef332009-07-14 13:58:08 -07002817
2818 public void onShow(DialogInterface dialog) {
Winson Chungaafa03c2010-06-11 17:34:16 -07002819 mWaitingForResult = true;
Romain Guy7b4ef332009-07-14 13:58:08 -07002820 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002821 }
2822
2823 /**
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002824 * Receives notifications when applications are added/removed.
2825 */
2826 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
2827 @Override
2828 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002829 closeSystemDialogs();
Joe Onoratob2061212009-11-24 16:13:54 -05002830 String reason = intent.getStringExtra("reason");
2831 if (!"homekey".equals(reason)) {
2832 boolean animate = true;
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002833 if (mPaused || "lock".equals(reason)) {
Joe Onoratob2061212009-11-24 16:13:54 -05002834 animate = false;
2835 }
Joe Onoratob2061212009-11-24 16:13:54 -05002836 closeAllApps(animate);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002837 hideCustomizationDrawer(animate);
Joe Onoratob2061212009-11-24 16:13:54 -05002838 }
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002839 }
2840 }
2841
2842 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002843 * Receives notifications whenever the appwidgets are reset.
2844 */
2845 private class AppWidgetResetObserver extends ContentObserver {
2846 public AppWidgetResetObserver() {
2847 super(new Handler());
2848 }
2849
2850 @Override
2851 public void onChange(boolean selfChange) {
2852 onAppWidgetReset();
2853 }
2854 }
2855
2856 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002857 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002858 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002859 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07002860 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002861 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07002862 } else {
2863 return SCREEN_COUNT / 2;
2864 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002865 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002866
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002867 void setAllAppsPagedView(PagedView view) {
2868 mAllAppsPagedView = view;
2869 }
2870
Joe Onorato9c1289c2009-08-17 11:03:03 -04002871 /**
2872 * Refreshes the shortcuts shown on the workspace.
2873 *
2874 * Implementation of the method from LauncherModel.Callbacks.
2875 */
2876 public void startBinding() {
2877 final Workspace workspace = mWorkspace;
2878 int count = workspace.getChildCount();
2879 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04002880 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Joe Onorato9c1289c2009-08-17 11:03:03 -04002881 ((ViewGroup) workspace.getChildAt(i)).removeAllViewsInLayout();
2882 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002883
Joe Onorato9c1289c2009-08-17 11:03:03 -04002884 if (DEBUG_USER_INTERFACE) {
2885 android.widget.Button finishButton = new android.widget.Button(this);
2886 finishButton.setText("Finish");
2887 workspace.addInScreen(finishButton, 1, 0, 0, 1, 1);
2888
2889 finishButton.setOnClickListener(new android.widget.Button.OnClickListener() {
2890 public void onClick(View v) {
2891 finish();
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002892 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002893 });
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002894 }
2895 }
2896
2897 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002898 * Bind the items start-end from the list.
2899 *
2900 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002901 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002902 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
2903
2904 final Workspace workspace = mWorkspace;
2905
2906 for (int i=start; i<end; i++) {
2907 final ItemInfo item = shortcuts.get(i);
2908 mDesktopItems.add(item);
2909 switch (item.itemType) {
2910 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
2911 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Joe Onorato0589f0f2010-02-08 13:44:00 -08002912 final View shortcut = createShortcut((ShortcutInfo)item);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002913 workspace.addInScreen(shortcut, item.screen, item.cellX, item.cellY, 1, 1,
2914 false);
2915 break;
2916 case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER:
2917 final FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07002918 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Joe Onorato9c1289c2009-08-17 11:03:03 -04002919 (UserFolderInfo) item);
2920 workspace.addInScreen(newFolder, item.screen, item.cellX, item.cellY, 1, 1,
2921 false);
2922 break;
2923 case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER:
2924 final FolderIcon newLiveFolder = LiveFolderIcon.fromXml(
2925 R.layout.live_folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07002926 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Joe Onorato9c1289c2009-08-17 11:03:03 -04002927 (LiveFolderInfo) item);
2928 workspace.addInScreen(newLiveFolder, item.screen, item.cellX, item.cellY, 1, 1,
2929 false);
2930 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002931 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002932 }
2933
Joe Onorato9c1289c2009-08-17 11:03:03 -04002934 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002935 }
2936
Joe Onorato9c1289c2009-08-17 11:03:03 -04002937 /**
2938 * Implementation of the method from LauncherModel.Callbacks.
2939 */
Joe Onoratoad72e172009-11-06 16:25:04 -05002940 public void bindFolders(HashMap<Long, FolderInfo> folders) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002941 sFolders.clear();
2942 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002943 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002944
2945 /**
2946 * Add the views for a widget to the workspace.
2947 *
2948 * Implementation of the method from LauncherModel.Callbacks.
2949 */
2950 public void bindAppWidget(LauncherAppWidgetInfo item) {
Daniel Sandler843e8602010-06-07 14:59:01 -04002951 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
2952 if (DEBUG_WIDGETS) {
2953 Log.d(TAG, "bindAppWidget: " + item);
2954 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002955 final Workspace workspace = mWorkspace;
2956
2957 final int appWidgetId = item.appWidgetId;
2958 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04002959 if (DEBUG_WIDGETS) {
2960 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
2961 }
2962
Joe Onorato9c1289c2009-08-17 11:03:03 -04002963 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
2964
Joe Onorato9c1289c2009-08-17 11:03:03 -04002965 item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
2966 item.hostView.setTag(item);
2967
2968 workspace.addInScreen(item.hostView, item.screen, item.cellX,
2969 item.cellY, item.spanX, item.spanY, false);
2970
2971 workspace.requestLayout();
2972
2973 mDesktopItems.add(item);
Daniel Sandler843e8602010-06-07 14:59:01 -04002974
2975 if (DEBUG_WIDGETS) {
2976 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
2977 + (SystemClock.uptimeMillis()-start) + "ms");
2978 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002979 }
2980
2981 /**
2982 * Callback saying that there aren't any more items to bind.
2983 *
2984 * Implementation of the method from LauncherModel.Callbacks.
2985 */
2986 public void finishBindingItems() {
2987 if (mSavedState != null) {
2988 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07002989 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002990 }
2991
2992 final long[] userFolders = mSavedState.getLongArray(RUNTIME_STATE_USER_FOLDERS);
2993 if (userFolders != null) {
2994 for (long folderId : userFolders) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002995 final FolderInfo info = sFolders.get(folderId);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002996 if (info != null) {
2997 openFolder(info);
2998 }
2999 }
3000 final Folder openFolder = mWorkspace.getOpenFolder();
3001 if (openFolder != null) {
3002 openFolder.requestFocus();
3003 }
3004 }
3005
Joe Onorato9c1289c2009-08-17 11:03:03 -04003006 mSavedState = null;
3007 }
3008
3009 if (mSavedInstanceState != null) {
3010 super.onRestoreInstanceState(mSavedInstanceState);
3011 mSavedInstanceState = null;
3012 }
3013
Joe Onorato9c1289c2009-08-17 11:03:03 -04003014 mWorkspaceLoading = false;
3015 }
3016
3017 /**
3018 * Add the icons for all apps.
3019 *
3020 * Implementation of the method from LauncherModel.Callbacks.
3021 */
3022 public void bindAllApplications(ArrayList<ApplicationInfo> apps) {
Romain Guy84f296c2009-11-04 15:00:44 -08003023 mAllAppsGrid.setApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003024 if (mCustomizePagedView != null) {
3025 mCustomizePagedView.setApps(apps);
3026 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003027 updateAppMarketIcon();
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003028 updateGlobalSearchIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003029 }
3030
3031 /**
3032 * A package was installed.
3033 *
3034 * Implementation of the method from LauncherModel.Callbacks.
3035 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003036 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003037 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onoratoa8138d52009-10-06 19:25:30 -07003038 mAllAppsGrid.addApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003039 if (mCustomizePagedView != null) {
3040 mCustomizePagedView.addApps(apps);
3041 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003042 updateAppMarketIcon();
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003043 updateGlobalSearchIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003044 }
3045
3046 /**
3047 * A package was updated.
3048 *
3049 * Implementation of the method from LauncherModel.Callbacks.
3050 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003051 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003052 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato64e6be72010-03-05 15:05:52 -05003053 mWorkspace.updateShortcuts(apps);
3054 mAllAppsGrid.updateApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003055 if (mCustomizePagedView != null) {
3056 mCustomizePagedView.updateApps(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 uninstalled.
3064 *
3065 * Implementation of the method from LauncherModel.Callbacks.
3066 */
Joe Onorato36115782010-06-17 13:28:48 -04003067 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003068 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato36115782010-06-17 13:28:48 -04003069 if (permanent) {
3070 mWorkspace.removeItems(apps);
3071 }
Joe Onoratoa8138d52009-10-06 19:25:30 -07003072 mAllAppsGrid.removeApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003073 if (mCustomizePagedView != null) {
3074 mCustomizePagedView.removeApps(apps);
3075 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003076 updateAppMarketIcon();
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003077 updateGlobalSearchIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003078 }
Joe Onoratobe386092009-11-17 17:32:16 -08003079
3080 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003081 * A number of packages were updated.
3082 */
3083 public void bindPackagesUpdated() {
3084 // update the customization drawer contents
Winson Chung5f941722010-09-28 16:36:43 -07003085 if (mCustomizePagedView != null) {
Winson Chungb3347bb2010-08-19 14:51:28 -07003086 mCustomizePagedView.update();
Winson Chung5f941722010-09-28 16:36:43 -07003087 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003088 }
3089
3090 /**
Joe Onoratobe386092009-11-17 17:32:16 -08003091 * Prints out out state for debugging.
3092 */
3093 public void dumpState() {
3094 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08003095 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08003096 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
3097 Log.d(TAG, "mRestoring=" + mRestoring);
3098 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
3099 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
3100 Log.d(TAG, "mDesktopItems.size=" + mDesktopItems.size());
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003101 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08003102 mModel.dumpState();
3103 mAllAppsGrid.dumpState();
3104 Log.d(TAG, "END launcher2 dump state");
3105 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003106}