blob: f5a5935436934737bdae726778d99f56fd53680a [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);
Winson Chung58f20882010-10-01 13:44:56 -07001487 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application));
Joe Onorato4a79a042010-09-24 16:17:21 -07001488 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001489 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001490 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001491 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001492 }
1493
Winson Chung24ab2f12010-09-16 14:10:47 -07001494 void processWallpaper(Intent intent) {
1495 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1496 }
1497
Michael Jurka0280c3b2010-09-17 15:00:07 -07001498 void addLiveFolderFromDrop(ComponentName componentName, int screen, int[] position) {
1499 resetAddInfo();
1500 mAddScreen = screen;
1501 mAddDropPosition = position;
1502
1503 Intent createFolderIntent = new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER);
1504 createFolderIntent.setComponent(componentName);
1505
1506 addLiveFolder(createFolderIntent);
1507 }
1508
1509 void addLiveFolder(Intent intent) { // YYY add screen intersect etc. parameters here
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001510 // Handle case where user selected "Folder"
Jeffrey Sharkeyc4bbd0a2009-03-24 22:47:52 -07001511 String folderName = getResources().getString(R.string.group_folder);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001512 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001513
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001514 if (folderName != null && folderName.equals(shortcutName)) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001515 addFolder(mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001516 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001517 startActivityForResultSafely(intent, REQUEST_CREATE_LIVE_FOLDER);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001518 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001519 }
1520
Michael Jurka0280c3b2010-09-17 15:00:07 -07001521 void addFolder(int screen, int intersectCellX, int intersectCellY) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001522 UserFolderInfo folderInfo = new UserFolderInfo();
1523 folderInfo.title = getText(R.string.folder_name);
1524
Michael Jurka0280c3b2010-09-17 15:00:07 -07001525 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1526 final int[] cellXY = mTmpAddItemCellCoordinates;
1527 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1528 showOutOfSpaceMessage();
1529 return;
1530 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001531
1532 // Update the model
Joe Onorato9c1289c2009-08-17 11:03:03 -04001533 LauncherModel.addItemToDatabase(this, folderInfo,
1534 LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001535 screen, cellXY[0], cellXY[1], false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001536 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001537
1538 // Create the view
1539 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07001540 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), folderInfo);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001541 mWorkspace.addInScreen(newFolder, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001542 }
Romain Guycbb89e42009-06-08 15:52:54 -07001543
Joe Onorato9c1289c2009-08-17 11:03:03 -04001544 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001545 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001546 }
1547
Michael Jurka28750fb2010-09-24 17:43:49 -07001548 private void completeAddLiveFolder(
1549 Intent data, int screen, int intersectCellX, int intersectCellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001550 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1551 final int[] cellXY = mTmpAddItemCellCoordinates;
1552 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1553 showOutOfSpaceMessage();
1554 return;
1555 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001556
Michael Jurka0280c3b2010-09-17 15:00:07 -07001557 final LiveFolderInfo info = addLiveFolder(this, data, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001558
1559 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001560 final View view = LiveFolderIcon.fromXml(R.layout.live_folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07001561 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001562 mWorkspace.addInScreen(view, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001563 }
1564 }
1565
1566 static LiveFolderInfo addLiveFolder(Context context, Intent data,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001567 int screen, int cellX, int cellY, boolean notify) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001568
1569 Intent baseIntent = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT);
1570 String name = data.getStringExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME);
1571
1572 Drawable icon = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001573 Intent.ShortcutIconResource iconResource = null;
1574
1575 Parcelable extra = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON);
1576 if (extra != null && extra instanceof Intent.ShortcutIconResource) {
1577 try {
1578 iconResource = (Intent.ShortcutIconResource) extra;
1579 final PackageManager packageManager = context.getPackageManager();
1580 Resources resources = packageManager.getResourcesForApplication(
1581 iconResource.packageName);
1582 final int id = resources.getIdentifier(iconResource.resourceName, null, null);
1583 icon = resources.getDrawable(id);
1584 } catch (Exception e) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001585 Log.w(TAG, "Could not load live folder icon: " + extra);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001586 }
1587 }
1588
1589 if (icon == null) {
1590 icon = context.getResources().getDrawable(R.drawable.ic_launcher_folder);
1591 }
1592
1593 final LiveFolderInfo info = new LiveFolderInfo();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001594 info.icon = Utilities.createIconBitmap(icon, context);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001595 info.title = name;
1596 info.iconResource = iconResource;
1597 info.uri = data.getData();
1598 info.baseIntent = baseIntent;
1599 info.displayMode = data.getIntExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE,
1600 LiveFolders.DISPLAY_MODE_GRID);
1601
1602 LauncherModel.addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001603 screen, cellX, cellY, notify);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001604 sFolders.put(info.id, info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001605
1606 return info;
1607 }
1608
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001609 private void showNotifications() {
1610 final StatusBarManager statusBar = (StatusBarManager) getSystemService(STATUS_BAR_SERVICE);
1611 if (statusBar != null) {
1612 statusBar.expand();
1613 }
1614 }
1615
1616 private void startWallpaper() {
Joe Onoratoe6168662009-11-08 13:39:30 -05001617 closeAllApps(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001618 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001619 Intent chooser = Intent.createChooser(pickWallpaper,
1620 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001621 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1622 // Removed in Eclair MR1
1623// WallpaperManager wm = (WallpaperManager)
1624// getSystemService(Context.WALLPAPER_SERVICE);
1625// WallpaperInfo wi = wm.getWallpaperInfo();
1626// if (wi != null && wi.getSettingsActivity() != null) {
1627// LabeledIntent li = new LabeledIntent(getPackageName(),
1628// R.string.configure_wallpaper, 0);
1629// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1630// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1631// }
Mike Clerona0618e42009-10-22 13:55:21 -07001632 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001633 }
1634
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001635 /**
1636 * Registers various content observers. The current implementation registers
1637 * only a favorites observer to keep track of the favorites applications.
1638 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001639 private void registerContentObservers() {
1640 ContentResolver resolver = getContentResolver();
1641 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1642 true, mWidgetObserver);
1643 }
1644
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001645 @Override
1646 public boolean dispatchKeyEvent(KeyEvent event) {
1647 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1648 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001649 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001650 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001651 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jason Samseb5615d2009-11-30 11:50:10 -08001652 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
Joe Onoratobe386092009-11-17 17:32:16 -08001653 dumpState();
1654 return true;
1655 }
1656 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001657 }
1658 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1659 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001660 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001661 return true;
1662 }
1663 }
1664
1665 return super.dispatchKeyEvent(event);
1666 }
1667
Joe Onorato88ec0992009-11-19 13:16:06 -08001668 @Override
1669 public void onBackPressed() {
1670 if (isAllAppsVisible()) {
1671 closeAllApps(true);
Patrick Dubroy558654c2010-07-23 16:48:11 -07001672 } else if (isCustomizationDrawerVisible()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07001673 hideCustomizationDrawer(true);
Joe Onorato88ec0992009-11-19 13:16:06 -08001674 } else {
1675 closeFolder();
1676 }
Michael Jurkaaf442092010-06-10 17:01:57 -07001677 // Some launcher layouts don't have a previous and next view
1678 if (mPreviousView != null) {
1679 dismissPreview(mPreviousView);
1680 dismissPreview(mNextView);
1681 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001682 }
1683
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001684 private void closeFolder() {
1685 Folder folder = mWorkspace.getOpenFolder();
1686 if (folder != null) {
1687 closeFolder(folder);
1688 }
1689 }
1690
1691 void closeFolder(Folder folder) {
1692 folder.getInfo().opened = false;
1693 ViewGroup parent = (ViewGroup) folder.getParent();
1694 if (parent != null) {
1695 parent.removeView(folder);
Joe Onoratob6341e92009-11-02 10:41:48 -05001696 if (folder instanceof DropTarget) {
1697 // Live folders aren't DropTargets.
1698 mDragController.removeDropTarget((DropTarget)folder);
1699 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001700 }
1701 folder.onClose();
1702 }
1703
1704 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001705 * Re-listen when widgets are reset.
1706 */
1707 private void onAppWidgetReset() {
1708 mAppWidgetHost.startListening();
1709 }
1710
1711 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001712 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1713 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001714 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04001715 private void unbindDesktopItems() {
1716 for (ItemInfo item: mDesktopItems) {
1717 item.unbind();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001718 }
1719 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001720
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001721 /**
1722 * Launches the intent referred by the clicked shortcut.
1723 *
1724 * @param v The view representing the clicked shortcut.
1725 */
1726 public void onClick(View v) {
1727 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001728 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001729 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08001730 final Intent intent = ((ShortcutInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001731 int[] pos = new int[2];
1732 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08001733 intent.setSourceBounds(new Rect(pos[0], pos[1],
1734 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Joe Onoratof984e852010-03-25 09:47:45 -07001735 startActivitySafely(intent, tag);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001736 } else if (tag instanceof FolderInfo) {
1737 handleFolderClick((FolderInfo) tag);
Joe Onorato7404ee42009-07-31 11:54:44 -07001738 } else if (v == mHandleView) {
Joe Onoratofb0ca672009-09-14 17:55:46 -04001739 if (isAllAppsVisible()) {
Joe Onorato7bb17492009-09-24 17:51:01 -07001740 closeAllApps(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001741 } else {
Joe Onorato3a8820b2009-11-10 15:06:42 -08001742 showAllApps(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001743 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001744 }
1745 }
1746
Michael Jurka0e260592010-06-30 17:07:39 -07001747 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07001748 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurka0e260592010-06-30 17:07:39 -07001749 // clicking anywhere on the workspace causes the drawer to slide down
Patrick Dubroy6b509c12010-08-23 15:08:16 -07001750 hideCustomizationDrawer(true);
Michael Jurka0e260592010-06-30 17:07:39 -07001751 return false;
1752 }
1753
Michael Jurkaaf442092010-06-10 17:01:57 -07001754 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001755 * Event handler for the search button
1756 *
1757 * @param v The view that was clicked.
1758 */
1759 public void onClickSearchButton(View v) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07001760 startSearch(null, false, null, true);
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001761 }
1762
1763 /**
1764 * Event handler for the "gear" button that appears on the home screen, which
Michael Jurkaaf442092010-06-10 17:01:57 -07001765 * enters home screen customization mode.
1766 *
1767 * @param v The view that was clicked.
1768 */
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001769 public void onClickConfigureButton(View v) {
Patrick Dubroy558654c2010-07-23 16:48:11 -07001770 addItems();
Michael Jurkaaf442092010-06-10 17:01:57 -07001771 }
1772
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001773 /**
1774 * Event handler for the "grid" button that appears on the home screen, which
1775 * enters all apps mode.
1776 *
1777 * @param v The view that was clicked.
1778 */
1779 public void onClickAllAppsButton(View v) {
1780 showAllApps(true);
1781 }
1782
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001783 public void onClickAppMarketButton(View v) {
1784 if (mAppMarketIntent != null) {
1785 startActivitySafely(mAppMarketIntent, "app market");
1786 }
1787 }
1788
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001789 void startApplicationDetailsActivity(ComponentName componentName) {
1790 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001791 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
1792 Uri.fromParts("package", packageName, null));
1793 startActivity(intent);
1794 }
1795
Patrick Dubroy5539af72010-09-07 15:22:01 -07001796 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
1797 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
1798 // System applications cannot be installed. For now, show a toast explaining that.
1799 // We may give them the option of disabling apps this way.
1800 int messageId = R.string.uninstall_system_app_text;
1801 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
1802 } else {
1803 String packageName = appInfo.componentName.getPackageName();
1804 String className = appInfo.componentName.getClassName();
1805 Intent intent = new Intent(
1806 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
1807 startActivity(intent);
1808 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001809 }
1810
Joe Onoratof984e852010-03-25 09:47:45 -07001811 void startActivitySafely(Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001812 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1813 try {
1814 startActivity(intent);
1815 } catch (ActivityNotFoundException e) {
1816 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Daniel Sandlerc9b18772010-04-22 14:37:59 -04001817 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001818 } catch (SecurityException e) {
1819 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001820 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001821 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07001822 "or use the exported attribute for this activity. "
1823 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001824 }
1825 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001826
Romain Guy8e633c52010-03-04 12:51:36 -08001827 void startActivityForResultSafely(Intent intent, int requestCode) {
1828 try {
1829 startActivityForResult(intent, requestCode);
1830 } catch (ActivityNotFoundException e) {
1831 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1832 } catch (SecurityException e) {
1833 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1834 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
1835 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
1836 "or use the exported attribute for this activity.", e);
1837 }
1838 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001839
1840 private void handleFolderClick(FolderInfo folderInfo) {
1841 if (!folderInfo.opened) {
1842 // Close any open folder
1843 closeFolder();
1844 // Open the requested folder
1845 openFolder(folderInfo);
1846 } else {
1847 // Find the open folder...
1848 Folder openFolder = mWorkspace.getFolderForTag(folderInfo);
1849 int folderScreen;
1850 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07001851 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001852 // .. and close it
1853 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07001854 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001855 // Close any folder open on the current screen
1856 closeFolder();
1857 // Pull the folder onto this screen
1858 openFolder(folderInfo);
1859 }
1860 }
1861 }
1862 }
1863
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001864 /**
1865 * Opens the user fodler described by the specified tag. The opening of the folder
1866 * is animated relative to the specified View. If the View is null, no animation
1867 * is played.
1868 *
1869 * @param folderInfo The FolderInfo describing the folder to open.
1870 */
Winson Chungaafa03c2010-06-11 17:34:16 -07001871 public void openFolder(FolderInfo folderInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001872 Folder openFolder;
1873
1874 if (folderInfo instanceof UserFolderInfo) {
1875 openFolder = UserFolder.fromXml(this);
1876 } else if (folderInfo instanceof LiveFolderInfo) {
Joe Onoratoa5902522009-07-30 13:37:37 -07001877 openFolder = com.android.launcher2.LiveFolder.fromXml(this, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001878 } else {
1879 return;
1880 }
1881
Joe Onorato00acb122009-08-04 16:04:30 -04001882 openFolder.setDragController(mDragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001883 openFolder.setLauncher(this);
1884
1885 openFolder.bind(folderInfo);
1886 folderInfo.opened = true;
1887
Winson Chungaafa03c2010-06-11 17:34:16 -07001888 mWorkspace.addInFullScreen(openFolder, folderInfo.screen);
1889
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001890 openFolder.onOpen();
1891 }
1892
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001893 public boolean onLongClick(View v) {
Romain Guy1fbc1c82009-11-09 20:43:08 -08001894 switch (v.getId()) {
1895 case R.id.previous_screen:
Joe Onorato0d44e942009-11-16 18:20:51 -08001896 if (!isAllAppsVisible()) {
1897 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1898 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Romain Guyf8e6a802009-12-07 17:48:02 -08001899 showPreviews(v);
Joe Onorato0d44e942009-11-16 18:20:51 -08001900 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08001901 return true;
1902 case R.id.next_screen:
Joe Onorato0d44e942009-11-16 18:20:51 -08001903 if (!isAllAppsVisible()) {
1904 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1905 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Romain Guyf8e6a802009-12-07 17:48:02 -08001906 showPreviews(v);
1907 }
1908 return true;
1909 case R.id.all_apps_button:
1910 if (!isAllAppsVisible()) {
1911 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1912 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
1913 showPreviews(v);
Joe Onorato0d44e942009-11-16 18:20:51 -08001914 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08001915 return true;
1916 }
1917
Joe Onorato9c1289c2009-08-17 11:03:03 -04001918 if (isWorkspaceLocked()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001919 return false;
1920 }
1921
1922 if (!(v instanceof CellLayout)) {
1923 v = (View) v.getParent();
1924 }
1925
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001926
Michael Jurka0280c3b2010-09-17 15:00:07 -07001927 resetAddInfo();
1928 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001929 // This happens when long clicking an item with the dpad/trackball
Michael Jurka0280c3b2010-09-17 15:00:07 -07001930 if (longClickCellInfo == null || !longClickCellInfo.valid) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001931 return true;
1932 }
1933
Michael Jurka0280c3b2010-09-17 15:00:07 -07001934 final View itemUnderLongClick = longClickCellInfo.cell;
1935
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001936 if (mWorkspace.allowLongPress()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001937 if (itemUnderLongClick == null) {
1938 // User long pressed on empty space
1939 mWorkspace.setAllowLongPress(false);
1940 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1941 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Michael Jurka56170562010-10-05 14:14:56 -07001942 if (!LauncherApplication.isScreenXLarge()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001943 showAddDialog(longClickCellInfo.cellX, longClickCellInfo.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001944 }
1945 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001946 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001947 // User long pressed on an item
Joe Onorato0d44e942009-11-16 18:20:51 -08001948 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1949 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001950 mAddIntersectCellX = longClickCellInfo.cellX;
1951 mAddIntersectCellY = longClickCellInfo.cellY;
1952 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001953 }
1954 }
1955 }
1956 return true;
1957 }
1958
Romain Guye6b8e2f2009-11-10 11:56:55 -08001959 @SuppressWarnings({"unchecked"})
Romain Guy9d31e9f2009-11-11 18:54:28 -08001960 private void dismissPreview(final View v) {
1961 final PopupWindow window = (PopupWindow) v.getTag();
Romain Guy1fbc1c82009-11-09 20:43:08 -08001962 if (window != null) {
Romain Guy9d31e9f2009-11-11 18:54:28 -08001963 window.setOnDismissListener(new PopupWindow.OnDismissListener() {
1964 public void onDismiss() {
1965 ViewGroup group = (ViewGroup) v.getTag(R.id.workspace);
1966 int count = group.getChildCount();
1967 for (int i = 0; i < count; i++) {
1968 ((ImageView) group.getChildAt(i)).setImageDrawable(null);
1969 }
Romain Guy9d31e9f2009-11-11 18:54:28 -08001970 ArrayList<Bitmap> bitmaps = (ArrayList<Bitmap>) v.getTag(R.id.icon);
1971 for (Bitmap bitmap : bitmaps) bitmap.recycle();
1972
1973 v.setTag(R.id.workspace, null);
1974 v.setTag(R.id.icon, null);
1975 window.setOnDismissListener(null);
1976 }
1977 });
Romain Guy1fbc1c82009-11-09 20:43:08 -08001978 window.dismiss();
Romain Guy1fbc1c82009-11-09 20:43:08 -08001979 }
1980 v.setTag(null);
1981 }
1982
Romain Guyf8e6a802009-12-07 17:48:02 -08001983 private void showPreviews(View anchor) {
Romain Guy9d31e9f2009-11-11 18:54:28 -08001984 showPreviews(anchor, 0, mWorkspace.getChildCount());
Romain Guy1fbc1c82009-11-09 20:43:08 -08001985 }
1986
Romain Guya6abce82009-11-10 02:54:41 -08001987 private void showPreviews(final View anchor, int start, int end) {
Romain Guyf8e6a802009-12-07 17:48:02 -08001988 final Resources resources = getResources();
1989 final Workspace workspace = mWorkspace;
Romain Guy1fbc1c82009-11-09 20:43:08 -08001990
Romain Guya6abce82009-11-10 02:54:41 -08001991 CellLayout cell = ((CellLayout) workspace.getChildAt(start));
Winson Chungaafa03c2010-06-11 17:34:16 -07001992
Romain Guy9d31e9f2009-11-11 18:54:28 -08001993 float max = workspace.getChildCount();
Winson Chungaafa03c2010-06-11 17:34:16 -07001994
Romain Guyf8e6a802009-12-07 17:48:02 -08001995 final Rect r = new Rect();
Romain Guy9d31e9f2009-11-11 18:54:28 -08001996 resources.getDrawable(R.drawable.preview_background).getPadding(r);
Romain Guye6b8e2f2009-11-10 11:56:55 -08001997 int extraW = (int) ((r.left + r.right) * max);
1998 int extraH = r.top + r.bottom;
Romain Guya6abce82009-11-10 02:54:41 -08001999
2000 int aW = cell.getWidth() - extraW;
2001 float w = aW / max;
2002
2003 int width = cell.getWidth();
2004 int height = cell.getHeight();
2005 int x = cell.getLeftPadding();
2006 int y = cell.getTopPadding();
2007 width -= (x + cell.getRightPadding());
2008 height -= (y + cell.getBottomPadding());
2009
2010 float scale = w / width;
2011
2012 int count = end - start;
2013
2014 final float sWidth = width * scale;
2015 float sHeight = height * scale;
2016
Romain Guye6b8e2f2009-11-10 11:56:55 -08002017 LinearLayout preview = new LinearLayout(this);
Romain Guya6abce82009-11-10 02:54:41 -08002018
Romain Guye6b8e2f2009-11-10 11:56:55 -08002019 PreviewTouchHandler handler = new PreviewTouchHandler(anchor);
2020 ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>(count);
Romain Guya6abce82009-11-10 02:54:41 -08002021
2022 for (int i = start; i < end; i++) {
Romain Guye6b8e2f2009-11-10 11:56:55 -08002023 ImageView image = new ImageView(this);
Romain Guya6abce82009-11-10 02:54:41 -08002024 cell = (CellLayout) workspace.getChildAt(i);
2025
Romain Guyf8e6a802009-12-07 17:48:02 -08002026 final Bitmap bitmap = Bitmap.createBitmap((int) sWidth, (int) sHeight,
Romain Guye6b8e2f2009-11-10 11:56:55 -08002027 Bitmap.Config.ARGB_8888);
Romain Guyf8e6a802009-12-07 17:48:02 -08002028
2029 final Canvas c = new Canvas(bitmap);
Romain Guya6abce82009-11-10 02:54:41 -08002030 c.scale(scale, scale);
2031 c.translate(-cell.getLeftPadding(), -cell.getTopPadding());
Patrick Dubroy1262e362010-10-06 15:49:50 -07002032 cell.drawChildren(c);
Romain Guya6abce82009-11-10 02:54:41 -08002033
Romain Guy9d31e9f2009-11-11 18:54:28 -08002034 image.setBackgroundDrawable(resources.getDrawable(R.drawable.preview_background));
Romain Guye6b8e2f2009-11-10 11:56:55 -08002035 image.setImageBitmap(bitmap);
2036 image.setTag(i);
2037 image.setOnClickListener(handler);
Romain Guy9d31e9f2009-11-11 18:54:28 -08002038 image.setOnFocusChangeListener(handler);
2039 image.setFocusable(true);
Michael Jurka0142d492010-08-25 17:46:15 -07002040 if (i == mWorkspace.getCurrentPage()) image.requestFocus();
Romain Guye6b8e2f2009-11-10 11:56:55 -08002041
2042 preview.addView(image,
Romain Guy9d31e9f2009-11-11 18:54:28 -08002043 LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
2044
Winson Chungaafa03c2010-06-11 17:34:16 -07002045 bitmaps.add(bitmap);
Romain Guya6abce82009-11-10 02:54:41 -08002046 }
Romain Guyf8e6a802009-12-07 17:48:02 -08002047
2048 final PopupWindow p = new PopupWindow(this);
Romain Guye6b8e2f2009-11-10 11:56:55 -08002049 p.setContentView(preview);
2050 p.setWidth((int) (sWidth * count + extraW));
2051 p.setHeight((int) (sHeight + extraH));
2052 p.setAnimationStyle(R.style.AnimationPreview);
2053 p.setOutsideTouchable(true);
Romain Guy9d31e9f2009-11-11 18:54:28 -08002054 p.setFocusable(true);
Romain Guyff0c2e22009-11-10 12:09:59 -08002055 p.setBackgroundDrawable(new ColorDrawable(0));
Romain Guy9d31e9f2009-11-11 18:54:28 -08002056 p.showAsDropDown(anchor, 0, 0);
Romain Guya6abce82009-11-10 02:54:41 -08002057
Romain Guye6b8e2f2009-11-10 11:56:55 -08002058 p.setOnDismissListener(new PopupWindow.OnDismissListener() {
2059 public void onDismiss() {
2060 dismissPreview(anchor);
2061 }
2062 });
Romain Guy1fbc1c82009-11-09 20:43:08 -08002063
2064 anchor.setTag(p);
2065 anchor.setTag(R.id.workspace, preview);
Winson Chungaafa03c2010-06-11 17:34:16 -07002066 anchor.setTag(R.id.icon, bitmaps);
Romain Guy1fbc1c82009-11-09 20:43:08 -08002067 }
2068
Romain Guy9d31e9f2009-11-11 18:54:28 -08002069 class PreviewTouchHandler implements View.OnClickListener, Runnable, View.OnFocusChangeListener {
Romain Guya6abce82009-11-10 02:54:41 -08002070 private final View mAnchor;
Romain Guya6abce82009-11-10 02:54:41 -08002071
Romain Guye6b8e2f2009-11-10 11:56:55 -08002072 public PreviewTouchHandler(View anchor) {
Romain Guya6abce82009-11-10 02:54:41 -08002073 mAnchor = anchor;
Romain Guya6abce82009-11-10 02:54:41 -08002074 }
2075
2076 public void onClick(View v) {
Michael Jurka0142d492010-08-25 17:46:15 -07002077 mWorkspace.snapToPage((Integer) v.getTag());
Romain Guy9d31e9f2009-11-11 18:54:28 -08002078 v.post(this);
2079 }
2080
2081 public void run() {
Winson Chungaafa03c2010-06-11 17:34:16 -07002082 dismissPreview(mAnchor);
Romain Guy9d31e9f2009-11-11 18:54:28 -08002083 }
2084
2085 public void onFocusChange(View v, boolean hasFocus) {
2086 if (hasFocus) {
Michael Jurka0142d492010-08-25 17:46:15 -07002087 mWorkspace.snapToPage((Integer) v.getTag());
Romain Guy9d31e9f2009-11-11 18:54:28 -08002088 }
Romain Guya6abce82009-11-10 02:54:41 -08002089 }
2090 }
2091
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002092 Workspace getWorkspace() {
2093 return mWorkspace;
2094 }
2095
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002096 @Override
2097 protected Dialog onCreateDialog(int id) {
2098 switch (id) {
2099 case DIALOG_CREATE_SHORTCUT:
2100 return new CreateShortcut().createDialog();
2101 case DIALOG_RENAME_FOLDER:
2102 return new RenameFolder().createDialog();
2103 }
2104
2105 return super.onCreateDialog(id);
2106 }
2107
2108 @Override
2109 protected void onPrepareDialog(int id, Dialog dialog) {
2110 switch (id) {
2111 case DIALOG_CREATE_SHORTCUT:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002112 break;
2113 case DIALOG_RENAME_FOLDER:
Romain Guy7b4ef332009-07-14 13:58:08 -07002114 if (mFolderInfo != null) {
2115 EditText input = (EditText) dialog.findViewById(R.id.folder_name);
2116 final CharSequence text = mFolderInfo.title;
2117 input.setText(text);
2118 input.setSelection(0, text.length());
2119 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002120 break;
2121 }
2122 }
2123
2124 void showRenameDialog(FolderInfo info) {
2125 mFolderInfo = info;
2126 mWaitingForResult = true;
2127 showDialog(DIALOG_RENAME_FOLDER);
2128 }
2129
Michael Jurka0280c3b2010-09-17 15:00:07 -07002130 private void showAddDialog(int intersectX, int intersectY) {
2131 resetAddInfo();
2132 mAddIntersectCellX = intersectX;
2133 mAddIntersectCellY = intersectY;
2134 mAddScreen = mWorkspace.getCurrentPage();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002135 mWaitingForResult = true;
2136 showDialog(DIALOG_CREATE_SHORTCUT);
2137 }
2138
Joe Onoratodeb98af2010-02-19 14:59:39 -08002139 private void pickShortcut() {
Michael Jurka0e260592010-06-30 17:07:39 -07002140 // Insert extra item to handle picking application
Romain Guy73b979d2009-06-09 12:57:21 -07002141 Bundle bundle = new Bundle();
2142
2143 ArrayList<String> shortcutNames = new ArrayList<String>();
2144 shortcutNames.add(getString(R.string.group_applications));
2145 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
2146
2147 ArrayList<ShortcutIconResource> shortcutIcons = new ArrayList<ShortcutIconResource>();
2148 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
2149 R.drawable.ic_launcher_application));
2150 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
2151
2152 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2153 pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_CREATE_SHORTCUT));
Joe Onoratodeb98af2010-02-19 14:59:39 -08002154 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_shortcut));
Romain Guy73b979d2009-06-09 12:57:21 -07002155 pickIntent.putExtras(bundle);
2156
Joe Onoratodeb98af2010-02-19 14:59:39 -08002157 startActivityForResult(pickIntent, REQUEST_PICK_SHORTCUT);
Romain Guy73b979d2009-06-09 12:57:21 -07002158 }
2159
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002160 private class RenameFolder {
2161 private EditText mInput;
2162
2163 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002164 final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null);
2165 mInput = (EditText) layout.findViewById(R.id.folder_name);
2166
2167 AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
2168 builder.setIcon(0);
2169 builder.setTitle(getString(R.string.rename_folder_title));
2170 builder.setCancelable(true);
2171 builder.setOnCancelListener(new Dialog.OnCancelListener() {
2172 public void onCancel(DialogInterface dialog) {
2173 cleanup();
2174 }
2175 });
2176 builder.setNegativeButton(getString(R.string.cancel_action),
2177 new Dialog.OnClickListener() {
2178 public void onClick(DialogInterface dialog, int which) {
2179 cleanup();
2180 }
2181 }
2182 );
2183 builder.setPositiveButton(getString(R.string.rename_action),
2184 new Dialog.OnClickListener() {
2185 public void onClick(DialogInterface dialog, int which) {
2186 changeFolderName();
2187 }
2188 }
2189 );
2190 builder.setView(layout);
Romain Guy7b4ef332009-07-14 13:58:08 -07002191
2192 final AlertDialog dialog = builder.create();
2193 dialog.setOnShowListener(new DialogInterface.OnShowListener() {
2194 public void onShow(DialogInterface dialog) {
Joe Onorato7018d8e2010-04-13 20:25:47 -07002195 mWaitingForResult = true;
Joe Onoratod753b422009-11-08 13:31:11 -05002196 mInput.requestFocus();
2197 InputMethodManager inputManager = (InputMethodManager)
2198 getSystemService(Context.INPUT_METHOD_SERVICE);
2199 inputManager.showSoftInput(mInput, 0);
Romain Guy7b4ef332009-07-14 13:58:08 -07002200 }
2201 });
2202
2203 return dialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002204 }
2205
2206 private void changeFolderName() {
2207 final String name = mInput.getText().toString();
2208 if (!TextUtils.isEmpty(name)) {
2209 // Make sure we have the right folder info
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002210 mFolderInfo = sFolders.get(mFolderInfo.id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002211 mFolderInfo.title = name;
2212 LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo);
2213
Joe Onorato9c1289c2009-08-17 11:03:03 -04002214 if (mWorkspaceLoading) {
Joe Onorato7c312c12009-08-13 21:36:53 -07002215 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002216 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002217 } else {
2218 final FolderIcon folderIcon = (FolderIcon)
2219 mWorkspace.getViewForTag(mFolderInfo);
2220 if (folderIcon != null) {
2221 folderIcon.setText(name);
2222 getWorkspace().requestLayout();
2223 } else {
Joe Onorato7c312c12009-08-13 21:36:53 -07002224 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002225 mWorkspaceLoading = true;
2226 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002227 }
2228 }
2229 }
2230 cleanup();
2231 }
2232
2233 private void cleanup() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002234 dismissDialog(DIALOG_RENAME_FOLDER);
2235 mWaitingForResult = false;
2236 mFolderInfo = null;
2237 }
2238 }
2239
Daniel Sandler843e8602010-06-07 14:59:01 -04002240 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
2241 public boolean isAllAppsVisible() {
Romain Guy5bbc91b2010-08-18 11:38:46 -07002242 return mAllAppsGrid != null && mAllAppsGrid.isVisible();
Joe Onoratofb0ca672009-09-14 17:55:46 -04002243 }
2244
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002245 // AllAppsView.Watcher
2246 public void zoomed(float zoom) {
Michael Jurka213d9632010-07-28 11:29:25 -07002247 // In XLarge view, we zoom down the workspace below all apps so it's still visible
2248 if (zoom == 1.0f && !LauncherApplication.isScreenXLarge()) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002249 mWorkspace.setVisibility(View.GONE);
2250 }
2251 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002252
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002253 private void showToolbarButton(View button) {
2254 button.setAlpha(1.0f);
2255 button.setVisibility(View.VISIBLE);
2256 button.setFocusable(true);
2257 button.setClickable(true);
2258 }
2259
2260 private void hideToolbarButton(View button) {
2261 button.setAlpha(0.0f);
2262 // We can't set it to GONE, otherwise the RelativeLayout gets screwed up
2263 button.setVisibility(View.INVISIBLE);
2264 button.setFocusable(false);
2265 button.setClickable(false);
2266 }
2267
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002268 /**
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002269 * Helper function for showing or hiding a toolbar button, possibly animated.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002270 *
2271 * @param show If true, create an animation to the show the item. Otherwise, hide it.
2272 * @param view The toolbar button to be animated
Chet Haaseb1254a62010-09-07 13:35:00 -07002273 * @param seq A AnimatorSet that will be used to animate the transition. If null, the
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002274 * transition will not be animated.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002275 */
Chet Haaseb1254a62010-09-07 13:35:00 -07002276 private void hideOrShowToolbarButton(boolean show, final View view, AnimatorSet seq) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002277 final boolean showing = show;
2278 final boolean hiding = !show;
2279
2280 final int duration = show ?
2281 getResources().getInteger(R.integer.config_toolbarButtonFadeInTime) :
2282 getResources().getInteger(R.integer.config_toolbarButtonFadeOutTime);
2283
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002284 if (seq != null) {
Chet Haaseb1254a62010-09-07 13:35:00 -07002285 Animator anim = new ObjectAnimator<Float>(duration, view, "alpha", show ? 1.0f : 0.0f);
2286 anim.addListener(new AnimatorListenerAdapter() {
2287 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002288 if (showing) showToolbarButton(view);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002289 }
Chet Haaseb1254a62010-09-07 13:35:00 -07002290 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002291 if (hiding) hideToolbarButton(view);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002292 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002293 });
2294 seq.play(anim);
2295 } else {
2296 if (showing) {
2297 showToolbarButton(view);
2298 } else {
2299 hideToolbarButton(view);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002300 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002301 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002302 }
2303
2304 /**
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002305 * Show/hide the appropriate toolbar buttons for newState.
2306 * If showSeq or hideSeq is null, the transition will be done immediately (not animated).
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002307 *
2308 * @param newState The state that is being switched to
Chet Haaseb1254a62010-09-07 13:35:00 -07002309 * @param showSeq AnimatorSet in which to put "show" animations, or null.
2310 * @param hideSeq AnimatorSet in which to put "hide" animations, or null.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002311 */
Chet Haaseb1254a62010-09-07 13:35:00 -07002312 private void hideAndShowToolbarButtons(State newState, AnimatorSet showSeq, AnimatorSet hideSeq) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002313 final View searchButton = findViewById(R.id.search_button);
2314 final View allAppsButton = findViewById(R.id.all_apps_button);
2315 final View marketButton = findViewById(R.id.market_button);
2316 final View configureButton = findViewById(R.id.configure_button);
2317
2318 switch (newState) {
2319 case WORKSPACE:
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002320 hideOrShowToolbarButton(true, searchButton, showSeq);
2321 hideOrShowToolbarButton(true, allAppsButton, showSeq);
2322 hideOrShowToolbarButton(true, configureButton, showSeq);
2323 hideOrShowToolbarButton(false, marketButton, hideSeq);
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002324 mDeleteZone.setHandle(allAppsButton);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002325 break;
2326 case ALL_APPS:
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002327 hideOrShowToolbarButton(true, configureButton, showSeq);
2328 hideOrShowToolbarButton(true, marketButton, showSeq);
2329 hideOrShowToolbarButton(false, searchButton, hideSeq);
2330 hideOrShowToolbarButton(false, allAppsButton, hideSeq);
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002331 mDeleteZone.setHandle(marketButton);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002332 break;
2333 case CUSTOMIZE:
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002334 hideOrShowToolbarButton(true, allAppsButton, showSeq);
2335 hideOrShowToolbarButton(false, searchButton, hideSeq);
2336 hideOrShowToolbarButton(false, marketButton, hideSeq);
2337 hideOrShowToolbarButton(false, configureButton, hideSeq);
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002338 mDeleteZone.setHandle(allAppsButton);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002339 break;
2340 }
2341 }
2342
2343 /**
2344 * Helper method for the cameraZoomIn/cameraZoomOut animations
2345 * @param view The view being animated
2346 * @param state The state that we are moving in or out of -- either ALL_APPS or CUSTOMIZE
2347 * @param scaleFactor The scale factor used for the zoom
2348 */
2349 private void setPivotsForZoom(View view, State state, float scaleFactor) {
2350 final int height = view.getHeight();
2351 view.setPivotX(view.getWidth() / 2.0f);
2352 // Set pivotY so that at the starting zoom factor, the view is off-screen by a small margin
2353 // Assumes that the view is normally anchored to either the top or bottom of the screen
2354 final int margin = getResources().getInteger(R.integer.config_allAppsVerticalOffset);
2355 if (state == State.ALL_APPS) {
2356 view.setPivotY(height + ((view.getTop() + height) / scaleFactor) + margin);
2357 } else {
2358 view.setPivotY(0.0f - (view.getTop() / scaleFactor) - margin);
2359 }
2360 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002361
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002362 /**
2363 * Zoom the camera out from the workspace to reveal 'toView'.
2364 * Assumes that the view to show is anchored at either the very top or very bottom
2365 * of the screen.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002366 * @param toState The state to zoom out to. Must be ALL_APPS or CUSTOMIZE.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002367 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002368 private void cameraZoomOut(State toState, boolean animated) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002369 final Resources res = getResources();
2370 final int duration = res.getInteger(R.integer.config_allAppsZoomInTime);
2371 final float scale = (float) res.getInteger(R.integer.config_allAppsZoomScaleFactor);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002372 final boolean toAllApps = (toState == State.ALL_APPS);
2373 final View toView = toAllApps ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
Patrick Dubroy558654c2010-07-23 16:48:11 -07002374
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002375 setPivotsForZoom(toView, toState, scale);
2376
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002377 if (toState == State.ALL_APPS) {
2378 mWorkspace.shrinkToBottom(animated);
2379 } else {
2380 mWorkspace.shrinkToTop(animated);
2381 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002382
2383 if (animated) {
Chet Haaseb1254a62010-09-07 13:35:00 -07002384 ValueAnimator scaleAnim = new ObjectAnimator(duration, toView,
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002385 new PropertyValuesHolder<Float>("scaleX", scale, 1.0f),
2386 new PropertyValuesHolder<Float>("scaleY", scale, 1.0f));
2387 scaleAnim.setInterpolator(new DecelerateInterpolator());
Chet Haaseb1254a62010-09-07 13:35:00 -07002388 scaleAnim.addListener(new AnimatorListenerAdapter() {
2389 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002390 // Prepare the position
2391 toView.setTranslationX(0.0f);
2392 toView.setTranslationY(0.0f);
2393 toView.setVisibility(View.VISIBLE);
2394 }
2395 });
2396
Chet Haaseb1254a62010-09-07 13:35:00 -07002397 AnimatorSet toolbarHideAnim = new AnimatorSet();
2398 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002399 hideAndShowToolbarButtons(toState, toolbarShowAnim, toolbarHideAnim);
2400
2401 // toView should appear right at the end of the workspace shrink animation
2402 final int startDelay = res.getInteger(R.integer.config_workspaceShrinkTime) - duration;
2403
Chet Haaseb1254a62010-09-07 13:35:00 -07002404 AnimatorSet s = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002405 s.playTogether(scaleAnim, toolbarHideAnim);
2406 s.play(scaleAnim).after(startDelay);
2407
2408 // Show the new toolbar buttons just as the main animation is ending
2409 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
2410 s.play(toolbarShowAnim).after(duration + startDelay - fadeInTime);
2411 s.start();
2412 } else {
2413 toView.setTranslationX(0.0f);
2414 toView.setTranslationY(0.0f);
2415 toView.setScaleX(1.0f);
2416 toView.setScaleY(1.0f);
2417 toView.setVisibility(View.VISIBLE);
2418 hideAndShowToolbarButtons(toState, null, null);
2419 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002420 }
2421
2422 /**
2423 * Zoom the camera back into the workspace, hiding 'fromView'.
2424 * This is the opposite of cameraZoomOut.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002425 * @param fromState The current state (must be ALL_APPS or CUSTOMIZE).
2426 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002427 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002428 private void cameraZoomIn(State fromState, boolean animated) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002429 Resources res = getResources();
2430 int duration = res.getInteger(R.integer.config_allAppsZoomOutTime);
2431 float scaleFactor = (float) res.getInteger(R.integer.config_allAppsZoomScaleFactor);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002432 final View fromView =
2433 (fromState == State.ALL_APPS) ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
2434
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002435 mCustomizePagedView.endChoiceMode();
2436 mAllAppsPagedView.endChoiceMode();
2437
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002438 setPivotsForZoom(fromView, fromState, scaleFactor);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002439
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002440 mWorkspace.unshrink(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002441
2442 if (animated) {
Chet Haaseb1254a62010-09-07 13:35:00 -07002443 AnimatorSet s = new AnimatorSet();
2444 ValueAnimator scaleAnim = new ObjectAnimator(duration, fromView,
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002445 new PropertyValuesHolder<Float>("scaleX", scaleFactor),
2446 new PropertyValuesHolder<Float>("scaleY", scaleFactor));
2447 scaleAnim.setInterpolator(new AccelerateInterpolator());
Chet Haaseb1254a62010-09-07 13:35:00 -07002448 s.addListener(new AnimatorListenerAdapter() {
2449 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002450 fromView.setVisibility(View.GONE);
2451 fromView.setScaleX(1.0f);
2452 fromView.setScaleY(1.0f);
2453 }
2454 });
2455
Chet Haaseb1254a62010-09-07 13:35:00 -07002456 AnimatorSet toolbarHideAnim = new AnimatorSet();
2457 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002458 hideAndShowToolbarButtons(State.WORKSPACE, toolbarShowAnim, toolbarHideAnim);
2459
2460 s.playTogether(scaleAnim, toolbarHideAnim);
2461
2462 // Show the new toolbar buttons at the very end of the whole animation
2463 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
2464 final int unshrinkTime = res.getInteger(R.integer.config_workspaceUnshrinkTime);
2465 s.play(toolbarShowAnim).after(unshrinkTime - fadeInTime);
2466 s.start();
2467 } else {
2468 fromView.setVisibility(View.GONE);
2469 hideAndShowToolbarButtons(State.WORKSPACE, null, null);
2470 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002471 }
2472
2473 /**
2474 * Pan the camera in the vertical plane between 'fromView' and 'toView'.
2475 * This is the transition used on xlarge screens to go between all apps and
2476 * the home customization drawer.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002477 * @param fromState The view to pan away from. Must be ALL_APPS or CUSTOMIZE.
2478 * @param toState The view to pan into the frame. Must be ALL_APPS or CUSTOMIZE.
2479 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002480 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002481 private void cameraPan(State fromState, State toState, boolean animated) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002482 final Resources res = getResources();
2483 final int duration = res.getInteger(R.integer.config_allAppsCameraPanTime);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002484 final int workspaceHeight = mWorkspace.getHeight();
2485
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002486 final boolean fromAllApps = (fromState == State.ALL_APPS);
2487 final View fromView = fromAllApps ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
2488 final View toView = fromAllApps ? mHomeCustomizationDrawer : (View) mAllAppsGrid;
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002489
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002490 final float fromViewStartY = fromAllApps ? 0.0f : fromView.getY();
2491 final float fromViewEndY = fromAllApps ? -fromView.getHeight() * 2 : workspaceHeight * 2;
2492 final float toViewStartY = fromAllApps ? workspaceHeight * 2 : -toView.getHeight() * 2;
2493 final float toViewEndY = fromAllApps ? workspaceHeight - toView.getHeight() : 0.0f;
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002494
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002495 mCustomizePagedView.endChoiceMode();
2496 mAllAppsPagedView.endChoiceMode();
2497
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002498 if (toState == State.ALL_APPS) {
2499 mWorkspace.shrinkToBottom(animated);
2500 } else {
2501 mWorkspace.shrinkToTop(animated);
2502 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002503
2504 if (animated) {
Chet Haaseb1254a62010-09-07 13:35:00 -07002505 AnimatorSet s = new AnimatorSet();
2506 s.addListener(new AnimatorListenerAdapter() {
2507 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002508 toView.setVisibility(View.VISIBLE);
2509 toView.setY(toViewStartY);
2510 }
Chet Haaseb1254a62010-09-07 13:35:00 -07002511 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002512 fromView.setVisibility(View.GONE);
2513 }
2514 });
2515
Chet Haaseb1254a62010-09-07 13:35:00 -07002516 AnimatorSet toolbarHideAnim = new AnimatorSet();
2517 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002518 hideAndShowToolbarButtons(toState, toolbarShowAnim, toolbarHideAnim);
2519
2520 s.playTogether(
2521 toolbarHideAnim,
Chet Haaseb1254a62010-09-07 13:35:00 -07002522 new ObjectAnimator(duration, fromView, "y", fromViewStartY, fromViewEndY),
2523 new ObjectAnimator(duration, toView, "y", toViewStartY, toViewEndY));
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002524
2525 // Show the new toolbar buttons just as the main animation is ending
2526 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
2527 s.play(toolbarShowAnim).after(duration - fadeInTime);
2528 s.start();
2529 } else {
2530 fromView.setY(fromViewEndY);
2531 fromView.setVisibility(View.GONE);
2532 toView.setY(toViewEndY);
2533 toView.setVisibility(View.VISIBLE);
2534 hideAndShowToolbarButtons(toState, null, null);
2535 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002536 }
2537
2538 void showAllApps(boolean animated) {
Winson Chung80baf5a2010-08-09 16:03:15 -07002539 if (mAllAppsGrid.isVisible())
2540 return;
2541
Michael Jurka79212d82010-07-30 16:36:20 -07002542 if (LauncherApplication.isScreenXLarge()) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002543 if (isCustomizationDrawerVisible()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002544 cameraPan(State.CUSTOMIZE, State.ALL_APPS, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002545 } else {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002546 cameraZoomOut(State.ALL_APPS, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002547 }
Patrick Dubroy558654c2010-07-23 16:48:11 -07002548 } else {
2549 mAllAppsGrid.zoom(1.0f, animated);
2550 }
Joe Onorato3a8820b2009-11-10 15:06:42 -08002551
Romain Guyc16fea72010-03-12 17:17:56 -08002552 ((View) mAllAppsGrid).setFocusable(true);
2553 ((View) mAllAppsGrid).requestFocus();
Winson Chungaafa03c2010-06-11 17:34:16 -07002554
Joe Onorato7c312c12009-08-13 21:36:53 -07002555 // TODO: fade these two too
2556 mDeleteZone.setVisibility(View.GONE);
Joe Onorato00acb122009-08-04 16:04:30 -04002557 }
2558
Joe Onoratob2061212009-11-24 16:13:54 -05002559 /**
Joe Onorato7e4ed992009-12-03 13:10:49 -08002560 * Things to test when changing this code.
Joe Onoratob2061212009-11-24 16:13:54 -05002561 * - Home from workspace
2562 * - from center screen
2563 * - from other screens
2564 * - Home from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002565 * - from center screen
2566 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002567 * - Back from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002568 * - from center screen
2569 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002570 * - Launch app from workspace and quit
2571 * - with back
2572 * - with home
2573 * - Launch app from all apps and quit
2574 * - with back
2575 * - with home
Joe Onorato7e4ed992009-12-03 13:10:49 -08002576 * - Go to a screen that's not the default, then all
2577 * apps, and launch and app, and go back
2578 * - with back
2579 * -with home
Joe Onoratob2061212009-11-24 16:13:54 -05002580 * - On workspace, long press power and go back
2581 * - with back
2582 * - with home
2583 * - On all apps, long press power and go back
2584 * - with back
2585 * - with home
2586 * - On workspace, power off
2587 * - On all apps, power off
Joe Onorato7e4ed992009-12-03 13:10:49 -08002588 * - Launch an app and turn off the screen while in that app
2589 * - Go back with home key
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002590 * - Go back with back key TODO: make this not go to workspace
Joe Onorato7e4ed992009-12-03 13:10:49 -08002591 * - From all apps
2592 * - From workspace
Joe Onoratoeffc4a82010-04-15 11:48:13 -07002593 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2594 * - From all apps
2595 * - From the center workspace
2596 * - From another workspace
Joe Onoratob2061212009-11-24 16:13:54 -05002597 */
Joe Onorato7bb17492009-09-24 17:51:01 -07002598 void closeAllApps(boolean animated) {
Joe Onoratofb0ca672009-09-14 17:55:46 -04002599 if (mAllAppsGrid.isVisible()) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002600 mWorkspace.setVisibility(View.VISIBLE);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002601 if (LauncherApplication.isScreenXLarge()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002602 cameraZoomIn(State.ALL_APPS, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002603 } else {
2604 mAllAppsGrid.zoom(0.0f, animated);
2605 }
Daniel Sandler388f6792010-03-02 14:08:08 -05002606 ((View)mAllAppsGrid).setFocusable(false);
Michael Jurka0142d492010-08-25 17:46:15 -07002607 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onoratoe77c08d2009-08-01 00:01:20 -07002608 }
Joe Onorato7404ee42009-07-31 11:54:44 -07002609 }
2610
Joe Onorato7c312c12009-08-13 21:36:53 -07002611 void lockAllApps() {
2612 // TODO
2613 }
2614
2615 void unlockAllApps() {
2616 // TODO
2617 }
2618
Patrick Dubroy558654c2010-07-23 16:48:11 -07002619 private boolean isCustomizationDrawerVisible() {
Michael Jurka54f7ac32010-08-02 13:56:46 -07002620 return mHomeCustomizationDrawer != null &&
2621 mHomeCustomizationDrawer.getVisibility() == View.VISIBLE;
Patrick Dubroy558654c2010-07-23 16:48:11 -07002622 }
2623
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002624 // Show the customization drawer (only exists in x-large configuration)
2625 private void showCustomizationDrawer(boolean animated) {
Patrick Dubroy558654c2010-07-23 16:48:11 -07002626 if (isAllAppsVisible()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002627 cameraPan(State.ALL_APPS, State.CUSTOMIZE, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002628 } else {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002629 cameraZoomOut(State.CUSTOMIZE, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002630 }
Patrick Dubroy558654c2010-07-23 16:48:11 -07002631 }
2632
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002633 // Hide the customization drawer (only exists in x-large configuration)
2634 void hideCustomizationDrawer(boolean animated) {
Patrick Dubroy558654c2010-07-23 16:48:11 -07002635 if (isCustomizationDrawerVisible()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002636 cameraZoomIn(State.CUSTOMIZE, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002637 }
2638 }
2639
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002640 void onWorkspaceClick(CellLayout layout) {
2641 Object itemInfo = mAllAppsPagedView.getChosenItem();
2642 if (itemInfo == null) {
2643 itemInfo = mCustomizePagedView.getChosenItem();
Michael Jurka213d9632010-07-28 11:29:25 -07002644 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002645
2646 if (itemInfo == null) {
2647 // No items are chosen in All Apps or Customize, so just zoom into the workspace
2648 mWorkspace.unshrink(layout);
2649 if (isAllAppsVisible()) {
2650 closeAllApps(true);
2651 } else if (isCustomizationDrawerVisible()) {
2652 hideCustomizationDrawer(true);
2653 }
2654 } else {
2655 // Act as if the chosen item was dropped on the given CellLayout
2656 if (mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
2657 mAllAppsPagedView.endChoiceMode();
2658 mCustomizePagedView.endChoiceMode();
2659 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002660 showOutOfSpaceMessage();
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002661 }
Michael Jurka213d9632010-07-28 11:29:25 -07002662 }
2663 }
2664
Michael Jurka0423dcf2010-10-05 14:56:18 -07002665 private void updateButtonWithIconFromExternalActivity(
2666 int buttonId, ComponentName activityName, int fallbackDrawableId) {
2667 ImageView button = (ImageView) findViewById(buttonId);
2668 Drawable toolbarIcon = null;
2669 try {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002670 PackageManager packageManager = getPackageManager();
Michael Jurka0423dcf2010-10-05 14:56:18 -07002671 // Look for the toolbar icon specified in the activity meta-data
2672 Bundle metaData = packageManager.getActivityInfo(
2673 activityName, PackageManager.GET_META_DATA).metaData;
2674 if (metaData != null) {
2675 int iconResId = metaData.getInt(TOOLBAR_ICON_METADATA_NAME);
2676 if (iconResId != 0) {
2677 Resources res = packageManager.getResourcesForActivity(activityName);
2678 toolbarIcon = res.getDrawable(iconResId);
2679 }
2680 }
2681 } catch (NameNotFoundException e) {
2682 // Do nothing
2683 }
2684 // If we were unable to find the icon via the meta-data, use a generic one
2685 if (toolbarIcon == null) {
2686 button.setImageResource(fallbackDrawableId);
2687 } else {
2688 button.setImageDrawable(toolbarIcon);
2689 }
2690 }
2691
2692 private void updateGlobalSearchIcon() {
2693 if (LauncherApplication.isScreenXLarge()) {
2694 final SearchManager searchManager =
2695 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2696 ComponentName activityName = searchManager.getGlobalSearchActivity();
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002697 if (activityName != null) {
Michael Jurka0423dcf2010-10-05 14:56:18 -07002698 updateButtonWithIconFromExternalActivity(
2699 R.id.search_button, activityName, R.drawable.search_button_generic);
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002700 }
2701 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002702 }
Michael Jurka0423dcf2010-10-05 14:56:18 -07002703
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002704 /**
2705 * Sets the app market icon (shown when all apps is visible on x-large screens)
2706 */
2707 private void updateAppMarketIcon() {
Michael Jurka0423dcf2010-10-05 14:56:18 -07002708 if (LauncherApplication.isScreenXLarge()) {
2709 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
2710 // Find the app market activity by resolving an intent.
2711 // (If multiple app markets are installed, it will return the ResolverActivity.)
2712 ComponentName activityName = intent.resolveActivity(getPackageManager());
2713 if (activityName != null) {
2714 mAppMarketIntent = intent;
2715 updateButtonWithIconFromExternalActivity(
2716 R.id.market_button, activityName, R.drawable.app_market_generic);
2717 }
2718 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002719 }
2720
2721 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002722 * Displays the shortcut creation dialog and launches, if necessary, the
2723 * appropriate activity.
2724 */
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002725 private class CreateShortcut implements DialogInterface.OnClickListener,
Romain Guy7b4ef332009-07-14 13:58:08 -07002726 DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
2727 DialogInterface.OnShowListener {
2728
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002729 private AddAdapter mAdapter;
Romain Guy9ffb5432009-03-24 21:04:15 -07002730
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002731 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002732 mAdapter = new AddAdapter(Launcher.this);
Romain Guycbb89e42009-06-08 15:52:54 -07002733
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002734 final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
2735 builder.setTitle(getString(R.string.menu_item_add_item));
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002736 builder.setAdapter(mAdapter, this);
Romain Guycbb89e42009-06-08 15:52:54 -07002737
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002738 builder.setInverseBackgroundForced(true);
2739
2740 AlertDialog dialog = builder.create();
2741 dialog.setOnCancelListener(this);
Romain Guycbb89e42009-06-08 15:52:54 -07002742 dialog.setOnDismissListener(this);
Romain Guy7b4ef332009-07-14 13:58:08 -07002743 dialog.setOnShowListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002744
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002745 return dialog;
2746 }
2747
2748 public void onCancel(DialogInterface dialog) {
2749 mWaitingForResult = false;
2750 cleanup();
2751 }
2752
Romain Guycbb89e42009-06-08 15:52:54 -07002753 public void onDismiss(DialogInterface dialog) {
Romain Guycbb89e42009-06-08 15:52:54 -07002754 }
2755
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002756 private void cleanup() {
Joe Onoratocc19a532009-11-19 14:19:17 -08002757 try {
2758 dismissDialog(DIALOG_CREATE_SHORTCUT);
2759 } catch (Exception e) {
2760 // An exception is thrown if the dialog is not visible, which is fine
2761 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002762 }
2763
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002764 /**
2765 * Handle the action clicked in the "Add to home" dialog.
2766 */
2767 public void onClick(DialogInterface dialog, int which) {
2768 Resources res = getResources();
2769 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002770
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002771 switch (which) {
2772 case AddAdapter.ITEM_SHORTCUT: {
Joe Onoratodeb98af2010-02-19 14:59:39 -08002773 pickShortcut();
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002774 break;
2775 }
Romain Guycbb89e42009-06-08 15:52:54 -07002776
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002777 case AddAdapter.ITEM_APPWIDGET: {
2778 int appWidgetId = Launcher.this.mAppWidgetHost.allocateAppWidgetId();
Romain Guycbb89e42009-06-08 15:52:54 -07002779
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002780 Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
2781 pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002782 // start the pick activity
2783 startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET);
2784 break;
2785 }
Romain Guycbb89e42009-06-08 15:52:54 -07002786
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002787 case AddAdapter.ITEM_LIVE_FOLDER: {
2788 // Insert extra item to handle inserting folder
2789 Bundle bundle = new Bundle();
Romain Guycbb89e42009-06-08 15:52:54 -07002790
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002791 ArrayList<String> shortcutNames = new ArrayList<String>();
2792 shortcutNames.add(res.getString(R.string.group_folder));
2793 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
Romain Guycbb89e42009-06-08 15:52:54 -07002794
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002795 ArrayList<ShortcutIconResource> shortcutIcons =
2796 new ArrayList<ShortcutIconResource>();
2797 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
2798 R.drawable.ic_launcher_folder));
2799 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
2800
2801 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2802 pickIntent.putExtra(Intent.EXTRA_INTENT,
2803 new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER));
2804 pickIntent.putExtra(Intent.EXTRA_TITLE,
2805 getText(R.string.title_select_live_folder));
2806 pickIntent.putExtras(bundle);
Romain Guycbb89e42009-06-08 15:52:54 -07002807
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002808 startActivityForResult(pickIntent, REQUEST_PICK_LIVE_FOLDER);
2809 break;
2810 }
2811
2812 case AddAdapter.ITEM_WALLPAPER: {
2813 startWallpaper();
2814 break;
2815 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002816 }
2817 }
Romain Guy7b4ef332009-07-14 13:58:08 -07002818
2819 public void onShow(DialogInterface dialog) {
Winson Chungaafa03c2010-06-11 17:34:16 -07002820 mWaitingForResult = true;
Romain Guy7b4ef332009-07-14 13:58:08 -07002821 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002822 }
2823
2824 /**
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002825 * Receives notifications when applications are added/removed.
2826 */
2827 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
2828 @Override
2829 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002830 closeSystemDialogs();
Joe Onoratob2061212009-11-24 16:13:54 -05002831 String reason = intent.getStringExtra("reason");
2832 if (!"homekey".equals(reason)) {
2833 boolean animate = true;
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002834 if (mPaused || "lock".equals(reason)) {
Joe Onoratob2061212009-11-24 16:13:54 -05002835 animate = false;
2836 }
Joe Onoratob2061212009-11-24 16:13:54 -05002837 closeAllApps(animate);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002838 hideCustomizationDrawer(animate);
Joe Onoratob2061212009-11-24 16:13:54 -05002839 }
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002840 }
2841 }
2842
2843 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002844 * Receives notifications whenever the appwidgets are reset.
2845 */
2846 private class AppWidgetResetObserver extends ContentObserver {
2847 public AppWidgetResetObserver() {
2848 super(new Handler());
2849 }
2850
2851 @Override
2852 public void onChange(boolean selfChange) {
2853 onAppWidgetReset();
2854 }
2855 }
2856
2857 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002858 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002859 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002860 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07002861 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002862 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07002863 } else {
2864 return SCREEN_COUNT / 2;
2865 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002866 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002867
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002868 void setAllAppsPagedView(PagedView view) {
2869 mAllAppsPagedView = view;
2870 }
2871
Joe Onorato9c1289c2009-08-17 11:03:03 -04002872 /**
2873 * Refreshes the shortcuts shown on the workspace.
2874 *
2875 * Implementation of the method from LauncherModel.Callbacks.
2876 */
2877 public void startBinding() {
2878 final Workspace workspace = mWorkspace;
2879 int count = workspace.getChildCount();
2880 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04002881 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Joe Onorato9c1289c2009-08-17 11:03:03 -04002882 ((ViewGroup) workspace.getChildAt(i)).removeAllViewsInLayout();
2883 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002884
Joe Onorato9c1289c2009-08-17 11:03:03 -04002885 if (DEBUG_USER_INTERFACE) {
2886 android.widget.Button finishButton = new android.widget.Button(this);
2887 finishButton.setText("Finish");
2888 workspace.addInScreen(finishButton, 1, 0, 0, 1, 1);
2889
2890 finishButton.setOnClickListener(new android.widget.Button.OnClickListener() {
2891 public void onClick(View v) {
2892 finish();
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002893 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002894 });
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002895 }
2896 }
2897
2898 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002899 * Bind the items start-end from the list.
2900 *
2901 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002902 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002903 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
2904
2905 final Workspace workspace = mWorkspace;
2906
2907 for (int i=start; i<end; i++) {
2908 final ItemInfo item = shortcuts.get(i);
2909 mDesktopItems.add(item);
2910 switch (item.itemType) {
2911 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
2912 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Joe Onorato0589f0f2010-02-08 13:44:00 -08002913 final View shortcut = createShortcut((ShortcutInfo)item);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002914 workspace.addInScreen(shortcut, item.screen, item.cellX, item.cellY, 1, 1,
2915 false);
2916 break;
2917 case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER:
2918 final FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07002919 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Joe Onorato9c1289c2009-08-17 11:03:03 -04002920 (UserFolderInfo) item);
2921 workspace.addInScreen(newFolder, item.screen, item.cellX, item.cellY, 1, 1,
2922 false);
2923 break;
2924 case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER:
2925 final FolderIcon newLiveFolder = LiveFolderIcon.fromXml(
2926 R.layout.live_folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07002927 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Joe Onorato9c1289c2009-08-17 11:03:03 -04002928 (LiveFolderInfo) item);
2929 workspace.addInScreen(newLiveFolder, item.screen, item.cellX, item.cellY, 1, 1,
2930 false);
2931 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002932 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002933 }
2934
Joe Onorato9c1289c2009-08-17 11:03:03 -04002935 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002936 }
2937
Joe Onorato9c1289c2009-08-17 11:03:03 -04002938 /**
2939 * Implementation of the method from LauncherModel.Callbacks.
2940 */
Joe Onoratoad72e172009-11-06 16:25:04 -05002941 public void bindFolders(HashMap<Long, FolderInfo> folders) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002942 sFolders.clear();
2943 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002944 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002945
2946 /**
2947 * Add the views for a widget to the workspace.
2948 *
2949 * Implementation of the method from LauncherModel.Callbacks.
2950 */
2951 public void bindAppWidget(LauncherAppWidgetInfo item) {
Daniel Sandler843e8602010-06-07 14:59:01 -04002952 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
2953 if (DEBUG_WIDGETS) {
2954 Log.d(TAG, "bindAppWidget: " + item);
2955 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002956 final Workspace workspace = mWorkspace;
2957
2958 final int appWidgetId = item.appWidgetId;
2959 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04002960 if (DEBUG_WIDGETS) {
2961 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
2962 }
2963
Joe Onorato9c1289c2009-08-17 11:03:03 -04002964 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
2965
Joe Onorato9c1289c2009-08-17 11:03:03 -04002966 item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
2967 item.hostView.setTag(item);
2968
2969 workspace.addInScreen(item.hostView, item.screen, item.cellX,
2970 item.cellY, item.spanX, item.spanY, false);
2971
2972 workspace.requestLayout();
2973
2974 mDesktopItems.add(item);
Daniel Sandler843e8602010-06-07 14:59:01 -04002975
2976 if (DEBUG_WIDGETS) {
2977 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
2978 + (SystemClock.uptimeMillis()-start) + "ms");
2979 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002980 }
2981
2982 /**
2983 * Callback saying that there aren't any more items to bind.
2984 *
2985 * Implementation of the method from LauncherModel.Callbacks.
2986 */
2987 public void finishBindingItems() {
2988 if (mSavedState != null) {
2989 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07002990 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002991 }
2992
2993 final long[] userFolders = mSavedState.getLongArray(RUNTIME_STATE_USER_FOLDERS);
2994 if (userFolders != null) {
2995 for (long folderId : userFolders) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002996 final FolderInfo info = sFolders.get(folderId);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002997 if (info != null) {
2998 openFolder(info);
2999 }
3000 }
3001 final Folder openFolder = mWorkspace.getOpenFolder();
3002 if (openFolder != null) {
3003 openFolder.requestFocus();
3004 }
3005 }
3006
Joe Onorato9c1289c2009-08-17 11:03:03 -04003007 mSavedState = null;
3008 }
3009
3010 if (mSavedInstanceState != null) {
3011 super.onRestoreInstanceState(mSavedInstanceState);
3012 mSavedInstanceState = null;
3013 }
3014
Joe Onorato9c1289c2009-08-17 11:03:03 -04003015 mWorkspaceLoading = false;
3016 }
3017
3018 /**
3019 * Add the icons for all apps.
3020 *
3021 * Implementation of the method from LauncherModel.Callbacks.
3022 */
3023 public void bindAllApplications(ArrayList<ApplicationInfo> apps) {
Romain Guy84f296c2009-11-04 15:00:44 -08003024 mAllAppsGrid.setApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003025 if (mCustomizePagedView != null) {
3026 mCustomizePagedView.setApps(apps);
3027 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003028 updateAppMarketIcon();
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003029 updateGlobalSearchIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003030 }
3031
3032 /**
3033 * A package was installed.
3034 *
3035 * Implementation of the method from LauncherModel.Callbacks.
3036 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003037 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003038 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onoratoa8138d52009-10-06 19:25:30 -07003039 mAllAppsGrid.addApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003040 if (mCustomizePagedView != null) {
3041 mCustomizePagedView.addApps(apps);
3042 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003043 updateAppMarketIcon();
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003044 updateGlobalSearchIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003045 }
3046
3047 /**
3048 * A package was updated.
3049 *
3050 * Implementation of the method from LauncherModel.Callbacks.
3051 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003052 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003053 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato64e6be72010-03-05 15:05:52 -05003054 mWorkspace.updateShortcuts(apps);
3055 mAllAppsGrid.updateApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003056 if (mCustomizePagedView != null) {
3057 mCustomizePagedView.updateApps(apps);
3058 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003059 updateAppMarketIcon();
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003060 updateGlobalSearchIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003061 }
3062
3063 /**
3064 * A package was uninstalled.
3065 *
3066 * Implementation of the method from LauncherModel.Callbacks.
3067 */
Joe Onorato36115782010-06-17 13:28:48 -04003068 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003069 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato36115782010-06-17 13:28:48 -04003070 if (permanent) {
3071 mWorkspace.removeItems(apps);
3072 }
Joe Onoratoa8138d52009-10-06 19:25:30 -07003073 mAllAppsGrid.removeApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003074 if (mCustomizePagedView != null) {
3075 mCustomizePagedView.removeApps(apps);
3076 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003077 updateAppMarketIcon();
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003078 updateGlobalSearchIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003079 }
Joe Onoratobe386092009-11-17 17:32:16 -08003080
3081 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003082 * A number of packages were updated.
3083 */
3084 public void bindPackagesUpdated() {
3085 // update the customization drawer contents
Winson Chung5f941722010-09-28 16:36:43 -07003086 if (mCustomizePagedView != null) {
Winson Chungb3347bb2010-08-19 14:51:28 -07003087 mCustomizePagedView.update();
Winson Chung5f941722010-09-28 16:36:43 -07003088 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003089 }
3090
3091 /**
Joe Onoratobe386092009-11-17 17:32:16 -08003092 * Prints out out state for debugging.
3093 */
3094 public void dumpState() {
3095 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08003096 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08003097 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
3098 Log.d(TAG, "mRestoring=" + mRestoring);
3099 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
3100 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
3101 Log.d(TAG, "mDesktopItems.size=" + mDesktopItems.size());
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003102 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08003103 mModel.dumpState();
3104 mAllAppsGrid.dumpState();
3105 Log.d(TAG, "END launcher2 dump state");
3106 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003107}