blob: c82f998286bf78b8b7cdd833e8883c4907c1785f [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 WALLPAPER_SCREENS_SPAN = 2;
122
123 private static final int MENU_GROUP_ADD = 1;
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800124 private static final int MENU_GROUP_WALLPAPER = MENU_GROUP_ADD + 1;
125
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800126 private static final int MENU_ADD = Menu.FIRST + 1;
127 private static final int MENU_WALLPAPER_SETTINGS = MENU_ADD + 1;
128 private static final int MENU_SEARCH = MENU_WALLPAPER_SETTINGS + 1;
129 private static final int MENU_NOTIFICATIONS = MENU_SEARCH + 1;
Romain Guy94dabf12009-07-21 10:55:43 -0700130 private static final int MENU_SETTINGS = MENU_NOTIFICATIONS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800131
132 private static final int REQUEST_CREATE_SHORTCUT = 1;
133 private static final int REQUEST_CREATE_LIVE_FOLDER = 4;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700134 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800135 private static final int REQUEST_PICK_APPLICATION = 6;
136 private static final int REQUEST_PICK_SHORTCUT = 7;
137 private static final int REQUEST_PICK_LIVE_FOLDER = 8;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700138 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700139 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800140
141 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
142
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800143 static final int SCREEN_COUNT = 5;
144 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800145
Joe Onorato7c312c12009-08-13 21:36:53 -0700146 static final int DIALOG_CREATE_SHORTCUT = 1;
147 static final int DIALOG_RENAME_FOLDER = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800148
Romain Guy98d01652009-06-30 16:21:04 -0700149 private static final String PREFERENCES = "launcher.preferences";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800150
151 // Type: int
152 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
153 // Type: boolean
154 private static final String RUNTIME_STATE_ALL_APPS_FOLDER = "launcher.all_apps_folder";
155 // Type: long
156 private static final String RUNTIME_STATE_USER_FOLDERS = "launcher.user_folder";
157 // Type: int
158 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
159 // Type: int
160 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cellX";
161 // Type: int
162 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cellY";
163 // Type: int
164 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_spanX";
165 // Type: int
166 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_spanY";
167 // Type: int
168 private static final String RUNTIME_STATE_PENDING_ADD_COUNT_X = "launcher.add_countX";
169 // Type: int
170 private static final String RUNTIME_STATE_PENDING_ADD_COUNT_Y = "launcher.add_countY";
171 // Type: int[]
172 private static final String RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS = "launcher.add_occupied_cells";
173 // Type: boolean
174 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
175 // Type: long
176 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
177
Winson Chung80baf5a2010-08-09 16:03:15 -0700178 // tags for the customization tabs
179 private static final String WIDGETS_TAG = "widgets";
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700180 private static final String APPLICATIONS_TAG = "applications";
Winson Chung80baf5a2010-08-09 16:03:15 -0700181 private static final String FOLDERS_TAG = "folders";
182 private static final String SHORTCUTS_TAG = "shortcuts";
183 private static final String WALLPAPERS_TAG = "wallpapers";
184
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700185 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
186
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700187 /** The different states that Launcher can be in. */
188 private enum State { WORKSPACE, ALL_APPS, CUSTOMIZE, OVERVIEW };
189
Joe Onorato9c1289c2009-08-17 11:03:03 -0400190 static final int APPWIDGET_HOST_ID = 1024;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800191
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800192 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800193 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800194
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800195 private final BroadcastReceiver mCloseSystemDialogsReceiver
196 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800197 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
198
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800199 private LayoutInflater mInflater;
200
Joe Onorato00acb122009-08-04 16:04:30 -0400201 private DragController mDragController;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800202 private Workspace mWorkspace;
Romain Guycbb89e42009-06-08 15:52:54 -0700203
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700204 private AppWidgetManager mAppWidgetManager;
205 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700206
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800207 private CellLayout.CellInfo mAddItemCellInfo;
Michael Jurkaa63c4522010-08-19 13:52:27 -0700208 private int[] mAddItemCoordinates;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800209 private CellLayout.CellInfo mMenuAddInfo;
210 private final int[] mCellCoordinates = new int[2];
211 private FolderInfo mFolderInfo;
212
Joe Onorato7c312c12009-08-13 21:36:53 -0700213 private DeleteZone mDeleteZone;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700214 private HandleView mHandleView;
Joe Onorato7c312c12009-08-13 21:36:53 -0700215 private AllAppsView mAllAppsGrid;
Michael Jurka0e260592010-06-30 17:07:39 -0700216 private TabHost mHomeCustomizationDrawer;
Patrick Dubroy2b9ff372010-09-07 17:49:27 -0700217
218 private PagedView mAllAppsPagedView = null;
219 private CustomizePagedView mCustomizePagedView = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800220
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800221 private Bundle mSavedState;
222
223 private SpannableStringBuilder mDefaultKeySsb = null;
224
Joe Onorato9c1289c2009-08-17 11:03:03 -0400225 private boolean mWorkspaceLoading = true;
226
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800227 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800228 private boolean mRestoring;
229 private boolean mWaitingForResult;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800230
231 private Bundle mSavedInstanceState;
232
Joe Onorato9c1289c2009-08-17 11:03:03 -0400233 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800234 private IconCache mIconCache;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400235
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700236 private static LocaleConfiguration sLocaleConfiguration = null;
237
Romain Guy84f296c2009-11-04 15:00:44 -0800238 private ArrayList<ItemInfo> mDesktopItems = new ArrayList<ItemInfo>();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700239 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700240
Romain Guy1fbc1c82009-11-09 20:43:08 -0800241 private ImageView mPreviousView;
242 private ImageView mNextView;
Joe Onorato080d9b62009-11-02 12:01:11 -0500243
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400244 // Hotseats (quick-launch icons next to AllApps)
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400245 private String[] mHotseatConfig = null;
246 private Intent[] mHotseats = null;
247 private Drawable[] mHotseatIcons = null;
248 private CharSequence[] mHotseatLabels = null;
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400249
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700250 private Intent mAppMarketIntent = null;
251
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800252 @Override
253 protected void onCreate(Bundle savedInstanceState) {
254 super.onCreate(savedInstanceState);
Romain Guyb1b69f52009-08-10 15:10:15 -0700255
Winson Chungaafa03c2010-06-11 17:34:16 -0700256 if (LauncherApplication.isInPlaceRotationEnabled()) {
257 // hide the status bar (temporary until we get the status bar design figured out)
258 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
259 this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
260 }
261
Joe Onorato0589f0f2010-02-08 13:44:00 -0800262 LauncherApplication app = ((LauncherApplication)getApplication());
263 mModel = app.setLauncher(this);
264 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400265 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800266 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700267
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700268 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700269 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
270 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700271
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800272 if (PROFILE_STARTUP) {
273 android.os.Debug.startMethodTracing("/sdcard/launcher");
274 }
275
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400276 loadHotseats();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800277 checkForLocaleChange();
278 setWallpaperDimension();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800279 setContentView(R.layout.launcher);
Michael Jurka946ad472010-07-09 18:05:18 -0700280 mHomeCustomizationDrawer = (TabHost) findViewById(com.android.internal.R.id.tabhost);
281 if (mHomeCustomizationDrawer != null) {
282 mHomeCustomizationDrawer.setup();
Winson Chungaafa03c2010-06-11 17:34:16 -0700283
Winson Chung80baf5a2010-08-09 16:03:15 -0700284 // share the same customization workspace across all the tabs
Winson Chunge3193b92010-09-10 11:44:42 -0700285 mCustomizePagedView = (CustomizePagedView) mInflater.inflate(
286 R.layout.customization_drawer, mHomeCustomizationDrawer, false);
Winson Chung80baf5a2010-08-09 16:03:15 -0700287 TabContentFactory contentFactory = new TabContentFactory() {
288 public View createTabContent(String tag) {
289 return mCustomizePagedView;
290 }
291 };
292
Michael Jurka946ad472010-07-09 18:05:18 -0700293 String widgetsLabel = getString(R.string.widgets_tab_label);
Winson Chung80baf5a2010-08-09 16:03:15 -0700294 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(WIDGETS_TAG)
295 .setIndicator(widgetsLabel).setContent(contentFactory));
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700296 String applicationsLabel = getString(R.string.applications_tab_label);
297 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(APPLICATIONS_TAG)
298 .setIndicator(applicationsLabel).setContent(contentFactory));
Michael Jurka946ad472010-07-09 18:05:18 -0700299 String foldersLabel = getString(R.string.folders_tab_label);
Winson Chung80baf5a2010-08-09 16:03:15 -0700300 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(FOLDERS_TAG)
301 .setIndicator(foldersLabel).setContent(contentFactory));
Michael Jurka946ad472010-07-09 18:05:18 -0700302 String wallpapersLabel = getString(R.string.wallpapers_tab_label);
Winson Chung80baf5a2010-08-09 16:03:15 -0700303 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(WALLPAPERS_TAG)
304 .setIndicator(wallpapersLabel).setContent(contentFactory));
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700305 String shortcutsLabel = getString(R.string.shortcuts_tab_label);
306 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(SHORTCUTS_TAG)
307 .setIndicator(shortcutsLabel).setContent(contentFactory));
Winson Chung80baf5a2010-08-09 16:03:15 -0700308
309 // TEMP: just styling the tab widget to be a bit nicer until we get the actual
310 // new assets
311 TabWidget tabWidget = mHomeCustomizationDrawer.getTabWidget();
312 for (int i = 0; i < tabWidget.getChildCount(); ++i) {
313 RelativeLayout tab = (RelativeLayout) tabWidget.getChildTabViewAt(i);
314 TextView text = (TextView) tab.getChildAt(1);
315 text.setTextSize(20.0f);
316 text.setPadding(20, 0, 20, 0);
317 text.setShadowLayer(1.0f, 0.0f, 1.0f, Color.BLACK);
318 tab.setBackgroundDrawable(null);
319 }
320
321 mHomeCustomizationDrawer.setOnTabChangedListener(new OnTabChangeListener() {
322 public void onTabChanged(String tabId) {
323 // animate the changing of the tab content by fading pages in and out
324 final int duration = 150;
325 final float alpha = mCustomizePagedView.getAlpha();
Chet Haaseb1254a62010-09-07 13:35:00 -0700326 ValueAnimator alphaAnim = new ObjectAnimator(duration, mCustomizePagedView,
Winson Chung80baf5a2010-08-09 16:03:15 -0700327 "alpha", alpha, 0.0f);
Chet Haaseb1254a62010-09-07 13:35:00 -0700328 alphaAnim.addListener(new AnimatorListenerAdapter() {
329 public void onAnimationEnd(Animator animation) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700330 String tag = mHomeCustomizationDrawer.getCurrentTabTag();
331 if (tag == WIDGETS_TAG) {
332 mCustomizePagedView.setCustomizationFilter(
333 CustomizePagedView.CustomizationType.WidgetCustomization);
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700334 } else if (tag == APPLICATIONS_TAG) {
335 mCustomizePagedView.setCustomizationFilter(
336 CustomizePagedView.CustomizationType.ApplicationCustomization);
Winson Chung80baf5a2010-08-09 16:03:15 -0700337 } else if (tag == FOLDERS_TAG) {
338 mCustomizePagedView.setCustomizationFilter(
339 CustomizePagedView.CustomizationType.FolderCustomization);
Winson Chung80baf5a2010-08-09 16:03:15 -0700340 } else if (tag == WALLPAPERS_TAG) {
341 mCustomizePagedView.setCustomizationFilter(
342 CustomizePagedView.CustomizationType.WallpaperCustomization);
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700343 } else if (tag == SHORTCUTS_TAG) {
344 mCustomizePagedView.setCustomizationFilter(
345 CustomizePagedView.CustomizationType.ShortcutCustomization);
Winson Chung80baf5a2010-08-09 16:03:15 -0700346 }
347
348 final float alpha = mCustomizePagedView.getAlpha();
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700349 ValueAnimator alphaAnim = new ObjectAnimator(duration,
350 mCustomizePagedView, "alpha", alpha, 1.0f);
Winson Chung80baf5a2010-08-09 16:03:15 -0700351 alphaAnim.start();
352 }
353 });
354 alphaAnim.start();
355 }
356 });
Michael Jurka946ad472010-07-09 18:05:18 -0700357
358 mHomeCustomizationDrawer.setCurrentTab(0);
359 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800360 setupViews();
361
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800362 registerContentObservers();
363
Joe Onorato7c312c12009-08-13 21:36:53 -0700364 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700365
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800366 mSavedState = savedInstanceState;
367 restoreState(mSavedState);
368
369 if (PROFILE_STARTUP) {
370 android.os.Debug.stopMethodTracing();
371 }
372
373 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400374 mModel.startLoader(this, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800375 }
376
377 // For handling default keys
378 mDefaultKeySsb = new SpannableStringBuilder();
379 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800380
381 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
382 registerReceiver(mCloseSystemDialogsReceiver, filter);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800383 }
Romain Guycbb89e42009-06-08 15:52:54 -0700384
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800385 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700386 if (sLocaleConfiguration == null) {
387 new AsyncTask<Void, Void, LocaleConfiguration>() {
388 @Override
389 protected LocaleConfiguration doInBackground(Void... unused) {
390 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
391 readConfiguration(Launcher.this, localeConfiguration);
392 return localeConfiguration;
393 }
394
395 @Override
396 protected void onPostExecute(LocaleConfiguration result) {
397 sLocaleConfiguration = result;
398 checkForLocaleChange(); // recursive, but now with a locale configuration
399 }
400 }.execute();
401 return;
402 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700403
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800404 final Configuration configuration = getResources().getConfiguration();
405
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700406 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800407 final String locale = configuration.locale.toString();
408
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700409 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800410 final int mcc = configuration.mcc;
411
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700412 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800413 final int mnc = configuration.mnc;
414
Romain Guy84f296c2009-11-04 15:00:44 -0800415 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800416
Romain Guy84f296c2009-11-04 15:00:44 -0800417 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700418 sLocaleConfiguration.locale = locale;
419 sLocaleConfiguration.mcc = mcc;
420 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700421
Joe Onorato0589f0f2010-02-08 13:44:00 -0800422 mIconCache.flush();
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400423 loadHotseats();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700424
425 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
426 new Thread("WriteLocaleConfiguration") {
427 public void run() {
428 writeConfiguration(Launcher.this, localeConfiguration);
429 }
430 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700431 }
432 }
433
434 private static class LocaleConfiguration {
435 public String locale;
436 public int mcc = -1;
437 public int mnc = -1;
438 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700439
Romain Guy98d01652009-06-30 16:21:04 -0700440 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
441 DataInputStream in = null;
442 try {
443 in = new DataInputStream(context.openFileInput(PREFERENCES));
444 configuration.locale = in.readUTF();
445 configuration.mcc = in.readInt();
446 configuration.mnc = in.readInt();
447 } catch (FileNotFoundException e) {
448 // Ignore
449 } catch (IOException e) {
450 // Ignore
451 } finally {
452 if (in != null) {
453 try {
454 in.close();
455 } catch (IOException e) {
456 // Ignore
457 }
458 }
459 }
460 }
461
462 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
463 DataOutputStream out = null;
464 try {
465 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
466 out.writeUTF(configuration.locale);
467 out.writeInt(configuration.mcc);
468 out.writeInt(configuration.mnc);
469 out.flush();
470 } catch (FileNotFoundException e) {
471 // Ignore
472 } catch (IOException e) {
473 //noinspection ResultOfMethodCallIgnored
474 context.getFileStreamPath(PREFERENCES).delete();
475 } finally {
476 if (out != null) {
477 try {
478 out.close();
479 } catch (IOException e) {
480 // Ignore
481 }
482 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800483 }
484 }
485
486 static int getScreen() {
487 synchronized (sLock) {
488 return sScreen;
489 }
490 }
491
492 static void setScreen(int screen) {
493 synchronized (sLock) {
494 sScreen = screen;
495 }
496 }
497
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800498 private void setWallpaperDimension() {
Dianne Hackborn107f8392009-08-05 21:32:16 -0700499 WallpaperManager wpm = (WallpaperManager)getSystemService(WALLPAPER_SERVICE);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800500
501 Display display = getWindowManager().getDefaultDisplay();
Romain Guy5bbc91b2010-08-18 11:38:46 -0700502 // TODO: Put back when we decide about scrolling the wallpaper
503 // boolean isPortrait = display.getWidth() < display.getHeight();
504 // final int width = isPortrait ? display.getWidth() : display.getHeight();
505 // final int height = isPortrait ? display.getHeight() : display.getWidth();
506 wpm.suggestDesiredDimensions(Math.max(display.getWidth(), display.getHeight()),
507 Math.max(display.getWidth(), display.getHeight()));
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800508 }
509
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400510 // Note: This doesn't do all the client-id magic that BrowserProvider does
511 // in Browser. (http://b/2425179)
512 private Uri getDefaultBrowserUri() {
513 String url = getString(R.string.default_browser_url);
514 if (url.indexOf("{CID}") != -1) {
515 url = url.replace("{CID}", "android-google");
516 }
517 return Uri.parse(url);
518 }
519
520 // Load the Intent templates from arrays.xml to populate the hotseats. For
521 // each Intent, if it resolves to a single app, use that as the launch
522 // intent & use that app's label as the contentDescription. Otherwise,
523 // retain the ResolveActivity so the user can pick an app.
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400524 private void loadHotseats() {
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400525 if (mHotseatConfig == null) {
526 mHotseatConfig = getResources().getStringArray(R.array.hotseats);
527 if (mHotseatConfig.length > 0) {
528 mHotseats = new Intent[mHotseatConfig.length];
529 mHotseatLabels = new CharSequence[mHotseatConfig.length];
530 mHotseatIcons = new Drawable[mHotseatConfig.length];
531 } else {
532 mHotseats = null;
533 mHotseatIcons = null;
534 mHotseatLabels = null;
535 }
536
537 TypedArray hotseatIconDrawables = getResources().obtainTypedArray(R.array.hotseat_icons);
538 for (int i=0; i<mHotseatConfig.length; i++) {
539 // load icon for this slot; currently unrelated to the actual activity
540 try {
541 mHotseatIcons[i] = hotseatIconDrawables.getDrawable(i);
542 } catch (ArrayIndexOutOfBoundsException ex) {
543 Log.w(TAG, "Missing hotseat_icons array item #" + i);
544 mHotseatIcons[i] = null;
545 }
546 }
547 hotseatIconDrawables.recycle();
548 }
549
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400550 PackageManager pm = getPackageManager();
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400551 for (int i=0; i<mHotseatConfig.length; i++) {
552 Intent intent = null;
553 if (mHotseatConfig[i].equals("*BROWSER*")) {
554 // magic value meaning "launch user's default web browser"
555 // replace it with a generic web request so we can see if there is indeed a default
556 String defaultUri = getString(R.string.default_browser_url);
557 intent = new Intent(
558 Intent.ACTION_VIEW,
559 ((defaultUri != null)
560 ? Uri.parse(defaultUri)
561 : getDefaultBrowserUri())
562 ).addCategory(Intent.CATEGORY_BROWSABLE);
563 // note: if the user launches this without a default set, she
564 // will always be taken to the default URL above; this is
565 // unavoidable as we must specify a valid URL in order for the
Winson Chungaafa03c2010-06-11 17:34:16 -0700566 // chooser to appear, and once the user selects something, that
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400567 // URL is unavoidably sent to the chosen app.
568 } else {
569 try {
570 intent = Intent.parseUri(mHotseatConfig[i], 0);
571 } catch (java.net.URISyntaxException ex) {
572 Log.w(TAG, "Invalid hotseat intent: " + mHotseatConfig[i]);
573 // bogus; leave intent=null
574 }
575 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700576
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400577 if (intent == null) {
578 mHotseats[i] = null;
579 mHotseatLabels[i] = getText(R.string.activity_not_found);
580 continue;
581 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400582
583 if (LOGD) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700584 Log.d(TAG, "loadHotseats: hotseat " + i
585 + " initial intent=["
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400586 + intent.toUri(Intent.URI_INTENT_SCHEME)
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400587 + "]");
588 }
589
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400590 ResolveInfo bestMatch = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
591 List<ResolveInfo> allMatches = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
Winson Chungaafa03c2010-06-11 17:34:16 -0700592 if (LOGD) {
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400593 Log.d(TAG, "Best match for intent: " + bestMatch);
594 Log.d(TAG, "All matches: ");
595 for (ResolveInfo ri : allMatches) {
596 Log.d(TAG, " --> " + ri);
597 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400598 }
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400599 // did this resolve to a single app, or the resolver?
600 if (allMatches.size() == 0 || bestMatch == null) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700601 // can't find any activity to handle this. let's leave the
602 // intent as-is and let Launcher show a toast when it fails
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400603 // to launch.
604 mHotseats[i] = intent;
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400605
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400606 // set accessibility text to "Not installed"
607 mHotseatLabels[i] = getText(R.string.activity_not_found);
608 } else {
609 boolean found = false;
610 for (ResolveInfo ri : allMatches) {
611 if (bestMatch.activityInfo.name.equals(ri.activityInfo.name)
612 && bestMatch.activityInfo.applicationInfo.packageName
613 .equals(ri.activityInfo.applicationInfo.packageName)) {
614 found = true;
615 break;
616 }
617 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700618
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400619 if (!found) {
620 if (LOGD) Log.d(TAG, "Multiple options, no default yet");
621 // the bestMatch is probably the ResolveActivity, meaning the
622 // user has not yet selected a default
623 // so: we'll keep the original intent for now
624 mHotseats[i] = intent;
625
626 // set the accessibility text to "Select shortcut"
627 mHotseatLabels[i] = getText(R.string.title_select_shortcut);
628 } else {
629 // we have an app!
630 // now reconstruct the intent to launch it through the front
631 // door
632 ComponentName com = new ComponentName(
633 bestMatch.activityInfo.applicationInfo.packageName,
634 bestMatch.activityInfo.name);
635 mHotseats[i] = new Intent(Intent.ACTION_MAIN).setComponent(com);
636
637 // load the app label for accessibility
638 mHotseatLabels[i] = bestMatch.activityInfo.loadLabel(pm);
639 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400640 }
641
642 if (LOGD) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700643 Log.d(TAG, "loadHotseats: hotseat " + i
644 + " final intent=["
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400645 + ((mHotseats[i] == null)
646 ? "null"
647 : mHotseats[i].toUri(Intent.URI_INTENT_SCHEME))
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400648 + "] label=[" + mHotseatLabels[i]
649 + "]"
650 );
651 }
652 }
653 }
654
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800655 @Override
656 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Romain Guyaad5ef42009-06-10 02:48:37 -0700657 mWaitingForResult = false;
658
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800659 // The pattern used here is that a user PICKs a specific application,
660 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700661
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800662 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
663 // launch over to the Music app to actually CREATE_SHORTCUT.
Romain Guycbb89e42009-06-08 15:52:54 -0700664
Romain Guy94dabf12009-07-21 10:55:43 -0700665 if (resultCode == RESULT_OK && mAddItemCellInfo != null) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800666 switch (requestCode) {
667 case REQUEST_PICK_APPLICATION:
Joe Onorato9c1289c2009-08-17 11:03:03 -0400668 completeAddApplication(this, data, mAddItemCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800669 break;
670 case REQUEST_PICK_SHORTCUT:
Joe Onoratodeb98af2010-02-19 14:59:39 -0800671 processShortcut(data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800672 break;
673 case REQUEST_CREATE_SHORTCUT:
Joe Onorato9c1289c2009-08-17 11:03:03 -0400674 completeAddShortcut(data, mAddItemCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800675 break;
676 case REQUEST_PICK_LIVE_FOLDER:
677 addLiveFolder(data);
678 break;
679 case REQUEST_CREATE_LIVE_FOLDER:
Joe Onorato9c1289c2009-08-17 11:03:03 -0400680 completeAddLiveFolder(data, mAddItemCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800681 break;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700682 case REQUEST_PICK_APPWIDGET:
Michael Jurkaaf442092010-06-10 17:01:57 -0700683 addAppWidgetFromPick(data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800684 break;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700685 case REQUEST_CREATE_APPWIDGET:
Michael Jurkaaf442092010-06-10 17:01:57 -0700686 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurkaaf442092010-06-10 17:01:57 -0700687 completeAddAppWidget(appWidgetId, mAddItemCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800688 break;
Mike Clerona0618e42009-10-22 13:55:21 -0700689 case REQUEST_PICK_WALLPAPER:
690 // We just wanted the activity result here so we can clear mWaitingForResult
691 break;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800692 }
Romain Guy18042c82009-11-06 11:44:55 -0800693 } else if ((requestCode == REQUEST_PICK_APPWIDGET ||
694 requestCode == REQUEST_CREATE_APPWIDGET) && resultCode == RESULT_CANCELED &&
695 data != null) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700696 // Clean up the appWidgetId if we canceled
697 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
698 if (appWidgetId != -1) {
699 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800700 }
701 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800702 }
703
704 @Override
705 protected void onResume() {
706 super.onResume();
707
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800708 mPaused = false;
Joe Onorato7e4ed992009-12-03 13:10:49 -0800709
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800710 if (mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400711 mWorkspaceLoading = true;
712 mModel.startLoader(this, true);
713 mRestoring = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800714 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700715 // When we resume Launcher, a different Activity might be responsible for the app
716 // market intent, so refresh the icon
717 updateAppMarketIcon();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800718 }
719
720 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700721 protected void onPause() {
722 super.onPause();
Michael Jurkaaf442092010-06-10 17:01:57 -0700723 // Some launcher layouts don't have a previous and next view
724 if (mPreviousView != null) {
725 dismissPreview(mPreviousView);
Patrick Dubroyab962b72010-07-26 12:10:10 -0700726 }
727 if (mNextView != null) {
Michael Jurkaaf442092010-06-10 17:01:57 -0700728 dismissPreview(mNextView);
729 }
Joe Onorato24b6fd82009-11-12 13:47:09 -0800730 mDragController.cancelDrag();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700731 }
Romain Guycbb89e42009-06-08 15:52:54 -0700732
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700733 @Override
734 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400735 // Flag the loader to stop early before switching
736 mModel.stopLoader();
Romain Guy13c2e7b2010-03-10 19:45:00 -0800737 mAllAppsGrid.surrender();
Romain Guy13c2e7b2010-03-10 19:45:00 -0800738 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700739 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700740
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800741 // We can't hide the IME if it was forced open. So don't bother
742 /*
743 @Override
744 public void onWindowFocusChanged(boolean hasFocus) {
745 super.onWindowFocusChanged(hasFocus);
746
747 if (hasFocus) {
748 final InputMethodManager inputManager = (InputMethodManager)
749 getSystemService(Context.INPUT_METHOD_SERVICE);
750 WindowManager.LayoutParams lp = getWindow().getAttributes();
751 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
752 android.os.Handler()) {
753 protected void onReceiveResult(int resultCode, Bundle resultData) {
754 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
755 }
756 });
757 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
758 }
759 }
760 */
761
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800762 private boolean acceptFilter() {
763 final InputMethodManager inputManager = (InputMethodManager)
764 getSystemService(Context.INPUT_METHOD_SERVICE);
765 return !inputManager.isFullscreenMode();
766 }
767
768 @Override
769 public boolean onKeyDown(int keyCode, KeyEvent event) {
770 boolean handled = super.onKeyDown(keyCode, event);
771 if (!handled && acceptFilter() && keyCode != KeyEvent.KEYCODE_ENTER) {
772 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
773 keyCode, event);
774 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700775 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700776 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700777 // showSearchDialog()
778 // If there are multiple keystrokes before the search dialog takes focus,
779 // onSearchRequested() will be called for every keystroke,
780 // but it is idempotent, so it's fine.
781 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800782 }
783 }
784
Joe Onorato8a9625e2010-01-28 15:55:35 -0800785 // Eat the long press event so the keyboard doesn't come up.
786 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
787 return true;
788 }
789
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800790 return handled;
791 }
792
Karl Rosaen138a0412009-04-23 19:00:21 -0700793 private String getTypedText() {
794 return mDefaultKeySsb.toString();
795 }
796
797 private void clearTypedText() {
798 mDefaultKeySsb.clear();
799 mDefaultKeySsb.clearSpans();
800 Selection.setSelection(mDefaultKeySsb, 0);
801 }
802
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800803 /**
804 * Restores the previous state, if it exists.
805 *
806 * @param savedState The previous state.
807 */
808 private void restoreState(Bundle savedState) {
809 if (savedState == null) {
810 return;
811 }
812
Joe Onorato3a8820b2009-11-10 15:06:42 -0800813 final boolean allApps = savedState.getBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, false);
814 if (allApps) {
815 showAllApps(false);
816 }
817
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800818 final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
819 if (currentScreen > -1) {
Michael Jurka0142d492010-08-25 17:46:15 -0700820 mWorkspace.setCurrentPage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800821 }
822
823 final int addScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
824 if (addScreen > -1) {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700825 mAddItemCoordinates = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800826 mAddItemCellInfo = new CellLayout.CellInfo();
827 final CellLayout.CellInfo addItemCellInfo = mAddItemCellInfo;
828 addItemCellInfo.valid = true;
829 addItemCellInfo.screen = addScreen;
830 addItemCellInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
831 addItemCellInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
832 addItemCellInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
833 addItemCellInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
Michael Jurkac28de512010-08-13 11:27:44 -0700834 addItemCellInfo.updateOccupiedCells(
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800835 savedState.getBooleanArray(RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS),
836 savedState.getInt(RUNTIME_STATE_PENDING_ADD_COUNT_X),
837 savedState.getInt(RUNTIME_STATE_PENDING_ADD_COUNT_Y));
838 mRestoring = true;
839 }
840
841 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
842 if (renameFolder) {
843 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700844 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800845 mRestoring = true;
846 }
847 }
848
849 /**
850 * Finds all the views we need and configure them properly.
851 */
852 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700853 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -0400854
Romain Guyb1b69f52009-08-10 15:10:15 -0700855 DragLayer dragLayer = (DragLayer) findViewById(R.id.drag_layer);
Joe Onorato00acb122009-08-04 16:04:30 -0400856 dragLayer.setDragController(dragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800857
Joe Onorato7c312c12009-08-13 21:36:53 -0700858 mAllAppsGrid = (AllAppsView)dragLayer.findViewById(R.id.all_apps_view);
Joe Onorato6665c0f2009-09-02 15:27:24 -0700859 mAllAppsGrid.setLauncher(this);
Joe Onorato5162ea92009-09-03 09:39:42 -0700860 mAllAppsGrid.setDragController(dragController);
Romain Guyc16fea72010-03-12 17:17:56 -0800861 ((View) mAllAppsGrid).setWillNotDraw(false); // We don't want a hole punched in our window.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700862 // Manage focusability manually since this thing is always visible (in non-xlarge)
Winson Chungaafa03c2010-06-11 17:34:16 -0700863 ((View) mAllAppsGrid).setFocusable(false);
Joe Onorato7c312c12009-08-13 21:36:53 -0700864
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700865 if (LauncherApplication.isScreenXLarge()) {
866 // They need to be INVISIBLE initially so that they will be measured in the layout.
867 // Otherwise the animations are messed up when we show them for the first time.
868 ((View) mAllAppsGrid).setVisibility(View.INVISIBLE);
869 mHomeCustomizationDrawer.setVisibility(View.INVISIBLE);
870 }
871
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800872 mWorkspace = (Workspace) dragLayer.findViewById(R.id.workspace);
873 final Workspace workspace = mWorkspace;
Joe Onoratof0dde092010-02-16 18:25:23 -0500874 workspace.setHapticFeedbackEnabled(false);
Michael Jurka946ad472010-07-09 18:05:18 -0700875
Joe Onorato7c312c12009-08-13 21:36:53 -0700876 DeleteZone deleteZone = (DeleteZone) dragLayer.findViewById(R.id.delete_zone);
877 mDeleteZone = deleteZone;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800878
Michael Jurka2c3af5f2010-08-03 13:53:20 -0700879 View handleView = findViewById(R.id.all_apps_button);
880 if (handleView != null && handleView instanceof HandleView) {
881 // we don't use handle view in xlarge mode
Michael Jurka7ef4f752010-08-03 16:04:26 -0700882 mHandleView = (HandleView)handleView;
Michael Jurka2c3af5f2010-08-03 13:53:20 -0700883 mHandleView.setLauncher(this);
884 mHandleView.setOnClickListener(this);
885 mHandleView.setOnLongClickListener(this);
886 }
Romain Guy1fbc1c82009-11-09 20:43:08 -0800887
Winson Chung80baf5a2010-08-09 16:03:15 -0700888 if (mCustomizePagedView != null) {
889 mCustomizePagedView.setLauncher(this);
890 mCustomizePagedView.setDragController(dragController);
891 mCustomizePagedView.update();
Michael Jurkaaf442092010-06-10 17:01:57 -0700892 } else {
893 ImageView hotseatLeft = (ImageView) findViewById(R.id.hotseat_left);
894 hotseatLeft.setContentDescription(mHotseatLabels[0]);
895 hotseatLeft.setImageDrawable(mHotseatIcons[0]);
896 ImageView hotseatRight = (ImageView) findViewById(R.id.hotseat_right);
897 hotseatRight.setContentDescription(mHotseatLabels[1]);
898 hotseatRight.setImageDrawable(mHotseatIcons[1]);
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400899
Michael Jurkaaf442092010-06-10 17:01:57 -0700900 mPreviousView = (ImageView) dragLayer.findViewById(R.id.previous_screen);
901 mNextView = (ImageView) dragLayer.findViewById(R.id.next_screen);
Romain Guy1fbc1c82009-11-09 20:43:08 -0800902
Michael Jurkaaf442092010-06-10 17:01:57 -0700903 Drawable previous = mPreviousView.getDrawable();
904 Drawable next = mNextView.getDrawable();
905 mWorkspace.setIndicators(previous, next);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800906
Michael Jurkaaf442092010-06-10 17:01:57 -0700907 mPreviousView.setHapticFeedbackEnabled(false);
908 mPreviousView.setOnLongClickListener(this);
909 mNextView.setHapticFeedbackEnabled(false);
910 mNextView.setOnLongClickListener(this);
911 }
Romain Guy1fbc1c82009-11-09 20:43:08 -0800912
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800913 workspace.setOnLongClickListener(this);
Joe Onorato00acb122009-08-04 16:04:30 -0400914 workspace.setDragController(dragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800915 workspace.setLauncher(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800916
917 deleteZone.setLauncher(this);
Joe Onorato00acb122009-08-04 16:04:30 -0400918 deleteZone.setDragController(dragController);
Michael Jurka54f7ac32010-08-02 13:56:46 -0700919 int deleteZoneHandleId;
920 if (LauncherApplication.isScreenXLarge()) {
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700921 deleteZoneHandleId = R.id.all_apps_button;
Michael Jurka54f7ac32010-08-02 13:56:46 -0700922 } else {
923 deleteZoneHandleId = R.id.all_apps_button_cluster;
924 }
Michael Jurkaaf442092010-06-10 17:01:57 -0700925 deleteZone.setHandle(findViewById(deleteZoneHandleId));
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700926 dragController.addDragListener(deleteZone);
927
928 ApplicationInfoDropTarget infoButton = (ApplicationInfoDropTarget)findViewById(R.id.info_button);
929 if (infoButton != null) {
930 infoButton.setLauncher(this);
931 infoButton.setHandle(findViewById(R.id.configure_button));
932 infoButton.setDragColor(getResources().getColor(R.color.app_info_filter));
933 dragController.addDragListener(infoButton);
934 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800935
Joe Onorato00acb122009-08-04 16:04:30 -0400936 dragController.setDragScoller(workspace);
Joe Onorato00acb122009-08-04 16:04:30 -0400937 dragController.setScrollView(dragLayer);
Romain Guyea3763c2010-01-11 18:02:04 -0800938 dragController.setMoveTarget(workspace);
Jason Samsfd22dac2009-09-20 17:24:16 -0700939
Joe Onorato00acb122009-08-04 16:04:30 -0400940 // The order here is bottom to top.
941 dragController.addDropTarget(workspace);
942 dragController.addDropTarget(deleteZone);
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700943 if (infoButton != null) {
944 dragController.addDropTarget(infoButton);
945 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800946 }
947
Romain Guy8a73c512009-11-09 19:19:59 -0800948 @SuppressWarnings({"UnusedDeclaration"})
949 public void previousScreen(View v) {
Joe Onorato61597bd2009-11-19 12:51:57 -0800950 if (!isAllAppsVisible()) {
951 mWorkspace.scrollLeft();
952 }
Romain Guy8a73c512009-11-09 19:19:59 -0800953 }
954
955 @SuppressWarnings({"UnusedDeclaration"})
956 public void nextScreen(View v) {
Joe Onorato61597bd2009-11-19 12:51:57 -0800957 if (!isAllAppsVisible()) {
958 mWorkspace.scrollRight();
959 }
Romain Guy8a73c512009-11-09 19:19:59 -0800960 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400961
962 @SuppressWarnings({"UnusedDeclaration"})
963 public void launchHotSeat(View v) {
Daniel Sandler3e9454a2010-05-24 11:22:41 -0400964 if (isAllAppsVisible()) return;
965
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400966 int index = -1;
967 if (v.getId() == R.id.hotseat_left) {
968 index = 0;
969 } else if (v.getId() == R.id.hotseat_right) {
970 index = 1;
971 }
972
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400973 // reload these every tap; you never know when they might change
974 loadHotseats();
975 if (index >= 0 && index < mHotseats.length && mHotseats[index] != null) {
976 Intent intent = mHotseats[index];
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400977 startActivitySafely(
978 mHotseats[index],
979 "hotseat"
980 );
981 }
982 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700983
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800984 /**
985 * Creates a view representing a shortcut.
986 *
987 * @param info The data structure describing the shortcut.
988 *
989 * @return A View inflated from R.layout.application.
990 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800991 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800992 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -0700993 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800994 }
995
996 /**
997 * Creates a view representing a shortcut inflated from the specified resource.
998 *
999 * @param layoutResId The id of the XML layout used to create the shortcut.
1000 * @param parent The group the shortcut belongs to.
1001 * @param info The data structure describing the shortcut.
1002 *
1003 * @return A View inflated from layoutResId.
1004 */
Joe Onorato0589f0f2010-02-08 13:44:00 -08001005 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001006 TextView favorite = (TextView) mInflater.inflate(layoutResId, parent, false);
1007
Joe Onorato0589f0f2010-02-08 13:44:00 -08001008 favorite.setCompoundDrawablesWithIntrinsicBounds(null,
1009 new FastBitmapDrawable(info.getIcon(mIconCache)),
1010 null, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001011 favorite.setText(info.title);
1012 favorite.setTag(info);
1013 favorite.setOnClickListener(this);
1014
1015 return favorite;
1016 }
1017
1018 /**
1019 * Add an application shortcut to the workspace.
1020 *
1021 * @param data The intent describing the application.
1022 * @param cellInfo The position on screen where to create the shortcut.
1023 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04001024 void completeAddApplication(Context context, Intent data, CellLayout.CellInfo cellInfo) {
Michael Jurka0142d492010-08-25 17:46:15 -07001025 cellInfo.screen = mWorkspace.getCurrentPage();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001026 if (!findSingleSlot(cellInfo)) return;
1027
Joe Onorato0589f0f2010-02-08 13:44:00 -08001028 final ShortcutInfo info = mModel.getShortcutInfo(context.getPackageManager(),
1029 data, context);
1030
Romain Guy73b979d2009-06-09 12:57:21 -07001031 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -08001032 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001033 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001034 info.container = ItemInfo.NO_ID;
1035 mWorkspace.addApplicationShortcut(info, cellInfo, isWorkspaceLocked());
1036 } else {
1037 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001038 }
1039 }
Romain Guycbb89e42009-06-08 15:52:54 -07001040
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001041 /**
1042 * Add a shortcut to the workspace.
1043 *
1044 * @param data The intent describing the shortcut.
1045 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001046 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04001047 private void completeAddShortcut(Intent data, CellLayout.CellInfo cellInfo) {
Michael Jurka0142d492010-08-25 17:46:15 -07001048 cellInfo.screen = mWorkspace.getCurrentPage();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001049 if (!findSingleSlot(cellInfo)) return;
Romain Guycbb89e42009-06-08 15:52:54 -07001050
Joe Onorato0589f0f2010-02-08 13:44:00 -08001051 final ShortcutInfo info = mModel.addShortcut(this, data, cellInfo, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001052
1053 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001054 final View view = createShortcut(info);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001055 mWorkspace.addInCurrentScreen(view, cellInfo.cellX, cellInfo.cellY, 1, 1,
1056 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001057 }
1058 }
1059
Romain Guycbb89e42009-06-08 15:52:54 -07001060
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001061 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001062 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001063 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001064 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001065 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001066 */
Michael Jurkaaf442092010-06-10 17:01:57 -07001067 private void completeAddAppWidget(int appWidgetId, CellLayout.CellInfo cellInfo) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001068 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Romain Guycbb89e42009-06-08 15:52:54 -07001069
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001070 // Calculate the grid spans needed to fit this widget
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001071 CellLayout layout = (CellLayout) mWorkspace.getChildAt(cellInfo.screen);
Patrick Dubroy8f86ddc2010-07-16 13:55:32 -07001072 int[] spans = layout.rectToCell(appWidgetInfo.minWidth, appWidgetInfo.minHeight, null);
Romain Guycbb89e42009-06-08 15:52:54 -07001073
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001074 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001075 // We have saved the position to which the widget was dragged-- this really only matters
1076 // if we are placing widgets on a "spring-loaded" screen
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001077 final int[] xy = mCellCoordinates;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001078
1079 // For now, we don't save the coordinate where we dropped the icon because we're not
1080 // supporting spring-loaded mini-screens; however, leaving the ability to directly place
1081 // a widget on the home screen in case we want to add it in the future
1082 final int[] xyTouch = null;
1083 //final int[] xyTouch = mAddItemCoordinates;
1084 boolean findNearestVacantAreaFailed = false;
1085 if (xyTouch != null) {
1086 CellLayout screen = (CellLayout) mWorkspace.getChildAt(cellInfo.screen);
1087 int[] result = screen.findNearestVacantArea(
1088 mAddItemCoordinates[0], mAddItemCoordinates[1],
1089 spans[0], spans[1], cellInfo, xy);
1090 findNearestVacantAreaFailed = (result == null);
1091 }
1092
1093 if (findNearestVacantAreaFailed ||
1094 (xyTouch == null && !findSlot(cellInfo, xy, spans[0], spans[1]))) {
Romain Guy18042c82009-11-06 11:44:55 -08001095 if (appWidgetId != -1) mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1096 return;
1097 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001098
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001099 // Build Launcher-specific widget info and save to database
1100 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001101 launcherInfo.spanX = spans[0];
1102 launcherInfo.spanY = spans[1];
Romain Guycbb89e42009-06-08 15:52:54 -07001103
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001104 LauncherModel.addItemToDatabase(this, launcherInfo,
1105 LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurkaa63c4522010-08-19 13:52:27 -07001106 cellInfo.screen, xy[0], xy[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001107
1108 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001109 mDesktopItems.add(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001110
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001111 // Perform actual inflation because we're live
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001112 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001113
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001114 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001115 launcherInfo.hostView.setTag(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001116
Michael Jurkaa63c4522010-08-19 13:52:27 -07001117 mWorkspace.addInScreen(launcherInfo.hostView, cellInfo.screen, xy[0], xy[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001118 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001119 }
1120 }
Romain Guycbb89e42009-06-08 15:52:54 -07001121
Joe Onorato9c1289c2009-08-17 11:03:03 -04001122 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
1123 mDesktopItems.remove(launcherInfo);
1124 launcherInfo.hostView = null;
1125 }
1126
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001127 public LauncherAppWidgetHost getAppWidgetHost() {
1128 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001129 }
Romain Guycbb89e42009-06-08 15:52:54 -07001130
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001131 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001132 getWindow().closeAllPanels();
1133
1134 try {
1135 dismissDialog(DIALOG_CREATE_SHORTCUT);
1136 // Unlock the workspace if the dialog was showing
1137 } catch (Exception e) {
1138 // An exception is thrown if the dialog is not visible, which is fine
1139 }
1140
1141 try {
1142 dismissDialog(DIALOG_RENAME_FOLDER);
1143 // Unlock the workspace if the dialog was showing
1144 } catch (Exception e) {
1145 // An exception is thrown if the dialog is not visible, which is fine
1146 }
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001147
1148 // Whatever we were doing is hereby canceled.
1149 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001150 }
1151
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001152 @Override
1153 protected void onNewIntent(Intent intent) {
1154 super.onNewIntent(intent);
1155
1156 // Close the menu
1157 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001158 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001159 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001160
Joe Onorato14f122b2009-11-19 14:06:36 -08001161 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1162 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
1163 boolean allAppsVisible = isAllAppsVisible();
Michael Jurka01f0ed42010-08-20 00:41:17 -07001164 boolean customizationDrawerVisible = isCustomizationDrawerVisible();
1165
Michael Jurka4cb37242010-08-09 21:05:32 -07001166 // in all these cases, only animate if we're already on home
1167 if (LauncherApplication.isScreenXLarge()) {
Michael Jurka99229f62010-09-09 11:49:32 -07001168 mWorkspace.unshrink(alreadyOnHome);
1169 }
1170 if (!mWorkspace.isDefaultPageShowing()) {
Michael Jurka4cb37242010-08-09 21:05:32 -07001171 // on the phone, we don't animate the change to the workspace if all apps is visible
Michael Jurka99229f62010-09-09 11:49:32 -07001172 mWorkspace.moveToDefaultScreen(
1173 alreadyOnHome && (LauncherApplication.isScreenXLarge() || !allAppsVisible));
Joe Onorato3a8820b2009-11-10 15:06:42 -08001174 }
Joe Onorato14f122b2009-11-19 14:06:36 -08001175 closeAllApps(alreadyOnHome && allAppsVisible);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07001176 hideCustomizationDrawer(alreadyOnHome);
Romain Guy1dd3a072009-07-16 13:21:01 -07001177
Joe Onorato3a8820b2009-11-10 15:06:42 -08001178 final View v = getWindow().peekDecorView();
1179 if (v != null && v.getWindowToken() != null) {
1180 InputMethodManager imm = (InputMethodManager)getSystemService(
1181 INPUT_METHOD_SERVICE);
1182 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001183 }
1184 }
1185 }
1186
1187 @Override
1188 protected void onRestoreInstanceState(Bundle savedInstanceState) {
1189 // Do not call super here
1190 mSavedInstanceState = savedInstanceState;
Michael Jurka946ad472010-07-09 18:05:18 -07001191
1192 if (mHomeCustomizationDrawer != null) {
1193 String cur = savedInstanceState.getString("currentTab");
1194 if (cur != null) {
1195 mHomeCustomizationDrawer.setCurrentTabByTag(cur);
1196 }
1197 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001198 }
1199
1200 @Override
1201 protected void onSaveInstanceState(Bundle outState) {
Michael Jurka0142d492010-08-25 17:46:15 -07001202 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001203
1204 final ArrayList<Folder> folders = mWorkspace.getOpenFolders();
1205 if (folders.size() > 0) {
1206 final int count = folders.size();
1207 long[] ids = new long[count];
1208 for (int i = 0; i < count; i++) {
1209 final FolderInfo info = folders.get(i).getInfo();
1210 ids[i] = info.id;
1211 }
1212 outState.putLongArray(RUNTIME_STATE_USER_FOLDERS, ids);
1213 } else {
1214 super.onSaveInstanceState(outState);
1215 }
1216
Joe Onoratofb0ca672009-09-14 17:55:46 -04001217 // TODO should not do this if the drawer is currently closing.
Joe Onorato3a8820b2009-11-10 15:06:42 -08001218 if (isAllAppsVisible()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001219 outState.putBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, true);
Romain Guy5a941392009-04-28 15:18:25 -07001220 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001221
1222 if (mAddItemCellInfo != null && mAddItemCellInfo.valid && mWaitingForResult) {
1223 final CellLayout.CellInfo addItemCellInfo = mAddItemCellInfo;
1224 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(addItemCellInfo.screen);
1225
1226 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, addItemCellInfo.screen);
1227 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, addItemCellInfo.cellX);
1228 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, addItemCellInfo.cellY);
1229 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, addItemCellInfo.spanX);
1230 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, addItemCellInfo.spanY);
1231 outState.putInt(RUNTIME_STATE_PENDING_ADD_COUNT_X, layout.getCountX());
1232 outState.putInt(RUNTIME_STATE_PENDING_ADD_COUNT_Y, layout.getCountY());
1233 outState.putBooleanArray(RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS,
Patrick Dubroy6569f2c2010-07-12 14:25:18 -07001234 layout.getOccupiedCellsFlattened());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001235 }
1236
1237 if (mFolderInfo != null && mWaitingForResult) {
1238 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1239 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1240 }
Michael Jurka946ad472010-07-09 18:05:18 -07001241
1242 if (mHomeCustomizationDrawer != null) {
1243 String currentTabTag = mHomeCustomizationDrawer.getCurrentTabTag();
1244 if (currentTabTag != null) {
1245 outState.putString("currentTab", currentTabTag);
1246 }
1247 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001248 }
1249
1250 @Override
1251 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001252 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001253
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001254 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001255 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001256 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001257 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001258 }
1259
1260 TextKeyListener.getInstance().release();
1261
Joe Onorato9c1289c2009-08-17 11:03:03 -04001262 mModel.stopLoader();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001263
Joe Onorato9c1289c2009-08-17 11:03:03 -04001264 unbindDesktopItems();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001265
1266 getContentResolver().unregisterContentObserver(mWidgetObserver);
Winson Chungaafa03c2010-06-11 17:34:16 -07001267
Patrick Dubroyab962b72010-07-26 12:10:10 -07001268 // Some launcher layouts don't have a previous and next view
1269 if (mPreviousView != null) {
1270 dismissPreview(mPreviousView);
1271 }
1272 if (mNextView != null) {
1273 dismissPreview(mNextView);
1274 }
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001275
1276 unregisterReceiver(mCloseSystemDialogsReceiver);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001277 }
1278
1279 @Override
1280 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001281 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001282 super.startActivityForResult(intent, requestCode);
1283 }
1284
1285 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001286 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001287 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001288
Joe Onorato7bb17492009-09-24 17:51:01 -07001289 closeAllApps(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001290
Karl Rosaen138a0412009-04-23 19:00:21 -07001291 if (initialQuery == null) {
1292 // Use any text typed in the launcher as the initial query
1293 initialQuery = getTypedText();
1294 clearTypedText();
1295 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001296 if (appSearchData == null) {
1297 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +00001298 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001299 }
Romain Guycbb89e42009-06-08 15:52:54 -07001300
Karl Rosaen138a0412009-04-23 19:00:21 -07001301 final SearchManager searchManager =
1302 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Karl Rosaen138a0412009-04-23 19:00:21 -07001303 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Romain Guycbb89e42009-06-08 15:52:54 -07001304 appSearchData, globalSearch);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001305 }
1306
1307 @Override
1308 public boolean onCreateOptionsMenu(Menu menu) {
Patrick Dubroy5905bca2010-09-08 22:43:38 -07001309 if (isWorkspaceLocked()) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001310 return false;
1311 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001312
1313 super.onCreateOptionsMenu(menu);
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001314
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001315 menu.add(MENU_GROUP_ADD, MENU_ADD, 0, R.string.menu_add)
1316 .setIcon(android.R.drawable.ic_menu_add)
1317 .setAlphabeticShortcut('A');
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001318 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001319 .setIcon(android.R.drawable.ic_menu_gallery)
1320 .setAlphabeticShortcut('W');
1321 menu.add(0, MENU_SEARCH, 0, R.string.menu_search)
1322 .setIcon(android.R.drawable.ic_search_category_default)
1323 .setAlphabeticShortcut(SearchManager.MENU_KEY);
1324 menu.add(0, MENU_NOTIFICATIONS, 0, R.string.menu_notifications)
1325 .setIcon(com.android.internal.R.drawable.ic_menu_notifications)
1326 .setAlphabeticShortcut('N');
1327
1328 final Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
Romain Guy5a941392009-04-28 15:18:25 -07001329 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
1330 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001331
1332 menu.add(0, MENU_SETTINGS, 0, R.string.menu_settings)
1333 .setIcon(android.R.drawable.ic_menu_preferences).setAlphabeticShortcut('P')
1334 .setIntent(settings);
1335
1336 return true;
1337 }
1338
1339 @Override
1340 public boolean onPrepareOptionsMenu(Menu menu) {
1341 super.onPrepareOptionsMenu(menu);
1342
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001343 // If all apps is animating, don't show the menu, because we don't know
1344 // which one to show.
Patrick Dubroyff5f0402010-07-26 15:23:26 -07001345 if (mAllAppsGrid.isAnimating()) {
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001346 return false;
1347 }
1348
1349 // Only show the add and wallpaper options when we're not in all apps.
Patrick Dubroyff5f0402010-07-26 15:23:26 -07001350 boolean visible = !mAllAppsGrid.isVisible();
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001351 menu.setGroupVisible(MENU_GROUP_ADD, visible);
1352 menu.setGroupVisible(MENU_GROUP_WALLPAPER, visible);
1353
1354 // Disable add if the workspace is full.
1355 if (visible) {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001356 mMenuAddInfo = mWorkspace.updateOccupiedCellsForCurrentScreen(null);
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001357 menu.setGroupEnabled(MENU_GROUP_ADD, mMenuAddInfo != null && mMenuAddInfo.valid);
1358 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001359
1360 return true;
1361 }
1362
Michael Jurka0e260592010-06-30 17:07:39 -07001363 // we need to initialize mAddItemCellInfo before adding something to the homescreen -- when
1364 // using the settings menu to add an item, something similar happens in showAddDialog
1365 public void prepareAddItemFromHomeCustomizationDrawer() {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001366 mMenuAddInfo = mWorkspace.updateOccupiedCellsForCurrentScreen(null);
Michael Jurka0e260592010-06-30 17:07:39 -07001367 mAddItemCellInfo = mMenuAddInfo;
1368 }
1369
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001370 @Override
1371 public boolean onOptionsItemSelected(MenuItem item) {
1372 switch (item.getItemId()) {
1373 case MENU_ADD:
1374 addItems();
1375 return true;
1376 case MENU_WALLPAPER_SETTINGS:
1377 startWallpaper();
1378 return true;
1379 case MENU_SEARCH:
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001380 onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001381 return true;
1382 case MENU_NOTIFICATIONS:
1383 showNotifications();
1384 return true;
1385 }
1386
1387 return super.onOptionsItemSelected(item);
1388 }
Romain Guycbb89e42009-06-08 15:52:54 -07001389
Karl Rosaen138a0412009-04-23 19:00:21 -07001390 /**
1391 * Indicates that we want global search for this activity by setting the globalSearch
1392 * argument for {@link #startSearch} to true.
1393 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001394
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001395 @Override
1396 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001397 startSearch(null, false, null, true);
Karl Rosaen138a0412009-04-23 19:00:21 -07001398 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001399 }
1400
Joe Onorato9c1289c2009-08-17 11:03:03 -04001401 public boolean isWorkspaceLocked() {
1402 return mWorkspaceLoading || mWaitingForResult;
1403 }
1404
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001405 private void addItems() {
Patrick Dubroy558654c2010-07-23 16:48:11 -07001406 if (LauncherApplication.isScreenXLarge()) {
1407 // Animate the widget chooser up from the bottom of the screen
1408 if (!isCustomizationDrawerVisible()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07001409 showCustomizationDrawer(true);
Patrick Dubroy558654c2010-07-23 16:48:11 -07001410 }
1411 } else {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001412 closeAllApps(true);
Patrick Dubroy558654c2010-07-23 16:48:11 -07001413 showAddDialog(mMenuAddInfo);
1414 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001415 }
1416
Michael Jurkaa63c4522010-08-19 13:52:27 -07001417 void addAppWidgetFromDrop(ComponentName appWidgetProvider, CellLayout.CellInfo cellInfo,
1418 int[] position) {
Michael Jurkaaf442092010-06-10 17:01:57 -07001419 mAddItemCellInfo = cellInfo;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001420
1421 // only set mAddItemCoordinates if we dropped on home screen in "spring-loaded" manner
1422 mAddItemCoordinates = position;
Michael Jurkaaf442092010-06-10 17:01:57 -07001423 int appWidgetId = getAppWidgetHost().allocateAppWidgetId();
1424 AppWidgetManager.getInstance(this).bindAppWidgetId(appWidgetId, appWidgetProvider);
1425 addAppWidgetImpl(appWidgetId);
1426 }
1427
1428 void addAppWidgetFromPick(Intent data) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001429 // TODO: catch bad widget exception when sent
1430 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurkaaf442092010-06-10 17:01:57 -07001431 // TODO: Is this log message meaningful?
1432 if (LOGD) Log.d(TAG, "dumping extras content=" + data.getExtras());
1433 addAppWidgetImpl(appWidgetId);
1434 }
1435
1436 void addAppWidgetImpl(int appWidgetId) {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001437 AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001438
Bjorn Bringert7984c942009-12-09 15:38:25 +00001439 if (appWidget.configure != null) {
1440 // Launch over to configure widget, if needed
1441 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
1442 intent.setComponent(appWidget.configure);
1443 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
1444
Romain Guy8e633c52010-03-04 12:51:36 -08001445 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001446 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001447 // Otherwise just add it
Michael Jurkaaf442092010-06-10 17:01:57 -07001448 completeAddAppWidget(appWidgetId, mAddItemCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001449 }
1450 }
Romain Guycbb89e42009-06-08 15:52:54 -07001451
Joe Onoratodeb98af2010-02-19 14:59:39 -08001452 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001453 // Handle case where user selected "Applications"
1454 String applicationName = getResources().getString(R.string.group_applications);
1455 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001456
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001457 if (applicationName != null && applicationName.equals(shortcutName)) {
1458 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1459 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001460
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001461 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1462 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Joe Onoratodeb98af2010-02-19 14:59:39 -08001463 startActivityForResult(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001464 } else {
Joe Onoratodeb98af2010-02-19 14:59:39 -08001465 startActivityForResult(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001466 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001467 }
1468
Winson Chung24ab2f12010-09-16 14:10:47 -07001469 void processWallpaper(Intent intent) {
1470 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1471 }
1472
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001473 void addLiveFolder(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001474 // Handle case where user selected "Folder"
Jeffrey Sharkeyc4bbd0a2009-03-24 22:47:52 -07001475 String folderName = getResources().getString(R.string.group_folder);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001476 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001477
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001478 if (folderName != null && folderName.equals(shortcutName)) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001479 addFolder();
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001480 } else {
1481 startActivityForResult(intent, REQUEST_CREATE_LIVE_FOLDER);
1482 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001483 }
1484
Joe Onorato9c1289c2009-08-17 11:03:03 -04001485 void addFolder() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001486 UserFolderInfo folderInfo = new UserFolderInfo();
1487 folderInfo.title = getText(R.string.folder_name);
1488
1489 CellLayout.CellInfo cellInfo = mAddItemCellInfo;
Michael Jurka0142d492010-08-25 17:46:15 -07001490 cellInfo.screen = mWorkspace.getCurrentPage();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001491 if (!findSingleSlot(cellInfo)) return;
1492
1493 // Update the model
Joe Onorato9c1289c2009-08-17 11:03:03 -04001494 LauncherModel.addItemToDatabase(this, folderInfo,
1495 LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurka0142d492010-08-25 17:46:15 -07001496 mWorkspace.getCurrentPage(), cellInfo.cellX, cellInfo.cellY, false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001497 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001498
1499 // Create the view
1500 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07001501 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001502 mWorkspace.addInCurrentScreen(newFolder,
Joe Onorato9c1289c2009-08-17 11:03:03 -04001503 cellInfo.cellX, cellInfo.cellY, 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001504 }
Romain Guycbb89e42009-06-08 15:52:54 -07001505
Joe Onorato9c1289c2009-08-17 11:03:03 -04001506 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001507 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001508 }
1509
1510 private void completeAddLiveFolder(Intent data, CellLayout.CellInfo cellInfo) {
Michael Jurka0142d492010-08-25 17:46:15 -07001511 cellInfo.screen = mWorkspace.getCurrentPage();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001512 if (!findSingleSlot(cellInfo)) return;
1513
1514 final LiveFolderInfo info = addLiveFolder(this, data, cellInfo, false);
1515
1516 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001517 final View view = LiveFolderIcon.fromXml(R.layout.live_folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07001518 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001519 mWorkspace.addInCurrentScreen(view, cellInfo.cellX, cellInfo.cellY, 1, 1,
1520 isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001521 }
1522 }
1523
1524 static LiveFolderInfo addLiveFolder(Context context, Intent data,
1525 CellLayout.CellInfo cellInfo, boolean notify) {
1526
1527 Intent baseIntent = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT);
1528 String name = data.getStringExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME);
1529
1530 Drawable icon = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001531 Intent.ShortcutIconResource iconResource = null;
1532
1533 Parcelable extra = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON);
1534 if (extra != null && extra instanceof Intent.ShortcutIconResource) {
1535 try {
1536 iconResource = (Intent.ShortcutIconResource) extra;
1537 final PackageManager packageManager = context.getPackageManager();
1538 Resources resources = packageManager.getResourcesForApplication(
1539 iconResource.packageName);
1540 final int id = resources.getIdentifier(iconResource.resourceName, null, null);
1541 icon = resources.getDrawable(id);
1542 } catch (Exception e) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001543 Log.w(TAG, "Could not load live folder icon: " + extra);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001544 }
1545 }
1546
1547 if (icon == null) {
1548 icon = context.getResources().getDrawable(R.drawable.ic_launcher_folder);
1549 }
1550
1551 final LiveFolderInfo info = new LiveFolderInfo();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001552 info.icon = Utilities.createIconBitmap(icon, context);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001553 info.title = name;
1554 info.iconResource = iconResource;
1555 info.uri = data.getData();
1556 info.baseIntent = baseIntent;
1557 info.displayMode = data.getIntExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE,
1558 LiveFolders.DISPLAY_MODE_GRID);
1559
1560 LauncherModel.addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
1561 cellInfo.screen, cellInfo.cellX, cellInfo.cellY, notify);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001562 sFolders.put(info.id, info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001563
1564 return info;
1565 }
1566
1567 private boolean findSingleSlot(CellLayout.CellInfo cellInfo) {
1568 final int[] xy = new int[2];
1569 if (findSlot(cellInfo, xy, 1, 1)) {
1570 cellInfo.cellX = xy[0];
1571 cellInfo.cellY = xy[1];
1572 return true;
1573 }
1574 return false;
1575 }
1576
1577 private boolean findSlot(CellLayout.CellInfo cellInfo, int[] xy, int spanX, int spanY) {
1578 if (!cellInfo.findCellForSpan(xy, spanX, spanY)) {
Michael Jurkaa63c4522010-08-19 13:52:27 -07001579 CellLayout targetLayout = (CellLayout) mWorkspace.getChildAt(cellInfo.screen);
1580 cellInfo = targetLayout.updateOccupiedCells(null, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001581 if (!cellInfo.findCellForSpan(xy, spanX, spanY)) {
1582 Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show();
1583 return false;
1584 }
1585 }
1586 return true;
1587 }
1588
1589 private void showNotifications() {
1590 final StatusBarManager statusBar = (StatusBarManager) getSystemService(STATUS_BAR_SERVICE);
1591 if (statusBar != null) {
1592 statusBar.expand();
1593 }
1594 }
1595
1596 private void startWallpaper() {
Joe Onoratoe6168662009-11-08 13:39:30 -05001597 closeAllApps(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001598 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001599 Intent chooser = Intent.createChooser(pickWallpaper,
1600 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001601 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1602 // Removed in Eclair MR1
1603// WallpaperManager wm = (WallpaperManager)
1604// getSystemService(Context.WALLPAPER_SERVICE);
1605// WallpaperInfo wi = wm.getWallpaperInfo();
1606// if (wi != null && wi.getSettingsActivity() != null) {
1607// LabeledIntent li = new LabeledIntent(getPackageName(),
1608// R.string.configure_wallpaper, 0);
1609// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1610// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1611// }
Mike Clerona0618e42009-10-22 13:55:21 -07001612 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001613 }
1614
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001615 /**
1616 * Registers various content observers. The current implementation registers
1617 * only a favorites observer to keep track of the favorites applications.
1618 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001619 private void registerContentObservers() {
1620 ContentResolver resolver = getContentResolver();
1621 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1622 true, mWidgetObserver);
1623 }
1624
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001625 @Override
1626 public boolean dispatchKeyEvent(KeyEvent event) {
1627 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1628 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001629 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001630 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001631 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jason Samseb5615d2009-11-30 11:50:10 -08001632 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
Joe Onoratobe386092009-11-17 17:32:16 -08001633 dumpState();
1634 return true;
1635 }
1636 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001637 }
1638 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1639 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001640 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001641 return true;
1642 }
1643 }
1644
1645 return super.dispatchKeyEvent(event);
1646 }
1647
Joe Onorato88ec0992009-11-19 13:16:06 -08001648 @Override
1649 public void onBackPressed() {
1650 if (isAllAppsVisible()) {
1651 closeAllApps(true);
Patrick Dubroy558654c2010-07-23 16:48:11 -07001652 } else if (isCustomizationDrawerVisible()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07001653 hideCustomizationDrawer(true);
Joe Onorato88ec0992009-11-19 13:16:06 -08001654 } else {
1655 closeFolder();
1656 }
Michael Jurkaaf442092010-06-10 17:01:57 -07001657 // Some launcher layouts don't have a previous and next view
1658 if (mPreviousView != null) {
1659 dismissPreview(mPreviousView);
1660 dismissPreview(mNextView);
1661 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001662 }
1663
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001664 private void closeFolder() {
1665 Folder folder = mWorkspace.getOpenFolder();
1666 if (folder != null) {
1667 closeFolder(folder);
1668 }
1669 }
1670
1671 void closeFolder(Folder folder) {
1672 folder.getInfo().opened = false;
1673 ViewGroup parent = (ViewGroup) folder.getParent();
1674 if (parent != null) {
1675 parent.removeView(folder);
Joe Onoratob6341e92009-11-02 10:41:48 -05001676 if (folder instanceof DropTarget) {
1677 // Live folders aren't DropTargets.
1678 mDragController.removeDropTarget((DropTarget)folder);
1679 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001680 }
1681 folder.onClose();
1682 }
1683
1684 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001685 * Re-listen when widgets are reset.
1686 */
1687 private void onAppWidgetReset() {
1688 mAppWidgetHost.startListening();
1689 }
1690
1691 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001692 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1693 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001694 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04001695 private void unbindDesktopItems() {
1696 for (ItemInfo item: mDesktopItems) {
1697 item.unbind();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001698 }
1699 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001700
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001701 /**
1702 * Launches the intent referred by the clicked shortcut.
1703 *
1704 * @param v The view representing the clicked shortcut.
1705 */
1706 public void onClick(View v) {
1707 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001708 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001709 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08001710 final Intent intent = ((ShortcutInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001711 int[] pos = new int[2];
1712 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08001713 intent.setSourceBounds(new Rect(pos[0], pos[1],
1714 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Joe Onoratof984e852010-03-25 09:47:45 -07001715 startActivitySafely(intent, tag);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001716 } else if (tag instanceof FolderInfo) {
1717 handleFolderClick((FolderInfo) tag);
Joe Onorato7404ee42009-07-31 11:54:44 -07001718 } else if (v == mHandleView) {
Joe Onoratofb0ca672009-09-14 17:55:46 -04001719 if (isAllAppsVisible()) {
Joe Onorato7bb17492009-09-24 17:51:01 -07001720 closeAllApps(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001721 } else {
Joe Onorato3a8820b2009-11-10 15:06:42 -08001722 showAllApps(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001723 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001724 }
1725 }
1726
Michael Jurka0e260592010-06-30 17:07:39 -07001727 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07001728 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurka0e260592010-06-30 17:07:39 -07001729 // clicking anywhere on the workspace causes the drawer to slide down
Patrick Dubroy6b509c12010-08-23 15:08:16 -07001730 hideCustomizationDrawer(true);
Michael Jurka0e260592010-06-30 17:07:39 -07001731 return false;
1732 }
1733
Michael Jurkaaf442092010-06-10 17:01:57 -07001734 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001735 * Event handler for the search button
1736 *
1737 * @param v The view that was clicked.
1738 */
1739 public void onClickSearchButton(View v) {
1740 Intent i = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
1741 View button = findViewById(R.id.search_button);
1742 i.setSourceBounds(
1743 new Rect(button.getLeft(), button.getTop(), button.getRight(), button.getBottom()));
1744 startActivity(i);
1745 }
1746
1747 /**
1748 * Event handler for the "gear" button that appears on the home screen, which
Michael Jurkaaf442092010-06-10 17:01:57 -07001749 * enters home screen customization mode.
1750 *
1751 * @param v The view that was clicked.
1752 */
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001753 public void onClickConfigureButton(View v) {
Patrick Dubroy558654c2010-07-23 16:48:11 -07001754 addItems();
Michael Jurkaaf442092010-06-10 17:01:57 -07001755 }
1756
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001757 /**
1758 * Event handler for the "grid" button that appears on the home screen, which
1759 * enters all apps mode.
1760 *
1761 * @param v The view that was clicked.
1762 */
1763 public void onClickAllAppsButton(View v) {
1764 showAllApps(true);
1765 }
1766
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001767 public void onClickAppMarketButton(View v) {
1768 if (mAppMarketIntent != null) {
1769 startActivitySafely(mAppMarketIntent, "app market");
1770 }
1771 }
1772
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001773 void startApplicationDetailsActivity(ComponentName componentName) {
1774 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001775 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
1776 Uri.fromParts("package", packageName, null));
1777 startActivity(intent);
1778 }
1779
Patrick Dubroy5539af72010-09-07 15:22:01 -07001780 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
1781 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
1782 // System applications cannot be installed. For now, show a toast explaining that.
1783 // We may give them the option of disabling apps this way.
1784 int messageId = R.string.uninstall_system_app_text;
1785 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
1786 } else {
1787 String packageName = appInfo.componentName.getPackageName();
1788 String className = appInfo.componentName.getClassName();
1789 Intent intent = new Intent(
1790 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
1791 startActivity(intent);
1792 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001793 }
1794
Joe Onoratof984e852010-03-25 09:47:45 -07001795 void startActivitySafely(Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001796 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1797 try {
1798 startActivity(intent);
1799 } catch (ActivityNotFoundException e) {
1800 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Daniel Sandlerc9b18772010-04-22 14:37:59 -04001801 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001802 } catch (SecurityException e) {
1803 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001804 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001805 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07001806 "or use the exported attribute for this activity. "
1807 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001808 }
1809 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001810
Romain Guy8e633c52010-03-04 12:51:36 -08001811 void startActivityForResultSafely(Intent intent, int requestCode) {
1812 try {
1813 startActivityForResult(intent, requestCode);
1814 } catch (ActivityNotFoundException e) {
1815 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1816 } catch (SecurityException e) {
1817 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1818 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
1819 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
1820 "or use the exported attribute for this activity.", e);
1821 }
1822 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001823
1824 private void handleFolderClick(FolderInfo folderInfo) {
1825 if (!folderInfo.opened) {
1826 // Close any open folder
1827 closeFolder();
1828 // Open the requested folder
1829 openFolder(folderInfo);
1830 } else {
1831 // Find the open folder...
1832 Folder openFolder = mWorkspace.getFolderForTag(folderInfo);
1833 int folderScreen;
1834 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07001835 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001836 // .. and close it
1837 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07001838 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001839 // Close any folder open on the current screen
1840 closeFolder();
1841 // Pull the folder onto this screen
1842 openFolder(folderInfo);
1843 }
1844 }
1845 }
1846 }
1847
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001848 /**
1849 * Opens the user fodler described by the specified tag. The opening of the folder
1850 * is animated relative to the specified View. If the View is null, no animation
1851 * is played.
1852 *
1853 * @param folderInfo The FolderInfo describing the folder to open.
1854 */
Winson Chungaafa03c2010-06-11 17:34:16 -07001855 public void openFolder(FolderInfo folderInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001856 Folder openFolder;
1857
1858 if (folderInfo instanceof UserFolderInfo) {
1859 openFolder = UserFolder.fromXml(this);
1860 } else if (folderInfo instanceof LiveFolderInfo) {
Joe Onoratoa5902522009-07-30 13:37:37 -07001861 openFolder = com.android.launcher2.LiveFolder.fromXml(this, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001862 } else {
1863 return;
1864 }
1865
Joe Onorato00acb122009-08-04 16:04:30 -04001866 openFolder.setDragController(mDragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001867 openFolder.setLauncher(this);
1868
1869 openFolder.bind(folderInfo);
1870 folderInfo.opened = true;
1871
Winson Chungaafa03c2010-06-11 17:34:16 -07001872 mWorkspace.addInFullScreen(openFolder, folderInfo.screen);
1873
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001874 openFolder.onOpen();
1875 }
1876
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001877 public boolean onLongClick(View v) {
Romain Guy1fbc1c82009-11-09 20:43:08 -08001878 switch (v.getId()) {
1879 case R.id.previous_screen:
Joe Onorato0d44e942009-11-16 18:20:51 -08001880 if (!isAllAppsVisible()) {
1881 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1882 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Romain Guyf8e6a802009-12-07 17:48:02 -08001883 showPreviews(v);
Joe Onorato0d44e942009-11-16 18:20:51 -08001884 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08001885 return true;
1886 case R.id.next_screen:
Joe Onorato0d44e942009-11-16 18:20:51 -08001887 if (!isAllAppsVisible()) {
1888 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1889 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Romain Guyf8e6a802009-12-07 17:48:02 -08001890 showPreviews(v);
1891 }
1892 return true;
1893 case R.id.all_apps_button:
1894 if (!isAllAppsVisible()) {
1895 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1896 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
1897 showPreviews(v);
Joe Onorato0d44e942009-11-16 18:20:51 -08001898 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08001899 return true;
1900 }
1901
Joe Onorato9c1289c2009-08-17 11:03:03 -04001902 if (isWorkspaceLocked()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001903 return false;
1904 }
1905
1906 if (!(v instanceof CellLayout)) {
1907 v = (View) v.getParent();
1908 }
1909
1910 CellLayout.CellInfo cellInfo = (CellLayout.CellInfo) v.getTag();
1911
1912 // This happens when long clicking an item with the dpad/trackball
1913 if (cellInfo == null) {
1914 return true;
1915 }
1916
1917 if (mWorkspace.allowLongPress()) {
1918 if (cellInfo.cell == null) {
1919 if (cellInfo.valid) {
1920 // User long pressed on empty space
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001921 mWorkspace.setAllowLongPress(false);
Joe Onoratof0dde092010-02-16 18:25:23 -05001922 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1923 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001924 showAddDialog(cellInfo);
1925 }
1926 } else {
1927 if (!(cellInfo.cell instanceof Folder)) {
1928 // User long pressed on an item
Joe Onorato0d44e942009-11-16 18:20:51 -08001929 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1930 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001931 mWorkspace.startDrag(cellInfo);
1932 }
1933 }
1934 }
1935 return true;
1936 }
1937
Romain Guye6b8e2f2009-11-10 11:56:55 -08001938 @SuppressWarnings({"unchecked"})
Romain Guy9d31e9f2009-11-11 18:54:28 -08001939 private void dismissPreview(final View v) {
1940 final PopupWindow window = (PopupWindow) v.getTag();
Romain Guy1fbc1c82009-11-09 20:43:08 -08001941 if (window != null) {
Romain Guy9d31e9f2009-11-11 18:54:28 -08001942 window.setOnDismissListener(new PopupWindow.OnDismissListener() {
1943 public void onDismiss() {
1944 ViewGroup group = (ViewGroup) v.getTag(R.id.workspace);
1945 int count = group.getChildCount();
1946 for (int i = 0; i < count; i++) {
1947 ((ImageView) group.getChildAt(i)).setImageDrawable(null);
1948 }
Romain Guy9d31e9f2009-11-11 18:54:28 -08001949 ArrayList<Bitmap> bitmaps = (ArrayList<Bitmap>) v.getTag(R.id.icon);
1950 for (Bitmap bitmap : bitmaps) bitmap.recycle();
1951
1952 v.setTag(R.id.workspace, null);
1953 v.setTag(R.id.icon, null);
1954 window.setOnDismissListener(null);
1955 }
1956 });
Romain Guy1fbc1c82009-11-09 20:43:08 -08001957 window.dismiss();
Romain Guy1fbc1c82009-11-09 20:43:08 -08001958 }
1959 v.setTag(null);
1960 }
1961
Romain Guyf8e6a802009-12-07 17:48:02 -08001962 private void showPreviews(View anchor) {
Romain Guy9d31e9f2009-11-11 18:54:28 -08001963 showPreviews(anchor, 0, mWorkspace.getChildCount());
Romain Guy1fbc1c82009-11-09 20:43:08 -08001964 }
1965
Romain Guya6abce82009-11-10 02:54:41 -08001966 private void showPreviews(final View anchor, int start, int end) {
Romain Guyf8e6a802009-12-07 17:48:02 -08001967 final Resources resources = getResources();
1968 final Workspace workspace = mWorkspace;
Romain Guy1fbc1c82009-11-09 20:43:08 -08001969
Romain Guya6abce82009-11-10 02:54:41 -08001970 CellLayout cell = ((CellLayout) workspace.getChildAt(start));
Winson Chungaafa03c2010-06-11 17:34:16 -07001971
Romain Guy9d31e9f2009-11-11 18:54:28 -08001972 float max = workspace.getChildCount();
Winson Chungaafa03c2010-06-11 17:34:16 -07001973
Romain Guyf8e6a802009-12-07 17:48:02 -08001974 final Rect r = new Rect();
Romain Guy9d31e9f2009-11-11 18:54:28 -08001975 resources.getDrawable(R.drawable.preview_background).getPadding(r);
Romain Guye6b8e2f2009-11-10 11:56:55 -08001976 int extraW = (int) ((r.left + r.right) * max);
1977 int extraH = r.top + r.bottom;
Romain Guya6abce82009-11-10 02:54:41 -08001978
1979 int aW = cell.getWidth() - extraW;
1980 float w = aW / max;
1981
1982 int width = cell.getWidth();
1983 int height = cell.getHeight();
1984 int x = cell.getLeftPadding();
1985 int y = cell.getTopPadding();
1986 width -= (x + cell.getRightPadding());
1987 height -= (y + cell.getBottomPadding());
1988
1989 float scale = w / width;
1990
1991 int count = end - start;
1992
1993 final float sWidth = width * scale;
1994 float sHeight = height * scale;
1995
Romain Guye6b8e2f2009-11-10 11:56:55 -08001996 LinearLayout preview = new LinearLayout(this);
Romain Guya6abce82009-11-10 02:54:41 -08001997
Romain Guye6b8e2f2009-11-10 11:56:55 -08001998 PreviewTouchHandler handler = new PreviewTouchHandler(anchor);
1999 ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>(count);
Romain Guya6abce82009-11-10 02:54:41 -08002000
2001 for (int i = start; i < end; i++) {
Romain Guye6b8e2f2009-11-10 11:56:55 -08002002 ImageView image = new ImageView(this);
Romain Guya6abce82009-11-10 02:54:41 -08002003 cell = (CellLayout) workspace.getChildAt(i);
2004
Romain Guyf8e6a802009-12-07 17:48:02 -08002005 final Bitmap bitmap = Bitmap.createBitmap((int) sWidth, (int) sHeight,
Romain Guye6b8e2f2009-11-10 11:56:55 -08002006 Bitmap.Config.ARGB_8888);
Romain Guyf8e6a802009-12-07 17:48:02 -08002007
2008 final Canvas c = new Canvas(bitmap);
Romain Guya6abce82009-11-10 02:54:41 -08002009 c.scale(scale, scale);
2010 c.translate(-cell.getLeftPadding(), -cell.getTopPadding());
2011 cell.dispatchDraw(c);
Romain Guya6abce82009-11-10 02:54:41 -08002012
Romain Guy9d31e9f2009-11-11 18:54:28 -08002013 image.setBackgroundDrawable(resources.getDrawable(R.drawable.preview_background));
Romain Guye6b8e2f2009-11-10 11:56:55 -08002014 image.setImageBitmap(bitmap);
2015 image.setTag(i);
2016 image.setOnClickListener(handler);
Romain Guy9d31e9f2009-11-11 18:54:28 -08002017 image.setOnFocusChangeListener(handler);
2018 image.setFocusable(true);
Michael Jurka0142d492010-08-25 17:46:15 -07002019 if (i == mWorkspace.getCurrentPage()) image.requestFocus();
Romain Guye6b8e2f2009-11-10 11:56:55 -08002020
2021 preview.addView(image,
Romain Guy9d31e9f2009-11-11 18:54:28 -08002022 LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
2023
Winson Chungaafa03c2010-06-11 17:34:16 -07002024 bitmaps.add(bitmap);
Romain Guya6abce82009-11-10 02:54:41 -08002025 }
Romain Guyf8e6a802009-12-07 17:48:02 -08002026
2027 final PopupWindow p = new PopupWindow(this);
Romain Guye6b8e2f2009-11-10 11:56:55 -08002028 p.setContentView(preview);
2029 p.setWidth((int) (sWidth * count + extraW));
2030 p.setHeight((int) (sHeight + extraH));
2031 p.setAnimationStyle(R.style.AnimationPreview);
2032 p.setOutsideTouchable(true);
Romain Guy9d31e9f2009-11-11 18:54:28 -08002033 p.setFocusable(true);
Romain Guyff0c2e22009-11-10 12:09:59 -08002034 p.setBackgroundDrawable(new ColorDrawable(0));
Romain Guy9d31e9f2009-11-11 18:54:28 -08002035 p.showAsDropDown(anchor, 0, 0);
Romain Guya6abce82009-11-10 02:54:41 -08002036
Romain Guye6b8e2f2009-11-10 11:56:55 -08002037 p.setOnDismissListener(new PopupWindow.OnDismissListener() {
2038 public void onDismiss() {
2039 dismissPreview(anchor);
2040 }
2041 });
Romain Guy1fbc1c82009-11-09 20:43:08 -08002042
2043 anchor.setTag(p);
2044 anchor.setTag(R.id.workspace, preview);
Winson Chungaafa03c2010-06-11 17:34:16 -07002045 anchor.setTag(R.id.icon, bitmaps);
Romain Guy1fbc1c82009-11-09 20:43:08 -08002046 }
2047
Romain Guy9d31e9f2009-11-11 18:54:28 -08002048 class PreviewTouchHandler implements View.OnClickListener, Runnable, View.OnFocusChangeListener {
Romain Guya6abce82009-11-10 02:54:41 -08002049 private final View mAnchor;
Romain Guya6abce82009-11-10 02:54:41 -08002050
Romain Guye6b8e2f2009-11-10 11:56:55 -08002051 public PreviewTouchHandler(View anchor) {
Romain Guya6abce82009-11-10 02:54:41 -08002052 mAnchor = anchor;
Romain Guya6abce82009-11-10 02:54:41 -08002053 }
2054
2055 public void onClick(View v) {
Michael Jurka0142d492010-08-25 17:46:15 -07002056 mWorkspace.snapToPage((Integer) v.getTag());
Romain Guy9d31e9f2009-11-11 18:54:28 -08002057 v.post(this);
2058 }
2059
2060 public void run() {
Winson Chungaafa03c2010-06-11 17:34:16 -07002061 dismissPreview(mAnchor);
Romain Guy9d31e9f2009-11-11 18:54:28 -08002062 }
2063
2064 public void onFocusChange(View v, boolean hasFocus) {
2065 if (hasFocus) {
Michael Jurka0142d492010-08-25 17:46:15 -07002066 mWorkspace.snapToPage((Integer) v.getTag());
Romain Guy9d31e9f2009-11-11 18:54:28 -08002067 }
Romain Guya6abce82009-11-10 02:54:41 -08002068 }
2069 }
2070
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002071 Workspace getWorkspace() {
2072 return mWorkspace;
2073 }
2074
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002075 @Override
2076 protected Dialog onCreateDialog(int id) {
2077 switch (id) {
2078 case DIALOG_CREATE_SHORTCUT:
2079 return new CreateShortcut().createDialog();
2080 case DIALOG_RENAME_FOLDER:
2081 return new RenameFolder().createDialog();
2082 }
2083
2084 return super.onCreateDialog(id);
2085 }
2086
2087 @Override
2088 protected void onPrepareDialog(int id, Dialog dialog) {
2089 switch (id) {
2090 case DIALOG_CREATE_SHORTCUT:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002091 break;
2092 case DIALOG_RENAME_FOLDER:
Romain Guy7b4ef332009-07-14 13:58:08 -07002093 if (mFolderInfo != null) {
2094 EditText input = (EditText) dialog.findViewById(R.id.folder_name);
2095 final CharSequence text = mFolderInfo.title;
2096 input.setText(text);
2097 input.setSelection(0, text.length());
2098 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002099 break;
2100 }
2101 }
2102
2103 void showRenameDialog(FolderInfo info) {
2104 mFolderInfo = info;
2105 mWaitingForResult = true;
2106 showDialog(DIALOG_RENAME_FOLDER);
2107 }
2108
2109 private void showAddDialog(CellLayout.CellInfo cellInfo) {
2110 mAddItemCellInfo = cellInfo;
Michael Jurkaa63c4522010-08-19 13:52:27 -07002111 mAddItemCoordinates = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002112 mWaitingForResult = true;
2113 showDialog(DIALOG_CREATE_SHORTCUT);
2114 }
2115
Joe Onoratodeb98af2010-02-19 14:59:39 -08002116 private void pickShortcut() {
Michael Jurka0e260592010-06-30 17:07:39 -07002117 // Insert extra item to handle picking application
Romain Guy73b979d2009-06-09 12:57:21 -07002118 Bundle bundle = new Bundle();
2119
2120 ArrayList<String> shortcutNames = new ArrayList<String>();
2121 shortcutNames.add(getString(R.string.group_applications));
2122 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
2123
2124 ArrayList<ShortcutIconResource> shortcutIcons = new ArrayList<ShortcutIconResource>();
2125 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
2126 R.drawable.ic_launcher_application));
2127 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
2128
2129 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2130 pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_CREATE_SHORTCUT));
Joe Onoratodeb98af2010-02-19 14:59:39 -08002131 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_shortcut));
Romain Guy73b979d2009-06-09 12:57:21 -07002132 pickIntent.putExtras(bundle);
2133
Joe Onoratodeb98af2010-02-19 14:59:39 -08002134 startActivityForResult(pickIntent, REQUEST_PICK_SHORTCUT);
Romain Guy73b979d2009-06-09 12:57:21 -07002135 }
2136
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002137 private class RenameFolder {
2138 private EditText mInput;
2139
2140 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002141 final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null);
2142 mInput = (EditText) layout.findViewById(R.id.folder_name);
2143
2144 AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
2145 builder.setIcon(0);
2146 builder.setTitle(getString(R.string.rename_folder_title));
2147 builder.setCancelable(true);
2148 builder.setOnCancelListener(new Dialog.OnCancelListener() {
2149 public void onCancel(DialogInterface dialog) {
2150 cleanup();
2151 }
2152 });
2153 builder.setNegativeButton(getString(R.string.cancel_action),
2154 new Dialog.OnClickListener() {
2155 public void onClick(DialogInterface dialog, int which) {
2156 cleanup();
2157 }
2158 }
2159 );
2160 builder.setPositiveButton(getString(R.string.rename_action),
2161 new Dialog.OnClickListener() {
2162 public void onClick(DialogInterface dialog, int which) {
2163 changeFolderName();
2164 }
2165 }
2166 );
2167 builder.setView(layout);
Romain Guy7b4ef332009-07-14 13:58:08 -07002168
2169 final AlertDialog dialog = builder.create();
2170 dialog.setOnShowListener(new DialogInterface.OnShowListener() {
2171 public void onShow(DialogInterface dialog) {
Joe Onorato7018d8e2010-04-13 20:25:47 -07002172 mWaitingForResult = true;
Joe Onoratod753b422009-11-08 13:31:11 -05002173 mInput.requestFocus();
2174 InputMethodManager inputManager = (InputMethodManager)
2175 getSystemService(Context.INPUT_METHOD_SERVICE);
2176 inputManager.showSoftInput(mInput, 0);
Romain Guy7b4ef332009-07-14 13:58:08 -07002177 }
2178 });
2179
2180 return dialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002181 }
2182
2183 private void changeFolderName() {
2184 final String name = mInput.getText().toString();
2185 if (!TextUtils.isEmpty(name)) {
2186 // Make sure we have the right folder info
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002187 mFolderInfo = sFolders.get(mFolderInfo.id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002188 mFolderInfo.title = name;
2189 LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo);
2190
Joe Onorato9c1289c2009-08-17 11:03:03 -04002191 if (mWorkspaceLoading) {
Joe Onorato7c312c12009-08-13 21:36:53 -07002192 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002193 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002194 } else {
2195 final FolderIcon folderIcon = (FolderIcon)
2196 mWorkspace.getViewForTag(mFolderInfo);
2197 if (folderIcon != null) {
2198 folderIcon.setText(name);
2199 getWorkspace().requestLayout();
2200 } else {
Joe Onorato7c312c12009-08-13 21:36:53 -07002201 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002202 mWorkspaceLoading = true;
2203 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002204 }
2205 }
2206 }
2207 cleanup();
2208 }
2209
2210 private void cleanup() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002211 dismissDialog(DIALOG_RENAME_FOLDER);
2212 mWaitingForResult = false;
2213 mFolderInfo = null;
2214 }
2215 }
2216
Daniel Sandler843e8602010-06-07 14:59:01 -04002217 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
2218 public boolean isAllAppsVisible() {
Romain Guy5bbc91b2010-08-18 11:38:46 -07002219 return mAllAppsGrid != null && mAllAppsGrid.isVisible();
Joe Onoratofb0ca672009-09-14 17:55:46 -04002220 }
2221
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002222 // AllAppsView.Watcher
2223 public void zoomed(float zoom) {
Michael Jurka213d9632010-07-28 11:29:25 -07002224 // In XLarge view, we zoom down the workspace below all apps so it's still visible
2225 if (zoom == 1.0f && !LauncherApplication.isScreenXLarge()) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002226 mWorkspace.setVisibility(View.GONE);
2227 }
2228 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002229
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002230 private void showToolbarButton(View button) {
2231 button.setAlpha(1.0f);
2232 button.setVisibility(View.VISIBLE);
2233 button.setFocusable(true);
2234 button.setClickable(true);
2235 }
2236
2237 private void hideToolbarButton(View button) {
2238 button.setAlpha(0.0f);
2239 // We can't set it to GONE, otherwise the RelativeLayout gets screwed up
2240 button.setVisibility(View.INVISIBLE);
2241 button.setFocusable(false);
2242 button.setClickable(false);
2243 }
2244
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002245 /**
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002246 * Helper function for showing or hiding a toolbar button, possibly animated.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002247 *
2248 * @param show If true, create an animation to the show the item. Otherwise, hide it.
2249 * @param view The toolbar button to be animated
Chet Haaseb1254a62010-09-07 13:35:00 -07002250 * @param seq A AnimatorSet that will be used to animate the transition. If null, the
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002251 * transition will not be animated.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002252 */
Chet Haaseb1254a62010-09-07 13:35:00 -07002253 private void hideOrShowToolbarButton(boolean show, final View view, AnimatorSet seq) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002254 final boolean showing = show;
2255 final boolean hiding = !show;
2256
2257 final int duration = show ?
2258 getResources().getInteger(R.integer.config_toolbarButtonFadeInTime) :
2259 getResources().getInteger(R.integer.config_toolbarButtonFadeOutTime);
2260
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002261 if (seq != null) {
Chet Haaseb1254a62010-09-07 13:35:00 -07002262 Animator anim = new ObjectAnimator<Float>(duration, view, "alpha", show ? 1.0f : 0.0f);
2263 anim.addListener(new AnimatorListenerAdapter() {
2264 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002265 if (showing) showToolbarButton(view);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002266 }
Chet Haaseb1254a62010-09-07 13:35:00 -07002267 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002268 if (hiding) hideToolbarButton(view);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002269 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002270 });
2271 seq.play(anim);
2272 } else {
2273 if (showing) {
2274 showToolbarButton(view);
2275 } else {
2276 hideToolbarButton(view);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002277 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002278 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002279 }
2280
2281 /**
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002282 * Show/hide the appropriate toolbar buttons for newState.
2283 * If showSeq or hideSeq is null, the transition will be done immediately (not animated).
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002284 *
2285 * @param newState The state that is being switched to
Chet Haaseb1254a62010-09-07 13:35:00 -07002286 * @param showSeq AnimatorSet in which to put "show" animations, or null.
2287 * @param hideSeq AnimatorSet in which to put "hide" animations, or null.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002288 */
Chet Haaseb1254a62010-09-07 13:35:00 -07002289 private void hideAndShowToolbarButtons(State newState, AnimatorSet showSeq, AnimatorSet hideSeq) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002290 final View searchButton = findViewById(R.id.search_button);
2291 final View allAppsButton = findViewById(R.id.all_apps_button);
2292 final View marketButton = findViewById(R.id.market_button);
2293 final View configureButton = findViewById(R.id.configure_button);
2294
2295 switch (newState) {
2296 case WORKSPACE:
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002297 hideOrShowToolbarButton(true, searchButton, showSeq);
2298 hideOrShowToolbarButton(true, allAppsButton, showSeq);
2299 hideOrShowToolbarButton(true, configureButton, showSeq);
2300 hideOrShowToolbarButton(false, marketButton, hideSeq);
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002301 mDeleteZone.setHandle(allAppsButton);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002302 break;
2303 case ALL_APPS:
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002304 hideOrShowToolbarButton(true, configureButton, showSeq);
2305 hideOrShowToolbarButton(true, marketButton, showSeq);
2306 hideOrShowToolbarButton(false, searchButton, hideSeq);
2307 hideOrShowToolbarButton(false, allAppsButton, hideSeq);
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002308 mDeleteZone.setHandle(marketButton);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002309 break;
2310 case CUSTOMIZE:
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002311 hideOrShowToolbarButton(true, allAppsButton, showSeq);
2312 hideOrShowToolbarButton(false, searchButton, hideSeq);
2313 hideOrShowToolbarButton(false, marketButton, hideSeq);
2314 hideOrShowToolbarButton(false, configureButton, hideSeq);
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002315 mDeleteZone.setHandle(allAppsButton);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002316 break;
2317 }
2318 }
2319
2320 /**
2321 * Helper method for the cameraZoomIn/cameraZoomOut animations
2322 * @param view The view being animated
2323 * @param state The state that we are moving in or out of -- either ALL_APPS or CUSTOMIZE
2324 * @param scaleFactor The scale factor used for the zoom
2325 */
2326 private void setPivotsForZoom(View view, State state, float scaleFactor) {
2327 final int height = view.getHeight();
2328 view.setPivotX(view.getWidth() / 2.0f);
2329 // Set pivotY so that at the starting zoom factor, the view is off-screen by a small margin
2330 // Assumes that the view is normally anchored to either the top or bottom of the screen
2331 final int margin = getResources().getInteger(R.integer.config_allAppsVerticalOffset);
2332 if (state == State.ALL_APPS) {
2333 view.setPivotY(height + ((view.getTop() + height) / scaleFactor) + margin);
2334 } else {
2335 view.setPivotY(0.0f - (view.getTop() / scaleFactor) - margin);
2336 }
2337 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002338
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002339 /**
2340 * Zoom the camera out from the workspace to reveal 'toView'.
2341 * Assumes that the view to show is anchored at either the very top or very bottom
2342 * of the screen.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002343 * @param toState The state to zoom out to. Must be ALL_APPS or CUSTOMIZE.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002344 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002345 private void cameraZoomOut(State toState, boolean animated) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002346 final Resources res = getResources();
2347 final int duration = res.getInteger(R.integer.config_allAppsZoomInTime);
2348 final float scale = (float) res.getInteger(R.integer.config_allAppsZoomScaleFactor);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002349 final boolean toAllApps = (toState == State.ALL_APPS);
2350 final View toView = toAllApps ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
Patrick Dubroy558654c2010-07-23 16:48:11 -07002351
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002352 setPivotsForZoom(toView, toState, scale);
2353
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002354 if (toState == State.ALL_APPS) {
2355 mWorkspace.shrinkToBottom(animated);
2356 } else {
2357 mWorkspace.shrinkToTop(animated);
2358 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002359
2360 if (animated) {
Chet Haaseb1254a62010-09-07 13:35:00 -07002361 ValueAnimator scaleAnim = new ObjectAnimator(duration, toView,
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002362 new PropertyValuesHolder<Float>("scaleX", scale, 1.0f),
2363 new PropertyValuesHolder<Float>("scaleY", scale, 1.0f));
2364 scaleAnim.setInterpolator(new DecelerateInterpolator());
Chet Haaseb1254a62010-09-07 13:35:00 -07002365 scaleAnim.addListener(new AnimatorListenerAdapter() {
2366 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002367 // Prepare the position
2368 toView.setTranslationX(0.0f);
2369 toView.setTranslationY(0.0f);
2370 toView.setVisibility(View.VISIBLE);
2371 }
2372 });
2373
Chet Haaseb1254a62010-09-07 13:35:00 -07002374 AnimatorSet toolbarHideAnim = new AnimatorSet();
2375 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002376 hideAndShowToolbarButtons(toState, toolbarShowAnim, toolbarHideAnim);
2377
2378 // toView should appear right at the end of the workspace shrink animation
2379 final int startDelay = res.getInteger(R.integer.config_workspaceShrinkTime) - duration;
2380
Chet Haaseb1254a62010-09-07 13:35:00 -07002381 AnimatorSet s = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002382 s.playTogether(scaleAnim, toolbarHideAnim);
2383 s.play(scaleAnim).after(startDelay);
2384
2385 // Show the new toolbar buttons just as the main animation is ending
2386 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
2387 s.play(toolbarShowAnim).after(duration + startDelay - fadeInTime);
2388 s.start();
2389 } else {
2390 toView.setTranslationX(0.0f);
2391 toView.setTranslationY(0.0f);
2392 toView.setScaleX(1.0f);
2393 toView.setScaleY(1.0f);
2394 toView.setVisibility(View.VISIBLE);
2395 hideAndShowToolbarButtons(toState, null, null);
2396 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002397 }
2398
2399 /**
2400 * Zoom the camera back into the workspace, hiding 'fromView'.
2401 * This is the opposite of cameraZoomOut.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002402 * @param fromState The current state (must be ALL_APPS or CUSTOMIZE).
2403 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002404 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002405 private void cameraZoomIn(State fromState, boolean animated) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002406 Resources res = getResources();
2407 int duration = res.getInteger(R.integer.config_allAppsZoomOutTime);
2408 float scaleFactor = (float) res.getInteger(R.integer.config_allAppsZoomScaleFactor);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002409 final View fromView =
2410 (fromState == State.ALL_APPS) ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
2411
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002412 mCustomizePagedView.endChoiceMode();
2413 mAllAppsPagedView.endChoiceMode();
2414
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002415 setPivotsForZoom(fromView, fromState, scaleFactor);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002416
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002417 mWorkspace.unshrink(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002418
2419 if (animated) {
Chet Haaseb1254a62010-09-07 13:35:00 -07002420 AnimatorSet s = new AnimatorSet();
2421 ValueAnimator scaleAnim = new ObjectAnimator(duration, fromView,
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002422 new PropertyValuesHolder<Float>("scaleX", scaleFactor),
2423 new PropertyValuesHolder<Float>("scaleY", scaleFactor));
2424 scaleAnim.setInterpolator(new AccelerateInterpolator());
Chet Haaseb1254a62010-09-07 13:35:00 -07002425 s.addListener(new AnimatorListenerAdapter() {
2426 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002427 fromView.setVisibility(View.GONE);
2428 fromView.setScaleX(1.0f);
2429 fromView.setScaleY(1.0f);
2430 }
2431 });
2432
Chet Haaseb1254a62010-09-07 13:35:00 -07002433 AnimatorSet toolbarHideAnim = new AnimatorSet();
2434 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002435 hideAndShowToolbarButtons(State.WORKSPACE, toolbarShowAnim, toolbarHideAnim);
2436
2437 s.playTogether(scaleAnim, toolbarHideAnim);
2438
2439 // Show the new toolbar buttons at the very end of the whole animation
2440 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
2441 final int unshrinkTime = res.getInteger(R.integer.config_workspaceUnshrinkTime);
2442 s.play(toolbarShowAnim).after(unshrinkTime - fadeInTime);
2443 s.start();
2444 } else {
2445 fromView.setVisibility(View.GONE);
2446 hideAndShowToolbarButtons(State.WORKSPACE, null, null);
2447 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002448 }
2449
2450 /**
2451 * Pan the camera in the vertical plane between 'fromView' and 'toView'.
2452 * This is the transition used on xlarge screens to go between all apps and
2453 * the home customization drawer.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002454 * @param fromState The view to pan away from. Must be ALL_APPS or CUSTOMIZE.
2455 * @param toState The view to pan into the frame. Must be ALL_APPS or CUSTOMIZE.
2456 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002457 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002458 private void cameraPan(State fromState, State toState, boolean animated) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002459 final Resources res = getResources();
2460 final int duration = res.getInteger(R.integer.config_allAppsCameraPanTime);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002461 final int workspaceHeight = mWorkspace.getHeight();
2462
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002463 final boolean fromAllApps = (fromState == State.ALL_APPS);
2464 final View fromView = fromAllApps ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
2465 final View toView = fromAllApps ? mHomeCustomizationDrawer : (View) mAllAppsGrid;
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002466
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002467 final float fromViewStartY = fromAllApps ? 0.0f : fromView.getY();
2468 final float fromViewEndY = fromAllApps ? -fromView.getHeight() * 2 : workspaceHeight * 2;
2469 final float toViewStartY = fromAllApps ? workspaceHeight * 2 : -toView.getHeight() * 2;
2470 final float toViewEndY = fromAllApps ? workspaceHeight - toView.getHeight() : 0.0f;
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002471
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002472 mCustomizePagedView.endChoiceMode();
2473 mAllAppsPagedView.endChoiceMode();
2474
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002475 if (toState == State.ALL_APPS) {
2476 mWorkspace.shrinkToBottom(animated);
2477 } else {
2478 mWorkspace.shrinkToTop(animated);
2479 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002480
2481 if (animated) {
Chet Haaseb1254a62010-09-07 13:35:00 -07002482 AnimatorSet s = new AnimatorSet();
2483 s.addListener(new AnimatorListenerAdapter() {
2484 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002485 toView.setVisibility(View.VISIBLE);
2486 toView.setY(toViewStartY);
2487 }
Chet Haaseb1254a62010-09-07 13:35:00 -07002488 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002489 fromView.setVisibility(View.GONE);
2490 }
2491 });
2492
Chet Haaseb1254a62010-09-07 13:35:00 -07002493 AnimatorSet toolbarHideAnim = new AnimatorSet();
2494 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002495 hideAndShowToolbarButtons(toState, toolbarShowAnim, toolbarHideAnim);
2496
2497 s.playTogether(
2498 toolbarHideAnim,
Chet Haaseb1254a62010-09-07 13:35:00 -07002499 new ObjectAnimator(duration, fromView, "y", fromViewStartY, fromViewEndY),
2500 new ObjectAnimator(duration, toView, "y", toViewStartY, toViewEndY));
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002501
2502 // Show the new toolbar buttons just as the main animation is ending
2503 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
2504 s.play(toolbarShowAnim).after(duration - fadeInTime);
2505 s.start();
2506 } else {
2507 fromView.setY(fromViewEndY);
2508 fromView.setVisibility(View.GONE);
2509 toView.setY(toViewEndY);
2510 toView.setVisibility(View.VISIBLE);
2511 hideAndShowToolbarButtons(toState, null, null);
2512 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002513 }
2514
2515 void showAllApps(boolean animated) {
Winson Chung80baf5a2010-08-09 16:03:15 -07002516 if (mAllAppsGrid.isVisible())
2517 return;
2518
Michael Jurka79212d82010-07-30 16:36:20 -07002519 if (LauncherApplication.isScreenXLarge()) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002520 if (isCustomizationDrawerVisible()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002521 cameraPan(State.CUSTOMIZE, State.ALL_APPS, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002522 } else {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002523 cameraZoomOut(State.ALL_APPS, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002524 }
Patrick Dubroy558654c2010-07-23 16:48:11 -07002525 } else {
2526 mAllAppsGrid.zoom(1.0f, animated);
2527 }
Joe Onorato3a8820b2009-11-10 15:06:42 -08002528
Romain Guyc16fea72010-03-12 17:17:56 -08002529 ((View) mAllAppsGrid).setFocusable(true);
2530 ((View) mAllAppsGrid).requestFocus();
Winson Chungaafa03c2010-06-11 17:34:16 -07002531
Joe Onorato7c312c12009-08-13 21:36:53 -07002532 // TODO: fade these two too
2533 mDeleteZone.setVisibility(View.GONE);
Joe Onorato00acb122009-08-04 16:04:30 -04002534 }
2535
Joe Onoratob2061212009-11-24 16:13:54 -05002536 /**
Joe Onorato7e4ed992009-12-03 13:10:49 -08002537 * Things to test when changing this code.
Joe Onoratob2061212009-11-24 16:13:54 -05002538 * - Home from workspace
2539 * - from center screen
2540 * - from other screens
2541 * - Home from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002542 * - from center screen
2543 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002544 * - Back from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002545 * - from center screen
2546 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002547 * - Launch app from workspace and quit
2548 * - with back
2549 * - with home
2550 * - Launch app from all apps and quit
2551 * - with back
2552 * - with home
Joe Onorato7e4ed992009-12-03 13:10:49 -08002553 * - Go to a screen that's not the default, then all
2554 * apps, and launch and app, and go back
2555 * - with back
2556 * -with home
Joe Onoratob2061212009-11-24 16:13:54 -05002557 * - On workspace, long press power and go back
2558 * - with back
2559 * - with home
2560 * - On all apps, long press power and go back
2561 * - with back
2562 * - with home
2563 * - On workspace, power off
2564 * - On all apps, power off
Joe Onorato7e4ed992009-12-03 13:10:49 -08002565 * - Launch an app and turn off the screen while in that app
2566 * - Go back with home key
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002567 * - Go back with back key TODO: make this not go to workspace
Joe Onorato7e4ed992009-12-03 13:10:49 -08002568 * - From all apps
2569 * - From workspace
Joe Onoratoeffc4a82010-04-15 11:48:13 -07002570 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2571 * - From all apps
2572 * - From the center workspace
2573 * - From another workspace
Joe Onoratob2061212009-11-24 16:13:54 -05002574 */
Joe Onorato7bb17492009-09-24 17:51:01 -07002575 void closeAllApps(boolean animated) {
Joe Onoratofb0ca672009-09-14 17:55:46 -04002576 if (mAllAppsGrid.isVisible()) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002577 mWorkspace.setVisibility(View.VISIBLE);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002578 if (LauncherApplication.isScreenXLarge()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002579 cameraZoomIn(State.ALL_APPS, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002580 } else {
2581 mAllAppsGrid.zoom(0.0f, animated);
2582 }
Daniel Sandler388f6792010-03-02 14:08:08 -05002583 ((View)mAllAppsGrid).setFocusable(false);
Michael Jurka0142d492010-08-25 17:46:15 -07002584 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onoratoe77c08d2009-08-01 00:01:20 -07002585 }
Joe Onorato7404ee42009-07-31 11:54:44 -07002586 }
2587
Joe Onorato7c312c12009-08-13 21:36:53 -07002588 void lockAllApps() {
2589 // TODO
2590 }
2591
2592 void unlockAllApps() {
2593 // TODO
2594 }
2595
Patrick Dubroy558654c2010-07-23 16:48:11 -07002596 private boolean isCustomizationDrawerVisible() {
Michael Jurka54f7ac32010-08-02 13:56:46 -07002597 return mHomeCustomizationDrawer != null &&
2598 mHomeCustomizationDrawer.getVisibility() == View.VISIBLE;
Patrick Dubroy558654c2010-07-23 16:48:11 -07002599 }
2600
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002601 // Show the customization drawer (only exists in x-large configuration)
2602 private void showCustomizationDrawer(boolean animated) {
Patrick Dubroy558654c2010-07-23 16:48:11 -07002603 if (isAllAppsVisible()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002604 cameraPan(State.ALL_APPS, State.CUSTOMIZE, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002605 } else {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002606 cameraZoomOut(State.CUSTOMIZE, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002607 }
Patrick Dubroy558654c2010-07-23 16:48:11 -07002608 }
2609
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002610 // Hide the customization drawer (only exists in x-large configuration)
2611 void hideCustomizationDrawer(boolean animated) {
Patrick Dubroy558654c2010-07-23 16:48:11 -07002612 if (isCustomizationDrawerVisible()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002613 cameraZoomIn(State.CUSTOMIZE, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002614 }
2615 }
2616
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002617 void onWorkspaceClick(CellLayout layout) {
2618 Object itemInfo = mAllAppsPagedView.getChosenItem();
2619 if (itemInfo == null) {
2620 itemInfo = mCustomizePagedView.getChosenItem();
Michael Jurka213d9632010-07-28 11:29:25 -07002621 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002622
2623 if (itemInfo == null) {
2624 // No items are chosen in All Apps or Customize, so just zoom into the workspace
2625 mWorkspace.unshrink(layout);
2626 if (isAllAppsVisible()) {
2627 closeAllApps(true);
2628 } else if (isCustomizationDrawerVisible()) {
2629 hideCustomizationDrawer(true);
2630 }
2631 } else {
2632 // Act as if the chosen item was dropped on the given CellLayout
2633 if (mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
2634 mAllAppsPagedView.endChoiceMode();
2635 mCustomizePagedView.endChoiceMode();
2636 } else {
2637 Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show();
2638 }
Michael Jurka213d9632010-07-28 11:29:25 -07002639 }
2640 }
2641
Joe Onorato7404ee42009-07-31 11:54:44 -07002642 /**
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002643 * Sets the app market icon (shown when all apps is visible on x-large screens)
2644 */
2645 private void updateAppMarketIcon() {
2646 if (LauncherApplication.isScreenXLarge()) {
2647 // Find the app market activity by resolving an intent.
2648 // (If multiple app markets are installed, it will return the ResolverActivity.)
2649 PackageManager packageManager = getPackageManager();
2650 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
2651 ComponentName activityName = intent.resolveActivity(getPackageManager());
2652 if (activityName != null) {
2653 mAppMarketIntent = intent;
2654 ImageView marketButton = (ImageView) findViewById(R.id.market_button);
2655 Drawable toolbarIcon = null;
2656 try {
2657 // Look for the toolbar icon specified in the activity meta-data
2658 Bundle metaData = packageManager.getActivityInfo(
2659 activityName, PackageManager.GET_META_DATA).metaData;
2660 if (metaData != null) {
2661 int iconResId = metaData.getInt(TOOLBAR_ICON_METADATA_NAME);
2662 if (iconResId != 0) {
2663 Resources res = packageManager.getResourcesForActivity(activityName);
2664 toolbarIcon = res.getDrawable(iconResId);
2665 }
2666 }
2667 } catch (NameNotFoundException e) {
2668 // Do nothing
2669 }
2670 // If we were unable to find the icon via the meta-data, use a generic one
2671 if (toolbarIcon == null) {
2672 marketButton.setImageResource(R.drawable.app_market_generic);
2673 } else {
2674 marketButton.setImageDrawable(toolbarIcon);
2675 }
2676 } else {
2677 mAppMarketIntent = null;
2678 }
2679 }
2680 }
2681
2682 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002683 * Displays the shortcut creation dialog and launches, if necessary, the
2684 * appropriate activity.
2685 */
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002686 private class CreateShortcut implements DialogInterface.OnClickListener,
Romain Guy7b4ef332009-07-14 13:58:08 -07002687 DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
2688 DialogInterface.OnShowListener {
2689
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002690 private AddAdapter mAdapter;
Romain Guy9ffb5432009-03-24 21:04:15 -07002691
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002692 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002693 mAdapter = new AddAdapter(Launcher.this);
Romain Guycbb89e42009-06-08 15:52:54 -07002694
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002695 final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
2696 builder.setTitle(getString(R.string.menu_item_add_item));
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002697 builder.setAdapter(mAdapter, this);
Romain Guycbb89e42009-06-08 15:52:54 -07002698
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002699 builder.setInverseBackgroundForced(true);
2700
2701 AlertDialog dialog = builder.create();
2702 dialog.setOnCancelListener(this);
Romain Guycbb89e42009-06-08 15:52:54 -07002703 dialog.setOnDismissListener(this);
Romain Guy7b4ef332009-07-14 13:58:08 -07002704 dialog.setOnShowListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002705
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002706 return dialog;
2707 }
2708
2709 public void onCancel(DialogInterface dialog) {
2710 mWaitingForResult = false;
2711 cleanup();
2712 }
2713
Romain Guycbb89e42009-06-08 15:52:54 -07002714 public void onDismiss(DialogInterface dialog) {
Romain Guycbb89e42009-06-08 15:52:54 -07002715 }
2716
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002717 private void cleanup() {
Joe Onoratocc19a532009-11-19 14:19:17 -08002718 try {
2719 dismissDialog(DIALOG_CREATE_SHORTCUT);
2720 } catch (Exception e) {
2721 // An exception is thrown if the dialog is not visible, which is fine
2722 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002723 }
2724
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002725 /**
2726 * Handle the action clicked in the "Add to home" dialog.
2727 */
2728 public void onClick(DialogInterface dialog, int which) {
2729 Resources res = getResources();
2730 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002731
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002732 switch (which) {
2733 case AddAdapter.ITEM_SHORTCUT: {
Joe Onoratodeb98af2010-02-19 14:59:39 -08002734 pickShortcut();
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002735 break;
2736 }
Romain Guycbb89e42009-06-08 15:52:54 -07002737
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002738 case AddAdapter.ITEM_APPWIDGET: {
2739 int appWidgetId = Launcher.this.mAppWidgetHost.allocateAppWidgetId();
Romain Guycbb89e42009-06-08 15:52:54 -07002740
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002741 Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
2742 pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002743 // start the pick activity
2744 startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET);
2745 break;
2746 }
Romain Guycbb89e42009-06-08 15:52:54 -07002747
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002748 case AddAdapter.ITEM_LIVE_FOLDER: {
2749 // Insert extra item to handle inserting folder
2750 Bundle bundle = new Bundle();
Romain Guycbb89e42009-06-08 15:52:54 -07002751
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002752 ArrayList<String> shortcutNames = new ArrayList<String>();
2753 shortcutNames.add(res.getString(R.string.group_folder));
2754 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
Romain Guycbb89e42009-06-08 15:52:54 -07002755
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002756 ArrayList<ShortcutIconResource> shortcutIcons =
2757 new ArrayList<ShortcutIconResource>();
2758 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
2759 R.drawable.ic_launcher_folder));
2760 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
2761
2762 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2763 pickIntent.putExtra(Intent.EXTRA_INTENT,
2764 new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER));
2765 pickIntent.putExtra(Intent.EXTRA_TITLE,
2766 getText(R.string.title_select_live_folder));
2767 pickIntent.putExtras(bundle);
Romain Guycbb89e42009-06-08 15:52:54 -07002768
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002769 startActivityForResult(pickIntent, REQUEST_PICK_LIVE_FOLDER);
2770 break;
2771 }
2772
2773 case AddAdapter.ITEM_WALLPAPER: {
2774 startWallpaper();
2775 break;
2776 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002777 }
2778 }
Romain Guy7b4ef332009-07-14 13:58:08 -07002779
2780 public void onShow(DialogInterface dialog) {
Winson Chungaafa03c2010-06-11 17:34:16 -07002781 mWaitingForResult = true;
Romain Guy7b4ef332009-07-14 13:58:08 -07002782 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002783 }
2784
2785 /**
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002786 * Receives notifications when applications are added/removed.
2787 */
2788 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
2789 @Override
2790 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002791 closeSystemDialogs();
Joe Onoratob2061212009-11-24 16:13:54 -05002792 String reason = intent.getStringExtra("reason");
2793 if (!"homekey".equals(reason)) {
2794 boolean animate = true;
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002795 if (mPaused || "lock".equals(reason)) {
Joe Onoratob2061212009-11-24 16:13:54 -05002796 animate = false;
2797 }
Joe Onoratob2061212009-11-24 16:13:54 -05002798 closeAllApps(animate);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002799 hideCustomizationDrawer(animate);
Joe Onoratob2061212009-11-24 16:13:54 -05002800 }
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002801 }
2802 }
2803
2804 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002805 * Receives notifications whenever the appwidgets are reset.
2806 */
2807 private class AppWidgetResetObserver extends ContentObserver {
2808 public AppWidgetResetObserver() {
2809 super(new Handler());
2810 }
2811
2812 @Override
2813 public void onChange(boolean selfChange) {
2814 onAppWidgetReset();
2815 }
2816 }
2817
2818 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002819 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002820 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002821 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07002822 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002823 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07002824 } else {
2825 return SCREEN_COUNT / 2;
2826 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002827 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002828
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002829 void setAllAppsPagedView(PagedView view) {
2830 mAllAppsPagedView = view;
2831 }
2832
Joe Onorato9c1289c2009-08-17 11:03:03 -04002833 /**
2834 * Refreshes the shortcuts shown on the workspace.
2835 *
2836 * Implementation of the method from LauncherModel.Callbacks.
2837 */
2838 public void startBinding() {
2839 final Workspace workspace = mWorkspace;
2840 int count = workspace.getChildCount();
2841 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04002842 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Joe Onorato9c1289c2009-08-17 11:03:03 -04002843 ((ViewGroup) workspace.getChildAt(i)).removeAllViewsInLayout();
2844 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002845
Joe Onorato9c1289c2009-08-17 11:03:03 -04002846 if (DEBUG_USER_INTERFACE) {
2847 android.widget.Button finishButton = new android.widget.Button(this);
2848 finishButton.setText("Finish");
2849 workspace.addInScreen(finishButton, 1, 0, 0, 1, 1);
2850
2851 finishButton.setOnClickListener(new android.widget.Button.OnClickListener() {
2852 public void onClick(View v) {
2853 finish();
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002854 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002855 });
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002856 }
2857 }
2858
2859 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002860 * Bind the items start-end from the list.
2861 *
2862 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002863 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002864 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
2865
2866 final Workspace workspace = mWorkspace;
2867
2868 for (int i=start; i<end; i++) {
2869 final ItemInfo item = shortcuts.get(i);
2870 mDesktopItems.add(item);
2871 switch (item.itemType) {
2872 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
2873 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Joe Onorato0589f0f2010-02-08 13:44:00 -08002874 final View shortcut = createShortcut((ShortcutInfo)item);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002875 workspace.addInScreen(shortcut, item.screen, item.cellX, item.cellY, 1, 1,
2876 false);
2877 break;
2878 case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER:
2879 final FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07002880 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Joe Onorato9c1289c2009-08-17 11:03:03 -04002881 (UserFolderInfo) item);
2882 workspace.addInScreen(newFolder, item.screen, item.cellX, item.cellY, 1, 1,
2883 false);
2884 break;
2885 case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER:
2886 final FolderIcon newLiveFolder = LiveFolderIcon.fromXml(
2887 R.layout.live_folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07002888 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Joe Onorato9c1289c2009-08-17 11:03:03 -04002889 (LiveFolderInfo) item);
2890 workspace.addInScreen(newLiveFolder, item.screen, item.cellX, item.cellY, 1, 1,
2891 false);
2892 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002893 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002894 }
2895
Joe Onorato9c1289c2009-08-17 11:03:03 -04002896 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002897 }
2898
Joe Onorato9c1289c2009-08-17 11:03:03 -04002899 /**
2900 * Implementation of the method from LauncherModel.Callbacks.
2901 */
Joe Onoratoad72e172009-11-06 16:25:04 -05002902 public void bindFolders(HashMap<Long, FolderInfo> folders) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002903 sFolders.clear();
2904 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002905 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002906
2907 /**
2908 * Add the views for a widget to the workspace.
2909 *
2910 * Implementation of the method from LauncherModel.Callbacks.
2911 */
2912 public void bindAppWidget(LauncherAppWidgetInfo item) {
Daniel Sandler843e8602010-06-07 14:59:01 -04002913 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
2914 if (DEBUG_WIDGETS) {
2915 Log.d(TAG, "bindAppWidget: " + item);
2916 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002917 final Workspace workspace = mWorkspace;
2918
2919 final int appWidgetId = item.appWidgetId;
2920 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04002921 if (DEBUG_WIDGETS) {
2922 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
2923 }
2924
Joe Onorato9c1289c2009-08-17 11:03:03 -04002925 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
2926
Joe Onorato9c1289c2009-08-17 11:03:03 -04002927 item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
2928 item.hostView.setTag(item);
2929
2930 workspace.addInScreen(item.hostView, item.screen, item.cellX,
2931 item.cellY, item.spanX, item.spanY, false);
2932
2933 workspace.requestLayout();
2934
2935 mDesktopItems.add(item);
Daniel Sandler843e8602010-06-07 14:59:01 -04002936
2937 if (DEBUG_WIDGETS) {
2938 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
2939 + (SystemClock.uptimeMillis()-start) + "ms");
2940 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002941 }
2942
2943 /**
2944 * Callback saying that there aren't any more items to bind.
2945 *
2946 * Implementation of the method from LauncherModel.Callbacks.
2947 */
2948 public void finishBindingItems() {
2949 if (mSavedState != null) {
2950 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07002951 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002952 }
2953
2954 final long[] userFolders = mSavedState.getLongArray(RUNTIME_STATE_USER_FOLDERS);
2955 if (userFolders != null) {
2956 for (long folderId : userFolders) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002957 final FolderInfo info = sFolders.get(folderId);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002958 if (info != null) {
2959 openFolder(info);
2960 }
2961 }
2962 final Folder openFolder = mWorkspace.getOpenFolder();
2963 if (openFolder != null) {
2964 openFolder.requestFocus();
2965 }
2966 }
2967
Joe Onorato9c1289c2009-08-17 11:03:03 -04002968 mSavedState = null;
2969 }
2970
2971 if (mSavedInstanceState != null) {
2972 super.onRestoreInstanceState(mSavedInstanceState);
2973 mSavedInstanceState = null;
2974 }
2975
Joe Onorato9c1289c2009-08-17 11:03:03 -04002976 mWorkspaceLoading = false;
2977 }
2978
2979 /**
2980 * Add the icons for all apps.
2981 *
2982 * Implementation of the method from LauncherModel.Callbacks.
2983 */
2984 public void bindAllApplications(ArrayList<ApplicationInfo> apps) {
Romain Guy84f296c2009-11-04 15:00:44 -08002985 mAllAppsGrid.setApps(apps);
Winson Chung5ffd8ea2010-09-23 18:40:29 -07002986 mCustomizePagedView.setApps(apps);
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002987 updateAppMarketIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002988 }
2989
2990 /**
2991 * A package was installed.
2992 *
2993 * Implementation of the method from LauncherModel.Callbacks.
2994 */
Joe Onorato64e6be72010-03-05 15:05:52 -05002995 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04002996 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onoratoa8138d52009-10-06 19:25:30 -07002997 mAllAppsGrid.addApps(apps);
Winson Chung5ffd8ea2010-09-23 18:40:29 -07002998 mCustomizePagedView.addApps(apps);
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002999 updateAppMarketIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003000 }
3001
3002 /**
3003 * A package was updated.
3004 *
3005 * Implementation of the method from LauncherModel.Callbacks.
3006 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003007 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003008 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato64e6be72010-03-05 15:05:52 -05003009 mWorkspace.updateShortcuts(apps);
3010 mAllAppsGrid.updateApps(apps);
Winson Chung5ffd8ea2010-09-23 18:40:29 -07003011 mCustomizePagedView.updateApps(apps);
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003012 updateAppMarketIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003013 }
3014
3015 /**
3016 * A package was uninstalled.
3017 *
3018 * Implementation of the method from LauncherModel.Callbacks.
3019 */
Joe Onorato36115782010-06-17 13:28:48 -04003020 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003021 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato36115782010-06-17 13:28:48 -04003022 if (permanent) {
3023 mWorkspace.removeItems(apps);
3024 }
Joe Onoratoa8138d52009-10-06 19:25:30 -07003025 mAllAppsGrid.removeApps(apps);
Winson Chung5ffd8ea2010-09-23 18:40:29 -07003026 mCustomizePagedView.removeApps(apps);
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003027 updateAppMarketIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003028 }
Joe Onoratobe386092009-11-17 17:32:16 -08003029
3030 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003031 * A number of packages were updated.
3032 */
3033 public void bindPackagesUpdated() {
3034 // update the customization drawer contents
Winson Chungb3347bb2010-08-19 14:51:28 -07003035 if (mCustomizePagedView != null)
3036 mCustomizePagedView.update();
Winson Chung80baf5a2010-08-09 16:03:15 -07003037 }
3038
3039 /**
Joe Onoratobe386092009-11-17 17:32:16 -08003040 * Prints out out state for debugging.
3041 */
3042 public void dumpState() {
3043 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08003044 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08003045 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
3046 Log.d(TAG, "mRestoring=" + mRestoring);
3047 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
3048 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
3049 Log.d(TAG, "mDesktopItems.size=" + mDesktopItems.size());
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003050 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08003051 mModel.dumpState();
3052 mAllAppsGrid.dumpState();
3053 Log.d(TAG, "END launcher2 dump state");
3054 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003055}