blob: ad3777944a0767556bdc9c0f623451db8324b921 [file] [log] [blame]
Michael Jurka01f0ed42010-08-20 00:41:17 -07001
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002/*
3 * Copyright (C) 2008 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
Joe Onoratoa5902522009-07-30 13:37:37 -070018package com.android.launcher2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080019
Chet Haaseb1254a62010-09-07 13:35:00 -070020import android.animation.Animator;
21import android.animation.AnimatorListenerAdapter;
22import android.animation.ValueAnimator;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070023import com.android.common.Search;
24import com.android.launcher.R;
25
Chet Haaseb1254a62010-09-07 13:35:00 -070026import android.animation.ObjectAnimator;
Patrick Dubroy07a0de42010-08-26 11:48:35 -070027import android.animation.PropertyValuesHolder;
Chet Haaseb1254a62010-09-07 13:35:00 -070028import android.animation.AnimatorSet;
Michael Jurka946ad472010-07-09 18:05:18 -070029import android.app.Activity;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080030import android.app.AlertDialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080031import android.app.Dialog;
32import android.app.SearchManager;
33import android.app.StatusBarManager;
Dianne Hackborn107f8392009-08-05 21:32:16 -070034import android.app.WallpaperManager;
Michael Jurkaaf442092010-06-10 17:01:57 -070035import android.appwidget.AppWidgetManager;
36import android.appwidget.AppWidgetProviderInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080037import android.content.ActivityNotFoundException;
Joe Onorato2ca0ae72009-11-10 13:14:13 -080038import android.content.BroadcastReceiver;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040039import android.content.ComponentName;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080040import android.content.ContentResolver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080041import android.content.Context;
42import android.content.DialogInterface;
43import android.content.Intent;
Winson Chung80baf5a2010-08-09 16:03:15 -070044import android.content.Intent.ShortcutIconResource;
Romain Guy5bbc91b2010-08-18 11:38:46 -070045import android.content.IntentFilter;
Winson Chungaafa03c2010-06-11 17:34:16 -070046import android.content.pm.ActivityInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080047import android.content.pm.PackageManager;
Patrick Dubroyceae05d2010-08-30 10:40:53 -070048import android.content.pm.PackageManager.NameNotFoundException;
Daniel Sandlerab1ebd72010-04-27 16:57:25 -040049import android.content.pm.ResolveInfo;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080050import android.content.res.Configuration;
Karl Rosaen138a0412009-04-23 19:00:21 -070051import android.content.res.Resources;
Daniel Sandlerab1ebd72010-04-27 16:57:25 -040052import android.content.res.TypedArray;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080053import android.database.ContentObserver;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080054import android.graphics.Bitmap;
Romain Guya6abce82009-11-10 02:54:41 -080055import android.graphics.Canvas;
Winson Chung80baf5a2010-08-09 16:03:15 -070056import android.graphics.Color;
Michael Jurkaaf442092010-06-10 17:01:57 -070057import android.graphics.Rect;
Romain Guyff0c2e22009-11-10 12:09:59 -080058import android.graphics.drawable.ColorDrawable;
Michael Jurkaaf442092010-06-10 17:01:57 -070059import android.graphics.drawable.Drawable;
Daniel Sandlerc9b18772010-04-22 14:37:59 -040060import android.net.Uri;
Brad Fitzpatrick319226a2010-09-01 13:45:16 -070061import android.os.AsyncTask;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080062import android.os.Bundle;
Jeff Sharkey1e2efc82009-11-06 15:17:59 -080063import android.os.Handler;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080064import android.os.Parcelable;
Daniel Sandler843e8602010-06-07 14:59:01 -040065import android.os.SystemClock;
Joe Onoratobe386092009-11-17 17:32:16 -080066import android.os.SystemProperties;
Karl Rosaen138a0412009-04-23 19:00:21 -070067import android.provider.LiveFolders;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070068import android.provider.Settings;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080069import android.text.Selection;
70import android.text.SpannableStringBuilder;
71import android.text.TextUtils;
72import android.text.method.TextKeyListener;
Joe Onorato7c312c12009-08-13 21:36:53 -070073import android.util.Log;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080074import android.view.Display;
Joe Onorato0d44e942009-11-16 18:20:51 -080075import android.view.HapticFeedbackConstants;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080076import android.view.KeyEvent;
77import android.view.LayoutInflater;
78import android.view.Menu;
79import android.view.MenuItem;
Michael Jurka0e260592010-06-30 17:07:39 -070080import android.view.MotionEvent;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080081import android.view.View;
Romain Guy5bbc91b2010-08-18 11:38:46 -070082import android.view.View.OnLongClickListener;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080083import android.view.ViewGroup;
Winson Chungaafa03c2010-06-11 17:34:16 -070084import android.view.WindowManager;
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -070085import android.view.animation.AccelerateInterpolator;
Patrick Dubroy7247f632010-08-04 16:02:59 -070086import android.view.animation.DecelerateInterpolator;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080087import android.view.inputmethod.InputMethodManager;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080088import android.widget.EditText;
Michael Jurkaaf442092010-06-10 17:01:57 -070089import android.widget.ImageView;
90import android.widget.LinearLayout;
91import android.widget.PopupWindow;
Winson Chung80baf5a2010-08-09 16:03:15 -070092import android.widget.RelativeLayout;
Michael Jurka0e260592010-06-30 17:07:39 -070093import android.widget.TabHost;
Romain Guy5bbc91b2010-08-18 11:38:46 -070094import android.widget.TabHost.OnTabChangeListener;
95import android.widget.TabHost.TabContentFactory;
Winson Chung80baf5a2010-08-09 16:03:15 -070096import android.widget.TabWidget;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080097import android.widget.TextView;
98import android.widget.Toast;
Patrick Dubroy4ed62782010-08-17 15:11:18 -070099
100import java.io.DataInputStream;
101import java.io.DataOutputStream;
102import java.io.FileNotFoundException;
103import java.io.IOException;
104import java.util.ArrayList;
105import java.util.HashMap;
106import java.util.List;
Romain Guyedcce092010-03-04 13:03:17 -0800107
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800108/**
109 * Default launcher application.
110 */
Michael Jurka946ad472010-07-09 18:05:18 -0700111public final class Launcher extends Activity
Michael Jurka0e260592010-06-30 17:07:39 -0700112 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
113 AllAppsView.Watcher, View.OnTouchListener {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -0800114 static final String TAG = "Launcher";
Joe Onoratocc67f472010-06-08 10:54:30 -0700115 static final boolean LOGD = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800116
Joe Onorato9c1289c2009-08-17 11:03:03 -0400117 static final boolean PROFILE_STARTUP = false;
Daniel Sandler843e8602010-06-07 14:59:01 -0400118 static final boolean DEBUG_WIDGETS = false;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400119 static final boolean DEBUG_USER_INTERFACE = false;
Romain Guy6fefcf12009-06-11 13:07:43 -0700120
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800121 private static final int MENU_GROUP_ADD = 1;
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800122 private static final int MENU_GROUP_WALLPAPER = MENU_GROUP_ADD + 1;
123
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800124 private static final int MENU_ADD = Menu.FIRST + 1;
Winson Chung7ad01412010-09-27 11:33:03 -0700125 private static final int MENU_MANAGE_APPS = MENU_ADD + 1;
126 private static final int MENU_WALLPAPER_SETTINGS = MENU_MANAGE_APPS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800127 private static final int MENU_SEARCH = MENU_WALLPAPER_SETTINGS + 1;
128 private static final int MENU_NOTIFICATIONS = MENU_SEARCH + 1;
Romain Guy94dabf12009-07-21 10:55:43 -0700129 private static final int MENU_SETTINGS = MENU_NOTIFICATIONS + 1;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800130
131 private static final int REQUEST_CREATE_SHORTCUT = 1;
132 private static final int REQUEST_CREATE_LIVE_FOLDER = 4;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700133 private static final int REQUEST_CREATE_APPWIDGET = 5;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800134 private static final int REQUEST_PICK_APPLICATION = 6;
135 private static final int REQUEST_PICK_SHORTCUT = 7;
136 private static final int REQUEST_PICK_LIVE_FOLDER = 8;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700137 private static final int REQUEST_PICK_APPWIDGET = 9;
Mike Clerona0618e42009-10-22 13:55:21 -0700138 private static final int REQUEST_PICK_WALLPAPER = 10;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800139
140 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
141
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800142 static final int SCREEN_COUNT = 5;
143 static final int DEFAULT_SCREEN = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800144
Joe Onorato7c312c12009-08-13 21:36:53 -0700145 static final int DIALOG_CREATE_SHORTCUT = 1;
146 static final int DIALOG_RENAME_FOLDER = 2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800147
Romain Guy98d01652009-06-30 16:21:04 -0700148 private static final String PREFERENCES = "launcher.preferences";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800149
150 // Type: int
151 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
152 // Type: boolean
153 private static final String RUNTIME_STATE_ALL_APPS_FOLDER = "launcher.all_apps_folder";
154 // Type: long
155 private static final String RUNTIME_STATE_USER_FOLDERS = "launcher.user_folder";
156 // Type: int
157 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
158 // Type: int
159 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cellX";
160 // Type: int
161 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cellY";
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800162 // Type: boolean
163 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
164 // Type: long
165 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
166
Winson Chung80baf5a2010-08-09 16:03:15 -0700167 // tags for the customization tabs
168 private static final String WIDGETS_TAG = "widgets";
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700169 private static final String APPLICATIONS_TAG = "applications";
Winson Chung80baf5a2010-08-09 16:03:15 -0700170 private static final String FOLDERS_TAG = "folders";
171 private static final String SHORTCUTS_TAG = "shortcuts";
172 private static final String WALLPAPERS_TAG = "wallpapers";
173
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700174 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
175
Patrick Dubroy6b509c12010-08-23 15:08:16 -0700176 /** The different states that Launcher can be in. */
177 private enum State { WORKSPACE, ALL_APPS, CUSTOMIZE, OVERVIEW };
178
Joe Onorato9c1289c2009-08-17 11:03:03 -0400179 static final int APPWIDGET_HOST_ID = 1024;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800180
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800181 private static final Object sLock = new Object();
Mike Cleron3a2b3f22009-11-05 17:17:42 -0800182 private static int sScreen = DEFAULT_SCREEN;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800183
Joe Onorato2ca0ae72009-11-10 13:14:13 -0800184 private final BroadcastReceiver mCloseSystemDialogsReceiver
185 = new CloseSystemDialogsIntentReceiver();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800186 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
187
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800188 private LayoutInflater mInflater;
189
Joe Onorato00acb122009-08-04 16:04:30 -0400190 private DragController mDragController;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800191 private Workspace mWorkspace;
Romain Guycbb89e42009-06-08 15:52:54 -0700192
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700193 private AppWidgetManager mAppWidgetManager;
194 private LauncherAppWidgetHost mAppWidgetHost;
Romain Guycbb89e42009-06-08 15:52:54 -0700195
Michael Jurka0280c3b2010-09-17 15:00:07 -0700196 private int mAddScreen = -1;
197 private int mAddIntersectCellX = -1;
198 private int mAddIntersectCellY = -1;
199 private int[] mAddDropPosition;
200 private int[] mTmpAddItemCellCoordinates = new int[2];
201
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800202 private FolderInfo mFolderInfo;
203
Joe Onorato7c312c12009-08-13 21:36:53 -0700204 private DeleteZone mDeleteZone;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700205 private HandleView mHandleView;
Joe Onorato7c312c12009-08-13 21:36:53 -0700206 private AllAppsView mAllAppsGrid;
Michael Jurka0e260592010-06-30 17:07:39 -0700207 private TabHost mHomeCustomizationDrawer;
Patrick Dubroy2b9ff372010-09-07 17:49:27 -0700208
209 private PagedView mAllAppsPagedView = null;
210 private CustomizePagedView mCustomizePagedView = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800211
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800212 private Bundle mSavedState;
213
214 private SpannableStringBuilder mDefaultKeySsb = null;
215
Joe Onorato9c1289c2009-08-17 11:03:03 -0400216 private boolean mWorkspaceLoading = true;
217
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800218 private boolean mPaused = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800219 private boolean mRestoring;
220 private boolean mWaitingForResult;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800221
222 private Bundle mSavedInstanceState;
223
Joe Onorato9c1289c2009-08-17 11:03:03 -0400224 private LauncherModel mModel;
Joe Onorato0589f0f2010-02-08 13:44:00 -0800225 private IconCache mIconCache;
Joe Onorato9c1289c2009-08-17 11:03:03 -0400226
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700227 private static LocaleConfiguration sLocaleConfiguration = null;
228
Romain Guy84f296c2009-11-04 15:00:44 -0800229 private ArrayList<ItemInfo> mDesktopItems = new ArrayList<ItemInfo>();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700230 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
Romain Guycbb89e42009-06-08 15:52:54 -0700231
Romain Guy1fbc1c82009-11-09 20:43:08 -0800232 private ImageView mPreviousView;
233 private ImageView mNextView;
Joe Onorato080d9b62009-11-02 12:01:11 -0500234
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400235 // Hotseats (quick-launch icons next to AllApps)
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400236 private String[] mHotseatConfig = null;
237 private Intent[] mHotseats = null;
238 private Drawable[] mHotseatIcons = null;
239 private CharSequence[] mHotseatLabels = null;
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400240
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700241 private Intent mAppMarketIntent = null;
Michael Jurka6ae0fcf2010-10-01 12:23:12 -0700242 private Intent mGlobalSearchIntent = null;
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700243
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800244 @Override
245 protected void onCreate(Bundle savedInstanceState) {
246 super.onCreate(savedInstanceState);
Romain Guyb1b69f52009-08-10 15:10:15 -0700247
Winson Chungaafa03c2010-06-11 17:34:16 -0700248 if (LauncherApplication.isInPlaceRotationEnabled()) {
249 // hide the status bar (temporary until we get the status bar design figured out)
250 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
251 this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
252 }
253
Joe Onorato0589f0f2010-02-08 13:44:00 -0800254 LauncherApplication app = ((LauncherApplication)getApplication());
255 mModel = app.setLauncher(this);
256 mIconCache = app.getIconCache();
Joe Onorato41a12d22009-10-31 18:30:00 -0400257 mDragController = new DragController(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800258 mInflater = getLayoutInflater();
Romain Guycbb89e42009-06-08 15:52:54 -0700259
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700260 mAppWidgetManager = AppWidgetManager.getInstance(this);
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700261 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
262 mAppWidgetHost.startListening();
Romain Guycbb89e42009-06-08 15:52:54 -0700263
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800264 if (PROFILE_STARTUP) {
265 android.os.Debug.startMethodTracing("/sdcard/launcher");
266 }
267
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400268 loadHotseats();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800269 checkForLocaleChange();
270 setWallpaperDimension();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800271 setContentView(R.layout.launcher);
Michael Jurka946ad472010-07-09 18:05:18 -0700272 mHomeCustomizationDrawer = (TabHost) findViewById(com.android.internal.R.id.tabhost);
273 if (mHomeCustomizationDrawer != null) {
274 mHomeCustomizationDrawer.setup();
Winson Chungaafa03c2010-06-11 17:34:16 -0700275
Winson Chung80baf5a2010-08-09 16:03:15 -0700276 // share the same customization workspace across all the tabs
Winson Chunge3193b92010-09-10 11:44:42 -0700277 mCustomizePagedView = (CustomizePagedView) mInflater.inflate(
278 R.layout.customization_drawer, mHomeCustomizationDrawer, false);
Winson Chung80baf5a2010-08-09 16:03:15 -0700279 TabContentFactory contentFactory = new TabContentFactory() {
280 public View createTabContent(String tag) {
281 return mCustomizePagedView;
282 }
283 };
284
Michael Jurka946ad472010-07-09 18:05:18 -0700285 String widgetsLabel = getString(R.string.widgets_tab_label);
Winson Chung80baf5a2010-08-09 16:03:15 -0700286 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(WIDGETS_TAG)
287 .setIndicator(widgetsLabel).setContent(contentFactory));
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700288 String applicationsLabel = getString(R.string.applications_tab_label);
289 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(APPLICATIONS_TAG)
290 .setIndicator(applicationsLabel).setContent(contentFactory));
Michael Jurka946ad472010-07-09 18:05:18 -0700291 String foldersLabel = getString(R.string.folders_tab_label);
Winson Chung80baf5a2010-08-09 16:03:15 -0700292 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(FOLDERS_TAG)
293 .setIndicator(foldersLabel).setContent(contentFactory));
Michael Jurka946ad472010-07-09 18:05:18 -0700294 String wallpapersLabel = getString(R.string.wallpapers_tab_label);
Winson Chung80baf5a2010-08-09 16:03:15 -0700295 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(WALLPAPERS_TAG)
296 .setIndicator(wallpapersLabel).setContent(contentFactory));
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700297 String shortcutsLabel = getString(R.string.shortcuts_tab_label);
298 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(SHORTCUTS_TAG)
299 .setIndicator(shortcutsLabel).setContent(contentFactory));
Winson Chung80baf5a2010-08-09 16:03:15 -0700300
301 // TEMP: just styling the tab widget to be a bit nicer until we get the actual
302 // new assets
303 TabWidget tabWidget = mHomeCustomizationDrawer.getTabWidget();
304 for (int i = 0; i < tabWidget.getChildCount(); ++i) {
305 RelativeLayout tab = (RelativeLayout) tabWidget.getChildTabViewAt(i);
306 TextView text = (TextView) tab.getChildAt(1);
307 text.setTextSize(20.0f);
308 text.setPadding(20, 0, 20, 0);
309 text.setShadowLayer(1.0f, 0.0f, 1.0f, Color.BLACK);
310 tab.setBackgroundDrawable(null);
311 }
312
313 mHomeCustomizationDrawer.setOnTabChangedListener(new OnTabChangeListener() {
314 public void onTabChanged(String tabId) {
315 // animate the changing of the tab content by fading pages in and out
316 final int duration = 150;
317 final float alpha = mCustomizePagedView.getAlpha();
Chet Haaseb1254a62010-09-07 13:35:00 -0700318 ValueAnimator alphaAnim = new ObjectAnimator(duration, mCustomizePagedView,
Winson Chung80baf5a2010-08-09 16:03:15 -0700319 "alpha", alpha, 0.0f);
Chet Haaseb1254a62010-09-07 13:35:00 -0700320 alphaAnim.addListener(new AnimatorListenerAdapter() {
321 public void onAnimationEnd(Animator animation) {
Winson Chung80baf5a2010-08-09 16:03:15 -0700322 String tag = mHomeCustomizationDrawer.getCurrentTabTag();
323 if (tag == WIDGETS_TAG) {
324 mCustomizePagedView.setCustomizationFilter(
325 CustomizePagedView.CustomizationType.WidgetCustomization);
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700326 } else if (tag == APPLICATIONS_TAG) {
327 mCustomizePagedView.setCustomizationFilter(
328 CustomizePagedView.CustomizationType.ApplicationCustomization);
Winson Chung80baf5a2010-08-09 16:03:15 -0700329 } else if (tag == FOLDERS_TAG) {
330 mCustomizePagedView.setCustomizationFilter(
331 CustomizePagedView.CustomizationType.FolderCustomization);
Winson Chung80baf5a2010-08-09 16:03:15 -0700332 } else if (tag == WALLPAPERS_TAG) {
333 mCustomizePagedView.setCustomizationFilter(
334 CustomizePagedView.CustomizationType.WallpaperCustomization);
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700335 } else if (tag == SHORTCUTS_TAG) {
336 mCustomizePagedView.setCustomizationFilter(
337 CustomizePagedView.CustomizationType.ShortcutCustomization);
Winson Chung80baf5a2010-08-09 16:03:15 -0700338 }
339
340 final float alpha = mCustomizePagedView.getAlpha();
Winson Chung5ffd8ea2010-09-23 18:40:29 -0700341 ValueAnimator alphaAnim = new ObjectAnimator(duration,
342 mCustomizePagedView, "alpha", alpha, 1.0f);
Winson Chung80baf5a2010-08-09 16:03:15 -0700343 alphaAnim.start();
344 }
345 });
346 alphaAnim.start();
347 }
348 });
Michael Jurka946ad472010-07-09 18:05:18 -0700349
350 mHomeCustomizationDrawer.setCurrentTab(0);
351 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800352 setupViews();
353
Jeff Sharkey1e2efc82009-11-06 15:17:59 -0800354 registerContentObservers();
355
Joe Onorato7c312c12009-08-13 21:36:53 -0700356 lockAllApps();
Joe Onorato7404ee42009-07-31 11:54:44 -0700357
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800358 mSavedState = savedInstanceState;
359 restoreState(mSavedState);
360
361 if (PROFILE_STARTUP) {
362 android.os.Debug.stopMethodTracing();
363 }
364
365 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400366 mModel.startLoader(this, true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800367 }
368
369 // For handling default keys
370 mDefaultKeySsb = new SpannableStringBuilder();
371 Selection.setSelection(mDefaultKeySsb, 0);
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800372
373 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
374 registerReceiver(mCloseSystemDialogsReceiver, filter);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800375 }
Romain Guycbb89e42009-06-08 15:52:54 -0700376
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800377 private void checkForLocaleChange() {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700378 if (sLocaleConfiguration == null) {
379 new AsyncTask<Void, Void, LocaleConfiguration>() {
380 @Override
381 protected LocaleConfiguration doInBackground(Void... unused) {
382 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
383 readConfiguration(Launcher.this, localeConfiguration);
384 return localeConfiguration;
385 }
386
387 @Override
388 protected void onPostExecute(LocaleConfiguration result) {
389 sLocaleConfiguration = result;
390 checkForLocaleChange(); // recursive, but now with a locale configuration
391 }
392 }.execute();
393 return;
394 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700395
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800396 final Configuration configuration = getResources().getConfiguration();
397
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700398 final String previousLocale = sLocaleConfiguration.locale;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800399 final String locale = configuration.locale.toString();
400
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700401 final int previousMcc = sLocaleConfiguration.mcc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800402 final int mcc = configuration.mcc;
403
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700404 final int previousMnc = sLocaleConfiguration.mnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800405 final int mnc = configuration.mnc;
406
Romain Guy84f296c2009-11-04 15:00:44 -0800407 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800408
Romain Guy84f296c2009-11-04 15:00:44 -0800409 if (localeChanged) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700410 sLocaleConfiguration.locale = locale;
411 sLocaleConfiguration.mcc = mcc;
412 sLocaleConfiguration.mnc = mnc;
Romain Guy98d01652009-06-30 16:21:04 -0700413
Joe Onorato0589f0f2010-02-08 13:44:00 -0800414 mIconCache.flush();
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400415 loadHotseats();
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700416
417 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
418 new Thread("WriteLocaleConfiguration") {
419 public void run() {
420 writeConfiguration(Launcher.this, localeConfiguration);
421 }
422 }.start();
Romain Guy98d01652009-06-30 16:21:04 -0700423 }
424 }
425
426 private static class LocaleConfiguration {
427 public String locale;
428 public int mcc = -1;
429 public int mnc = -1;
430 }
Jason Samsfd22dac2009-09-20 17:24:16 -0700431
Romain Guy98d01652009-06-30 16:21:04 -0700432 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
433 DataInputStream in = null;
434 try {
435 in = new DataInputStream(context.openFileInput(PREFERENCES));
436 configuration.locale = in.readUTF();
437 configuration.mcc = in.readInt();
438 configuration.mnc = in.readInt();
439 } catch (FileNotFoundException e) {
440 // Ignore
441 } catch (IOException e) {
442 // Ignore
443 } finally {
444 if (in != null) {
445 try {
446 in.close();
447 } catch (IOException e) {
448 // Ignore
449 }
450 }
451 }
452 }
453
454 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
455 DataOutputStream out = null;
456 try {
457 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
458 out.writeUTF(configuration.locale);
459 out.writeInt(configuration.mcc);
460 out.writeInt(configuration.mnc);
461 out.flush();
462 } catch (FileNotFoundException e) {
463 // Ignore
464 } catch (IOException e) {
465 //noinspection ResultOfMethodCallIgnored
466 context.getFileStreamPath(PREFERENCES).delete();
467 } finally {
468 if (out != null) {
469 try {
470 out.close();
471 } catch (IOException e) {
472 // Ignore
473 }
474 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800475 }
476 }
477
478 static int getScreen() {
479 synchronized (sLock) {
480 return sScreen;
481 }
482 }
483
484 static void setScreen(int screen) {
485 synchronized (sLock) {
486 sScreen = screen;
487 }
488 }
489
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800490 private void setWallpaperDimension() {
Dianne Hackborn107f8392009-08-05 21:32:16 -0700491 WallpaperManager wpm = (WallpaperManager)getSystemService(WALLPAPER_SERVICE);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800492
493 Display display = getWindowManager().getDefaultDisplay();
Romain Guy5bbc91b2010-08-18 11:38:46 -0700494 // TODO: Put back when we decide about scrolling the wallpaper
495 // boolean isPortrait = display.getWidth() < display.getHeight();
496 // final int width = isPortrait ? display.getWidth() : display.getHeight();
497 // final int height = isPortrait ? display.getHeight() : display.getWidth();
498 wpm.suggestDesiredDimensions(Math.max(display.getWidth(), display.getHeight()),
499 Math.max(display.getWidth(), display.getHeight()));
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800500 }
501
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400502 // Note: This doesn't do all the client-id magic that BrowserProvider does
503 // in Browser. (http://b/2425179)
504 private Uri getDefaultBrowserUri() {
505 String url = getString(R.string.default_browser_url);
506 if (url.indexOf("{CID}") != -1) {
507 url = url.replace("{CID}", "android-google");
508 }
509 return Uri.parse(url);
510 }
511
512 // Load the Intent templates from arrays.xml to populate the hotseats. For
513 // each Intent, if it resolves to a single app, use that as the launch
514 // intent & use that app's label as the contentDescription. Otherwise,
515 // retain the ResolveActivity so the user can pick an app.
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400516 private void loadHotseats() {
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400517 if (mHotseatConfig == null) {
518 mHotseatConfig = getResources().getStringArray(R.array.hotseats);
519 if (mHotseatConfig.length > 0) {
520 mHotseats = new Intent[mHotseatConfig.length];
521 mHotseatLabels = new CharSequence[mHotseatConfig.length];
522 mHotseatIcons = new Drawable[mHotseatConfig.length];
523 } else {
524 mHotseats = null;
525 mHotseatIcons = null;
526 mHotseatLabels = null;
527 }
528
529 TypedArray hotseatIconDrawables = getResources().obtainTypedArray(R.array.hotseat_icons);
530 for (int i=0; i<mHotseatConfig.length; i++) {
531 // load icon for this slot; currently unrelated to the actual activity
532 try {
533 mHotseatIcons[i] = hotseatIconDrawables.getDrawable(i);
534 } catch (ArrayIndexOutOfBoundsException ex) {
535 Log.w(TAG, "Missing hotseat_icons array item #" + i);
536 mHotseatIcons[i] = null;
537 }
538 }
539 hotseatIconDrawables.recycle();
540 }
541
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400542 PackageManager pm = getPackageManager();
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400543 for (int i=0; i<mHotseatConfig.length; i++) {
544 Intent intent = null;
545 if (mHotseatConfig[i].equals("*BROWSER*")) {
546 // magic value meaning "launch user's default web browser"
547 // replace it with a generic web request so we can see if there is indeed a default
548 String defaultUri = getString(R.string.default_browser_url);
549 intent = new Intent(
550 Intent.ACTION_VIEW,
551 ((defaultUri != null)
552 ? Uri.parse(defaultUri)
553 : getDefaultBrowserUri())
554 ).addCategory(Intent.CATEGORY_BROWSABLE);
555 // note: if the user launches this without a default set, she
556 // will always be taken to the default URL above; this is
557 // unavoidable as we must specify a valid URL in order for the
Winson Chungaafa03c2010-06-11 17:34:16 -0700558 // chooser to appear, and once the user selects something, that
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400559 // URL is unavoidably sent to the chosen app.
560 } else {
561 try {
562 intent = Intent.parseUri(mHotseatConfig[i], 0);
563 } catch (java.net.URISyntaxException ex) {
564 Log.w(TAG, "Invalid hotseat intent: " + mHotseatConfig[i]);
565 // bogus; leave intent=null
566 }
567 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700568
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400569 if (intent == null) {
570 mHotseats[i] = null;
571 mHotseatLabels[i] = getText(R.string.activity_not_found);
572 continue;
573 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400574
575 if (LOGD) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700576 Log.d(TAG, "loadHotseats: hotseat " + i
577 + " initial intent=["
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400578 + intent.toUri(Intent.URI_INTENT_SCHEME)
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400579 + "]");
580 }
581
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400582 ResolveInfo bestMatch = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
583 List<ResolveInfo> allMatches = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
Winson Chungaafa03c2010-06-11 17:34:16 -0700584 if (LOGD) {
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400585 Log.d(TAG, "Best match for intent: " + bestMatch);
586 Log.d(TAG, "All matches: ");
587 for (ResolveInfo ri : allMatches) {
588 Log.d(TAG, " --> " + ri);
589 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400590 }
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400591 // did this resolve to a single app, or the resolver?
592 if (allMatches.size() == 0 || bestMatch == null) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700593 // can't find any activity to handle this. let's leave the
594 // intent as-is and let Launcher show a toast when it fails
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400595 // to launch.
596 mHotseats[i] = intent;
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400597
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400598 // set accessibility text to "Not installed"
599 mHotseatLabels[i] = getText(R.string.activity_not_found);
600 } else {
601 boolean found = false;
602 for (ResolveInfo ri : allMatches) {
603 if (bestMatch.activityInfo.name.equals(ri.activityInfo.name)
604 && bestMatch.activityInfo.applicationInfo.packageName
605 .equals(ri.activityInfo.applicationInfo.packageName)) {
606 found = true;
607 break;
608 }
609 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700610
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400611 if (!found) {
612 if (LOGD) Log.d(TAG, "Multiple options, no default yet");
613 // the bestMatch is probably the ResolveActivity, meaning the
614 // user has not yet selected a default
615 // so: we'll keep the original intent for now
616 mHotseats[i] = intent;
617
618 // set the accessibility text to "Select shortcut"
619 mHotseatLabels[i] = getText(R.string.title_select_shortcut);
620 } else {
621 // we have an app!
622 // now reconstruct the intent to launch it through the front
623 // door
624 ComponentName com = new ComponentName(
625 bestMatch.activityInfo.applicationInfo.packageName,
626 bestMatch.activityInfo.name);
627 mHotseats[i] = new Intent(Intent.ACTION_MAIN).setComponent(com);
628
629 // load the app label for accessibility
630 mHotseatLabels[i] = bestMatch.activityInfo.loadLabel(pm);
631 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400632 }
633
634 if (LOGD) {
Winson Chungaafa03c2010-06-11 17:34:16 -0700635 Log.d(TAG, "loadHotseats: hotseat " + i
636 + " final intent=["
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400637 + ((mHotseats[i] == null)
638 ? "null"
639 : mHotseats[i].toUri(Intent.URI_INTENT_SCHEME))
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400640 + "] label=[" + mHotseatLabels[i]
641 + "]"
642 );
643 }
644 }
645 }
646
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800647 @Override
648 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Romain Guyaad5ef42009-06-10 02:48:37 -0700649 mWaitingForResult = false;
650
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800651 // The pattern used here is that a user PICKs a specific application,
652 // which, depending on the target, might need to CREATE the actual target.
Romain Guycbb89e42009-06-08 15:52:54 -0700653
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800654 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
655 // launch over to the Music app to actually CREATE_SHORTCUT.
Romain Guycbb89e42009-06-08 15:52:54 -0700656
Michael Jurka0280c3b2010-09-17 15:00:07 -0700657 if (resultCode == RESULT_OK && mAddScreen != -1) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800658 switch (requestCode) {
659 case REQUEST_PICK_APPLICATION:
Michael Jurka28750fb2010-09-24 17:43:49 -0700660 completeAddApplication(
661 this, data, mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800662 break;
663 case REQUEST_PICK_SHORTCUT:
Joe Onoratodeb98af2010-02-19 14:59:39 -0800664 processShortcut(data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800665 break;
666 case REQUEST_CREATE_SHORTCUT:
Michael Jurka0280c3b2010-09-17 15:00:07 -0700667 completeAddShortcut(data, mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800668 break;
669 case REQUEST_PICK_LIVE_FOLDER:
670 addLiveFolder(data);
671 break;
672 case REQUEST_CREATE_LIVE_FOLDER:
Michael Jurka0280c3b2010-09-17 15:00:07 -0700673 completeAddLiveFolder(data, mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800674 break;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700675 case REQUEST_PICK_APPWIDGET:
Michael Jurkaaf442092010-06-10 17:01:57 -0700676 addAppWidgetFromPick(data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800677 break;
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700678 case REQUEST_CREATE_APPWIDGET:
Michael Jurkaaf442092010-06-10 17:01:57 -0700679 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700680 completeAddAppWidget(appWidgetId, mAddScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800681 break;
Mike Clerona0618e42009-10-22 13:55:21 -0700682 case REQUEST_PICK_WALLPAPER:
683 // We just wanted the activity result here so we can clear mWaitingForResult
684 break;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800685 }
Romain Guy18042c82009-11-06 11:44:55 -0800686 } else if ((requestCode == REQUEST_PICK_APPWIDGET ||
687 requestCode == REQUEST_CREATE_APPWIDGET) && resultCode == RESULT_CANCELED &&
688 data != null) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700689 // Clean up the appWidgetId if we canceled
690 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
691 if (appWidgetId != -1) {
692 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800693 }
694 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800695 }
696
697 @Override
698 protected void onResume() {
699 super.onResume();
700
Joe Onorato34a0e1b2009-12-14 17:44:51 -0800701 mPaused = false;
Joe Onorato7e4ed992009-12-03 13:10:49 -0800702
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800703 if (mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400704 mWorkspaceLoading = true;
705 mModel.startLoader(this, true);
706 mRestoring = false;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800707 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -0700708 // When we resume Launcher, a different Activity might be responsible for the app
709 // market intent, so refresh the icon
710 updateAppMarketIcon();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800711 }
712
713 @Override
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700714 protected void onPause() {
715 super.onPause();
Michael Jurkaaf442092010-06-10 17:01:57 -0700716 // Some launcher layouts don't have a previous and next view
717 if (mPreviousView != null) {
718 dismissPreview(mPreviousView);
Patrick Dubroyab962b72010-07-26 12:10:10 -0700719 }
720 if (mNextView != null) {
Michael Jurkaaf442092010-06-10 17:01:57 -0700721 dismissPreview(mNextView);
722 }
Joe Onorato24b6fd82009-11-12 13:47:09 -0800723 mDragController.cancelDrag();
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700724 }
Romain Guycbb89e42009-06-08 15:52:54 -0700725
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700726 @Override
727 public Object onRetainNonConfigurationInstance() {
Joe Onorato9c1289c2009-08-17 11:03:03 -0400728 // Flag the loader to stop early before switching
729 mModel.stopLoader();
Romain Guy13c2e7b2010-03-10 19:45:00 -0800730 mAllAppsGrid.surrender();
Romain Guy13c2e7b2010-03-10 19:45:00 -0800731 return Boolean.TRUE;
Jeffrey Sharkey99c87582009-03-24 17:59:43 -0700732 }
The Android Open Source Project7376fae2009-03-11 12:11:58 -0700733
Joe Onorato2d7e7d02010-01-29 15:57:19 -0800734 // We can't hide the IME if it was forced open. So don't bother
735 /*
736 @Override
737 public void onWindowFocusChanged(boolean hasFocus) {
738 super.onWindowFocusChanged(hasFocus);
739
740 if (hasFocus) {
741 final InputMethodManager inputManager = (InputMethodManager)
742 getSystemService(Context.INPUT_METHOD_SERVICE);
743 WindowManager.LayoutParams lp = getWindow().getAttributes();
744 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new
745 android.os.Handler()) {
746 protected void onReceiveResult(int resultCode, Bundle resultData) {
747 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode);
748 }
749 });
750 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged");
751 }
752 }
753 */
754
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800755 private boolean acceptFilter() {
756 final InputMethodManager inputManager = (InputMethodManager)
757 getSystemService(Context.INPUT_METHOD_SERVICE);
758 return !inputManager.isFullscreenMode();
759 }
760
761 @Override
762 public boolean onKeyDown(int keyCode, KeyEvent event) {
763 boolean handled = super.onKeyDown(keyCode, event);
764 if (!handled && acceptFilter() && keyCode != KeyEvent.KEYCODE_ENTER) {
765 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
766 keyCode, event);
767 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
Karl Rosaen138a0412009-04-23 19:00:21 -0700768 // something usable has been typed - start a search
Romain Guycbb89e42009-06-08 15:52:54 -0700769 // the typed text will be retrieved and cleared by
Karl Rosaen138a0412009-04-23 19:00:21 -0700770 // showSearchDialog()
771 // If there are multiple keystrokes before the search dialog takes focus,
772 // onSearchRequested() will be called for every keystroke,
773 // but it is idempotent, so it's fine.
774 return onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800775 }
776 }
777
Joe Onorato8a9625e2010-01-28 15:55:35 -0800778 // Eat the long press event so the keyboard doesn't come up.
779 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
780 return true;
781 }
782
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800783 return handled;
784 }
785
Karl Rosaen138a0412009-04-23 19:00:21 -0700786 private String getTypedText() {
787 return mDefaultKeySsb.toString();
788 }
789
790 private void clearTypedText() {
791 mDefaultKeySsb.clear();
792 mDefaultKeySsb.clearSpans();
793 Selection.setSelection(mDefaultKeySsb, 0);
794 }
795
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800796 /**
797 * Restores the previous state, if it exists.
798 *
799 * @param savedState The previous state.
800 */
801 private void restoreState(Bundle savedState) {
802 if (savedState == null) {
803 return;
804 }
805
Joe Onorato3a8820b2009-11-10 15:06:42 -0800806 final boolean allApps = savedState.getBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, false);
807 if (allApps) {
808 showAllApps(false);
809 }
810
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800811 final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
812 if (currentScreen > -1) {
Michael Jurka0142d492010-08-25 17:46:15 -0700813 mWorkspace.setCurrentPage(currentScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800814 }
815
816 final int addScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
Michael Jurka0280c3b2010-09-17 15:00:07 -0700817
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800818 if (addScreen > -1) {
Michael Jurka0280c3b2010-09-17 15:00:07 -0700819 mAddScreen = addScreen;
820 mAddIntersectCellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
821 mAddIntersectCellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800822 mRestoring = true;
823 }
824
825 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
826 if (renameFolder) {
827 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -0700828 mFolderInfo = mModel.getFolderById(this, sFolders, id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800829 mRestoring = true;
830 }
831 }
832
833 /**
834 * Finds all the views we need and configure them properly.
835 */
836 private void setupViews() {
Michael Jurkaa63c4522010-08-19 13:52:27 -0700837 final DragController dragController = mDragController;
Joe Onorato00acb122009-08-04 16:04:30 -0400838
Romain Guyb1b69f52009-08-10 15:10:15 -0700839 DragLayer dragLayer = (DragLayer) findViewById(R.id.drag_layer);
Joe Onorato00acb122009-08-04 16:04:30 -0400840 dragLayer.setDragController(dragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800841
Joe Onorato7c312c12009-08-13 21:36:53 -0700842 mAllAppsGrid = (AllAppsView)dragLayer.findViewById(R.id.all_apps_view);
Joe Onorato6665c0f2009-09-02 15:27:24 -0700843 mAllAppsGrid.setLauncher(this);
Joe Onorato5162ea92009-09-03 09:39:42 -0700844 mAllAppsGrid.setDragController(dragController);
Romain Guyc16fea72010-03-12 17:17:56 -0800845 ((View) mAllAppsGrid).setWillNotDraw(false); // We don't want a hole punched in our window.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700846 // Manage focusability manually since this thing is always visible (in non-xlarge)
Winson Chungaafa03c2010-06-11 17:34:16 -0700847 ((View) mAllAppsGrid).setFocusable(false);
Joe Onorato7c312c12009-08-13 21:36:53 -0700848
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -0700849 if (LauncherApplication.isScreenXLarge()) {
850 // They need to be INVISIBLE initially so that they will be measured in the layout.
851 // Otherwise the animations are messed up when we show them for the first time.
852 ((View) mAllAppsGrid).setVisibility(View.INVISIBLE);
853 mHomeCustomizationDrawer.setVisibility(View.INVISIBLE);
854 }
855
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800856 mWorkspace = (Workspace) dragLayer.findViewById(R.id.workspace);
857 final Workspace workspace = mWorkspace;
Joe Onoratof0dde092010-02-16 18:25:23 -0500858 workspace.setHapticFeedbackEnabled(false);
Michael Jurka946ad472010-07-09 18:05:18 -0700859
Joe Onorato7c312c12009-08-13 21:36:53 -0700860 DeleteZone deleteZone = (DeleteZone) dragLayer.findViewById(R.id.delete_zone);
861 mDeleteZone = deleteZone;
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800862
Michael Jurka2c3af5f2010-08-03 13:53:20 -0700863 View handleView = findViewById(R.id.all_apps_button);
864 if (handleView != null && handleView instanceof HandleView) {
865 // we don't use handle view in xlarge mode
Michael Jurka7ef4f752010-08-03 16:04:26 -0700866 mHandleView = (HandleView)handleView;
Michael Jurka2c3af5f2010-08-03 13:53:20 -0700867 mHandleView.setLauncher(this);
868 mHandleView.setOnClickListener(this);
869 mHandleView.setOnLongClickListener(this);
870 }
Romain Guy1fbc1c82009-11-09 20:43:08 -0800871
Winson Chung80baf5a2010-08-09 16:03:15 -0700872 if (mCustomizePagedView != null) {
873 mCustomizePagedView.setLauncher(this);
874 mCustomizePagedView.setDragController(dragController);
875 mCustomizePagedView.update();
Michael Jurkaaf442092010-06-10 17:01:57 -0700876 } else {
877 ImageView hotseatLeft = (ImageView) findViewById(R.id.hotseat_left);
878 hotseatLeft.setContentDescription(mHotseatLabels[0]);
879 hotseatLeft.setImageDrawable(mHotseatIcons[0]);
880 ImageView hotseatRight = (ImageView) findViewById(R.id.hotseat_right);
881 hotseatRight.setContentDescription(mHotseatLabels[1]);
882 hotseatRight.setImageDrawable(mHotseatIcons[1]);
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400883
Michael Jurkaaf442092010-06-10 17:01:57 -0700884 mPreviousView = (ImageView) dragLayer.findViewById(R.id.previous_screen);
885 mNextView = (ImageView) dragLayer.findViewById(R.id.next_screen);
Romain Guy1fbc1c82009-11-09 20:43:08 -0800886
Michael Jurkaaf442092010-06-10 17:01:57 -0700887 Drawable previous = mPreviousView.getDrawable();
888 Drawable next = mNextView.getDrawable();
889 mWorkspace.setIndicators(previous, next);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800890
Michael Jurkaaf442092010-06-10 17:01:57 -0700891 mPreviousView.setHapticFeedbackEnabled(false);
892 mPreviousView.setOnLongClickListener(this);
893 mNextView.setHapticFeedbackEnabled(false);
894 mNextView.setOnLongClickListener(this);
895 }
Romain Guy1fbc1c82009-11-09 20:43:08 -0800896
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800897 workspace.setOnLongClickListener(this);
Joe Onorato00acb122009-08-04 16:04:30 -0400898 workspace.setDragController(dragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800899 workspace.setLauncher(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800900
901 deleteZone.setLauncher(this);
Joe Onorato00acb122009-08-04 16:04:30 -0400902 deleteZone.setDragController(dragController);
Michael Jurka54f7ac32010-08-02 13:56:46 -0700903 int deleteZoneHandleId;
904 if (LauncherApplication.isScreenXLarge()) {
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700905 deleteZoneHandleId = R.id.all_apps_button;
Michael Jurka54f7ac32010-08-02 13:56:46 -0700906 } else {
907 deleteZoneHandleId = R.id.all_apps_button_cluster;
908 }
Michael Jurkaaf442092010-06-10 17:01:57 -0700909 deleteZone.setHandle(findViewById(deleteZoneHandleId));
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700910 dragController.addDragListener(deleteZone);
911
912 ApplicationInfoDropTarget infoButton = (ApplicationInfoDropTarget)findViewById(R.id.info_button);
913 if (infoButton != null) {
914 infoButton.setLauncher(this);
915 infoButton.setHandle(findViewById(R.id.configure_button));
916 infoButton.setDragColor(getResources().getColor(R.color.app_info_filter));
917 dragController.addDragListener(infoButton);
918 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800919
Joe Onorato00acb122009-08-04 16:04:30 -0400920 dragController.setDragScoller(workspace);
Joe Onorato00acb122009-08-04 16:04:30 -0400921 dragController.setScrollView(dragLayer);
Romain Guyea3763c2010-01-11 18:02:04 -0800922 dragController.setMoveTarget(workspace);
Jason Samsfd22dac2009-09-20 17:24:16 -0700923
Joe Onorato00acb122009-08-04 16:04:30 -0400924 // The order here is bottom to top.
925 dragController.addDropTarget(workspace);
926 dragController.addDropTarget(deleteZone);
Patrick Dubroy4ed62782010-08-17 15:11:18 -0700927 if (infoButton != null) {
928 dragController.addDropTarget(infoButton);
929 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800930 }
931
Romain Guy8a73c512009-11-09 19:19:59 -0800932 @SuppressWarnings({"UnusedDeclaration"})
933 public void previousScreen(View v) {
Joe Onorato61597bd2009-11-19 12:51:57 -0800934 if (!isAllAppsVisible()) {
935 mWorkspace.scrollLeft();
936 }
Romain Guy8a73c512009-11-09 19:19:59 -0800937 }
938
939 @SuppressWarnings({"UnusedDeclaration"})
940 public void nextScreen(View v) {
Joe Onorato61597bd2009-11-19 12:51:57 -0800941 if (!isAllAppsVisible()) {
942 mWorkspace.scrollRight();
943 }
Romain Guy8a73c512009-11-09 19:19:59 -0800944 }
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400945
946 @SuppressWarnings({"UnusedDeclaration"})
947 public void launchHotSeat(View v) {
Daniel Sandler3e9454a2010-05-24 11:22:41 -0400948 if (isAllAppsVisible()) return;
949
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400950 int index = -1;
951 if (v.getId() == R.id.hotseat_left) {
952 index = 0;
953 } else if (v.getId() == R.id.hotseat_right) {
954 index = 1;
955 }
956
Daniel Sandlerab1ebd72010-04-27 16:57:25 -0400957 // reload these every tap; you never know when they might change
958 loadHotseats();
959 if (index >= 0 && index < mHotseats.length && mHotseats[index] != null) {
960 Intent intent = mHotseats[index];
Daniel Sandlerc9b18772010-04-22 14:37:59 -0400961 startActivitySafely(
962 mHotseats[index],
963 "hotseat"
964 );
965 }
966 }
Winson Chungaafa03c2010-06-11 17:34:16 -0700967
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800968 /**
969 * Creates a view representing a shortcut.
970 *
971 * @param info The data structure describing the shortcut.
972 *
973 * @return A View inflated from R.layout.application.
974 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800975 View createShortcut(ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800976 return createShortcut(R.layout.application,
Michael Jurka0142d492010-08-25 17:46:15 -0700977 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800978 }
979
980 /**
981 * Creates a view representing a shortcut inflated from the specified resource.
982 *
983 * @param layoutResId The id of the XML layout used to create the shortcut.
984 * @param parent The group the shortcut belongs to.
985 * @param info The data structure describing the shortcut.
986 *
987 * @return A View inflated from layoutResId.
988 */
Joe Onorato0589f0f2010-02-08 13:44:00 -0800989 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800990 TextView favorite = (TextView) mInflater.inflate(layoutResId, parent, false);
991
Joe Onorato0589f0f2010-02-08 13:44:00 -0800992 favorite.setCompoundDrawablesWithIntrinsicBounds(null,
993 new FastBitmapDrawable(info.getIcon(mIconCache)),
994 null, null);
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800995 favorite.setText(info.title);
996 favorite.setTag(info);
997 favorite.setOnClickListener(this);
998
999 return favorite;
1000 }
1001
1002 /**
1003 * Add an application shortcut to the workspace.
1004 *
1005 * @param data The intent describing the application.
1006 * @param cellInfo The position on screen where to create the shortcut.
1007 */
Michael Jurka0280c3b2010-09-17 15:00:07 -07001008 void completeAddApplication(Context context, Intent data, int screen,
1009 int intersectCellX, int intersectCellY) {
1010 final int[] cellXY = mTmpAddItemCellCoordinates;
1011 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1012
1013 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1014 showOutOfSpaceMessage();
1015 return;
1016 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001017
Joe Onorato0589f0f2010-02-08 13:44:00 -08001018 final ShortcutInfo info = mModel.getShortcutInfo(context.getPackageManager(),
1019 data, context);
1020
Romain Guy73b979d2009-06-09 12:57:21 -07001021 if (info != null) {
Joe Onorato0589f0f2010-02-08 13:44:00 -08001022 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK |
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001023 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001024 info.container = ItemInfo.NO_ID;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001025 mWorkspace.addApplicationShortcut(info, screen, cellXY[0], cellXY[1],
1026 isWorkspaceLocked(), mAddIntersectCellX, mAddIntersectCellY);
Joe Onorato0589f0f2010-02-08 13:44:00 -08001027 } else {
1028 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001029 }
1030 }
Romain Guycbb89e42009-06-08 15:52:54 -07001031
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001032 /**
1033 * Add a shortcut to the workspace.
1034 *
1035 * @param data The intent describing the shortcut.
1036 * @param cellInfo The position on screen where to create the shortcut.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001037 */
Michael Jurka0280c3b2010-09-17 15:00:07 -07001038 private void completeAddShortcut(Intent data, int screen,
1039 int intersectCellX, int intersectCellY) {
1040 final int[] cellXY = mTmpAddItemCellCoordinates;
1041 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
Romain Guycbb89e42009-06-08 15:52:54 -07001042
Michael Jurka0280c3b2010-09-17 15:00:07 -07001043 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1044 showOutOfSpaceMessage();
1045 return;
1046 }
1047
1048 final ShortcutInfo info = mModel.addShortcut(
1049 this, data, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001050
1051 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001052 final View view = createShortcut(info);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001053 mWorkspace.addInScreen(view, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001054 }
1055 }
1056
Romain Guycbb89e42009-06-08 15:52:54 -07001057
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001058 /**
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001059 * Add a widget to the workspace.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001060 *
Romain Guy5bbc91b2010-08-18 11:38:46 -07001061 * @param appWidgetId The app widget id
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001062 * @param cellInfo The position on screen where to create the widget.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001063 */
Michael Jurka0280c3b2010-09-17 15:00:07 -07001064 private void completeAddAppWidget(int appWidgetId, int screen) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001065 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Romain Guycbb89e42009-06-08 15:52:54 -07001066
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001067 // Calculate the grid spans needed to fit this widget
Michael Jurka0280c3b2010-09-17 15:00:07 -07001068 CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1069 int[] spanXY = layout.rectToCell(appWidgetInfo.minWidth, appWidgetInfo.minHeight, null);
Romain Guycbb89e42009-06-08 15:52:54 -07001070
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001071 // Try finding open space on Launcher screen
Michael Jurkaa63c4522010-08-19 13:52:27 -07001072 // We have saved the position to which the widget was dragged-- this really only matters
1073 // if we are placing widgets on a "spring-loaded" screen
Michael Jurka0280c3b2010-09-17 15:00:07 -07001074 final int[] cellXY = mTmpAddItemCellCoordinates;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001075
1076 // For now, we don't save the coordinate where we dropped the icon because we're not
1077 // supporting spring-loaded mini-screens; however, leaving the ability to directly place
1078 // a widget on the home screen in case we want to add it in the future
Michael Jurka0280c3b2010-09-17 15:00:07 -07001079 final int[] touchXY = null;
1080 //final int[] touchXY = mAddDropPosition;
Michael Jurkaa63c4522010-08-19 13:52:27 -07001081 boolean findNearestVacantAreaFailed = false;
Michael Jurka0280c3b2010-09-17 15:00:07 -07001082 boolean foundCellSpan = false;
1083 if (touchXY != null) {
1084 // when dragging and dropping, just find the closest free spot
1085 CellLayout screenLayout = (CellLayout) mWorkspace.getChildAt(screen);
1086 int[] result = screenLayout.findNearestVacantArea(
1087 touchXY[0], touchXY[1], spanXY[0], spanXY[1], cellXY);
Michael Jurkaa63c4522010-08-19 13:52:27 -07001088 findNearestVacantAreaFailed = (result == null);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001089 foundCellSpan = !findNearestVacantAreaFailed;
1090 } else {
1091 if (mAddIntersectCellX != -1 && mAddIntersectCellY != -1) {
1092 // if we long pressed on an empty cell to bring up a menu,
1093 // make sure we intersect the empty cell
1094 foundCellSpan = layout.findCellForSpanThatIntersects(cellXY, spanXY[0], spanXY[1],
1095 mAddIntersectCellX, mAddIntersectCellY);
1096 } else {
1097 // if we went through the menu -> add, just find any spot
1098 foundCellSpan = layout.findCellForSpan(cellXY, spanXY[0], spanXY[1]);
1099 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001100 }
1101
Michael Jurka0280c3b2010-09-17 15:00:07 -07001102 if (!foundCellSpan) {
Romain Guy18042c82009-11-06 11:44:55 -08001103 if (appWidgetId != -1) mAppWidgetHost.deleteAppWidgetId(appWidgetId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001104 showOutOfSpaceMessage();
Romain Guy18042c82009-11-06 11:44:55 -08001105 return;
1106 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001107
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001108 // Build Launcher-specific widget info and save to database
1109 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001110 launcherInfo.spanX = spanXY[0];
1111 launcherInfo.spanY = spanXY[1];
Romain Guycbb89e42009-06-08 15:52:54 -07001112
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001113 LauncherModel.addItemToDatabase(this, launcherInfo,
1114 LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001115 screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001116
1117 if (!mRestoring) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001118 mDesktopItems.add(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001119
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001120 // Perform actual inflation because we're live
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001121 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001122
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001123 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001124 launcherInfo.hostView.setTag(launcherInfo);
Romain Guycbb89e42009-06-08 15:52:54 -07001125
Michael Jurka0280c3b2010-09-17 15:00:07 -07001126 mWorkspace.addInScreen(launcherInfo.hostView, screen, cellXY[0], cellXY[1],
Joe Onorato9c1289c2009-08-17 11:03:03 -04001127 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001128 }
1129 }
Romain Guycbb89e42009-06-08 15:52:54 -07001130
Michael Jurka0280c3b2010-09-17 15:00:07 -07001131 void showOutOfSpaceMessage() {
1132 Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show();
1133 }
1134
Joe Onorato9c1289c2009-08-17 11:03:03 -04001135 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
1136 mDesktopItems.remove(launcherInfo);
1137 launcherInfo.hostView = null;
1138 }
1139
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001140 public LauncherAppWidgetHost getAppWidgetHost() {
1141 return mAppWidgetHost;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001142 }
Romain Guycbb89e42009-06-08 15:52:54 -07001143
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001144 void closeSystemDialogs() {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001145 getWindow().closeAllPanels();
1146
1147 try {
1148 dismissDialog(DIALOG_CREATE_SHORTCUT);
1149 // Unlock the workspace if the dialog was showing
1150 } catch (Exception e) {
1151 // An exception is thrown if the dialog is not visible, which is fine
1152 }
1153
1154 try {
1155 dismissDialog(DIALOG_RENAME_FOLDER);
1156 // Unlock the workspace if the dialog was showing
1157 } catch (Exception e) {
1158 // An exception is thrown if the dialog is not visible, which is fine
1159 }
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001160
1161 // Whatever we were doing is hereby canceled.
1162 mWaitingForResult = false;
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001163 }
1164
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001165 @Override
1166 protected void onNewIntent(Intent intent) {
1167 super.onNewIntent(intent);
1168
1169 // Close the menu
1170 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
Joe Onoratoa5c32d62009-11-19 10:28:49 -08001171 // also will cancel mWaitingForResult.
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001172 closeSystemDialogs();
Jason Samsfd22dac2009-09-20 17:24:16 -07001173
Joe Onorato14f122b2009-11-19 14:06:36 -08001174 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1175 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
1176 boolean allAppsVisible = isAllAppsVisible();
Michael Jurka01f0ed42010-08-20 00:41:17 -07001177 boolean customizationDrawerVisible = isCustomizationDrawerVisible();
1178
Michael Jurka4cb37242010-08-09 21:05:32 -07001179 // in all these cases, only animate if we're already on home
1180 if (LauncherApplication.isScreenXLarge()) {
Michael Jurka99229f62010-09-09 11:49:32 -07001181 mWorkspace.unshrink(alreadyOnHome);
1182 }
1183 if (!mWorkspace.isDefaultPageShowing()) {
Michael Jurka4cb37242010-08-09 21:05:32 -07001184 // on the phone, we don't animate the change to the workspace if all apps is visible
Michael Jurka99229f62010-09-09 11:49:32 -07001185 mWorkspace.moveToDefaultScreen(
1186 alreadyOnHome && (LauncherApplication.isScreenXLarge() || !allAppsVisible));
Joe Onorato3a8820b2009-11-10 15:06:42 -08001187 }
Joe Onorato14f122b2009-11-19 14:06:36 -08001188 closeAllApps(alreadyOnHome && allAppsVisible);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07001189 hideCustomizationDrawer(alreadyOnHome);
Romain Guy1dd3a072009-07-16 13:21:01 -07001190
Joe Onorato3a8820b2009-11-10 15:06:42 -08001191 final View v = getWindow().peekDecorView();
1192 if (v != null && v.getWindowToken() != null) {
1193 InputMethodManager imm = (InputMethodManager)getSystemService(
1194 INPUT_METHOD_SERVICE);
1195 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001196 }
1197 }
1198 }
1199
1200 @Override
1201 protected void onRestoreInstanceState(Bundle savedInstanceState) {
1202 // Do not call super here
1203 mSavedInstanceState = savedInstanceState;
Michael Jurka946ad472010-07-09 18:05:18 -07001204
1205 if (mHomeCustomizationDrawer != null) {
1206 String cur = savedInstanceState.getString("currentTab");
1207 if (cur != null) {
1208 mHomeCustomizationDrawer.setCurrentTabByTag(cur);
1209 }
1210 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001211 }
1212
1213 @Override
1214 protected void onSaveInstanceState(Bundle outState) {
Michael Jurka0142d492010-08-25 17:46:15 -07001215 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001216
1217 final ArrayList<Folder> folders = mWorkspace.getOpenFolders();
1218 if (folders.size() > 0) {
1219 final int count = folders.size();
1220 long[] ids = new long[count];
1221 for (int i = 0; i < count; i++) {
1222 final FolderInfo info = folders.get(i).getInfo();
1223 ids[i] = info.id;
1224 }
1225 outState.putLongArray(RUNTIME_STATE_USER_FOLDERS, ids);
1226 } else {
1227 super.onSaveInstanceState(outState);
1228 }
1229
Joe Onoratofb0ca672009-09-14 17:55:46 -04001230 // TODO should not do this if the drawer is currently closing.
Joe Onorato3a8820b2009-11-10 15:06:42 -08001231 if (isAllAppsVisible()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001232 outState.putBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, true);
Romain Guy5a941392009-04-28 15:18:25 -07001233 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001234
Michael Jurka0280c3b2010-09-17 15:00:07 -07001235 if (mAddScreen > -1 && mWaitingForResult) {
1236 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mAddScreen);
1237 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mAddIntersectCellX);
1238 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mAddIntersectCellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001239 }
1240
1241 if (mFolderInfo != null && mWaitingForResult) {
1242 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
1243 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
1244 }
Michael Jurka946ad472010-07-09 18:05:18 -07001245
1246 if (mHomeCustomizationDrawer != null) {
1247 String currentTabTag = mHomeCustomizationDrawer.getCurrentTabTag();
1248 if (currentTabTag != null) {
1249 outState.putString("currentTab", currentTabTag);
1250 }
1251 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001252 }
1253
1254 @Override
1255 public void onDestroy() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001256 super.onDestroy();
Romain Guycbb89e42009-06-08 15:52:54 -07001257
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001258 try {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001259 mAppWidgetHost.stopListening();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001260 } catch (NullPointerException ex) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001261 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001262 }
1263
1264 TextKeyListener.getInstance().release();
1265
Joe Onorato9c1289c2009-08-17 11:03:03 -04001266 mModel.stopLoader();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001267
Joe Onorato9c1289c2009-08-17 11:03:03 -04001268 unbindDesktopItems();
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001269
1270 getContentResolver().unregisterContentObserver(mWidgetObserver);
Winson Chungaafa03c2010-06-11 17:34:16 -07001271
Patrick Dubroyab962b72010-07-26 12:10:10 -07001272 // Some launcher layouts don't have a previous and next view
1273 if (mPreviousView != null) {
1274 dismissPreview(mPreviousView);
1275 }
1276 if (mNextView != null) {
1277 dismissPreview(mNextView);
1278 }
Joe Onorato34a0e1b2009-12-14 17:44:51 -08001279
1280 unregisterReceiver(mCloseSystemDialogsReceiver);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001281 }
1282
1283 @Override
1284 public void startActivityForResult(Intent intent, int requestCode) {
Romain Guy08f97492009-06-29 14:41:20 -07001285 if (requestCode >= 0) mWaitingForResult = true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001286 super.startActivityForResult(intent, requestCode);
1287 }
1288
1289 @Override
Romain Guycbb89e42009-06-08 15:52:54 -07001290 public void startSearch(String initialQuery, boolean selectInitialQuery,
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001291 Bundle appSearchData, boolean globalSearch) {
Karl Rosaen138a0412009-04-23 19:00:21 -07001292
Joe Onorato7bb17492009-09-24 17:51:01 -07001293 closeAllApps(true);
Romain Guycbb89e42009-06-08 15:52:54 -07001294
Karl Rosaen138a0412009-04-23 19:00:21 -07001295 if (initialQuery == null) {
1296 // Use any text typed in the launcher as the initial query
1297 initialQuery = getTypedText();
1298 clearTypedText();
1299 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001300 if (appSearchData == null) {
1301 appSearchData = new Bundle();
Bjorn Bringert3e244cf2010-02-10 14:17:35 +00001302 appSearchData.putString(Search.SOURCE, "launcher-search");
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001303 }
Romain Guycbb89e42009-06-08 15:52:54 -07001304
Karl Rosaen138a0412009-04-23 19:00:21 -07001305 final SearchManager searchManager =
1306 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
Karl Rosaen138a0412009-04-23 19:00:21 -07001307 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
Romain Guycbb89e42009-06-08 15:52:54 -07001308 appSearchData, globalSearch);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001309 }
1310
1311 @Override
1312 public boolean onCreateOptionsMenu(Menu menu) {
Patrick Dubroy5905bca2010-09-08 22:43:38 -07001313 if (isWorkspaceLocked()) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04001314 return false;
1315 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001316
1317 super.onCreateOptionsMenu(menu);
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001318
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001319 menu.add(MENU_GROUP_ADD, MENU_ADD, 0, R.string.menu_add)
1320 .setIcon(android.R.drawable.ic_menu_add)
1321 .setAlphabeticShortcut('A');
Winson Chung7ad01412010-09-27 11:33:03 -07001322 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps)
1323 .setIcon(android.R.drawable.ic_menu_manage)
1324 .setAlphabeticShortcut('M');
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001325 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001326 .setIcon(android.R.drawable.ic_menu_gallery)
1327 .setAlphabeticShortcut('W');
1328 menu.add(0, MENU_SEARCH, 0, R.string.menu_search)
1329 .setIcon(android.R.drawable.ic_search_category_default)
1330 .setAlphabeticShortcut(SearchManager.MENU_KEY);
1331 menu.add(0, MENU_NOTIFICATIONS, 0, R.string.menu_notifications)
1332 .setIcon(com.android.internal.R.drawable.ic_menu_notifications)
1333 .setAlphabeticShortcut('N');
1334
1335 final Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
Romain Guy5a941392009-04-28 15:18:25 -07001336 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
1337 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001338
1339 menu.add(0, MENU_SETTINGS, 0, R.string.menu_settings)
1340 .setIcon(android.R.drawable.ic_menu_preferences).setAlphabeticShortcut('P')
1341 .setIntent(settings);
1342
1343 return true;
1344 }
1345
1346 @Override
1347 public boolean onPrepareOptionsMenu(Menu menu) {
1348 super.onPrepareOptionsMenu(menu);
1349
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001350 // If all apps is animating, don't show the menu, because we don't know
1351 // which one to show.
Patrick Dubroyff5f0402010-07-26 15:23:26 -07001352 if (mAllAppsGrid.isAnimating()) {
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001353 return false;
1354 }
1355
1356 // Only show the add and wallpaper options when we're not in all apps.
Patrick Dubroyff5f0402010-07-26 15:23:26 -07001357 boolean visible = !mAllAppsGrid.isVisible();
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001358 menu.setGroupVisible(MENU_GROUP_ADD, visible);
1359 menu.setGroupVisible(MENU_GROUP_WALLPAPER, visible);
1360
1361 // Disable add if the workspace is full.
1362 if (visible) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001363 CellLayout layout = (CellLayout) mWorkspace.getChildAt(mWorkspace.getCurrentPage());
1364 menu.setGroupEnabled(MENU_GROUP_ADD, layout.existsEmptyCell());
Joe Onorato2d7e7d02010-01-29 15:57:19 -08001365 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001366
1367 return true;
1368 }
1369
1370 @Override
1371 public boolean onOptionsItemSelected(MenuItem item) {
1372 switch (item.getItemId()) {
1373 case MENU_ADD:
1374 addItems();
1375 return true;
Winson Chung7ad01412010-09-27 11:33:03 -07001376 case MENU_MANAGE_APPS:
1377 manageApps();
1378 return true;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001379 case MENU_WALLPAPER_SETTINGS:
1380 startWallpaper();
1381 return true;
1382 case MENU_SEARCH:
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001383 onSearchRequested();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001384 return true;
1385 case MENU_NOTIFICATIONS:
1386 showNotifications();
1387 return true;
1388 }
1389
1390 return super.onOptionsItemSelected(item);
1391 }
Romain Guycbb89e42009-06-08 15:52:54 -07001392
Karl Rosaen138a0412009-04-23 19:00:21 -07001393 /**
1394 * Indicates that we want global search for this activity by setting the globalSearch
1395 * argument for {@link #startSearch} to true.
1396 */
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001397
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001398 @Override
1399 public boolean onSearchRequested() {
Romain Guycbb89e42009-06-08 15:52:54 -07001400 startSearch(null, false, null, true);
Karl Rosaen138a0412009-04-23 19:00:21 -07001401 return true;
The Android Open Source Projectca9475f2009-03-13 13:04:24 -07001402 }
1403
Joe Onorato9c1289c2009-08-17 11:03:03 -04001404 public boolean isWorkspaceLocked() {
1405 return mWorkspaceLoading || mWaitingForResult;
1406 }
1407
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001408 private void addItems() {
Patrick Dubroy558654c2010-07-23 16:48:11 -07001409 if (LauncherApplication.isScreenXLarge()) {
1410 // Animate the widget chooser up from the bottom of the screen
1411 if (!isCustomizationDrawerVisible()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07001412 showCustomizationDrawer(true);
Patrick Dubroy558654c2010-07-23 16:48:11 -07001413 }
1414 } else {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07001415 closeAllApps(true);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001416 showAddDialog(-1, -1);
Patrick Dubroy558654c2010-07-23 16:48:11 -07001417 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001418 }
1419
Michael Jurka0280c3b2010-09-17 15:00:07 -07001420 private void resetAddInfo() {
1421 mAddScreen = -1;
1422 mAddIntersectCellX = -1;
1423 mAddIntersectCellY = -1;
1424 mAddDropPosition = null;
1425 }
Michael Jurkaa63c4522010-08-19 13:52:27 -07001426
Michael Jurka0280c3b2010-09-17 15:00:07 -07001427 void addAppWidgetFromDrop(ComponentName appWidgetProvider, int screen, int[] position) {
1428 resetAddInfo();
1429 mAddScreen = screen;
1430
1431 // only set mAddDropPosition if we dropped on home screen in "spring-loaded" manner
1432 mAddDropPosition = position;
1433
Michael Jurkaaf442092010-06-10 17:01:57 -07001434 int appWidgetId = getAppWidgetHost().allocateAppWidgetId();
1435 AppWidgetManager.getInstance(this).bindAppWidgetId(appWidgetId, appWidgetProvider);
1436 addAppWidgetImpl(appWidgetId);
1437 }
1438
Winson Chung7ad01412010-09-27 11:33:03 -07001439 private void manageApps() {
1440 startActivity(new Intent(android.provider.Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS));
1441 }
1442
Michael Jurkaaf442092010-06-10 17:01:57 -07001443 void addAppWidgetFromPick(Intent data) {
The Android Open Source Project7376fae2009-03-11 12:11:58 -07001444 // TODO: catch bad widget exception when sent
1445 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
Michael Jurkaaf442092010-06-10 17:01:57 -07001446 // TODO: Is this log message meaningful?
1447 if (LOGD) Log.d(TAG, "dumping extras content=" + data.getExtras());
1448 addAppWidgetImpl(appWidgetId);
1449 }
1450
1451 void addAppWidgetImpl(int appWidgetId) {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001452 AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001453
Bjorn Bringert7984c942009-12-09 15:38:25 +00001454 if (appWidget.configure != null) {
1455 // Launch over to configure widget, if needed
1456 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
1457 intent.setComponent(appWidget.configure);
1458 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
1459
Romain Guy8e633c52010-03-04 12:51:36 -08001460 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001461 } else {
Bjorn Bringert7984c942009-12-09 15:38:25 +00001462 // Otherwise just add it
Michael Jurka0280c3b2010-09-17 15:00:07 -07001463 completeAddAppWidget(appWidgetId, mAddScreen);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001464 }
1465 }
Romain Guycbb89e42009-06-08 15:52:54 -07001466
Michael Jurka0280c3b2010-09-17 15:00:07 -07001467 void processShortcutFromDrop(ComponentName componentName, int screen, int[] position) {
1468 resetAddInfo();
1469 mAddScreen = screen;
1470 mAddDropPosition = position;
1471
1472 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
1473 createShortcutIntent.setComponent(componentName);
1474 processShortcut(createShortcutIntent);
1475 }
1476
Joe Onoratodeb98af2010-02-19 14:59:39 -08001477 void processShortcut(Intent intent) {
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001478 // Handle case where user selected "Applications"
1479 String applicationName = getResources().getString(R.string.group_applications);
1480 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001481
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001482 if (applicationName != null && applicationName.equals(shortcutName)) {
1483 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
1484 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Romain Guycbb89e42009-06-08 15:52:54 -07001485
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001486 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
1487 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
Joe Onorato4a79a042010-09-24 16:17:21 -07001488 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001489 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001490 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001491 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001492 }
1493
Winson Chung24ab2f12010-09-16 14:10:47 -07001494 void processWallpaper(Intent intent) {
1495 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
1496 }
1497
Michael Jurka0280c3b2010-09-17 15:00:07 -07001498 void addLiveFolderFromDrop(ComponentName componentName, int screen, int[] position) {
1499 resetAddInfo();
1500 mAddScreen = screen;
1501 mAddDropPosition = position;
1502
1503 Intent createFolderIntent = new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER);
1504 createFolderIntent.setComponent(componentName);
1505
1506 addLiveFolder(createFolderIntent);
1507 }
1508
1509 void addLiveFolder(Intent intent) { // YYY add screen intersect etc. parameters here
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001510 // Handle case where user selected "Folder"
Jeffrey Sharkeyc4bbd0a2009-03-24 22:47:52 -07001511 String folderName = getResources().getString(R.string.group_folder);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001512 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Romain Guycbb89e42009-06-08 15:52:54 -07001513
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001514 if (folderName != null && folderName.equals(shortcutName)) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001515 addFolder(mAddScreen, mAddIntersectCellX, mAddIntersectCellY);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001516 } else {
Joe Onorato4a79a042010-09-24 16:17:21 -07001517 startActivityForResultSafely(intent, REQUEST_CREATE_LIVE_FOLDER);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07001518 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001519 }
1520
Michael Jurka0280c3b2010-09-17 15:00:07 -07001521 void addFolder(int screen, int intersectCellX, int intersectCellY) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001522 UserFolderInfo folderInfo = new UserFolderInfo();
1523 folderInfo.title = getText(R.string.folder_name);
1524
Michael Jurka0280c3b2010-09-17 15:00:07 -07001525 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1526 final int[] cellXY = mTmpAddItemCellCoordinates;
1527 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1528 showOutOfSpaceMessage();
1529 return;
1530 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001531
1532 // Update the model
Joe Onorato9c1289c2009-08-17 11:03:03 -04001533 LauncherModel.addItemToDatabase(this, folderInfo,
1534 LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001535 screen, cellXY[0], cellXY[1], false);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001536 sFolders.put(folderInfo.id, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001537
1538 // Create the view
1539 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07001540 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), folderInfo);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001541 mWorkspace.addInScreen(newFolder, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001542 }
Romain Guycbb89e42009-06-08 15:52:54 -07001543
Joe Onorato9c1289c2009-08-17 11:03:03 -04001544 void removeFolder(FolderInfo folder) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001545 sFolders.remove(folder.id);
Joe Onorato9c1289c2009-08-17 11:03:03 -04001546 }
1547
Michael Jurka28750fb2010-09-24 17:43:49 -07001548 private void completeAddLiveFolder(
1549 Intent data, int screen, int intersectCellX, int intersectCellY) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001550 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(screen);
1551 final int[] cellXY = mTmpAddItemCellCoordinates;
1552 if (!layout.findCellForSpanThatIntersects(cellXY, 1, 1, intersectCellX, intersectCellY)) {
1553 showOutOfSpaceMessage();
1554 return;
1555 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001556
Michael Jurka0280c3b2010-09-17 15:00:07 -07001557 final LiveFolderInfo info = addLiveFolder(this, data, screen, cellXY[0], cellXY[1], false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001558
1559 if (!mRestoring) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001560 final View view = LiveFolderIcon.fromXml(R.layout.live_folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07001561 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001562 mWorkspace.addInScreen(view, screen, cellXY[0], cellXY[1], 1, 1, isWorkspaceLocked());
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001563 }
1564 }
1565
1566 static LiveFolderInfo addLiveFolder(Context context, Intent data,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001567 int screen, int cellX, int cellY, boolean notify) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001568
1569 Intent baseIntent = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT);
1570 String name = data.getStringExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME);
1571
1572 Drawable icon = null;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001573 Intent.ShortcutIconResource iconResource = null;
1574
1575 Parcelable extra = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON);
1576 if (extra != null && extra instanceof Intent.ShortcutIconResource) {
1577 try {
1578 iconResource = (Intent.ShortcutIconResource) extra;
1579 final PackageManager packageManager = context.getPackageManager();
1580 Resources resources = packageManager.getResourcesForApplication(
1581 iconResource.packageName);
1582 final int id = resources.getIdentifier(iconResource.resourceName, null, null);
1583 icon = resources.getDrawable(id);
1584 } catch (Exception e) {
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001585 Log.w(TAG, "Could not load live folder icon: " + extra);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001586 }
1587 }
1588
1589 if (icon == null) {
1590 icon = context.getResources().getDrawable(R.drawable.ic_launcher_folder);
1591 }
1592
1593 final LiveFolderInfo info = new LiveFolderInfo();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001594 info.icon = Utilities.createIconBitmap(icon, context);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001595 info.title = name;
1596 info.iconResource = iconResource;
1597 info.uri = data.getData();
1598 info.baseIntent = baseIntent;
1599 info.displayMode = data.getIntExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE,
1600 LiveFolders.DISPLAY_MODE_GRID);
1601
1602 LauncherModel.addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
Michael Jurka0280c3b2010-09-17 15:00:07 -07001603 screen, cellX, cellY, notify);
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07001604 sFolders.put(info.id, info);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001605
1606 return info;
1607 }
1608
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001609 private void showNotifications() {
1610 final StatusBarManager statusBar = (StatusBarManager) getSystemService(STATUS_BAR_SERVICE);
1611 if (statusBar != null) {
1612 statusBar.expand();
1613 }
1614 }
1615
1616 private void startWallpaper() {
Joe Onoratoe6168662009-11-08 13:39:30 -05001617 closeAllApps(true);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001618 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Dianne Hackborn8355ae32009-09-07 21:47:51 -07001619 Intent chooser = Intent.createChooser(pickWallpaper,
1620 getText(R.string.chooser_wallpaper));
Romain Guyf2826c72009-11-12 17:39:34 -08001621 // NOTE: Adds a configure option to the chooser if the wallpaper supports it
1622 // Removed in Eclair MR1
1623// WallpaperManager wm = (WallpaperManager)
1624// getSystemService(Context.WALLPAPER_SERVICE);
1625// WallpaperInfo wi = wm.getWallpaperInfo();
1626// if (wi != null && wi.getSettingsActivity() != null) {
1627// LabeledIntent li = new LabeledIntent(getPackageName(),
1628// R.string.configure_wallpaper, 0);
1629// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
1630// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
1631// }
Mike Clerona0618e42009-10-22 13:55:21 -07001632 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001633 }
1634
Joe Onorato2ca0ae72009-11-10 13:14:13 -08001635 /**
1636 * Registers various content observers. The current implementation registers
1637 * only a favorites observer to keep track of the favorites applications.
1638 */
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001639 private void registerContentObservers() {
1640 ContentResolver resolver = getContentResolver();
1641 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
1642 true, mWidgetObserver);
1643 }
1644
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001645 @Override
1646 public boolean dispatchKeyEvent(KeyEvent event) {
1647 if (event.getAction() == KeyEvent.ACTION_DOWN) {
1648 switch (event.getKeyCode()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001649 case KeyEvent.KEYCODE_HOME:
Dianne Hackborn67800862009-07-24 17:15:20 -07001650 return true;
Joe Onoratobe386092009-11-17 17:32:16 -08001651 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jason Samseb5615d2009-11-30 11:50:10 -08001652 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
Joe Onoratobe386092009-11-17 17:32:16 -08001653 dumpState();
1654 return true;
1655 }
1656 break;
Dianne Hackborn67800862009-07-24 17:15:20 -07001657 }
1658 } else if (event.getAction() == KeyEvent.ACTION_UP) {
1659 switch (event.getKeyCode()) {
Dianne Hackborn67800862009-07-24 17:15:20 -07001660 case KeyEvent.KEYCODE_HOME:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001661 return true;
1662 }
1663 }
1664
1665 return super.dispatchKeyEvent(event);
1666 }
1667
Joe Onorato88ec0992009-11-19 13:16:06 -08001668 @Override
1669 public void onBackPressed() {
1670 if (isAllAppsVisible()) {
1671 closeAllApps(true);
Patrick Dubroy558654c2010-07-23 16:48:11 -07001672 } else if (isCustomizationDrawerVisible()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07001673 hideCustomizationDrawer(true);
Joe Onorato88ec0992009-11-19 13:16:06 -08001674 } else {
1675 closeFolder();
1676 }
Michael Jurkaaf442092010-06-10 17:01:57 -07001677 // Some launcher layouts don't have a previous and next view
1678 if (mPreviousView != null) {
1679 dismissPreview(mPreviousView);
1680 dismissPreview(mNextView);
1681 }
Joe Onorato88ec0992009-11-19 13:16:06 -08001682 }
1683
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001684 private void closeFolder() {
1685 Folder folder = mWorkspace.getOpenFolder();
1686 if (folder != null) {
1687 closeFolder(folder);
1688 }
1689 }
1690
1691 void closeFolder(Folder folder) {
1692 folder.getInfo().opened = false;
1693 ViewGroup parent = (ViewGroup) folder.getParent();
1694 if (parent != null) {
1695 parent.removeView(folder);
Joe Onoratob6341e92009-11-02 10:41:48 -05001696 if (folder instanceof DropTarget) {
1697 // Live folders aren't DropTargets.
1698 mDragController.removeDropTarget((DropTarget)folder);
1699 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001700 }
1701 folder.onClose();
1702 }
1703
1704 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08001705 * Re-listen when widgets are reset.
1706 */
1707 private void onAppWidgetReset() {
1708 mAppWidgetHost.startListening();
1709 }
1710
1711 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04001712 * Go through the and disconnect any of the callbacks in the drawables and the views or we
1713 * leak the previous Home screen on orientation change.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001714 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04001715 private void unbindDesktopItems() {
1716 for (ItemInfo item: mDesktopItems) {
1717 item.unbind();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001718 }
1719 }
Jeffrey Sharkey99c87582009-03-24 17:59:43 -07001720
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001721 /**
1722 * Launches the intent referred by the clicked shortcut.
1723 *
1724 * @param v The view representing the clicked shortcut.
1725 */
1726 public void onClick(View v) {
1727 Object tag = v.getTag();
Joe Onorato0589f0f2010-02-08 13:44:00 -08001728 if (tag instanceof ShortcutInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001729 // Open shortcut
Romain Guyfb5411e2010-02-24 10:04:17 -08001730 final Intent intent = ((ShortcutInfo) tag).intent;
Joe Onorato13724ea2009-12-02 21:16:35 -08001731 int[] pos = new int[2];
1732 v.getLocationOnScreen(pos);
Romain Guyfb5411e2010-02-24 10:04:17 -08001733 intent.setSourceBounds(new Rect(pos[0], pos[1],
1734 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
Joe Onoratof984e852010-03-25 09:47:45 -07001735 startActivitySafely(intent, tag);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001736 } else if (tag instanceof FolderInfo) {
1737 handleFolderClick((FolderInfo) tag);
Joe Onorato7404ee42009-07-31 11:54:44 -07001738 } else if (v == mHandleView) {
Joe Onoratofb0ca672009-09-14 17:55:46 -04001739 if (isAllAppsVisible()) {
Joe Onorato7bb17492009-09-24 17:51:01 -07001740 closeAllApps(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001741 } else {
Joe Onorato3a8820b2009-11-10 15:06:42 -08001742 showAllApps(true);
Joe Onorato7404ee42009-07-31 11:54:44 -07001743 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001744 }
1745 }
1746
Michael Jurka0e260592010-06-30 17:07:39 -07001747 public boolean onTouch(View v, MotionEvent event) {
Michael Jurkadee05892010-07-27 10:01:56 -07001748 // this is an intercepted event being forwarded from mWorkspace;
Michael Jurka0e260592010-06-30 17:07:39 -07001749 // clicking anywhere on the workspace causes the drawer to slide down
Patrick Dubroy6b509c12010-08-23 15:08:16 -07001750 hideCustomizationDrawer(true);
Michael Jurka0e260592010-06-30 17:07:39 -07001751 return false;
1752 }
1753
Michael Jurkaaf442092010-06-10 17:01:57 -07001754 /**
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001755 * Event handler for the search button
1756 *
1757 * @param v The view that was clicked.
1758 */
1759 public void onClickSearchButton(View v) {
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07001760 if (mGlobalSearchIntent != null) {
1761 View b = findViewById(R.id.search_button);
1762 mGlobalSearchIntent.setSourceBounds(
1763 new Rect(b.getLeft(), b.getTop(), b.getRight(), b.getBottom()));
1764 startActivitySafely(mGlobalSearchIntent, "global search");
1765 }
1766
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001767 }
1768
1769 /**
1770 * Event handler for the "gear" button that appears on the home screen, which
Michael Jurkaaf442092010-06-10 17:01:57 -07001771 * enters home screen customization mode.
1772 *
1773 * @param v The view that was clicked.
1774 */
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001775 public void onClickConfigureButton(View v) {
Patrick Dubroy558654c2010-07-23 16:48:11 -07001776 addItems();
Michael Jurkaaf442092010-06-10 17:01:57 -07001777 }
1778
Michael Jurka2c3af5f2010-08-03 13:53:20 -07001779 /**
1780 * Event handler for the "grid" button that appears on the home screen, which
1781 * enters all apps mode.
1782 *
1783 * @param v The view that was clicked.
1784 */
1785 public void onClickAllAppsButton(View v) {
1786 showAllApps(true);
1787 }
1788
Patrick Dubroyceae05d2010-08-30 10:40:53 -07001789 public void onClickAppMarketButton(View v) {
1790 if (mAppMarketIntent != null) {
1791 startActivitySafely(mAppMarketIntent, "app market");
1792 }
1793 }
1794
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001795 void startApplicationDetailsActivity(ComponentName componentName) {
1796 String packageName = componentName.getPackageName();
Patrick Dubroy4ed62782010-08-17 15:11:18 -07001797 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
1798 Uri.fromParts("package", packageName, null));
1799 startActivity(intent);
1800 }
1801
Patrick Dubroy5539af72010-09-07 15:22:01 -07001802 void startApplicationUninstallActivity(ApplicationInfo appInfo) {
1803 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) {
1804 // System applications cannot be installed. For now, show a toast explaining that.
1805 // We may give them the option of disabling apps this way.
1806 int messageId = R.string.uninstall_system_app_text;
1807 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
1808 } else {
1809 String packageName = appInfo.componentName.getPackageName();
1810 String className = appInfo.componentName.getClassName();
1811 Intent intent = new Intent(
1812 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
1813 startActivity(intent);
1814 }
Patrick Dubroybc6840b2010-09-01 11:54:27 -07001815 }
1816
Joe Onoratof984e852010-03-25 09:47:45 -07001817 void startActivitySafely(Intent intent, Object tag) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001818 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1819 try {
1820 startActivity(intent);
1821 } catch (ActivityNotFoundException e) {
1822 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Daniel Sandlerc9b18772010-04-22 14:37:59 -04001823 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001824 } catch (SecurityException e) {
1825 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
Joe Onoratoa30ce8e2009-11-11 08:16:49 -08001826 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001827 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
Joe Onoratof984e852010-03-25 09:47:45 -07001828 "or use the exported attribute for this activity. "
1829 + "tag="+ tag + " intent=" + intent, e);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001830 }
1831 }
Winson Chungaafa03c2010-06-11 17:34:16 -07001832
Romain Guy8e633c52010-03-04 12:51:36 -08001833 void startActivityForResultSafely(Intent intent, int requestCode) {
1834 try {
1835 startActivityForResult(intent, requestCode);
1836 } catch (ActivityNotFoundException e) {
1837 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1838 } catch (SecurityException e) {
1839 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
1840 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
1841 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
1842 "or use the exported attribute for this activity.", e);
1843 }
1844 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001845
1846 private void handleFolderClick(FolderInfo folderInfo) {
1847 if (!folderInfo.opened) {
1848 // Close any open folder
1849 closeFolder();
1850 // Open the requested folder
1851 openFolder(folderInfo);
1852 } else {
1853 // Find the open folder...
1854 Folder openFolder = mWorkspace.getFolderForTag(folderInfo);
1855 int folderScreen;
1856 if (openFolder != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07001857 folderScreen = mWorkspace.getPageForView(openFolder);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001858 // .. and close it
1859 closeFolder(openFolder);
Michael Jurka0142d492010-08-25 17:46:15 -07001860 if (folderScreen != mWorkspace.getCurrentPage()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001861 // Close any folder open on the current screen
1862 closeFolder();
1863 // Pull the folder onto this screen
1864 openFolder(folderInfo);
1865 }
1866 }
1867 }
1868 }
1869
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001870 /**
1871 * Opens the user fodler described by the specified tag. The opening of the folder
1872 * is animated relative to the specified View. If the View is null, no animation
1873 * is played.
1874 *
1875 * @param folderInfo The FolderInfo describing the folder to open.
1876 */
Winson Chungaafa03c2010-06-11 17:34:16 -07001877 public void openFolder(FolderInfo folderInfo) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001878 Folder openFolder;
1879
1880 if (folderInfo instanceof UserFolderInfo) {
1881 openFolder = UserFolder.fromXml(this);
1882 } else if (folderInfo instanceof LiveFolderInfo) {
Joe Onoratoa5902522009-07-30 13:37:37 -07001883 openFolder = com.android.launcher2.LiveFolder.fromXml(this, folderInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001884 } else {
1885 return;
1886 }
1887
Joe Onorato00acb122009-08-04 16:04:30 -04001888 openFolder.setDragController(mDragController);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001889 openFolder.setLauncher(this);
1890
1891 openFolder.bind(folderInfo);
1892 folderInfo.opened = true;
1893
Winson Chungaafa03c2010-06-11 17:34:16 -07001894 mWorkspace.addInFullScreen(openFolder, folderInfo.screen);
1895
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001896 openFolder.onOpen();
1897 }
1898
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001899 public boolean onLongClick(View v) {
Romain Guy1fbc1c82009-11-09 20:43:08 -08001900 switch (v.getId()) {
1901 case R.id.previous_screen:
Joe Onorato0d44e942009-11-16 18:20:51 -08001902 if (!isAllAppsVisible()) {
1903 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1904 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Romain Guyf8e6a802009-12-07 17:48:02 -08001905 showPreviews(v);
Joe Onorato0d44e942009-11-16 18:20:51 -08001906 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08001907 return true;
1908 case R.id.next_screen:
Joe Onorato0d44e942009-11-16 18:20:51 -08001909 if (!isAllAppsVisible()) {
1910 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1911 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Romain Guyf8e6a802009-12-07 17:48:02 -08001912 showPreviews(v);
1913 }
1914 return true;
1915 case R.id.all_apps_button:
1916 if (!isAllAppsVisible()) {
1917 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1918 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
1919 showPreviews(v);
Joe Onorato0d44e942009-11-16 18:20:51 -08001920 }
Romain Guy1fbc1c82009-11-09 20:43:08 -08001921 return true;
1922 }
1923
Joe Onorato9c1289c2009-08-17 11:03:03 -04001924 if (isWorkspaceLocked()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001925 return false;
1926 }
1927
1928 if (!(v instanceof CellLayout)) {
1929 v = (View) v.getParent();
1930 }
1931
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001932
Michael Jurka0280c3b2010-09-17 15:00:07 -07001933 resetAddInfo();
1934 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001935 // This happens when long clicking an item with the dpad/trackball
Michael Jurka0280c3b2010-09-17 15:00:07 -07001936 if (longClickCellInfo == null || !longClickCellInfo.valid) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001937 return true;
1938 }
1939
Michael Jurka0280c3b2010-09-17 15:00:07 -07001940 final View itemUnderLongClick = longClickCellInfo.cell;
1941
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001942 if (mWorkspace.allowLongPress()) {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001943 if (itemUnderLongClick == null) {
1944 // User long pressed on empty space
1945 mWorkspace.setAllowLongPress(false);
1946 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1947 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
1948 if (LauncherApplication.isScreenXLarge()) {
1949 // Animate the widget chooser up from the bottom of the screen
1950 if (!isCustomizationDrawerVisible()) {
1951 showCustomizationDrawer(true);
1952 }
1953 } else {
1954 showAddDialog(longClickCellInfo.cellX, longClickCellInfo.cellY);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001955 }
1956 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07001957 if (!(itemUnderLongClick instanceof Folder)) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001958 // User long pressed on an item
Joe Onorato0d44e942009-11-16 18:20:51 -08001959 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
1960 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
Michael Jurka0280c3b2010-09-17 15:00:07 -07001961 mAddIntersectCellX = longClickCellInfo.cellX;
1962 mAddIntersectCellY = longClickCellInfo.cellY;
1963 mWorkspace.startDrag(longClickCellInfo);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001964 }
1965 }
1966 }
1967 return true;
1968 }
1969
Romain Guye6b8e2f2009-11-10 11:56:55 -08001970 @SuppressWarnings({"unchecked"})
Romain Guy9d31e9f2009-11-11 18:54:28 -08001971 private void dismissPreview(final View v) {
1972 final PopupWindow window = (PopupWindow) v.getTag();
Romain Guy1fbc1c82009-11-09 20:43:08 -08001973 if (window != null) {
Romain Guy9d31e9f2009-11-11 18:54:28 -08001974 window.setOnDismissListener(new PopupWindow.OnDismissListener() {
1975 public void onDismiss() {
1976 ViewGroup group = (ViewGroup) v.getTag(R.id.workspace);
1977 int count = group.getChildCount();
1978 for (int i = 0; i < count; i++) {
1979 ((ImageView) group.getChildAt(i)).setImageDrawable(null);
1980 }
Romain Guy9d31e9f2009-11-11 18:54:28 -08001981 ArrayList<Bitmap> bitmaps = (ArrayList<Bitmap>) v.getTag(R.id.icon);
1982 for (Bitmap bitmap : bitmaps) bitmap.recycle();
1983
1984 v.setTag(R.id.workspace, null);
1985 v.setTag(R.id.icon, null);
1986 window.setOnDismissListener(null);
1987 }
1988 });
Romain Guy1fbc1c82009-11-09 20:43:08 -08001989 window.dismiss();
Romain Guy1fbc1c82009-11-09 20:43:08 -08001990 }
1991 v.setTag(null);
1992 }
1993
Romain Guyf8e6a802009-12-07 17:48:02 -08001994 private void showPreviews(View anchor) {
Romain Guy9d31e9f2009-11-11 18:54:28 -08001995 showPreviews(anchor, 0, mWorkspace.getChildCount());
Romain Guy1fbc1c82009-11-09 20:43:08 -08001996 }
1997
Romain Guya6abce82009-11-10 02:54:41 -08001998 private void showPreviews(final View anchor, int start, int end) {
Romain Guyf8e6a802009-12-07 17:48:02 -08001999 final Resources resources = getResources();
2000 final Workspace workspace = mWorkspace;
Romain Guy1fbc1c82009-11-09 20:43:08 -08002001
Romain Guya6abce82009-11-10 02:54:41 -08002002 CellLayout cell = ((CellLayout) workspace.getChildAt(start));
Winson Chungaafa03c2010-06-11 17:34:16 -07002003
Romain Guy9d31e9f2009-11-11 18:54:28 -08002004 float max = workspace.getChildCount();
Winson Chungaafa03c2010-06-11 17:34:16 -07002005
Romain Guyf8e6a802009-12-07 17:48:02 -08002006 final Rect r = new Rect();
Romain Guy9d31e9f2009-11-11 18:54:28 -08002007 resources.getDrawable(R.drawable.preview_background).getPadding(r);
Romain Guye6b8e2f2009-11-10 11:56:55 -08002008 int extraW = (int) ((r.left + r.right) * max);
2009 int extraH = r.top + r.bottom;
Romain Guya6abce82009-11-10 02:54:41 -08002010
2011 int aW = cell.getWidth() - extraW;
2012 float w = aW / max;
2013
2014 int width = cell.getWidth();
2015 int height = cell.getHeight();
2016 int x = cell.getLeftPadding();
2017 int y = cell.getTopPadding();
2018 width -= (x + cell.getRightPadding());
2019 height -= (y + cell.getBottomPadding());
2020
2021 float scale = w / width;
2022
2023 int count = end - start;
2024
2025 final float sWidth = width * scale;
2026 float sHeight = height * scale;
2027
Romain Guye6b8e2f2009-11-10 11:56:55 -08002028 LinearLayout preview = new LinearLayout(this);
Romain Guya6abce82009-11-10 02:54:41 -08002029
Romain Guye6b8e2f2009-11-10 11:56:55 -08002030 PreviewTouchHandler handler = new PreviewTouchHandler(anchor);
2031 ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>(count);
Romain Guya6abce82009-11-10 02:54:41 -08002032
2033 for (int i = start; i < end; i++) {
Romain Guye6b8e2f2009-11-10 11:56:55 -08002034 ImageView image = new ImageView(this);
Romain Guya6abce82009-11-10 02:54:41 -08002035 cell = (CellLayout) workspace.getChildAt(i);
2036
Romain Guyf8e6a802009-12-07 17:48:02 -08002037 final Bitmap bitmap = Bitmap.createBitmap((int) sWidth, (int) sHeight,
Romain Guye6b8e2f2009-11-10 11:56:55 -08002038 Bitmap.Config.ARGB_8888);
Romain Guyf8e6a802009-12-07 17:48:02 -08002039
2040 final Canvas c = new Canvas(bitmap);
Romain Guya6abce82009-11-10 02:54:41 -08002041 c.scale(scale, scale);
2042 c.translate(-cell.getLeftPadding(), -cell.getTopPadding());
2043 cell.dispatchDraw(c);
Romain Guya6abce82009-11-10 02:54:41 -08002044
Romain Guy9d31e9f2009-11-11 18:54:28 -08002045 image.setBackgroundDrawable(resources.getDrawable(R.drawable.preview_background));
Romain Guye6b8e2f2009-11-10 11:56:55 -08002046 image.setImageBitmap(bitmap);
2047 image.setTag(i);
2048 image.setOnClickListener(handler);
Romain Guy9d31e9f2009-11-11 18:54:28 -08002049 image.setOnFocusChangeListener(handler);
2050 image.setFocusable(true);
Michael Jurka0142d492010-08-25 17:46:15 -07002051 if (i == mWorkspace.getCurrentPage()) image.requestFocus();
Romain Guye6b8e2f2009-11-10 11:56:55 -08002052
2053 preview.addView(image,
Romain Guy9d31e9f2009-11-11 18:54:28 -08002054 LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
2055
Winson Chungaafa03c2010-06-11 17:34:16 -07002056 bitmaps.add(bitmap);
Romain Guya6abce82009-11-10 02:54:41 -08002057 }
Romain Guyf8e6a802009-12-07 17:48:02 -08002058
2059 final PopupWindow p = new PopupWindow(this);
Romain Guye6b8e2f2009-11-10 11:56:55 -08002060 p.setContentView(preview);
2061 p.setWidth((int) (sWidth * count + extraW));
2062 p.setHeight((int) (sHeight + extraH));
2063 p.setAnimationStyle(R.style.AnimationPreview);
2064 p.setOutsideTouchable(true);
Romain Guy9d31e9f2009-11-11 18:54:28 -08002065 p.setFocusable(true);
Romain Guyff0c2e22009-11-10 12:09:59 -08002066 p.setBackgroundDrawable(new ColorDrawable(0));
Romain Guy9d31e9f2009-11-11 18:54:28 -08002067 p.showAsDropDown(anchor, 0, 0);
Romain Guya6abce82009-11-10 02:54:41 -08002068
Romain Guye6b8e2f2009-11-10 11:56:55 -08002069 p.setOnDismissListener(new PopupWindow.OnDismissListener() {
2070 public void onDismiss() {
2071 dismissPreview(anchor);
2072 }
2073 });
Romain Guy1fbc1c82009-11-09 20:43:08 -08002074
2075 anchor.setTag(p);
2076 anchor.setTag(R.id.workspace, preview);
Winson Chungaafa03c2010-06-11 17:34:16 -07002077 anchor.setTag(R.id.icon, bitmaps);
Romain Guy1fbc1c82009-11-09 20:43:08 -08002078 }
2079
Romain Guy9d31e9f2009-11-11 18:54:28 -08002080 class PreviewTouchHandler implements View.OnClickListener, Runnable, View.OnFocusChangeListener {
Romain Guya6abce82009-11-10 02:54:41 -08002081 private final View mAnchor;
Romain Guya6abce82009-11-10 02:54:41 -08002082
Romain Guye6b8e2f2009-11-10 11:56:55 -08002083 public PreviewTouchHandler(View anchor) {
Romain Guya6abce82009-11-10 02:54:41 -08002084 mAnchor = anchor;
Romain Guya6abce82009-11-10 02:54:41 -08002085 }
2086
2087 public void onClick(View v) {
Michael Jurka0142d492010-08-25 17:46:15 -07002088 mWorkspace.snapToPage((Integer) v.getTag());
Romain Guy9d31e9f2009-11-11 18:54:28 -08002089 v.post(this);
2090 }
2091
2092 public void run() {
Winson Chungaafa03c2010-06-11 17:34:16 -07002093 dismissPreview(mAnchor);
Romain Guy9d31e9f2009-11-11 18:54:28 -08002094 }
2095
2096 public void onFocusChange(View v, boolean hasFocus) {
2097 if (hasFocus) {
Michael Jurka0142d492010-08-25 17:46:15 -07002098 mWorkspace.snapToPage((Integer) v.getTag());
Romain Guy9d31e9f2009-11-11 18:54:28 -08002099 }
Romain Guya6abce82009-11-10 02:54:41 -08002100 }
2101 }
2102
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002103 Workspace getWorkspace() {
2104 return mWorkspace;
2105 }
2106
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002107 @Override
2108 protected Dialog onCreateDialog(int id) {
2109 switch (id) {
2110 case DIALOG_CREATE_SHORTCUT:
2111 return new CreateShortcut().createDialog();
2112 case DIALOG_RENAME_FOLDER:
2113 return new RenameFolder().createDialog();
2114 }
2115
2116 return super.onCreateDialog(id);
2117 }
2118
2119 @Override
2120 protected void onPrepareDialog(int id, Dialog dialog) {
2121 switch (id) {
2122 case DIALOG_CREATE_SHORTCUT:
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002123 break;
2124 case DIALOG_RENAME_FOLDER:
Romain Guy7b4ef332009-07-14 13:58:08 -07002125 if (mFolderInfo != null) {
2126 EditText input = (EditText) dialog.findViewById(R.id.folder_name);
2127 final CharSequence text = mFolderInfo.title;
2128 input.setText(text);
2129 input.setSelection(0, text.length());
2130 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002131 break;
2132 }
2133 }
2134
2135 void showRenameDialog(FolderInfo info) {
2136 mFolderInfo = info;
2137 mWaitingForResult = true;
2138 showDialog(DIALOG_RENAME_FOLDER);
2139 }
2140
Michael Jurka0280c3b2010-09-17 15:00:07 -07002141 private void showAddDialog(int intersectX, int intersectY) {
2142 resetAddInfo();
2143 mAddIntersectCellX = intersectX;
2144 mAddIntersectCellY = intersectY;
2145 mAddScreen = mWorkspace.getCurrentPage();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002146 mWaitingForResult = true;
2147 showDialog(DIALOG_CREATE_SHORTCUT);
2148 }
2149
Joe Onoratodeb98af2010-02-19 14:59:39 -08002150 private void pickShortcut() {
Michael Jurka0e260592010-06-30 17:07:39 -07002151 // Insert extra item to handle picking application
Romain Guy73b979d2009-06-09 12:57:21 -07002152 Bundle bundle = new Bundle();
2153
2154 ArrayList<String> shortcutNames = new ArrayList<String>();
2155 shortcutNames.add(getString(R.string.group_applications));
2156 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
2157
2158 ArrayList<ShortcutIconResource> shortcutIcons = new ArrayList<ShortcutIconResource>();
2159 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
2160 R.drawable.ic_launcher_application));
2161 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
2162
2163 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2164 pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_CREATE_SHORTCUT));
Joe Onoratodeb98af2010-02-19 14:59:39 -08002165 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_shortcut));
Romain Guy73b979d2009-06-09 12:57:21 -07002166 pickIntent.putExtras(bundle);
2167
Joe Onoratodeb98af2010-02-19 14:59:39 -08002168 startActivityForResult(pickIntent, REQUEST_PICK_SHORTCUT);
Romain Guy73b979d2009-06-09 12:57:21 -07002169 }
2170
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002171 private class RenameFolder {
2172 private EditText mInput;
2173
2174 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002175 final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null);
2176 mInput = (EditText) layout.findViewById(R.id.folder_name);
2177
2178 AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
2179 builder.setIcon(0);
2180 builder.setTitle(getString(R.string.rename_folder_title));
2181 builder.setCancelable(true);
2182 builder.setOnCancelListener(new Dialog.OnCancelListener() {
2183 public void onCancel(DialogInterface dialog) {
2184 cleanup();
2185 }
2186 });
2187 builder.setNegativeButton(getString(R.string.cancel_action),
2188 new Dialog.OnClickListener() {
2189 public void onClick(DialogInterface dialog, int which) {
2190 cleanup();
2191 }
2192 }
2193 );
2194 builder.setPositiveButton(getString(R.string.rename_action),
2195 new Dialog.OnClickListener() {
2196 public void onClick(DialogInterface dialog, int which) {
2197 changeFolderName();
2198 }
2199 }
2200 );
2201 builder.setView(layout);
Romain Guy7b4ef332009-07-14 13:58:08 -07002202
2203 final AlertDialog dialog = builder.create();
2204 dialog.setOnShowListener(new DialogInterface.OnShowListener() {
2205 public void onShow(DialogInterface dialog) {
Joe Onorato7018d8e2010-04-13 20:25:47 -07002206 mWaitingForResult = true;
Joe Onoratod753b422009-11-08 13:31:11 -05002207 mInput.requestFocus();
2208 InputMethodManager inputManager = (InputMethodManager)
2209 getSystemService(Context.INPUT_METHOD_SERVICE);
2210 inputManager.showSoftInput(mInput, 0);
Romain Guy7b4ef332009-07-14 13:58:08 -07002211 }
2212 });
2213
2214 return dialog;
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002215 }
2216
2217 private void changeFolderName() {
2218 final String name = mInput.getText().toString();
2219 if (!TextUtils.isEmpty(name)) {
2220 // Make sure we have the right folder info
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002221 mFolderInfo = sFolders.get(mFolderInfo.id);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002222 mFolderInfo.title = name;
2223 LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo);
2224
Joe Onorato9c1289c2009-08-17 11:03:03 -04002225 if (mWorkspaceLoading) {
Joe Onorato7c312c12009-08-13 21:36:53 -07002226 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002227 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002228 } else {
2229 final FolderIcon folderIcon = (FolderIcon)
2230 mWorkspace.getViewForTag(mFolderInfo);
2231 if (folderIcon != null) {
2232 folderIcon.setText(name);
2233 getWorkspace().requestLayout();
2234 } else {
Joe Onorato7c312c12009-08-13 21:36:53 -07002235 lockAllApps();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002236 mWorkspaceLoading = true;
2237 mModel.startLoader(Launcher.this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002238 }
2239 }
2240 }
2241 cleanup();
2242 }
2243
2244 private void cleanup() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002245 dismissDialog(DIALOG_RENAME_FOLDER);
2246 mWaitingForResult = false;
2247 mFolderInfo = null;
2248 }
2249 }
2250
Daniel Sandler843e8602010-06-07 14:59:01 -04002251 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
2252 public boolean isAllAppsVisible() {
Romain Guy5bbc91b2010-08-18 11:38:46 -07002253 return mAllAppsGrid != null && mAllAppsGrid.isVisible();
Joe Onoratofb0ca672009-09-14 17:55:46 -04002254 }
2255
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002256 // AllAppsView.Watcher
2257 public void zoomed(float zoom) {
Michael Jurka213d9632010-07-28 11:29:25 -07002258 // In XLarge view, we zoom down the workspace below all apps so it's still visible
2259 if (zoom == 1.0f && !LauncherApplication.isScreenXLarge()) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002260 mWorkspace.setVisibility(View.GONE);
2261 }
2262 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002263
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002264 private void showToolbarButton(View button) {
2265 button.setAlpha(1.0f);
2266 button.setVisibility(View.VISIBLE);
2267 button.setFocusable(true);
2268 button.setClickable(true);
2269 }
2270
2271 private void hideToolbarButton(View button) {
2272 button.setAlpha(0.0f);
2273 // We can't set it to GONE, otherwise the RelativeLayout gets screwed up
2274 button.setVisibility(View.INVISIBLE);
2275 button.setFocusable(false);
2276 button.setClickable(false);
2277 }
2278
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002279 /**
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002280 * Helper function for showing or hiding a toolbar button, possibly animated.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002281 *
2282 * @param show If true, create an animation to the show the item. Otherwise, hide it.
2283 * @param view The toolbar button to be animated
Chet Haaseb1254a62010-09-07 13:35:00 -07002284 * @param seq A AnimatorSet that will be used to animate the transition. If null, the
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002285 * transition will not be animated.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002286 */
Chet Haaseb1254a62010-09-07 13:35:00 -07002287 private void hideOrShowToolbarButton(boolean show, final View view, AnimatorSet seq) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002288 final boolean showing = show;
2289 final boolean hiding = !show;
2290
2291 final int duration = show ?
2292 getResources().getInteger(R.integer.config_toolbarButtonFadeInTime) :
2293 getResources().getInteger(R.integer.config_toolbarButtonFadeOutTime);
2294
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002295 if (seq != null) {
Chet Haaseb1254a62010-09-07 13:35:00 -07002296 Animator anim = new ObjectAnimator<Float>(duration, view, "alpha", show ? 1.0f : 0.0f);
2297 anim.addListener(new AnimatorListenerAdapter() {
2298 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002299 if (showing) showToolbarButton(view);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002300 }
Chet Haaseb1254a62010-09-07 13:35:00 -07002301 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002302 if (hiding) hideToolbarButton(view);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002303 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002304 });
2305 seq.play(anim);
2306 } else {
2307 if (showing) {
2308 showToolbarButton(view);
2309 } else {
2310 hideToolbarButton(view);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002311 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002312 }
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002313 }
2314
2315 /**
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002316 * Show/hide the appropriate toolbar buttons for newState.
2317 * If showSeq or hideSeq is null, the transition will be done immediately (not animated).
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002318 *
2319 * @param newState The state that is being switched to
Chet Haaseb1254a62010-09-07 13:35:00 -07002320 * @param showSeq AnimatorSet in which to put "show" animations, or null.
2321 * @param hideSeq AnimatorSet in which to put "hide" animations, or null.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002322 */
Chet Haaseb1254a62010-09-07 13:35:00 -07002323 private void hideAndShowToolbarButtons(State newState, AnimatorSet showSeq, AnimatorSet hideSeq) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002324 final View searchButton = findViewById(R.id.search_button);
2325 final View allAppsButton = findViewById(R.id.all_apps_button);
2326 final View marketButton = findViewById(R.id.market_button);
2327 final View configureButton = findViewById(R.id.configure_button);
2328
2329 switch (newState) {
2330 case WORKSPACE:
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002331 hideOrShowToolbarButton(true, searchButton, showSeq);
2332 hideOrShowToolbarButton(true, allAppsButton, showSeq);
2333 hideOrShowToolbarButton(true, configureButton, showSeq);
2334 hideOrShowToolbarButton(false, marketButton, hideSeq);
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002335 mDeleteZone.setHandle(allAppsButton);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002336 break;
2337 case ALL_APPS:
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002338 hideOrShowToolbarButton(true, configureButton, showSeq);
2339 hideOrShowToolbarButton(true, marketButton, showSeq);
2340 hideOrShowToolbarButton(false, searchButton, hideSeq);
2341 hideOrShowToolbarButton(false, allAppsButton, hideSeq);
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002342 mDeleteZone.setHandle(marketButton);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002343 break;
2344 case CUSTOMIZE:
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002345 hideOrShowToolbarButton(true, allAppsButton, showSeq);
2346 hideOrShowToolbarButton(false, searchButton, hideSeq);
2347 hideOrShowToolbarButton(false, marketButton, hideSeq);
2348 hideOrShowToolbarButton(false, configureButton, hideSeq);
Patrick Dubroybc6840b2010-09-01 11:54:27 -07002349 mDeleteZone.setHandle(allAppsButton);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002350 break;
2351 }
2352 }
2353
2354 /**
2355 * Helper method for the cameraZoomIn/cameraZoomOut animations
2356 * @param view The view being animated
2357 * @param state The state that we are moving in or out of -- either ALL_APPS or CUSTOMIZE
2358 * @param scaleFactor The scale factor used for the zoom
2359 */
2360 private void setPivotsForZoom(View view, State state, float scaleFactor) {
2361 final int height = view.getHeight();
2362 view.setPivotX(view.getWidth() / 2.0f);
2363 // Set pivotY so that at the starting zoom factor, the view is off-screen by a small margin
2364 // Assumes that the view is normally anchored to either the top or bottom of the screen
2365 final int margin = getResources().getInteger(R.integer.config_allAppsVerticalOffset);
2366 if (state == State.ALL_APPS) {
2367 view.setPivotY(height + ((view.getTop() + height) / scaleFactor) + margin);
2368 } else {
2369 view.setPivotY(0.0f - (view.getTop() / scaleFactor) - margin);
2370 }
2371 }
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002372
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002373 /**
2374 * Zoom the camera out from the workspace to reveal 'toView'.
2375 * Assumes that the view to show is anchored at either the very top or very bottom
2376 * of the screen.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002377 * @param toState The state to zoom out to. Must be ALL_APPS or CUSTOMIZE.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002378 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002379 private void cameraZoomOut(State toState, boolean animated) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002380 final Resources res = getResources();
2381 final int duration = res.getInteger(R.integer.config_allAppsZoomInTime);
2382 final float scale = (float) res.getInteger(R.integer.config_allAppsZoomScaleFactor);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002383 final boolean toAllApps = (toState == State.ALL_APPS);
2384 final View toView = toAllApps ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
Patrick Dubroy558654c2010-07-23 16:48:11 -07002385
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002386 setPivotsForZoom(toView, toState, scale);
2387
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002388 if (toState == State.ALL_APPS) {
2389 mWorkspace.shrinkToBottom(animated);
2390 } else {
2391 mWorkspace.shrinkToTop(animated);
2392 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002393
2394 if (animated) {
Chet Haaseb1254a62010-09-07 13:35:00 -07002395 ValueAnimator scaleAnim = new ObjectAnimator(duration, toView,
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002396 new PropertyValuesHolder<Float>("scaleX", scale, 1.0f),
2397 new PropertyValuesHolder<Float>("scaleY", scale, 1.0f));
2398 scaleAnim.setInterpolator(new DecelerateInterpolator());
Chet Haaseb1254a62010-09-07 13:35:00 -07002399 scaleAnim.addListener(new AnimatorListenerAdapter() {
2400 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002401 // Prepare the position
2402 toView.setTranslationX(0.0f);
2403 toView.setTranslationY(0.0f);
2404 toView.setVisibility(View.VISIBLE);
2405 }
2406 });
2407
Chet Haaseb1254a62010-09-07 13:35:00 -07002408 AnimatorSet toolbarHideAnim = new AnimatorSet();
2409 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002410 hideAndShowToolbarButtons(toState, toolbarShowAnim, toolbarHideAnim);
2411
2412 // toView should appear right at the end of the workspace shrink animation
2413 final int startDelay = res.getInteger(R.integer.config_workspaceShrinkTime) - duration;
2414
Chet Haaseb1254a62010-09-07 13:35:00 -07002415 AnimatorSet s = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002416 s.playTogether(scaleAnim, toolbarHideAnim);
2417 s.play(scaleAnim).after(startDelay);
2418
2419 // Show the new toolbar buttons just as the main animation is ending
2420 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
2421 s.play(toolbarShowAnim).after(duration + startDelay - fadeInTime);
2422 s.start();
2423 } else {
2424 toView.setTranslationX(0.0f);
2425 toView.setTranslationY(0.0f);
2426 toView.setScaleX(1.0f);
2427 toView.setScaleY(1.0f);
2428 toView.setVisibility(View.VISIBLE);
2429 hideAndShowToolbarButtons(toState, null, null);
2430 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002431 }
2432
2433 /**
2434 * Zoom the camera back into the workspace, hiding 'fromView'.
2435 * This is the opposite of cameraZoomOut.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002436 * @param fromState The current state (must be ALL_APPS or CUSTOMIZE).
2437 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002438 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002439 private void cameraZoomIn(State fromState, boolean animated) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002440 Resources res = getResources();
2441 int duration = res.getInteger(R.integer.config_allAppsZoomOutTime);
2442 float scaleFactor = (float) res.getInteger(R.integer.config_allAppsZoomScaleFactor);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002443 final View fromView =
2444 (fromState == State.ALL_APPS) ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
2445
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002446 mCustomizePagedView.endChoiceMode();
2447 mAllAppsPagedView.endChoiceMode();
2448
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002449 setPivotsForZoom(fromView, fromState, scaleFactor);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002450
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002451 mWorkspace.unshrink(animated);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002452
2453 if (animated) {
Chet Haaseb1254a62010-09-07 13:35:00 -07002454 AnimatorSet s = new AnimatorSet();
2455 ValueAnimator scaleAnim = new ObjectAnimator(duration, fromView,
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002456 new PropertyValuesHolder<Float>("scaleX", scaleFactor),
2457 new PropertyValuesHolder<Float>("scaleY", scaleFactor));
2458 scaleAnim.setInterpolator(new AccelerateInterpolator());
Chet Haaseb1254a62010-09-07 13:35:00 -07002459 s.addListener(new AnimatorListenerAdapter() {
2460 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002461 fromView.setVisibility(View.GONE);
2462 fromView.setScaleX(1.0f);
2463 fromView.setScaleY(1.0f);
2464 }
2465 });
2466
Chet Haaseb1254a62010-09-07 13:35:00 -07002467 AnimatorSet toolbarHideAnim = new AnimatorSet();
2468 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002469 hideAndShowToolbarButtons(State.WORKSPACE, toolbarShowAnim, toolbarHideAnim);
2470
2471 s.playTogether(scaleAnim, toolbarHideAnim);
2472
2473 // Show the new toolbar buttons at the very end of the whole animation
2474 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
2475 final int unshrinkTime = res.getInteger(R.integer.config_workspaceUnshrinkTime);
2476 s.play(toolbarShowAnim).after(unshrinkTime - fadeInTime);
2477 s.start();
2478 } else {
2479 fromView.setVisibility(View.GONE);
2480 hideAndShowToolbarButtons(State.WORKSPACE, null, null);
2481 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002482 }
2483
2484 /**
2485 * Pan the camera in the vertical plane between 'fromView' and 'toView'.
2486 * This is the transition used on xlarge screens to go between all apps and
2487 * the home customization drawer.
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002488 * @param fromState The view to pan away from. Must be ALL_APPS or CUSTOMIZE.
2489 * @param toState The view to pan into the frame. Must be ALL_APPS or CUSTOMIZE.
2490 * @param animated If true, the transition will be animated.
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002491 */
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002492 private void cameraPan(State fromState, State toState, boolean animated) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002493 final Resources res = getResources();
2494 final int duration = res.getInteger(R.integer.config_allAppsCameraPanTime);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002495 final int workspaceHeight = mWorkspace.getHeight();
2496
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002497 final boolean fromAllApps = (fromState == State.ALL_APPS);
2498 final View fromView = fromAllApps ? (View) mAllAppsGrid : mHomeCustomizationDrawer;
2499 final View toView = fromAllApps ? mHomeCustomizationDrawer : (View) mAllAppsGrid;
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002500
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002501 final float fromViewStartY = fromAllApps ? 0.0f : fromView.getY();
2502 final float fromViewEndY = fromAllApps ? -fromView.getHeight() * 2 : workspaceHeight * 2;
2503 final float toViewStartY = fromAllApps ? workspaceHeight * 2 : -toView.getHeight() * 2;
2504 final float toViewEndY = fromAllApps ? workspaceHeight - toView.getHeight() : 0.0f;
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002505
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002506 mCustomizePagedView.endChoiceMode();
2507 mAllAppsPagedView.endChoiceMode();
2508
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002509 if (toState == State.ALL_APPS) {
2510 mWorkspace.shrinkToBottom(animated);
2511 } else {
2512 mWorkspace.shrinkToTop(animated);
2513 }
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002514
2515 if (animated) {
Chet Haaseb1254a62010-09-07 13:35:00 -07002516 AnimatorSet s = new AnimatorSet();
2517 s.addListener(new AnimatorListenerAdapter() {
2518 public void onAnimationStart(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002519 toView.setVisibility(View.VISIBLE);
2520 toView.setY(toViewStartY);
2521 }
Chet Haaseb1254a62010-09-07 13:35:00 -07002522 public void onAnimationEnd(Animator animation) {
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002523 fromView.setVisibility(View.GONE);
2524 }
2525 });
2526
Chet Haaseb1254a62010-09-07 13:35:00 -07002527 AnimatorSet toolbarHideAnim = new AnimatorSet();
2528 AnimatorSet toolbarShowAnim = new AnimatorSet();
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002529 hideAndShowToolbarButtons(toState, toolbarShowAnim, toolbarHideAnim);
2530
2531 s.playTogether(
2532 toolbarHideAnim,
Chet Haaseb1254a62010-09-07 13:35:00 -07002533 new ObjectAnimator(duration, fromView, "y", fromViewStartY, fromViewEndY),
2534 new ObjectAnimator(duration, toView, "y", toViewStartY, toViewEndY));
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002535
2536 // Show the new toolbar buttons just as the main animation is ending
2537 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime);
2538 s.play(toolbarShowAnim).after(duration - fadeInTime);
2539 s.start();
2540 } else {
2541 fromView.setY(fromViewEndY);
2542 fromView.setVisibility(View.GONE);
2543 toView.setY(toViewEndY);
2544 toView.setVisibility(View.VISIBLE);
2545 hideAndShowToolbarButtons(toState, null, null);
2546 }
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002547 }
2548
2549 void showAllApps(boolean animated) {
Winson Chung80baf5a2010-08-09 16:03:15 -07002550 if (mAllAppsGrid.isVisible())
2551 return;
2552
Michael Jurka79212d82010-07-30 16:36:20 -07002553 if (LauncherApplication.isScreenXLarge()) {
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002554 if (isCustomizationDrawerVisible()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002555 cameraPan(State.CUSTOMIZE, State.ALL_APPS, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002556 } else {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002557 cameraZoomOut(State.ALL_APPS, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002558 }
Patrick Dubroy558654c2010-07-23 16:48:11 -07002559 } else {
2560 mAllAppsGrid.zoom(1.0f, animated);
2561 }
Joe Onorato3a8820b2009-11-10 15:06:42 -08002562
Romain Guyc16fea72010-03-12 17:17:56 -08002563 ((View) mAllAppsGrid).setFocusable(true);
2564 ((View) mAllAppsGrid).requestFocus();
Winson Chungaafa03c2010-06-11 17:34:16 -07002565
Joe Onorato7c312c12009-08-13 21:36:53 -07002566 // TODO: fade these two too
2567 mDeleteZone.setVisibility(View.GONE);
Joe Onorato00acb122009-08-04 16:04:30 -04002568 }
2569
Joe Onoratob2061212009-11-24 16:13:54 -05002570 /**
Joe Onorato7e4ed992009-12-03 13:10:49 -08002571 * Things to test when changing this code.
Joe Onoratob2061212009-11-24 16:13:54 -05002572 * - Home from workspace
2573 * - from center screen
2574 * - from other screens
2575 * - Home from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002576 * - from center screen
2577 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002578 * - Back from all apps
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002579 * - from center screen
2580 * - from other screens
Joe Onoratob2061212009-11-24 16:13:54 -05002581 * - Launch app from workspace and quit
2582 * - with back
2583 * - with home
2584 * - Launch app from all apps and quit
2585 * - with back
2586 * - with home
Joe Onorato7e4ed992009-12-03 13:10:49 -08002587 * - Go to a screen that's not the default, then all
2588 * apps, and launch and app, and go back
2589 * - with back
2590 * -with home
Joe Onoratob2061212009-11-24 16:13:54 -05002591 * - On workspace, long press power and go back
2592 * - with back
2593 * - with home
2594 * - On all apps, long press power and go back
2595 * - with back
2596 * - with home
2597 * - On workspace, power off
2598 * - On all apps, power off
Joe Onorato7e4ed992009-12-03 13:10:49 -08002599 * - Launch an app and turn off the screen while in that app
2600 * - Go back with home key
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002601 * - Go back with back key TODO: make this not go to workspace
Joe Onorato7e4ed992009-12-03 13:10:49 -08002602 * - From all apps
2603 * - From workspace
Joe Onoratoeffc4a82010-04-15 11:48:13 -07002604 * - Enter and exit car mode (becuase it causes an extra configuration changed)
2605 * - From all apps
2606 * - From the center workspace
2607 * - From another workspace
Joe Onoratob2061212009-11-24 16:13:54 -05002608 */
Joe Onorato7bb17492009-09-24 17:51:01 -07002609 void closeAllApps(boolean animated) {
Joe Onoratofb0ca672009-09-14 17:55:46 -04002610 if (mAllAppsGrid.isVisible()) {
Daniel Sandlerc351eb82010-03-03 15:05:19 -05002611 mWorkspace.setVisibility(View.VISIBLE);
Patrick Dubroydf7c3a72010-08-26 17:52:56 -07002612 if (LauncherApplication.isScreenXLarge()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002613 cameraZoomIn(State.ALL_APPS, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002614 } else {
2615 mAllAppsGrid.zoom(0.0f, animated);
2616 }
Daniel Sandler388f6792010-03-02 14:08:08 -05002617 ((View)mAllAppsGrid).setFocusable(false);
Michael Jurka0142d492010-08-25 17:46:15 -07002618 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onoratoe77c08d2009-08-01 00:01:20 -07002619 }
Joe Onorato7404ee42009-07-31 11:54:44 -07002620 }
2621
Joe Onorato7c312c12009-08-13 21:36:53 -07002622 void lockAllApps() {
2623 // TODO
2624 }
2625
2626 void unlockAllApps() {
2627 // TODO
2628 }
2629
Patrick Dubroy558654c2010-07-23 16:48:11 -07002630 private boolean isCustomizationDrawerVisible() {
Michael Jurka54f7ac32010-08-02 13:56:46 -07002631 return mHomeCustomizationDrawer != null &&
2632 mHomeCustomizationDrawer.getVisibility() == View.VISIBLE;
Patrick Dubroy558654c2010-07-23 16:48:11 -07002633 }
2634
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002635 // Show the customization drawer (only exists in x-large configuration)
2636 private void showCustomizationDrawer(boolean animated) {
Patrick Dubroy558654c2010-07-23 16:48:11 -07002637 if (isAllAppsVisible()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002638 cameraPan(State.ALL_APPS, State.CUSTOMIZE, animated);
Patrick Dubroy3ec8bdd2010-08-06 16:01:33 -07002639 } else {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002640 cameraZoomOut(State.CUSTOMIZE, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002641 }
Patrick Dubroy558654c2010-07-23 16:48:11 -07002642 }
2643
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002644 // Hide the customization drawer (only exists in x-large configuration)
2645 void hideCustomizationDrawer(boolean animated) {
Patrick Dubroy558654c2010-07-23 16:48:11 -07002646 if (isCustomizationDrawerVisible()) {
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002647 cameraZoomIn(State.CUSTOMIZE, animated);
Patrick Dubroy558654c2010-07-23 16:48:11 -07002648 }
2649 }
2650
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002651 void onWorkspaceClick(CellLayout layout) {
2652 Object itemInfo = mAllAppsPagedView.getChosenItem();
2653 if (itemInfo == null) {
2654 itemInfo = mCustomizePagedView.getChosenItem();
Michael Jurka213d9632010-07-28 11:29:25 -07002655 }
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002656
2657 if (itemInfo == null) {
2658 // No items are chosen in All Apps or Customize, so just zoom into the workspace
2659 mWorkspace.unshrink(layout);
2660 if (isAllAppsVisible()) {
2661 closeAllApps(true);
2662 } else if (isCustomizationDrawerVisible()) {
2663 hideCustomizationDrawer(true);
2664 }
2665 } else {
2666 // Act as if the chosen item was dropped on the given CellLayout
2667 if (mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
2668 mAllAppsPagedView.endChoiceMode();
2669 mCustomizePagedView.endChoiceMode();
2670 } else {
Michael Jurka0280c3b2010-09-17 15:00:07 -07002671 showOutOfSpaceMessage();
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002672 }
Michael Jurka213d9632010-07-28 11:29:25 -07002673 }
2674 }
2675
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002676 /* Core logic for updating market and search button icons. Intent is used to resolve which
2677 * activity to ask for an icon. Returns intent to launch the activity, or null if it wasn't
2678 * resolved */
2679 private Intent updateExternalIcon(int buttonId, Intent intent, int fallbackDrawableId) {
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002680 if (LauncherApplication.isScreenXLarge()) {
2681 // Find the app market activity by resolving an intent.
2682 // (If multiple app markets are installed, it will return the ResolverActivity.)
2683 PackageManager packageManager = getPackageManager();
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002684 ComponentName activityName = intent.resolveActivity(getPackageManager());
2685 if (activityName != null) {
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002686 ImageView button = (ImageView) findViewById(buttonId);
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002687 Drawable toolbarIcon = null;
2688 try {
2689 // Look for the toolbar icon specified in the activity meta-data
2690 Bundle metaData = packageManager.getActivityInfo(
2691 activityName, PackageManager.GET_META_DATA).metaData;
2692 if (metaData != null) {
2693 int iconResId = metaData.getInt(TOOLBAR_ICON_METADATA_NAME);
2694 if (iconResId != 0) {
2695 Resources res = packageManager.getResourcesForActivity(activityName);
2696 toolbarIcon = res.getDrawable(iconResId);
2697 }
2698 }
2699 } catch (NameNotFoundException e) {
2700 // Do nothing
2701 }
2702 // If we were unable to find the icon via the meta-data, use a generic one
2703 if (toolbarIcon == null) {
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002704 button.setImageResource(fallbackDrawableId);
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002705 } else {
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002706 button.setImageDrawable(toolbarIcon);
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002707 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002708 return intent;
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002709 }
2710 }
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07002711 return null;
2712 }
2713 /**
2714 * Sets the app market icon (shown when all apps is visible on x-large screens)
2715 */
2716 private void updateAppMarketIcon() {
2717 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET);
2718 mAppMarketIntent = updateExternalIcon(
2719 R.id.market_button, intent, R.drawable.app_market_generic);
2720 }
2721
2722 private void updateGlobalSearchIcon() {
2723 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2724 mGlobalSearchIntent = updateExternalIcon(
2725 R.id.search_button, intent, R.drawable.search_button_generic);
Patrick Dubroyceae05d2010-08-30 10:40:53 -07002726 }
2727
2728 /**
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002729 * Displays the shortcut creation dialog and launches, if necessary, the
2730 * appropriate activity.
2731 */
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002732 private class CreateShortcut implements DialogInterface.OnClickListener,
Romain Guy7b4ef332009-07-14 13:58:08 -07002733 DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
2734 DialogInterface.OnShowListener {
2735
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002736 private AddAdapter mAdapter;
Romain Guy9ffb5432009-03-24 21:04:15 -07002737
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002738 Dialog createDialog() {
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002739 mAdapter = new AddAdapter(Launcher.this);
Romain Guycbb89e42009-06-08 15:52:54 -07002740
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002741 final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
2742 builder.setTitle(getString(R.string.menu_item_add_item));
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002743 builder.setAdapter(mAdapter, this);
Romain Guycbb89e42009-06-08 15:52:54 -07002744
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002745 builder.setInverseBackgroundForced(true);
2746
2747 AlertDialog dialog = builder.create();
2748 dialog.setOnCancelListener(this);
Romain Guycbb89e42009-06-08 15:52:54 -07002749 dialog.setOnDismissListener(this);
Romain Guy7b4ef332009-07-14 13:58:08 -07002750 dialog.setOnShowListener(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002751
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002752 return dialog;
2753 }
2754
2755 public void onCancel(DialogInterface dialog) {
2756 mWaitingForResult = false;
2757 cleanup();
2758 }
2759
Romain Guycbb89e42009-06-08 15:52:54 -07002760 public void onDismiss(DialogInterface dialog) {
Romain Guycbb89e42009-06-08 15:52:54 -07002761 }
2762
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002763 private void cleanup() {
Joe Onoratocc19a532009-11-19 14:19:17 -08002764 try {
2765 dismissDialog(DIALOG_CREATE_SHORTCUT);
2766 } catch (Exception e) {
2767 // An exception is thrown if the dialog is not visible, which is fine
2768 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002769 }
2770
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002771 /**
2772 * Handle the action clicked in the "Add to home" dialog.
2773 */
2774 public void onClick(DialogInterface dialog, int which) {
2775 Resources res = getResources();
2776 cleanup();
Romain Guycbb89e42009-06-08 15:52:54 -07002777
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002778 switch (which) {
2779 case AddAdapter.ITEM_SHORTCUT: {
Joe Onoratodeb98af2010-02-19 14:59:39 -08002780 pickShortcut();
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002781 break;
2782 }
Romain Guycbb89e42009-06-08 15:52:54 -07002783
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002784 case AddAdapter.ITEM_APPWIDGET: {
2785 int appWidgetId = Launcher.this.mAppWidgetHost.allocateAppWidgetId();
Romain Guycbb89e42009-06-08 15:52:54 -07002786
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002787 Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
2788 pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002789 // start the pick activity
2790 startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET);
2791 break;
2792 }
Romain Guycbb89e42009-06-08 15:52:54 -07002793
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002794 case AddAdapter.ITEM_LIVE_FOLDER: {
2795 // Insert extra item to handle inserting folder
2796 Bundle bundle = new Bundle();
Romain Guycbb89e42009-06-08 15:52:54 -07002797
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002798 ArrayList<String> shortcutNames = new ArrayList<String>();
2799 shortcutNames.add(res.getString(R.string.group_folder));
2800 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
Romain Guycbb89e42009-06-08 15:52:54 -07002801
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002802 ArrayList<ShortcutIconResource> shortcutIcons =
2803 new ArrayList<ShortcutIconResource>();
2804 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
2805 R.drawable.ic_launcher_folder));
2806 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
2807
2808 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
2809 pickIntent.putExtra(Intent.EXTRA_INTENT,
2810 new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER));
2811 pickIntent.putExtra(Intent.EXTRA_TITLE,
2812 getText(R.string.title_select_live_folder));
2813 pickIntent.putExtras(bundle);
Romain Guycbb89e42009-06-08 15:52:54 -07002814
Jeffrey Sharkeyc7fdae12009-03-24 20:41:22 -07002815 startActivityForResult(pickIntent, REQUEST_PICK_LIVE_FOLDER);
2816 break;
2817 }
2818
2819 case AddAdapter.ITEM_WALLPAPER: {
2820 startWallpaper();
2821 break;
2822 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002823 }
2824 }
Romain Guy7b4ef332009-07-14 13:58:08 -07002825
2826 public void onShow(DialogInterface dialog) {
Winson Chungaafa03c2010-06-11 17:34:16 -07002827 mWaitingForResult = true;
Romain Guy7b4ef332009-07-14 13:58:08 -07002828 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002829 }
2830
2831 /**
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002832 * Receives notifications when applications are added/removed.
2833 */
2834 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
2835 @Override
2836 public void onReceive(Context context, Intent intent) {
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002837 closeSystemDialogs();
Joe Onoratob2061212009-11-24 16:13:54 -05002838 String reason = intent.getStringExtra("reason");
2839 if (!"homekey".equals(reason)) {
2840 boolean animate = true;
Joe Onorato34a0e1b2009-12-14 17:44:51 -08002841 if (mPaused || "lock".equals(reason)) {
Joe Onoratob2061212009-11-24 16:13:54 -05002842 animate = false;
2843 }
Joe Onoratob2061212009-11-24 16:13:54 -05002844 closeAllApps(animate);
Patrick Dubroy6b509c12010-08-23 15:08:16 -07002845 hideCustomizationDrawer(animate);
Joe Onoratob2061212009-11-24 16:13:54 -05002846 }
Joe Onorato2ca0ae72009-11-10 13:14:13 -08002847 }
2848 }
2849
2850 /**
Jeff Sharkey1e2efc82009-11-06 15:17:59 -08002851 * Receives notifications whenever the appwidgets are reset.
2852 */
2853 private class AppWidgetResetObserver extends ContentObserver {
2854 public AppWidgetResetObserver() {
2855 super(new Handler());
2856 }
2857
2858 @Override
2859 public void onChange(boolean selfChange) {
2860 onAppWidgetReset();
2861 }
2862 }
2863
2864 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002865 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002866 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002867 public int getCurrentWorkspaceScreen() {
Joe Onoratod0afc872010-06-11 00:03:15 -07002868 if (mWorkspace != null) {
Michael Jurka0142d492010-08-25 17:46:15 -07002869 return mWorkspace.getCurrentPage();
Joe Onoratod0afc872010-06-11 00:03:15 -07002870 } else {
2871 return SCREEN_COUNT / 2;
2872 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002873 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002874
Patrick Dubroy2b9ff372010-09-07 17:49:27 -07002875 void setAllAppsPagedView(PagedView view) {
2876 mAllAppsPagedView = view;
2877 }
2878
Joe Onorato9c1289c2009-08-17 11:03:03 -04002879 /**
2880 * Refreshes the shortcuts shown on the workspace.
2881 *
2882 * Implementation of the method from LauncherModel.Callbacks.
2883 */
2884 public void startBinding() {
2885 final Workspace workspace = mWorkspace;
2886 int count = workspace.getChildCount();
2887 for (int i = 0; i < count; i++) {
Joe Onorato3c2f7e12009-10-31 19:17:31 -04002888 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
Joe Onorato9c1289c2009-08-17 11:03:03 -04002889 ((ViewGroup) workspace.getChildAt(i)).removeAllViewsInLayout();
2890 }
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002891
Joe Onorato9c1289c2009-08-17 11:03:03 -04002892 if (DEBUG_USER_INTERFACE) {
2893 android.widget.Button finishButton = new android.widget.Button(this);
2894 finishButton.setText("Finish");
2895 workspace.addInScreen(finishButton, 1, 0, 0, 1, 1);
2896
2897 finishButton.setOnClickListener(new android.widget.Button.OnClickListener() {
2898 public void onClick(View v) {
2899 finish();
The Android Open Source Projectf96811c2009-03-18 17:39:48 -07002900 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002901 });
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002902 }
2903 }
2904
2905 /**
Joe Onorato9c1289c2009-08-17 11:03:03 -04002906 * Bind the items start-end from the list.
2907 *
2908 * Implementation of the method from LauncherModel.Callbacks.
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002909 */
Joe Onorato9c1289c2009-08-17 11:03:03 -04002910 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
2911
2912 final Workspace workspace = mWorkspace;
2913
2914 for (int i=start; i<end; i++) {
2915 final ItemInfo item = shortcuts.get(i);
2916 mDesktopItems.add(item);
2917 switch (item.itemType) {
2918 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
2919 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
Joe Onorato0589f0f2010-02-08 13:44:00 -08002920 final View shortcut = createShortcut((ShortcutInfo)item);
Joe Onorato9c1289c2009-08-17 11:03:03 -04002921 workspace.addInScreen(shortcut, item.screen, item.cellX, item.cellY, 1, 1,
2922 false);
2923 break;
2924 case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER:
2925 final FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07002926 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Joe Onorato9c1289c2009-08-17 11:03:03 -04002927 (UserFolderInfo) item);
2928 workspace.addInScreen(newFolder, item.screen, item.cellX, item.cellY, 1, 1,
2929 false);
2930 break;
2931 case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER:
2932 final FolderIcon newLiveFolder = LiveFolderIcon.fromXml(
2933 R.layout.live_folder_icon, this,
Michael Jurka0142d492010-08-25 17:46:15 -07002934 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
Joe Onorato9c1289c2009-08-17 11:03:03 -04002935 (LiveFolderInfo) item);
2936 workspace.addInScreen(newLiveFolder, item.screen, item.cellX, item.cellY, 1, 1,
2937 false);
2938 break;
Joe Onorato9c1289c2009-08-17 11:03:03 -04002939 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002940 }
2941
Joe Onorato9c1289c2009-08-17 11:03:03 -04002942 workspace.requestLayout();
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002943 }
2944
Joe Onorato9c1289c2009-08-17 11:03:03 -04002945 /**
2946 * Implementation of the method from LauncherModel.Callbacks.
2947 */
Joe Onoratoad72e172009-11-06 16:25:04 -05002948 public void bindFolders(HashMap<Long, FolderInfo> folders) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07002949 sFolders.clear();
2950 sFolders.putAll(folders);
The Android Open Source Project31dd5032009-03-03 19:32:27 -08002951 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002952
2953 /**
2954 * Add the views for a widget to the workspace.
2955 *
2956 * Implementation of the method from LauncherModel.Callbacks.
2957 */
2958 public void bindAppWidget(LauncherAppWidgetInfo item) {
Daniel Sandler843e8602010-06-07 14:59:01 -04002959 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
2960 if (DEBUG_WIDGETS) {
2961 Log.d(TAG, "bindAppWidget: " + item);
2962 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002963 final Workspace workspace = mWorkspace;
2964
2965 final int appWidgetId = item.appWidgetId;
2966 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
Daniel Sandler843e8602010-06-07 14:59:01 -04002967 if (DEBUG_WIDGETS) {
2968 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
2969 }
2970
Joe Onorato9c1289c2009-08-17 11:03:03 -04002971 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
2972
Joe Onorato9c1289c2009-08-17 11:03:03 -04002973 item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
2974 item.hostView.setTag(item);
2975
2976 workspace.addInScreen(item.hostView, item.screen, item.cellX,
2977 item.cellY, item.spanX, item.spanY, false);
2978
2979 workspace.requestLayout();
2980
2981 mDesktopItems.add(item);
Daniel Sandler843e8602010-06-07 14:59:01 -04002982
2983 if (DEBUG_WIDGETS) {
2984 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
2985 + (SystemClock.uptimeMillis()-start) + "ms");
2986 }
Joe Onorato9c1289c2009-08-17 11:03:03 -04002987 }
2988
2989 /**
2990 * Callback saying that there aren't any more items to bind.
2991 *
2992 * Implementation of the method from LauncherModel.Callbacks.
2993 */
2994 public void finishBindingItems() {
2995 if (mSavedState != null) {
2996 if (!mWorkspace.hasFocus()) {
Michael Jurka0142d492010-08-25 17:46:15 -07002997 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
Joe Onorato9c1289c2009-08-17 11:03:03 -04002998 }
2999
3000 final long[] userFolders = mSavedState.getLongArray(RUNTIME_STATE_USER_FOLDERS);
3001 if (userFolders != null) {
3002 for (long folderId : userFolders) {
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003003 final FolderInfo info = sFolders.get(folderId);
Joe Onorato9c1289c2009-08-17 11:03:03 -04003004 if (info != null) {
3005 openFolder(info);
3006 }
3007 }
3008 final Folder openFolder = mWorkspace.getOpenFolder();
3009 if (openFolder != null) {
3010 openFolder.requestFocus();
3011 }
3012 }
3013
Joe Onorato9c1289c2009-08-17 11:03:03 -04003014 mSavedState = null;
3015 }
3016
3017 if (mSavedInstanceState != null) {
3018 super.onRestoreInstanceState(mSavedInstanceState);
3019 mSavedInstanceState = null;
3020 }
3021
Joe Onorato9c1289c2009-08-17 11:03:03 -04003022 mWorkspaceLoading = false;
3023 }
3024
3025 /**
3026 * Add the icons for all apps.
3027 *
3028 * Implementation of the method from LauncherModel.Callbacks.
3029 */
3030 public void bindAllApplications(ArrayList<ApplicationInfo> apps) {
Romain Guy84f296c2009-11-04 15:00:44 -08003031 mAllAppsGrid.setApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003032 if (mCustomizePagedView != null) {
3033 mCustomizePagedView.setApps(apps);
3034 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003035 updateAppMarketIcon();
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003036 updateGlobalSearchIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003037 }
3038
3039 /**
3040 * A package was installed.
3041 *
3042 * Implementation of the method from LauncherModel.Callbacks.
3043 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003044 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003045 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onoratoa8138d52009-10-06 19:25:30 -07003046 mAllAppsGrid.addApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003047 if (mCustomizePagedView != null) {
3048 mCustomizePagedView.addApps(apps);
3049 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003050 updateAppMarketIcon();
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003051 updateGlobalSearchIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003052 }
3053
3054 /**
3055 * A package was updated.
3056 *
3057 * Implementation of the method from LauncherModel.Callbacks.
3058 */
Joe Onorato64e6be72010-03-05 15:05:52 -05003059 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003060 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato64e6be72010-03-05 15:05:52 -05003061 mWorkspace.updateShortcuts(apps);
3062 mAllAppsGrid.updateApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003063 if (mCustomizePagedView != null) {
3064 mCustomizePagedView.updateApps(apps);
3065 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003066 updateAppMarketIcon();
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003067 updateGlobalSearchIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003068 }
3069
3070 /**
3071 * A package was uninstalled.
3072 *
3073 * Implementation of the method from LauncherModel.Callbacks.
3074 */
Joe Onorato36115782010-06-17 13:28:48 -04003075 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) {
Joe Onorato9c1289c2009-08-17 11:03:03 -04003076 removeDialog(DIALOG_CREATE_SHORTCUT);
Joe Onorato36115782010-06-17 13:28:48 -04003077 if (permanent) {
3078 mWorkspace.removeItems(apps);
3079 }
Joe Onoratoa8138d52009-10-06 19:25:30 -07003080 mAllAppsGrid.removeApps(apps);
Andrew Stadler959f6032010-09-27 11:42:53 -07003081 if (mCustomizePagedView != null) {
3082 mCustomizePagedView.removeApps(apps);
3083 }
Patrick Dubroyceae05d2010-08-30 10:40:53 -07003084 updateAppMarketIcon();
Michael Jurka6ae0fcf2010-10-01 12:23:12 -07003085 updateGlobalSearchIcon();
Joe Onorato9c1289c2009-08-17 11:03:03 -04003086 }
Joe Onoratobe386092009-11-17 17:32:16 -08003087
3088 /**
Winson Chung80baf5a2010-08-09 16:03:15 -07003089 * A number of packages were updated.
3090 */
3091 public void bindPackagesUpdated() {
3092 // update the customization drawer contents
Winson Chung5f941722010-09-28 16:36:43 -07003093 if (mCustomizePagedView != null) {
Winson Chungb3347bb2010-08-19 14:51:28 -07003094 mCustomizePagedView.update();
Winson Chung5f941722010-09-28 16:36:43 -07003095 }
Winson Chung80baf5a2010-08-09 16:03:15 -07003096 }
3097
3098 /**
Joe Onoratobe386092009-11-17 17:32:16 -08003099 * Prints out out state for debugging.
3100 */
3101 public void dumpState() {
3102 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
Joe Onorato39bfc132009-11-18 17:22:01 -08003103 Log.d(TAG, "mSavedState=" + mSavedState);
Joe Onorato39bfc132009-11-18 17:22:01 -08003104 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
3105 Log.d(TAG, "mRestoring=" + mRestoring);
3106 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
3107 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
3108 Log.d(TAG, "mDesktopItems.size=" + mDesktopItems.size());
Brad Fitzpatrick319226a2010-09-01 13:45:16 -07003109 Log.d(TAG, "sFolders.size=" + sFolders.size());
Joe Onoratobe386092009-11-17 17:32:16 -08003110 mModel.dumpState();
3111 mAllAppsGrid.dumpState();
3112 Log.d(TAG, "END launcher2 dump state");
3113 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -08003114}